question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Boolean 'isSnapped' to event or anything so you can find out whether a feature has been 'snapped'

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
jahowcommented, Oct 3, 2019

There is actually another possibility to work around this if you have for example lines or polygons: you could have the same features in 2 different sources and have different styles on them, one for the hit detection and the other for the labels.

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 😉

From this documentation I would think that a hit-circle of 100 pixel is set around the pixel-coordinate. But that is not the case, for it is possible to click between a point/circle and textlabel, without selecting the feature.

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.

2reactions
ahocevarcommented, Oct 1, 2019

@flexjoly The easiest way to make things work for you would be to configure the vector layer with renderBuffer: 10. Replace 10 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenLayers v5.3.2 API - Class: Modify
A function that takes an module:ol/MapBrowserEvent~MapBrowserEvent and returns a boolean to indicate whether a new vertex can be added to the sketch features....
Read more >
Reference.IsBroken property (Access) - Microsoft Learn
The IsBroken property returns a Boolean value indicating whether a Reference object points to a valid reference in the Windows Registry. Read- ...
Read more >
Library functions available for Node.js canary scripts
Explains the built-in functions included in CloudWatch Synthetics that you can use to write your own canary scripts in Node.js.
Read more >
Guidelines for State Machines and XState | Kyle Shevlin
A light bulb typically has two states: lit and unlit . When we have two states, we are often tempted to represent this...
Read more >
Unit 2 Lab 3: Tools and Techniques, Page 1
Predicates are blocks that always report a Boolean value (either true ... Determine what each of these Boolean expressions will report (without using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found