maplair 4.0.0 → 4.1.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 +118 -0
- package/dist/esm/Maplair.js +14 -14
- package/dist/esm/control/AttributionControl.js +24 -14
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +9 -11
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -3
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +9 -16
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +5 -7
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +144 -35
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +7 -9
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +14 -16
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +1 -3
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -9
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +99 -17
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +1 -3
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +5 -7
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +408 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +5 -7
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -37
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +21 -8
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +13 -11
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/Util.js +13 -1
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +8 -42
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +14 -68
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +17 -18
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +3 -25
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +15 -5
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3395.js +1 -1
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +1 -1
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +1 -1
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +2 -2
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +36 -30
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +8 -27
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +6 -8
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +15 -20
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/GeoJSON.js +9 -145
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +75 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +15 -17
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +20 -26
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +8 -10
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +51 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +26 -42
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +2 -5
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +15 -17
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +12 -15
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +15 -48
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +7 -9
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +7 -10
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +1 -2
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +61 -33
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +6 -8
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +85 -97
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +28 -36
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +1 -3
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +2 -2
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +17 -7
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +27 -20
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +20 -4
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
- package/dist/esm/layer/vector/Polyline.js +23 -7
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +5 -5
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +10 -6
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +116 -110
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +6 -8
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +19 -19
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +35 -35
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +12 -5
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +8009 -7369
- 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 +10040 -9381
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +148 -98
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/cs.json +6 -0
- package/i18n/de.json +6 -0
- package/i18n/en.json +6 -0
- package/i18n/es.json +6 -0
- package/i18n/fr.json +6 -0
- package/i18n/hu.json +6 -0
- package/i18n/it.json +6 -0
- package/i18n/rm.json +6 -0
- package/i18n/sk.json +6 -0
- package/i18n/sl.json +6 -0
- package/package.json +9 -11
- package/src/control/AttributionControl.js +25 -18
- package/src/control/ButtonControl.js +9 -11
- package/src/control/ContextMenu.js +3 -5
- package/src/control/Control.js +9 -19
- package/src/control/FullscreenControl.js +5 -7
- package/src/control/LayersControl.js +159 -36
- package/src/control/LegendControl.js +7 -9
- package/src/control/MiniMapControl.js +9 -11
- package/src/control/RotateControl.js +3 -5
- package/src/control/ScaleControl.js +7 -9
- package/src/control/SearchControl.js +102 -19
- package/src/control/SideBySideControl.js +3 -5
- package/src/control/TextControl.js +5 -7
- package/src/control/TimeControl.js +471 -0
- package/src/control/ZoomControl.js +5 -7
- package/src/control/index.js +1 -0
- package/src/core/Class.js +35 -34
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +14 -12
- package/src/core/Util.js +19 -1
- package/src/core/index.js +0 -1
- package/src/dom/DomEvent.DoubleTap.js +18 -10
- package/src/dom/DomEvent.PointerEvents.js +3 -26
- package/src/dom/DomEvent.js +8 -66
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +27 -22
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +20 -3
- package/src/geo/crs/EPSG3395.js +1 -1
- package/src/geo/crs/EPSG3857.js +1 -1
- package/src/geo/crs/EPSG4326.js +1 -1
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +1 -1
- package/src/geo/projection/Projection.LonLat.js +1 -1
- package/src/geo/projection/Projection.Mercator.js +1 -1
- package/src/geo/projection/Projection.SphericalMercator.js +1 -1
- package/src/geometry/LineUtil.js +47 -48
- package/src/geometry/PolyUtil.js +14 -43
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +15 -26
- package/src/layer/GeoJSON.js +7 -205
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +9 -11
- package/src/layer/ImageOverlay.js +19 -30
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +71 -0
- package/src/layer/Popup.js +28 -43
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +15 -19
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +15 -61
- package/src/layer/marker/DivIcon.js +9 -11
- package/src/layer/marker/Icon.js +7 -10
- package/src/layer/marker/Marker.Drag.js +1 -1
- package/src/layer/marker/Marker.Move.js +1 -2
- package/src/layer/marker/Marker.js +81 -39
- package/src/layer/marker/MarkerClusterGroup.js +370 -0
- package/src/layer/marker/SvgIcon.js +7 -9
- package/src/layer/marker/index.js +1 -0
- package/src/layer/tile/GridLayer.js +103 -133
- package/src/layer/tile/TileLayer.js +35 -43
- package/src/layer/tile/WMSTileLayer.js +26 -24
- package/src/layer/vector/Canvas.js +3 -5
- package/src/layer/vector/Circle.js +5 -2
- package/src/layer/vector/CircleMarker.js +17 -6
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +28 -5
- package/src/layer/vector/Polyline.js +25 -6
- package/src/layer/vector/Renderer.getRenderer.js +17 -17
- package/src/layer/vector/SVG.js +5 -5
- package/src/map/Map.Rotation.js +12 -4
- package/src/map/Map.js +142 -133
- package/src/map/handler/BoxZoomHandler.js +9 -8
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +25 -28
- package/src/map/handler/KeyboardHandler.js +42 -48
- package/src/map/handler/PinchZoomHandler.js +16 -5
- package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
- package/src/map/handler/TapHoldHandler.js +15 -4
- package/src/map/index.js +1 -1
- package/src/maplair.css +148 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/images/layers.svg +0 -1
- package/dist/images/marker-icon.svg +0 -1
- package/dist/images/marker-shadow.svg +0 -1
- package/src/core/Browser.js +0 -110
- package/src/images/layers.svg +0 -1
- package/src/images/marker-icon.svg +0 -1
- package/src/images/marker-shadow.svg +0 -1
|
@@ -88,13 +88,11 @@ function displaceable(layer) {
|
|
|
88
88
|
* ```
|
|
89
89
|
*/
|
|
90
90
|
var DisplaceHandler = class DisplaceHandler extends Handler {
|
|
91
|
-
static {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
97
|
-
}
|
|
91
|
+
static defaultOptions = {
|
|
92
|
+
gap: 2,
|
|
93
|
+
iterations: 80,
|
|
94
|
+
maxDistance: Infinity
|
|
95
|
+
};
|
|
98
96
|
/**
|
|
99
97
|
* @param {...MaplairMap} args The map.
|
|
100
98
|
*/
|
|
@@ -273,7 +271,7 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
|
|
|
273
271
|
* @param {{ iterations?: number, maxDisplacement?: number }} [options]
|
|
274
272
|
* @returns {Point[]} the same (displaced) points
|
|
275
273
|
*/
|
|
276
|
-
function displace(points, minSeparation, { iterations = DisplaceHandler.
|
|
274
|
+
function displace(points, minSeparation, { iterations = DisplaceHandler.defaultOptions.iterations, maxDisplacement = Infinity } = {}) {
|
|
277
275
|
const n = points.length;
|
|
278
276
|
if (n < 2) return points;
|
|
279
277
|
const sep = minSeparation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisplaceHandler.js","names":[],"sources":["../../../../src/map/handler/DisplaceHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as Util from '../../core/Util.js';\nimport {Point} from '../../geometry/Point.js';\nimport {CircleMarker} from '../../layer/vector/CircleMarker.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {Layer} from '../../layer/Layer.js' */\n/** @import {LayerEvent} from '../../core/Events.js' */\n/** @import {LatLng} from '../../geo/LatLng.js' */\n\n/**\n * Options of `DisplaceHandler`.\n * @typedef {object} DisplaceHandlerOptions\n * @property {number} [gap=2] Additional pixel distance between the outlines of two\n * markers.\n * @property {number} [iterations=80] Maximum number of relaxation passes per relayout.\n * @property {number} [maxDistance=Infinity] Maximum distance in meters a marker may be\n * moved away from its true position. Markers which would have to move further stay\n * overlapping. Meters rather than pixels, since the point of the limit is to bound the\n * geographic error. A limit in meters also scales itself: it only bites at the zoom\n * levels where a pixel is worth a lot of ground.\n */\n\n/**\n * Map options of `DisplaceHandler`, the interaction options for displacement.\n * @typedef {object} DisplaceHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|DisplaceHandlerOptions} [displace] Whether to displace\n * overlapping `CircleMarker`s, either `true` or an object overriding the options of\n * `DisplaceHandler`. Needs the `DisplaceHandler` to be added to the map, see there.\n */\n\n/**\n * Handler of `MaplairMap` for displacement, if added to the map (see `DisplaceHandler`).\n * @typedef {object} DisplaceHandlerMapProperties\n * @lends MaplairMap\n * @property {DisplaceHandler} [displace] The displacement handler, if added with the\n * name `displace`.\n */\n\n/**\n * Options of `CircleMarker` for the displacement by `DisplaceHandler`.\n * @typedef {object} DisplaceCircleMarkerOptions\n * @lends CircleMarkerOptions\n * @property {boolean} [displace] Whether to include this marker in the displacement of\n * the map, see `DisplaceHandler`.\n * @property {string} [displaceId] Stable identifier shared across marker instances that\n * represent the same thing on different layers, so that `DisplaceHandler` puts them at\n * the same displaced position.\n */\n\n/**\n * Whether a layer takes part in the displacement. Only these change the layout, so layers\n * that merely come and go on top of the markers — the highlight circle around a tapped or\n * searched bobble, for one — must not trigger a relayout of all of them.\n * @param {Layer} layer\n * @returns {boolean}\n */\nfunction displaceable(layer) {\n\treturn layer instanceof CircleMarker && !!layer.options.displace;\n}\n\n/**\n * Cartographic displacement of overlapping `CircleMarker`s: keeps all circle\n * markers created with `displace: true` free of overlap.\n *\n * Overlap is a screen space phenomenon: whether two markers cover each other\n * depends on their pixel radius and the current zoom level. The displacement is\n * therefore computed in projected pixel space and recomputed on every zoom. The\n * true position of each marker is kept by the handler, the displaced position is\n * applied via `setLatLng`. Since every run starts over from the true position,\n * markers never drift.\n *\n * `maxDistance` bounds how far a marker may be moved away from the truth, in\n * meters. It is worth noting what such a limit costs at low zoom levels: if a\n * marker is 11 km wide on the ground, separating two coincident ones moves each\n * of them by some 6 km, so a limit below that leaves them overlapping.\n *\n * Unlike the default handlers, it isn't added to every map, so that bundlers can\n * drop it from applications that don't use it. Add it to the map class (or to a\n * single map with `DisplaceHandler.addTo(map, 'displace')`), then enable it with\n * the map option `displace`, which is either `true` or an object overriding the\n * handler's options. It can be toggled at runtime via `map.displace.enable()` /\n * `map.displace.disable()`; disabling restores the true positions.\n *\n * @example\n * ```js\n * import { CircleMarker, DisplaceHandler, MaplairMap } from 'maplair';\n *\n * MaplairMap.addInitHook('addHandler', 'displace', DisplaceHandler);\n *\n * const map = new MaplairMap('map', {displace: { maxDistance: 10_000} });\n * new CircleMarker(latlng, { displace: true, radius: 6 }).addTo(map);\n * ```\n */\nexport class DisplaceHandler extends Handler {\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tgap: 2,\n\t\t\titerations: 80,\n\t\t\tmaxDistance: Infinity\n\t\t});\n\t}\n\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\t// the map option `displace` is either `true` or an object overriding the defaults\n\t\tUtil.setOptions(this, this._map.options.displace);\n\n\t\t/**\n\t\t * True (undisplaced) position per marker, kept outside of the marker so that\n\t\t * the displacement cannot clobber it and re-added markers keep their anchor.\n\t\t * @type {WeakMap<CircleMarker, LatLng>}\n\t\t */\n\t\tthis._trueLatLngs = new WeakMap();\n\n\t\t/**\n\t\t * Displaced position per `marker.options.displaceId`, per zoom level. Different\n\t\t * layers (e.g. one per classification) may create separate `CircleMarker`\n\t\t * instances for the same thing; keying by id instead of by marker instance\n\t\t * keeps it at the same displaced position regardless of which layer triggered\n\t\t * the relayout. Cleared whenever a true position changes.\n\t\t * @type {Map<number, Map<string, LatLng>>}\n\t\t */\n\t\tthis._displacedPositions = new Map();\n\n\t\tthis.callInitHooks(DisplaceHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tthis._map.on('zoomend', this.schedule, this);\n\t\tthis._map.on('layeradd', this._onLayerAdd, this);\n\t\tthis._map.on('layerremove', this._onLayerRemove, this);\n\t\tthis._map.eachLayer(layer => this._track(layer));\n\t\tthis.schedule();\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks and restores the\n\t * true positions of the markers.\n\t */\n\tremoveHooks() {\n\t\tthis._map.off('zoomend', this.schedule, this);\n\t\tthis._map.off('layeradd', this._onLayerAdd, this);\n\t\tthis._map.off('layerremove', this._onLayerRemove, this);\n\t\tif (this._frame) { cancelAnimationFrame(this._frame); }\n\t\tthis._frame = undefined;\n\t\tthis._restore();\n\t}\n\n\t/**\n\t * Requests a relayout in the next animation frame, at most one per frame.\n\t */\n\tschedule() {\n\t\tif (this._frame) {\n\t\t\treturn;\n\t\t}\n\t\tthis._frame = requestAnimationFrame(() => {\n\t\t\tthis._frame = undefined;\n\t\t\tthis.relayout();\n\t\t});\n\t}\n\n\t/**\n\t * Computes the displacement for all tracked markers in the pixel space of\n\t * the current zoom level and writes the displaced positions back.\n\t */\n\trelayout() {\n\t\tconst map = this._map;\n\t\t/** @type {CircleMarker[]} */\n\t\tconst markers = [];\n\t\tmap.eachLayer((layer) => {\n\t\t\tif (this._trueLatLngs.has(layer)) {\n\t\t\t\tmarkers.push(layer);\n\t\t\t}\n\t\t});\n\t\tif (markers.length < 2) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst zoom = map.getZoom();\n\t\tlet cache = this._displacedPositions.get(zoom);\n\t\tif (!cache) {\n\t\t\tcache = new Map();\n\t\t\tthis._displacedPositions.set(zoom, cache);\n\t\t}\n\n\t\t// If every currently visible marker already has a cached position for\n\t\t// this zoom (e.g. the same stations shown on a different layer), reuse\n\t\t// it as-is instead of recomputing the relaxation.\n\t\tif (markers.every(marker => marker.options.displaceId && cache.has(marker.options.displaceId))) {\n\t\t\tfor (const marker of markers) {\n\t\t\t\tthis._moveTo(marker, cache.get(marker.options.displaceId));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst {gap, iterations, maxDistance} = this.options;\n\t\tconst points = markers.map(marker => map.project(this._trueLatLngs.get(marker), zoom));\n\n\t\t// Usually a uniform radius per zoom level; max() as a safeguard.\n\t\tconst radius = markers.reduce((r, marker) => Math.max(r, marker.getRadius()), 0);\n\t\tdisplace(points, 2 * radius + gap, {iterations, maxDisplacement: maxDistance * this._pixelsPerMeter(zoom)});\n\n\t\tfor (let i = 0; i < markers.length; i++) {\n\t\t\tconst latLng = map.unproject(points[i], zoom);\n\t\t\tthis._moveTo(markers[i], latLng);\n\t\t\tif (markers[i].options.displaceId) {\n\t\t\t\tcache.set(markers[i].options.displaceId, latLng);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Scale of the map at `zoom`, measured with the CRS of the map at its\n\t * center. Since a relayout only ever covers one screen, the scale variation\n\t * across the view is ignored.\n\t * @param {number} zoom\n\t * @returns {number}\n\t */\n\t_pixelsPerMeter(zoom) {\n\t\tconst map = this._map;\n\t\tconst center = map.getCenter();\n\t\tconst east = map.unproject(map.project(center, zoom).add(new Point(100, 0)), zoom);\n\t\treturn 100 / map.distance(center, east);\n\t}\n\n\t/**\n\t * Moves a marker to its displaced (or true) position, without taking that\n\t * for a new true position, see `_onMarkerMove`.\n\t * @param {CircleMarker} marker\n\t * @param {LatLng} latLng\n\t */\n\t_moveTo(marker, latLng) {\n\t\tthis._moving = true;\n\t\ttry {\n\t\t\tmarker.setLatLng(latLng);\n\t\t} finally {\n\t\t\tthis._moving = false;\n\t\t}\n\t}\n\n\t/**\n\t * A tracked marker was moved by the application: that is its new true position,\n\t * which invalidates the cached displaced positions.\n\t * @param {Event} event\n\t */\n\t_onMarkerMove(event) {\n\t\tif (this._moving) { return; }\n\t\tthis._trueLatLngs.set(event.target, event.latlng);\n\t\tthis._displacedPositions.clear();\n\t\tif (this._enabled && this._map.hasLayer(event.target)) { this.schedule(); }\n\t}\n\n\t/**\n\t * @param {LayerEvent} event\n\t */\n\t_onLayerAdd(event) {\n\t\tthis._track(event.layer);\n\t\tif (displaceable(event.layer)) { this.schedule(); }\n\t}\n\n\t/**\n\t * @param {LayerEvent} event\n\t */\n\t_onLayerRemove(event) {\n\t\tif (displaceable(event.layer)) { this.schedule(); }\n\t}\n\n\t/**\n\t * Remembers the true position of a marker opted in via `displace: true`.\n\t * Markers seen before keep their previously stored position, so re-adding a\n\t * displaced marker does not anchor it to its displaced position.\n\t * @param {Layer} layer\n\t */\n\t_track(layer) {\n\t\tif (!displaceable(layer)) {\n\t\t\treturn;\n\t\t}\n\t\tif (!this._trueLatLngs.has(layer)) {\n\t\t\tthis._trueLatLngs.set(layer, layer.getLatLng());\n\t\t\tlayer.on('move', this._onMarkerMove, this);\n\t\t}\n\t}\n\n\t/**\n\t * Moves all tracked markers back to their true position.\n\t */\n\t_restore() {\n\t\tthis._map.eachLayer((layer) => {\n\t\t\tconst latLng = this._trueLatLngs.get(layer);\n\t\t\tif (latLng) { this._moveTo(layer, latLng); }\n\t\t});\n\t}\n}\n\n/**\n * Displaces overlapping points in pixel space until they are at least\n * `minSeparation` apart. Iterative relaxation: every overlapping pair is pushed\n * apart by half of its overlap per pass. Neighbour lookup uses a grid (cell\n * size = separation) ⇒ O(n) per iteration.\n *\n * No point ends up further than `maxDisplacement` away from where it started.\n * Points which hit that limit stay overlapping – the limit wins over the\n * separation.\n *\n * @param {Point[]} points Pixel coordinates (modified in place)\n * @param {number} minSeparation Minimum distance between centers, in pixels\n * @param {{ iterations?: number, maxDisplacement?: number }} [options]\n * @returns {Point[]} the same (displaced) points\n */\nexport function displace(\n\tpoints,\n\tminSeparation,\n\t{iterations = DisplaceHandler.prototype.options.iterations, maxDisplacement = Infinity} = {},\n) {\n\tconst n = points.length;\n\tif (n < 2) { return points; }\n\n\tconst sep = minSeparation;\n\tconst sepSq = sep * sep;\n\tconst cell = sep;\n\tconst dx = new Float64Array(n);\n\tconst dy = new Float64Array(n);\n\t// Anchors for `maxDisplacement`, the true positions of the points.\n\tconst ax = Float64Array.from(points, point => point.x);\n\tconst ay = Float64Array.from(points, point => point.y);\n\n\tfor (let iter = 0; iter < iterations; iter++) {\n\t\tdx.fill(0);\n\t\tdy.fill(0);\n\n\t\t// Sort the points into a grid (cell size = separation).\n\t\t/** @type {Map<string, number[]>} */\n\t\tconst grid = new Map();\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tconst key = `${Math.floor(points[i].x / cell)},${Math.floor(points[i].y / cell)}`;\n\t\t\tconst bucket = grid.get(key);\n\t\t\tif (bucket) {\n\t\t\t\tbucket.push(i);\n\t\t\t} else {\n\t\t\t\tgrid.set(key, [i]);\n\t\t\t}\n\t\t}\n\n\t\tlet overlaps = 0;\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tconst cx = Math.floor(points[i].x / cell);\n\t\t\tconst cy = Math.floor(points[i].y / cell);\n\t\t\t// Only the 3×3 neighbouring cells can be closer than `sep`.\n\t\t\tfor (let gx = cx - 1; gx <= cx + 1; gx++) {\n\t\t\t\tfor (let gy = cy - 1; gy <= cy + 1; gy++) {\n\t\t\t\t\tconst bucket = grid.get(`${gx},${gy}`);\n\t\t\t\t\tif (!bucket) { continue; }\n\t\t\t\t\tfor (const j of bucket) {\n\t\t\t\t\t\tif (j <= i) { continue; } // visit every pair once\n\t\t\t\t\t\tlet vx = points[i].x - points[j].x;\n\t\t\t\t\t\tlet vy = points[i].y - points[j].y;\n\t\t\t\t\t\tconst distSq = vx * vx + vy * vy;\n\t\t\t\t\t\tif (distSq >= sepSq) { continue; }\n\t\t\t\t\t\toverlaps++;\n\n\t\t\t\t\t\tlet dist;\n\t\t\t\t\t\tif (distSq === 0) {\n\t\t\t\t\t\t\t// Coincident points: deterministic direction derived\n\t\t\t\t\t\t\t// from the index (golden angle) instead of random.\n\t\t\t\t\t\t\tconst angle = i * 2.399963229728653;\n\t\t\t\t\t\t\tvx = Math.cos(angle);\n\t\t\t\t\t\t\tvy = Math.sin(angle);\n\t\t\t\t\t\t\tdist = 1;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdist = Math.sqrt(distSq);\n\t\t\t\t\t\t\tvx /= dist;\n\t\t\t\t\t\t\tvy /= dist;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst push = (sep - dist) / 2;\n\t\t\t\t\t\tdx[i] += vx * push;\n\t\t\t\t\t\tdy[i] += vy * push;\n\t\t\t\t\t\tdx[j] -= vx * push;\n\t\t\t\t\t\tdy[j] -= vy * push;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (overlaps === 0) {\n\t\t\tbreak; // converged – nothing left to do\n\t\t}\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tpoints[i].x += dx[i];\n\t\t\tpoints[i].y += dy[i];\n\n\t\t\t// Pull the point back onto the circle of radius `maxDisplacement`\n\t\t\t// around its anchor. Clamping inside the loop (instead of once at\n\t\t\t// the end) lets the following iterations redistribute along that\n\t\t\t// circle rather than piling up against it.\n\t\t\tconst ox = points[i].x - ax[i];\n\t\t\tconst oy = points[i].y - ay[i];\n\t\t\tconst offsetSq = ox * ox + oy * oy;\n\t\t\tif (offsetSq > maxDisplacement * maxDisplacement) {\n\t\t\t\tconst scale = maxDisplacement / Math.sqrt(offsetSq);\n\t\t\t\tpoints[i].x = ax[i] + ox * scale;\n\t\t\t\tpoints[i].y = ay[i] + oy * scale;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn points;\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAS,aAAa,OAAO;CAC5B,OAAO,iBAAiB,gBAAgB,CAAC,CAAC,MAAM,QAAQ;AACzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAa,kBAAb,MAAa,wBAAwB,QAAQ;CAC5C;EACC,KAAK,kBAAkB;GACtB,KAAK;GACL,YAAY;GACZ,aAAa;EACd,CAAC;CACF;;;;CAKA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EAEb,WAAgB,MAAM,KAAK,KAAK,QAAQ,QAAQ;;;;;;EAOhD,KAAK,+BAAe,IAAI,QAAQ;;;;;;;;;EAUhC,KAAK,sCAAsB,IAAI,IAAI;EAEnC,KAAK,cAAc,eAAe;CACnC;;;;CAKA,WAAW;EACV,KAAK,KAAK,GAAG,WAAW,KAAK,UAAU,IAAI;EAC3C,KAAK,KAAK,GAAG,YAAY,KAAK,aAAa,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OAAO,EAAE,CAAC,IAAI,GAAG,KAAK,KAAK;IAC3B,OAAO,EAAE,CAAC,IAAI,GAAG,KAAK,KAAK;GAC5B;EACD;CACD;CAEA,OAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"DisplaceHandler.js","names":[],"sources":["../../../../src/map/handler/DisplaceHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as Util from '../../core/Util.js';\nimport {Point} from '../../geometry/Point.js';\nimport {CircleMarker} from '../../layer/vector/CircleMarker.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {Layer} from '../../layer/Layer.js' */\n/** @import {LayerEvent} from '../../core/Events.js' */\n/** @import {LatLng} from '../../geo/LatLng.js' */\n\n/**\n * Options of `DisplaceHandler`.\n * @typedef {object} DisplaceHandlerOptions\n * @property {number} [gap=2] Additional pixel distance between the outlines of two\n * markers.\n * @property {number} [iterations=80] Maximum number of relaxation passes per relayout.\n * @property {number} [maxDistance=Infinity] Maximum distance in meters a marker may be\n * moved away from its true position. Markers which would have to move further stay\n * overlapping. Meters rather than pixels, since the point of the limit is to bound the\n * geographic error. A limit in meters also scales itself: it only bites at the zoom\n * levels where a pixel is worth a lot of ground.\n */\n\n/**\n * Map options of `DisplaceHandler`, the interaction options for displacement.\n * @typedef {object} DisplaceHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|DisplaceHandlerOptions} [displace] Whether to displace\n * overlapping `CircleMarker`s, either `true` or an object overriding the options of\n * `DisplaceHandler`. Needs the `DisplaceHandler` to be added to the map, see there.\n */\n\n/**\n * Handler of `MaplairMap` for displacement, if added to the map (see `DisplaceHandler`).\n * @typedef {object} DisplaceHandlerMapProperties\n * @lends MaplairMap\n * @property {DisplaceHandler} [displace] The displacement handler, if added with the\n * name `displace`.\n */\n\n/**\n * Options of `CircleMarker` for the displacement by `DisplaceHandler`.\n * @typedef {object} DisplaceCircleMarkerOptions\n * @lends CircleMarkerOptions\n * @property {boolean} [displace] Whether to include this marker in the displacement of\n * the map, see `DisplaceHandler`.\n * @property {string} [displaceId] Stable identifier shared across marker instances that\n * represent the same thing on different layers, so that `DisplaceHandler` puts them at\n * the same displaced position.\n */\n\n/**\n * Whether a layer takes part in the displacement. Only these change the layout, so layers\n * that merely come and go on top of the markers — the highlight circle around a tapped or\n * searched bobble, for one — must not trigger a relayout of all of them.\n * @param {Layer} layer\n * @returns {boolean}\n */\nfunction displaceable(layer) {\n\treturn layer instanceof CircleMarker && !!layer.options.displace;\n}\n\n/**\n * Cartographic displacement of overlapping `CircleMarker`s: keeps all circle\n * markers created with `displace: true` free of overlap.\n *\n * Overlap is a screen space phenomenon: whether two markers cover each other\n * depends on their pixel radius and the current zoom level. The displacement is\n * therefore computed in projected pixel space and recomputed on every zoom. The\n * true position of each marker is kept by the handler, the displaced position is\n * applied via `setLatLng`. Since every run starts over from the true position,\n * markers never drift.\n *\n * `maxDistance` bounds how far a marker may be moved away from the truth, in\n * meters. It is worth noting what such a limit costs at low zoom levels: if a\n * marker is 11 km wide on the ground, separating two coincident ones moves each\n * of them by some 6 km, so a limit below that leaves them overlapping.\n *\n * Unlike the default handlers, it isn't added to every map, so that bundlers can\n * drop it from applications that don't use it. Add it to the map class (or to a\n * single map with `DisplaceHandler.addTo(map, 'displace')`), then enable it with\n * the map option `displace`, which is either `true` or an object overriding the\n * handler's options. It can be toggled at runtime via `map.displace.enable()` /\n * `map.displace.disable()`; disabling restores the true positions.\n *\n * @example\n * ```js\n * import { CircleMarker, DisplaceHandler, MaplairMap } from 'maplair';\n *\n * MaplairMap.addInitHook('addHandler', 'displace', DisplaceHandler);\n *\n * const map = new MaplairMap('map', {displace: { maxDistance: 10_000} });\n * new CircleMarker(latlng, { displace: true, radius: 6 }).addTo(map);\n * ```\n */\nexport class DisplaceHandler extends Handler {\n\tstatic defaultOptions = {\n\t\tgap: 2,\n\t\titerations: 80,\n\t\tmaxDistance: Infinity\n\t};\n\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\t// the map option `displace` is either `true` or an object overriding the defaults\n\t\tUtil.setOptions(this, this._map.options.displace);\n\n\t\t/**\n\t\t * True (undisplaced) position per marker, kept outside of the marker so that\n\t\t * the displacement cannot clobber it and re-added markers keep their anchor.\n\t\t * @type {WeakMap<CircleMarker, LatLng>}\n\t\t */\n\t\tthis._trueLatLngs = new WeakMap();\n\n\t\t/**\n\t\t * Displaced position per `marker.options.displaceId`, per zoom level. Different\n\t\t * layers (e.g. one per classification) may create separate `CircleMarker`\n\t\t * instances for the same thing; keying by id instead of by marker instance\n\t\t * keeps it at the same displaced position regardless of which layer triggered\n\t\t * the relayout. Cleared whenever a true position changes.\n\t\t * @type {Map<number, Map<string, LatLng>>}\n\t\t */\n\t\tthis._displacedPositions = new Map();\n\n\t\tthis.callInitHooks(DisplaceHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tthis._map.on('zoomend', this.schedule, this);\n\t\tthis._map.on('layeradd', this._onLayerAdd, this);\n\t\tthis._map.on('layerremove', this._onLayerRemove, this);\n\t\tthis._map.eachLayer(layer => this._track(layer));\n\t\tthis.schedule();\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks and restores the\n\t * true positions of the markers.\n\t */\n\tremoveHooks() {\n\t\tthis._map.off('zoomend', this.schedule, this);\n\t\tthis._map.off('layeradd', this._onLayerAdd, this);\n\t\tthis._map.off('layerremove', this._onLayerRemove, this);\n\t\tif (this._frame) { cancelAnimationFrame(this._frame); }\n\t\tthis._frame = undefined;\n\t\tthis._restore();\n\t}\n\n\t/**\n\t * Requests a relayout in the next animation frame, at most one per frame.\n\t */\n\tschedule() {\n\t\tif (this._frame) {\n\t\t\treturn;\n\t\t}\n\t\tthis._frame = requestAnimationFrame(() => {\n\t\t\tthis._frame = undefined;\n\t\t\tthis.relayout();\n\t\t});\n\t}\n\n\t/**\n\t * Computes the displacement for all tracked markers in the pixel space of\n\t * the current zoom level and writes the displaced positions back.\n\t */\n\trelayout() {\n\t\tconst map = this._map;\n\t\t/** @type {CircleMarker[]} */\n\t\tconst markers = [];\n\t\tmap.eachLayer((layer) => {\n\t\t\tif (this._trueLatLngs.has(layer)) {\n\t\t\t\tmarkers.push(layer);\n\t\t\t}\n\t\t});\n\t\tif (markers.length < 2) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst zoom = map.getZoom();\n\t\tlet cache = this._displacedPositions.get(zoom);\n\t\tif (!cache) {\n\t\t\tcache = new Map();\n\t\t\tthis._displacedPositions.set(zoom, cache);\n\t\t}\n\n\t\t// If every currently visible marker already has a cached position for\n\t\t// this zoom (e.g. the same stations shown on a different layer), reuse\n\t\t// it as-is instead of recomputing the relaxation.\n\t\tif (markers.every(marker => marker.options.displaceId && cache.has(marker.options.displaceId))) {\n\t\t\tfor (const marker of markers) {\n\t\t\t\tthis._moveTo(marker, cache.get(marker.options.displaceId));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst {gap, iterations, maxDistance} = this.options;\n\t\tconst points = markers.map(marker => map.project(this._trueLatLngs.get(marker), zoom));\n\n\t\t// Usually a uniform radius per zoom level; max() as a safeguard.\n\t\tconst radius = markers.reduce((r, marker) => Math.max(r, marker.getRadius()), 0);\n\t\tdisplace(points, 2 * radius + gap, {iterations, maxDisplacement: maxDistance * this._pixelsPerMeter(zoom)});\n\n\t\tfor (let i = 0; i < markers.length; i++) {\n\t\t\tconst latLng = map.unproject(points[i], zoom);\n\t\t\tthis._moveTo(markers[i], latLng);\n\t\t\tif (markers[i].options.displaceId) {\n\t\t\t\tcache.set(markers[i].options.displaceId, latLng);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Scale of the map at `zoom`, measured with the CRS of the map at its\n\t * center. Since a relayout only ever covers one screen, the scale variation\n\t * across the view is ignored.\n\t * @param {number} zoom\n\t * @returns {number}\n\t */\n\t_pixelsPerMeter(zoom) {\n\t\tconst map = this._map;\n\t\tconst center = map.getCenter();\n\t\tconst east = map.unproject(map.project(center, zoom).add(new Point(100, 0)), zoom);\n\t\treturn 100 / map.distance(center, east);\n\t}\n\n\t/**\n\t * Moves a marker to its displaced (or true) position, without taking that\n\t * for a new true position, see `_onMarkerMove`.\n\t * @param {CircleMarker} marker\n\t * @param {LatLng} latLng\n\t */\n\t_moveTo(marker, latLng) {\n\t\tthis._moving = true;\n\t\ttry {\n\t\t\tmarker.setLatLng(latLng);\n\t\t} finally {\n\t\t\tthis._moving = false;\n\t\t}\n\t}\n\n\t/**\n\t * A tracked marker was moved by the application: that is its new true position,\n\t * which invalidates the cached displaced positions.\n\t * @param {Event} event\n\t */\n\t_onMarkerMove(event) {\n\t\tif (this._moving) { return; }\n\t\tthis._trueLatLngs.set(event.target, event.latlng);\n\t\tthis._displacedPositions.clear();\n\t\tif (this._enabled && this._map.hasLayer(event.target)) { this.schedule(); }\n\t}\n\n\t/**\n\t * @param {LayerEvent} event\n\t */\n\t_onLayerAdd(event) {\n\t\tthis._track(event.layer);\n\t\tif (displaceable(event.layer)) { this.schedule(); }\n\t}\n\n\t/**\n\t * @param {LayerEvent} event\n\t */\n\t_onLayerRemove(event) {\n\t\tif (displaceable(event.layer)) { this.schedule(); }\n\t}\n\n\t/**\n\t * Remembers the true position of a marker opted in via `displace: true`.\n\t * Markers seen before keep their previously stored position, so re-adding a\n\t * displaced marker does not anchor it to its displaced position.\n\t * @param {Layer} layer\n\t */\n\t_track(layer) {\n\t\tif (!displaceable(layer)) {\n\t\t\treturn;\n\t\t}\n\t\tif (!this._trueLatLngs.has(layer)) {\n\t\t\tthis._trueLatLngs.set(layer, layer.getLatLng());\n\t\t\tlayer.on('move', this._onMarkerMove, this);\n\t\t}\n\t}\n\n\t/**\n\t * Moves all tracked markers back to their true position.\n\t */\n\t_restore() {\n\t\tthis._map.eachLayer((layer) => {\n\t\t\tconst latLng = this._trueLatLngs.get(layer);\n\t\t\tif (latLng) { this._moveTo(layer, latLng); }\n\t\t});\n\t}\n}\n\n/**\n * Displaces overlapping points in pixel space until they are at least\n * `minSeparation` apart. Iterative relaxation: every overlapping pair is pushed\n * apart by half of its overlap per pass. Neighbour lookup uses a grid (cell\n * size = separation) ⇒ O(n) per iteration.\n *\n * No point ends up further than `maxDisplacement` away from where it started.\n * Points which hit that limit stay overlapping – the limit wins over the\n * separation.\n *\n * @param {Point[]} points Pixel coordinates (modified in place)\n * @param {number} minSeparation Minimum distance between centers, in pixels\n * @param {{ iterations?: number, maxDisplacement?: number }} [options]\n * @returns {Point[]} the same (displaced) points\n */\nexport function displace(\n\tpoints,\n\tminSeparation,\n\t{iterations = DisplaceHandler.defaultOptions.iterations, maxDisplacement = Infinity} = {},\n) {\n\tconst n = points.length;\n\tif (n < 2) { return points; }\n\n\tconst sep = minSeparation;\n\tconst sepSq = sep * sep;\n\tconst cell = sep;\n\tconst dx = new Float64Array(n);\n\tconst dy = new Float64Array(n);\n\t// Anchors for `maxDisplacement`, the true positions of the points.\n\tconst ax = Float64Array.from(points, point => point.x);\n\tconst ay = Float64Array.from(points, point => point.y);\n\n\tfor (let iter = 0; iter < iterations; iter++) {\n\t\tdx.fill(0);\n\t\tdy.fill(0);\n\n\t\t// Sort the points into a grid (cell size = separation).\n\t\t/** @type {Map<string, number[]>} */\n\t\tconst grid = new Map();\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tconst key = `${Math.floor(points[i].x / cell)},${Math.floor(points[i].y / cell)}`;\n\t\t\tconst bucket = grid.get(key);\n\t\t\tif (bucket) {\n\t\t\t\tbucket.push(i);\n\t\t\t} else {\n\t\t\t\tgrid.set(key, [i]);\n\t\t\t}\n\t\t}\n\n\t\tlet overlaps = 0;\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tconst cx = Math.floor(points[i].x / cell);\n\t\t\tconst cy = Math.floor(points[i].y / cell);\n\t\t\t// Only the 3×3 neighbouring cells can be closer than `sep`.\n\t\t\tfor (let gx = cx - 1; gx <= cx + 1; gx++) {\n\t\t\t\tfor (let gy = cy - 1; gy <= cy + 1; gy++) {\n\t\t\t\t\tconst bucket = grid.get(`${gx},${gy}`);\n\t\t\t\t\tif (!bucket) { continue; }\n\t\t\t\t\tfor (const j of bucket) {\n\t\t\t\t\t\tif (j <= i) { continue; } // visit every pair once\n\t\t\t\t\t\tlet vx = points[i].x - points[j].x;\n\t\t\t\t\t\tlet vy = points[i].y - points[j].y;\n\t\t\t\t\t\tconst distSq = vx * vx + vy * vy;\n\t\t\t\t\t\tif (distSq >= sepSq) { continue; }\n\t\t\t\t\t\toverlaps++;\n\n\t\t\t\t\t\tlet dist;\n\t\t\t\t\t\tif (distSq === 0) {\n\t\t\t\t\t\t\t// Coincident points: deterministic direction derived\n\t\t\t\t\t\t\t// from the index (golden angle) instead of random.\n\t\t\t\t\t\t\tconst angle = i * 2.399963229728653;\n\t\t\t\t\t\t\tvx = Math.cos(angle);\n\t\t\t\t\t\t\tvy = Math.sin(angle);\n\t\t\t\t\t\t\tdist = 1;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdist = Math.sqrt(distSq);\n\t\t\t\t\t\t\tvx /= dist;\n\t\t\t\t\t\t\tvy /= dist;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst push = (sep - dist) / 2;\n\t\t\t\t\t\tdx[i] += vx * push;\n\t\t\t\t\t\tdy[i] += vy * push;\n\t\t\t\t\t\tdx[j] -= vx * push;\n\t\t\t\t\t\tdy[j] -= vy * push;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (overlaps === 0) {\n\t\t\tbreak; // converged – nothing left to do\n\t\t}\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tpoints[i].x += dx[i];\n\t\t\tpoints[i].y += dy[i];\n\n\t\t\t// Pull the point back onto the circle of radius `maxDisplacement`\n\t\t\t// around its anchor. Clamping inside the loop (instead of once at\n\t\t\t// the end) lets the following iterations redistribute along that\n\t\t\t// circle rather than piling up against it.\n\t\t\tconst ox = points[i].x - ax[i];\n\t\t\tconst oy = points[i].y - ay[i];\n\t\t\tconst offsetSq = ox * ox + oy * oy;\n\t\t\tif (offsetSq > maxDisplacement * maxDisplacement) {\n\t\t\t\tconst scale = maxDisplacement / Math.sqrt(offsetSq);\n\t\t\t\tpoints[i].x = ax[i] + ox * scale;\n\t\t\t\tpoints[i].y = ay[i] + oy * scale;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn points;\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAS,aAAa,OAAO;CAC5B,OAAO,iBAAiB,gBAAgB,CAAC,CAAC,MAAM,QAAQ;AACzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAa,kBAAb,MAAa,wBAAwB,QAAQ;CAC5C,OAAO,iBAAiB;EACvB,KAAK;EACL,YAAY;EACZ,aAAa;CACd;;;;CAKA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EAEb,WAAgB,MAAM,KAAK,KAAK,QAAQ,QAAQ;;;;;;EAOhD,KAAK,+BAAe,IAAI,QAAQ;;;;;;;;;EAUhC,KAAK,sCAAsB,IAAI,IAAI;EAEnC,KAAK,cAAc,eAAe;CACnC;;;;CAKA,WAAW;EACV,KAAK,KAAK,GAAG,WAAW,KAAK,UAAU,IAAI;EAC3C,KAAK,KAAK,GAAG,YAAY,KAAK,aAAa,IAAI;EAC/C,KAAK,KAAK,GAAG,eAAe,KAAK,gBAAgB,IAAI;EACrD,KAAK,KAAK,WAAU,UAAS,KAAK,OAAO,KAAK,CAAC;EAC/C,KAAK,SAAS;CACf;;;;;CAMA,cAAc;EACb,KAAK,KAAK,IAAI,WAAW,KAAK,UAAU,IAAI;EAC5C,KAAK,KAAK,IAAI,YAAY,KAAK,aAAa,IAAI;EAChD,KAAK,KAAK,IAAI,eAAe,KAAK,gBAAgB,IAAI;EACtD,IAAI,KAAK,QAAU,qBAAqB,KAAK,MAAM;EACnD,K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E,CAAC,IAAI,OAAO,EAAE,CAAC;KACjC,IAAI,KAAK,OAAO,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC;KACjC,MAAM,SAAS,KAAK,KAAK,KAAK;KAC9B,IAAI,UAAU,OAAS;KACvB;KAEA,IAAI;KACJ,IAAI,WAAW,GAAG;MAGjB,MAAM,QAAQ,IAAI;MAClB,KAAK,KAAK,IAAI,KAAK;MACnB,KAAK,KAAK,IAAI,KAAK;MACnB,OAAO;KACR,OAAO;MACN,OAAO,KAAK,KAAK,MAAM;MACvB,MAAM;MACN,MAAM;KACP;KAEA,MAAM,QAAQ,MAAM,QAAQ;KAC5B,GAAG,MAAM,KAAK;KACd,GAAG,MAAM,KAAK;KACd,GAAG,MAAM,KAAK;KACd,GAAG,MAAM,KAAK;IACf;GACD;EAEF;EAEA,IAAI,aAAa,GAChB;EAED,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;GAC3B,OAAO,EAAE,CAAC,KAAK,GAAG;GAClB,OAAO,EAAE,CAAC,KAAK,GAAG;GAMlB,MAAM,KAAK,OAAO,EAAE,CAAC,IAAI,GAAG;GAC5B,MAAM,KAAK,OAAO,EAAE,CAAC,IAAI,GAAG;GAC5B,MAAM,WAAW,KAAK,KAAK,KAAK;GAChC,IAAI,WAAW,kBAAkB,iBAAiB;IACjD,MAAM,QAAQ,kBAAkB,KAAK,KAAK,QAAQ;IAClD,OAAO,EAAE,CAAC,IAAI,GAAG,KAAK,KAAK;IAC3B,OAAO,EAAE,CAAC,IAAI,GAAG,KAAK,KAAK;GAC5B;EACD;CACD;CAEA,OAAO;AACR"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Point } from "../../geometry/Point.js";
|
|
2
1
|
import { Bounds } from "../../geometry/Bounds.js";
|
|
3
2
|
import { LatLngBounds } from "../../geo/LatLngBounds.js";
|
|
4
3
|
import { Handler } from "../../core/Handler.js";
|
|
@@ -16,13 +15,14 @@ import { Draggable } from "../../dom/Draggable.js";
|
|
|
16
15
|
* the same direction for some time. Feels especially nice on touch devices.
|
|
17
16
|
* @property {number} [inertiaDeceleration=3400] The rate with which the inertial
|
|
18
17
|
* movement slows down, in pixels/second².
|
|
19
|
-
* @property {number} [inertiaMaxSpeed=
|
|
18
|
+
* @property {number} [inertiaMaxSpeed=1400] Max speed of the inertial movement,
|
|
20
19
|
* in pixels/second.
|
|
21
20
|
* @property {number} [easeLinearity=0.2] The linearity of the easing of the inertial
|
|
22
21
|
* movement.
|
|
23
22
|
* @property {boolean} [worldCopyJump=false] With this option enabled, the map tracks
|
|
24
23
|
* when you pan to another "copy" of the world and seamlessly jumps to the original one
|
|
25
|
-
* so that all overlays like markers and vector layers are still visible.
|
|
24
|
+
* so that all overlays like markers and vector layers are still visible. A map with an
|
|
25
|
+
* infinite CRS, such as `SimpleCRS`, does not jump, as it has no copies of the world.
|
|
26
26
|
* @property {number} [maxBoundsViscosity=0.0] If `maxBounds` is set, this option will
|
|
27
27
|
* control how solid the bounds are when dragging the map around. The default value of
|
|
28
28
|
* `0.0` allows the user to drag outside the bounds at normal speed, higher values will
|
|
@@ -59,16 +59,13 @@ var DragHandler = class DragHandler extends Handler {
|
|
|
59
59
|
const map = this._map;
|
|
60
60
|
this._draggable = new Draggable(map._mapPane, map._container);
|
|
61
61
|
this._draggable.on({
|
|
62
|
+
down: this._onDown,
|
|
62
63
|
dragstart: this._onDragStart,
|
|
63
64
|
drag: this._onDrag,
|
|
64
65
|
dragend: this._onDragEnd
|
|
65
66
|
}, this);
|
|
66
67
|
this._draggable.on("predrag", this._onPreDragLimit, this);
|
|
67
|
-
if (map.options.worldCopyJump)
|
|
68
|
-
this._draggable.on("predrag", this._onPreDragWrap, this);
|
|
69
|
-
map.on("zoomend crschange", this._onZoomEnd, this);
|
|
70
|
-
map.whenReady(this._onZoomEnd, this);
|
|
71
|
-
}
|
|
68
|
+
if (map.options.worldCopyJump) this._draggable.on("predrag", this._onPreDragWrap, this);
|
|
72
69
|
}
|
|
73
70
|
this._map._container.classList.add("maplair-grab", "maplair-touch-drag");
|
|
74
71
|
this._draggable.enable();
|
|
@@ -96,6 +93,9 @@ var DragHandler = class DragHandler extends Handler {
|
|
|
96
93
|
moving() {
|
|
97
94
|
return this._draggable?._moving;
|
|
98
95
|
}
|
|
96
|
+
_onDown() {
|
|
97
|
+
this._map._stop();
|
|
98
|
+
}
|
|
99
99
|
_onDragStart(e) {
|
|
100
100
|
const map = this._map;
|
|
101
101
|
map._stop();
|
|
@@ -126,11 +126,6 @@ var DragHandler = class DragHandler extends Handler {
|
|
|
126
126
|
this._times.shift();
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
_onZoomEnd() {
|
|
130
|
-
const pxCenter = this._map.getSize().divideBy(2), pxWorldCenter = this._map.latLngToLayerPoint([0, 0]);
|
|
131
|
-
this._initialWorldOffset = pxWorldCenter.subtract(pxCenter).x;
|
|
132
|
-
this._worldWidth = this._map.getPixelWorldBounds().getSize().x;
|
|
133
|
-
}
|
|
134
129
|
_viscousLimit(value, threshold) {
|
|
135
130
|
return value - (value - threshold) * this._viscosity;
|
|
136
131
|
}
|
|
@@ -145,9 +140,9 @@ var DragHandler = class DragHandler extends Handler {
|
|
|
145
140
|
this._draggable._newPos = this._draggable._startPos.add(offset);
|
|
146
141
|
}
|
|
147
142
|
_onPreDragWrap() {
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
143
|
+
const draggable = this._draggable;
|
|
144
|
+
draggable._absPos = draggable._newPos;
|
|
145
|
+
draggable._newPos = this._map._wrapWorldCopy(draggable._newPos);
|
|
151
146
|
}
|
|
152
147
|
_onDragEnd(e) {
|
|
153
148
|
const map = this._map, options = map.options, noInertia = !options.inertia || e.noInertia || this._times.length < 2;
|
|
@@ -155,8 +150,13 @@ var DragHandler = class DragHandler extends Handler {
|
|
|
155
150
|
if (noInertia) map.fire("moveend");
|
|
156
151
|
else {
|
|
157
152
|
this._prunePositions(Date.now());
|
|
158
|
-
const direction = this._lastPos.subtract(this._positions[0]), duration = (this._lastTime - this._times[0]) / 1e3, ease = options.easeLinearity, speedVector = direction.multiplyBy(ease / duration), speed = speedVector.distanceTo([0, 0]), limitedSpeed = Math.min(options.inertiaMaxSpeed, speed), limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed),
|
|
159
|
-
let offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();
|
|
153
|
+
const direction = this._lastPos.subtract(this._positions[0]), duration = (this._lastTime - this._times[0]) / 1e3, ease = options.easeLinearity, speedVector = direction.multiplyBy(ease / duration), speed = speedVector.distanceTo([0, 0]), limitedSpeed = Math.min(options.inertiaMaxSpeed, speed), limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed), maxOffset = map.getSize().divideBy(2);
|
|
154
|
+
let decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease), offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();
|
|
155
|
+
if (map._prefersReducedMotion() && !maxOffset.contains(offset)) {
|
|
156
|
+
const k = Math.min(maxOffset.x / Math.abs(offset.x), maxOffset.y / Math.abs(offset.y));
|
|
157
|
+
offset = offset.multiplyBy(k).round();
|
|
158
|
+
decelerationDuration *= Math.sqrt(k);
|
|
159
|
+
}
|
|
160
160
|
if (!offset.x && !offset.y) map.fire("moveend");
|
|
161
161
|
else {
|
|
162
162
|
offset = map._limitOffset(offset, map.options.maxBounds);
|
|
@@ -181,7 +181,7 @@ var DragHandler = class DragHandler extends Handler {
|
|
|
181
181
|
dragging: true,
|
|
182
182
|
inertia: true,
|
|
183
183
|
inertiaDeceleration: 3400,
|
|
184
|
-
inertiaMaxSpeed:
|
|
184
|
+
inertiaMaxSpeed: 1400,
|
|
185
185
|
easeLinearity: .2,
|
|
186
186
|
worldCopyJump: false,
|
|
187
187
|
maxBoundsViscosity: 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragHandler.js","names":[],"sources":["../../../../src/map/handler/DragHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport {Draggable} from '../../dom/Draggable.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {MaplairEvent, DragEndEvent} from '../../core/Events.js' */\n\n/**\n * Map options of `DragHandler`, the interaction options for dragging.\n * @typedef {object} DragHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [dragging=true] Whether the map is draggable with pointer or not.\n * @property {boolean} [inertia=true] If enabled, panning of the map will have an\n * inertia effect where the map builds momentum while dragging and continues moving in\n * the same direction for some time. Feels especially nice on touch devices.\n * @property {number} [inertiaDeceleration=3400] The rate with which the inertial\n * movement slows down, in pixels/second².\n * @property {number} [inertiaMaxSpeed=Infinity] Max speed of the inertial movement,\n * in pixels/second.\n * @property {number} [easeLinearity=0.2] The linearity of the easing of the inertial\n * movement.\n * @property {boolean} [worldCopyJump=false] With this option enabled, the map tracks\n * when you pan to another \"copy\" of the world and seamlessly jumps to the original one\n * so that all overlays like markers and vector layers are still visible.\n * @property {number} [maxBoundsViscosity=0.0] If `maxBounds` is set, this option will\n * control how solid the bounds are when dragging the map around. The default value of\n * `0.0` allows the user to drag outside the bounds at normal speed, higher values will\n * slow down map dragging outside bounds, and `1.0` makes the bounds fully solid,\n * preventing the user from dragging outside the bounds.\n */\n\n/**\n * Handler of `MaplairMap` for dragging.\n * @typedef {object} DragHandlerMapProperties\n * @lends MaplairMap\n * @property {DragHandler} dragging Map dragging handler.\n */\n\n/**\n * Makes the map draggable (with panning inertia), enabled by default, see the map\n * option `dragging`.\n *\n * @fires MaplairMap#dragstart {MaplairEvent} Fired when the user starts dragging the map.\n * @fires MaplairMap#drag {MaplairEvent} Fired repeatedly while the user drags the map.\n * @fires MaplairMap#dragend {DragEndEvent} Fired when the user stops dragging the map.\n */\nexport class DragHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(DragHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tif (!this._draggable) {\n\t\t\tconst map = this._map;\n\n\t\t\tthis._draggable = new Draggable(map._mapPane, map._container);\n\n\t\t\tthis._draggable.on({\n\t\t\t\tdragstart: this._onDragStart,\n\t\t\t\tdrag: this._onDrag,\n\t\t\t\tdragend: this._onDragEnd\n\t\t\t}, this);\n\n\t\t\tthis._draggable.on('predrag', this._onPreDragLimit, this);\n\t\t\tif (map.options.worldCopyJump) {\n\t\t\t\tthis._draggable.on('predrag', this._onPreDragWrap, this);\n\t\t\t\tmap.on('zoomend crschange', this._onZoomEnd, this);\n\n\t\t\t\tmap.whenReady(this._onZoomEnd, this);\n\t\t\t}\n\t\t}\n\t\tthis._map._container.classList.add('maplair-grab', 'maplair-touch-drag');\n\t\tthis._draggable.enable();\n\t\tthis._positions = [];\n\t\tthis._times = [];\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._map._container.classList.remove('maplair-grab', 'maplair-touch-drag');\n\t\tthis._draggable.disable();\n\t}\n\n\t/**\n\t * Returns `true` if the map has been moved by the current or last drag.\n\t * @returns {boolean}\n\t */\n\tmoved() {\n\t\treturn this._draggable?._moved;\n\t}\n\n\t/**\n\t * Returns `true` while the map is being dragged.\n\t * @returns {boolean}\n\t */\n\tmoving() {\n\t\treturn this._draggable?._moving;\n\t}\n\n\t_onDragStart(e) {\n\t\tconst map = this._map;\n\n\t\tmap._stop();\n\t\tmap._setUserEvent(e.originalEvent);\n\t\tif (this._map.options.maxBounds && this._map.options.maxBoundsViscosity) {\n\t\t\tconst bounds = LatLngBounds.from(this._map.options.maxBounds);\n\n\t\t\tthis._offsetLimit = new Bounds(\n\t\t\t\tthis._map.latLngToContainerPoint(bounds.getNorthWest()).multiplyBy(-1),\n\t\t\t\tthis._map.latLngToContainerPoint(bounds.getSouthEast()).multiplyBy(-1)\n\t\t\t\t\t.add(this._map.getSize()));\n\n\t\t\tthis._viscosity = Math.min(1.0, Math.max(0.0, this._map.options.maxBoundsViscosity));\n\t\t} else {\n\t\t\tthis._offsetLimit = null;\n\t\t}\n\n\t\tmap\n\t\t\t.fire('movestart')\n\t\t\t.fire('dragstart');\n\n\t\tif (map.options.inertia) {\n\t\t\tthis._positions = [];\n\t\t\tthis._times = [];\n\t\t}\n\t}\n\n\t_onDrag(e) {\n\t\tif (this._map.options.inertia) {\n\t\t\tconst time = this._lastTime = Date.now(),\n\t\t\tpos = this._lastPos = this._draggable._absPos || this._draggable._newPos;\n\n\t\t\tthis._positions.push(pos);\n\t\t\tthis._times.push(time);\n\n\t\t\tthis._prunePositions(time);\n\t\t}\n\n\t\tthis._map\n\t\t\t.fire('move', e)\n\t\t\t.fire('drag', e);\n\t}\n\n\t_prunePositions(time) {\n\t\twhile (this._positions.length > 1 && time - this._times[0] > 50) {\n\t\t\tthis._positions.shift();\n\t\t\tthis._times.shift();\n\t\t}\n\t}\n\n\t_onZoomEnd() {\n\t\tconst pxCenter = this._map.getSize().divideBy(2),\n\t\tpxWorldCenter = this._map.latLngToLayerPoint([0, 0]);\n\n\t\tthis._initialWorldOffset = pxWorldCenter.subtract(pxCenter).x;\n\t\tthis._worldWidth = this._map.getPixelWorldBounds().getSize().x;\n\t}\n\n\t_viscousLimit(value, threshold) {\n\t\treturn value - (value - threshold) * this._viscosity;\n\t}\n\n\t_onPreDragLimit() {\n\t\tif (!this._viscosity || !this._offsetLimit) { return; }\n\n\t\tconst offset = this._draggable._newPos.subtract(this._draggable._startPos);\n\n\t\tconst limit = this._offsetLimit;\n\t\tif (offset.x < limit.min.x) { offset.x = this._viscousLimit(offset.x, limit.min.x); }\n\t\tif (offset.y < limit.min.y) { offset.y = this._viscousLimit(offset.y, limit.min.y); }\n\t\tif (offset.x > limit.max.x) { offset.x = this._viscousLimit(offset.x, limit.max.x); }\n\t\tif (offset.y > limit.max.y) { offset.y = this._viscousLimit(offset.y, limit.max.y); }\n\n\t\tthis._draggable._newPos = this._draggable._startPos.add(offset);\n\t}\n\n\t_onPreDragWrap() {\n\t\t// TODO refactor to be able to adjust map pane position after zoom\n\t\tconst worldWidth = this._worldWidth,\n\t\thalfWidth = Math.round(worldWidth / 2),\n\t\tdx = this._initialWorldOffset,\n\t\tx = this._draggable._newPos.x,\n\t\tnewX1 = (x - halfWidth + dx) % worldWidth + halfWidth - dx,\n\t\tnewX2 = (x + halfWidth + dx) % worldWidth - halfWidth - dx,\n\t\tnewX = Math.abs(newX1 + dx) < Math.abs(newX2 + dx) ? newX1 : newX2;\n\n\t\tthis._draggable._absPos = new Point(this._draggable._newPos);\n\t\tthis._draggable._newPos.x = newX;\n\t}\n\n\t_onDragEnd(e) {\n\t\tconst map = this._map,\n\t\toptions = map.options,\n\n\t\tnoInertia = !options.inertia || e.noInertia || this._times.length < 2;\n\n\t\tmap.fire('dragend', e);\n\n\t\tif (noInertia) {\n\t\t\tmap.fire('moveend');\n\n\t\t} else {\n\t\t\tthis._prunePositions(Date.now());\n\n\t\t\tconst direction = this._lastPos.subtract(this._positions[0]),\n\t\t\tduration = (this._lastTime - this._times[0]) / 1000,\n\t\t\tease = options.easeLinearity,\n\n\t\t\tspeedVector = direction.multiplyBy(ease / duration),\n\t\t\tspeed = speedVector.distanceTo([0, 0]),\n\n\t\t\tlimitedSpeed = Math.min(options.inertiaMaxSpeed, speed),\n\t\t\tlimitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed),\n\n\t\t\tdecelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease);\n\t\t\tlet offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();\n\n\t\t\tif (!offset.x && !offset.y) {\n\t\t\t\tmap.fire('moveend');\n\n\t\t\t} else {\n\t\t\t\toffset = map._limitOffset(offset, map.options.maxBounds);\n\n\t\t\t\trequestAnimationFrame(() => {\n\t\t\t\t\tmap.panBy(offset, {\n\t\t\t\t\t\tduration: decelerationDuration,\n\t\t\t\t\t\teaseLinearity: ease,\n\t\t\t\t\t\tnoMoveStart: true,\n\t\t\t\t\t\tanimate: true\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tdragging: true,\n\t\t\tinertia: true,\n\t\t\tinertiaDeceleration: 3400, // px/s^2\n\t\t\tinertiaMaxSpeed: Infinity, // px/s\n\t\t\teaseLinearity: 0.2,\n\t\t\t// TODO refactor, move to CRS\n\t\t\tworldCopyJump: false,\n\t\t\tmaxBoundsViscosity: 0.0\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'dragging', DragHandler);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;;;;CAIxC,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;CAKA,WAAW;EACV,IAAI,CAAC,KAAK,YAAY;GACrB,MAAM,MAAM,KAAK;GAEjB,KAAK,aAAa,IAAI,UAAU,IAAI,UAAU,IAAI,UAAU;GAE5D,KAAK,WAAW,GAAG;IAClB,WAAW,KAAK;IAChB,MAAM,KAAK;IACX,SAAS,KAAK;GACf,GAAG,IAAI;GAEP,KAAK,WAAW,GAAG,WAAW,KAAK,iBAAiB,IAAI;GACxD,IAAI,IAAI,QAAQ,eAAe;IAC9B,KAAK,WAAW,GAAG,WAAW,KAAK,gBAAgB,IAAI;IACvD,IAAI,GAAG,qBAAqB,KAAK,YAAY,IAAI;IAEjD,IAAI,UAAU,KAAK,YAAY,IAAI;GACpC;EACD;EACA,KAAK,KAAK,WAAW,UAAU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V,SAAS;GACT,qBAAqB;GACrB,iBAAiB;GACjB,eAAe;GAEf,eAAe;GACf,oBAAoB;EACrB,CAAC;EAED,WAAW,YAAY,cAAc,YAAY,WAAW;CAC7D;AACD"}
|
|
1
|
+
{"version":3,"file":"DragHandler.js","names":[],"sources":["../../../../src/map/handler/DragHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport {Draggable} from '../../dom/Draggable.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {MaplairEvent, DragEndEvent} from '../../core/Events.js' */\n\n/**\n * Map options of `DragHandler`, the interaction options for dragging.\n * @typedef {object} DragHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [dragging=true] Whether the map is draggable with pointer or not.\n * @property {boolean} [inertia=true] If enabled, panning of the map will have an\n * inertia effect where the map builds momentum while dragging and continues moving in\n * the same direction for some time. Feels especially nice on touch devices.\n * @property {number} [inertiaDeceleration=3400] The rate with which the inertial\n * movement slows down, in pixels/second².\n * @property {number} [inertiaMaxSpeed=1400] Max speed of the inertial movement,\n * in pixels/second.\n * @property {number} [easeLinearity=0.2] The linearity of the easing of the inertial\n * movement.\n * @property {boolean} [worldCopyJump=false] With this option enabled, the map tracks\n * when you pan to another \"copy\" of the world and seamlessly jumps to the original one\n * so that all overlays like markers and vector layers are still visible. A map with an\n * infinite CRS, such as `SimpleCRS`, does not jump, as it has no copies of the world.\n * @property {number} [maxBoundsViscosity=0.0] If `maxBounds` is set, this option will\n * control how solid the bounds are when dragging the map around. The default value of\n * `0.0` allows the user to drag outside the bounds at normal speed, higher values will\n * slow down map dragging outside bounds, and `1.0` makes the bounds fully solid,\n * preventing the user from dragging outside the bounds.\n */\n\n/**\n * Handler of `MaplairMap` for dragging.\n * @typedef {object} DragHandlerMapProperties\n * @lends MaplairMap\n * @property {DragHandler} dragging Map dragging handler.\n */\n\n/**\n * Makes the map draggable (with panning inertia), enabled by default, see the map\n * option `dragging`.\n *\n * @fires MaplairMap#dragstart {MaplairEvent} Fired when the user starts dragging the map.\n * @fires MaplairMap#drag {MaplairEvent} Fired repeatedly while the user drags the map.\n * @fires MaplairMap#dragend {DragEndEvent} Fired when the user stops dragging the map.\n */\nexport class DragHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(DragHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tif (!this._draggable) {\n\t\t\tconst map = this._map;\n\n\t\t\tthis._draggable = new Draggable(map._mapPane, map._container);\n\n\t\t\tthis._draggable.on({\n\t\t\t\tdown: this._onDown,\n\t\t\t\tdragstart: this._onDragStart,\n\t\t\t\tdrag: this._onDrag,\n\t\t\t\tdragend: this._onDragEnd\n\t\t\t}, this);\n\n\t\t\tthis._draggable.on('predrag', this._onPreDragLimit, this);\n\t\t\tif (map.options.worldCopyJump) {\n\t\t\t\tthis._draggable.on('predrag', this._onPreDragWrap, this);\n\t\t\t}\n\t\t}\n\t\tthis._map._container.classList.add('maplair-grab', 'maplair-touch-drag');\n\t\tthis._draggable.enable();\n\t\tthis._positions = [];\n\t\tthis._times = [];\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._map._container.classList.remove('maplair-grab', 'maplair-touch-drag');\n\t\tthis._draggable.disable();\n\t}\n\n\t/**\n\t * Returns `true` if the map has been moved by the current or last drag.\n\t * @returns {boolean}\n\t */\n\tmoved() {\n\t\treturn this._draggable?._moved;\n\t}\n\n\t/**\n\t * Returns `true` while the map is being dragged.\n\t * @returns {boolean}\n\t */\n\tmoving() {\n\t\treturn this._draggable?._moving;\n\t}\n\n\t_onDown() {\n\t\t// Stop inertia before Draggable captures _startPos (#10376).\n\t\tthis._map._stop();\n\t}\n\n\t_onDragStart(e) {\n\t\tconst map = this._map;\n\n\t\tmap._stop();\n\t\tmap._setUserEvent(e.originalEvent);\n\t\tif (this._map.options.maxBounds && this._map.options.maxBoundsViscosity) {\n\t\t\tconst bounds = LatLngBounds.from(this._map.options.maxBounds);\n\n\t\t\tthis._offsetLimit = new Bounds(\n\t\t\t\tthis._map.latLngToContainerPoint(bounds.getNorthWest()).multiplyBy(-1),\n\t\t\t\tthis._map.latLngToContainerPoint(bounds.getSouthEast()).multiplyBy(-1)\n\t\t\t\t\t.add(this._map.getSize()));\n\n\t\t\tthis._viscosity = Math.min(1.0, Math.max(0.0, this._map.options.maxBoundsViscosity));\n\t\t} else {\n\t\t\tthis._offsetLimit = null;\n\t\t}\n\n\t\tmap\n\t\t\t.fire('movestart')\n\t\t\t.fire('dragstart');\n\n\t\tif (map.options.inertia) {\n\t\t\tthis._positions = [];\n\t\t\tthis._times = [];\n\t\t}\n\t}\n\n\t_onDrag(e) {\n\t\tif (this._map.options.inertia) {\n\t\t\tconst time = this._lastTime = Date.now(),\n\t\t\tpos = this._lastPos = this._draggable._absPos || this._draggable._newPos;\n\n\t\t\tthis._positions.push(pos);\n\t\t\tthis._times.push(time);\n\n\t\t\tthis._prunePositions(time);\n\t\t}\n\n\t\tthis._map\n\t\t\t.fire('move', e)\n\t\t\t.fire('drag', e);\n\t}\n\n\t_prunePositions(time) {\n\t\twhile (this._positions.length > 1 && time - this._times[0] > 50) {\n\t\t\tthis._positions.shift();\n\t\t\tthis._times.shift();\n\t\t}\n\t}\n\n\t_viscousLimit(value, threshold) {\n\t\treturn value - (value - threshold) * this._viscosity;\n\t}\n\n\t_onPreDragLimit() {\n\t\tif (!this._viscosity || !this._offsetLimit) { return; }\n\n\t\tconst offset = this._draggable._newPos.subtract(this._draggable._startPos);\n\n\t\tconst limit = this._offsetLimit;\n\t\tif (offset.x < limit.min.x) { offset.x = this._viscousLimit(offset.x, limit.min.x); }\n\t\tif (offset.y < limit.min.y) { offset.y = this._viscousLimit(offset.y, limit.min.y); }\n\t\tif (offset.x > limit.max.x) { offset.x = this._viscousLimit(offset.x, limit.max.x); }\n\t\tif (offset.y > limit.max.y) { offset.y = this._viscousLimit(offset.y, limit.max.y); }\n\n\t\tthis._draggable._newPos = this._draggable._startPos.add(offset);\n\t}\n\n\t_onPreDragWrap() {\n\t\tconst draggable = this._draggable;\n\t\tdraggable._absPos = draggable._newPos;\n\t\tdraggable._newPos = this._map._wrapWorldCopy(draggable._newPos);\n\t}\n\n\t_onDragEnd(e) {\n\t\tconst map = this._map,\n\t\toptions = map.options,\n\n\t\tnoInertia = !options.inertia || e.noInertia || this._times.length < 2;\n\n\t\tmap.fire('dragend', e);\n\n\t\tif (noInertia) {\n\t\t\tmap.fire('moveend');\n\n\t\t} else {\n\t\t\tthis._prunePositions(Date.now());\n\n\t\t\tconst direction = this._lastPos.subtract(this._positions[0]),\n\t\t\tduration = (this._lastTime - this._times[0]) / 1000,\n\t\t\tease = options.easeLinearity,\n\n\t\t\tspeedVector = direction.multiplyBy(ease / duration),\n\t\t\tspeed = speedVector.distanceTo([0, 0]),\n\n\t\t\tlimitedSpeed = Math.min(options.inertiaMaxSpeed, speed),\n\t\t\tlimitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed),\n\n\t\t\tmaxOffset = map.getSize().divideBy(2);\n\n\t\t\tlet decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease),\n\t\t\toffset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();\n\n\t\t\t// with reduced motion, shorten the coast to fit within half the map size; distance grows with the\n\t\t\t// square of duration, so scaling the duration by the square root keeps the deceleration the same\n\t\t\tif (map._prefersReducedMotion() && !maxOffset.contains(offset)) {\n\t\t\t\tconst k = Math.min(maxOffset.x / Math.abs(offset.x), maxOffset.y / Math.abs(offset.y));\n\t\t\t\toffset = offset.multiplyBy(k).round();\n\t\t\t\tdecelerationDuration *= Math.sqrt(k);\n\t\t\t}\n\n\t\t\tif (!offset.x && !offset.y) {\n\t\t\t\tmap.fire('moveend');\n\n\t\t\t} else {\n\t\t\t\toffset = map._limitOffset(offset, map.options.maxBounds);\n\n\t\t\t\trequestAnimationFrame(() => {\n\t\t\t\t\tmap.panBy(offset, {\n\t\t\t\t\t\tduration: decelerationDuration,\n\t\t\t\t\t\teaseLinearity: ease,\n\t\t\t\t\t\tnoMoveStart: true,\n\t\t\t\t\t\tanimate: true\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tdragging: true,\n\t\t\tinertia: true,\n\t\t\tinertiaDeceleration: 3400, // px/s^2\n\t\t\tinertiaMaxSpeed: 1400, // px/s\n\t\t\teaseLinearity: 0.2,\n\t\t\t// TODO refactor, move to CRS\n\t\t\tworldCopyJump: false,\n\t\t\tmaxBoundsViscosity: 0.0\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'dragging', DragHandler);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;;;;CAIxC,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;CAKA,WAAW;EACV,IAAI,CAAC,KAAK,YAAY;GACrB,MAAM,MAAM,KAAK;GAEjB,KAAK,aAAa,IAAI,UAAU,IAAI,UAAU,IAAI,UAAU;GAE5D,KAAK,WAAW,GAAG;IAClB,MAAM,KAAK;IACX,WAAW,KAAK;IAChB,MAAM,KAAK;IACX,SAAS,KAAK;GACf,GAAG,IAAI;GAEP,KAAK,WAAW,GAAG,WAAW,KAAK,iBAAiB,IAAI;GACxD,IAAI,IAAI,QAAQ,eACf,KAAK,WAAW,GAAG,WAAW,KAAK,gBAAgB,IAAI;E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-14,6 +14,10 @@ import { Handler } from "../../core/Handler.js";
|
|
|
14
14
|
* navigate the map with keyboard arrows and `+`/`-` keys.
|
|
15
15
|
* @property {number} [keyboardPanDelta=80] Amount of pixels to pan when pressing an
|
|
16
16
|
* arrow key.
|
|
17
|
+
* @property {boolean|string} [ariaKeyShortcuts=false] Sets the `aria-keyshortcuts`
|
|
18
|
+
* attribute of the map container. ARIA names keys by what they type on a given layout,
|
|
19
|
+
* so `true` uses the names for a US English layout, which can be wrong for pages in
|
|
20
|
+
* other languages; pass a string to set the value for your audience's layout instead.
|
|
17
21
|
*/
|
|
18
22
|
/**
|
|
19
23
|
* Handler of `MaplairMap` for keyboard navigation.
|
|
@@ -30,26 +34,19 @@ import { Handler } from "../../core/Handler.js";
|
|
|
30
34
|
*/
|
|
31
35
|
var KeyboardHandler = class KeyboardHandler extends Handler {
|
|
32
36
|
/**
|
|
33
|
-
* The [
|
|
34
|
-
* of the keys for panning and zooming the map
|
|
37
|
+
* The [values](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
|
|
38
|
+
* of the keys for panning and zooming the map, so zoom keys follow the keyboard
|
|
39
|
+
* layout and cover the numpad too; `=` and `_` keep the US `+` and `-` keys working
|
|
40
|
+
* both with and without Shift.
|
|
35
41
|
* @type {Record<'left'|'right'|'down'|'up'|'zoomIn'|'zoomOut', string[]>}
|
|
36
42
|
*/
|
|
37
|
-
static
|
|
43
|
+
static keys = {
|
|
38
44
|
left: ["ArrowLeft"],
|
|
39
45
|
right: ["ArrowRight"],
|
|
40
46
|
down: ["ArrowDown"],
|
|
41
47
|
up: ["ArrowUp"],
|
|
42
|
-
zoomIn: [
|
|
43
|
-
|
|
44
|
-
"NumpadAdd",
|
|
45
|
-
"BracketRight"
|
|
46
|
-
],
|
|
47
|
-
zoomOut: [
|
|
48
|
-
"Minus",
|
|
49
|
-
"NumpadSubtract",
|
|
50
|
-
"Digit6",
|
|
51
|
-
"Slash"
|
|
52
|
-
]
|
|
48
|
+
zoomIn: ["+", "="],
|
|
49
|
+
zoomOut: ["-", "_"]
|
|
53
50
|
};
|
|
54
51
|
/**
|
|
55
52
|
* @param {MaplairMap} map
|
|
@@ -65,8 +62,9 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
|
|
|
65
62
|
*/
|
|
66
63
|
addHooks() {
|
|
67
64
|
const container = this._map._container;
|
|
68
|
-
if (container.tabIndex <= 0) container.tabIndex =
|
|
69
|
-
|
|
65
|
+
if (container.tabIndex <= 0) container.tabIndex = 0;
|
|
66
|
+
const shortcuts = this._map.options.ariaKeyShortcuts;
|
|
67
|
+
if (shortcuts) container.ariaKeyShortcuts = shortcuts === true ? "ArrowLeft ArrowRight ArrowUp ArrowDown = Plus -" : shortcuts;
|
|
70
68
|
on(container, {
|
|
71
69
|
focus: this._onFocus,
|
|
72
70
|
blur: this._onBlur,
|
|
@@ -82,6 +80,7 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
|
|
|
82
80
|
*/
|
|
83
81
|
removeHooks() {
|
|
84
82
|
this._removeHooks();
|
|
83
|
+
if (this._map.options.ariaKeyShortcuts) this._map._container.removeAttribute("aria-keyshortcuts");
|
|
85
84
|
off(this._map._container, {
|
|
86
85
|
focus: this._onFocus,
|
|
87
86
|
blur: this._onBlur,
|
|
@@ -128,9 +127,10 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
|
|
|
128
127
|
}
|
|
129
128
|
_onPointerDown() {
|
|
130
129
|
if (this._focused) return;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
this._map._container.focus({
|
|
131
|
+
preventScroll: true,
|
|
132
|
+
focusVisible: false
|
|
133
|
+
});
|
|
134
134
|
}
|
|
135
135
|
_onFocus() {
|
|
136
136
|
this._focused = true;
|
|
@@ -141,16 +141,16 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
|
|
|
141
141
|
this._map.fire("blur");
|
|
142
142
|
}
|
|
143
143
|
_setPanDelta(panDelta) {
|
|
144
|
-
const
|
|
145
|
-
for (const
|
|
146
|
-
for (const
|
|
147
|
-
for (const
|
|
148
|
-
for (const
|
|
144
|
+
const panKeys = this._panKeys = {}, { left, right, down, up } = KeyboardHandler.keys;
|
|
145
|
+
for (const key of left) panKeys[key] = [-panDelta, 0];
|
|
146
|
+
for (const key of right) panKeys[key] = [panDelta, 0];
|
|
147
|
+
for (const key of down) panKeys[key] = [0, panDelta];
|
|
148
|
+
for (const key of up) panKeys[key] = [0, -panDelta];
|
|
149
149
|
}
|
|
150
150
|
_setZoomDelta(zoomDelta) {
|
|
151
|
-
const
|
|
152
|
-
for (const
|
|
153
|
-
for (const
|
|
151
|
+
const zoomKeys = this._zoomKeys = {}, { zoomIn, zoomOut } = KeyboardHandler.keys;
|
|
152
|
+
for (const key of zoomIn) zoomKeys[key] = zoomDelta;
|
|
153
|
+
for (const key of zoomOut) zoomKeys[key] = -zoomDelta;
|
|
154
154
|
}
|
|
155
155
|
_addHooks() {
|
|
156
156
|
on(document, "keydown", this._onKeyDown, this);
|
|
@@ -165,7 +165,7 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
|
|
|
165
165
|
stop(e);
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
|
-
const key = e.
|
|
168
|
+
const key = e.key, map = this._map;
|
|
169
169
|
let offset;
|
|
170
170
|
if (key in this._panKeys) {
|
|
171
171
|
if (!map._panAnim || !map._panAnim._inProgress) {
|
|
@@ -173,14 +173,13 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
|
|
|
173
173
|
if (e.shiftKey) offset = Point.from(offset).multiplyBy(3);
|
|
174
174
|
if (map.options.maxBounds) offset = map._limitOffset(Point.from(offset), map.options.maxBounds);
|
|
175
175
|
map._setUserEvent(e);
|
|
176
|
-
|
|
177
|
-
const newLatLng = map.wrapLatLng(map.unproject(map.project(map.getCenter()).add(offset)));
|
|
178
|
-
map.panTo(newLatLng);
|
|
179
|
-
} else map.panBy(offset);
|
|
176
|
+
map.panBy(offset);
|
|
180
177
|
}
|
|
181
178
|
} else if (key in this._zoomKeys) {
|
|
182
|
-
map.
|
|
183
|
-
|
|
179
|
+
if (!map._zoomInputBlocked()) {
|
|
180
|
+
map._setUserEvent(e);
|
|
181
|
+
map.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]);
|
|
182
|
+
}
|
|
184
183
|
} else if (key === "Escape" && map._popup && map._popup.options.closeOnEscapeKey) map.closePopup();
|
|
185
184
|
else return;
|
|
186
185
|
stop(e);
|
|
@@ -193,7 +192,8 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
|
|
|
193
192
|
static register(MaplairMap) {
|
|
194
193
|
MaplairMap.mergeOptions({
|
|
195
194
|
keyboard: true,
|
|
196
|
-
keyboardPanDelta: 80
|
|
195
|
+
keyboardPanDelta: 80,
|
|
196
|
+
ariaKeyShortcuts: false
|
|
197
197
|
});
|
|
198
198
|
MaplairMap.addInitHook("addHandler", "keyboard", KeyboardHandler);
|
|
199
199
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyboardHandler.js","names":["DomUtil.create"],"sources":["../../../../src/map/handler/KeyboardHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport {on, off, stop, disableClickPropagation, disableScrollPropagation} from '../../dom/DomEvent.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport {I18n} from '../../core/I18n.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n\n/**\n * Map options of `KeyboardHandler`, the keyboard navigation options.\n * @typedef {object} KeyboardHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [keyboard=true] Makes the map focusable and allows users to\n * navigate the map with keyboard arrows and `+`/`-` keys.\n * @property {number} [keyboardPanDelta=80] Amount of pixels to pan when pressing an\n * arrow key.\n */\n\n/**\n * Handler of `MaplairMap` for keyboard navigation.\n * @typedef {object} KeyboardHandlerMapProperties\n * @lends MaplairMap\n * @property {KeyboardHandler} keyboard Keyboard navigation handler.\n */\n\n/**\n * Handles keyboard interaction with the map, enabled by default, see the map option\n * `keyboard`. The `?` key shows a list of the keyboard shortcuts.\n *\n * @fires MaplairMap#focus {MaplairEvent} Fired when the map gains focus.\n * @fires MaplairMap#blur {MaplairEvent} Fired when the map loses focus.\n */\nexport class KeyboardHandler extends Handler {\n\n\t/**\n\t * The [codes](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code)\n\t * of the keys for panning and zooming the map.\n\t * @type {Record<'left'|'right'|'down'|'up'|'zoomIn'|'zoomOut', string[]>}\n\t */\n\tstatic keyCodes = {\n\t\tleft: ['ArrowLeft'],\n\t\tright: ['ArrowRight'],\n\t\tdown: ['ArrowDown'],\n\t\tup: ['ArrowUp'],\n\t\tzoomIn: ['Equal', 'NumpadAdd', 'BracketRight'],\n\t\tzoomOut: ['Minus', 'NumpadSubtract', 'Digit6', 'Slash']\n\t};\n\n\t/**\n\t * @param {MaplairMap} map\n\t */\n\tconstructor(map) {\n\t\tsuper(map);\n\n\t\tthis._setPanDelta(map.options.keyboardPanDelta);\n\t\tthis._setZoomDelta(map.options.zoomDelta);\n\n\t\tthis.callInitHooks(KeyboardHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tconst container = this._map._container;\n\n\t\t// make the container focusable by tabbing\n\t\tif (container.tabIndex <= 0) {\n\t\t\tcontainer.tabIndex = '0';\n\t\t}\n\n\t\t// add aria-attribute for keyboard shortcuts to the container\n\t\tcontainer.ariaKeyShortcuts = Object.values(KeyboardHandler.keyCodes).flat().join(' ');\n\n\t\ton(container, {\n\t\t\tfocus: this._onFocus,\n\t\t\tblur: this._onBlur,\n\t\t\tpointerdown: this._onPointerDown\n\t\t}, this);\n\n\t\tthis._map.on({\n\t\t\tfocus: this._addHooks,\n\t\t\tblur: this._removeHooks\n\t\t}, this);\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._removeHooks();\n\n\t\toff(this._map._container, {\n\t\t\tfocus: this._onFocus,\n\t\t\tblur: this._onBlur,\n\t\t\tpointerdown: this._onPointerDown\n\t\t}, this);\n\n\t\tthis._map.off({\n\t\t\tfocus: this._addHooks,\n\t\t\tblur: this._removeHooks\n\t\t}, this);\n\n\t\tthis._help?.remove();\n\t\tthis._help = null;\n\t}\n\n\t// Shows or hides a list of the keyboard shortcuts (on the `?` key), as popover\n\t// closed by pressing `Escape` or clicking outside of it.\n\t_toggleHelp() {\n\t\tthis._help ??= this._createHelp();\n\t\tthis._help.togglePopover();\n\t}\n\n\t_createHelp() {\n\t\tconst help = DomUtil.create('div', 'maplair-keyboard-help', this._map._container),\n\t\ttitle = I18n.translate('Keyboard shortcuts');\n\t\thelp.popover = 'auto';\n\t\thelp.setAttribute('role', 'dialog');\n\t\thelp.setAttribute('aria-label', title);\n\n\t\tDomUtil.create('h2', '', help).textContent = title;\n\t\tconst list = DomUtil.create('dl', '', help);\n\t\tfor (const [keys, description] of [\n\t\t\t[['←', '→', '↑', '↓'], I18n.translate('Pan the map')],\n\t\t\t[['+'], I18n.translate('Zoom in')],\n\t\t\t[['−'], I18n.translate('Zoom out')],\n\t\t\t[['Shift'], I18n.translate('Pan or zoom further, together with the keys above')],\n\t\t\t[['Esc'], I18n.translate('Close popup')],\n\t\t\t[['?'], I18n.translate('Show or hide the keyboard shortcuts')]\n\t\t]) {\n\t\t\tconst row = DomUtil.create('div', '', list),\n\t\t\tdt = DomUtil.create('dt', '', row);\n\t\t\tfor (const key of keys) {\n\t\t\t\tDomUtil.create('kbd', '', dt).textContent = key;\n\t\t\t}\n\t\t\tDomUtil.create('dd', '', row).textContent = description;\n\t\t}\n\n\t\tdisableClickPropagation(help);\n\t\tdisableScrollPropagation(help);\n\t\treturn help;\n\t}\n\n\t// acquire/lose focus #594, #1228, #1540\n\t_onPointerDown() {\n\t\tif (this._focused) { return; }\n\n\t\tconst body = document.body,\n\t\tdocEl = document.documentElement,\n\t\ttop = body.scrollTop || docEl.scrollTop,\n\t\tleft = body.scrollLeft || docEl.scrollLeft;\n\n\t\tthis._map._container.focus();\n\n\t\twindow.scrollTo(left, top);\n\t}\n\n\t_onFocus() {\n\t\tthis._focused = true;\n\t\tthis._map.fire('focus');\n\t}\n\n\t_onBlur() {\n\t\tthis._focused = false;\n\t\tthis._map.fire('blur');\n\t}\n\n\t_setPanDelta(panDelta) {\n\t\tconst keys = this._panKeys = {},\n\t\tcodes = KeyboardHandler.keyCodes;\n\n\t\tfor (const code of codes.left) {\n\t\t\tkeys[code] = [-1 * panDelta, 0];\n\t\t}\n\t\tfor (const code of codes.right) {\n\t\t\tkeys[code] = [panDelta, 0];\n\t\t}\n\t\tfor (const code of codes.down) {\n\t\t\tkeys[code] = [0, panDelta];\n\t\t}\n\t\tfor (const code of codes.up) {\n\t\t\tkeys[code] = [0, -1 * panDelta];\n\t\t}\n\t}\n\n\t_setZoomDelta(zoomDelta) {\n\t\tconst keys = this._zoomKeys = {},\n\t\tcodes = KeyboardHandler.keyCodes;\n\n\t\tfor (const code of codes.zoomIn) {\n\t\t\tkeys[code] = zoomDelta;\n\t\t}\n\t\tfor (const code of codes.zoomOut) {\n\t\t\tkeys[code] = -zoomDelta;\n\t\t}\n\t}\n\n\t_addHooks() {\n\t\ton(document, 'keydown', this._onKeyDown, this);\n\t}\n\n\t_removeHooks() {\n\t\toff(document, 'keydown', this._onKeyDown, this);\n\t}\n\n\t_onKeyDown(e) {\n\t\tif (e.altKey || e.ctrlKey || e.metaKey) { return; }\n\n\t\tif (e.key === '?') {\n\t\t\tthis._toggleHelp();\n\t\t\tstop(e);\n\t\t\treturn;\n\t\t}\n\n\t\tconst key = e.code,\n\t\tmap = this._map;\n\t\tlet offset;\n\n\t\tif (key in this._panKeys) {\n\t\t\tif (!map._panAnim || !map._panAnim._inProgress) {\n\t\t\t\toffset = this._panKeys[key];\n\t\t\t\tif (e.shiftKey) {\n\t\t\t\t\toffset = Point.from(offset).multiplyBy(3);\n\t\t\t\t}\n\n\t\t\t\tif (map.options.maxBounds) {\n\t\t\t\t\toffset = map._limitOffset(Point.from(offset), map.options.maxBounds);\n\t\t\t\t}\n\n\t\t\t\tmap._setUserEvent(e);\n\t\t\t\tif (map.options.worldCopyJump) {\n\t\t\t\t\tconst newLatLng = map.wrapLatLng(map.unproject(map.project(map.getCenter()).add(offset)));\n\t\t\t\t\tmap.panTo(newLatLng);\n\t\t\t\t} else {\n\t\t\t\t\tmap.panBy(offset);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (key in this._zoomKeys) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]);\n\n\t\t} else if (key === 'Escape' && map._popup && map._popup.options.closeOnEscapeKey) {\n\t\t\tmap.closePopup();\n\n\t\t} else {\n\t\t\treturn;\n\t\t}\n\n\t\tstop(e);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tkeyboard: true,\n\t\t\tkeyboardPanDelta: 80\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'keyboard', KeyboardHandler);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,kBAAb,MAAa,wBAAwB,QAAQ;;;;;;CAO5C,OAAO,WAAW;EACjB,MAAM,CAAC,WAAW;EAClB,OAAO,CAAC,YAAY;EACpB,MAAM,CAAC,WAAW;EAClB,IAAI,CAAC,SAAS;EACd,QAAQ;GAAC;GAAS;GAAa;EAAc;EAC7C,SAAS;GAAC;GAAS;GAAkB;GAAU;EAAO;CACvD;;;;CAKA,YAAY,KAAK;EAChB,MAAM,GAAG;EAET,KAAK,aAAa,IAAI,QAAQ,gBAAgB;EAC9C,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AW,aAAa;GACvB,UAAU;GACV,kBAAkB;EACnB,CAAC;EAED,WAAW,YAAY,cAAc,YAAY,eAAe;CACjE;AACD"}
|
|
1
|
+
{"version":3,"file":"KeyboardHandler.js","names":["DomUtil.create"],"sources":["../../../../src/map/handler/KeyboardHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport {on, off, stop, disableClickPropagation, disableScrollPropagation} from '../../dom/DomEvent.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport {I18n} from '../../core/I18n.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n\n/**\n * Map options of `KeyboardHandler`, the keyboard navigation options.\n * @typedef {object} KeyboardHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [keyboard=true] Makes the map focusable and allows users to\n * navigate the map with keyboard arrows and `+`/`-` keys.\n * @property {number} [keyboardPanDelta=80] Amount of pixels to pan when pressing an\n * arrow key.\n * @property {boolean|string} [ariaKeyShortcuts=false] Sets the `aria-keyshortcuts`\n * attribute of the map container. ARIA names keys by what they type on a given layout,\n * so `true` uses the names for a US English layout, which can be wrong for pages in\n * other languages; pass a string to set the value for your audience's layout instead.\n */\n\n/**\n * Handler of `MaplairMap` for keyboard navigation.\n * @typedef {object} KeyboardHandlerMapProperties\n * @lends MaplairMap\n * @property {KeyboardHandler} keyboard Keyboard navigation handler.\n */\n\n/**\n * Handles keyboard interaction with the map, enabled by default, see the map option\n * `keyboard`. The `?` key shows a list of the keyboard shortcuts.\n *\n * @fires MaplairMap#focus {MaplairEvent} Fired when the map gains focus.\n * @fires MaplairMap#blur {MaplairEvent} Fired when the map loses focus.\n */\nexport class KeyboardHandler extends Handler {\n\n\t/**\n\t * The [values](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)\n\t * of the keys for panning and zooming the map, so zoom keys follow the keyboard\n\t * layout and cover the numpad too; `=` and `_` keep the US `+` and `-` keys working\n\t * both with and without Shift.\n\t * @type {Record<'left'|'right'|'down'|'up'|'zoomIn'|'zoomOut', string[]>}\n\t */\n\tstatic keys = {\n\t\tleft: ['ArrowLeft'],\n\t\tright: ['ArrowRight'],\n\t\tdown: ['ArrowDown'],\n\t\tup: ['ArrowUp'],\n\t\tzoomIn: ['+', '='],\n\t\tzoomOut: ['-', '_']\n\t};\n\n\t/**\n\t * @param {MaplairMap} map\n\t */\n\tconstructor(map) {\n\t\tsuper(map);\n\n\t\tthis._setPanDelta(map.options.keyboardPanDelta);\n\t\tthis._setZoomDelta(map.options.zoomDelta);\n\n\t\tthis.callInitHooks(KeyboardHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tconst container = this._map._container;\n\n\t\t// make the container focusable by tabbing\n\t\tif (container.tabIndex <= 0) {\n\t\t\tcontainer.tabIndex = 0;\n\t\t}\n\n\t\tconst shortcuts = this._map.options.ariaKeyShortcuts;\n\t\tif (shortcuts) {\n\t\t\t// ARIA names physical keys by their unshifted character, so the default is for a US layout\n\t\t\tcontainer.ariaKeyShortcuts = shortcuts === true ?\n\t\t\t\t'ArrowLeft ArrowRight ArrowUp ArrowDown = Plus -' : shortcuts;\n\t\t}\n\n\t\ton(container, {\n\t\t\tfocus: this._onFocus,\n\t\t\tblur: this._onBlur,\n\t\t\tpointerdown: this._onPointerDown\n\t\t}, this);\n\n\t\tthis._map.on({\n\t\t\tfocus: this._addHooks,\n\t\t\tblur: this._removeHooks\n\t\t}, this);\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._removeHooks();\n\n\t\tif (this._map.options.ariaKeyShortcuts) {\n\t\t\tthis._map._container.removeAttribute('aria-keyshortcuts');\n\t\t}\n\n\t\toff(this._map._container, {\n\t\t\tfocus: this._onFocus,\n\t\t\tblur: this._onBlur,\n\t\t\tpointerdown: this._onPointerDown\n\t\t}, this);\n\n\t\tthis._map.off({\n\t\t\tfocus: this._addHooks,\n\t\t\tblur: this._removeHooks\n\t\t}, this);\n\n\t\tthis._help?.remove();\n\t\tthis._help = null;\n\t}\n\n\t// Shows or hides a list of the keyboard shortcuts (on the `?` key), as popover\n\t// closed by pressing `Escape` or clicking outside of it.\n\t_toggleHelp() {\n\t\tthis._help ??= this._createHelp();\n\t\tthis._help.togglePopover();\n\t}\n\n\t_createHelp() {\n\t\tconst help = DomUtil.create('div', 'maplair-keyboard-help', this._map._container),\n\t\ttitle = I18n.translate('Keyboard shortcuts');\n\t\thelp.popover = 'auto';\n\t\thelp.setAttribute('role', 'dialog');\n\t\thelp.setAttribute('aria-label', title);\n\n\t\tDomUtil.create('h2', '', help).textContent = title;\n\t\tconst list = DomUtil.create('dl', '', help);\n\t\tfor (const [keys, description] of [\n\t\t\t[['←', '→', '↑', '↓'], I18n.translate('Pan the map')],\n\t\t\t[['+'], I18n.translate('Zoom in')],\n\t\t\t[['−'], I18n.translate('Zoom out')],\n\t\t\t[['Shift'], I18n.translate('Pan or zoom further, together with the keys above')],\n\t\t\t[['Esc'], I18n.translate('Close popup')],\n\t\t\t[['?'], I18n.translate('Show or hide the keyboard shortcuts')]\n\t\t]) {\n\t\t\tconst row = DomUtil.create('div', '', list),\n\t\t\tdt = DomUtil.create('dt', '', row);\n\t\t\tfor (const key of keys) {\n\t\t\t\tDomUtil.create('kbd', '', dt).textContent = key;\n\t\t\t}\n\t\t\tDomUtil.create('dd', '', row).textContent = description;\n\t\t}\n\n\t\tdisableClickPropagation(help);\n\t\tdisableScrollPropagation(help);\n\t\treturn help;\n\t}\n\n\t// acquire/lose focus #594, #1228, #1540\n\t_onPointerDown() {\n\t\tif (this._focused) { return; }\n\n\t\t// script focus matches :focus-visible by default, which would show a focus ring on every click\n\t\tthis._map._container.focus({preventScroll: true, focusVisible: false});\n\t}\n\n\t_onFocus() {\n\t\tthis._focused = true;\n\t\tthis._map.fire('focus');\n\t}\n\n\t_onBlur() {\n\t\tthis._focused = false;\n\t\tthis._map.fire('blur');\n\t}\n\n\t_setPanDelta(panDelta) {\n\t\tconst panKeys = this._panKeys = {},\n\t\t{left, right, down, up} = KeyboardHandler.keys;\n\n\t\tfor (const key of left) { panKeys[key] = [-panDelta, 0]; }\n\t\tfor (const key of right) { panKeys[key] = [panDelta, 0]; }\n\t\tfor (const key of down) { panKeys[key] = [0, panDelta]; }\n\t\tfor (const key of up) { panKeys[key] = [0, -panDelta]; }\n\t}\n\n\t_setZoomDelta(zoomDelta) {\n\t\tconst zoomKeys = this._zoomKeys = {},\n\t\t{zoomIn, zoomOut} = KeyboardHandler.keys;\n\n\t\tfor (const key of zoomIn) { zoomKeys[key] = zoomDelta; }\n\t\tfor (const key of zoomOut) { zoomKeys[key] = -zoomDelta; }\n\t}\n\n\t_addHooks() {\n\t\ton(document, 'keydown', this._onKeyDown, this);\n\t}\n\n\t_removeHooks() {\n\t\toff(document, 'keydown', this._onKeyDown, this);\n\t}\n\n\t_onKeyDown(e) {\n\t\tif (e.altKey || e.ctrlKey || e.metaKey) { return; }\n\n\t\tif (e.key === '?') {\n\t\t\tthis._toggleHelp();\n\t\t\tstop(e);\n\t\t\treturn;\n\t\t}\n\n\t\tconst key = e.key,\n\t\tmap = this._map;\n\t\tlet offset;\n\n\t\tif (key in this._panKeys) {\n\t\t\tif (!map._panAnim || !map._panAnim._inProgress) {\n\t\t\t\toffset = this._panKeys[key];\n\t\t\t\tif (e.shiftKey) {\n\t\t\t\t\toffset = Point.from(offset).multiplyBy(3);\n\t\t\t\t}\n\n\t\t\t\tif (map.options.maxBounds) {\n\t\t\t\t\toffset = map._limitOffset(Point.from(offset), map.options.maxBounds);\n\t\t\t\t}\n\n\t\t\t\tmap._setUserEvent(e);\n\t\t\t\tmap.panBy(offset);\n\t\t\t}\n\t\t} else if (key in this._zoomKeys) {\n\t\t\tif (!map._zoomInputBlocked()) {\n\t\t\t\tmap._setUserEvent(e);\n\t\t\t\tmap.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]);\n\t\t\t}\n\n\t\t} else if (key === 'Escape' && map._popup && map._popup.options.closeOnEscapeKey) {\n\t\t\tmap.closePopup();\n\n\t\t} else {\n\t\t\treturn;\n\t\t}\n\n\t\tstop(e);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tkeyboard: true,\n\t\t\tkeyboardPanDelta: 80,\n\t\t\tariaKeyShortcuts: false\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'keyboard', KeyboardHandler);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,kBAAb,MAAa,wBAAwB,QAAQ;;;;;;;;CAS5C,OAAO,OAAO;EACb,MAAM,CAAC,WAAW;EAClB,OAAO,CAAC,YAAY;EACpB,MAAM,CAAC,WAAW;EAClB,IAAI,CAAC,SAAS;EACd,QAAQ,CAAC,KAAK,GAAG;EACjB,SAAS,CAAC,KAAK,GAAG;CACnB;;;;CAKA,YAAY,KAAK;EAChB,MAAM,GAAG;EAET,KAAK,aAAa,IAAI,QAAQ,gBAAgB;EAC9C,KAAK,cAAc,IAAI,QAAQ,SAAS;EAExC,KAAK,cAAc,eAAe;CACnC;;;;CAKA,WAAW;EACV,MAAM,YAAY,KAAK,KAAK;EAG5B,IAAI,UAAU,YAAY,GACzB,UAAU,WAAW;EAGtB,MAAM,YAAY,KAAK,KAAK,QAAQ;EACpC,IAAI,WAEH,UAAU,mBAAmB,cAAc,OAC1C,oDAAoD;EAGtD,GAAG,WAAW;GACb,OAAO,KAAK;GACZ,MAAM,KAAK;GACX,aAAa,KAAK;EACnB,GAAG,IAAI;EAEP,KAAK,KAAK,GAAG;GACZ,OAAO,KAAK;GACZ,MAAM,KAAK;EACZ,GAAG,IAAI;CACR;;;;CAKA,cAAc;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AAO,KAAK,UACX;OAAA,CAAC,IAAI,YAAY,CAAC,IAAI,SAAS,aAAa;IAC/C,SAAS,KAAK,SAAS;IACvB,IAAI,EAAE,UACL,SAAS,MAAM,KAAK,MAAM,CAAC,CAAC,WAAW,CAAC;IAGzC,IAAI,IAAI,QAAQ,WACf,SAAS,IAAI,aAAa,MAAM,KAAK,MAAM,GAAG,IAAI,QAAQ,SAAS;IAGpE,IAAI,cAAc,CAAC;IACnB,IAAI,MAAM,MAAM;GACjB;SACM,IAAI,OAAO,KAAK,WAClB;OAAA,CAAC,IAAI,kBAAkB,GAAG;IAC7B,IAAI,cAAc,CAAC;IACnB,IAAI,QAAQ,IAAI,QAAQ,KAAK,EAAE,WAAW,IAAI,KAAK,KAAK,UAAU,IAAI;GACvE;SAEM,IAAI,QAAQ,YAAY,IAAI,UAAU,IAAI,OAAO,QAAQ,kBAC/D,IAAI,WAAW;OAGf;EAGD,KAAK,CAAC;CACP;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa;GACvB,UAAU;GACV,kBAAkB;GAClB,kBAAkB;EACnB,CAAC;EAED,WAAW,YAAY,cAAc,YAAY,eAAe;CACjE;AACD"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { Point } from "../../geometry/Point.js";
|
|
1
2
|
import { getPointers } from "../../dom/DomEvent.PointerEvents.js";
|
|
2
3
|
import { off, on } from "../../dom/DomEvent.js";
|
|
4
|
+
import { getScale } from "../../dom/DomUtil.js";
|
|
3
5
|
import { Handler } from "../../core/Handler.js";
|
|
4
6
|
//#region src/map/handler/PinchZoomHandler.js
|
|
5
7
|
/** @import {MaplairMap} from '../Map.js' */
|
|
@@ -54,7 +56,11 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
|
|
|
54
56
|
const map = this._map;
|
|
55
57
|
const pointers = getPointers();
|
|
56
58
|
if (pointers.length !== 2 || map._animatingZoom || this._zooming) return;
|
|
57
|
-
const p1 = map.pointerEventToContainerPoint(pointers[0])
|
|
59
|
+
const p1 = map.pointerEventToContainerPoint(pointers[0]);
|
|
60
|
+
const p2 = map.pointerEventToContainerPoint(pointers[1]);
|
|
61
|
+
const { x, y } = getScale(map._container);
|
|
62
|
+
this._containerScale = new Point(x, y);
|
|
63
|
+
this._containerOrigin = new Point(pointers[0].clientX, pointers[0].clientY)._subtract(p1.scaleBy(this._containerScale));
|
|
58
64
|
this._centerPoint = map.getSize()._divideBy(2);
|
|
59
65
|
this._startLatLng = map.containerPointToLatLng(this._centerPoint);
|
|
60
66
|
if (map.options.pinchZoom !== "center") this._pinchStartLatLng = map.containerPointToLatLng(p1.add(p2)._divideBy(2));
|
|
@@ -70,7 +76,7 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
|
|
|
70
76
|
_onPointerMove(e) {
|
|
71
77
|
const pointers = getPointers();
|
|
72
78
|
if (pointers.length !== 2 || !this._zooming) return;
|
|
73
|
-
const map = this._map, p1 =
|
|
79
|
+
const map = this._map, p1 = this._toContainerPoint(pointers[0]), p2 = this._toContainerPoint(pointers[1]), scale = p1.distanceTo(p2) / this._startDist;
|
|
74
80
|
this._zoom = map.getScaleZoom(scale, this._startZoom);
|
|
75
81
|
if (!map.options.bounceAtZoomLimits && (this._zoom < map.getMinZoom() && scale < 1 || this._zoom > map.getMaxZoom() && scale > 1)) this._zoom = map._limitZoom(this._zoom);
|
|
76
82
|
if (map.options.pinchZoom === "center") {
|
|
@@ -94,6 +100,9 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
|
|
|
94
100
|
this._animRequest = requestAnimationFrame(moveFn.bind(this));
|
|
95
101
|
e.preventDefault();
|
|
96
102
|
}
|
|
103
|
+
_toContainerPoint(e) {
|
|
104
|
+
return new Point(e.clientX, e.clientY)._subtract(this._containerOrigin).unscaleBy(this._containerScale);
|
|
105
|
+
}
|
|
97
106
|
_onPointerEnd() {
|
|
98
107
|
off(this._map._container, "pointermove", this._onPointerMove, this);
|
|
99
108
|
off(this._map._container, "pointerup pointercancel", this._onPointerEnd, this);
|
|
@@ -103,7 +112,7 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
|
|
|
103
112
|
}
|
|
104
113
|
this._zooming = false;
|
|
105
114
|
cancelAnimationFrame(this._animRequest);
|
|
106
|
-
if (this._map.
|
|
115
|
+
if (this._map._zoomAnimated) this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.zoomSnap);
|
|
107
116
|
else this._map._resetView(this._center, this._map._limitZoom(this._zoom));
|
|
108
117
|
}
|
|
109
118
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PinchZoomHandler.js","names":["PointerEvents.getPointers"],"sources":["../../../../src/map/handler/PinchZoomHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as PointerEvents from '../../dom/DomEvent.PointerEvents.js';\n/** @import {MaplairMap} from '../Map.js' */\n\n/**\n * Map options of `PinchZoomHandler`, touch interaction options.\n * @typedef {object} PinchZoomHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|'center'} [pinchZoom=true] Whether the map can be zoomed by\n * touch-dragging with two fingers. If passed `'center'`, it will zoom to the center of\n * the view regardless of where the touch events (fingers) were. Enabled for\n * touch-capable web browsers.\n * @property {boolean} [bounceAtZoomLimits=true] Set it to false if you don't want the\n * map to zoom beyond min/max zoom and then bounce back when pinch-zooming.\n * @property {boolean|'center'} [touchZoom] Deprecated, use `pinchZoom` instead.\n */\n\n/**\n * Handler of `MaplairMap` for pinch zoom.\n * @typedef {object} PinchZoomHandlerMapProperties\n * @lends MaplairMap\n * @property {PinchZoomHandler} pinchZoom Pinch zoom handler.\n * @property {PinchZoomHandler} touchZoom Deprecated, the same as `pinchZoom`.\n */\n\n/**\n * Adds pinch zoom to the map on supported mobile browsers, enabled by default, see the\n * map option `pinchZoom`.\n */\nexport class PinchZoomHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(PinchZoomHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tthis._map._container.classList.add('maplair-touch-zoom');\n\t\tDomEvent.on(this._map._container, 'pointerdown', this._onPointerStart, this);\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._map._container.classList.remove('maplair-touch-zoom');\n\t\tDomEvent.off(this._map._container, 'pointerdown', this._onPointerStart, this);\n\t\tDomEvent.off(this._map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(this._map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\t}\n\n\t_onPointerStart(e) {\n\t\tconst map = this._map;\n\n\t\tconst pointers = PointerEvents.getPointers();\n\t\tif (pointers.length !== 2 || map._animatingZoom || this._zooming) { return; }\n\n\t\tconst p1 = map.pointerEventToContainerPoint(pointers[0]),\n\t\tp2 = map.pointerEventToContainerPoint(pointers[1]);\n\n\t\tthis._centerPoint = map.getSize()._divideBy(2);\n\t\tthis._startLatLng = map.containerPointToLatLng(this._centerPoint);\n\t\tif (map.options.pinchZoom !== 'center') {\n\t\t\tthis._pinchStartLatLng = map.containerPointToLatLng(p1.add(p2)._divideBy(2));\n\t\t}\n\n\t\tthis._startDist = p1.distanceTo(p2);\n\t\tthis._startZoom = map.getZoom();\n\n\t\tthis._moved = false;\n\t\tthis._zooming = true;\n\n\t\tmap._stop();\n\n\t\tDomEvent.on(this._map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.on(this._map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\n\t\te.preventDefault();\n\t}\n\n\t_onPointerMove(e) {\n\t\tconst pointers = PointerEvents.getPointers();\n\t\tif (pointers.length !== 2 || !this._zooming) { return; }\n\n\t\tconst map = this._map,\n\t\tp1 = map.pointerEventToContainerPoint(pointers[0]),\n\t\tp2 = map.pointerEventToContainerPoint(pointers[1]),\n\t\tscale = p1.distanceTo(p2) / this._startDist;\n\n\t\tthis._zoom = map.getScaleZoom(scale, this._startZoom);\n\n\t\tif (!map.options.bounceAtZoomLimits && (\n\t\t\t(this._zoom < map.getMinZoom() && scale < 1) ||\n\t\t\t(this._zoom > map.getMaxZoom() && scale > 1))) {\n\t\t\tthis._zoom = map._limitZoom(this._zoom);\n\t\t}\n\n\t\tif (map.options.pinchZoom === 'center') {\n\t\t\tthis._center = this._startLatLng;\n\t\t\tif (scale === 1) { return; }\n\t\t} else {\n\t\t\t// Get delta from pinch to center, so centerLatLng is delta applied to initial pinchLatLng\n\t\t\tconst delta = p1._add(p2)._divideBy(2)._subtract(this._centerPoint);\n\t\t\tif (scale === 1 && delta.x === 0 && delta.y === 0) { return; }\n\t\t\tthis._center = map.unproject(map.project(this._pinchStartLatLng, this._zoom).subtract(delta), this._zoom);\n\t\t}\n\n\t\tif (!this._moved) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap._moveStart(true, false);\n\t\t\tthis._moved = true;\n\t\t}\n\n\t\tcancelAnimationFrame(this._animRequest);\n\n\t\tconst moveFn = map._move.bind(map, this._center, this._zoom, {pinch: true, round: false}, undefined);\n\t\tthis._animRequest = requestAnimationFrame(moveFn.bind(this));\n\n\t\te.preventDefault();\n\t}\n\n\t_onPointerEnd() {\n\t\tDomEvent.off(this._map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(this._map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\n\t\tif (!this._moved || !this._zooming) {\n\t\t\tthis._zooming = false;\n\t\t\treturn;\n\t\t}\n\n\t\tthis._zooming = false;\n\t\tcancelAnimationFrame(this._animRequest);\n\n\t\t// Pinch updates GridLayers' levels only when zoomSnap is off, so zoomSnap becomes noUpdate.\n\t\tif (this._map.options.zoomAnimation) {\n\t\t\tthis._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.zoomSnap);\n\t\t} else {\n\t\t\tthis._map._resetView(this._center, this._map._limitZoom(this._zoom));\n\t\t}\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tpinchZoom: true,\n\t\t\tbounceAtZoomLimits: true\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'pinchZoom', PinchZoomHandler);\n\n\t\t// Deprecated - Backward compatibility touchZoom\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tthis.touchZoom = this.pinchZoom;\n\n\t\t\tif (this.options.touchZoom !== undefined) {\n\t\t\t\t// To be removed in maplair 3\n\t\t\t\tconsole.warn('Map: touchZoom option is deprecated and will be removed in future versions. Use pinchZoom instead.');\n\t\t\t\tthis.options.pinchZoom = this.options.touchZoom;\n\t\t\t\tdelete this.options.touchZoom;\n\t\t\t}\n\t\t\tif (this.options.pinchZoom) {\n\t\t\t\tthis.pinchZoom.enable();\n\t\t\t} else {\n\t\t\t\tthis.pinchZoom.disable();\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAa,mBAAb,MAAa,yBAAyB,QAAQ;;;;CAI7C,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,gBAAgB;CACpC;;;;CAKA,WAAW;EACV,KAAK,KAAK,WAAW,UAAU,IAAI,oBAAoB;EACvD,GAAY,KAAK,KAAK,YAAY,eAAe,KAAK,iBAAiB,IAAI;CAC5E;;;;CAKA,cAAc;EACb,KAAK,KAAK,WAAW,UAAU,OAAO,oBAAoB;EAC1D,IAAa,KAAK,KAAK,YAAY,eAAe,KAAK,iBAAiB,IAAI;EAC5E,IAAa,KAAK,KAAK,YAAY,eAAe,KAAK,gBAAgB,IAAI;EAC3E,IAAa,KAAK,KAAK,YAAY,2BAA2B,KAAK,eAAe,IAAI;CACvF;CAEA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AAK,YAAY,KAAK;GAEtB,IAAI,KAAK,QAAQ,cAAc,KAAA,GAAW;IAEzC,QAAQ,KAAK,oGAAoG;IACjH,KAAK,QAAQ,YAAY,KAAK,QAAQ;IACtC,OAAO,KAAK,QAAQ;GACrB;GACA,IAAI,KAAK,QAAQ,WAChB,KAAK,UAAU,OAAO;QAEtB,KAAK,UAAU,QAAQ;EAEzB,CAAC;CACF;AACD"}
|
|
1
|
+
{"version":3,"file":"PinchZoomHandler.js","names":["PointerEvents.getPointers","DomUtil.getScale"],"sources":["../../../../src/map/handler/PinchZoomHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport * as PointerEvents from '../../dom/DomEvent.PointerEvents.js';\n/** @import {MaplairMap} from '../Map.js' */\n\n/**\n * Map options of `PinchZoomHandler`, touch interaction options.\n * @typedef {object} PinchZoomHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|'center'} [pinchZoom=true] Whether the map can be zoomed by\n * touch-dragging with two fingers. If passed `'center'`, it will zoom to the center of\n * the view regardless of where the touch events (fingers) were. Enabled for\n * touch-capable web browsers.\n * @property {boolean} [bounceAtZoomLimits=true] Set it to false if you don't want the\n * map to zoom beyond min/max zoom and then bounce back when pinch-zooming.\n * @property {boolean|'center'} [touchZoom] Deprecated, use `pinchZoom` instead.\n */\n\n/**\n * Handler of `MaplairMap` for pinch zoom.\n * @typedef {object} PinchZoomHandlerMapProperties\n * @lends MaplairMap\n * @property {PinchZoomHandler} pinchZoom Pinch zoom handler.\n * @property {PinchZoomHandler} touchZoom Deprecated, the same as `pinchZoom`.\n */\n\n/**\n * Adds pinch zoom to the map on supported mobile browsers, enabled by default, see the\n * map option `pinchZoom`.\n */\nexport class PinchZoomHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(PinchZoomHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tthis._map._container.classList.add('maplair-touch-zoom');\n\t\tDomEvent.on(this._map._container, 'pointerdown', this._onPointerStart, this);\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._map._container.classList.remove('maplair-touch-zoom');\n\t\tDomEvent.off(this._map._container, 'pointerdown', this._onPointerStart, this);\n\t\tDomEvent.off(this._map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(this._map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\t}\n\n\t_onPointerStart(e) {\n\t\tconst map = this._map;\n\n\t\tconst pointers = PointerEvents.getPointers();\n\t\tif (pointers.length !== 2 || map._animatingZoom || this._zooming) { return; }\n\n\t\tconst p1 = map.pointerEventToContainerPoint(pointers[0]);\n\t\tconst p2 = map.pointerEventToContainerPoint(pointers[1]);\n\t\tconst {x, y} = DomUtil.getScale(map._container);\n\n\t\t// the container doesn't move during a pinch, so keep its client offset and CSS scale to avoid reading layout on every move\n\t\tthis._containerScale = new Point(x, y);\n\t\tthis._containerOrigin = new Point(pointers[0].clientX, pointers[0].clientY)._subtract(p1.scaleBy(this._containerScale));\n\n\t\tthis._centerPoint = map.getSize()._divideBy(2);\n\t\tthis._startLatLng = map.containerPointToLatLng(this._centerPoint);\n\t\tif (map.options.pinchZoom !== 'center') {\n\t\t\tthis._pinchStartLatLng = map.containerPointToLatLng(p1.add(p2)._divideBy(2));\n\t\t}\n\n\t\tthis._startDist = p1.distanceTo(p2);\n\t\tthis._startZoom = map.getZoom();\n\n\t\tthis._moved = false;\n\t\tthis._zooming = true;\n\n\t\tmap._stop();\n\n\t\tDomEvent.on(this._map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.on(this._map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\n\t\te.preventDefault();\n\t}\n\n\t_onPointerMove(e) {\n\t\tconst pointers = PointerEvents.getPointers();\n\t\tif (pointers.length !== 2 || !this._zooming) { return; }\n\n\t\tconst map = this._map,\n\t\tp1 = this._toContainerPoint(pointers[0]),\n\t\tp2 = this._toContainerPoint(pointers[1]),\n\t\tscale = p1.distanceTo(p2) / this._startDist;\n\n\t\tthis._zoom = map.getScaleZoom(scale, this._startZoom);\n\n\t\tif (!map.options.bounceAtZoomLimits && (\n\t\t\t(this._zoom < map.getMinZoom() && scale < 1) ||\n\t\t\t(this._zoom > map.getMaxZoom() && scale > 1))) {\n\t\t\tthis._zoom = map._limitZoom(this._zoom);\n\t\t}\n\n\t\tif (map.options.pinchZoom === 'center') {\n\t\t\tthis._center = this._startLatLng;\n\t\t\tif (scale === 1) { return; }\n\t\t} else {\n\t\t\t// Get delta from pinch to center, so centerLatLng is delta applied to initial pinchLatLng\n\t\t\tconst delta = p1._add(p2)._divideBy(2)._subtract(this._centerPoint);\n\t\t\tif (scale === 1 && delta.x === 0 && delta.y === 0) { return; }\n\t\t\tthis._center = map.unproject(map.project(this._pinchStartLatLng, this._zoom).subtract(delta), this._zoom);\n\t\t}\n\n\t\tif (!this._moved) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap._moveStart(true, false);\n\t\t\tthis._moved = true;\n\t\t}\n\n\t\tcancelAnimationFrame(this._animRequest);\n\n\t\tconst moveFn = map._move.bind(map, this._center, this._zoom, {pinch: true, round: false}, undefined);\n\t\tthis._animRequest = requestAnimationFrame(moveFn.bind(this));\n\n\t\te.preventDefault();\n\t}\n\n\t_toContainerPoint(e) {\n\t\treturn new Point(e.clientX, e.clientY)._subtract(this._containerOrigin).unscaleBy(this._containerScale);\n\t}\n\n\t_onPointerEnd() {\n\t\tDomEvent.off(this._map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(this._map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\n\t\tif (!this._moved || !this._zooming) {\n\t\t\tthis._zooming = false;\n\t\t\treturn;\n\t\t}\n\n\t\tthis._zooming = false;\n\t\tcancelAnimationFrame(this._animRequest);\n\n\t\t// Pinch updates GridLayers' levels only when zoomSnap is off, so zoomSnap becomes noUpdate.\n\t\tif (this._map._zoomAnimated) {\n\t\t\tthis._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.zoomSnap);\n\t\t} else {\n\t\t\tthis._map._resetView(this._center, this._map._limitZoom(this._zoom));\n\t\t}\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tpinchZoom: true,\n\t\t\tbounceAtZoomLimits: true\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'pinchZoom', PinchZoomHandler);\n\n\t\t// Deprecated - Backward compatibility touchZoom\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tthis.touchZoom = this.pinchZoom;\n\n\t\t\tif (this.options.touchZoom !== undefined) {\n\t\t\t\t// To be removed in maplair 3\n\t\t\t\tconsole.warn('Map: touchZoom option is deprecated and will be removed in future versions. Use pinchZoom instead.');\n\t\t\t\tthis.options.pinchZoom = this.options.touchZoom;\n\t\t\t\tdelete this.options.touchZoom;\n\t\t\t}\n\t\t\tif (this.options.pinchZoom) {\n\t\t\t\tthis.pinchZoom.enable();\n\t\t\t} else {\n\t\t\t\tthis.pinchZoom.disable();\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,mBAAb,MAAa,yBAAyB,QAAQ;;;;CAI7C,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,gBAAgB;CACpC;;;;CAKA,WAAW;EACV,KAAK,KAAK,WAAW,UAAU,IAAI,oBAAoB;EACvD,GAAY,KAAK,KAAK,YAAY,eAAe,KAAK,iBAAiB,IAAI;CAC5E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AgB;EACf,IAAa,KAAK,KAAK,YAAY,eAAe,KAAK,gBAAgB,IAAI;EAC3E,IAAa,KAAK,KAAK,YAAY,2BAA2B,KAAK,eAAe,IAAI;EAEtF,IAAI,CAAC,KAAK,UAAU,CAAC,KAAK,UAAU;GACnC,KAAK,WAAW;GAChB;EACD;EAEA,KAAK,WAAW;EAChB,qBAAqB,KAAK,YAAY;EAGtC,IAAI,KAAK,KAAK,eACb,KAAK,KAAK,aAAa,KAAK,SAAS,KAAK,KAAK,WAAW,KAAK,KAAK,GAAG,MAAM,KAAK,KAAK,QAAQ,QAAQ;OAEvG,KAAK,KAAK,WAAW,KAAK,SAAS,KAAK,KAAK,WAAW,KAAK,KAAK,CAAC;CAErE;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa;GACvB,WAAW;GACX,oBAAoB;EACrB,CAAC;EAED,WAAW,YAAY,cAAc,aAAa,gBAAgB;EAGlE,WAAW,YAAY,WAAY;GAClC,KAAK,YAAY,KAAK;GAEtB,IAAI,KAAK,QAAQ,cAAc,KAAA,GAAW;IAEzC,QAAQ,KAAK,oGAAoG;IACjH,KAAK,QAAQ,YAAY,KAAK,QAAQ;IACtC,OAAO,KAAK,QAAQ;GACrB;GACA,IAAI,KAAK,QAAQ,WAChB,KAAK,UAAU,OAAO;QAEtB,KAAK,UAAU,QAAQ;EAEzB,CAAC;CACF;AACD"}
|
|
@@ -172,7 +172,6 @@ var ScrollWheelZoomHandler = class ScrollWheelZoomHandler extends Handler {
|
|
|
172
172
|
const delta = getWheelDelta(e);
|
|
173
173
|
const debounce = this._map.options.wheelDebounceTime;
|
|
174
174
|
this._delta += delta;
|
|
175
|
-
this._lastMousePos = this._map.pointerEventToContainerPoint(e);
|
|
176
175
|
this._lastEvent = e;
|
|
177
176
|
if (!this._startTime) this._startTime = Date.now();
|
|
178
177
|
const left = Math.max(debounce - (Date.now() - this._startTime), 0);
|
|
@@ -183,13 +182,13 @@ var ScrollWheelZoomHandler = class ScrollWheelZoomHandler extends Handler {
|
|
|
183
182
|
_performZoom() {
|
|
184
183
|
const map = this._map, zoom = map.getZoom(), snap = this._map.options.zoomSnap ?? 0;
|
|
185
184
|
map._stop();
|
|
186
|
-
const d2 = this._delta / (this._map.options.wheelPxPerZoomLevel * 4), d3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2, d4 = snap ? Math.ceil(d3 / snap) * snap : d3, delta = map._limitZoom(zoom + (this._delta > 0 ?
|
|
185
|
+
const d2 = this._delta / (this._map.options.wheelPxPerZoomLevel * 4), d3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2, d4 = snap ? Math.ceil(d3 / snap) * snap : d3, d5 = map._prefersReducedMotion() ? Math.min(d4, 1) : d4, delta = map._limitZoom(zoom + (this._delta > 0 ? d5 : -d5)) - zoom;
|
|
187
186
|
this._delta = 0;
|
|
188
187
|
this._startTime = null;
|
|
189
|
-
if (!delta) return;
|
|
188
|
+
if (!delta || map._zoomInputBlocked()) return;
|
|
190
189
|
map._setUserEvent(this._lastEvent);
|
|
191
190
|
if (map.options.scrollWheelZoom === "center") map.setZoom(zoom + delta);
|
|
192
|
-
else map.setZoomAround(this.
|
|
191
|
+
else map.setZoomAround(map.pointerEventToContainerPoint(this._lastEvent), zoom + delta);
|
|
193
192
|
}
|
|
194
193
|
/**
|
|
195
194
|
* Registers this default feature on the map class, called by `MaplairMap` itself.
|