Hi all,
I'm seeing an issue with Viewer.flyTo (also zoomTo) on entities derived from a KML file. To illustrate, here's a Sandcastle example that loads a KML file with a single placemark:
var viewer = new Cesium.Viewer('cesiumContainer');
var options = {
camera : viewer.scene.camera,
canvas : viewer.scene.canvas
};
var zoomTarget;
var kmlFile = "https://raw.githubusercontent.com/googlemaps/kml-samples/gh-pages/kml/Placemark/placemark.kml";
var promise = Cesium.KmlDataSource.load(kmlFile, options);
Cesium.when(promise, function(dataSource) {
viewer.dataSources.add(dataSource);
zoomTarget = dataSource.entities.values[0];
});
Sandcastle.addToolbarButton('Fly to Placemark', function() {
viewer.flyTo(zoomTarget);
}, 'toolbar');
Content of the KML file:
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>
My office
</name>
<description>
This is the location of my office.
</description>
<Point>
<coordinates>
-122.087461,37.422069
</coordinates>
</Point>
</Placemark>
</kml>
When you click the button to fly to the placemark, the viewer zooms too far ending up below ground. Clicking the button again zooms out to the correct view.
Interestingly, the issue doesn't occur with non-KML entities. In the following example, an entity is created with the same coordinates as the KML placemark above, but in this case, the viewer zooms to the appropriate view on the first button click.
var viewer = new Cesium.Viewer('cesiumContainer');
var options = {
camera : viewer.scene.camera,
canvas : viewer.scene.canvas
};
var pinBuilder = new Cesium.PinBuilder();
var entity = viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(-122.087461,37.422069),
label : {
text : 'pin',
verticalOrigin : Cesium.VerticalOrigin.TOP
},
billboard : {
image : pinBuilder.fromColor(Cesium.Color.SALMON, 24).toDataURL(),
verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
}
});
Sandcastle.addToolbarButton('Fly To Entity', function() {
viewer.flyTo(entity);
}, 'toolbar');
The difference between the two examples appears to be the initial bounding sphere computed for the entity. For the second example, the center of the bounding sphere is identical to the entity's position. Not so with the KML example -- the z-component in particular is much smaller. After the second button click, the bounding sphere gets recalculated and the center becomes roughly the same.
Is there anything that can be done so users don't have to click twice to zoom to KML features?
Thanks,
--Norm