On a map, I have drew a polygon and I want to popup some information when I click on ONLY boundaries of the polygon. Do you have any solutions to force the selection on boundaries?
var featureContext = new ol.Feature({
geometry: new ol.geom.Polygon([polyCoords])
})
featureContext.setStyle(
new ol.style.Style({
stroke: new ol.style.Stroke({
color: context[cc].displayColor,
width: 3
})
})
);
var layerContext = new ol.layer.Vector({
source: new ol.source.Vector({
features: [featureContext]
})
});
map.addLayer(layerContext);
What I have done right now:
map.on('singleclick', function(evt) {
if (evt.dragging) {
return;
}
var feature = map.forEachFeatureAtPixel(map.getEventPixel(evt.originalEvent), function(feature) {
return feature;
});
if (feature) {
popUp(feature);
}
});
But this will select everything on the polygon (area, etc.) and popup informations in the polygon.
Thanks for your help.
Not optimal but maybe if you draw the boundaries as a line (in addition to polygon) and only accept if feature is a line ? Also add an id in the properties of the line which point to the polygon. There must be some better ways ... but if you have only a few small polygons this is ok.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.