Skip to content

Commit d5e5f7e

Browse files
committed
refactor(pickFeaturesAt): avoid picking twice the same featureGeometry
1 parent 1131abe commit d5e5f7e

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/Core/View.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,9 @@ class View extends THREE.EventDispatcher {
836836
}
837837

838838
/**
839-
* Searches for {@link Feature} in {@link ColorLayer}, under the mouse of at
840-
* a specified coordinates, in this view.
839+
* Searches for {@link FeatureGeometry} in {@link ColorLayer}, under the mouse or at
840+
* the specified coordinates, in this view. Combining them per layer and in a Feature
841+
* like format.
841842
*
842843
* @param {Object} mouseOrEvt - Mouse position in window coordinates (from
843844
* the top left corner of the window) or `MouseEvent` or `TouchEvent`.
@@ -847,10 +848,15 @@ class View extends THREE.EventDispatcher {
847848
* into. If not specified, all {@link ColorLayer} and {@link GeometryLayer}
848849
* layers of this view will be looked in.
849850
*
850-
* @return {Object} - An object, with a property per layer. For example,
851-
* looking for features on layers `wfsBuilding` and `wfsRoads` will give an
852-
* object like `{ wfsBuilding: [...], wfsRoads: [] }`. Each property is made
853-
* of an array, that can be empty or filled with found features.
851+
* @return {Object} - An object, having one property per layer.
852+
* For example, looking for features on layers `wfsBuilding` and `wfsRoads`
853+
* will give an object like `{ wfsBuilding: [...], wfsRoads: [] }`.
854+
* Each property is made of an array, that can be empty or filled with
855+
* Feature like objects composed of:
856+
* - the FeatureGeometry
857+
* - the feature type
858+
* - the style
859+
* - the coordinate if the FeatureGeometry is a point
854860
*
855861
* @example
856862
* view.pickFeaturesAt({ x, y });
@@ -924,8 +930,12 @@ class View extends THREE.EventDispatcher {
924930

925931
precision = CRS.isMetricUnit(texture.features.crs) ? precisions.M : precisions.D;
926932

927-
result[materialLayer.id] = result[materialLayer.id].concat(
928-
FeaturesUtils.filterFeaturesUnderCoordinate(coordinates, texture.features, precision));
933+
const featuresUnderCoor = FeaturesUtils.filterFeaturesUnderCoordinate(coordinates, texture.features, precision);
934+
featuresUnderCoor.forEach((feature) => {
935+
if (!result[materialLayer.id].find(f => f.geometry === feature.geometry)) {
936+
result[materialLayer.id].push(feature);
937+
}
938+
});
929939
}
930940
}
931941
}

0 commit comments

Comments
 (0)