-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Pass geometry to forEachFeatureAtPixel callback #11781
Conversation
@@ -538,8 +538,7 @@ class PluggableMap extends BaseObject { | |||
* callback with each intersecting feature. Layers included in the detection can | |||
* be configured through the `layerFilter` option in `opt_options`. | |||
* @param {import("./pixel.js").Pixel} pixel Pixel. | |||
* @param {function(this: S, import("./Feature.js").FeatureLike, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description should be updated to include the third geometry parameter.
The FeatueCallback<T>
type is not available for the apidocs, becomes a dead link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally did not document that third parameter, because I am not sure it is relevant for the API. The reason why I added it was to be able to use the Modify interaction with hit detection and geometry collections after #11781, where this third parameter is used internally.
I did update the type to avoid the dead link, so the documentation should now be the same as before this pull request.
const featureCallback = function (feature) { | ||
const featureCallback = function (feature, geometry) { | ||
const key = getUid(feature); | ||
if (!(key in features)) { | ||
features[key] = true; | ||
return callback(feature, layer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The forEachFeatureAtPixel
callback will only be called with the first detected geometry, but multiple geometries of the same feature could be at that pixel.
This should probably also be documented.
I updated the documentation now at least for internal use according to your suggestions. Thanks, @MoonE. |
If this is used with the new layer option of the Modify interaction MutliGeometries will not be supported because there is just one geometry object. Is this expected? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the point in my previous comment is not an issue this looks good to me.
I know it is unfortunate, but it is expected. For geometry collections, this change was a low hanging fruit. For multi geometries, this would be much harder to achieve. |
Working on #11769, I realized that when editing a geometry collection, it is useful to not only get the feature that a hit was detected on, but also the exact geometry from the collection. Since this information is available at the time a hit is detected, this change is only about passing that information all the way to the map's
forEachFeatureAtPixel()
method.