It does not help.
I am trying to put marker with right click and get his location in terrain mode.
When I am zooming the map closer to the ground and right click for getting the location, the marker doesn’t put where I clicked, it put the marker very far from where I clicked.
what I am missing?
this is my code:
var viewer = new Cesium.Viewer(‘cesiumContainer’);
viewer.scene.canvas.addEventListener(‘contextmenu’, (event) => {
event.preventDefault();
const mousePosition = new Cesium.Cartesian2(event.clientX, event.clientY);
const selectedLocation = convertScreenPixelToLocation(mousePosition );
setMarkerInPos(selectedLocation);
}, false);
function convertScreenPixelToLocation(mousePosition) {
const ellipsoid = viewer.scene.globe.ellipsoid;
const cartesian = viewer.camera.pickEllipsoid(mousePosition, ellipsoid);
if (cartesian) {
const cartographic = ellipsoid.cartesianToCartographic(cartesian);
const longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(15);
const latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(15);
return {lat: Number(latitudeString),lng: Number(longitudeString)};
} else {
return null;
}
}
function setMarkerInPos(position){
viewer.pickTranslucentDepth = true;
const locationMarker = viewer.entities.add({
name : ‘location’,
position : Cesium.Cartesian3.fromDegrees(position.lng, position.lat, 300),
point : {
pixelSize : 5,
color : Cesium.Color.RED,
outlineColor : Cesium.Color.WHITE,
outlineWidth : 2
},
label : {
text : ‘check’,
font : ‘14pt monospace’,
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
outlineWidth : 2,
verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
pixelOffset : new Cesium.Cartesian2(0, -9)
}
});
}
בתאריך יום ב׳, 11 בפבר׳ 2019 ב-14:41 מאת Omar Shehata <omar.sameh.shehata@gmail.com>: