爲了在銫地形上添加標記,我使用sampleTerrain
函數來獲取高度。如何在銫地形上添加標記
我可以在山頂上添加標記,但標記位置遠離鼠標點擊。我怎樣才能在銫地形上添加標記,這樣標記將被精確添加到點擊位置?
僅供參考我會把我的代碼在這裏:
async leftClickInputAction(event:{position: {x:number, y:number}}):Promise<any> {
let positionCartesian3 = this.cesium.viewer.camera.pickEllipsoid(event.position);
let positionCartographic = Cesium.Cartographic.fromCartesian(positionCartesian3);
await Cesium.sampleTerrain(this.cesium.viewer.terrainProvider, 9, [positionCartographic]);
let height = positionCartographic.height;
let cart3_with_height = Cesium.Cartesian3.fromRadians(positionCartographic.longitude, positionCartographic.latitude, positionCartographic.height);
let window_coordinates = this.cesium.calcService.toFixes7Obj(Cesium.SceneTransforms.wgs84ToWindowCoordinates(this.cesium.viewer.scene,cart3_with_height));
positionCartesian3 = this.cesium.viewer.camera.pickEllipsoid(event.position);
positionCartographic = Cesium.Cartographic.fromCartesian(positionCartesian3);
positionCartographic.height = height;*/
let lngDeg:number = Cesium.Math.toDegrees(positionCartographic.longitude);
let latDeg:number = Cesium.Math.toDegrees(positionCartographic.latitude);
let position: [number, number, number] = [lngDeg, latDeg, positionCartographic.height];
let color:string = this.cesium.positionFormService.getSelectedColor();
let marker_picker = {position};
if(color != "blue") marker_picker['color'] = color;
this.cesium.queryParamsHelperService.addMarker(marker_picker);
感謝!!!!!! BTW是否有可能沒有baseLayerPicker? –
是的,你可以關閉baseLayerPicker,但是你應該使用地形來源,這樣山脈就可以繼續使用。當地形不見時,Scene.pickPosition將無法正常工作。 – emackey
我使用https://assets.agi.com/stk-terrain/world的地形來源,並且在baseLayerPicker = false時不起作用 –