Cesiumjs – How to get the the coordinate of a KML point ?

phpmind-cesiumjs-coordinate-of-a-KML-point

Here is an event handler that will get the Cartesian3 position of a point on left click and writes it to the console.

            var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
        handler.setInputAction(function(click) {
            var pickedObject = viewer.scene.pick(click.position);
            if (Cesium.defined(pickedObject)) {
                console.log(pickedObject.id.position.getValue(viewer.clock.currentTime));
            }
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    
// Output for example
// (-1506927.5843447673, -5174505.091726597, 3399472.531280526)
// (-1704963.9958314616, -4665566.981540714, 3987362.8409044705)

Share

Leave a Reply

Your email address will not be published. Required fields are marked *