对拾取位置的的示例做了改进,想增加停止拾取(停止标注)的功能,虽然实现了,但我写的不接地气,请问“停止标注”怎么写最简洁?
官网示例
http://support.supermap.com.cn:8090/webgl/examples/editor.html#pickPosition
我停止标注的代码
/*
* 点标注开始
* */
var handler_drawpoint = new Cesium.ScreenSpaceEventHandler(scene.canvas);
//开始点标注
$('#start_drawpoint').click(function(){
//设置鼠标左键单击回调事件
handler_drawpoint.setInputAction(function(e) {
//首先移除之前添加的点
//viewer.entities.removeAll();
//获取点击位置笛卡尔坐标
var position = scene.pickPosition(e.position);
//将笛卡尔坐标转化为经纬度坐标
var cartographic = Cesium.Cartographic.fromCartesian(position);
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
var height = cartographic.height;
if(height < 0) {
height = 0;
}
//在点击位置添加对应点
viewer.entities.add(new Cesium.Entity({
point : new Cesium.PointGraphics({
color : new Cesium.Color(1, 1, 0),
pixelSize : 20,
outlineColor : new Cesium.Color(0, 1, 1)
}),
position : Cesium.Cartesian3.fromDegrees(longitude, latitude , height + 20)
}));
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
});
//停止点标注
$('#end_drawpoint').click(function(){
handler_drawpoint.setInputAction(function(e) {
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
});
//清除点标注
$('#clear_drawpoint').click(function(){
viewer.entities.removeAll();
});