如何解决仅在执行viewer.zoomTo之后运行自定义Cesium函数
我有一个CesiumJS函数,我想在执行zoomTo()之后且仅在执行完之后才执行,这可以确保地形已完全加载(如文档中所述)! br /> 这是因为此函数实际上应该compute the intersection between a ray and the terrain,所以必须完全加载地形才能成功执行。
在当前状态下,以下代码返回:null
超级快(它根本不等待地形):
例如:
var viewer = new Cesium.Viewer('cesiumContainer',{
imageryProvider : new Cesium.BingMapsImageryProvider({
url : 'https://dev.virtualearth.net',key : $(BING_KEY),mapStyle : Cesium.BingMapsstyle.AERIAL
}),terrainProvider: new Cesium.CesiumTerrainProvider({
url : 'https://api.maptiler.com/tiles/terrain-quantized-mesh/?key$(MKEY)'
});
baseLayerPicker : false,infoBox : false,});
var p0 = [10.7465,48.3147,1500];
var p1 = [10.7475,48.3127,1000];
var start = new Cesium.Cartesian3.fromdegrees(...p0);
var end = new Cesium.Cartesian3.fromdegrees(...p1);
var entity = viewer.entities.add({
polyline : {
positions : Cesium.Cartesian3.fromdegreesArrayHeights([
...(p0.concat(p1))
]),width : 4,material : new Cesium.polylineGlowMaterialProperty({
glowPower : 1,color : Cesium.Color.GREEN
})
}
});
viewer.zoomTo(viewer.entities);
// then run this function:
function pickGlobeIntersection(viewer,p0,p1) {
var direction = new Cesium.Cartesian3();
Cesium.Cartesian3.subtract(p1,direction);
console.log("direction: ",direction);
Cesium.Cartesian3.normalize(direction,direction);
var ray = new Cesium.Ray(p0,direction);
var hitPos = viewer.scene.globe.pick(ray,viewer.scene);
if ((hitPos !== undefined) && (hitPos !== null)) {
console.log("hitPos: ",hitPos);
return hitPos;
} else {
console.log("hitPos is null!");
return null;
}
}
pickGlobeIntersection(viewer,start,end);
(如果在sandcastle中使用了代码,则将查看器默认替换为一个)
如何确保仅在地形完全加载后才执行该功能?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。