Skip to content

Instantly share code, notes, and snippets.

@EdoardoVignati
Last active April 26, 2022 21:55
Show Gist options
  • Save EdoardoVignati/83a125b30546bf26d4ac28000863dfc5 to your computer and use it in GitHub Desktop.
Save EdoardoVignati/83a125b30546bf26d4ac28000863dfc5 to your computer and use it in GitHub Desktop.
JS OpenLayers intercept click on marker and get coordinates with button cursor.
map.on("singleclick", function(e) {
feature = map.forEachFeatureAtPixel(e.pixel, function(feature) {
return feature;
});
var coord = feature.getGeometry().getCoordinates();
coord = ol.proj.transform(coord,"EPSG:3857","EPSG:4326");
console.log(coord);
});
map.on("pointermove", function (evt) {
var hit = this.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
return true;
});
if (hit) {
this.getTargetElement().style.cursor = "pointer";
} else {
this.getTargetElement().style.cursor = "";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment