Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Last SnapTo Feature #14675

Closed
fmg-lydonchandra opened this issue Apr 16, 2023 · 5 comments · Fixed by #14676
Closed

Return Last SnapTo Feature #14675

fmg-lydonchandra opened this issue Apr 16, 2023 · 5 comments · Fixed by #14676

Comments

@fmg-lydonchandra
Copy link
Contributor

fmg-lydonchandra commented Apr 16, 2023

Is your feature request related to a problem? Please describe.
ol.interaction.Snap to return last snapTo feature.
see https://stackoverflow.com/questions/32194030/how-to-get-feature-which-is-snaped-by-ol-interaction-snap

Describe the solution you'd like
ol.interaction.Snap to return last snapTo feature alongside existing result object

return {
            vertex: closestVertex,
            vertexPixel: [
              Math.round(vertexPixel[0]),
              Math.round(vertexPixel[1]),
            ],
            feature: closestFeature,
          };
@mike-000
Copy link
Contributor

As you suggested in Stack Overflow you can use forEachFeatureAtPixel. That could be done in a condition function for any interaction, as well as drawstart and drawend, and done using only documented API methods as in https://codesandbox.io/s/draw-and-modify-features-forked-enrgqv?file=/main.js If the Snap interaction was constructed with features: snapFeatures instead of source: snapSource just replace snapSource.getFeatures().includes with snapFeatures.getArray().includes.

@ahocevar
Copy link
Member

ahocevar commented May 8, 2023

I think the best way to add an API for getting information about what was snapped would be a new Snap event, dispatched by the Snap interaction, in its handleEvent function when there is a result. The event could have the desired vertex, vertexPixel and feature properties.

@fmg-lydonchandra
Copy link
Contributor Author

hi @ahocevar & @mike-000 feedback / review please, #14676

@fmg-lydonchandra
Copy link
Contributor Author

hi @ahocevar , PR re-review please #14676

@fmg-lydonchandra
Copy link
Contributor Author

hi @ahocevar , PR re-review please #14676

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants