var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
var scene = viewer.scene
var billboard
handler.setInputAction(function(click){
var cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid)
if(cartesian){
var pickdObject = scene.pick(click.position)
var position = viewer.camera.pickEllipsoid(click.position)
if(Cesium.defined(pickdObject)){
//根据点击对象的id删除该对象
viewer.entities.getById(pickdObject.id._id).show = false //隐藏标记
}else{
var cartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(position)
var lng = Cesium.Math.toDegrees(cartographic.longitude).toFixed(4) //经纬度
var lat = Cesium.Math.toDegrees(cartographic.latitude).toFixed(4)
billboard = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(lng, lat),
billboard: {
image: "img/placeMarker.png",
pixelOffset: new Cesium.Cartesian2(0, 0),
eyeOffset: new Cesium.Cartesian3(0.0, 0.0, 0.0),
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM
}
});
}
}
},Cesium.ScreenSpaceEventType.LEFT_CLICK)