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