修改新增点事件逻辑

tykong-cidian
dongjiajun 2024-07-05 18:24:20 +08:00
parent 8db90be785
commit 43e6b9ac2a
2 changed files with 36 additions and 16 deletions

View File

@ -629,17 +629,15 @@ export default {
// }); // });
}, },
// //
async selectPoint(){ selectPoint(){
// //
let res = await cu.clickToAddPoint() cu.clickToAddPoint(point=>{
cu.addPoint(res.lng, res.lat, 10); this.updatedPoint = {
this.updatedPoint = {
...this.currentSelectPoint, ...this.currentSelectPoint,
lng: res.lng, lng: point[0],
lat: res.lat lat: point[1],
} }
console.log(this.updatedPoint,'查看点'); })
console.log(this.simpleData[2],'查看simpleData');
}, },
// //
savePoint(){ savePoint(){
@ -657,6 +655,8 @@ export default {
this.$refs.multipleTable.toggleAllSelection(); this.$refs.multipleTable.toggleAllSelection();
// //
this.updatePointVisible = false; this.updatePointVisible = false;
//
cu.destroyClickToAddPoint()
} }
}, },
computed: { computed: {

View File

@ -176,12 +176,16 @@ class CesiumUtils {
this.viewer.entities.removeAll(); this.viewer.entities.removeAll();
} }
//修改点的位置 //修改点的位置
static clickToAddPoint(){ static clickToAddPoint(callback){
return new Promise((resolve, reject) => { //清空之前的handler
if (this.handler) {
this.handler.destroy();
}
// return new Promise((resolve, reject) => {
var scene = this.viewer.scene; var scene = this.viewer.scene;
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas); this.handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
const that = this; const that = this;
handler.setInputAction(function (movement) { this.handler.setInputAction(function (movement) {
// 清除历史单击点 // 清除历史单击点
// handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK); // handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
// movement.position 像素的x、y坐标 // movement.position 像素的x、y坐标
@ -196,13 +200,29 @@ class CesiumUtils {
var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(6); var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(6);
let lng = Number(longitudeString); let lng = Number(longitudeString);
let lat = Number(latitudeString); let lat = Number(latitudeString);
resolve({ lng, lat }); const positions = [lng, lat];
}else{ that.viewer.entities.removeById("theNewPoint");
reject('未获取到坐标'); that.viewer.entities.add({
id: "theNewPoint",
position: cartesian,
point: {
color: Cesium.Color.fromCssColorString('#9cf7e3'),
pixelSize: 10
// heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
}
});
//通过callback函数将数据传递到外部使用
callback(positions);
} }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK); }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}); // });
} }
//销毁监听
static destroyClickToAddPoint(){
this.handler.destroy();
}
//鼠标点击 //鼠标点击
static handleClick() { static handleClick() {
var scene = this.viewer.scene; var scene = this.viewer.scene;