Report features actually being modified, not all

This commit is contained in:
Andreas Hocevar
2020-11-24 22:43:16 +01:00
parent b3bcfb5b41
commit 6874bfaaef
2 changed files with 38 additions and 16 deletions

View File

@@ -248,10 +248,10 @@ class Modify extends PointerInteraction {
this.ignoreNextSingleClick_ = false; this.ignoreNextSingleClick_ = false;
/** /**
* @type {boolean} * @type {Array<Feature>}
* @private * @private
*/ */
this.modified_ = false; this.featuresBeingModified_ = null;
/** /**
* Segment RTree for each layer * Segment RTree for each layer
@@ -403,14 +403,27 @@ class Modify extends PointerInteraction {
} }
/** /**
* @param {import("../MapBrowserEvent.js").default} evt Map browser event * @param {import("../MapBrowserEvent.js").default} evt Map browser event.
* @param {Array<Array<SegmentData>>} segments The segments subject to modification.
* @private * @private
*/ */
willModifyFeatures_(evt) { willModifyFeatures_(evt, segments) {
if (!this.modified_) { if (!this.featuresBeingModified_) {
this.modified_ = true; this.featuresBeingModified_ = [];
const features = this.featuresBeingModified_;
for (let i = 0, ii = segments.length; i < ii; ++i) {
const feature = segments[i][0].feature;
if (features.indexOf(feature) === -1) {
features.push(feature);
}
}
this.dispatchEvent( this.dispatchEvent(
new ModifyEvent(ModifyEventType.MODIFYSTART, this.features_, evt) new ModifyEvent(
ModifyEventType.MODIFYSTART,
new Collection(features),
evt
)
); );
} }
} }
@@ -811,7 +824,7 @@ class Modify extends PointerInteraction {
*/ */
handleDragEvent(evt) { handleDragEvent(evt) {
this.ignoreNextSingleClick_ = false; this.ignoreNextSingleClick_ = false;
this.willModifyFeatures_(evt); this.willModifyFeatures_(evt, this.dragSegments_);
const vertex = [ const vertex = [
evt.coordinate[0] + this.delta_[0], evt.coordinate[0] + this.delta_[0],
@@ -914,7 +927,7 @@ class Modify extends PointerInteraction {
const pixelCoordinate = evt.coordinate; const pixelCoordinate = evt.coordinate;
this.handlePointerAtPixel_(evt.pixel, evt.map, pixelCoordinate); this.handlePointerAtPixel_(evt.pixel, evt.map, pixelCoordinate);
this.dragSegments_.length = 0; this.dragSegments_.length = 0;
this.modified_ = false; this.featuresBeingModified_ = null;
const vertexFeature = this.vertexFeature_; const vertexFeature = this.vertexFeature_;
if (vertexFeature) { if (vertexFeature) {
const projection = evt.map.getView().getProjection(); const projection = evt.map.getView().getProjection();
@@ -995,7 +1008,7 @@ class Modify extends PointerInteraction {
} }
if (insertVertices.length) { if (insertVertices.length) {
this.willModifyFeatures_(evt); this.willModifyFeatures_(evt, [insertVertices]);
} }
for (let j = insertVertices.length - 1; j >= 0; --j) { for (let j = insertVertices.length - 1; j >= 0; --j) {
@@ -1044,11 +1057,15 @@ class Modify extends PointerInteraction {
this.rBush_.update(boundingExtent(segmentData.segment), segmentData); this.rBush_.update(boundingExtent(segmentData.segment), segmentData);
} }
} }
if (this.modified_) { if (this.featuresBeingModified_) {
this.dispatchEvent( this.dispatchEvent(
new ModifyEvent(ModifyEventType.MODIFYEND, this.features_, evt) new ModifyEvent(
ModifyEventType.MODIFYEND,
new Collection(this.featuresBeingModified_),
evt
)
); );
this.modified_ = false; this.featuresBeingModified_ = null;
} }
return false; return false;
} }
@@ -1269,12 +1286,16 @@ class Modify extends PointerInteraction {
this.lastPointerEvent_.type != MapBrowserEventType.POINTERDRAG this.lastPointerEvent_.type != MapBrowserEventType.POINTERDRAG
) { ) {
const evt = this.lastPointerEvent_; const evt = this.lastPointerEvent_;
this.willModifyFeatures_(evt); this.willModifyFeatures_(evt, this.dragSegments_);
const removed = this.removeVertex_(); const removed = this.removeVertex_();
this.dispatchEvent( this.dispatchEvent(
new ModifyEvent(ModifyEventType.MODIFYEND, this.features_, evt) new ModifyEvent(
ModifyEventType.MODIFYEND,
new Collection(this.featuresBeingModified_),
evt
)
); );
this.modified_ = false; this.featuresBeingModified_ = null;
return removed; return removed;
} }
return false; return false;

View File

@@ -562,6 +562,7 @@ describe('ol.interaction.Modify', function () {
let modify, feature, events; let modify, feature, events;
beforeEach(function () { beforeEach(function () {
features.push(new Feature(new Point([12, 34])));
modify = new Modify({ modify = new Modify({
features: new Collection(features), features: new Collection(features),
}); });