maplair 4.2.0 → 4.4.0
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/CHANGELOG.md +106 -8
- package/dist/esm/control/AttributionControl.js +10 -10
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +0 -1
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -1
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +16 -11
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +0 -1
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +13 -9
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +0 -1
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +4 -5
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +3 -2
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/ZoomControl.js +13 -13
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Events.js +4 -2
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Util.js +16 -4
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +55 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +4 -7
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +5 -5
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +4 -6
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +23 -34
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +6 -3
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +2 -2
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +12 -17
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -7
- package/dist/esm/geometry/Transformation.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +1 -1
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +23 -23
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +7 -4
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +11 -6
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +30 -11
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +18 -35
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +2 -2
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +4 -8
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +16 -15
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +6 -7
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +49 -48
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/SvgIcon.js +1 -1
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +18 -16
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +9 -9
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +44 -93
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +8 -7
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +9 -1
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +10 -5
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +10 -11
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.js +19 -26
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +16 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +3 -3
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +6 -9
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +104 -49
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -4
- package/dist/esm/map/MapSync.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +2 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +68 -30
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +3 -5
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +3 -6
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -6
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -4
- package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +8 -20
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +700 -687
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +700 -687
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/en.json +1 -0
- package/package.json +2 -1
- package/src/control/AttributionControl.js +9 -9
- package/src/control/ButtonControl.js +0 -1
- package/src/control/ContextMenu.js +1 -1
- package/src/control/Control.js +13 -16
- package/src/control/FullscreenControl.js +0 -1
- package/src/control/LayersControl.js +14 -10
- package/src/control/RotateControl.js +0 -1
- package/src/control/ScaleControl.js +4 -5
- package/src/control/SideBySideControl.js +4 -2
- package/src/control/ZoomControl.js +10 -13
- package/src/core/Events.js +8 -2
- package/src/core/Util.js +16 -3
- package/src/dom/DomEvent.PointerEvents.js +47 -1
- package/src/dom/DomEvent.js +5 -17
- package/src/dom/DomUtil.js +5 -5
- package/src/dom/Draggable.js +5 -6
- package/src/geo/LatLng.js +22 -36
- package/src/geo/LatLngBounds.js +10 -4
- package/src/geometry/Bounds.js +3 -3
- package/src/geometry/Point.js +18 -26
- package/src/geometry/Transformation.js +1 -8
- package/src/layer/BlanketOverlay.js +1 -1
- package/src/layer/DivOverlay.js +28 -30
- package/src/layer/ImageOverlay.js +9 -7
- package/src/layer/Layer.js +18 -6
- package/src/layer/Popup.js +38 -17
- package/src/layer/Tooltip.js +17 -44
- package/src/layer/VideoOverlay.js +2 -2
- package/src/layer/marker/DivIcon.js +3 -6
- package/src/layer/marker/Icon.js +19 -18
- package/src/layer/marker/Marker.Drag.js +16 -18
- package/src/layer/marker/Marker.js +66 -59
- package/src/layer/marker/SvgIcon.js +1 -1
- package/src/layer/tile/GridLayer.js +21 -23
- package/src/layer/tile/TileLayer.js +17 -14
- package/src/layer/vector/Canvas.js +52 -148
- package/src/layer/vector/Circle.js +14 -9
- package/src/layer/vector/CircleMarker.js +11 -1
- package/src/layer/vector/Path.js +11 -5
- package/src/layer/vector/Polygon.js +11 -10
- package/src/layer/vector/Polyline.js +20 -21
- package/src/layer/vector/Renderer.getRenderer.js +2 -1
- package/src/layer/vector/Renderer.js +21 -3
- package/src/layer/vector/SVG.js +3 -3
- package/src/map/Map.Rotation.js +7 -6
- package/src/map/Map.js +135 -54
- package/src/map/MapSync.js +1 -1
- package/src/map/handler/BoxZoomHandler.js +2 -0
- package/src/map/handler/DisplaceHandler.js +53 -7
- package/src/map/handler/KeyboardHandler.js +5 -10
- package/src/map/handler/PinchZoomHandler.js +3 -3
- package/src/map/handler/ScrollWheelZoomHandler.js +3 -3
- package/src/map/handler/TapDragZoomHandler.js +1 -1
- package/src/map/handler/TapHoldHandler.js +13 -25
- package/src/maplair.css +38 -9
- package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
- package/src/dom/DomEvent.DoubleTap.js +0 -143
package/src/layer/vector/SVG.js
CHANGED
|
@@ -48,7 +48,7 @@ export class SVG extends Renderer {
|
|
|
48
48
|
this._container.setAttribute('pointer-events', 'none');
|
|
49
49
|
|
|
50
50
|
this._rootGroup = SVG.create('g');
|
|
51
|
-
this._container.
|
|
51
|
+
this._container.append(this._rootGroup);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
_destroyContainer() {
|
|
@@ -61,7 +61,7 @@ export class SVG extends Renderer {
|
|
|
61
61
|
const size = super._resizeContainer();
|
|
62
62
|
|
|
63
63
|
// set size of svg-container if changed
|
|
64
|
-
if (!this._svgSize
|
|
64
|
+
if (!this._svgSize?.equals(size)) {
|
|
65
65
|
this._svgSize = size;
|
|
66
66
|
this._container.setAttribute('width', `${size.x}`);
|
|
67
67
|
this._container.setAttribute('height', `${size.y}`);
|
|
@@ -110,7 +110,7 @@ export class SVG extends Renderer {
|
|
|
110
110
|
|
|
111
111
|
_addPath(layer) {
|
|
112
112
|
if (!this._rootGroup) { this._initContainer(); }
|
|
113
|
-
this._rootGroup.
|
|
113
|
+
this._rootGroup.append(layer._path);
|
|
114
114
|
layer.addInteractiveTarget(layer._path);
|
|
115
115
|
}
|
|
116
116
|
|
package/src/map/Map.Rotation.js
CHANGED
|
@@ -173,8 +173,8 @@ const mapRotationMethods = {
|
|
|
173
173
|
// the map pane is wrapped in a pane rotated around the center of the container
|
|
174
174
|
const rotatePane = this._rotatePane = DomUtil.create('div', 'maplair-rotate-pane');
|
|
175
175
|
rotatedMaps.set(rotatePane, this);
|
|
176
|
-
this.
|
|
177
|
-
rotatePane.
|
|
176
|
+
this._mapPane.before(rotatePane);
|
|
177
|
+
rotatePane.append(this._mapPane);
|
|
178
178
|
}
|
|
179
179
|
if (bearing === this.getBearing()) { return; }
|
|
180
180
|
|
|
@@ -292,12 +292,13 @@ const mapRotationMethods = {
|
|
|
292
292
|
|
|
293
293
|
_tryAnimatedPan(center, options) {
|
|
294
294
|
// difference between the new and current centers in pixels
|
|
295
|
-
|
|
295
|
+
// difference in the frame of the map pane, which `_panBy()` moves
|
|
296
|
+
const offset = this.latLngToLayerPoint(center)._subtract(this._getCenterLayerPoint())._round();
|
|
296
297
|
|
|
297
298
|
// don't animate too far unless animate: true specified in options
|
|
298
|
-
if (options?.animate !== true && !this.getSize().contains(offset)) { return false; }
|
|
299
|
+
if (options?.animate !== true && !this.getSize().contains(this._rotateToContainer(offset))) { return false; }
|
|
299
300
|
|
|
300
|
-
this.
|
|
301
|
+
this._panBy(offset, options);
|
|
301
302
|
|
|
302
303
|
return true;
|
|
303
304
|
},
|
|
@@ -880,7 +881,7 @@ const pinchZoomHandlerRotationMethods = {
|
|
|
880
881
|
|
|
881
882
|
cancelAnimationFrame(this._animRequest);
|
|
882
883
|
|
|
883
|
-
const moveFn = map._move.bind(map, this._center, this._zoom, {pinch: true
|
|
884
|
+
const moveFn = map._move.bind(map, this._center, this._zoom, {pinch: true}, undefined);
|
|
884
885
|
this._animRequest = requestAnimationFrame(moveFn.bind(this));
|
|
885
886
|
|
|
886
887
|
e.preventDefault();
|
package/src/map/Map.js
CHANGED
|
@@ -61,7 +61,9 @@ const zoomAnimDuration = 250;
|
|
|
61
61
|
* user tries to pan outside the view. To set the restriction dynamically, use
|
|
62
62
|
* [`setMaxBounds`](#map-setmaxbounds) method.
|
|
63
63
|
* @property {Renderer} [renderer] The default method for drawing vector layers on the
|
|
64
|
-
* map. `SVG`
|
|
64
|
+
* map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
|
|
65
|
+
* instead. Paths in custom panes get their own renderer for that pane, of the same
|
|
66
|
+
* class and with the same options as this one.
|
|
65
67
|
* @property {boolean} [zoomAnimation=true] Whether the map zoom animation is enabled.
|
|
66
68
|
* @property {number} [zoomAnimationThreshold=4] Won't animate zoom if the zoom
|
|
67
69
|
* difference exceeds this value (or 1 if the user prefers
|
|
@@ -149,16 +151,26 @@ const zoomAnimDuration = 250;
|
|
|
149
151
|
/**
|
|
150
152
|
* Options of the `MaplairMap` methods which modify the zoom level and the center.
|
|
151
153
|
* @typedef {object} ZoomPanOptions
|
|
154
|
+
* @property {boolean} [animate] Whether to animate the change: like `ZoomOptions.animate`
|
|
155
|
+
* if the zoom level changes, and like `PanOptions.animate` otherwise. The `zoom` and
|
|
156
|
+
* `pan` options can set it for each case separately.
|
|
157
|
+
* @property {boolean} [reset] If `true`, the view is reset without animation.
|
|
158
|
+
* @property {ZoomOptions} [zoom] Options for the zoom part of the change, taking
|
|
159
|
+
* precedence over `animate`.
|
|
160
|
+
* @property {PanOptions} [pan] Options for the pan part of the change, taking
|
|
161
|
+
* precedence over `animate`.
|
|
152
162
|
* @extends ZoomOptions, PanOptions
|
|
153
163
|
*/
|
|
154
164
|
|
|
155
165
|
/**
|
|
156
166
|
* Options of `MaplairMap.invalidateSize()`.
|
|
157
167
|
* @typedef {object} InvalidateSizeOptions
|
|
168
|
+
* @property {boolean} [animate=false] If `true`, the map pans to its new center with
|
|
169
|
+
* animation.
|
|
158
170
|
* @property {boolean} [pan=true] If `false`, panning will not occur.
|
|
159
171
|
* @property {boolean} [debounceMoveend=false] If `true`, it will delay `moveend` event
|
|
160
172
|
* so that it doesn't happen often even if the method is called many times in a row.
|
|
161
|
-
* @extends
|
|
173
|
+
* @extends PanOptions
|
|
162
174
|
*/
|
|
163
175
|
|
|
164
176
|
/**
|
|
@@ -209,7 +221,9 @@ const zoomAnimDuration = 250;
|
|
|
209
221
|
* pressing a key or clicking a zoom button) have an `originalEvent` property with the
|
|
210
222
|
* DOM event that started the change. It is `undefined` for changes made by code (e.g.
|
|
211
223
|
* `setView()`), which allows to tell them apart, e.g. to avoid feedback loops when
|
|
212
|
-
* synchronizing the view.
|
|
224
|
+
* synchronizing the view. The `move` and `zoom` events also have `flyTo: true` on each
|
|
225
|
+
* [`flyTo`](#map-flyto) animation frame, and `pinch: true` while the user pinch-zooms
|
|
226
|
+
* the map.
|
|
213
227
|
*
|
|
214
228
|
* @example
|
|
215
229
|
* ```js
|
|
@@ -316,6 +330,8 @@ export class MaplairMap extends Evented {
|
|
|
316
330
|
this._handlers = [];
|
|
317
331
|
this._layers = {};
|
|
318
332
|
this._zoomBoundLayers = {};
|
|
333
|
+
// canvas renderers on the map, topmost first
|
|
334
|
+
this._canvases = [];
|
|
319
335
|
this._sizeChanged = true;
|
|
320
336
|
|
|
321
337
|
this._initContainer(id);
|
|
@@ -369,12 +385,22 @@ export class MaplairMap extends Evented {
|
|
|
369
385
|
*/
|
|
370
386
|
setView(center, zoom, options) {
|
|
371
387
|
|
|
372
|
-
zoom = zoom === undefined ? this.
|
|
388
|
+
zoom = zoom === undefined ? this._targetZoom() : this._limitZoom(zoom);
|
|
389
|
+
const targetCenter = center;
|
|
373
390
|
center = this._limitCenter(new LatLng(center), zoom, this.options.maxBounds);
|
|
374
391
|
options ??= {};
|
|
375
392
|
|
|
376
393
|
this._stop();
|
|
377
394
|
|
|
395
|
+
// cleared by the moveend that completes this view, so set it before anything can fire one
|
|
396
|
+
this._targetView = {center: targetCenter, zoom};
|
|
397
|
+
|
|
398
|
+
// the end of a running zoom animation would override the new view, so apply it afterwards
|
|
399
|
+
if (this._animatingZoom) {
|
|
400
|
+
this._pendingView = {center, zoom, options};
|
|
401
|
+
return this;
|
|
402
|
+
}
|
|
403
|
+
|
|
378
404
|
if (this._loaded && !options.reset && options !== true) {
|
|
379
405
|
|
|
380
406
|
if (options.animate !== undefined) {
|
|
@@ -384,7 +410,7 @@ export class MaplairMap extends Evented {
|
|
|
384
410
|
|
|
385
411
|
// try animating pan or zoom
|
|
386
412
|
const moved = (this._zoom !== zoom) ?
|
|
387
|
-
this._tryAnimatedZoom
|
|
413
|
+
this._tryAnimatedZoom?.(center, zoom, options.zoom) :
|
|
388
414
|
this._tryAnimatedPan(center, options.pan);
|
|
389
415
|
|
|
390
416
|
if (moved) {
|
|
@@ -395,7 +421,7 @@ export class MaplairMap extends Evented {
|
|
|
395
421
|
}
|
|
396
422
|
|
|
397
423
|
// animation didn't start, just reset the map view
|
|
398
|
-
this._resetView(center, zoom, options.pan?.noMoveStart);
|
|
424
|
+
this._resetView(this.options.worldCopyJump ? this.wrapLatLng(center) : center, zoom, options.pan?.noMoveStart);
|
|
399
425
|
|
|
400
426
|
return this;
|
|
401
427
|
}
|
|
@@ -412,7 +438,8 @@ export class MaplairMap extends Evented {
|
|
|
412
438
|
this._zoom = zoom;
|
|
413
439
|
return this;
|
|
414
440
|
}
|
|
415
|
-
|
|
441
|
+
// zoom around where a running animation is heading, so that setView(c) then setZoom(z) ends at c
|
|
442
|
+
return this.setView(this._targetView?.center ?? this.getCenter(), zoom, {zoom: options});
|
|
416
443
|
}
|
|
417
444
|
|
|
418
445
|
/**
|
|
@@ -424,7 +451,7 @@ export class MaplairMap extends Evented {
|
|
|
424
451
|
*/
|
|
425
452
|
zoomIn(delta, options) {
|
|
426
453
|
delta ??= this.options.zoomDelta;
|
|
427
|
-
return this.setZoom(this.
|
|
454
|
+
return this.setZoom(this._targetZoom() + delta, options);
|
|
428
455
|
}
|
|
429
456
|
|
|
430
457
|
/**
|
|
@@ -436,7 +463,7 @@ export class MaplairMap extends Evented {
|
|
|
436
463
|
*/
|
|
437
464
|
zoomOut(delta, options) {
|
|
438
465
|
delta ??= this.options.zoomDelta;
|
|
439
|
-
return this.setZoom(this.
|
|
466
|
+
return this.setZoom(this._targetZoom() - delta, options);
|
|
440
467
|
}
|
|
441
468
|
|
|
442
469
|
/**
|
|
@@ -473,7 +500,7 @@ export class MaplairMap extends Evented {
|
|
|
473
500
|
|
|
474
501
|
let zoom = this.getBoundsZoom(bounds, false, paddingTL.add(paddingBR));
|
|
475
502
|
|
|
476
|
-
zoom =
|
|
503
|
+
zoom = Math.min(options.maxZoom ?? Infinity, zoom);
|
|
477
504
|
|
|
478
505
|
if (zoom === Infinity) {
|
|
479
506
|
return {
|
|
@@ -533,7 +560,7 @@ export class MaplairMap extends Evented {
|
|
|
533
560
|
* @returns {this}
|
|
534
561
|
*/
|
|
535
562
|
panTo(center, options) {
|
|
536
|
-
return this.setView(center,
|
|
563
|
+
return this.setView(center, undefined, {pan: options});
|
|
537
564
|
}
|
|
538
565
|
/**
|
|
539
566
|
* Pans the map by a given number of pixels (animated unless `animate: false` is passed,
|
|
@@ -545,27 +572,25 @@ export class MaplairMap extends Evented {
|
|
|
545
572
|
* @returns {this}
|
|
546
573
|
*/
|
|
547
574
|
panBy(offset, options) {
|
|
548
|
-
|
|
575
|
+
// pan from where a running animation is heading, so that panTo(c) then panBy(o) ends at c + o
|
|
576
|
+
const {center = this.getCenter(), zoom = this._zoom} = this._targetView ?? {},
|
|
577
|
+
newCenter = this.unproject(this.project(center, zoom).add(Point.from(offset).round()), zoom);
|
|
578
|
+
|
|
579
|
+
return this.setView(newCenter, zoom, {pan: options});
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// Pans the map pane by `offset` pixels, see `_tryAnimatedPan()`.
|
|
583
|
+
_panBy(offset, options) {
|
|
549
584
|
options ??= {};
|
|
550
585
|
|
|
551
586
|
if (!offset.x && !offset.y) {
|
|
552
|
-
return this.
|
|
553
|
-
}
|
|
554
|
-
// If we pan too far, Chrome gets issues with tiles
|
|
555
|
-
// and makes them disappear or appear in the wrong place (slightly offset) #2602
|
|
556
|
-
const size = this.getSize();
|
|
557
|
-
if (options.animate !== true && !size.contains(offset)) {
|
|
558
|
-
const center = this.unproject(this.project(this.getCenter()).add(offset));
|
|
559
|
-
this._resetView(this.options.worldCopyJump ? this.wrapLatLng(center) : center, this.getZoom());
|
|
560
|
-
return this;
|
|
587
|
+
return this._moveStart(false, true)._moveEnd(false);
|
|
561
588
|
}
|
|
562
589
|
|
|
563
590
|
if (!this._panAnim) {
|
|
564
|
-
this._panAnim = new PosAnimation()
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
'step': this._onPanTransitionStep,
|
|
568
|
-
'end': this._onPanTransitionEnd
|
|
591
|
+
this._panAnim = new PosAnimation().on({
|
|
592
|
+
step: this._onPanTransitionStep,
|
|
593
|
+
end: this._onPanTransitionEnd
|
|
569
594
|
}, this);
|
|
570
595
|
}
|
|
571
596
|
|
|
@@ -575,7 +600,7 @@ export class MaplairMap extends Evented {
|
|
|
575
600
|
}
|
|
576
601
|
|
|
577
602
|
// with reduced motion, only short pans are animated unless animate: true is specified
|
|
578
|
-
const tooFarForReducedMotion = this._prefersReducedMotion() && !
|
|
603
|
+
const tooFarForReducedMotion = this._prefersReducedMotion() && !this.getSize().divideBy(2).contains(offset);
|
|
579
604
|
if (options.animate === true || (options.animate !== false && !tooFarForReducedMotion)) {
|
|
580
605
|
this._mapPane.classList.add('maplair-pan-anim');
|
|
581
606
|
|
|
@@ -584,7 +609,7 @@ export class MaplairMap extends Evented {
|
|
|
584
609
|
} else {
|
|
585
610
|
this._rawPanBy(offset);
|
|
586
611
|
this._wrapWorldCopy();
|
|
587
|
-
this.fire('move').
|
|
612
|
+
this.fire('move')._moveEnd(false);
|
|
588
613
|
}
|
|
589
614
|
|
|
590
615
|
return this;
|
|
@@ -610,11 +635,13 @@ export class MaplairMap extends Evented {
|
|
|
610
635
|
return this.setView(targetCenter, targetZoom, options);
|
|
611
636
|
}
|
|
612
637
|
|
|
613
|
-
this.
|
|
614
|
-
|
|
615
|
-
targetZoom = targetZoom === undefined ? this._zoom : this._limitZoom(targetZoom);
|
|
638
|
+
targetZoom = targetZoom === undefined ? this._targetZoom() : this._limitZoom(targetZoom);
|
|
639
|
+
const requestedCenter = targetCenter;
|
|
616
640
|
targetCenter = this._limitCenter(new LatLng(targetCenter), targetZoom, this.options.maxBounds);
|
|
617
641
|
|
|
642
|
+
this._stop();
|
|
643
|
+
this._targetView = {center: requestedCenter, zoom: targetZoom};
|
|
644
|
+
|
|
618
645
|
const from = this.project(this.getCenter()),
|
|
619
646
|
to = this.project(targetCenter),
|
|
620
647
|
size = this.getSize(),
|
|
@@ -643,7 +670,7 @@ export class MaplairMap extends Evented {
|
|
|
643
670
|
|
|
644
671
|
const start = Date.now(),
|
|
645
672
|
S = (r(1) - r0) / rho,
|
|
646
|
-
duration =
|
|
673
|
+
duration = 1000 * (options.duration || S * 0.8);
|
|
647
674
|
|
|
648
675
|
const frame = () => {
|
|
649
676
|
const t = (Date.now() - start) / duration,
|
|
@@ -852,8 +879,8 @@ export class MaplairMap extends Evented {
|
|
|
852
879
|
|
|
853
880
|
/**
|
|
854
881
|
* Checks if the map container size changed and updates the map if so —
|
|
855
|
-
* call it after you've changed the map size dynamically, also
|
|
856
|
-
*
|
|
882
|
+
* call it after you've changed the map size dynamically, also panning to
|
|
883
|
+
* keep the center by default. If `options.pan` is `false`, panning will not occur.
|
|
857
884
|
* If `options.debounceMoveend` is `true`, it will delay `moveend` event so
|
|
858
885
|
* that it doesn't happen often even if the method is called many
|
|
859
886
|
* times in a row. Passing `true` instead of options animates the panning.
|
|
@@ -872,10 +899,14 @@ export class MaplairMap extends Evented {
|
|
|
872
899
|
|
|
873
900
|
const oldSize = this.getSize();
|
|
874
901
|
this._sizeChanged = true;
|
|
875
|
-
this._lastCenter = null;
|
|
876
902
|
|
|
877
|
-
const newSize = this.getSize()
|
|
878
|
-
|
|
903
|
+
const newSize = this.getSize();
|
|
904
|
+
|
|
905
|
+
// keep the exact center for a no-op call (e.g. the initial resize observer callback), since recomputing
|
|
906
|
+
// it from the pane snaps it to whole pixels
|
|
907
|
+
if (!newSize.equals(oldSize)) { this._lastCenter = null; }
|
|
908
|
+
|
|
909
|
+
const oldCenter = oldSize.divideBy(2).round(),
|
|
879
910
|
newCenter = newSize.divideBy(2).round(),
|
|
880
911
|
offset = oldCenter.subtract(newCenter);
|
|
881
912
|
|
|
@@ -1001,9 +1032,7 @@ export class MaplairMap extends Evented {
|
|
|
1001
1032
|
_handleGeolocationResponse(pos) {
|
|
1002
1033
|
if (!this._container._maplair_id) { return; }
|
|
1003
1034
|
|
|
1004
|
-
const
|
|
1005
|
-
lng = pos.coords.longitude,
|
|
1006
|
-
latlng = new LatLng(lat, lng),
|
|
1035
|
+
const latlng = new LatLng(pos.coords.latitude, pos.coords.longitude),
|
|
1007
1036
|
bounds = latlng.toBounds(pos.coords.accuracy * 2),
|
|
1008
1037
|
options = this._locateOptions;
|
|
1009
1038
|
|
|
@@ -1056,7 +1085,7 @@ export class MaplairMap extends Evented {
|
|
|
1056
1085
|
remove() {
|
|
1057
1086
|
|
|
1058
1087
|
this._initEvents(true);
|
|
1059
|
-
|
|
1088
|
+
this.off('moveend', this._panInsideMaxBounds);
|
|
1060
1089
|
|
|
1061
1090
|
if (this._containerId !== this._container._maplair_id) {
|
|
1062
1091
|
throw new Error('Map container is being reused by another instance');
|
|
@@ -1209,8 +1238,9 @@ export class MaplairMap extends Evented {
|
|
|
1209
1238
|
size = this.getSize().subtract(padding),
|
|
1210
1239
|
boundsSize = new Bounds(this.project(se, zoom), this.project(nw, zoom)).getSize(),
|
|
1211
1240
|
snap = this.options.zoomSnap,
|
|
1212
|
-
|
|
1213
|
-
|
|
1241
|
+
// padding larger than the map leaves no room: zoom out, not in
|
|
1242
|
+
scalex = Math.max(size.x, 0) / boundsSize.x,
|
|
1243
|
+
scaley = Math.max(size.y, 0) / boundsSize.y,
|
|
1214
1244
|
scale = inside ? Math.max(scalex, scaley) : Math.min(scalex, scaley);
|
|
1215
1245
|
|
|
1216
1246
|
zoom = this.getScaleZoom(scale, zoom);
|
|
@@ -1731,6 +1761,9 @@ export class MaplairMap extends Evented {
|
|
|
1731
1761
|
}
|
|
1732
1762
|
|
|
1733
1763
|
_moveEnd(zoomChanged) {
|
|
1764
|
+
// a zoom animation ending with a queued view isn't where the map is heading yet
|
|
1765
|
+
if (!this._pendingView) { this._targetView = null; }
|
|
1766
|
+
|
|
1734
1767
|
if (zoomChanged) {
|
|
1735
1768
|
this.fire('zoomend');
|
|
1736
1769
|
}
|
|
@@ -1739,6 +1772,8 @@ export class MaplairMap extends Evented {
|
|
|
1739
1772
|
}
|
|
1740
1773
|
|
|
1741
1774
|
_stop() {
|
|
1775
|
+
this._pendingView = null;
|
|
1776
|
+
this._targetView = null;
|
|
1742
1777
|
cancelAnimationFrame(this._flyToFrame);
|
|
1743
1778
|
cancelAnimationFrame(this._zoomAnimFrame);
|
|
1744
1779
|
this._panAnim?.stop();
|
|
@@ -1841,15 +1876,17 @@ export class MaplairMap extends Evented {
|
|
|
1841
1876
|
src = e.target,
|
|
1842
1877
|
dragging = false;
|
|
1843
1878
|
const isHover = type === 'pointerout' || type === 'pointerover';
|
|
1879
|
+
// clicks with `detail` 0 come from `element.click()` or the keyboard, so they can't end a drag
|
|
1880
|
+
const canEndDrag = (type === 'click' || type === 'preclick') && e.detail > 0;
|
|
1844
1881
|
|
|
1845
1882
|
while (src) {
|
|
1846
1883
|
target = this._targets[Util.stamp(src)];
|
|
1847
|
-
if (target &&
|
|
1884
|
+
if (target && canEndDrag && this._draggableMoved(target)) {
|
|
1848
1885
|
// Prevent firing click after you just dragged an object.
|
|
1849
1886
|
dragging = true;
|
|
1850
1887
|
break;
|
|
1851
1888
|
}
|
|
1852
|
-
if (target
|
|
1889
|
+
if (target?.listens(type, true)) {
|
|
1853
1890
|
if (isHover && !DomEvent.isExternalTarget(src, e)) { break; }
|
|
1854
1891
|
targets.push(target);
|
|
1855
1892
|
if (isHover) { break; }
|
|
@@ -1872,13 +1909,42 @@ export class MaplairMap extends Evented {
|
|
|
1872
1909
|
|
|
1873
1910
|
_handleDOMEvent(e) {
|
|
1874
1911
|
const el = e.target;
|
|
1875
|
-
if (
|
|
1912
|
+
if (e.type === 'click') { PointerEvents.simulateDblclick(e, this._container); }
|
|
1913
|
+
if (!this._loaded || e.type === 'click' && this._isClickDisabled(el)) {
|
|
1876
1914
|
return;
|
|
1877
1915
|
}
|
|
1878
1916
|
|
|
1879
|
-
|
|
1917
|
+
// canvas elements don't receive pointer events, so hit-test canvas renderers when the event isn't on
|
|
1918
|
+
// an interactive DOM layer, and track hover (cursor, pointerover/out) for canvas layers here
|
|
1919
|
+
const type = e.type,
|
|
1920
|
+
move = type === 'pointermove',
|
|
1921
|
+
hovered = this._hoveredCanvasLayer,
|
|
1922
|
+
skip = type === 'pointerover' || type === 'pointerout' || type.startsWith('key') ||
|
|
1923
|
+
this._animatingZoom || move && this.dragging?.moving(),
|
|
1924
|
+
layer = skip ? undefined : this._canvasLayerAt(e, type === 'click'),
|
|
1925
|
+
leftMap = type === 'pointerout' && !this._container.contains(e.relatedTarget);
|
|
1926
|
+
|
|
1927
|
+
if (layer !== hovered && (move && !skip || leftMap)) {
|
|
1928
|
+
if (hovered) { this._fireDOMEvent(e, 'pointerout', [hovered]); }
|
|
1929
|
+
this._container.classList.toggle('maplair-interactive', !!layer); // change cursor
|
|
1930
|
+
this._hoveredCanvasLayer = layer;
|
|
1931
|
+
if (layer) { this._fireDOMEvent(e, 'pointerover', [layer]); }
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
this._fireDOMEvent(e, type, layer && [layer]);
|
|
1880
1935
|
};
|
|
1881
1936
|
|
|
1937
|
+
_canvasLayerAt(e, click) {
|
|
1938
|
+
// skip events on interactive DOM layers and controls
|
|
1939
|
+
for (let el = e.target; el !== this._container; el = el.parentNode) {
|
|
1940
|
+
if (!el || el === this._controlContainer || this._targets[Util.stamp(el)]) { return; }
|
|
1941
|
+
}
|
|
1942
|
+
for (const renderer of this._canvases) {
|
|
1943
|
+
const layer = renderer._layerAt(e, click);
|
|
1944
|
+
if (layer) { return layer; }
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1882
1948
|
static _pointerEvents = ['click', 'dblclick', 'pointerover', 'pointerout', 'contextmenu'];
|
|
1883
1949
|
|
|
1884
1950
|
_fireDOMEvent(e, type, canvasTargets) {
|
|
@@ -1888,8 +1954,10 @@ export class MaplairMap extends Evented {
|
|
|
1888
1954
|
this._fireDOMEvent(e, 'preclick', canvasTargets);
|
|
1889
1955
|
}
|
|
1890
1956
|
|
|
1891
|
-
// Find the layer the event is propagating from and its parents
|
|
1892
|
-
|
|
1957
|
+
// Find the layer the event is propagating from and its parents
|
|
1958
|
+
// (synthetic canvas hover events don't propagate to DOM layers).
|
|
1959
|
+
const canvasHover = canvasTargets && (type === 'pointerover' || type === 'pointerout');
|
|
1960
|
+
let targets = canvasHover ? [] : this._findEventTargets(e, type);
|
|
1893
1961
|
|
|
1894
1962
|
if (canvasTargets) {
|
|
1895
1963
|
// pick only targets with listeners
|
|
@@ -2056,24 +2124,25 @@ export class MaplairMap extends Evented {
|
|
|
2056
2124
|
_onPanTransitionEnd() {
|
|
2057
2125
|
this._mapPane.classList.remove('maplair-pan-anim');
|
|
2058
2126
|
this._wrapWorldCopy();
|
|
2059
|
-
this.
|
|
2127
|
+
this._moveEnd(false);
|
|
2060
2128
|
}
|
|
2061
2129
|
|
|
2062
2130
|
_tryAnimatedPan(center, options) {
|
|
2063
2131
|
// difference between the new and current centers in pixels
|
|
2064
|
-
|
|
2132
|
+
// rounding the difference keeps a pan exact on maps whose center is between pixels
|
|
2133
|
+
const offset = this.latLngToLayerPoint(center)._subtract(this._getCenterLayerPoint())._round();
|
|
2065
2134
|
|
|
2066
2135
|
// don't animate too far unless animate: true specified in options
|
|
2067
2136
|
if (options?.animate !== true && !this.getSize().contains(offset)) { return false; }
|
|
2068
2137
|
|
|
2069
|
-
this.
|
|
2138
|
+
this._panBy(offset, options);
|
|
2070
2139
|
|
|
2071
2140
|
return true;
|
|
2072
2141
|
}
|
|
2073
2142
|
|
|
2074
2143
|
_createAnimProxy() {
|
|
2075
2144
|
this._proxy = DomUtil.create('div', 'maplair-proxy maplair-zoom-animated');
|
|
2076
|
-
this._panes.mapPane.
|
|
2145
|
+
this._panes.mapPane.append(this._proxy);
|
|
2077
2146
|
|
|
2078
2147
|
this.on('zoomanim', this._animateProxyZoom, this);
|
|
2079
2148
|
this.on('load moveend', this._animMoveEnd, this);
|
|
@@ -2145,6 +2214,10 @@ export class MaplairMap extends Evented {
|
|
|
2145
2214
|
this._flyToFrame = requestAnimationFrame(frame);
|
|
2146
2215
|
}
|
|
2147
2216
|
|
|
2217
|
+
_targetZoom() {
|
|
2218
|
+
return this._targetView?.zoom ?? this._zoom;
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2148
2221
|
// an animated zoom drops zooms from input until it ends, so hold them as long after an instant zoom too,
|
|
2149
2222
|
// or a trackpad swipe or a held key zooms several times as far
|
|
2150
2223
|
_zoomInputBlocked() {
|
|
@@ -2227,7 +2300,8 @@ export class MaplairMap extends Evented {
|
|
|
2227
2300
|
|
|
2228
2301
|
this._animatingZoom = false;
|
|
2229
2302
|
|
|
2230
|
-
|
|
2303
|
+
// a drag during the animation moves the map pane, so the center is read from the pane rather than restored
|
|
2304
|
+
this._move(this.getCenter(), this._animateToZoom, undefined, true);
|
|
2231
2305
|
|
|
2232
2306
|
if (this._tempFireZoomEvent) {
|
|
2233
2307
|
this.fire('zoom');
|
|
@@ -2237,6 +2311,13 @@ export class MaplairMap extends Evented {
|
|
|
2237
2311
|
this.fire('move');
|
|
2238
2312
|
|
|
2239
2313
|
this._moveEnd(true);
|
|
2314
|
+
|
|
2315
|
+
// read after moveend, since its listeners may have queued a newer view or stopped the map
|
|
2316
|
+
const view = this._pendingView;
|
|
2317
|
+
if (view) {
|
|
2318
|
+
this._pendingView = null;
|
|
2319
|
+
this.setView(view.center, view.zoom, view.options);
|
|
2320
|
+
}
|
|
2240
2321
|
}
|
|
2241
2322
|
}
|
|
2242
2323
|
|
package/src/map/MapSync.js
CHANGED
|
@@ -203,7 +203,7 @@ export class MapSync {
|
|
|
203
203
|
}
|
|
204
204
|
} else {
|
|
205
205
|
// zooming frame by frame (pinch, flyTo, continuousZoom) or at the end
|
|
206
|
-
other._move(center, zoom, during ? {pinch: true
|
|
206
|
+
other._move(center, zoom, during ? {pinch: true} : undefined);
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
|
|
@@ -51,6 +51,7 @@ export class BoxZoomHandler extends Handler {
|
|
|
51
51
|
*/
|
|
52
52
|
addHooks() {
|
|
53
53
|
DomEvent.on(this._map._container, 'pointerdown', this._onPointerDown, this);
|
|
54
|
+
this._map._container.classList.add('maplair-box-zoom');
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
/**
|
|
@@ -58,6 +59,7 @@ export class BoxZoomHandler extends Handler {
|
|
|
58
59
|
*/
|
|
59
60
|
removeHooks() {
|
|
60
61
|
DomEvent.off(this._map._container, 'pointerdown', this._onPointerDown, this);
|
|
62
|
+
this._map._container.classList.remove('maplair-box-zoom');
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
/**
|
|
@@ -131,6 +131,8 @@ export class DisplaceHandler extends Handler {
|
|
|
131
131
|
* Called when the handler is enabled, adds the event hooks.
|
|
132
132
|
*/
|
|
133
133
|
addHooks() {
|
|
134
|
+
// see `CircleMarker#beforeAdd`
|
|
135
|
+
this._map._displaceHandler = this;
|
|
134
136
|
this._map.on('zoomend', this.schedule, this);
|
|
135
137
|
this._map.on('layeradd', this._onLayerAdd, this);
|
|
136
138
|
this._map.on('layerremove', this._onLayerRemove, this);
|
|
@@ -143,6 +145,7 @@ export class DisplaceHandler extends Handler {
|
|
|
143
145
|
* true positions of the markers.
|
|
144
146
|
*/
|
|
145
147
|
removeHooks() {
|
|
148
|
+
if (this._map._displaceHandler === this) { delete this._map._displaceHandler; }
|
|
146
149
|
this._map.off('zoomend', this.schedule, this);
|
|
147
150
|
this._map.off('layeradd', this._onLayerAdd, this);
|
|
148
151
|
this._map.off('layerremove', this._onLayerRemove, this);
|
|
@@ -235,6 +238,8 @@ export class DisplaceHandler extends Handler {
|
|
|
235
238
|
* @param {LatLng} latLng
|
|
236
239
|
*/
|
|
237
240
|
_moveTo(marker, latLng) {
|
|
241
|
+
// e.g. already placed by `_beforeMarkerAdd`: spares redrawing every marker
|
|
242
|
+
if (marker.getLatLng().equals(latLng)) { return; }
|
|
238
243
|
this._moving = true;
|
|
239
244
|
try {
|
|
240
245
|
marker.setLatLng(latLng);
|
|
@@ -255,6 +260,20 @@ export class DisplaceHandler extends Handler {
|
|
|
255
260
|
if (this._enabled && this._map.hasLayer(event.target)) { this.schedule(); }
|
|
256
261
|
}
|
|
257
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Called by `CircleMarker#beforeAdd`: puts a marker whose `displaceId` already
|
|
265
|
+
* has a displaced position at the current zoom (e.g. the same station on
|
|
266
|
+
* another layer) there before it is drawn, instead of drawing it twice.
|
|
267
|
+
* @param {CircleMarker} marker
|
|
268
|
+
*/
|
|
269
|
+
_beforeMarkerAdd(marker) {
|
|
270
|
+
if (!displaceable(marker)) { return; }
|
|
271
|
+
this._track(marker);
|
|
272
|
+
const {displaceId} = marker.options;
|
|
273
|
+
const latLng = displaceId && this._displacedPositions.get(this._map.getZoom())?.get(displaceId);
|
|
274
|
+
if (latLng) { this._moveTo(marker, latLng); }
|
|
275
|
+
}
|
|
276
|
+
|
|
258
277
|
/**
|
|
259
278
|
* @param {LayerEvent} event
|
|
260
279
|
*/
|
|
@@ -297,6 +316,11 @@ export class DisplaceHandler extends Handler {
|
|
|
297
316
|
}
|
|
298
317
|
}
|
|
299
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Movement in pixels per pass below which `displace` stops early
|
|
321
|
+
*/
|
|
322
|
+
const MIN_MOVE = 0.01;
|
|
323
|
+
|
|
300
324
|
/**
|
|
301
325
|
* Displaces overlapping points in pixel space until they are at least
|
|
302
326
|
* `minSeparation` apart. Iterative relaxation: every overlapping pair is pushed
|
|
@@ -305,7 +329,8 @@ export class DisplaceHandler extends Handler {
|
|
|
305
329
|
*
|
|
306
330
|
* No point ends up further than `maxDisplacement` away from where it started.
|
|
307
331
|
* Points which hit that limit stay overlapping – the limit wins over the
|
|
308
|
-
* separation.
|
|
332
|
+
* separation. The relaxation stops early once the points are separated or
|
|
333
|
+
* no point moves by more than a hundredth of a pixel per pass.
|
|
309
334
|
*
|
|
310
335
|
* @param {Point[]} points Pixel coordinates (modified in place)
|
|
311
336
|
* @param {number} minSeparation Minimum distance between centers, in pixels
|
|
@@ -333,16 +358,24 @@ export function displace(
|
|
|
333
358
|
dx.fill(0);
|
|
334
359
|
dy.fill(0);
|
|
335
360
|
|
|
336
|
-
// Sort the points into a grid (cell size = separation)
|
|
337
|
-
|
|
361
|
+
// Sort the points into a grid (cell size = separation), keyed by column and
|
|
362
|
+
// then row. Numeric keys instead of a string "x,y" per lookup: the relaxation
|
|
363
|
+
// runs up to `iterations` times over all points and 9 cells each.
|
|
364
|
+
/** @type {Map<number, Map<number, number[]>>} */
|
|
338
365
|
const grid = new Map();
|
|
339
366
|
for (let i = 0; i < n; i++) {
|
|
340
|
-
const
|
|
341
|
-
const
|
|
367
|
+
const cx = Math.floor(points[i].x / cell);
|
|
368
|
+
const cy = Math.floor(points[i].y / cell);
|
|
369
|
+
let column = grid.get(cx);
|
|
370
|
+
if (!column) {
|
|
371
|
+
column = new Map();
|
|
372
|
+
grid.set(cx, column);
|
|
373
|
+
}
|
|
374
|
+
const bucket = column.get(cy);
|
|
342
375
|
if (bucket) {
|
|
343
376
|
bucket.push(i);
|
|
344
377
|
} else {
|
|
345
|
-
|
|
378
|
+
column.set(cy, [i]);
|
|
346
379
|
}
|
|
347
380
|
}
|
|
348
381
|
|
|
@@ -352,8 +385,10 @@ export function displace(
|
|
|
352
385
|
const cy = Math.floor(points[i].y / cell);
|
|
353
386
|
// Only the 3×3 neighbouring cells can be closer than `sep`.
|
|
354
387
|
for (let gx = cx - 1; gx <= cx + 1; gx++) {
|
|
388
|
+
const column = grid.get(gx);
|
|
389
|
+
if (!column) { continue; }
|
|
355
390
|
for (let gy = cy - 1; gy <= cy + 1; gy++) {
|
|
356
|
-
const bucket =
|
|
391
|
+
const bucket = column.get(gy);
|
|
357
392
|
if (!bucket) { continue; }
|
|
358
393
|
for (const j of bucket) {
|
|
359
394
|
if (j <= i) { continue; } // visit every pair once
|
|
@@ -390,7 +425,10 @@ export function displace(
|
|
|
390
425
|
if (overlaps === 0) {
|
|
391
426
|
break; // converged – nothing left to do
|
|
392
427
|
}
|
|
428
|
+
let maxMoveSq = 0;
|
|
393
429
|
for (let i = 0; i < n; i++) {
|
|
430
|
+
const x = points[i].x;
|
|
431
|
+
const y = points[i].y;
|
|
394
432
|
points[i].x += dx[i];
|
|
395
433
|
points[i].y += dy[i];
|
|
396
434
|
|
|
@@ -406,6 +444,14 @@ export function displace(
|
|
|
406
444
|
points[i].x = ax[i] + ox * scale;
|
|
407
445
|
points[i].y = ay[i] + oy * scale;
|
|
408
446
|
}
|
|
447
|
+
const mx = points[i].x - x;
|
|
448
|
+
const my = points[i].y - y;
|
|
449
|
+
maxMoveSq = Math.max(maxMoveSq, mx * mx + my * my);
|
|
450
|
+
}
|
|
451
|
+
// Points held back by `maxDisplacement` keep overlapping, so `overlaps`
|
|
452
|
+
// never drops to 0: stop once no point moves noticeably any more.
|
|
453
|
+
if (maxMoveSq < MIN_MOVE * MIN_MOVE) {
|
|
454
|
+
break;
|
|
409
455
|
}
|
|
410
456
|
}
|
|
411
457
|
|