简体   繁体   English

在Cesium中移动KML对象而不会闪烁

[英]Move a KML object in Cesium without flashing

I'm porting an existing Google Earth application to Cesium. 我正在将现有的Google Earth应用程序移植到Cesium。 The application tracks the position of a vehicle over time. 该应用程序会随时间跟踪车辆的位置。 Some base kml is loaded at first to show the overall track of the vehicle. 首先会加载一些基本kml,以显示车辆的整体轨迹。 Then a kml file is continuously updated with a placemark which shows the current position of the vehicle. 然后,使用显示车辆当前位置的地标连续更新kml文件。

Currently, I am able to achieve the desired effect of moving the placmark in Cesium by adding the updated kml and removing the old kml every time it changes. 目前,我可以通过添加更新的kml并在每次更改时删除旧的kml来实现在Cesium中移动placmark的预期效果。 The problem is that the placemark seems to flash or glitch each time that I reload it. 问题在于,每次我重新加载地标时,地标似乎都会闪烁或出现故障。

I had a similar issue in Google Earth which I solved by moving the existing KML instead of adding and deleting each time it changed. 我在Google Earth中遇到了类似的问题,我通过移动现有的KML而不是每次更改都添加和删除来解决了。 I'd like to find a way to do the same with Cesium. 我想找到一种使用铯的方法。 I've tried looking into the entity objects associated with the KmlDataSource but I can't see any way to move them. 我尝试查看与KmlDataSource关联的实体对象,但看不到任何移动它们的方法。 I was able to find the associated primitive available through the scene but I was not able to determine how to make it move. 我可以通过场景找到可用的关联基元,但是无法确定如何移动它。

Below is the snippet I use to add and remove the kml. 以下是我用来添加和删除kml的代码段。

var pparser = new DOMParser();
var newPositionDataSource = new Cesium.KmlDataSource();
var prom = newPositionDataSource.load(parser.parseFromString(testkml, "text/xml"));
viewer.dataSources.add(newPositionDataSource);

if (positionDataSource != null)
{
    Cesium.when(prom, function()
    {
        viewer.dataSources.remove(positionDataSource);
    });
}
positionDataSource = newPositionDataSource;

I got this to work for placemarks. 我将其用于地标。 Emackey's suggestion was a good one. Emackey的建议是一个好建议。 I modified my code so that I only add the KML for the placemark once. 我修改了代码,以便只为地标添加一次KML。 For each position update after the first I load in the new KML and set the original data source entity's position equal to that of the new KML data source. 对于第一次更新后的每个位置,我都会加载新的KML,并将原始数据源实体的位置设置为与新的KML数据源相同。

This allows the placemark to move smoothly without glitching and saves me the trouble of manually parsing the KML. 这样可以使地标平稳移动而不会出现毛刺,并且省去了手动解析KML的麻烦。 It works great for the placemarks. 它非常适合地标。

Unfortunately, I have a couple of lines connecting the placemarks and they still glitch as it updates. 不幸的是,我有几条线连接地标,并且在地标更新时仍会出现故障。 If anyone has any ideas about how the line glitching could be prevented, I would be happy to read them. 如果有人对如何防止线路故障有任何想法,我将很高兴阅读它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM