Hello,
I need to zoom to my loaded KML in javascript.
This is my source code inside my index.html
// Load my QGIS published KML -----------------------------
var viewer = new Cesium.Viewer('cesiumContainer');
viewer.dataSources.add(Cesium.KmlDataSource.load('gaetaDoc.kml'));
// How to FlyTo or ZoomTo the extents of a KML file? Something like:
// viewer.camera.flyTo(
What is the correct syntax ?
Thank you for any help
Roberto
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var promise = viewer.dataSources.add(Cesium.KmlDataSource.load(‘gaetaDoc.kml’));
// when the DS done loading datam fly to it (flyTo would get the resolved value which is the filled data source)
Cesium.when(promise, viewer.flyTo);
Yonatan,
I changed your code and now it works :
var promise = viewer.dataSources.add(Cesium.KmlDataSource.load('gaetaDoc.kml'));
Cesium.when(viewer.flyTo(promise));
Correct ?
Thank you for the suggestion
Roberto
Yea. I forgot that flyTo also accepts a promise. Cheers
You don’t need the Cesium.when either. The below works fine.
var promise = viewer.dataSources.add(Cesium.KmlDataSource.load(‘gaetaDoc.kml’));
viewer.flyTo(promise);
Yes, thanks. But, "Cesium.when(viewer.flyTo(promise));" zoom only
after fully loaded KML.
In my case it works better.
Great !
Roberto
They are both supposed to run after the KML fully loaded. The
"Cesium.when(viewer.flyTo(promise)" is supposed to give you the ability to
do something after flight was over -
Cesium.when(viewer.flyTo(promise, someMethodAfterFlight)
Haven't tried either, but according to docs it's supposed to work