When hit detected, only consider hit node

This commit is contained in:
Andreas Hocevar
2020-12-06 12:07:36 +01:00
parent 630a72f222
commit 44e054d528
+12 -5
View File
@@ -1113,7 +1113,7 @@ class Modify extends PointerInteraction {
); );
}; };
let box, hitPointGeometry; let nodes, hitPointGeometry;
if (this.hitDetection_) { if (this.hitDetection_) {
const layerFilter = const layerFilter =
typeof this.hitDetection_ === 'object' typeof this.hitDetection_ === 'object'
@@ -1125,25 +1125,32 @@ class Modify extends PointerInteraction {
geometry = geometry || feature.getGeometry(); geometry = geometry || feature.getGeometry();
if (geometry.getType() === GeometryType.POINT) { if (geometry.getType() === GeometryType.POINT) {
hitPointGeometry = geometry; hitPointGeometry = geometry;
box = hitPointGeometry.getExtent(); const coordinate = geometry.getCoordinates();
nodes = [
{
feature,
geometry,
segment: [coordinate, coordinate],
},
];
} }
return true; return true;
}, },
{layerFilter} {layerFilter}
); );
} }
if (!box) { if (!nodes) {
const viewExtent = fromUserExtent( const viewExtent = fromUserExtent(
createExtent(pixelCoordinate, tempExtent), createExtent(pixelCoordinate, tempExtent),
projection projection
); );
const buffer = map.getView().getResolution() * this.pixelTolerance_; const buffer = map.getView().getResolution() * this.pixelTolerance_;
box = toUserExtent( const box = toUserExtent(
bufferExtent(viewExtent, buffer, tempExtent), bufferExtent(viewExtent, buffer, tempExtent),
projection projection
); );
nodes = this.rBush_.getInExtent(box);
} }
const nodes = this.rBush_.getInExtent(box);
if (nodes && nodes.length > 0) { if (nodes && nodes.length > 0) {
const node = nodes.sort(sortByDistance)[0]; const node = nodes.sort(sortByDistance)[0];