maxiaoxiao 9 meses atrás
pai
commit
81ad2886e5
2 arquivos alterados com 34 adições e 32 exclusões
  1. 28 0
      src/utils/help.js
  2. 6 32
      src/views/remote/farmland/index.vue

+ 28 - 0
src/utils/help.js

@@ -0,0 +1,28 @@
+import WebGLTile from "ol/layer/WebGLTile";
+import GeoTIFF from "ol/source/GeoTIFF";
+export function removeWebGLTile(name) {
+  console.log(name);
+  const allLayers = window.map[name].getLayers().getArray();
+  allLayers.forEach((layer) => {
+    if (layer instanceof WebGLTile) {
+      window.map[name].removeLayer(layer);
+    }
+  });
+  console.log(window.map[name].getLayers().getArray(), name);
+}
+export function addTiff(name, url) {
+  const source = new GeoTIFF({
+    sources: [
+      {
+        url,
+        nodata: 0,
+        imageExtent: [38.207187, 106.672957, 38.21268, 106.67845],
+        projection: "EPSG:4326",
+      },
+    ],
+  });
+  const layer = new WebGLTile({
+    source: source,
+  });
+  window.map[name].addLayer(layer);
+}

+ 6 - 32
src/views/remote/farmland/index.vue

@@ -102,9 +102,8 @@ import ImageLayer from "ol/layer/Image";
 import ImageStatic from "ol/source/ImageStatic";
 import Draw from "ol/interaction/Draw";
 import GeoJSON from "ol/format/GeoJSON";
-import GeoTIFF from "ol/source/GeoTIFF";
-import WebGLTile from "ol/layer/WebGLTile";
 import { transform } from "@/utils/transformUtils";
+import { removeWebGLTile, addTiff } from "@/utils/help";
 
 export default {
   components: {
@@ -147,46 +146,21 @@ export default {
 
   methods: {
     tableClick(row) {
-      this.removeWebGLTile("mapCon1");
-      this.removeWebGLTile("mapCon2");
+      removeWebGLTile("mapCon1");
+      removeWebGLTile("mapCon2");
       let urlQsx = this.newObj.proxypath + row.qsxtif;
       let urlHsx = this.newObj.proxypath + row.hsxtif;
       if (this.nowId != row.id) {
         this.maptype = "split";
         this.nowId = row.id;
-        this.addLayer("mapCon1", urlQsx);
-        this.addLayer("mapCon2", urlHsx);
+        addTiff("mapCon1", urlQsx);
+        addTiff("mapCon2", urlHsx);
       } else {
         this.maptype = "normal";
         this.nowId = "";
       }
     },
-    removeWebGLTile(name) {
-      console.log(name);
-      const allLayers = window.map[name].getLayers().getArray();
-      allLayers.forEach((layer) => {
-        if (layer instanceof WebGLTile) {
-          window.map[name].removeLayer(layer);
-        }
-      });
-      console.log(window.map[name].getLayers().getArray(), name);
-    },
-    addLayer(name, url) {
-      const source = new GeoTIFF({
-        sources: [
-          {
-            url,
-            nodata: 0,
-            imageExtent: [38.207187, 106.672957, 38.21268, 106.67845],
-            projection: "EPSG:4326",
-          },
-        ],
-      });
-      const layer = new WebGLTile({
-        source: source,
-      });
-      window.map[name].addLayer(layer);
-    },
+
     getList() {
       listPcsjXQList(this.queryParams).then((response) => {
         this.tableData = response.rows;