From 9ecc792eb82c7a94f35ea7f2056567202c6efbff Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Mon, 13 Mar 2023 11:00:19 +0800
Subject: [PATCH] 地图选点方式改变,点击按钮后根据所选行政区跳转

---
 src/components/OpenLayersMap/index.vue |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/components/OpenLayersMap/index.vue b/src/components/OpenLayersMap/index.vue
index 935b320..03ad4d2 100644
--- a/src/components/OpenLayersMap/index.vue
+++ b/src/components/OpenLayersMap/index.vue
@@ -19,7 +19,7 @@
       </div>
     </div>
     <div v-if="!mapLocation.isDetail" style="position: absolute;right:51%;top:7%;z-index: 999999;">
-      <el-button type="info" icon="el-icon-location-outline" circle @click="createPoint"></el-button>
+      <el-button type="info" icon="el-icon-location-outline" circle @click="setCenterByDistrict()"></el-button>
     </div>
   </div>
 </template>
@@ -102,6 +102,8 @@
         if (this.mapLocation.location[0]&&this.mapLocation.location[1]){
           this.setCenter(this.mapLocation.location[0],this.mapLocation.location[1])
         }
+      }else {
+        this.createPoint()
       }
 
     },
@@ -136,7 +138,6 @@
     getLocation(regionCode,regionName){
       this.region = regionCode
       this.regionName = regionName
-      this.setCenterByDistrict(regionName)
     },
     //搜索框选择
     handleSelect(item) {
@@ -156,8 +157,13 @@
       view.setZoom(20);
     },
     //根据区域名设置中心点
-    setCenterByDistrict(regionName){
+    setCenterByDistrict(){
       const that = this
+      let regionName = this.regionName
+      if (regionName.length ==0){
+        this.$message.warning("请先选择行政区");
+        return
+      }
       AMap.plugin('AMap.DistrictSearch', function () {
         // 创建行政区查询对象
         var district = new AMap.DistrictSearch({

--
Gitblit v1.9.3