Get entity position on pick

Hi,

I have a Geojsonfile with only points (position in WGS 84). When I click on a point I would like to zoom on this point (this part works) and display in a popup the WGS 84 (longitude and latitude) position of the point. This is where I’m having trouble. I can’t get the position in WGS 84 !

Here is my current code :

_this.viewer.screenSpaceEventHandler.setInputAction(function(click) {
            var pickedFeature = _this.viewer.scene.pick(click.position);
            if (Cesium.defined(pickedFeature)){
                _this.viewer.flyTo(
                    pickedFeature.id, {
                        offset: new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-90), 0),
                    }
                );  
                _this.popupEntity(pickedFeature);
                //_this.load3DModels(pickedFeature);
            }            
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

popupEntity(pickedFeature){
        if(pickedFeature.id.properties){
            openNav("side-popup", "550px"); 
            let typologie = pickedFeature.id.properties.typologie._value;
            let position = pickedFeature.id.position._value;
            console.log(Cesium.Ellipsoid.WGS84.cartesianToCartographic(position));
            document.getElementById("side-popup-text-content").innerHTML = `
            
            Typologie = ${typologie} <br />
            Cesium position X = ${ position.x} <br />
            Cesium position Y = ${ position.y} <br />  
            Longitude WGS 84  = ${ Cesium.Ellipsoid.WGS84.cartesianToCartographic(position).longitude } <br />
            Latitude WGS 84  =  ${ Cesium.Ellipsoid.WGS84.cartesianToCartographic(position).latitude } <br />            
            `;             
            document.getElementById("main-text-popup").style.display = 'block';
        }
    }

My coordinates should be something like 55.30488, -21.04814 but the result is totally different :

Cesium position X = 3388713.806071788
Cesium position Y = 4894993.289412959
Longitude WGS 84 = 0.9652692990863668
Latitude WGS 84 = -0.36807763585072933

Could you please help me to understand how to get the coordinates of a cesium primitive ?

Thanks for your help,

Arnaud

1 Like

What is the output of typeof pickedFeature.id.position?
Assuming that it is Cartesian, the issue you’re likely having is that you expect to see the lat/lon in degrees whilst they’re displayed in radians. Try wrapping the lon and lat in a Cesium.Math.toDegrees(x).

Hi @PieterT2000 ,

Thanks for your help. For the typeOf pickedFeature.position the result is object.
Converting the coordinates degrees did the job.
Now the result is :

Cesium position X = 3388713.806071788
Cesium position Y = 4894993.289412959
Longitude = 55.30585693119999
Latitude = -21.089295067399995
TypeOF = object 

Thank you very much for your help !

1 Like