Reputation: 1277
I have located a point on a map
var layer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [
new ol.Feature({
geometry: new ol.geom.Point(ol.proj.fromLonLat(cord)),
label: 'Label'
})
]
}),
style: (feature) => {
myStyle.getText().setText(feature.get('label'));
return [myStyle];
}
});
I just wanted to make a link to the label (or the point) that takes me to another page. Any help.
Upvotes: 3
Views: 737
Reputation: 38431
Put a click event handler on your map and use getFeaturesAtPixel
to find the feature (if any) that has been clicked on. For example:
map.on("click", (event) => {
const features = map.getFeaturesAtPixel(event.pixel);
if (features && features.length > 0) {
// ...
}
});
Upvotes: 2