CesiumJS:可拖动点跳转到静态点位置
CesiumJS: Draggable points jump to static point locations
我写了一些函数来在 Cesium 中绘制可拖动的静态点。但是,将它们一起使用时我遇到了一个大问题。
我可以通过在地图上单击来绘制可拖动的点,并通过单击和拖动来移动它们。但是,如果我在绘制可拖动点后绘制静态点,则可拖动点会跳转到静态点的位置!我仍然可以拖动该点,但它总是会快速回到静态点位置。
这里有一个 Sandcastle 演示来说明我的问题 - http://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=54a2252d95768ca89d23948ad010356a
在这个例子中,在地图上的任何点击都会创建一个可拖动的点(红点)。脚本末尾有两次超时,一次5s后绘制静态点,一次10s后在不同位置绘制静态点。静态点是紫色的,比可拖动的要小很多。
如您所见,如果您在前 5 秒内绘制一个可拖动点,它将跳转到第一个静态点的位置。
这是怎么回事?!
Cesium 团队的 Rachel Hwang 为我解决了这个问题。这是她的解决方案:
This:
let positionCallback = () => {
return waypointPosition;
};
Should be:
let positionCallback = (time, result) => {
return waypointPosition.clone(result);
};
The reason is that the signature for the CallbackProperty callback (https://cesiumjs.org/Cesium/Build/Documentation/CallbackProperty.html#~Callback)
takes a time and result. If result is provided then you MUST store
the result into that existing object and return it (otherwise you
should return a new value). Calling clone(result) does just that.
The reason it is done this way is because we make heavy use of scratch
variables to avoid memory allocations.
Sandcastle 现在可以正常工作了 - http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Hello%20World.html&label=Showcases&gist=54a2252d95768ca89d23948ad010356a
我写了一些函数来在 Cesium 中绘制可拖动的静态点。但是,将它们一起使用时我遇到了一个大问题。
我可以通过在地图上单击来绘制可拖动的点,并通过单击和拖动来移动它们。但是,如果我在绘制可拖动点后绘制静态点,则可拖动点会跳转到静态点的位置!我仍然可以拖动该点,但它总是会快速回到静态点位置。
这里有一个 Sandcastle 演示来说明我的问题 - http://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=54a2252d95768ca89d23948ad010356a
在这个例子中,在地图上的任何点击都会创建一个可拖动的点(红点)。脚本末尾有两次超时,一次5s后绘制静态点,一次10s后在不同位置绘制静态点。静态点是紫色的,比可拖动的要小很多。
如您所见,如果您在前 5 秒内绘制一个可拖动点,它将跳转到第一个静态点的位置。
这是怎么回事?!
Cesium 团队的 Rachel Hwang 为我解决了这个问题。这是她的解决方案:
This:
let positionCallback = () => { return waypointPosition; };
Should be:
let positionCallback = (time, result) => { return waypointPosition.clone(result); };
The reason is that the signature for the CallbackProperty callback (https://cesiumjs.org/Cesium/Build/Documentation/CallbackProperty.html#~Callback) takes a time and result. If result is provided then you MUST store the result into that existing object and return it (otherwise you should return a new value). Calling clone(result) does just that. The reason it is done this way is because we make heavy use of scratch variables to avoid memory allocations.
Sandcastle 现在可以正常工作了 - http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Hello%20World.html&label=Showcases&gist=54a2252d95768ca89d23948ad010356a