Fix Modify interaction with hitDetection

Hit detection should ignore any RenderFeatures and features not in the configured
source / collection.
This commit is contained in:
Maximilian Krög
2021-04-23 09:39:45 +02:00
parent 863d387927
commit 4e9b89c358
+10 -4
View File
@@ -33,7 +33,7 @@ import {
squaredDistanceToSegment, squaredDistanceToSegment,
} from '../coordinate.js'; } from '../coordinate.js';
import {createEditingStyle} from '../style/Style.js'; import {createEditingStyle} from '../style/Style.js';
import {equals} from '../array.js'; import {equals, includes} from '../array.js';
import {fromCircle} from '../geom/Polygon.js'; import {fromCircle} from '../geom/Polygon.js';
import { import {
fromUserCoordinate, fromUserCoordinate,
@@ -1126,7 +1126,9 @@ class Modify extends PointerInteraction {
); );
}; };
let nodes, hitPointGeometry; /** @type {Array<SegmentData>|undefined} */
let nodes;
let hitPointGeometry;
if (this.hitDetection_) { if (this.hitDetection_) {
const layerFilter = const layerFilter =
typeof this.hitDetection_ === 'object' typeof this.hitDetection_ === 'object'
@@ -1136,12 +1138,16 @@ class Modify extends PointerInteraction {
pixel, pixel,
(feature, layer, geometry) => { (feature, layer, geometry) => {
geometry = geometry || feature.getGeometry(); geometry = geometry || feature.getGeometry();
if (geometry.getType() === GeometryType.POINT) { if (
geometry.getType() === GeometryType.POINT &&
geometry.getCoordinates && // Skip RenderFeature
includes(this.features_.getArray(), feature)
) {
hitPointGeometry = geometry; hitPointGeometry = geometry;
const coordinate = geometry.getCoordinates(); const coordinate = geometry.getCoordinates();
nodes = [ nodes = [
{ {
feature, feature: /** @type {Feature} */ (feature),
geometry, geometry,
segment: [coordinate, coordinate], segment: [coordinate, coordinate],
}, },