I'm trying to add a new marker on the map in the coordinates that the user select by doubleclick on the map. I read lot of documentation online but my evt.coordinate is undefined. There is the code
this.map.getViewport().addEventListener("dblclick", function(evt) {
this.addMarker(evt.coordinate)
}.bind(this));
MyClientLibrary.prototype.addMarker= function(coordinates) {
console.log(coordinates);
var marker = new OpenLayers.Feature(new OpenLayers.geom.Point(coordinates));
var zIndex = 1;
marker.setStyle(new OpenLayers.style.Style({
image: new OpenLayers.style.Icon(({
anchor: [0.5, 36],
anchorXUnits: "fraction",
anchorYUnits: "pixels",
opacity: 1,
src: "mapIcons/pinother.png",
zIndex: zIndex
})),
zIndex: zIndex
}));
vectorSource.addFeature(marker);
}
How can I do? Thanks.