Browse Source

嘉定区行政边界线完善配置

ming 3 năm trước cách đây
mục cha
commit
050eb9ee8d
2 tập tin đã thay đổi với 12 bổ sung23 xóa
  1. 0 8
      src/main.js
  2. 12 15
      src/views/home/index.vue

+ 0 - 8
src/main.js

@@ -27,14 +27,6 @@ const app = createApp(App);
 
 import Interface from "../public/InterfaceReturn.json"
 
-// import AMap from "AMap";
-// app.use(AMap)
-// AMap.initAMapApiLoader({
-//     plugin: ['AMap.DistrictSearch']
-
-// })
-
-
 app.config.globalProperties.$Interface = Interface
 app.config.globalProperties.$UCore = UCore;
 app.config.globalProperties.$axios = axios;

+ 12 - 15
src/views/home/index.vue

@@ -109,6 +109,7 @@
     <!-- bottomBox end -->
   </section>
 </template>
+
 <script>
 import statisTop from "./components/statisTop";
 import statisBottom from "./components/statisBottom";
@@ -499,22 +500,18 @@ export default {
       //加载行政区划插件
       if (!this.district) {
         //实例化DistrictSearch
-        // alert(1)
-
+        var that=this
         AMap.plugin("AMap.DistrictSearch", function () {
-          this.district = new AMap.DistrictSearch({
+          that.district = new AMap.DistrictSearch({
             subdistrict: 0, //获取边界不需要返回下级行政区
             extensions: "all", //返回行政区边界坐标组等具体信息
             level: "district", //查询行政级别为 市
           });
-           alert(2)
-           console.log('this.district');
-          console.log(this.district);
 
           //行政区查询
-          this.district.search("嘉定区", function (status, result) {
-            this.map.remove(this.polygons); //清除上次结果
-            this.polygons = [];
+          that.district.search("嘉定区", function (status, result) {
+            that.map.remove(that.polygons); //清除上次结果
+            that.polygons = [];
             var bounds = result.districtList[0].boundaries;
             if (bounds) {
               for (var i = 0, l = bounds.length; i < l; i++) {
@@ -522,15 +519,15 @@ export default {
                 var polygon = new AMap.Polygon({
                   strokeWeight: 1,
                   path: bounds[i],  
-                  fillOpacity:1,
-                  fillColor: "green",
-                  strokeColor: "green",
+                  fillOpacity:.2,
+                  fillColor: "pink",
+                  strokeColor: "pink",
                 });
-                this.polygons.push(polygon);
+                that.polygons.push(polygon);
               }
             }
-            this.map.add(this.polygons);
-            this.map.setFitView(this.polygons); //视口自适应
+            that.map.add(that.polygons);
+            that.map.setFitView(that.polygons); //视口自适应
           });
         });
       }