cesium获取坐标及高程

1、获取entity坐标及高程

 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);

2、鼠标点选获取坐标及高程

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;
}
}
}

3、根据坐标获取高程

var carto=new Cesium.Cartographic.fromDegrees(lon,lat);  //输入经纬度
var h1=viewer.scene.globe.getHeight(carto);

4、根据坐标获取地表附着物高程

var carto=new Cesium.Cartographic.fromDegrees(lon,lat);  //输入经纬度
var h2=_this.viewer.scene.sampleHeight(carto);

 5、根据坐标获取terrain高程,精度为m

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;
});   

  

-----------------------------------------------------------

转载请注明出处:https://www.cnblogs.com/implementer/

  

你可能感兴趣的:(cesium获取坐标及高程)