Add Boolean 'isSnapped' to event or anything so you can find out whether a feature has been 'snapped'
See original GitHub issueIs your feature request related to a problem? Please describe. Our markers are styled as a small circle with a text-label. Snap is the only interaction which only matches with the circle/point. interaction/Select or map.getFeatureAtPixel also select a feature when clicking/hovering at the text-label. So far I could not find any other simple solution/workaround for this.
Snap does exactly what we need. Only I could not find how to know if Snap found a feature. For it only changed the pixels/coordinate.
Describe the solution you’d like As far as I can see, adding a boolean parameter to current event would solve this. This could be done in de handleEvent():
Snap.prototype.handleEvent = function handleEvent (evt) {
var result = this.snapTo(evt.pixel, evt.coordinate, evt.map);
evt.isSnapped = false;
if (result.snapped) {
evt.coordinate = result.vertex.slice(0, 2);
evt.pixel = result.vertexPixel;
evt.isSnapped = true;
}
return PointerInteraction.prototype.handleEvent.call(this, evt);
};
Of course it is better if such a boolean is initiated with the event itself, like the boolean ‘dragging’ in the MapBrowserEvent.
Another solution would be a new ‘snapped’ event… but that is more complicated and costs more performance, I think.
Thanks in advance!
Issue Analytics
- State:
- Created 4 years ago
- Comments:18 (18 by maintainers)
Top GitHub Comments
I suggested earlier to do this, only have one source but 2 different layers with different styles (one with labels, one without), which seemed like a “clean” way of handling this. @ahocevar’s suggestion is definitely the most performant though 😉
The render buffer is applied around the canvas where the features are rendered. A little bit hard to explain why it works in your case but basically, when doing hit detection the library will not look too far from the point you have clicked (only a few pixels instead of 100), and as such will not register a hit on the label of the points which are too far from the actual coordinate.
@flexjoly The easiest way to make things work for you would be to configure the vector layer with
renderBuffer: 10
. Replace10
with the half of your maximum point size in pixels. Then labels will no longer be considered for hit detection, and as a bonus you’ll get better hit detection performance.