I'm trying to draw in cesium with mouse click.But there is something wrong when i get the position of mouse click to add entity or primitive.If i set terrainProvider will cause problems,if not,it's ok
mouseHandler.setInputAction(function(movement) {
if(movement.position != null) {
var cartesian = scene.camera.pickEllipsoid(movement.position, ellipsoid);
if (cartesian) {
var cartographic = ellipsoid.cartesianToCartographic(cartesian);
// 将弧度转为度的十进制度表示
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
var height = that.viewer.scene.globe.getHeight(cartographic);
/**
*if i use this,the entity's position is not the
position of mouse click
*/
var e = that.viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(longitude , latitude),
point : {
color : Cesium.Color.SKYBLUE,
pixelSize : 10,
outlineColor : Cesium.Color.YELLOW,
outlineWidth : 3,
heightReference : Cesium.HeightReference.CLAMP_TO_GROUND
}
});
/*
*if i use this,the billboard will can't see when i zoom to big level
*/
var b = new Cesium.BillboardCollection();
this.scene.primitives.add(b);
b.add({
show : true,
position : Cesium.Cartesian3.fromDegrees(longitude,latitude),
image: this._options.iconUrl,
heightReference : Cesium.HeightReference.CLAMP_TO_GROUND,
/*
*//if i use this parameter,this billboard can always see but if i change camera the position will change too
*disableDepthTestDistance : Number.POSITIVE_INFINITY*/
});
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
Cesium version is 1.39
thanks for help