From bb3f41765d5410105b0a45175fc83005c687db5a Mon Sep 17 00:00:00 2001 From: dai <851733175@qq.com> Date: Wed, 2 Nov 2022 16:51:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A5=BD=E5=83=8F=E6=98=AF=E5=A5=BD=E4=BA=86?= =?UTF-8?q?=20=E5=9C=B0=E5=9B=BE=E9=A3=9E=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 2 +- src/utils/dai-map.js | 39 +++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/public/index.html b/public/index.html index e099cd9fc..c6e160baa 100644 --- a/public/index.html +++ b/public/index.html @@ -48,7 +48,7 @@ toLoadJs('https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77') } - console.log('============调试版本:1.0.2') + console.log('============调试版本:1.0.3') console.log('nodeEnv', window.SITE_CONFIG['nodeEnv']) diff --git a/src/utils/dai-map.js b/src/utils/dai-map.js index 2f852a730..1d2f4bb07 100644 --- a/src/utils/dai-map.js +++ b/src/utils/dai-map.js @@ -344,31 +344,38 @@ export default function init(ele, position, params) { this.setMarker = function (lat, lng, title = "位置") { lat = parseFloat(lat); lng = parseFloat(lng); + const style = { + externalGraphic: require("@/assets/img/common/map-poi.png"), + graphicWidth: 32, + graphicHeight: 32, + }; if (!this.marker) { //创建矢量图层 - var graphicLayer = new OpenLayers.Layer.Vector("graphicLayer", { + this.markerLayer = new OpenLayers.Layer.Vector("graphicLayer", { style: OpenLayers.Util.extend( {}, OpenLayers.Feature.Vector.style["default"] ), }); - this.map.addLayer(graphicLayer); - let pt = new OpenLayers.Geometry.Point(lng, lat); - var style = { - externalGraphic: require("@/assets/img/common/map-poi.png"), - graphicWidth: 32, - graphicHeight: 32, - }; - var feature = new OpenLayers.Feature.Vector(pt, null, style); - graphicLayer.addFeatures([feature]); - this.marker = feature; - this.markerLayer = graphicLayer; + this.map.addLayer(this.markerLayer); + this.marker = new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.Point(lng, lat), + null, + style + ); + this.markerLayer.addFeatures([this.marker]); } else { console.log("this marker", this.marker); - // this.marker.geometry.x = lng; - // this.marker.geometry.y = lat; - this.marker.geometry = new OpenLayers.Geometry.Point(lng, lat); - + this.marker.geometry.x = 0; + this.marker.geometry.y = 0; + this.marker.geometry.destroy(); + this.markerLayer.removeFeatures([this.marker]); + this.marker = new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.Point(lng, lat), + null, + style + ); + // this.markerLayer.addFeatures([this.marker]); this.markerLayer.redraw(); console.log("redraw", this.marker); }