cesiumpy icon indicating copy to clipboard operation
cesiumpy copied to clipboard

Flyto or zoomto to an entity or entities

Open CMCDragonkai opened this issue 7 years ago • 5 comments

On cesium you can normally add an entity and fly to that entity:

            var wyoming = viewer.entities.add({
                name: 'Wyoming',
                // polygon :: Cesium.PolygonGraphics
                polygon: {
                    // polygon longitude and latitude (not totally accurate)
                    hierarchy: Cesium.Cartesian3.fromDegreesArray([
                        -109.080842, 45.002073,
                        -105.91517,  45.002073,
                        -104.058488, 44.996596,
                        -104.053011, 43.002989,
                        -104.053011, 41.003906,
                        -105.728954, 40.998429,
                        -107.919731, 41.003906,
                        -109.04798,  40.998429,
                        -111.047063, 40.998429,
                        -111.047063, 42.000709,
                        -111.047063, 44.476286,
                        -111.05254,  45.002073
                    ]),
                    material: Cesium.Color.RED.withAlpha(0.5)
                }
            });

            viewer.flyTo(wyoming).then(function(result){
                if (result) {
                    viewer.selectedEntity = wyoming;
                }
            });

I just tried this with an entity I added via ob = v.dataSources.add() but I wasn't able run v.camera.flyTo(ob), it didn't fly anywhere.

How can this be done? Also I'm a bit confused as to how Cesium's Javascript API maps to the Python object API, some things are placed in different areas.

CMCDragonkai avatar Oct 17 '16 10:10 CMCDragonkai

Furthermore, how do you set the default position of the camera? This didn't work: http://stackoverflow.com/questions/28709007/how-to-set-the-default-view-location-cesium-1-6

CMCDragonkai avatar Oct 17 '16 11:10 CMCDragonkai

Thx for the report. Because simple JavaScript call v.camera.flyTo(v.dataSources) doesn't work, current impl needs to be fixed. Will consider better soln.

sinhrks avatar Oct 23 '16 11:10 sinhrks

Any news on this?

CMCDragonkai avatar Jan 18 '17 10:01 CMCDragonkai

Any news on this?

callmeYe avatar Mar 21 '20 12:03 callmeYe

This might help someone since I also had trouble using zoomTo on an entity that had just been added. https://cesium.com/docs/cesiumjs-ref-doc/Rectangle.html#.fromCartesianArray

    const arrayOfPositions = /* create array of Cesium.Cartesian3 here */;
    const destination = Cesium.Rectangle.fromCartesianArray(arrayOfPositions);
    this.viewer.camera.setView({
      destination,
    });
    this.viewer.camera.zoomOut(); // maybe not needed but adds a helpful buffer for my purposes

fc avatar May 27 '20 23:05 fc