Bläddra i källkod

修复乡镇边界绘画出现多次绘制。实现林场地图访问限制。林场接口联调

wangcc 2 år sedan
förälder
incheckning
077bb03839
1 ändrade filer med 56 tillägg och 56 borttagningar
  1. 56 56
      src/components/amap.vue

+ 56 - 56
src/components/amap.vue

@@ -28,6 +28,7 @@ import {
   farmInfo
 } from '@/service/index.js';
 import { mapMutations, mapState, mapGetters } from 'vuex';
+import { Message } from 'element-ui';
 export default {
   name: 'amap',
   data() {
@@ -62,7 +63,8 @@ export default {
       cityMarkerArr: [],
       putPolygonData: [],
       townPolygons: [],
-      treeCompMarkers: []
+      treeCompMarkers: [],
+      forestFarmData: []
     };
   },
 
@@ -92,6 +94,7 @@ export default {
       handler(val) {
         this.leftPage = val;
         if (this.parentId) {
+          // this.getrjx()
           this.switch2AreaNode(
             this.parentId,
             this.$store.state.addr.mapLevel,
@@ -228,6 +231,7 @@ export default {
             pathArray.push.apply(pathArray, holes);
             that.polygon = new AMap.Polygon({
               pathL: pathArray,
+              map: that.map,
               strokeColor: '#00eeff',
               strokeWeight: 1,
               fillColor: '#0c1b05', // 遮罩背景色
@@ -235,7 +239,7 @@ export default {
               height: 10000
             });
             that.polygon.setPath(pathArray);
-            that.map.add(that.polygon);
+            // that.map.add(that.polygon);
             var cityArr = result.districtList[0].districtList;
             for (let i = 0; i < cityArr.length; i++) {
               that.cityMarker = new AMap.Text({
@@ -299,37 +303,41 @@ export default {
       //feature被点击
       this.districtExplorer.on('featureClick', (e, feature) => {
         const props = feature.properties;
-        mapLevel = props.level;
-        adName = props.name;
-        this.$store.dispatch('searchArea', {
-          parentId: props.adcode,
-          name: props.name,
-          mapLevel: props.level
-        });
-        let valCode = props.adcode + '000000';
-        let areaId = '';
-        this.vuexCityList.forEach((item) => {
-          if (valCode == item.areaCode) {
-            areaId = item.areaId;
-          }
-        });
-        this.vuexDistrictList.forEach((item) => {
-          if (valCode == item.areaCode) {
-            areaId = item.areaId;
+        for (let item of this.forestFarmData) {
+          if (props.name == item.cityName || props.name == item.countyName) {
+            mapLevel = props.level;
+            adName = props.name;
+            this.$store.dispatch('searchArea', {
+              parentId: props.adcode,
+              name: props.name,
+              mapLevel: props.level
+            });
+            let valCode = props.adcode + '000000';
+            let areaId = '';
+            this.vuexCityList.forEach((item) => {
+              if (valCode == item.areaCode) {
+                areaId = item.areaId;
+              }
+            });
+            this.vuexDistrictList.forEach((item) => {
+              if (valCode == item.areaCode) {
+                areaId = item.areaId;
+              }
+            });
+            if (props.level == 'city') {
+              this.changeSelectCity({
+                value: valCode,
+                label: props.name,
+                areaId: areaId
+              });
+            } else if (props.level == 'district') {
+              this.changeSelectDistrict({
+                value: valCode,
+                label: props.name,
+                areaId: areaId
+              });
+            }
           }
-        });
-        if (props.level == 'city') {
-          this.changeSelectCity({
-            value: valCode,
-            label: props.name,
-            areaId: areaId
-          });
-        } else if (props.level == 'district') {
-          this.changeSelectDistrict({
-            value: valCode,
-            label: props.name,
-            areaId: areaId
-          });
         }
       });
       that.getDistrict(adName, mapLevel);
@@ -418,7 +426,6 @@ export default {
         }
         if (mapLevel === 'district') {
           this.getrjx(adcode);
-         
         }
         //设置当前使用的定位用节点
         this.districtExplorer.setAreaNodesForLocating([this.currentAreaNode]);
@@ -550,6 +557,7 @@ export default {
         let lngLat = [item.longitude, item.latitude];
         if (item.longitude && item.latitude) {
           this.forestMarker = new AMap.Marker({
+            map: _this.map,
             position: lngLat,
             icon: sampleIcon,
             anchor: 'bottom-center',
@@ -608,7 +616,7 @@ export default {
               content: `<div class="label-treecomp">${item.treeComp}<span class="smallH">${item.smallNumber}</span></div>` //设置文本标注内容
             });
           }
-          this.map.add(this.forestMarker);
+          // this.map.add(this.forestMarker);
         }
       });
     },
@@ -625,7 +633,7 @@ export default {
           zIndex: 999,
           cursor: 'pointer'
         });
-        this.map.add(polygon);
+        // this.map.add(polygon);
         var lanLatArr = [];
         polygon.on('mouseover', (e) => {
           polygon.setOptions({
@@ -820,7 +828,7 @@ export default {
             fillColor: '#ccebc5'
           });
         });
-        this.map.add(polygon);
+        // this.map.add(polygon);
       });
 
       financeBasePlant({
@@ -870,6 +878,7 @@ export default {
             imageSize: new AMap.Size(iconMeta[0], iconMeta[1]) // 根据所设置的大小拉伸或压缩图片
           });
           let baseMarker = new AMap.Marker({
+            map: this.map,
             position: lanLatArr,
             icon: sampleIcon,
             anchor: 'bottom-center',
@@ -926,11 +935,10 @@ export default {
       });
     },
     setMarker() {
-      let forestFarm = [];
       farmInfo().then((res) => {
-        forestFarm = res.rows;
+        this.forestFarmData = res.rows;
         let parentMarker = require('@/assets/img/pre-marker.png');
-        forestFarm.forEach((item) => {
+        this.forestFarmData.forEach((item) => {
           if (this.$store.state.addr.selectCity.label) {
             if (this.$store.state.addr.selectCity.label == item.cityName) {
               let lngLat = [item.longitude, item.latitude];
@@ -966,14 +974,17 @@ export default {
       });
     },
     getrjx(adcode) {
-      this.putPolygonData = [];
       if (adcode == '522632') {
         axios.get('/static/rongjangintown.json').then((res) => {
-          this.putPolygon(res.data.features);
+          let putPolygonData = [];
+          putPolygonData = res.data.features;
+          this.putPolygon(putPolygonData);
         });
       } else if (adcode == '520181') {
         axios.get('/static/qingzhenzhen.json').then((res) => {
-          this.putPolygon(res.data.features);
+          let qingzhenputPolygonData = [];
+          qingzhenputPolygonData = res.data.features;
+          this.putPolygon(qingzhenputPolygonData);
         });
       }
     },
@@ -990,20 +1001,8 @@ export default {
           zIndex: 999,
           cursor: 'pointer'
         });
-        // polygon.on('mouseover', (e) => {
-        //     polygon.setOptions({
-        //       fillOpacity: 0.7,
-        //       fillColor: '#0dbc79'
-        //     });
-        //   });
-        //   polygon.on('mouseout', (e) => {
-        //     polygon.setOptions({
-        //       fillOpacity: 0,
-        //       fillColor: '#0dbc79'
-        //     });
-        //   });
         that.townPolygons.push(this.boundaryPolygon);
-        that.map.add(that.townPolygons);
+        // that.map.add(that.townPolygons);
 
         this.boundaryPolygon.on('click', (e) => {
           this.smallClassMapArr = [];
@@ -1035,6 +1034,7 @@ export default {
           var pathArray = [outer];
           pathArray.push.apply(pathArray, holes);
           let townPolygon = new AMap.Polygon({
+            map: that.map,
             pathL: pathArray,
             strokeColor: '#00eeff',
             strokeWeight: 1,
@@ -1042,7 +1042,7 @@ export default {
             fillOpacity: 0.8
           });
           townPolygon.setPath(pathArray);
-          that.map.add(townPolygon);
+          // that.map.add(townPolygon);
           that.map.setZoomAndCenter(13, centerLanLatArr, false, 12);
 
           // that.map.setBounds(townPolygon.getBounds(), null, null, true);