aur-openlayers 1.0.2 → 1.0.4

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.
@@ -150,6 +150,15 @@ class FlushScheduler {
150
150
  shouldUpgradePolicy(current, next) {
151
151
  return current === 'microtask' && next === 'raf';
152
152
  }
153
+ dispose() {
154
+ if (this.rafId !== null) {
155
+ cancelAnimationFrame(this.rafId);
156
+ this.rafId = null;
157
+ }
158
+ this.scheduledToken++;
159
+ this.queue.clear();
160
+ this.pendingPolicy = null;
161
+ }
153
162
  }
154
163
 
155
164
  const createMapContext = (map, layers, popupHost, scheduler = new FlushScheduler()) => {
@@ -312,22 +321,21 @@ class InteractionManager {
312
321
  const active = {
313
322
  targetKey,
314
323
  startCoordinate: event.coordinate,
324
+ startPixel: event.pixel,
315
325
  lastCoordinate: event.coordinate,
316
326
  lastItem: resolved,
317
327
  moveThrottleMs: translate.moveThrottleMs ?? 0,
328
+ startThresholdPx: Math.max(0, translate.startThresholdPx ?? 1),
329
+ started: false,
318
330
  translate,
319
331
  };
320
332
  this.activeTranslates.set(entry.descriptor.id, active);
321
333
  this.lockDragPan();
322
- if (translate.state) {
323
- this.applyState([resolved], translate.state, true);
324
- }
325
- const handled = translate.onStart
326
- ? this.isHandled(translate.onStart({ item: resolved, ctx: this.ctx, event: translateEvent }))
327
- : false;
328
- active.lastHandled = handled;
329
- if (handled && this.shouldStopPropagation(translate)) {
330
- break;
334
+ if (active.startThresholdPx <= 0) {
335
+ this.startTranslate(entry, active, resolved, event);
336
+ if (active.lastHandled && this.shouldStopPropagation(translate)) {
337
+ break;
338
+ }
331
339
  }
332
340
  }
333
341
  }
@@ -476,7 +484,7 @@ class InteractionManager {
476
484
  this.applyTranslateMove(entry, active, pending);
477
485
  }
478
486
  const resolved = this.resolveTarget(entry, active.targetKey);
479
- if (resolved && translate.onEnd) {
487
+ if (active.started && resolved && translate.onEnd) {
480
488
  const translateEvent = this.createTranslateEvent(event, active.startCoordinate, 'translateend', [resolved]);
481
489
  active.lastHandled = this.isHandled(translate.onEnd({ item: resolved, ctx: this.ctx, event: translateEvent }));
482
490
  }
@@ -1050,6 +1058,19 @@ class InteractionManager {
1050
1058
  }
1051
1059
  return { descriptor, layer, api, index };
1052
1060
  }
1061
+ startTranslate(entry, active, resolved, event) {
1062
+ if (active.started) {
1063
+ return;
1064
+ }
1065
+ active.started = true;
1066
+ if (active.translate.state) {
1067
+ this.applyState([resolved], active.translate.state, true);
1068
+ }
1069
+ const translateEvent = this.createTranslateEvent(event, active.startCoordinate, 'translatestart', [resolved]);
1070
+ active.lastHandled = active.translate.onStart
1071
+ ? this.isHandled(active.translate.onStart({ item: resolved, ctx: this.ctx, event: translateEvent }))
1072
+ : false;
1073
+ }
1053
1074
  applyTranslateMove(entry, active, event) {
1054
1075
  const translate = active.translate;
1055
1076
  const resolved = this.resolveTarget(entry, active.targetKey);
@@ -1062,6 +1083,17 @@ class InteractionManager {
1062
1083
  nextCoordinate[0] - active.lastCoordinate[0],
1063
1084
  nextCoordinate[1] - active.lastCoordinate[1],
1064
1085
  ];
1086
+ if (!active.started) {
1087
+ const currentPixel = event.pixel;
1088
+ const offsetX = currentPixel[0] - active.startPixel[0];
1089
+ const offsetY = currentPixel[1] - active.startPixel[1];
1090
+ const distance = Math.hypot(offsetX, offsetY);
1091
+ if (distance < active.startThresholdPx) {
1092
+ active.lastHandled = false;
1093
+ return;
1094
+ }
1095
+ this.startTranslate(entry, active, resolved, event);
1096
+ }
1065
1097
  active.lastCoordinate = nextCoordinate;
1066
1098
  active.lastItem = resolved;
1067
1099
  const geometry = resolved.feature.getGeometry();
@@ -1075,7 +1107,7 @@ class InteractionManager {
1075
1107
  const translateEvent = this.createTranslateEvent(event, active.startCoordinate, 'translating', [resolved]);
1076
1108
  active.lastHandled = this.isHandled(translate.onChange({ item: resolved, ctx: this.ctx, event: translateEvent }));
1077
1109
  }
1078
- else {
1110
+ else if (!translate.onStart) {
1079
1111
  active.lastHandled = false;
1080
1112
  }
1081
1113
  }
@@ -1311,7 +1343,7 @@ class InteractionManager {
1311
1343
  if (aZ !== bZ) {
1312
1344
  return bZ - aZ;
1313
1345
  }
1314
- return a.index - b.index;
1346
+ return b.index - a.index;
1315
1347
  });
1316
1348
  }
1317
1349
  getHitTolerance(hitTolerance) {
@@ -1504,6 +1536,16 @@ class InteractionManager {
1504
1536
  shouldStopClusterPropagation() {
1505
1537
  return true;
1506
1538
  }
1539
+ dispose() {
1540
+ this.listenerKeys.forEach((key) => Observable.unByKey(key));
1541
+ this.listenerKeys.clear();
1542
+ Array.from(this.nativeModifies.keys()).forEach((id) => this.teardownNativeModify(id));
1543
+ this.hoverItems.clear();
1544
+ this.selectedItems.clear();
1545
+ this.activeTranslates.clear();
1546
+ this.activeModifies.clear();
1547
+ this.enabledState.clear();
1548
+ }
1507
1549
  }
1508
1550
 
1509
1551
  class StyleCache {
@@ -1995,7 +2037,7 @@ class ClusteredVectorLayer extends VectorLayerBase {
1995
2037
  this.layer.setSource(this.clusteringEnabled ? this.clusterSource : this.source);
1996
2038
  }
1997
2039
  setModels(models) {
1998
- this.setModelsInternal(models);
2040
+ super.setModels(models);
1999
2041
  this.scheduleInvalidate();
2000
2042
  }
2001
2043
  setClusteringEnabled(enabled) {
@@ -2224,11 +2266,15 @@ class LayerManager {
2224
2266
  layers = {};
2225
2267
  apis = {};
2226
2268
  interactions;
2269
+ scheduler;
2270
+ popupHost;
2227
2271
  ctx;
2228
2272
  constructor(map, schema) {
2229
2273
  this.map = map;
2230
2274
  const popupHost = schema.options?.popupHost ? new PopupHost(schema.options.popupHost) : undefined;
2231
2275
  const scheduler = new FlushScheduler(schema.options?.scheduler?.policy ?? 'microtask');
2276
+ this.scheduler = scheduler;
2277
+ this.popupHost = popupHost;
2232
2278
  const ctx = createMapContext(this.map, this.apis, popupHost, scheduler);
2233
2279
  this.ctx = ctx;
2234
2280
  schema.layers.forEach((descriptor) => {
@@ -2297,6 +2343,12 @@ class LayerManager {
2297
2343
  refreshEnabled() {
2298
2344
  this.interactions.refreshEnabled();
2299
2345
  }
2346
+ dispose() {
2347
+ this.interactions.dispose();
2348
+ this.popupHost?.dispose();
2349
+ this.scheduler.dispose();
2350
+ Object.values(this.layers).forEach((layer) => this.map.removeLayer(layer));
2351
+ }
2300
2352
  }
2301
2353
 
2302
2354
  /*