浏览代码

定位拾取

qinhouyu 8 月之前
父节点
当前提交
0f8035017a
共有 1 个文件被更改,包括 35 次插入11 次删除
  1. 35 11
      screen-demo/src/views/templateInstance.vue

+ 35 - 11
screen-demo/src/views/templateInstance.vue

@@ -344,19 +344,43 @@ export default {
       this.open=true
       this.setpoint()
     },
+    MercatorToWGS84(coords) {
+      const originShift = Math.PI * 6378137;
+      const lon = (coords[0] / originShift) * 180;
+      let lat = (coords[1] / originShift) * 180;
+      lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
+      return [lon, lat];
+    },
     setpoint(){
-      const location = new CTMapOl.extend.ToolLocation(this.map.map, {
-        onPick: coords => {
-          console.log("1",coords)
-          if (this.start){
-            this.end = [coords[0],coords[1]]
-          }else {
-            this.start = [coords[0],coords[1]]
+      let location = null
+      if (this.mapType === "3D") {
+        location = new CTMapOl.extend.ToolLocation(this.map, {
+          onPick: coords => {
+            let wgs8s = this.MercatorToWGS84(coords)
+            if (this.start){
+              this.end = wgs8s
+            }else {
+              this.start = wgs8s
+            }
           }
-        }
-      })
+        })
+      } else {
+        location = new CTMapOl.extend.ToolLocation(this.map.map, {
+          onPick: coords => {
+            let wgs8s = this.MercatorToWGS84(coords)
+            if (this.start){
+              this.end = wgs8s
+            }else {
+              this.start = wgs8s
+            }
+          }
+        })
+      }
+
+
       location._draw.overlay_.setStyle(null) //
       location.pick() //
+
       const onClickMap = this.map.on('click', evt => {
         console.log("2",evt.coordinate)
       })
@@ -419,7 +443,7 @@ export default {
       if (this.num===1){this.echarts2q(names1,values1)}
     },
     echarts1q(){
-      const result = {
+      let result = {
         "code": 200,
         "msg": "请求成功",
         "time": 1691406303301,
@@ -1796,7 +1820,7 @@ export default {
         this.markPoints = res.data;
         // 添加打点
         if (this.map) {
-          if (this.mapType === "3D" || this.mapType === "2D") {
+          if (this.mapType === "3D") {
             this.addPoint3D(this.map);
           } else {
             this.addPoint(this.map.map);