Browse Source

缩小地图返回上一层

wangcc 2 years ago
parent
commit
b3c427e3b3
1 changed files with 60 additions and 43 deletions
  1. 60 43
      src/components/amap.vue

+ 60 - 43
src/components/amap.vue

@@ -108,11 +108,11 @@ export default {
         this.map.remove(this.polygon);
         this.map.setCity(val.label);
         // that.map.setZoomAndCenter(13, centerLanLatArr, false, 12);
-        this.$store.dispatch('getSmallClassMap', {
-          cityId: this.$store.state.addr.selectCity.areaId,
-          countyId: this.$store.state.addr.selectDistrict.areaId,
-          townId: this.$store.state.addr.selectStreet.areaId
-        });
+        // this.$store.dispatch('getSmallClassMap', {
+        //   cityId: this.$store.state.addr.selectCity.areaId,
+        //   countyId: this.$store.state.addr.selectDistrict.areaId,
+        //   townId: this.$store.state.addr.selectStreet.areaId
+        // });
         // that.map.setBounds(townPolygon.getBounds(), null, null, true);
         console.log(this.leftPage);
         if (this.leftPage === 'forest') {
@@ -326,7 +326,7 @@ export default {
           terrain: true,
           zoom: _this.zoom, //初始化地图级别
           center: _this.lngLat, //初始化地图中心点位置
-          pitch: 30,
+          pitch: 45,
           // layers: [
           //   new AMap.TileLayer.Satellite(),
           //   new AMap.TileLayer.RoadNet()
@@ -507,38 +507,50 @@ export default {
           }
         }
       });
-      console.log(this.$store.state.addr.selectCity);
-      // this.map.on('mousewheel', (e) => {
-      //   console.log(e.lnglat.lng, e.lnglat.lat);
-      //   var zoom = this.map.getZoom(); //获取当前地图级别
-      //   if (zoom > '11.8' && zoom < '12.1') {
-      //     if (this.districtData.value) {
-      //       let districtCode = this.districtData.value.substring(0, 6);
-      //       this.$store.dispatch('searchArea', {
-      //         parentId: districtCode,
-      //         name: this.districtData.label,
-      //         mapLevel: 'district'
-      //       });
-      //     }
-      //   }
-      //   if (zoom > '9' && zoom < '9.2') {
-      //     if (this.selectData.value) {
-      //       let districtCode = this.selectData.value.substring(0, 6);
-      //       this.$store.dispatch('searchArea', {
-      //         parentId: districtCode,
-      //         name: this.selectData.label,
-      //         mapLevel: 'city'
-      //       });
-      //     }
-      //   }
-      //   if (zoom > '7.6' && zoom < '7.9') {
-      //     this.$store.dispatch('searchArea', {
-      //       parentId: '520000',
-      //       name: '贵州省',
-      //       mapLevel: 'province'
-      //     });
-      //   }
-      // });
+      console.log(this.map.getZoom());
+      this.map.on('mousewheel', (e) => {
+        //   console.log(e.lnglat.lng, e.lnglat.lat);
+        var zoom = this.map.getZoom(); //获取当前地图级别
+        if (
+          zoom > '10.5' &&
+          zoom < '11' &&
+          this.$store.state.addr.mapLevel == 'street'
+        ) {
+          if (this.districtData.value) {
+            let districtCode = this.districtData.value.substring(0, 6);
+            this.$store.dispatch('searchArea', {
+              parentId: districtCode,
+              name: this.districtData.label,
+              mapLevel: 'district'
+            });
+          }
+        }
+        if (
+          zoom > '9' &&
+          zoom < '9.5' &&
+          this.$store.state.addr.mapLevel == 'district'
+        ) {
+          if (this.selectData.value) {
+            let districtCode = this.selectData.value.substring(0, 6);
+            this.$store.dispatch('searchArea', {
+              parentId: districtCode,
+              name: this.selectData.label,
+              mapLevel: 'city'
+            });
+          }
+        }
+        if (
+          zoom > '7.6' &&
+          zoom < '7.9' &&
+          this.$store.state.addr.mapLevel == 'city'
+        ) {
+          this.$store.dispatch('searchArea', {
+            parentId: '520000',
+            name: '贵州省',
+            mapLevel: 'province'
+          });
+        }
+      });
       that.getDistrict(adName, mapLevel);
       this.switch2AreaNode(adcode);
     },
@@ -1274,6 +1286,11 @@ export default {
             areaId: areaId
           });
           this.changeSelectAddr('street');
+          this.$store.dispatch('searchArea', {
+            parentId: valCode,
+            name: label,
+            mapLevel: 'street'
+          });
           console.log(this.streetData);
           var outer = [
             new AMap.LngLat(-360, 90, true),
@@ -1295,11 +1312,11 @@ export default {
           townPolygon.setPath(holes);
           // that.map.add(townPolygon);
           that.map.setZoomAndCenter(13, centerLanLatArr, false, 12);
-          this.$store.dispatch('getSmallClassMap', {
-            cityId: this.$store.state.addr.selectCity.areaId,
-            countyId: this.$store.state.addr.selectDistrict.areaId,
-            townId: this.$store.state.addr.selectStreet.areaId
-          });
+          // this.$store.dispatch('getSmallClassMap', {
+          //   cityId: this.$store.state.addr.selectCity.areaId,
+          //   countyId: this.$store.state.addr.selectDistrict.areaId,
+          //   townId: this.$store.state.addr.selectStreet.areaId
+          // });
           // that.map.setBounds(townPolygon.getBounds(), null, null, true);
           console.log(this.leftPage);
           if (this.leftPage === 'forest') {