From 9accd1e41ec57265ce5b6d9be1db12647c6e9fb0 Mon Sep 17 00:00:00 2001 From: mengfanliang Date: Mon, 19 Aug 2024 17:27:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=89=A9=E8=B5=84?= =?UTF-8?q?=E8=A3=85=E5=A4=87=E5=BA=93=E7=9A=84=E5=9C=B0=E5=9B=BE=E6=89=8E?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource_management/util/getPoint.vue | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/views/emergen_cyrescue/resource_management/util/getPoint.vue b/src/views/emergen_cyrescue/resource_management/util/getPoint.vue index ad3401b..fef076c 100644 --- a/src/views/emergen_cyrescue/resource_management/util/getPoint.vue +++ b/src/views/emergen_cyrescue/resource_management/util/getPoint.vue @@ -95,18 +95,33 @@ export default { var geolocation = new BMap.Geolocation() const myGeo = new BMap.Geocoder() var $this = this + map.enableScrollWheelZoom(true) // 开启鼠标滚轮缩放,默认关闭 + map.addEventListener('zoomend', () => { + this.addPoint({ + LATITUDE: $this.LATITUDE, + LONGITUDE: $this.LONGITUDE, + BMap, + map + }) + }) // 调用百度地图api 中的获取当前位置接口 geolocation.getCurrentPosition(function(r) { myGeo.getLocation(new BMap.Point(r.point.lng, r.point.lat), function(result) { if (result) { $this.ISLOADingMap = false $this.$set($this, 'pointLngLat', { lng: result.point.lng, lat: result.point.lat }) - map.enableScrollWheelZoom(true) // 开启鼠标滚轮缩放,默认关闭 - $this.setCenter({ BMap, map }) + $this.setCenter({ BMap, map, zoom: 15 }) // 设置中心点 } }) }) }, + addPoint({ LATITUDE, LONGITUDE, BMap, map }) { + if (!LATITUDE) throw new Error('请传入经度') + if (!LONGITUDE) throw new Error('请传入纬度') + const point = new BMap.Point(LONGITUDE, LATITUDE) + const marker = new BMap.Marker(point) // 创建标注 + map.addOverlay(marker) // 将标注添加到地图中 + }, // 搜索地图 querySearch(queryString, cb) { var options = { @@ -139,7 +154,7 @@ export default { this.LATITUDE = point.lat }, // 设置打开中心位置 - setCenter({ BMap, map }) { + setCenter({ BMap, map, zoom }) { var lng = '' var lat = '' if (this.LONGITUDE === '' || this.LATITUDE === '') { @@ -149,11 +164,11 @@ export default { lng = this.LONGITUDE lat = this.LATITUDE } - var point = new BMap.Point(lng, lat) - const zoom = map.getZoom() + map.panTo(new BMap.Point(lng, lat)) + // 延迟设置缩放级别,确保中心点已经设置 setTimeout(() => { - map.centerAndZoom(point, zoom) - }, 0) + map.setZoom(15) // 设置适当的缩放级别 + }, 300) // 延迟时间可以根据实际需求调整 }, getClickInfo(e) { this.LONGITUDE = e.point.lng