Browse Source

好像是好了 地图飞点

dev-烟台中转登录
dai 3 years ago
parent
commit
bb3f41765d
  1. 2
      public/index.html
  2. 39
      src/utils/dai-map.js

2
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'])
</script>
</head>

39
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);
}

Loading…
Cancel
Save