From 8b8f88d7d8d713a1355d9849f467e3a2dc0c22fe Mon Sep 17 00:00:00 2001
From: Surpriseplus <845948745@qq.com>
Date: 星期二, 05 九月 2023 14:50:26 +0800
Subject: [PATCH] 配置文件修改

---
 src/assets/js/Map/olMap.js |   54 ++++++++++++++++++++++++++++--------------------------
 1 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/src/assets/js/Map/olMap.js b/src/assets/js/Map/olMap.js
index 5b90955..1c0fdbb 100644
--- a/src/assets/js/Map/olMap.js
+++ b/src/assets/js/Map/olMap.js
@@ -1,6 +1,6 @@
 import { getToken } from "@/utils/auth";
 //閰嶇疆鏂囦欢鍦板潃
-import config from "./config";
+import config from "../../../../public/config/config";
 import { Map, View } from "ol"; //鍦板浘,瑙嗗浘
 import OSM from "ol/source/OSM"; //鍙互鐞嗚В涓烘暟鎹簮,灏辨槸涓�寮犲浘鐗�
 import TileLayer from "ol/layer/Tile"; //鍙互鐞嗚В涓哄浘灞�
@@ -10,14 +10,16 @@
 import WMTSTileGrid from "ol/tilegrid/WMTS.js";
 import { get as getProjection, Projection } from "ol/proj.js";
 import { register } from "ol/proj/proj4";
-
+import MousePosition from "ol/control/MousePosition.js";
 import { getTopLeft, getWidth } from "ol/extent.js";
+import { format } from "ol/coordinate";
+import store from "@/store";
 const olMap = {
   map: null,
   Layer: null,
   projectionObj: {
-    code: "ESRI:103881",
-    extent: [-180, -90, 180, 90],
+    code: null,
+    extent: null,
   },
   initMap() {
     //google鍦板浘
@@ -31,10 +33,21 @@
     //   "+proj=laea +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +R=1737400 +units=m +no_defs +type=crs"
     // );
     // register(proj4);
+    let mousePositionControl = new MousePosition({
+      coordinateFormat: (coordinate) => {
+        store.state.olLon = coordinate[0].toFixed(6)
+        store.state.olLat = coordinate[1].toFixed(6);
+        if (this.map) {
+          store.state.olZoom = parseInt(this.map.getView().getZoom())
+        }
+      },
+      projection: this.projectionObj.code,
+      target: 'mouse',
+    });
     const projection = new Projection({
       // code: this.projectionObj.code,
-      code: "ESRI:103881",
-      extent: [-180, -90, 180, 90],
+      code: this.projectionObj.code,
+      extent: this.projectionObj.extent,
       //   extent: this.projectionObj.extent,
     });
     this.map = new Map({
@@ -42,15 +55,15 @@
       layers: [], //AMapLayer, baiduMapLayer
       view: new View({
         projection: projection,
-        center: [180, 90],
+        center: [0, 0],
         zoom: 4,
       }),
+      controls: [mousePositionControl]
     });
   },
   addTreeData(treeNode, obj) {
     // this.delLayerAll();
     this.projectionObj = obj;
-    console.log(this.projectionObj);
     //鍒ゆ柇鏄惁涓轰唬鐞�
     if (treeNode.proxy) {
       this.addProxyAddress(treeNode); //鏈変唬鐞�
@@ -164,8 +177,13 @@
       code: this.projectionObj.code,
       // extent: this.projectionObj.extent,
       // code: "ESRI:103879",
-      extent: [-180, -90, 180, 90],
+      extent: this.projectionObj.extent,
     });
+
+    if (this.map) {
+      this.map.values_.view.projection_ = projection
+    }
+
     // var projection = getProjection("ESRI:103880");
     var projectionExtent = projection.getExtent();
 
@@ -196,27 +214,11 @@
     });
     if (this.map) {
       this.map.addLayer(this.Layer);
-      var that = this;
-      window.olMap = this.map;
-      window.layer = this.Layer
-      setTimeout(() => {
-        that.getLayersExtent();
-      }, 1000)
-      // this.Layer.getSource().on('addfeature', function () {
-      //   this.map.getView().fit(this.Layer.getSource().getExtent());
-      // });
-
+      this.map.getView().fit(this.projectionObj.extent);
 
     }
   },
-  getLayersExtent() {
-    // 缂╂斁鑷冲浘灞傝寖鍥�
 
-    this.map.getView().fit(this.Layer.renderer_.renderedExtent_);
-
-
-
-  }
 
 };
 export default olMap;

--
Gitblit v1.9.3