一、獲取entity座標及高程javascript
var cartographic = Cesium.Cartographic.fromCartesian(entity.position.getValue()); var lon = Cesium.Math.toDegrees(cartographic.longitude); var lat = Cesium.Math.toDegrees(cartographic.latitude); var elev = viewer.scene.globe.getHeight(cartographic);
二、鼠標點選獲取座標及高程java
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); handler.setInputAction(function (event) { var wp = event.position; if (!Cesium.defined(wp)) { return } var ray = viewer.scene.camera.getPickRay(wp); if (!Cesium.defined(ray)) { return } var cartesian = viewer.scene.globe.pick(ray, viewer.scene); if (!Cesium.defined(cartesian)) { return } if (cartesian) { var cartographic = Cesium.Cartographic.fromCartesian(cartesian); var lon = Cesium.Math.toDegrees(cartographic.longitude); var lat = Cesium.Math.toDegrees(cartographic.latitude); var elev = viewer.scene.globe.getHeight(cartographic); } } }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
鼠標點選2(能夠選擇模型)
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
var handler.setInputAction(function (event) {
var wp = event.position;
if (!Cesium.defined(wp)) {
return
}
var cartesian=viewer.scene.pickPosition(wp);
if(cartesian){
var cartographic=ellipsoid.cartesianToCartographic(cartesian);
//畫點
var lon = Cesium.Math.toDegrees(cartographic.longitude);
var lat = Cesium.Math.toDegrees(cartographic.latitude);
var elev = cartographic.height;
if(elev<0){
var ray = viewer.scene.camera.getPickRay(wp);
if (!Cesium.defined(ray)) {
return
}
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
if (!Cesium.defined(cartesian)) {
return
}
if(cartesian){
cartographic=ellipsoid.cartesianToCartographic(cartesian);
lon = Cesium.Math.toDegrees(cartographic.longitude);
lat = Cesium.Math.toDegrees(cartographic.latitude);
elev = cartographic.height;
}
}
}
三、根據座標獲取高程git
var carto=new Cesium.Cartographic.fromDegrees(lon,lat); //輸入經緯度 var h1=viewer.scene.globe.getHeight(carto);
四、根據座標獲取地表附着物高程canvas
var carto=new Cesium.Cartographic.fromDegrees(lon,lat); //輸入經緯度 var h2=_this.viewer.scene.sampleHeight(carto);
五、根據座標獲取terrain高程,精度爲mpromise
var terrainData = new Cesium.CesiumTerrainProvider({ url:this.server_url_outer+"terrain/" //輸入terrian地形數據加載地址 }); var positions = [ Cesium.Cartographic.fromDegrees(lon,lat) //輸入經緯度 ]; var promise = Cesium.sampleTerrain(terrainData,14,positions); //獲取14級地形高程 Cesium.when(promise, function (updatedPositions) { var terrainHeight = updatedPositions[0].height; });
-----------------------------------------------------------ide
轉載請註明出處:https://www.cnblogs.com/implementer/this