ol 10.7.1-dev.1763988930570 → 10.7.1-dev.1764255874638
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ol.js +1 -1
- package/dist/ol.js.map +1 -1
- package/interaction/Modify.d.ts +62 -24
- package/interaction/Modify.d.ts.map +1 -1
- package/interaction/Modify.js +210 -50
- package/package.json +1 -1
- package/util.js +1 -1
package/interaction/Modify.d.ts
CHANGED
|
@@ -52,6 +52,11 @@ export type SegmentData = {
|
|
|
52
52
|
*/
|
|
53
53
|
featureSegments?: SegmentData[] | undefined;
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* A function that takes a {@link module :ol/Feature~Feature} and returns `true` if
|
|
57
|
+
* the feature may be modified or `false` otherwise.
|
|
58
|
+
*/
|
|
59
|
+
export type FilterFunction = (arg0: Feature) => boolean;
|
|
55
60
|
export type DragSegment = [SegmentData, number];
|
|
56
61
|
export type Options = {
|
|
57
62
|
/**
|
|
@@ -120,6 +125,10 @@ export type Options = {
|
|
|
120
125
|
* provided, a vector source must be provided with the `source` option.
|
|
121
126
|
*/
|
|
122
127
|
features?: Collection<Feature<import("../geom/Geometry.js").default>> | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* A function that takes a {@link module :ol/Feature~Feature}and returns `true` if the feature may be modified or `false` otherwise.
|
|
130
|
+
*/
|
|
131
|
+
filter?: FilterFunction | undefined;
|
|
123
132
|
/**
|
|
124
133
|
* Trace a portion of another geometry.
|
|
125
134
|
* Tracing starts when two neighboring vertices are dragged onto a trace target, without any other modification in between..
|
|
@@ -189,6 +198,33 @@ declare class Modify extends PointerInteraction {
|
|
|
189
198
|
* @param {Options} options Options.
|
|
190
199
|
*/
|
|
191
200
|
constructor(options: Options);
|
|
201
|
+
/**
|
|
202
|
+
* @param {import("../source/Vector.js").VectorSourceEvent} event Event.
|
|
203
|
+
* @private
|
|
204
|
+
*/
|
|
205
|
+
private handleSourceAdd_;
|
|
206
|
+
/**
|
|
207
|
+
* @param {import("../source/Vector.js").VectorSourceEvent} event Event.
|
|
208
|
+
* @private
|
|
209
|
+
*/
|
|
210
|
+
private handleSourceRemove_;
|
|
211
|
+
/**
|
|
212
|
+
* @param {import("../Collection.js").CollectionEvent} event Event.
|
|
213
|
+
* @private
|
|
214
|
+
*/
|
|
215
|
+
private handleExternalCollectionAdd_;
|
|
216
|
+
/**
|
|
217
|
+
* @param {import("../Collection.js").CollectionEvent} event Event.
|
|
218
|
+
* @private
|
|
219
|
+
*/
|
|
220
|
+
private handleExternalCollectionRemove_;
|
|
221
|
+
/**
|
|
222
|
+
* Listener for features in external source or features collection. Ensures the feature filter
|
|
223
|
+
* is re-run and segment data is updated.
|
|
224
|
+
* @param {import("../events/Event.js").default | import("../Object").ObjectEvent} evt Event.
|
|
225
|
+
* @private
|
|
226
|
+
*/
|
|
227
|
+
private handleFeatureChange_;
|
|
192
228
|
/***
|
|
193
229
|
* @type {ModifyOnSignature<import("../events").EventsKey>}
|
|
194
230
|
*/
|
|
@@ -201,8 +237,6 @@ declare class Modify extends PointerInteraction {
|
|
|
201
237
|
* @type {ModifyOnSignature<void>}
|
|
202
238
|
*/
|
|
203
239
|
un: ModifyOnSignature<void>;
|
|
204
|
-
/** @private */
|
|
205
|
-
private boundHandleFeatureChange_;
|
|
206
240
|
/**
|
|
207
241
|
* @private
|
|
208
242
|
* @type {import("../events/condition.js").Condition}
|
|
@@ -324,7 +358,21 @@ declare class Modify extends PointerInteraction {
|
|
|
324
358
|
*/
|
|
325
359
|
private hitDetection_;
|
|
326
360
|
/**
|
|
327
|
-
*
|
|
361
|
+
* Useful for performance optimization
|
|
362
|
+
* @private
|
|
363
|
+
* @type boolean
|
|
364
|
+
*/
|
|
365
|
+
private filterFunctionWasSupplied_;
|
|
366
|
+
/**
|
|
367
|
+
* @private
|
|
368
|
+
* @type {FilterFunction}
|
|
369
|
+
*/
|
|
370
|
+
private filter_;
|
|
371
|
+
featuresCollection_: Collection<Feature<import("../geom/Geometry.js").default>> | undefined;
|
|
372
|
+
/**
|
|
373
|
+
* Internal features array. When adding or removing features, be sure to use
|
|
374
|
+
* addFeature_()/removeFeature_() so that the the segment index is adjusted.
|
|
375
|
+
* @type {Array<Feature>}
|
|
328
376
|
* @private
|
|
329
377
|
*/
|
|
330
378
|
private features_;
|
|
@@ -351,6 +399,7 @@ declare class Modify extends PointerInteraction {
|
|
|
351
399
|
*/
|
|
352
400
|
setTrace(trace: boolean | import("../events/condition.js").Condition): void;
|
|
353
401
|
/**
|
|
402
|
+
* Called when a feature is added to the internal features collection
|
|
354
403
|
* @param {Feature} feature Feature.
|
|
355
404
|
* @private
|
|
356
405
|
*/
|
|
@@ -362,6 +411,8 @@ declare class Modify extends PointerInteraction {
|
|
|
362
411
|
*/
|
|
363
412
|
private willModifyFeatures_;
|
|
364
413
|
/**
|
|
414
|
+
* Removes a feature from the internal features collection and updates internal state
|
|
415
|
+
* accordingly.
|
|
365
416
|
* @param {Feature} feature Feature.
|
|
366
417
|
* @private
|
|
367
418
|
*/
|
|
@@ -386,30 +437,17 @@ declare class Modify extends PointerInteraction {
|
|
|
386
437
|
*/
|
|
387
438
|
getOverlay(): VectorLayer;
|
|
388
439
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
|
|
392
|
-
private handleSourceAdd_;
|
|
393
|
-
/**
|
|
394
|
-
* @param {import("../source/Vector.js").VectorSourceEvent} event Event.
|
|
395
|
-
* @private
|
|
396
|
-
*/
|
|
397
|
-
private handleSourceRemove_;
|
|
398
|
-
/**
|
|
399
|
-
* @param {import("../Collection.js").CollectionEvent<Feature>} evt Event.
|
|
400
|
-
* @private
|
|
401
|
-
*/
|
|
402
|
-
private handleFeatureAdd_;
|
|
403
|
-
/**
|
|
404
|
-
* @param {import("../events/Event.js").default} evt Event.
|
|
405
|
-
* @private
|
|
440
|
+
* Common handler for event signaling addition of feature to the supplied features source
|
|
441
|
+
* or collection.
|
|
442
|
+
* @param {Feature} feature Feature.
|
|
406
443
|
*/
|
|
407
|
-
|
|
444
|
+
externalAddFeatureHandler_(feature: Feature): void;
|
|
408
445
|
/**
|
|
409
|
-
*
|
|
410
|
-
*
|
|
446
|
+
* Common handler for event signaling removal of feature from the supplied features source
|
|
447
|
+
* or collection.
|
|
448
|
+
* @param {Feature} feature Feature.
|
|
411
449
|
*/
|
|
412
|
-
|
|
450
|
+
externalRemoveFeatureHandler_(feature: Feature): void;
|
|
413
451
|
/**
|
|
414
452
|
* @param {Feature} feature Feature
|
|
415
453
|
* @param {Point} geometry Geometry.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modify.d.ts","sourceRoot":"","sources":["Modify.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Modify.d.ts","sourceRoot":"","sources":["Modify.js"],"names":[],"mappings":"AAyLA;;;;GAIG;AACH;IACE;;;;;;OAMG;IACH,kBANW,eAAe,YACf,UAAU,CAAC,OAAO,CAAC,mBAEnB,OAAO,uBAAuB,EAAE,OAAO,EAmBjD;IAbC;;;;OAIG;IACH,UAHU,UAAU,CAAC,OAAO,CAAC,CAGL;IAExB;;;;OAIG;IACH,iBAHU,OAAO,uBAAuB,EAAE,OAAO,CAGX;CAEzC;;;;;;;;;;aA7Ha,OAAO;;;;cACP,OAAO,2BAA2B,EAAE,OAAO;;;;;;;;aAE3C,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;;;;;;;;;;6BAOrB,CAAS,IAAO,EAAP,OAAO,KAAE,OAAO;0BAIzB,CAAC,WAAW,EAAE,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAkHrB,MAAM,IACN,OAAO,eAAe,EAAE,WAAW,CAAC,OAAO,eAAe,EAAE,UAAU,EAAE,OAAO,oBAAoB,EAAE,OAAO,EAAE,MAAM,CAAC,GACjI,OAAW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;;;OAIG;IACH,iCA4CC;IAED;;;;;OAKG;IACH,8BAmDC;IAED;;;OAGG;IACH,wBAHW,OAAO,kBAAkB,EAAE,UAAU,eACrC,WAAW,QAmFrB;IAiJD;;;OAGG;IACH,2BAGC;IAED;;;OAGG;IACH,8BAuJC;IAED;;;;;OAKG;IACH,sBA8DC;IAED;;;;OAIG;IACH,uBAKC;IAED;;;OAGG;IACH,YAFY,OAAO,kBAAkB,EAAE,UAAU,GAAG,IAAI,CAWvD;IAED;;;;;OAKG;IACH,kBAHY,OAAO,CAyBlB;IAED;;;;;;OAMG;IACH,yBALW,OAAO,kBAAkB,EAAE,UAAU,GAEpC,OAAO,CAoClB;IAED;;;;OAIG;IACH,sBAiHC;IAED;;;;;OAKG;IACH,kBAHY,OAAO,CA2BlB;IAED;;;;;;OAMG;IACH,yBALW,OAAO,kBAAkB,EAAE,UAAU,GAEpC,OAAO,CAiBlB;IAED;;;;OAIG;IACH,gCAIC;IAED;;;;;;OAMG;IACH,8BAeC;CAuDF;yBA1rEwB,qBAAqB;+BAKf,cAAc;wBAbrB,oBAAoB"}
|
package/interaction/Modify.js
CHANGED
|
@@ -5,6 +5,7 @@ import Collection from '../Collection.js';
|
|
|
5
5
|
import CollectionEventType from '../CollectionEventType.js';
|
|
6
6
|
import Feature from '../Feature.js';
|
|
7
7
|
import MapBrowserEventType from '../MapBrowserEventType.js';
|
|
8
|
+
import ObjectEventType from '../ObjectEventType.js';
|
|
8
9
|
import {equals} from '../array.js';
|
|
9
10
|
import {
|
|
10
11
|
closestOnSegment,
|
|
@@ -94,6 +95,12 @@ const ModifyEventType = {
|
|
|
94
95
|
* @property {Array<SegmentData>} [featureSegments] FeatureSegments.
|
|
95
96
|
*/
|
|
96
97
|
|
|
98
|
+
/**
|
|
99
|
+
* A function that takes a {@link module:ol/Feature~Feature} and returns `true` if
|
|
100
|
+
* the feature may be modified or `false` otherwise.
|
|
101
|
+
* @typedef {function(Feature):boolean} FilterFunction
|
|
102
|
+
*/
|
|
103
|
+
|
|
97
104
|
/**
|
|
98
105
|
* @typedef {[SegmentData, number]} DragSegment
|
|
99
106
|
*/
|
|
@@ -144,6 +151,8 @@ const ModifyEventType = {
|
|
|
144
151
|
* @property {Collection<Feature>} [features]
|
|
145
152
|
* The features the interaction works on. If a feature collection is not
|
|
146
153
|
* provided, a vector source must be provided with the `source` option.
|
|
154
|
+
* @property {FilterFunction} [filter] A function that takes a {@link module:ol/Feature~Feature}
|
|
155
|
+
* and returns `true` if the feature may be modified or `false` otherwise.
|
|
147
156
|
* @property {boolean|import("../events/condition.js").Condition} [trace=false] Trace a portion of another geometry.
|
|
148
157
|
* Tracing starts when two neighboring vertices are dragged onto a trace target, without any other modification in between..
|
|
149
158
|
* @property {VectorSource} [traceSource] Source for features to trace. If tracing is active and a `traceSource` is
|
|
@@ -244,6 +253,24 @@ class Modify extends PointerInteraction {
|
|
|
244
253
|
constructor(options) {
|
|
245
254
|
super(/** @type {import("./Pointer.js").Options} */ (options));
|
|
246
255
|
|
|
256
|
+
//Maintain a ref to event handlers for later unregistering
|
|
257
|
+
/** @private */
|
|
258
|
+
this.handleSourceAdd_ = this.handleSourceAdd_.bind(this);
|
|
259
|
+
|
|
260
|
+
/** @private */
|
|
261
|
+
this.handleSourceRemove_ = this.handleSourceRemove_.bind(this);
|
|
262
|
+
|
|
263
|
+
/** @private */
|
|
264
|
+
this.handleExternalCollectionAdd_ =
|
|
265
|
+
this.handleExternalCollectionAdd_.bind(this);
|
|
266
|
+
|
|
267
|
+
/** @private */
|
|
268
|
+
this.handleExternalCollectionRemove_ =
|
|
269
|
+
this.handleExternalCollectionRemove_.bind(this);
|
|
270
|
+
|
|
271
|
+
/** @private */
|
|
272
|
+
this.handleFeatureChange_ = this.handleFeatureChange_.bind(this);
|
|
273
|
+
|
|
247
274
|
/***
|
|
248
275
|
* @type {ModifyOnSignature<import("../events").EventsKey>}
|
|
249
276
|
*/
|
|
@@ -259,9 +286,6 @@ class Modify extends PointerInteraction {
|
|
|
259
286
|
*/
|
|
260
287
|
this.un;
|
|
261
288
|
|
|
262
|
-
/** @private */
|
|
263
|
-
this.boundHandleFeatureChange_ = this.handleFeatureChange_.bind(this);
|
|
264
|
-
|
|
265
289
|
/**
|
|
266
290
|
* @private
|
|
267
291
|
* @type {import("../events/condition.js").Condition}
|
|
@@ -430,46 +454,80 @@ class Modify extends PointerInteraction {
|
|
|
430
454
|
*/
|
|
431
455
|
this.hitDetection_ = null;
|
|
432
456
|
|
|
433
|
-
/**
|
|
457
|
+
/**
|
|
458
|
+
* Useful for performance optimization
|
|
459
|
+
* @private
|
|
460
|
+
* @type boolean
|
|
461
|
+
*/
|
|
462
|
+
this.filterFunctionWasSupplied_ =
|
|
463
|
+
options.filter != undefined ? true : false;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* @private
|
|
467
|
+
* @type {FilterFunction}
|
|
468
|
+
*/
|
|
469
|
+
this.filter_ = options.filter ? options.filter : () => true;
|
|
470
|
+
|
|
471
|
+
if (!(options.features || options.source)) {
|
|
472
|
+
throw new Error(
|
|
473
|
+
'The modify interaction requires features collection or a source',
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
/** @type {Array<Feature>} */
|
|
434
477
|
let features;
|
|
435
478
|
if (options.features) {
|
|
436
|
-
features = options.features;
|
|
479
|
+
features = options.features.getArray();
|
|
480
|
+
//setup listeners on external features collection and features
|
|
481
|
+
options.features.addEventListener(
|
|
482
|
+
CollectionEventType.ADD,
|
|
483
|
+
this.handleExternalCollectionAdd_,
|
|
484
|
+
);
|
|
485
|
+
options.features.addEventListener(
|
|
486
|
+
CollectionEventType.REMOVE,
|
|
487
|
+
this.handleExternalCollectionRemove_,
|
|
488
|
+
);
|
|
489
|
+
//keep ref for unsubscribe on dispose
|
|
490
|
+
this.featuresCollection_ = options.features;
|
|
437
491
|
} else if (options.source) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
492
|
+
features = options.source.getFeatures();
|
|
493
|
+
//setup listeners on external source and features
|
|
494
|
+
options.source.addEventListener(
|
|
441
495
|
VectorEventType.ADDFEATURE,
|
|
442
|
-
this.handleSourceAdd_
|
|
496
|
+
this.handleSourceAdd_,
|
|
443
497
|
);
|
|
444
|
-
|
|
498
|
+
options.source.addEventListener(
|
|
445
499
|
VectorEventType.REMOVEFEATURE,
|
|
446
|
-
this.handleSourceRemove_
|
|
447
|
-
);
|
|
448
|
-
}
|
|
449
|
-
if (!features) {
|
|
450
|
-
throw new Error(
|
|
451
|
-
'The modify interaction requires features, a source or a layer',
|
|
500
|
+
this.handleSourceRemove_,
|
|
452
501
|
);
|
|
502
|
+
//keep ref for unsubscribe on dispose
|
|
503
|
+
this.source_ = options.source;
|
|
453
504
|
}
|
|
505
|
+
features.forEach((feature) => {
|
|
506
|
+
//any modification to the feature requires filter to be re-run
|
|
507
|
+
feature.addEventListener(EventType.CHANGE, this.handleFeatureChange_);
|
|
508
|
+
//prop change handler is only to re-run the filter
|
|
509
|
+
if (this.filterFunctionWasSupplied_) {
|
|
510
|
+
feature.addEventListener(
|
|
511
|
+
ObjectEventType.PROPERTYCHANGE,
|
|
512
|
+
this.handleFeatureChange_,
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
|
|
454
517
|
if (options.hitDetection) {
|
|
455
518
|
this.hitDetection_ = options.hitDetection;
|
|
456
519
|
}
|
|
457
520
|
|
|
458
521
|
/**
|
|
459
|
-
*
|
|
522
|
+
* Internal features array. When adding or removing features, be sure to use
|
|
523
|
+
* addFeature_()/removeFeature_() so that the the segment index is adjusted.
|
|
524
|
+
* @type {Array<Feature>}
|
|
460
525
|
* @private
|
|
461
526
|
*/
|
|
462
|
-
this.features_ =
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
CollectionEventType.ADD,
|
|
467
|
-
this.handleFeatureAdd_.bind(this),
|
|
468
|
-
);
|
|
469
|
-
this.features_.addEventListener(
|
|
470
|
-
CollectionEventType.REMOVE,
|
|
471
|
-
this.handleFeatureRemove_.bind(this),
|
|
472
|
-
);
|
|
527
|
+
this.features_ = [];
|
|
528
|
+
features
|
|
529
|
+
.filter(this.filter_)
|
|
530
|
+
.forEach((feature) => this.addFeature_(feature));
|
|
473
531
|
|
|
474
532
|
/**
|
|
475
533
|
* @type {import("../MapBrowserEvent.js").default}
|
|
@@ -512,10 +570,12 @@ class Modify extends PointerInteraction {
|
|
|
512
570
|
}
|
|
513
571
|
|
|
514
572
|
/**
|
|
573
|
+
* Called when a feature is added to the internal features collection
|
|
515
574
|
* @param {Feature} feature Feature.
|
|
516
575
|
* @private
|
|
517
576
|
*/
|
|
518
577
|
addFeature_(feature) {
|
|
578
|
+
this.features_.push(feature);
|
|
519
579
|
const geometry = feature.getGeometry();
|
|
520
580
|
if (geometry) {
|
|
521
581
|
const writer = this.SEGMENT_WRITERS_[geometry.getType()];
|
|
@@ -527,7 +587,6 @@ class Modify extends PointerInteraction {
|
|
|
527
587
|
if (map && map.isRendered() && this.getActive()) {
|
|
528
588
|
this.handlePointerAtPixel_(this.lastCoordinate_);
|
|
529
589
|
}
|
|
530
|
-
feature.addEventListener(EventType.CHANGE, this.boundHandleFeatureChange_);
|
|
531
590
|
}
|
|
532
591
|
|
|
533
592
|
/**
|
|
@@ -560,20 +619,20 @@ class Modify extends PointerInteraction {
|
|
|
560
619
|
}
|
|
561
620
|
|
|
562
621
|
/**
|
|
622
|
+
* Removes a feature from the internal features collection and updates internal state
|
|
623
|
+
* accordingly.
|
|
563
624
|
* @param {Feature} feature Feature.
|
|
564
625
|
* @private
|
|
565
626
|
*/
|
|
566
627
|
removeFeature_(feature) {
|
|
628
|
+
const itemIndex = this.features_.indexOf(feature);
|
|
629
|
+
this.features_.splice(itemIndex, 1);
|
|
567
630
|
this.removeFeatureSegmentData_(feature);
|
|
568
631
|
// Remove the vertex feature if the collection of candidate features is empty.
|
|
569
|
-
if (this.vertexFeature_ && this.features_.
|
|
632
|
+
if (this.vertexFeature_ && this.features_.length === 0) {
|
|
570
633
|
this.overlay_.getSource().removeFeature(this.vertexFeature_);
|
|
571
634
|
this.vertexFeature_ = null;
|
|
572
635
|
}
|
|
573
|
-
feature.removeEventListener(
|
|
574
|
-
EventType.CHANGE,
|
|
575
|
-
this.boundHandleFeatureChange_,
|
|
576
|
-
);
|
|
577
636
|
}
|
|
578
637
|
|
|
579
638
|
/**
|
|
@@ -646,8 +705,9 @@ class Modify extends PointerInteraction {
|
|
|
646
705
|
* @private
|
|
647
706
|
*/
|
|
648
707
|
handleSourceAdd_(event) {
|
|
649
|
-
|
|
650
|
-
|
|
708
|
+
const feature = event.feature;
|
|
709
|
+
if (feature) {
|
|
710
|
+
this.externalAddFeatureHandler_(feature);
|
|
651
711
|
}
|
|
652
712
|
}
|
|
653
713
|
|
|
@@ -656,37 +716,83 @@ class Modify extends PointerInteraction {
|
|
|
656
716
|
* @private
|
|
657
717
|
*/
|
|
658
718
|
handleSourceRemove_(event) {
|
|
659
|
-
|
|
660
|
-
|
|
719
|
+
const feature = event.feature;
|
|
720
|
+
if (feature) {
|
|
721
|
+
this.externalRemoveFeatureHandler_(feature);
|
|
661
722
|
}
|
|
662
723
|
}
|
|
663
724
|
|
|
664
725
|
/**
|
|
665
|
-
* @param {import("../Collection.js").CollectionEvent
|
|
726
|
+
* @param {import("../Collection.js").CollectionEvent} event Event.
|
|
666
727
|
* @private
|
|
667
728
|
*/
|
|
668
|
-
|
|
669
|
-
|
|
729
|
+
handleExternalCollectionAdd_(event) {
|
|
730
|
+
const feature = event.element;
|
|
731
|
+
if (feature) {
|
|
732
|
+
this.externalAddFeatureHandler_(feature);
|
|
733
|
+
}
|
|
670
734
|
}
|
|
671
735
|
|
|
672
736
|
/**
|
|
673
|
-
* @param {import("../
|
|
737
|
+
* @param {import("../Collection.js").CollectionEvent} event Event.
|
|
674
738
|
* @private
|
|
675
739
|
*/
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
this.
|
|
740
|
+
handleExternalCollectionRemove_(event) {
|
|
741
|
+
const feature = event.element;
|
|
742
|
+
if (feature) {
|
|
743
|
+
this.externalRemoveFeatureHandler_(feature);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Common handler for event signaling addition of feature to the supplied features source
|
|
749
|
+
* or collection.
|
|
750
|
+
* @param {Feature} feature Feature.
|
|
751
|
+
*/
|
|
752
|
+
externalAddFeatureHandler_(feature) {
|
|
753
|
+
feature.addEventListener(EventType.CHANGE, this.handleFeatureChange_);
|
|
754
|
+
//prop change handler is only for reapplying the filter
|
|
755
|
+
if (this.filterFunctionWasSupplied_) {
|
|
756
|
+
feature.addEventListener(
|
|
757
|
+
ObjectEventType.PROPERTYCHANGE,
|
|
758
|
+
this.handleFeatureChange_,
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
if (this.filter_(feature)) {
|
|
680
762
|
this.addFeature_(feature);
|
|
681
763
|
}
|
|
682
764
|
}
|
|
683
765
|
|
|
684
766
|
/**
|
|
685
|
-
*
|
|
767
|
+
* Common handler for event signaling removal of feature from the supplied features source
|
|
768
|
+
* or collection.
|
|
769
|
+
* @param {Feature} feature Feature.
|
|
770
|
+
*/
|
|
771
|
+
externalRemoveFeatureHandler_(feature) {
|
|
772
|
+
feature.removeEventListener(EventType.CHANGE, this.handleFeatureChange_);
|
|
773
|
+
if (this.filterFunctionWasSupplied_) {
|
|
774
|
+
feature.removeEventListener(
|
|
775
|
+
ObjectEventType.PROPERTYCHANGE,
|
|
776
|
+
this.handleFeatureChange_,
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
this.removeFeature_(feature);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Listener for features in external source or features collection. Ensures the feature filter
|
|
784
|
+
* is re-run and segment data is updated.
|
|
785
|
+
* @param {import("../events/Event.js").default | import("../Object").ObjectEvent} evt Event.
|
|
686
786
|
* @private
|
|
687
787
|
*/
|
|
688
|
-
|
|
689
|
-
this.
|
|
788
|
+
handleFeatureChange_(evt) {
|
|
789
|
+
if (!this.changingFeature_) {
|
|
790
|
+
const feature = /** @type {Feature} */ (evt.target);
|
|
791
|
+
this.removeFeature_(feature);
|
|
792
|
+
//safe to remove handler on a feature if there isn't one, but need to apply the filter
|
|
793
|
+
// before adding the feature.
|
|
794
|
+
this.filter_(feature) && this.addFeature_(feature);
|
|
795
|
+
}
|
|
690
796
|
}
|
|
691
797
|
|
|
692
798
|
/**
|
|
@@ -1615,7 +1721,7 @@ class Modify extends PointerInteraction {
|
|
|
1615
1721
|
geom &&
|
|
1616
1722
|
geom.getType() === 'Point' &&
|
|
1617
1723
|
feature instanceof Feature &&
|
|
1618
|
-
this.features_.
|
|
1724
|
+
this.features_.includes(feature)
|
|
1619
1725
|
) {
|
|
1620
1726
|
hitPointGeometry = /** @type {Point} */ (geom);
|
|
1621
1727
|
const coordinate = /** @type {Point} */ (feature.getGeometry())
|
|
@@ -2112,6 +2218,60 @@ class Modify extends PointerInteraction {
|
|
|
2112
2218
|
},
|
|
2113
2219
|
);
|
|
2114
2220
|
}
|
|
2221
|
+
|
|
2222
|
+
/**
|
|
2223
|
+
* @override
|
|
2224
|
+
*/
|
|
2225
|
+
disposeInternal() {
|
|
2226
|
+
super.disposeInternal();
|
|
2227
|
+
if (this.featuresCollection_) {
|
|
2228
|
+
this.featuresCollection_.removeEventListener(
|
|
2229
|
+
CollectionEventType.ADD,
|
|
2230
|
+
this.handleExternalCollectionAdd_,
|
|
2231
|
+
);
|
|
2232
|
+
this.featuresCollection_.removeEventListener(
|
|
2233
|
+
CollectionEventType.REMOVE,
|
|
2234
|
+
this.handleExternalCollectionRemove_,
|
|
2235
|
+
);
|
|
2236
|
+
//change and propertychange event handlers were placed on all features in the external
|
|
2237
|
+
// collection, not just the ones that passed the filter. Remove these too.
|
|
2238
|
+
for (const feature of this.featuresCollection_.getArray()) {
|
|
2239
|
+
feature.removeEventListener(
|
|
2240
|
+
EventType.CHANGE,
|
|
2241
|
+
this.handleFeatureChange_,
|
|
2242
|
+
);
|
|
2243
|
+
if (this.filterFunctionWasSupplied_) {
|
|
2244
|
+
feature.removeEventListener(
|
|
2245
|
+
ObjectEventType.PROPERTYCHANGE,
|
|
2246
|
+
this.handleFeatureChange_,
|
|
2247
|
+
);
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
} else if (this.source_) {
|
|
2251
|
+
this.source_.removeEventListener(
|
|
2252
|
+
VectorEventType.ADDFEATURE,
|
|
2253
|
+
this.handleSourceAdd_,
|
|
2254
|
+
);
|
|
2255
|
+
this.source_.removeEventListener(
|
|
2256
|
+
VectorEventType.REMOVEFEATURE,
|
|
2257
|
+
this.handleSourceRemove_,
|
|
2258
|
+
);
|
|
2259
|
+
//change and propertychange event handlers were placed on all features in the source, not
|
|
2260
|
+
// just the ones that passed the filter. Remove these too.
|
|
2261
|
+
for (const feature of this.source_.getFeatures()) {
|
|
2262
|
+
feature.removeEventListener(
|
|
2263
|
+
EventType.CHANGE,
|
|
2264
|
+
this.handleFeatureChange_,
|
|
2265
|
+
);
|
|
2266
|
+
if (this.filterFunctionWasSupplied_) {
|
|
2267
|
+
feature.removeEventListener(
|
|
2268
|
+
ObjectEventType.PROPERTYCHANGE,
|
|
2269
|
+
this.handleFeatureChange_,
|
|
2270
|
+
);
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2115
2275
|
}
|
|
2116
2276
|
|
|
2117
2277
|
/**
|
package/package.json
CHANGED
package/util.js
CHANGED