修改新增点事件逻辑

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

View File

@ -176,12 +176,16 @@ class CesiumUtils {
this.viewer.entities.removeAll();
}
//修改点的位置
static clickToAddPoint(){
return new Promise((resolve, reject) => {
static clickToAddPoint(callback){
//清空之前的handler
if (this.handler) {
this.handler.destroy();
}
// return new Promise((resolve, reject) => {
var scene = this.viewer.scene;
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
this.handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
const that = this;
handler.setInputAction(function (movement) {
this.handler.setInputAction(function (movement) {
// 清除历史单击点
// handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
// movement.position 像素的x、y坐标
@ -196,13 +200,29 @@ class CesiumUtils {
var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(6);
let lng = Number(longitudeString);
let lat = Number(latitudeString);
resolve({ lng, lat });
}else{
reject('未获取到坐标');
const positions = [lng, lat];
that.viewer.entities.removeById("theNewPoint");
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);
});
// });
}
//销毁监听
static destroyClickToAddPoint(){
this.handler.destroy();
}
//鼠标点击
static handleClick() {
var scene = this.viewer.scene;