代码:
1 var annotations; 2 function axToolCoordinate(layer) { 3 var handler=new Cesium.ScreenSpaceEventHandler(viewer.canvas); 4 annotations=viewer.scene.primitives.add( new Cesium.LabelCollection()); 5 handler.setInputAction(function (evt){ 6 var pickedObject=viewer.scene.pick(evt.position); 7 if(viewer.scene.pickPositionSupported && Cesium.defined(pickedObject)){ 8 var cartesian=viewr.scene.pickPosition(evt.position); 9 if(Cesium.defined(cartesian)) 10 { 11 var cartographic=Cesium.Cartographic.fromCartesian(cartesian); 12 var lng=Cesium.Math.toDegrees(cartographic.longitude); 13 var lat=Cesium.Math.toDegrees(cartographic.latitude); 14 var height=cartographic.height; 15 annotate(cartesian,lng,lat,height); 16 } 17 } 18 else{ 19 var ray=viewer.camera.getPickRay(evt.position); 20 var cartesian=viewer.scene.globe.pick(ray,viewer.scene); 21 if(Cesium.defined(cartesian)){ 22 var cartographic=Cesium.Cartographic.fromCartesian(cartesian); 23 var lng=Cesium.Math.toDegrees(cartographic.longitude); 24 var lat=Cesium.Math.toDegrees(cartographic.latitude); 25 var height=cartographic.height; 26 annotate(cartesian,lng,lat,height); 27 } 28 } 29 },Cesium.ScreenSpaceEventType.LEFT_CLICK); 30 31 handler.setInputAction(function (){ 32 viewer.entities.removeAll(); 33 annotations.removeAll(); 34 },Cesium.ScreenSpaceEventType.RIGHT_CLICK); 35 } 36 37 function createPoint(worldPostion){ 38 var point = viewer.entities.add({ 39 position:worldPostion, 40 point:{ 41 color:Cesium.Color.CRIMSON, 42 pixelSize:9, 43 outlineColor:Cesium.Color.ALICEBLUE, 44 outlineWidth:2, 45 disableDepthTestDistance:1000 46 } 47 }); 48 } 49 50 function annotate(cartesian,lng,lat, height){ 51 createPoint (cartesian); 52 annotations.add({ 53 position:cartesian, 54 text: 55 'Lon:'+lng.toFixed(5)+'\u00B0'+ 56 '\nLat:'+lat.toFixed(5)+'\u00B0'+ 57 '\nHeight:'+height.toFixed(2)+'m', 58 showBackground:true, 59 font:'22px monospace', 60 horizontalOrigin: Cesium.HorizontalOrigin.LEFT, 61 verticalOrigin: Cesium.VerticalOrigin.Bottom, 62 disableDepthTestDiatane:Number.POSITIVE_INFINITY 63 }); 64 }
标签:11,cartesian,量测,cartographic,viewer,height,var,Cesium From: https://www.cnblogs.com/yhlx125/p/17899606.html