issue with Viewer.flyTo on KML entity

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

Hello Norm,

Thanks for looking into this! I’ve filed an issue on our GitHub for us to look into it: https://github.com/AnalyticalGraphicsInc/cesium/issues/4327

viewer.flyTo polls to get the bounding sphere for the entity and isn’t supposed to fly to it until the bounding sphere is ready. I’m guessing flyTo is being triggered before the bounding sphere is ready

We have a bug bash coming up in the middle of October, and I’ve tagged this issue for us to look into it then. Of course, we’d gladly accept a contribution if you would like to look into fixing the problem before then =)

Here’s the function in viewer that computes the bounding sphere to fly to: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Widgets/Viewer/Viewer.js#L1811-L1819

And here is where the data source display gets the bounding spheres from the entity visualizers: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/DataSources/DataSourceDisplay.js#L337

You can check out our contributors documentation for how to download and build the code base: https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Documentation/Contributors/BuildGuide

Sorry I don’t have any good workarounds.

Thanks again,

Hannah

Hello,

This issue has been fixed and will be available in the Cesium 1.27 release available on November 1st.

Best,

Hannah

I believe this is not fixed. I have just tested with original code and all my labels and pins from KML are still underground.
I have posted also to original https://github.com/AnalyticalGraphicsInc/cesium/issues/4327

So if anyone has a working examle of KML loading and flyTo I would be happy.