How to get Feature which is snaped by ol.interaction snap?
Asked Answered
H

1

8

I used ol.interaction.snap but i want to get feature which point was snaped?

 snapInteraction = new ol.interaction.Snap({
        source: Source.stationSource
    });

because of no event i can not get which point is snaped

Horseleech answered 25/8, 2015 at 1:8 Comment(4)
What you ask is currently not supported in OL3. I pull request would be appreciated.Adversity
The Snap interaction modifies event coordinates when snapping, so the interactions you use in conjunction with Snap are the ones you want to configure to reveal the snapped features. If you provide a bit more context (i.e. show how you use the Snap interaction in conjunction with other interaction), it will be easier to point you to a solution.Pennon
@AlexandreDubé I was searching for a solution of this problem in a newer version of OL (v6) and came up to this post. Do you have an idea how to get the feature which was snaped by snap interaction?Heimdall
@Pennon is there a better way to get snapped features for draw interaction ? draw.on('drawstart', (evt) => { const featuresAtPixel = map.getFeaturesAtPixel(evt.target.downPx_) console.log('drawstart', evt, featuresAtPixel); })Mi
M
0

For draw interaction snapping, one way is getFeaturesAtPixel, where pixel is evt.target.downPx_

draw.on('drawstart', (evt) => {
  const featuresAtPixel = map.getFeaturesAtPixel(evt.target.downPx_)          
  console.log('drawstart', evt, featuresAtPixel);
})
Mi answered 12/4, 2023 at 13:0 Comment(3)
is there a better way to get snapped features for draw interaction @Pennon ?Mi
Using private properties (downPx_ in this case) is never a good idea. I'd say getting the last snapped feature from the Snap interaction is a missing feature, which could easily be implemented if someone is up for creating a pull request. The first step would be to create an issue on github.com/openlayers/openlayers.Pennon
thanks @Pennon github.com/openlayers/openlayers/issues/14675Mi

© 2022 - 2024 — McMap. All rights reserved.