maplair 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +89 -8
- package/dist/esm/control/AttributionControl.js +10 -10
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +0 -1
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -1
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +16 -11
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +0 -1
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +13 -9
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +0 -1
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +4 -5
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +3 -2
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/ZoomControl.js +13 -13
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Events.js +3 -2
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Util.js +16 -4
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +55 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +4 -7
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +5 -5
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +4 -6
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +23 -34
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +6 -3
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +2 -2
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +12 -17
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -7
- package/dist/esm/geometry/Transformation.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +1 -1
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +23 -23
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +7 -4
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +11 -6
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +30 -11
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +18 -35
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +2 -2
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +4 -8
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +16 -15
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +6 -7
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +49 -48
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/SvgIcon.js +1 -1
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +18 -16
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +9 -9
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +44 -93
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +7 -7
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +9 -1
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +10 -5
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +10 -11
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.js +19 -26
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +16 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +3 -3
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +6 -9
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +104 -49
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -4
- package/dist/esm/map/MapSync.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +2 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +68 -30
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +3 -5
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +3 -6
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -6
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -4
- package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +8 -20
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +698 -687
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +698 -687
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/en.json +1 -0
- package/package.json +1 -1
- package/src/control/AttributionControl.js +9 -9
- package/src/control/ButtonControl.js +0 -1
- package/src/control/ContextMenu.js +1 -1
- package/src/control/Control.js +13 -16
- package/src/control/FullscreenControl.js +0 -1
- package/src/control/LayersControl.js +14 -10
- package/src/control/RotateControl.js +0 -1
- package/src/control/ScaleControl.js +4 -5
- package/src/control/SideBySideControl.js +4 -2
- package/src/control/ZoomControl.js +10 -13
- package/src/core/Events.js +6 -2
- package/src/core/Util.js +16 -3
- package/src/dom/DomEvent.PointerEvents.js +47 -1
- package/src/dom/DomEvent.js +5 -17
- package/src/dom/DomUtil.js +5 -5
- package/src/dom/Draggable.js +5 -6
- package/src/geo/LatLng.js +22 -36
- package/src/geo/LatLngBounds.js +10 -4
- package/src/geometry/Bounds.js +3 -3
- package/src/geometry/Point.js +18 -26
- package/src/geometry/Transformation.js +1 -8
- package/src/layer/BlanketOverlay.js +1 -1
- package/src/layer/DivOverlay.js +28 -30
- package/src/layer/ImageOverlay.js +9 -7
- package/src/layer/Layer.js +18 -6
- package/src/layer/Popup.js +38 -17
- package/src/layer/Tooltip.js +17 -44
- package/src/layer/VideoOverlay.js +2 -2
- package/src/layer/marker/DivIcon.js +3 -6
- package/src/layer/marker/Icon.js +19 -18
- package/src/layer/marker/Marker.Drag.js +16 -18
- package/src/layer/marker/Marker.js +66 -59
- package/src/layer/marker/SvgIcon.js +1 -1
- package/src/layer/tile/GridLayer.js +21 -23
- package/src/layer/tile/TileLayer.js +17 -14
- package/src/layer/vector/Canvas.js +52 -148
- package/src/layer/vector/Circle.js +11 -9
- package/src/layer/vector/CircleMarker.js +11 -1
- package/src/layer/vector/Path.js +11 -5
- package/src/layer/vector/Polygon.js +11 -10
- package/src/layer/vector/Polyline.js +20 -21
- package/src/layer/vector/Renderer.getRenderer.js +2 -1
- package/src/layer/vector/Renderer.js +21 -3
- package/src/layer/vector/SVG.js +3 -3
- package/src/map/Map.Rotation.js +7 -6
- package/src/map/Map.js +135 -54
- package/src/map/MapSync.js +1 -1
- package/src/map/handler/BoxZoomHandler.js +2 -0
- package/src/map/handler/DisplaceHandler.js +53 -7
- package/src/map/handler/KeyboardHandler.js +5 -10
- package/src/map/handler/PinchZoomHandler.js +3 -3
- package/src/map/handler/ScrollWheelZoomHandler.js +3 -3
- package/src/map/handler/TapDragZoomHandler.js +1 -1
- package/src/map/handler/TapHoldHandler.js +13 -25
- package/src/maplair.css +38 -9
- package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
- package/src/dom/DomEvent.DoubleTap.js +0 -143
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Util.js","names":[],"sources":["../../../src/core/Util.js"],"sourcesContent":["// Util: various utility functions, used by Maplair internally.\n\n/**\n * Last unique ID used by [`stamp()`](#util-stamp).\n * @type {number}\n */\nexport let lastId = 0;\n\n/**\n * Returns the unique ID of an object, assigning it one if it doesn't have it.\n * @param {object} obj\n * @returns {number}\n */\nexport function stamp(obj) {\n\tif (!('_maplair_id' in obj)) {\n\t\tobj['_maplair_id'] = ++lastId;\n\t}\n\treturn obj._maplair_id;\n}\n\n/**\n * Returns a function which executes function `fn` with the given scope `context`\n * (so that the `this` keyword refers to `context` inside `fn`'s code). The function\n * `fn` will be called no more than one time per given amount of `time`. The arguments\n * received by the bound function will be any arguments passed when binding the\n * function, followed by any arguments passed when invoking the bound function.\n * @param {(...args: any[]) => void} fn\n * @param {number} time In milliseconds.\n * @param {object} [context]\n * @returns {(...args: any[]) => void}\n */\nexport function throttle(fn, time, context) {\n\tlet lock, queuedArgs;\n\n\tfunction later() {\n\t\t// reset lock and call if queued\n\t\tlock = false;\n\t\tif (queuedArgs) {\n\t\t\twrapperFn.apply(context, queuedArgs);\n\t\t\tqueuedArgs = false;\n\t\t}\n\t}\n\n\tfunction wrapperFn(...args) {\n\t\tif (lock) {\n\t\t\t// called too soon, queue to call later\n\t\t\tqueuedArgs = args;\n\n\t\t} else {\n\t\t\t// call and lock until later\n\t\t\tfn.apply(context, args);\n\t\t\tsetTimeout(later, time);\n\t\t\tlock = true;\n\t\t}\n\t}\n\n\treturn wrapperFn;\n}\n\n/**\n * Returns the number `x` modulo `range` in such a way so it lies within\n * `range[0]` and `range[1]`. The returned value will always be smaller than\n * `range[1]` unless `includeMax` is set to `true`.\n * @param {number} x\n * @param {[number, number]} range\n * @param {boolean} [includeMax]\n * @returns {number}\n */\nexport function wrapNum(x, range, includeMax) {\n\tconst max = range[1],\n\tmin = range[0],\n\td = max - min;\n\treturn x === max && includeMax ? x : ((x - min) % d + d) % d + min;\n}\n\n/**\n * A function which always returns `false`.\n * @returns {false}\n */\nexport function falseFn() { return false; }\n\n/**\n * Returns the number `num` rounded with specified `precision`.\n * The default `precision` value is 6 decimal places.\n * `false` can be passed to skip any processing (can be useful to avoid round-off errors).\n * @param {number} num\n * @param {number|false} [precision]\n * @returns {number}\n */\nexport function formatNum(num, precision) {\n\tif (precision === false) { return num; }\n\tconst pow = 10 **
|
|
1
|
+
{"version":3,"file":"Util.js","names":[],"sources":["../../../src/core/Util.js"],"sourcesContent":["// Util: various utility functions, used by Maplair internally.\n\n/**\n * Last unique ID used by [`stamp()`](#util-stamp).\n * @type {number}\n */\nexport let lastId = 0;\n\n/**\n * Returns the unique ID of an object, assigning it one if it doesn't have it.\n * @param {object} obj\n * @returns {number}\n */\nexport function stamp(obj) {\n\tif (!('_maplair_id' in obj)) {\n\t\tobj['_maplair_id'] = ++lastId;\n\t}\n\treturn obj._maplair_id;\n}\n\n/**\n * Returns a function which executes function `fn` with the given scope `context`\n * (so that the `this` keyword refers to `context` inside `fn`'s code). The function\n * `fn` will be called no more than one time per given amount of `time`. The arguments\n * received by the bound function will be any arguments passed when binding the\n * function, followed by any arguments passed when invoking the bound function.\n * @param {(...args: any[]) => void} fn\n * @param {number} time In milliseconds.\n * @param {object} [context]\n * @returns {(...args: any[]) => void}\n */\nexport function throttle(fn, time, context) {\n\tlet lock, queuedArgs;\n\n\tfunction later() {\n\t\t// reset lock and call if queued\n\t\tlock = false;\n\t\tif (queuedArgs) {\n\t\t\twrapperFn.apply(context, queuedArgs);\n\t\t\tqueuedArgs = false;\n\t\t}\n\t}\n\n\tfunction wrapperFn(...args) {\n\t\tif (lock) {\n\t\t\t// called too soon, queue to call later\n\t\t\tqueuedArgs = args;\n\n\t\t} else {\n\t\t\t// call and lock until later\n\t\t\tfn.apply(context, args);\n\t\t\tsetTimeout(later, time);\n\t\t\tlock = true;\n\t\t}\n\t}\n\n\treturn wrapperFn;\n}\n\n/**\n * Returns the number `x` modulo `range` in such a way so it lies within\n * `range[0]` and `range[1]`. The returned value will always be smaller than\n * `range[1]` unless `includeMax` is set to `true`.\n * @param {number} x\n * @param {[number, number]} range\n * @param {boolean} [includeMax]\n * @returns {number}\n */\nexport function wrapNum(x, range, includeMax) {\n\tconst max = range[1],\n\tmin = range[0],\n\td = max - min;\n\treturn x === max && includeMax ? x : ((x - min) % d + d) % d + min;\n}\n\n/**\n * A function which always returns `false`.\n * @returns {false}\n */\nexport function falseFn() { return false; }\n\n/**\n * Returns the number `num` rounded with specified `precision`.\n * The default `precision` value is 6 decimal places.\n * `false` can be passed to skip any processing (can be useful to avoid round-off errors).\n * @param {number} num\n * @param {number|false} [precision]\n * @returns {number}\n */\nexport function formatNum(num, precision = 6) {\n\tif (precision === false) { return num; }\n\tconst pow = 10 ** precision;\n\treturn Math.round(num * pow) / pow;\n}\n\n/**\n * Returns `value` if it's a number (including `Infinity`), converts it if it's a\n * numeric string, and returns `NaN` for anything else, unlike `Number()`, which turns\n * `''`, `null` and booleans into `0` or `1`.\n * @param {unknown} value\n * @returns {number}\n */\nexport function toNumber(value) {\n\treturn typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' ? +value : NaN;\n}\n\nconst WHITESPACE_RE = /\\s+/;\n\n/**\n * Trims and splits the string on whitespace and returns the array of parts.\n * @param {string} str\n * @returns {string[]}\n */\nexport function splitWords(str) {\n\t// a single word is the common case, and splitting allocates a lot more than the array\n\tconst trimmed = str.trim();\n\treturn WHITESPACE_RE.test(trimmed) ? trimmed.split(WHITESPACE_RE) : [trimmed];\n}\n\n/**\n * Merges the given properties to the `options` of the `obj` object, returning the\n * resulting options. See `Class options`.\n * @param {object} obj\n * @param {object} [options]\n * @returns {object}\n */\nexport function setOptions(obj, options) {\n\tif (!Object.hasOwn(obj, 'options')) {\n\t\tconst defaults = getDefaultOptions(obj.constructor) ?? obj.options;\n\t\tobj.options = defaults ? Object.create(defaults) : {};\n\t}\n\tfor (const i in options) {\n\t\tif (Object.hasOwn(options, i)) {\n\t\t\tobj.options[i] = options[i];\n\t\t}\n\t}\n\treturn obj.options;\n}\n\nconst chainedDefaults = new WeakMap(); // class -> the defaultOptions object it was chained with\n\n// Links the `defaultOptions` of each class in the chain to its parent's, so defaults are inherited and stay live.\n// Done on first use because a static field can't do it in its initializer and stay tree-shakeable.\nfunction getDefaultOptions(cls) {\n\tconst defaults = cls?.defaultOptions;\n\tif (defaults && chainedDefaults.get(cls) !== defaults) {\n\t\tfor (let c = cls; c.defaultOptions; c = Object.getPrototypeOf(c)) {\n\t\t\tif (Object.hasOwn(c, 'defaultOptions')) {\n\t\t\t\tObject.setPrototypeOf(c.defaultOptions, Object.getPrototypeOf(c).defaultOptions ?? Object.prototype);\n\t\t\t}\n\t\t}\n\t\tchainedDefaults.set(cls, defaults);\n\t}\n\treturn defaults;\n}\n\nconst templateRe = /\\{ *([\\w_ -]+) *\\}/g;\n\n/**\n * Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`\n * and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string\n * `('Hello foo, bar')`. You can also specify functions instead of strings for\n * data values — they will be evaluated passing `data` as an argument.\n * @param {string} str\n * @param {Record<string, any>} data\n * @returns {string}\n */\nexport function template(str, data) {\n\treturn str.replace(templateRe, (str, key) => {\n\t\tlet value = data[key];\n\n\t\tif (value === undefined) {\n\t\t\tthrow new Error(`No value provided for variable ${str}`);\n\n\t\t} else if (typeof value === 'function') {\n\t\t\tvalue = value(data);\n\t\t}\n\t\treturn value;\n\t});\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAMA,IAAW,SAAS;;;;;;AAOpB,SAAgB,MAAM,KAAK;CAC1B,IAAI,EAAE,iBAAiB,MACtB,IAAI,iBAAiB,EAAE;CAExB,OAAO,IAAI;AACZ;;;;;;;;;;;;AAaA,SAAgB,SAAS,IAAI,MAAM,SAAS;CAC3C,IAAI,MAAM;CAEV,SAAS,QAAQ;EAEhB,OAAO;EACP,IAAI,YAAY;GACf,UAAU,MAAM,SAAS,UAAU;GACnC,aAAa;EACd;CACD;CAEA,SAAS,UAAU,GAAG,MAAM;EAC3B,IAAI,MAEH,aAAa;OAEP;GAEN,GAAG,MAAM,SAAS,IAAI;GACtB,WAAW,OAAO,IAAI;GACtB,OAAO;EACR;CACD;CAEA,OAAO;AACR;;;;;;;;;;AAWA,SAAgB,QAAQ,GAAG,OAAO,YAAY;CAC7C,MAAM,MAAM,MAAM,IAClB,MAAM,MAAM,IACZ,IAAI,MAAM;CACV,OAAO,MAAM,OAAO,aAAa,MAAM,IAAI,OAAO,IAAI,KAAK,IAAI;AAChE;;;;;AAMA,SAAgB,UAAU;CAAE,OAAO;AAAO;;;;;;;;;AAU1C,SAAgB,UAAU,KAAK,YAAY,GAAG;CAC7C,IAAI,cAAc,OAAS,OAAO;CAClC,MAAM,MAAM,MAAM;CAClB,OAAO,KAAK,MAAM,MAAM,GAAG,IAAI;AAChC;;;;;;;;AASA,SAAgB,SAAS,OAAO;CAC/B,OAAO,OA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
@@ -3,9 +3,11 @@ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
|
3
3
|
var DomEvent_PointerEvents_exports = /* @__PURE__ */ __exportAll({
|
|
4
4
|
disablePointerDetection: () => disablePointerDetection,
|
|
5
5
|
enablePointerDetection: () => enablePointerDetection,
|
|
6
|
-
getPointers: () => getPointers
|
|
6
|
+
getPointers: () => getPointers,
|
|
7
|
+
simulateDblclick: () => simulateDblclick
|
|
7
8
|
});
|
|
8
9
|
const activePointers = /* @__PURE__ */ new Map();
|
|
10
|
+
let lastPointerType;
|
|
9
11
|
/**
|
|
10
12
|
* Enables pointer detection and capture for the document.
|
|
11
13
|
* @group Pointer detection
|
|
@@ -34,6 +36,7 @@ function disablePointerDetection(el) {
|
|
|
34
36
|
function _onSet(e) {
|
|
35
37
|
if (e.isTrusted) e.target.setPointerCapture(e.pointerId);
|
|
36
38
|
activePointers.set(e.pointerId, e);
|
|
39
|
+
lastPointerType = e.pointerType;
|
|
37
40
|
}
|
|
38
41
|
function _onUpdate(e) {
|
|
39
42
|
if (activePointers.has(e.pointerId)) activePointers.set(e.pointerId, e);
|
|
@@ -50,6 +53,56 @@ function _onDelete(e) {
|
|
|
50
53
|
function getPointers() {
|
|
51
54
|
return [...activePointers.values()];
|
|
52
55
|
}
|
|
53
|
-
|
|
56
|
+
const dblclickProps = [
|
|
57
|
+
"bubbles",
|
|
58
|
+
"cancelable",
|
|
59
|
+
"composed",
|
|
60
|
+
"view",
|
|
61
|
+
"screenX",
|
|
62
|
+
"screenY",
|
|
63
|
+
"clientX",
|
|
64
|
+
"clientY",
|
|
65
|
+
"ctrlKey",
|
|
66
|
+
"shiftKey",
|
|
67
|
+
"altKey",
|
|
68
|
+
"metaKey",
|
|
69
|
+
"button",
|
|
70
|
+
"buttons",
|
|
71
|
+
"relatedTarget"
|
|
72
|
+
];
|
|
73
|
+
let lastClickTime = 0;
|
|
74
|
+
let lastClick;
|
|
75
|
+
let lastClickMap;
|
|
76
|
+
let clickCount = 0;
|
|
77
|
+
/**
|
|
78
|
+
* Fires a `dblclick` on double tap where the browser doesn't (like iOS Safari),
|
|
79
|
+
* which is where it always reports `detail: 1` on clicks (see Leaflet#7012). The
|
|
80
|
+
* pointer type comes from `pointerdown`, because iOS Safari reports `mouse` on
|
|
81
|
+
* clicks from touch (WebKit bug 282988). Called by the map for clicks in it.
|
|
82
|
+
* @internal
|
|
83
|
+
* @param {MouseEvent} e
|
|
84
|
+
* @param {HTMLElement} mapContainer The container of the map, two taps make a double
|
|
85
|
+
* tap only in the same map.
|
|
86
|
+
* @returns {void}
|
|
87
|
+
*/
|
|
88
|
+
function simulateDblclick(e, mapContainer) {
|
|
89
|
+
if (e === lastClick) return;
|
|
90
|
+
lastClick = e;
|
|
91
|
+
const target = e.target;
|
|
92
|
+
if (e.detail !== 1 || lastPointerType === "mouse" || target.closest("label")) {
|
|
93
|
+
clickCount = 0;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const now = Date.now();
|
|
97
|
+
clickCount = now - lastClickTime <= 200 && mapContainer === lastClickMap ? clickCount + 1 : 1;
|
|
98
|
+
lastClickTime = now;
|
|
99
|
+
lastClickMap = mapContainer;
|
|
100
|
+
if (clickCount === 2) {
|
|
101
|
+
const init = { detail: 2 };
|
|
102
|
+
for (const prop of dblclickProps) init[prop] = e[prop];
|
|
103
|
+
target.dispatchEvent(new MouseEvent("dblclick", init));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export { DomEvent_PointerEvents_exports, disablePointerDetection, enablePointerDetection, getPointers, simulateDblclick };
|
|
54
107
|
|
|
55
108
|
//# sourceMappingURL=DomEvent.PointerEvents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomEvent.PointerEvents.js","names":[],"sources":["../../../src/dom/DomEvent.PointerEvents.js"],"sourcesContent":["// DomEvent.PointerEvents: detects the pointers that are currently active on the\n// document.\n\nconst activePointers = new Map();\n\n/**\n * Enables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction enablePointerDetection(el) {\n\tel.addEventListener('pointerdown', _onSet, {capture: true});\n\tel.addEventListener('pointermove', _onUpdate, {capture: true});\n\tel.addEventListener('pointerup', _onDelete, {capture: true});\n\tel.addEventListener('pointercancel', _onDelete, {capture: true});\n\tactivePointers.clear();\n}\n\n/**\n * Disables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction disablePointerDetection(el) {\n\tel.removeEventListener('pointerdown', _onSet, {capture: true});\n\tel.removeEventListener('pointermove', _onUpdate, {capture: true});\n\tel.removeEventListener('pointerup', _onDelete, {capture: true});\n\tel.removeEventListener('pointercancel', _onDelete, {capture: true});\n}\n\n// capturing throws for synthetic pointers the browser doesn't know about, so only capture real ones\nfunction _onSet(e) {\n\tif (e.isTrusted) { e.target.setPointerCapture(e.pointerId); }\n\tactivePointers.set(e.pointerId, e);\n}\n\nfunction _onUpdate(e) {\n\tif (activePointers.has(e.pointerId)) {\n\t\tactivePointers.set(e.pointerId, e);\n\t}\n}\n\nfunction _onDelete(e) {\n\t// released already if the document has nested maps (e.g. an overview map)\n\tif (e.target.hasPointerCapture(e.pointerId)) {\n\t\te.target.releasePointerCapture(e.pointerId);\n\t}\n\tactivePointers.delete(e.pointerId);\n}\n\n/**\n * Returns the active pointers on the document.\n * @group Pointer detection\n * @returns {PointerEvent[]}\n */\nfunction getPointers() {\n\treturn [...activePointers.values()];\n}\n\nexport {\n\tenablePointerDetection,\n\tdisablePointerDetection,\n\tgetPointers\n};\n\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DomEvent.PointerEvents.js","names":[],"sources":["../../../src/dom/DomEvent.PointerEvents.js"],"sourcesContent":["// DomEvent.PointerEvents: detects the pointers that are currently active on the\n// document.\n\nconst activePointers = new Map();\n\nlet lastPointerType;\n\n/**\n * Enables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction enablePointerDetection(el) {\n\tel.addEventListener('pointerdown', _onSet, {capture: true});\n\tel.addEventListener('pointermove', _onUpdate, {capture: true});\n\tel.addEventListener('pointerup', _onDelete, {capture: true});\n\tel.addEventListener('pointercancel', _onDelete, {capture: true});\n\tactivePointers.clear();\n}\n\n/**\n * Disables pointer detection and capture for the document.\n * @group Pointer detection\n * @param {EventTarget} el\n * @returns {void}\n */\nfunction disablePointerDetection(el) {\n\tel.removeEventListener('pointerdown', _onSet, {capture: true});\n\tel.removeEventListener('pointermove', _onUpdate, {capture: true});\n\tel.removeEventListener('pointerup', _onDelete, {capture: true});\n\tel.removeEventListener('pointercancel', _onDelete, {capture: true});\n}\n\n// capturing throws for synthetic pointers the browser doesn't know about, so only capture real ones\nfunction _onSet(e) {\n\tif (e.isTrusted) { e.target.setPointerCapture(e.pointerId); }\n\tactivePointers.set(e.pointerId, e);\n\tlastPointerType = e.pointerType;\n}\n\nfunction _onUpdate(e) {\n\tif (activePointers.has(e.pointerId)) {\n\t\tactivePointers.set(e.pointerId, e);\n\t}\n}\n\nfunction _onDelete(e) {\n\t// released already if the document has nested maps (e.g. an overview map)\n\tif (e.target.hasPointerCapture(e.pointerId)) {\n\t\te.target.releasePointerCapture(e.pointerId);\n\t}\n\tactivePointers.delete(e.pointerId);\n}\n\n/**\n * Returns the active pointers on the document.\n * @group Pointer detection\n * @returns {PointerEvent[]}\n */\nfunction getPointers() {\n\treturn [...activePointers.values()];\n}\n\nconst dblclickProps = ['bubbles', 'cancelable', 'composed', 'view', 'screenX', 'screenY', 'clientX', 'clientY',\n\t'ctrlKey', 'shiftKey', 'altKey', 'metaKey', 'button', 'buttons', 'relatedTarget'];\n\nlet lastClickTime = 0,\nlastClick,\nlastClickMap,\nclickCount = 0;\n\n/**\n * Fires a `dblclick` on double tap where the browser doesn't (like iOS Safari),\n * which is where it always reports `detail: 1` on clicks (see Leaflet#7012). The\n * pointer type comes from `pointerdown`, because iOS Safari reports `mouse` on\n * clicks from touch (WebKit bug 282988). Called by the map for clicks in it.\n * @internal\n * @param {MouseEvent} e\n * @param {HTMLElement} mapContainer The container of the map, two taps make a double\n * tap only in the same map.\n * @returns {void}\n */\nfunction simulateDblclick(e, mapContainer) {\n\t// a click in a nested map (e.g. an overview map) counts for the innermost one only\n\tif (e === lastClick) { return; }\n\tlastClick = e;\n\tconst target = e.target;\n\n\t// a click on a label is followed by a click on its input, so it would count as a double tap\n\tif (e.detail !== 1 || lastPointerType === 'mouse' || target.closest('label')) {\n\t\tclickCount = 0;\n\t\treturn;\n\t}\n\tconst now = Date.now();\n\tclickCount = now - lastClickTime <= 200 && mapContainer === lastClickMap ? clickCount + 1 : 1;\n\tlastClickTime = now;\n\tlastClickMap = mapContainer;\n\n\tif (clickCount === 2) {\n\t\tconst init = {detail: 2};\n\t\tfor (const prop of dblclickProps) { init[prop] = e[prop]; }\n\t\ttarget.dispatchEvent(new MouseEvent('dblclick', init));\n\t}\n}\n\nexport {\n\tenablePointerDetection,\n\tdisablePointerDetection,\n\tgetPointers,\n\tsimulateDblclick\n};\n\n"],"mappings":";;;;;;;;AAGA,MAAM,iCAAiB,IAAI,IAAI;AAE/B,IAAI;;;;;;;AAQJ,SAAS,uBAAuB,IAAI;CACnC,GAAG,iBAAiB,eAAe,QAAQ,EAAC,SAAS,KAAI,CAAC;CAC1D,GAAG,iBAAiB,eAAe,WAAW,EAAC,SAAS,KAAI,CAAC;CAC7D,GAAG,iBAAiB,aAAa,WAAW,EAAC,SAAS,KAAI,CAAC;CAC3D,GAAG,iBAAiB,iBAAiB,WAAW,EAAC,SAAS,KAAI,CAAC;CAC/D,eAAe,MAAM;AACtB;;;;;;;AAQA,SAAS,wBAAwB,IAAI;CACpC,GAAG,oBAAoB,eAAe,QAAQ,EAAC,SAAS,KAAI,CAAC;CAC7D,GAAG,oBAAoB,eAAe,WAAW,EAAC,SAAS,KAAI,CAAC;CAChE,GAAG,oBAAoB,aAAa,WAAW,EAAC,SAAS,KAAI,CAAC;CAC9D,GAAG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1,6 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { splitWords, stamp } from "../core/Util.js";
|
|
3
3
|
import { Point } from "../geometry/Point.js";
|
|
4
|
-
import { addDoubleTapListener, removeDoubleTapListener } from "./DomEvent.DoubleTap.js";
|
|
5
4
|
import { DomEvent_PointerEvents_exports } from "./DomEvent.PointerEvents.js";
|
|
6
5
|
import { getScale } from "./DomUtil.js";
|
|
7
6
|
// src/dom/DomEvent.js
|
|
@@ -71,11 +70,10 @@ function batchRemove(obj, filterFn) {
|
|
|
71
70
|
function addOne(obj, type, fn, context) {
|
|
72
71
|
const id = type + stamp(fn) + (context ? `_${stamp(context)}` : "");
|
|
73
72
|
if (obj[eventsKey] && obj[eventsKey][id]) return;
|
|
74
|
-
|
|
73
|
+
const handler = function(e) {
|
|
75
74
|
return fn.call(context || obj, e);
|
|
76
75
|
};
|
|
77
|
-
|
|
78
|
-
else obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
|
|
76
|
+
obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
|
|
79
77
|
obj[eventsKey] ??= {};
|
|
80
78
|
obj[eventsKey][id] = handler;
|
|
81
79
|
}
|
|
@@ -83,8 +81,7 @@ function removeOne(obj, type, fn, context, id) {
|
|
|
83
81
|
id ??= type + stamp(fn) + (context ? `_${stamp(context)}` : "");
|
|
84
82
|
const handler = obj[eventsKey] && obj[eventsKey][id];
|
|
85
83
|
if (!handler) return;
|
|
86
|
-
|
|
87
|
-
else obj.removeEventListener(type, handler, false);
|
|
84
|
+
obj.removeEventListener(type, handler, false);
|
|
88
85
|
obj[eventsKey][id] = null;
|
|
89
86
|
}
|
|
90
87
|
/**
|
|
@@ -170,7 +167,7 @@ function getWheelPxFactor() {
|
|
|
170
167
|
* @returns {number}
|
|
171
168
|
*/
|
|
172
169
|
function getWheelDelta(e) {
|
|
173
|
-
return e.deltaY
|
|
170
|
+
return -e.deltaY * (e.deltaMode ? e.deltaMode === 1 ? 20 : 60 : 1 / getWheelPxFactor()) || 0;
|
|
174
171
|
}
|
|
175
172
|
/**
|
|
176
173
|
* Checks if the pointer really left/entered the element `el` (for
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomEvent.js","names":["Util.splitWords","Util.stamp"],"sources":["../../../src/dom/DomEvent.js"],"sourcesContent":["import {Point} from '../geometry/Point.js';\nimport * as Util from '../core/Util.js';\nimport {addDoubleTapListener, removeDoubleTapListener} from './DomEvent.DoubleTap.js';\nimport {getScale} from './DomUtil.js';\n\nimport * as PointerEvents from './DomEvent.PointerEvents.js';\nexport {PointerEvents};\n\n// DomEvent: utility functions to work with the\n// [DOM events](https://developer.mozilla.org/docs/Web/API/Event), used by Maplair\n// internally. The functions return the `DomEvent` namespace for chaining.\n\n// Inspired by John Resig, Dean Edwards and YUI addEvent implementations.\n\n/**\n * Adds a listener function (`fn`) to a particular DOM event type of the\n * element `obj`. You can optionally specify the context of the listener\n * (object the `this` keyword will point to). You can also pass several\n * space-separated types (e.g. `'click dblclick'`). Alternatively, adds a set of\n * type/listener pairs, e.g. `{click: onClick, pointermove: onPointerMove}`, with the\n * context as third argument.\n * @param {EventTarget} obj\n * @param {string|Record<string, (ev: any) => void>} types\n * @param {((ev: any) => void)|object} [fn]\n * @param {object} [context]\n * @returns {void}\n */\nexport function on(obj, types, fn, context) {\n\n\tif (types && typeof types === 'object') {\n\t\tfor (const [type, listener] of Object.entries(types)) {\n\t\t\taddOne(obj, type, listener, fn);\n\t\t}\n\t} else {\n\t\tfor (const type of Util.splitWords(types)) {\n\t\t\taddOne(obj, type, fn, context);\n\t\t}\n\t}\n}\n\nconst eventsKey = '_maplair_events';\n\n/**\n * Removes a previously added listener function.\n * Note that if you passed a custom context to on, you must pass the same\n * context to `off` in order to remove the listener. Alternatively, removes a set of\n * type/listener pairs, e.g. `{click: onClick, pointermove: onPointerMove}`; with\n * `types` only, removes all previously added listeners of given types; with the\n * element only, removes all previously added listeners from the given element.\n * @param {EventTarget} obj\n * @param {string|Record<string, (ev: any) => void>} [types]\n * @param {((ev: any) => void)|object} [fn]\n * @param {object} [context]\n * @returns {void}\n */\nexport function off(obj, types, fn, context) {\n\n\tif (arguments.length === 1) {\n\t\tbatchRemove(obj);\n\t\tdelete obj[eventsKey];\n\n\t} else if (types && typeof types === 'object') {\n\t\tfor (const [type, listener] of Object.entries(types)) {\n\t\t\tremoveOne(obj, type, listener, fn);\n\t\t}\n\n\t} else {\n\t\ttypes = Util.splitWords(types);\n\n\t\tif (arguments.length === 2) {\n\t\t\tbatchRemove(obj, type => types.includes(type));\n\t\t} else {\n\t\t\tfor (const type of types) {\n\t\t\t\tremoveOne(obj, type, fn, context);\n\t\t\t}\n\t\t}\n\t}\n}\n\nconst DIGIT_RE = /\\d/;\n\nfunction batchRemove(obj, filterFn) {\n\tfor (const id of Object.keys(obj[eventsKey] ?? {})) {\n\t\tconst type = id.split(DIGIT_RE)[0];\n\t\tif (!filterFn || filterFn(type)) {\n\t\t\tremoveOne(obj, type, null, null, id);\n\t\t}\n\t}\n}\n\nfunction addOne(obj, type, fn, context) {\n\tconst id = type + Util.stamp(fn) + (context ? `_${Util.stamp(context)}` : '');\n\n\tif (obj[eventsKey] && obj[eventsKey][id]) { return; }\n\n\tlet handler = function (e) {\n\t\treturn fn.call(context || obj, e);\n\t};\n\n\tif (type === 'dblclick') {\n\t\thandler = addDoubleTapListener(obj, handler);\n\t} else {\n\t\tobj.addEventListener(type, handler, type === 'wheel' ? {passive: false} : false);\n\t}\n\n\tobj[eventsKey] ??= {};\n\tobj[eventsKey][id] = handler;\n}\n\nfunction removeOne(obj, type, fn, context, id) {\n\tid ??= type + Util.stamp(fn) + (context ? `_${Util.stamp(context)}` : '');\n\tconst handler = obj[eventsKey] && obj[eventsKey][id];\n\n\tif (!handler) { return; }\n\n\tif (type === 'dblclick') {\n\t\tremoveDoubleTapListener(obj, handler);\n\t} else {\n\t\tobj.removeEventListener(type, handler, false);\n\t}\n\n\tobj[eventsKey][id] = null;\n}\n\n/**\n * Stop the given event from propagation to parent elements. Used inside the listener\n * functions:\n * ```js\n * DomEvent.on(div, 'click', DomEvent.stopPropagation);\n * ```\n * Also accepts a Maplair event with an `originalEvent`.\n * @param {Event|{originalEvent: Event}} e\n * @returns {void}\n */\nexport function stopPropagation(e) {\n\n\t// feature detection rather than `instanceof Event`, which fails for events from other windows (e.g. iframes)\n\tif (e.stopPropagation) {\n\t\te.stopPropagation();\n\t} else if (e.originalEvent) { // In case of Maplair event.\n\t\te.originalEvent._stopped = true;\n\t} else {\n\t\t// custom Maplair event\n\t\tconsole.debug('Unsupported event', e);\n\t}\n}\n\n/**\n * Adds `stopPropagation` to the element's `'wheel'` events (plus browser variants).\n * @param {HTMLElement} el\n * @returns {void}\n */\nexport function disableScrollPropagation(el) {\n\taddOne(el, 'wheel', stopPropagation);\n}\n\n/**\n * Adds `stopPropagation` to the element's `'dblclick'`, `'contextmenu'`\n * and `'pointerdown'` events (plus browser variants).\n * For `'click'` events, prevents the map from handling the click\n * while still allowing the native DOM click event to propagate normally.\n * @param {HTMLElement} el\n * @returns {void}\n */\nexport function disableClickPropagation(el) {\n\ton(el, 'pointerdown dblclick contextmenu', stopPropagation);\n\tel['_maplair_disable_click'] = true;\n}\n\n/**\n * Prevents the default action of the DOM Event `e` from happening (such as\n * following a link in the href of the a element, or doing a POST request\n * with page reload when a `<form>` is submitted).\n * Use it inside listener functions.\n * @param {Event} e\n * @returns {void}\n */\nexport function preventDefault(e) {\n\te.preventDefault?.();\n}\n\n/**\n * Does `stopPropagation` and `preventDefault` at the same time.\n * @param {Event} e\n * @returns {void}\n */\nexport function stop(e) {\n\tpreventDefault(e);\n\tstopPropagation(e);\n}\n\n/**\n * Gets normalized pointer position from a DOM event relative to the\n * `container` (border excluded) or to the whole page if not specified.\n * @param {MouseEvent|Touch} e\n * @param {HTMLElement} [container]\n * @returns {Point}\n */\nexport function getPointerPosition(e, container) {\n\tif (!container) {\n\t\treturn new Point(e.clientX, e.clientY);\n\t}\n\n\tconst scale = getScale(container),\n\toffset = scale.boundingClientRect; // left and top values are in page scale (like the event clientX/Y)\n\n\treturn new Point(\n\t\t// offset.left/top values are in page scale (like clientX/Y),\n\t\t// whereas clientLeft/Top (border width) values are the original values (before CSS scale applies).\n\t\t(e.clientX - offset.left) / scale.x - container.clientLeft,\n\t\t(e.clientY - offset.top) / scale.y - container.clientTop\n\t);\n}\n\n/**\n * Gets the wheel pixel factor based on the devicePixelRatio.\n * @returns {number}\n */\nexport function getWheelPxFactor() {\n\t// We need double the scroll pixels (see #7403 and #4538)\n\treturn window.devicePixelRatio * 2;\n}\n\n/**\n * Gets normalized wheel delta from a wheel DOM event, in vertical\n * pixels scrolled (negative if scrolling down).\n * Events from pointing devices without precise scrolling are mapped to\n * a best guess of 60 pixels.\n * @param {WheelEvent} e\n * @returns {number}\n */\nexport function getWheelDelta(e) {\n\treturn (e.deltaY && e.deltaMode === 0) ? -e.deltaY / getWheelPxFactor() : // Pixels\n\t\t(e.deltaY && e.deltaMode === 1) ? -e.deltaY * 20 : // Lines\n\t\t(e.deltaY && e.deltaMode === 2) ? -e.deltaY * 60 : // Pages\n\t\t(e.deltaX || e.deltaZ) ? 0 :\t// Skip horizontal/depth wheel events\n\t\t0;\n}\n\n/**\n * Checks if the pointer really left/entered the element `el` (for\n * `pointerover`/`pointerout`).\n * @internal\n * @param {Node} el\n * @param {MouseEvent} e\n * @returns {boolean}\n */\nexport function isExternalTarget(el, e) {\n\treturn !el.contains(e.relatedTarget);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,GAAG,KAAK,OAAO,IAAI,SAAS;CAE3C,IAAI,SAAS,OAAO,UAAU,UAC7B,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,KAAK,GAClD,OAAO,KAAK,MAAM,UAAU,EAAE;MAG/B,KAAK,MAAM,QAAQA,WAAgB,KAAK,GACvC,OAAO,KAAK,MAAM,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UAAU,EAAE,cAAc,IAAK,CAAC,EAAE,SAAS,KAC7C,EAAE,UAAU,EAAE,SAAU,IACzB;AACF;;;;;;;;;AAUA,SAAgB,iBAAiB,IAAI,GAAG;CACvC,OAAO,CAAC,GAAG,SAAS,EAAE,aAAa;AACpC"}
|
|
1
|
+
{"version":3,"file":"DomEvent.js","names":["Util.splitWords","Util.stamp"],"sources":["../../../src/dom/DomEvent.js"],"sourcesContent":["import {Point} from '../geometry/Point.js';\nimport * as Util from '../core/Util.js';\nimport {getScale} from './DomUtil.js';\n\nimport * as PointerEvents from './DomEvent.PointerEvents.js';\nexport {PointerEvents};\n\n// DomEvent: utility functions to work with the\n// [DOM events](https://developer.mozilla.org/docs/Web/API/Event), used by Maplair\n// internally. The functions return the `DomEvent` namespace for chaining.\n\n// Inspired by John Resig, Dean Edwards and YUI addEvent implementations.\n\n/**\n * Adds a listener function (`fn`) to a particular DOM event type of the\n * element `obj`. You can optionally specify the context of the listener\n * (object the `this` keyword will point to). You can also pass several\n * space-separated types (e.g. `'click dblclick'`). Alternatively, adds a set of\n * type/listener pairs, e.g. `{click: onClick, pointermove: onPointerMove}`, with the\n * context as third argument.\n * @param {EventTarget} obj\n * @param {string|Record<string, (ev: any) => void>} types\n * @param {((ev: any) => void)|object} [fn]\n * @param {object} [context]\n * @returns {void}\n */\nexport function on(obj, types, fn, context) {\n\n\tif (types && typeof types === 'object') {\n\t\tfor (const [type, listener] of Object.entries(types)) {\n\t\t\taddOne(obj, type, listener, fn);\n\t\t}\n\t} else {\n\t\tfor (const type of Util.splitWords(types)) {\n\t\t\taddOne(obj, type, fn, context);\n\t\t}\n\t}\n}\n\nconst eventsKey = '_maplair_events';\n\n/**\n * Removes a previously added listener function.\n * Note that if you passed a custom context to on, you must pass the same\n * context to `off` in order to remove the listener. Alternatively, removes a set of\n * type/listener pairs, e.g. `{click: onClick, pointermove: onPointerMove}`; with\n * `types` only, removes all previously added listeners of given types; with the\n * element only, removes all previously added listeners from the given element.\n * @param {EventTarget} obj\n * @param {string|Record<string, (ev: any) => void>} [types]\n * @param {((ev: any) => void)|object} [fn]\n * @param {object} [context]\n * @returns {void}\n */\nexport function off(obj, types, fn, context) {\n\n\tif (arguments.length === 1) {\n\t\tbatchRemove(obj);\n\t\tdelete obj[eventsKey];\n\n\t} else if (types && typeof types === 'object') {\n\t\tfor (const [type, listener] of Object.entries(types)) {\n\t\t\tremoveOne(obj, type, listener, fn);\n\t\t}\n\n\t} else {\n\t\ttypes = Util.splitWords(types);\n\n\t\tif (arguments.length === 2) {\n\t\t\tbatchRemove(obj, type => types.includes(type));\n\t\t} else {\n\t\t\tfor (const type of types) {\n\t\t\t\tremoveOne(obj, type, fn, context);\n\t\t\t}\n\t\t}\n\t}\n}\n\nconst DIGIT_RE = /\\d/;\n\nfunction batchRemove(obj, filterFn) {\n\tfor (const id of Object.keys(obj[eventsKey] ?? {})) {\n\t\tconst type = id.split(DIGIT_RE)[0];\n\t\tif (!filterFn || filterFn(type)) {\n\t\t\tremoveOne(obj, type, null, null, id);\n\t\t}\n\t}\n}\n\nfunction addOne(obj, type, fn, context) {\n\tconst id = type + Util.stamp(fn) + (context ? `_${Util.stamp(context)}` : '');\n\n\tif (obj[eventsKey] && obj[eventsKey][id]) { return; }\n\n\tconst handler = function (e) {\n\t\treturn fn.call(context || obj, e);\n\t};\n\n\tobj.addEventListener(type, handler, type === 'wheel' ? {passive: false} : false);\n\n\tobj[eventsKey] ??= {};\n\tobj[eventsKey][id] = handler;\n}\n\nfunction removeOne(obj, type, fn, context, id) {\n\tid ??= type + Util.stamp(fn) + (context ? `_${Util.stamp(context)}` : '');\n\tconst handler = obj[eventsKey] && obj[eventsKey][id];\n\n\tif (!handler) { return; }\n\n\tobj.removeEventListener(type, handler, false);\n\n\tobj[eventsKey][id] = null;\n}\n\n/**\n * Stop the given event from propagation to parent elements. Used inside the listener\n * functions:\n * ```js\n * DomEvent.on(div, 'click', DomEvent.stopPropagation);\n * ```\n * Also accepts a Maplair event with an `originalEvent`.\n * @param {Event|{originalEvent: Event}} e\n * @returns {void}\n */\nexport function stopPropagation(e) {\n\n\t// feature detection rather than `instanceof Event`, which fails for events from other windows (e.g. iframes)\n\tif (e.stopPropagation) {\n\t\te.stopPropagation();\n\t} else if (e.originalEvent) { // In case of Maplair event.\n\t\te.originalEvent._stopped = true;\n\t} else {\n\t\t// custom Maplair event\n\t\tconsole.debug('Unsupported event', e);\n\t}\n}\n\n/**\n * Adds `stopPropagation` to the element's `'wheel'` events (plus browser variants).\n * @param {HTMLElement} el\n * @returns {void}\n */\nexport function disableScrollPropagation(el) {\n\taddOne(el, 'wheel', stopPropagation);\n}\n\n/**\n * Adds `stopPropagation` to the element's `'dblclick'`, `'contextmenu'`\n * and `'pointerdown'` events (plus browser variants).\n * For `'click'` events, prevents the map from handling the click\n * while still allowing the native DOM click event to propagate normally.\n * @param {HTMLElement} el\n * @returns {void}\n */\nexport function disableClickPropagation(el) {\n\ton(el, 'pointerdown dblclick contextmenu', stopPropagation);\n\tel['_maplair_disable_click'] = true;\n}\n\n/**\n * Prevents the default action of the DOM Event `e` from happening (such as\n * following a link in the href of the a element, or doing a POST request\n * with page reload when a `<form>` is submitted).\n * Use it inside listener functions.\n * @param {Event} e\n * @returns {void}\n */\nexport function preventDefault(e) {\n\te.preventDefault?.();\n}\n\n/**\n * Does `stopPropagation` and `preventDefault` at the same time.\n * @param {Event} e\n * @returns {void}\n */\nexport function stop(e) {\n\tpreventDefault(e);\n\tstopPropagation(e);\n}\n\n/**\n * Gets normalized pointer position from a DOM event relative to the\n * `container` (border excluded) or to the whole page if not specified.\n * @param {MouseEvent|Touch} e\n * @param {HTMLElement} [container]\n * @returns {Point}\n */\nexport function getPointerPosition(e, container) {\n\tif (!container) {\n\t\treturn new Point(e.clientX, e.clientY);\n\t}\n\n\tconst scale = getScale(container),\n\toffset = scale.boundingClientRect; // left and top values are in page scale (like the event clientX/Y)\n\n\treturn new Point(\n\t\t// offset.left/top values are in page scale (like clientX/Y),\n\t\t// whereas clientLeft/Top (border width) values are the original values (before CSS scale applies).\n\t\t(e.clientX - offset.left) / scale.x - container.clientLeft,\n\t\t(e.clientY - offset.top) / scale.y - container.clientTop\n\t);\n}\n\n/**\n * Gets the wheel pixel factor based on the devicePixelRatio.\n * @returns {number}\n */\nexport function getWheelPxFactor() {\n\t// We need double the scroll pixels (see #7403 and #4538)\n\treturn window.devicePixelRatio * 2;\n}\n\n/**\n * Gets normalized wheel delta from a wheel DOM event, in vertical\n * pixels scrolled (negative if scrolling down).\n * Events from pointing devices without precise scrolling are mapped to\n * a best guess of 60 pixels.\n * @param {WheelEvent} e\n * @returns {number}\n */\nexport function getWheelDelta(e) {\n\t// scaled per delta mode: pixels, lines, pages; horizontal and depth scrolling give 0\n\treturn -e.deltaY * (e.deltaMode ? e.deltaMode === 1 ? 20 : 60 : 1 / getWheelPxFactor()) || 0;\n}\n\n/**\n * Checks if the pointer really left/entered the element `el` (for\n * `pointerover`/`pointerout`).\n * @internal\n * @param {Node} el\n * @param {MouseEvent} e\n * @returns {boolean}\n */\nexport function isExternalTarget(el, e) {\n\treturn !el.contains(e.relatedTarget);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,GAAG,KAAK,OAAO,IAAI,SAAS;CAE3C,IAAI,SAAS,OAAO,UAAU,UAC7B,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,KAAK,GAClD,OAAO,KAAK,MAAM,UAAU,EAAE;MAG/B,KAAK,MAAM,QAAQA,WAAgB,KAAK,GACvC,OAAO,KAAK,MAAM,IAAI,OAAO;AAGhC;AAEA,MAAM,YAAY;;;;;;;;;;;;;;AAelB,SAAgB,IAAI,KAAK,OAAO,IAAI,SAAS;CAE5C,IAAI,UAAU,WAAW,GAAG;EAC3B,YAAY,GAAG;EACf,OAAO,IAAI;CAEZ,OAAO,IAAI,SAAS,OAAO,UAAU,UACpC,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,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,EAAE,cAAc,WAAW;MAG3B,QAAQ,MAAM,qBAAqB,CAAC;AAEtC;;;;;;AAOA,SAAgB,yBAAyB,IAAI;CAC5C,OAAO,IAAI,SAAS,eAAe;AACpC;;;;;;;;;AAUA,SAAgB,wBAAwB,IAAI;CAC3C,GAAG,IAAI,oCAAoC,eAAe;CAC1D,GAAG,4BAA4B;AAChC;;;;;;;;;AAUA,SAAgB,eAAe,GAAG;CACjC,EAAE,iBAAiB;AACpB;;;;;;AAOA,SAAgB,KAAK,GAAG;CACvB,eAAe,CAAC;CAChB,gBAAgB,CAAC;AAClB;;;;;;;;AASA,SAAgB,mBAAmB,GAAG,WAAW;CAChD,IAAI,CAAC,WACJ,OAAO,IAAI,MAAM,EAAE,SAAS,EAAE,OAAO;CAGtC,MAAM,QAAQ,SAAS,SAAS,GAChC,SAAS,MAAM;CAEf,OAAO,IAAI,OAGT,EAAE,UAAU,OAAO,QAAQ,MAAM,IAAI,UAAU,aAC/C,EAAE,UAAU,OAAO,OAAO,MAAM,IAAI,UAAU,SAChD;AACD;;;;;AAMA,SAAgB,mBAAmB;CAElC,OAAO,OAAO,mBAAmB;AAClC;;;;;;;;;AAUA,SAAgB,cAAc,GAAG;CAEhC,OAAO,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,IAAI,KAAK,KAAK,IAAI,iBAAiB,MAAM;AAC5F;;;;;;;;;AAUA,SAAgB,iBAAiB,IAAI,GAAG;CACvC,OAAO,CAAC,GAAG,SAAS,EAAE,aAAa;AACpC"}
|
package/dist/esm/dom/DomUtil.js
CHANGED
|
@@ -35,7 +35,7 @@ function get(id) {
|
|
|
35
35
|
function create(tagName, className, container) {
|
|
36
36
|
const el = document.createElement(tagName);
|
|
37
37
|
el.className = className ?? "";
|
|
38
|
-
container?.
|
|
38
|
+
container?.append(el);
|
|
39
39
|
return el;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
@@ -47,8 +47,8 @@ function create(tagName, className, container) {
|
|
|
47
47
|
function toFront(el) {
|
|
48
48
|
const parent = el.parentNode;
|
|
49
49
|
if (!parent || parent.lastChild === el) return;
|
|
50
|
-
if (el.matches(":hover")) while (el.nextSibling)
|
|
51
|
-
else parent.
|
|
50
|
+
if (el.matches(":hover")) while (el.nextSibling) el.before(el.nextSibling);
|
|
51
|
+
else parent.append(el);
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Makes `el` the first child of its parent, so it renders behind the other children.
|
|
@@ -58,8 +58,8 @@ function toFront(el) {
|
|
|
58
58
|
function toBack(el) {
|
|
59
59
|
const parent = el.parentNode;
|
|
60
60
|
if (!parent || parent.firstChild === el) return;
|
|
61
|
-
if (el.matches(":hover")) while (el.previousSibling)
|
|
62
|
-
else parent.
|
|
61
|
+
if (el.matches(":hover")) while (el.previousSibling) el.after(el.previousSibling);
|
|
62
|
+
else parent.prepend(el);
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* Resets the 3D CSS transform of `el` so it is translated by `offset` pixels
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomUtil.js","names":["DomEvent.preventDefault"],"sources":["../../../src/dom/DomUtil.js"],"sourcesContent":["import * as DomEvent from './DomEvent.js';\nimport {Point} from '../geometry/Point.js';\n\n// DomUtil: utility functions to work with the\n// [DOM](https://developer.mozilla.org/docs/Web/API/Document_Object_Model)\n// tree, used by Maplair internally.\n//\n// Most functions expecting or returning a `HTMLElement` also work for\n// SVG elements. The only difference is that classes refer to CSS classes\n// in HTML and SVG classes in SVG.\n\n/**\n * Returns an element given its DOM id, or returns the element itself\n * if it was passed directly.\n * @param {string|HTMLElement} id\n * @returns {HTMLElement|null}\n */\nexport function get(id) {\n\treturn typeof id === 'string' ? document.getElementById(id) : id;\n}\n\n/**\n * Creates an HTML element with `tagName`, sets its class to `className`, and\n * optionally appends it to `container` element.\n * @param {string} tagName\n * @param {string} [className]\n * @param {HTMLElement} [container]\n * @returns {HTMLElement}\n */\nexport function create(tagName, className, container) {\n\tconst el = document.createElement(tagName);\n\tel.className = className ?? '';\n\n\tcontainer?.
|
|
1
|
+
{"version":3,"file":"DomUtil.js","names":["DomEvent.preventDefault"],"sources":["../../../src/dom/DomUtil.js"],"sourcesContent":["import * as DomEvent from './DomEvent.js';\nimport {Point} from '../geometry/Point.js';\n\n// DomUtil: utility functions to work with the\n// [DOM](https://developer.mozilla.org/docs/Web/API/Document_Object_Model)\n// tree, used by Maplair internally.\n//\n// Most functions expecting or returning a `HTMLElement` also work for\n// SVG elements. The only difference is that classes refer to CSS classes\n// in HTML and SVG classes in SVG.\n\n/**\n * Returns an element given its DOM id, or returns the element itself\n * if it was passed directly.\n * @param {string|HTMLElement} id\n * @returns {HTMLElement|null}\n */\nexport function get(id) {\n\treturn typeof id === 'string' ? document.getElementById(id) : id;\n}\n\n/**\n * Creates an HTML element with `tagName`, sets its class to `className`, and\n * optionally appends it to `container` element.\n * @param {string} tagName\n * @param {string} [className]\n * @param {HTMLElement} [container]\n * @returns {HTMLElement}\n */\nexport function create(tagName, className, container) {\n\tconst el = document.createElement(tagName);\n\tel.className = className ?? '';\n\n\tcontainer?.append(el);\n\treturn el;\n}\n\n/**\n * Makes `el` the last child of its parent, so it renders in front of the other\n * children.\n * @param {Element} el\n * @returns {void}\n */\nexport function toFront(el) {\n\tconst parent = el.parentNode;\n\tif (!parent || parent.lastChild === el) { return; }\n\n\t// re-inserting a hovered node (e.g. bringToFront in a pointerover handler) makes Chromium 144+ fire a repeated\n\t// pointerover and lose the next pointerout (#10129), so move the nodes after it instead\n\tif (el.matches(':hover')) {\n\t\twhile (el.nextSibling) { el.before(el.nextSibling); }\n\t} else {\n\t\tparent.append(el);\n\t}\n}\n\n/**\n * Makes `el` the first child of its parent, so it renders behind the other children.\n * @param {Element} el\n * @returns {void}\n */\nexport function toBack(el) {\n\tconst parent = el.parentNode;\n\tif (!parent || parent.firstChild === el) { return; }\n\n\tif (el.matches(':hover')) { // see toFront\n\t\twhile (el.previousSibling) { el.after(el.previousSibling); }\n\t} else {\n\t\tparent.prepend(el);\n\t}\n}\n\n/**\n * Resets the 3D CSS transform of `el` so it is translated by `offset` pixels\n * and optionally scaled by `scale`. Does not have an effect if the\n * browser doesn't support 3D CSS transforms.\n * @param {HTMLElement|SVGElement} el\n * @param {Point} [offset]\n * @param {number} [scale]\n * @returns {void}\n */\nexport function setTransform(el, offset, scale) {\n\tconst pos = offset ?? new Point(0, 0);\n\n\t// same format as browsers serialize it, so that unchanged positions can be skipped\n\tconst transform = `translate3d(${pos.x}px, ${pos.y}px, 0px)${scale ? ` scale(${scale})` : ''}`;\n\tif (el.style.transform !== transform) {\n\t\tel.style.transform = transform;\n\t}\n}\n\nconst positions = new WeakMap();\n\n/**\n * Sets the position of `el` to coordinates specified by `point` using a CSS translate\n * (used by Maplair internally to position its layers). With `flat`, the translate is 2D,\n * so `el` is painted into its parent's compositor layer instead of getting a layer of its own.\n * @param {HTMLElement|SVGElement} el\n * @param {Point} point\n * @param {boolean} [flat]\n * @returns {void}\n */\nexport function setPosition(el, point, flat) {\n\tpositions.set(el, point);\n\tif (flat) {\n\t\tel.style.transform = `translate(${point.x}px, ${point.y}px)`;\n\t} else {\n\t\tsetTransform(el, point);\n\t}\n}\n\n/**\n * Returns the coordinates of an element previously positioned with setPosition.\n * @param {HTMLElement|SVGElement} el\n * @returns {Point}\n */\nexport function getPosition(el) {\n\t// this method is only used for elements previously positioned using setPosition,\n\t// so it's safe to cache the position for performance\n\treturn positions.get(el) ?? new Point(0, 0);\n}\n\n/**\n * Prevents the user from generating `dragstart` DOM events, usually generated when\n * the user drags an image.\n * @returns {void}\n */\nexport function disableImageDrag() {\n\tDomEvent.on(window, 'dragstart', DomEvent.preventDefault);\n}\n\n/**\n * Cancels the effects of a previous\n * [`DomUtil.disableImageDrag`](#domutil-disableimagedrag).\n * @returns {void}\n */\nexport function enableImageDrag() {\n\tDomEvent.off(window, 'dragstart', DomEvent.preventDefault);\n}\n\n/**\n * Finds the closest parent node which size (width and height) is not null.\n * @param {HTMLElement} element\n * @returns {HTMLElement}\n */\nexport function getSizedParentNode(element) {\n\tdo {\n\t\telement = element.parentNode;\n\t} while ((!element.offsetWidth || !element.offsetHeight) && element !== document.body);\n\treturn element;\n}\n\n/**\n * Computes the CSS scale currently applied on the element.\n * Returns an object with `x` and `y` members as horizontal and vertical scales\n * respectively, and `boundingClientRect` as the result of\n * [`getBoundingClientRect()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).\n * @param {HTMLElement} element\n * @returns {{x: number, y: number, boundingClientRect: DOMRect}}\n */\nexport function getScale(element) {\n\tconst rect = element.getBoundingClientRect();\n\n\treturn {\n\t\tx: rect.width / element.offsetWidth || 1,\n\t\ty: rect.height / element.offsetHeight || 1,\n\t\tboundingClientRect: rect\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAgB,IAAI,IAAI;CACvB,OAAO,OAAO,OAAO,WAAW,SAAS,eAAe,EAAE,IAAI;AAC/D;;;;;;;;;AAUA,SAAgB,OAAO,SAAS,WAAW,WAAW;CACrD,MAAM,KAAK,SAAS,cAAc,OAAO;CACzC,GAAG,YAAY,aAAa;CAE5B,WAAW,OAAO,EAAE;CACpB,OAAO;AACR;;;;;;;AAQA,SAAgB,QAAQ,IAAI;CAC3B,MAAM,SAAS,GAAG;CAClB,IAAI,CAAC,UAAU,OAAO,cAAc,IAAM;CAI1C,IAAI,GAAG,QAAQ,QAAQ,GACtB,OAAO,GAAG,aAAe,GAAG,OAAO,GAAG,WAAW;MAEjD,OAAO,OAAO,EAAE;AAElB;;;;;;AAOA,SAAgB,OAAO,IAAI;CAC1B,MAAM,SAAS,GAAG;CAClB,IAAI,CAAC,UAAU,OAAO,eAAe,IAAM;CAE3C,IAAI,GAAG,QAAQ,QAAQ,GACtB,OAAO,GAAG,iBAAmB,GAAG,MAAM,GAAG,eAAe;MAExD,OAAO,QAAQ,EAAE;AAEnB;;;;;;;;;;AAWA,SAAgB,aAAa,IAAI,QAAQ,OAAO;CAC/C,MAAM,MAAM,UAAU,IAAI,MAAM,GAAG,CAAC;CAGpC,MAAM,YAAY,eAAe,IAAI,EAAE,MAAM,IAAI,EAAE,UAAU,QAAQ,UAAU,MAAM,KAAK;CAC1F,IAAI,GAAG,MAAM,cAAc,WAC1B,GAAG,MAAM,YAAY;AAEvB;AAEA,MAAM,4BAAY,IAAI,QAAQ;;;;;;;;;;AAW9B,SAAgB,YAAY,IAAI,OAAO,MAAM;CAC5C,UAAU,IAAI,IAAI,KAAK;CACvB,IAAI,MACH,GAAG,MAAM,YAAY,aAAa,MAAM,EAAE,MAAM,MAAM,EAAE;MAExD,aAAa,IAAI,KAAK;AAExB;;;;;;AAOA,SAAgB,YAAY,IAAI;CAG/B,OAAO,UAAU,IAAI,EAAE,KAAK,IAAI,MAAM,GAAG,CAAC;AAC3C;;;;;;AAOA,SAAgB,mBAAmB;CAClC,GAAY,QAAQ,aAAaA,cAAuB;AACzD;;;;;;AAOA,SAAgB,kBAAkB;CACjC,IAAa,QAAQ,aAAaA,cAAuB;AAC1D;;;;;;AAOA,SAAgB,mBAAmB,SAAS;CAC3C;EACC,UAAU,QAAQ;SACT,CAAC,QAAQ,eAAe,CAAC,QAAQ,iBAAiB,YAAY,SAAS;CACjF,OAAO;AACR;;;;;;;;;AAUA,SAAgB,SAAS,SAAS;CACjC,MAAM,OAAO,QAAQ,sBAAsB;CAE3C,OAAO;EACN,GAAG,KAAK,QAAQ,QAAQ,eAAe;EACvC,GAAG,KAAK,SAAS,QAAQ,gBAAgB;EACzC,oBAAoB;CACrB;AACD"}
|
|
@@ -76,13 +76,13 @@ var Draggable = class Draggable extends Evented {
|
|
|
76
76
|
}
|
|
77
77
|
_onDown(e) {
|
|
78
78
|
this._moved = false;
|
|
79
|
-
if (this._element.classList.contains("maplair-zoom-anim")) return;
|
|
80
79
|
const pointers = getPointers().length;
|
|
81
80
|
if (pointers > 1) {
|
|
82
81
|
if (Draggable._dragging === this) this.finishDrag();
|
|
83
82
|
return;
|
|
84
83
|
}
|
|
85
|
-
|
|
84
|
+
const boxZoom = e.shiftKey && this._element.closest(".maplair-container")?.classList.contains("maplair-box-zoom");
|
|
85
|
+
if (Draggable._dragging || boxZoom || e.button !== 0 && e.pointerType !== "touch") return;
|
|
86
86
|
Draggable._dragging = this;
|
|
87
87
|
disableImageDrag();
|
|
88
88
|
if (this._moving) return;
|
|
@@ -140,10 +140,8 @@ var Draggable = class Draggable extends Evented {
|
|
|
140
140
|
finishDrag(noInertia) {
|
|
141
141
|
this._draggingContainer?.classList.remove("maplair-dragging");
|
|
142
142
|
this._draggingContainer = null;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this._lastTarget = null;
|
|
146
|
-
}
|
|
143
|
+
this._lastTarget?.classList.remove("maplair-drag-target");
|
|
144
|
+
this._lastTarget = null;
|
|
147
145
|
off(this._dragStartTarget, "pointermove", this._onMove, this);
|
|
148
146
|
off(this._dragStartTarget, "pointerup pointercancel lostpointercapture", this._onUp, this);
|
|
149
147
|
enableImageDrag();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Draggable.js","names":["PointerEvents.getPointers","DomUtil.getSizedParentNode","DomUtil.getPosition","DomUtil.getScale"],"sources":["../../../src/dom/Draggable.js"],"sourcesContent":["import {Evented} from '../core/Events.js';\nimport * as DomEvent from './DomEvent.js';\nimport * as DomUtil from './DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport {Point} from '../geometry/Point.js';\nimport * as PointerEvents from './DomEvent.PointerEvents.js';\n/** @import {MaplairEvent, DragEndEvent} from '../core/Events.js' */\n\n/**\n * Options of `Draggable`.\n * @typedef {object} DraggableOptions\n * @property {number} [clickTolerance=3] The max number of pixels a user can shift the\n * pointer during a click for it to be considered a valid click (as opposed to a\n * pointer drag).\n */\n\n/**\n * The event object of `dragstart`, `predrag` and `drag` of `Draggable`.\n * @typedef {object} DraggableEvent\n * @property {PointerEvent} originalEvent The DOM event of the pointer which drags.\n * @extends MaplairEvent\n */\n\n/**\n * A class for making DOM elements draggable.\n * Used internally for map and marker dragging. Works on any DOM element.\n *\n * @example\n * ```js\n * const draggable = new Draggable(elementToDrag);\n * draggable.enable();\n * ```\n *\n * @fires down {MaplairEvent} Fired when a drag is about to start.\n * @fires dragstart {DraggableEvent} Fired when a drag starts.\n * @fires predrag {DraggableEvent} Fired continuously during dragging *before* each\n * corresponding update of the element's position.\n * @fires drag {DraggableEvent} Fired continuously during dragging.\n * @fires dragend {DragEndEvent} Fired when the drag ends (with `noInertia: true` if\n * the drag was finished without inertia, e.g. by disabling the draggable).\n */\nexport class Draggable extends Evented {\n\n\tstatic defaultOptions = {\n\t\tclickTolerance: 3\n\t};\n\n\t/**\n\t * Creates a `Draggable` object for moving `element` when you start dragging the\n\t * `dragStartTarget` element (equals `element` itself by default).\n\t * @param {HTMLElement} element\n\t * @param {HTMLElement} [dragStartTarget]\n\t * @param {DraggableOptions} [options]\n\t */\n\tconstructor(element, dragStartTarget, options) {\n\t\tif (typeof options === 'boolean') {\n\t\t\tthrow new Error('Draggable: the preventOutline argument is removed in Maplair. Pass options as the third argument.');\n\t\t}\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis._element = element;\n\t\tthis._dragStartTarget = dragStartTarget ?? element;\n\n\t\tthis.callInitHooks(Draggable);\n\t}\n\n\t/**\n\t * Enables the dragging ability.\n\t * @returns {void}\n\t */\n\tenable() {\n\t\tif (this._enabled) { return; }\n\n\t\tDomEvent.on(this._dragStartTarget, 'pointerdown', this._onDown, this);\n\n\t\tthis._enabled = true;\n\t}\n\n\t/**\n\t * Disables the dragging ability.\n\t * @returns {void}\n\t */\n\tdisable() {\n\t\tif (!this._enabled) { return; }\n\n\t\t// If we're currently dragging this draggable,\n\t\t// disabling it counts as first ending the drag.\n\t\tif (Draggable._dragging === this) {\n\t\t\tthis.finishDrag(true);\n\t\t}\n\n\t\tDomEvent.off(this._dragStartTarget, 'pointerdown', this._onDown, this);\n\n\t\tthis._enabled = false;\n\t\tthis._moved = false;\n\t}\n\n\t_onDown(e) {\n\t\tthis._moved = false;\n\n\t\tif (this._element.classList.contains('maplair-zoom-anim')) { return; }\n\n\t\tconst pointers = PointerEvents.getPointers().length;\n\t\tif (pointers > 1) {\n\t\t\t// Finish dragging to avoid conflict with touchZoom\n\t\t\tif (Draggable._dragging === this) {\n\t\t\t\tthis.finishDrag();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (Draggable._dragging || e.shiftKey || (e.button !== 0 && e.pointerType !== 'touch')) { return; }\n\t\tDraggable._dragging = this; // Prevent dragging multiple objects at once.\n\n\t\tDomUtil.disableImageDrag();\n\n\t\tif (this._moving) { return; }\n\n\t\t// outside a map, nothing tracks pointers or captures them, so capture this one to keep its moves coming\n\t\tif (!pointers && e.isTrusted) { e.target.setPointerCapture(e.pointerId); }\n\n\t\tthis.fire('down');\n\n\t\tconst sizedParent = DomUtil.getSizedParentNode(this._element);\n\n\t\tthis._startPoint = new Point(e.clientX, e.clientY);\n\t\tthis._startPos = DomUtil.getPosition(this._element);\n\n\t\t// Cache the scale, so that we can continuously compensate for it during drag (_onMove).\n\t\tthis._parentScale = DomUtil.getScale(sizedParent);\n\n\t\tDomEvent.on(this._dragStartTarget, 'pointermove', this._onMove, this);\n\t\tDomEvent.on(this._dragStartTarget, 'pointerup pointercancel lostpointercapture', this._onUp, this);\n\t}\n\n\t_onMove(e) {\n\t\tif (PointerEvents.getPointers().length > 1) {\n\t\t\tthis._moved = true;\n\t\t\treturn;\n\t\t}\n\n\t\tconst offset = new Point(e.clientX, e.clientY)._subtract(this._startPoint);\n\n\t\t// once the drag has started, the pointer must be followed even when it comes back near the start point\n\t\tconst dist = Math.abs(offset.x) + Math.abs(offset.y);\n\t\tif (!this._moved && (!dist || dist < this.options.clickTolerance)) { return; }\n\n\t\t// We assume that the parent container's position, border and scale do not change for the duration of the drag.\n\t\t// Therefore there is no need to account for the position and border (they are eliminated by the subtraction)\n\t\t// and we can use the cached value for the scale.\n\t\toffset.x /= this._parentScale.x;\n\t\toffset.y /= this._parentScale.y;\n\n\t\tif (e.cancelable) {\n\t\t\te.preventDefault();\n\t\t}\n\n\t\tif (!this._moved) {\n\t\t\tthis.fire('dragstart', {originalEvent: e});\n\n\t\t\tthis._moved = true;\n\n\t\t\t// on the map container rather than the body, so that toggling it doesn't restyle the whole page\n\t\t\tthis._draggingContainer = this._element.closest('.maplair-container') ?? this._element;\n\t\t\tthis._draggingContainer.classList.add('maplair-dragging');\n\n\t\t\tthis._lastTarget = e.target;\n\t\t\tthis._lastTarget.classList.add('maplair-drag-target');\n\t\t}\n\n\t\tthis._newPos = this._startPos.add(offset);\n\t\tthis._moving = true;\n\n\t\tthis._lastEvent = e;\n\t\tthis._updatePosition();\n\t}\n\n\t_updatePosition() {\n\t\tconst e = {originalEvent: this._lastEvent};\n\n\t\tthis.fire('predrag', e);\n\n\t\t// pointer events can have fractional coordinates; snap them to device pixels, since an edge in the middle of\n\t\t// one is drawn partly transparent on both sides and shows a seam between tiles\n\t\tconst dpr = window.devicePixelRatio;\n\t\tthis._newPos = this._newPos.multiplyBy(dpr)._round()._divideBy(dpr);\n\t\tDomUtil.setPosition(this._element, this._newPos);\n\n\t\tthis.fire('drag', e);\n\t}\n\n\t_onUp(e) {\n\t\t// releasing the button outside the window may fire no pointerup, only a lostpointercapture with no buttons;\n\t\t// capture lost while the button is still held (e.g. the pressed element was removed) shouldn't end the drag\n\t\tif (e.type === 'lostpointercapture' && e.buttons) { return; }\n\t\tthis.finishDrag();\n\t}\n\n\t/**\n\t * Ends the current drag.\n\t * @internal\n\t * @param {boolean} [noInertia]\n\t * @returns {void}\n\t */\n\tfinishDrag(noInertia) {\n\t\tthis._draggingContainer?.classList.remove('maplair-dragging');\n\t\tthis._draggingContainer = null;\n\n\t\tif (this._lastTarget) {\n\t\t\tthis._lastTarget.classList.remove('maplair-drag-target');\n\t\t\tthis._lastTarget = null;\n\t\t}\n\n\t\tDomEvent.off(this._dragStartTarget, 'pointermove', this._onMove, this);\n\t\tDomEvent.off(this._dragStartTarget, 'pointerup pointercancel lostpointercapture', this._onUp, this);\n\n\t\tDomUtil.enableImageDrag();\n\n\t\tconst fireDragend = this._moved && this._moving;\n\n\t\tthis._moving = false;\n\t\tDraggable._dragging = false;\n\n\t\tif (fireDragend) {\n\t\t\tthis.fire('dragend', {\n\t\t\t\tnoInertia,\n\t\t\t\tdistance: this._newPos.distanceTo(this._startPos)\n\t\t\t});\n\t\t}\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,YAAb,MAAa,kBAAkB,QAAQ;CAEtC,OAAO,iBAAiB,EACvB,gBAAgB,EACjB;;;;;;;;CASA,YAAY,SAAS,iBAAiB,SAAS;EAC9C,IAAI,OAAO,YAAY,WACtB,MAAM,IAAI,MAAM,mGAAmG;EAEpH,MAAM;EACN,WAAgB,MAAM,OAAO;EAE7B,KAAK,WAAW;EAChB,KAAK,mBAAmB,mBAAmB;EAE3C,KAAK,cAAc,SAAS;CAC7B;;;;;CAMA,SAAS;EACR,IAAI,KAAK,UAAY;EAErB,GAAY,KAAK,kBAAkB,eAAe,KAAK,SAAS,IAAI;EAEpE,KAAK,WAAW;CACjB;;;;;CAMA,UAAU;EACT,IAAI,CAAC,KAAK,UAAY;EAItB,IAAI,UAAU,cAAc,MAC3B,KAAK,WAAW,IAAI;EAGrB,IAAa,KAAK,kBAAkB,eAAe,KAAK,SAAS,IAAI;EAErE,KAAK,WAAW;EAChB,KAAK,SAAS;CACf;CAEA,QAAQ,GAAG;EACV,KAAK,SAAS;EAEd,IAAI,KAAK,SAAS,UAAU,SAAS,mBAAmB,GAAK;EAE7D,MAAM,WAAWA,YAA0B,CAAC,CAAC;EAC7C,IAAI,WAAW,GAAG;GAEjB,IAAI,UAAU,cAAc,MAC3B,KAAK,WAAW;GAEjB;EACD;EAEA,IAAI,UAAU,aAAa,EAAE,YAAa,EAAE,WAAW,KAAK,EAAE,gBAA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B;CACtB;CAEA,kBAAkB;EACjB,MAAM,IAAI,EAAC,eAAe,KAAK,WAAU;EAEzC,KAAK,KAAK,WAAW,CAAC;EAItB,MAAM,MAAM,OAAO;EACnB,KAAK,UAAU,KAAK,QAAQ,WAAW,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,GAAG;EAClE,YAAoB,KAAK,UAAU,KAAK,OAAO;EAE/C,KAAK,KAAK,QAAQ,CAAC;CACpB;CAEA,MAAM,GAAG;EAGR,IAAI,EAAE,SAAS,wBAAwB,EAAE,SAAW;EACpD,KAAK,WAAW;CACjB;;;;;;;CAQA,WAAW,WAAW;EACrB,KAAK,oBAAoB,UAAU,OAAO,kBAAkB;EAC5D,KAAK,qBAAqB;EAE1B,IAAI,KAAK,aAAa;GACrB,KAAK,YAAY,UAAU,OAAO,qBAAqB;GACvD,KAAK,cAAc;EACpB;EAEA,IAAa,KAAK,kBAAkB,eAAe,KAAK,SAAS,IAAI;EACrE,IAAa,KAAK,kBAAkB,8CAA8C,KAAK,OAAO,IAAI;EAElG,gBAAwB;EAExB,MAAM,cAAc,KAAK,UAAU,KAAK;EAExC,KAAK,UAAU;EACf,UAAU,YAAY;EAEtB,IAAI,aACH,KAAK,KAAK,WAAW;GACpB;GACA,UAAU,KAAK,QAAQ,WAAW,KAAK,SAAS;EACjD,CAAC;CAEH;AAED"}
|
|
1
|
+
{"version":3,"file":"Draggable.js","names":["PointerEvents.getPointers","DomUtil.getSizedParentNode","DomUtil.getPosition","DomUtil.getScale"],"sources":["../../../src/dom/Draggable.js"],"sourcesContent":["import {Evented} from '../core/Events.js';\nimport * as DomEvent from './DomEvent.js';\nimport * as DomUtil from './DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport {Point} from '../geometry/Point.js';\nimport * as PointerEvents from './DomEvent.PointerEvents.js';\n/** @import {MaplairEvent, DragEndEvent} from '../core/Events.js' */\n\n/**\n * Options of `Draggable`.\n * @typedef {object} DraggableOptions\n * @property {number} [clickTolerance=3] The max number of pixels a user can shift the\n * pointer during a click for it to be considered a valid click (as opposed to a\n * pointer drag).\n */\n\n/**\n * The event object of `dragstart`, `predrag` and `drag` of `Draggable`.\n * @typedef {object} DraggableEvent\n * @property {PointerEvent} originalEvent The DOM event of the pointer which drags.\n * @extends MaplairEvent\n */\n\n/**\n * A class for making DOM elements draggable.\n * Used internally for map and marker dragging. Works on any DOM element.\n *\n * @example\n * ```js\n * const draggable = new Draggable(elementToDrag);\n * draggable.enable();\n * ```\n *\n * @fires down {MaplairEvent} Fired when a drag is about to start.\n * @fires dragstart {DraggableEvent} Fired when a drag starts.\n * @fires predrag {DraggableEvent} Fired continuously during dragging *before* each\n * corresponding update of the element's position.\n * @fires drag {DraggableEvent} Fired continuously during dragging.\n * @fires dragend {DragEndEvent} Fired when the drag ends (with `noInertia: true` if\n * the drag was finished without inertia, e.g. by disabling the draggable).\n */\nexport class Draggable extends Evented {\n\n\tstatic defaultOptions = {\n\t\tclickTolerance: 3\n\t};\n\n\t/**\n\t * Creates a `Draggable` object for moving `element` when you start dragging the\n\t * `dragStartTarget` element (equals `element` itself by default).\n\t * @param {HTMLElement} element\n\t * @param {HTMLElement} [dragStartTarget]\n\t * @param {DraggableOptions} [options]\n\t */\n\tconstructor(element, dragStartTarget, options) {\n\t\tif (typeof options === 'boolean') {\n\t\t\tthrow new Error('Draggable: the preventOutline argument is removed in Maplair. Pass options as the third argument.');\n\t\t}\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis._element = element;\n\t\tthis._dragStartTarget = dragStartTarget ?? element;\n\n\t\tthis.callInitHooks(Draggable);\n\t}\n\n\t/**\n\t * Enables the dragging ability.\n\t * @returns {void}\n\t */\n\tenable() {\n\t\tif (this._enabled) { return; }\n\n\t\tDomEvent.on(this._dragStartTarget, 'pointerdown', this._onDown, this);\n\n\t\tthis._enabled = true;\n\t}\n\n\t/**\n\t * Disables the dragging ability.\n\t * @returns {void}\n\t */\n\tdisable() {\n\t\tif (!this._enabled) { return; }\n\n\t\t// If we're currently dragging this draggable,\n\t\t// disabling it counts as first ending the drag.\n\t\tif (Draggable._dragging === this) {\n\t\t\tthis.finishDrag(true);\n\t\t}\n\n\t\tDomEvent.off(this._dragStartTarget, 'pointerdown', this._onDown, this);\n\n\t\tthis._enabled = false;\n\t\tthis._moved = false;\n\t}\n\n\t_onDown(e) {\n\t\tthis._moved = false;\n\n\n\t\tconst pointers = PointerEvents.getPointers().length;\n\t\tif (pointers > 1) {\n\t\t\t// Finish dragging to avoid conflict with touchZoom\n\t\t\tif (Draggable._dragging === this) {\n\t\t\t\tthis.finishDrag();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Shift-drag draws a box to zoom to, unless box zoom is disabled\n\t\tconst boxZoom = e.shiftKey && this._element.closest('.maplair-container')?.classList.contains('maplair-box-zoom');\n\t\tif (Draggable._dragging || boxZoom || (e.button !== 0 && e.pointerType !== 'touch')) { return; }\n\t\tDraggable._dragging = this; // Prevent dragging multiple objects at once.\n\n\t\tDomUtil.disableImageDrag();\n\n\t\tif (this._moving) { return; }\n\n\t\t// outside a map, nothing tracks pointers or captures them, so capture this one to keep its moves coming\n\t\tif (!pointers && e.isTrusted) { e.target.setPointerCapture(e.pointerId); }\n\n\t\tthis.fire('down');\n\n\t\tconst sizedParent = DomUtil.getSizedParentNode(this._element);\n\n\t\tthis._startPoint = new Point(e.clientX, e.clientY);\n\t\tthis._startPos = DomUtil.getPosition(this._element);\n\n\t\t// Cache the scale, so that we can continuously compensate for it during drag (_onMove).\n\t\tthis._parentScale = DomUtil.getScale(sizedParent);\n\n\t\tDomEvent.on(this._dragStartTarget, 'pointermove', this._onMove, this);\n\t\tDomEvent.on(this._dragStartTarget, 'pointerup pointercancel lostpointercapture', this._onUp, this);\n\t}\n\n\t_onMove(e) {\n\t\tif (PointerEvents.getPointers().length > 1) {\n\t\t\tthis._moved = true;\n\t\t\treturn;\n\t\t}\n\n\t\tconst offset = new Point(e.clientX, e.clientY)._subtract(this._startPoint);\n\n\t\t// once the drag has started, the pointer must be followed even when it comes back near the start point\n\t\tconst dist = Math.abs(offset.x) + Math.abs(offset.y);\n\t\tif (!this._moved && (!dist || dist < this.options.clickTolerance)) { return; }\n\n\t\t// We assume that the parent container's position, border and scale do not change for the duration of the drag.\n\t\t// Therefore there is no need to account for the position and border (they are eliminated by the subtraction)\n\t\t// and we can use the cached value for the scale.\n\t\toffset.x /= this._parentScale.x;\n\t\toffset.y /= this._parentScale.y;\n\n\t\tif (e.cancelable) {\n\t\t\te.preventDefault();\n\t\t}\n\n\t\tif (!this._moved) {\n\t\t\tthis.fire('dragstart', {originalEvent: e});\n\n\t\t\tthis._moved = true;\n\n\t\t\t// on the map container rather than the body, so that toggling it doesn't restyle the whole page\n\t\t\tthis._draggingContainer = this._element.closest('.maplair-container') ?? this._element;\n\t\t\tthis._draggingContainer.classList.add('maplair-dragging');\n\n\t\t\tthis._lastTarget = e.target;\n\t\t\tthis._lastTarget.classList.add('maplair-drag-target');\n\t\t}\n\n\t\tthis._newPos = this._startPos.add(offset);\n\t\tthis._moving = true;\n\n\t\tthis._lastEvent = e;\n\t\tthis._updatePosition();\n\t}\n\n\t_updatePosition() {\n\t\tconst e = {originalEvent: this._lastEvent};\n\n\t\tthis.fire('predrag', e);\n\n\t\t// pointer events can have fractional coordinates; snap them to device pixels, since an edge in the middle of\n\t\t// one is drawn partly transparent on both sides and shows a seam between tiles\n\t\tconst dpr = window.devicePixelRatio;\n\t\tthis._newPos = this._newPos.multiplyBy(dpr)._round()._divideBy(dpr);\n\t\tDomUtil.setPosition(this._element, this._newPos);\n\n\t\tthis.fire('drag', e);\n\t}\n\n\t_onUp(e) {\n\t\t// releasing the button outside the window may fire no pointerup, only a lostpointercapture with no buttons;\n\t\t// capture lost while the button is still held (e.g. the pressed element was removed) shouldn't end the drag\n\t\tif (e.type === 'lostpointercapture' && e.buttons) { return; }\n\t\tthis.finishDrag();\n\t}\n\n\t/**\n\t * Ends the current drag.\n\t * @internal\n\t * @param {boolean} [noInertia]\n\t * @returns {void}\n\t */\n\tfinishDrag(noInertia) {\n\t\tthis._draggingContainer?.classList.remove('maplair-dragging');\n\t\tthis._draggingContainer = null;\n\n\t\tthis._lastTarget?.classList.remove('maplair-drag-target');\n\t\tthis._lastTarget = null;\n\n\t\tDomEvent.off(this._dragStartTarget, 'pointermove', this._onMove, this);\n\t\tDomEvent.off(this._dragStartTarget, 'pointerup pointercancel lostpointercapture', this._onUp, this);\n\n\t\tDomUtil.enableImageDrag();\n\n\t\tconst fireDragend = this._moved && this._moving;\n\n\t\tthis._moving = false;\n\t\tDraggable._dragging = false;\n\n\t\tif (fireDragend) {\n\t\t\tthis.fire('dragend', {\n\t\t\t\tnoInertia,\n\t\t\t\tdistance: this._newPos.distanceTo(this._startPos)\n\t\t\t});\n\t\t}\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,YAAb,MAAa,kBAAkB,QAAQ;CAEtC,OAAO,iBAAiB,EACvB,gBAAgB,EACjB;;;;;;;;CASA,YAAY,SAAS,iBAAiB,SAAS;EAC9C,IAAI,OAAO,YAAY,WACtB,MAAM,IAAI,MAAM,mGAAmG;EAEpH,MAAM;EACN,WAAgB,MAAM,OAAO;EAE7B,KAAK,WAAW;EAChB,KAAK,mBAAmB,mBAAmB;EAE3C,KAAK,cAAc,SAAS;CAC7B;;;;;CAMA,SAAS;EACR,IAAI,KAAK,UAAY;EAErB,GAAY,KAAK,kBAAkB,eAAe,KAAK,SAAS,IAAI;EAEpE,KAAK,WAAW;CACjB;;;;;CAMA,UAAU;EACT,IAAI,CAAC,KAAK,UAAY;EAItB,IAAI,UAAU,cAAc,MAC3B,KAAK,WAAW,IAAI;EAGrB,IAAa,KAAK,kBAAkB,eAAe,KAAK,SAAS,IAAI;EAErE,KAAK,WAAW;EAChB,KAAK,SAAS;CACf;CAEA,QAAQ,GAAG;EACV,KAAK,SAAS;EAGd,MAAM,WAAWA,YAA0B,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,SAAS,QAAQ,oBAAoB,KAAK,KAAK;GAC9E,KAAK,mBAAmB,UAAU,IAAI,kBAAkB;GAExD,KAAK,cAAc,EAAE;GACrB,KAAK,YAAY,UAAU,IAAI,qBAAqB;EACrD;EAEA,KAAK,UAAU,KAAK,UAAU,IAAI,MAAM;EACxC,KAAK,UAAU;EAEf,KAAK,aAAa;EAClB,KAAK,gBAAgB;CACtB;CAEA,kBAAkB;EACjB,MAAM,IAAI,EAAC,eAAe,KAAK,WAAU;EAEzC,KAAK,KAAK,WAAW,CAAC;EAItB,MAAM,MAAM,OAAO;EACnB,KAAK,UAAU,KAAK,QAAQ,WAAW,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,GAAG;EAClE,YAAoB,KAAK,UAAU,KAAK,OAAO;EAE/C,KAAK,KAAK,QAAQ,CAAC;CACpB;CAEA,MAAM,GAAG;EAGR,IAAI,EAAE,SAAS,wBAAwB,EAAE,SAAW;EACpD,KAAK,WAAW;CACjB;;;;;;;CAQA,WAAW,WAAW;EACrB,KAAK,oBAAoB,UAAU,OAAO,kBAAkB;EAC5D,KAAK,qBAAqB;EAE1B,KAAK,aAAa,UAAU,OAAO,qBAAqB;EACxD,KAAK,cAAc;EAEnB,IAAa,KAAK,kBAAkB,eAAe,KAAK,SAAS,IAAI;EACrE,IAAa,KAAK,kBAAkB,8CAA8C,KAAK,OAAO,IAAI;EAElG,gBAAwB;EAExB,MAAM,cAAc,KAAK,UAAU,KAAK;EAExC,KAAK,UAAU;EACf,UAAU,YAAY;EAEtB,IAAI,aACH,KAAK,KAAK,WAAW;GACpB;GACA,UAAU,KAAK,QAAQ,WAAW,KAAK,SAAS;EACjD,CAAC;CAEH;AAED"}
|
package/dist/esm/geo/LatLng.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatNum, wrapNum } from "../core/Util.js";
|
|
1
|
+
import { formatNum, toNumber, wrapNum } from "../core/Util.js";
|
|
2
2
|
import { LatLngBounds } from "./LatLngBounds.js";
|
|
3
3
|
// src/geo/LatLng.js
|
|
4
4
|
const coordinate = String.raw`([+-]?\d+(?:\.\d+)?)\s*°?`;
|
|
@@ -49,46 +49,36 @@ var LatLng = class LatLng {
|
|
|
49
49
|
* @param {number} [alt] Altitude in meters.
|
|
50
50
|
*/
|
|
51
51
|
constructor(lat, lng, alt) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (lat
|
|
55
|
-
_lat = lat.lat;
|
|
56
|
-
_lng = lat
|
|
57
|
-
_alt = lat
|
|
58
|
-
} else if (
|
|
59
|
-
if (lat.length === 3) {
|
|
60
|
-
_lat = lat[0];
|
|
61
|
-
_lng = lat[1];
|
|
62
|
-
_alt = lat[2];
|
|
63
|
-
} else if (lat.length === 2) {
|
|
64
|
-
_lat = lat[0];
|
|
65
|
-
_lng = lat[1];
|
|
66
|
-
}
|
|
67
|
-
} else if (typeof lat === "object" && "lat" in lat) {
|
|
52
|
+
let _lat = lat, _lng = lng, _alt = alt;
|
|
53
|
+
if (lat instanceof LatLng) ({lat: _lat, lng: _lng, alt: _alt} = lat);
|
|
54
|
+
else if (Array.isArray(lat)) {
|
|
55
|
+
_lat = lat.length <= 3 ? lat[0] : NaN;
|
|
56
|
+
_lng = lat[1];
|
|
57
|
+
_alt = lat[2];
|
|
58
|
+
} else if (typeof lat === "object" && lat !== null) {
|
|
68
59
|
_lat = lat.lat;
|
|
69
60
|
_lng = "lng" in lat ? lat.lng : lat.lon;
|
|
70
61
|
_alt = lat.alt;
|
|
71
|
-
} else {
|
|
72
|
-
_lat = lat;
|
|
73
|
-
_lng = lng;
|
|
74
|
-
_alt = alt;
|
|
75
62
|
}
|
|
76
63
|
/**
|
|
77
64
|
* Latitude in degrees.
|
|
78
65
|
* @type {number}
|
|
79
66
|
*/
|
|
80
|
-
this.lat =
|
|
67
|
+
this.lat = toNumber(_lat);
|
|
81
68
|
/**
|
|
82
69
|
* Longitude in degrees.
|
|
83
70
|
* @type {number}
|
|
84
71
|
*/
|
|
85
|
-
this.lng =
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
72
|
+
this.lng = toNumber(_lng);
|
|
73
|
+
if (isNaN(this.lat) || isNaN(this.lng)) throw new Error(`Invalid LatLng object: (${_lat}, ${_lng})`);
|
|
74
|
+
if (_alt != null) {
|
|
75
|
+
/**
|
|
76
|
+
* Altitude in meters (optional).
|
|
77
|
+
* @type {number|undefined}
|
|
78
|
+
*/
|
|
79
|
+
this.alt = toNumber(_alt);
|
|
80
|
+
if (isNaN(this.alt)) throw new Error(`Invalid LatLng altitude: ${_alt}`);
|
|
81
|
+
}
|
|
92
82
|
}
|
|
93
83
|
/**
|
|
94
84
|
* Returns the given `LatLng` object as it is, or else a new `LatLng` object created
|
|
@@ -117,12 +107,11 @@ var LatLng = class LatLng {
|
|
|
117
107
|
* @returns {boolean}
|
|
118
108
|
*/
|
|
119
109
|
static validate(lat, lng, alt) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
110
|
+
try {
|
|
111
|
+
return !!new LatLng(lat, lng, alt);
|
|
112
|
+
} catch {
|
|
123
113
|
return false;
|
|
124
|
-
}
|
|
125
|
-
return false;
|
|
114
|
+
}
|
|
126
115
|
}
|
|
127
116
|
/**
|
|
128
117
|
* Parses coordinates in decimal degrees: a pair of numbers (latitude first), e.g.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LatLng.js","names":["Util.formatNum","Util.wrapNum"],"sources":["../../../src/geo/LatLng.js"],"sourcesContent":["import * as Util from '../core/Util.js';\nimport {LatLngBounds} from './LatLngBounds.js';\n\n// a coordinate in decimal degrees, with an optional degree sign\nconst coordinate = String.raw`([+-]?\\d+(?:\\.\\d+)?)\\s*°?`,\nseparator = String.raw`(?:\\s*[,;]\\s*|\\s+)`,\n// `47.27 11.4`, `47.27, 11.4`, `+47.27;+11.4`\nplainRe = new RegExp(`^${coordinate}${separator}${coordinate}$`),\n// `N47.27 E11.4`, `N 47.27°, E 11.4°`\nprefixRe = new RegExp(`^([NSEW])\\\\s*${coordinate}${separator}([NSEW])\\\\s*${coordinate}$`, 'i'),\n// `47.27N 11.4E`, `47.27° N, 11.4° E`\nsuffixRe = new RegExp(`^${coordinate}\\\\s*([NSEW])${separator}${coordinate}\\\\s*([NSEW])$`, 'i'),\nhemisphereRe = /^[NSEW]$/i,\n// `geo:47.27,11.4`, `geo:47.27,11.4,500;u=35`, `geo:47.27,11.4?z=13` (RFC 5870)\ngeoUriRe = /^geo:([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?)(?:,([+-]?\\d+(?:\\.\\d+)?))?(?:[;?].*)?$/i;\n\n/**\n * A geographical point: a `LatLng`, an array of the form `[lat, lng]` or\n * `[lat, lng, alt]`, or a plain object of the form `{lat, lng}` or `{lat, lng, alt}`\n * (`lon` can be used in place of `lng`). Accepted by all Maplair methods which accept\n * `LatLng` objects (unless noted otherwise). Plain arrays (`number[]`) are accepted\n * for JavaScript, where array literals in variables are no tuples.\n * @typedef {LatLng|[number, number]|[number, number, number]|number[]|{lat: number, lng: number, alt?: number}|{lat: number, lon: number, alt?: number}} LatLngExpression\n */\n\n/**\n * Represents a geographical point with a certain latitude and longitude.\n *\n * @example\n * ```js\n * const latlng = new LatLng(50.5, 30.5);\n * ```\n *\n * All Maplair methods that accept LatLng objects also accept them in a simple Array\n * form and simple object form (unless noted otherwise), so these lines are equivalent:\n *\n * ```js\n * map.panTo([50, 30]);\n * map.panTo({lat: 50, lng: 30});\n * map.panTo({lat: 50, lon: 30});\n * map.panTo(new LatLng(50, 30));\n * ```\n *\n * Note that `LatLng` does not inherit from Maplair's `Class` object,\n * which means new classes can't inherit from it, and new methods\n * can't be added to it with the `include` function.\n */\nexport class LatLng {\n\t/**\n\t * Creates an object representing a geographical point with the given latitude and\n\t * longitude (and optionally altitude). Alternatively, expects a `LatLng` object, an\n\t * array of the form `[lat, lng]` or `[lat, lng, alt]`, or a plain object of the form\n\t * `{lat, lng}` or `{lat, lng, alt}` (`lon` can be used in place of `lng`) instead.\n\t * @param {number|LatLngExpression} lat Latitude in degrees, or the coordinates.\n\t * @param {number} [lng] Longitude in degrees.\n\t * @param {number} [alt] Altitude in meters.\n\t */\n\tconstructor(lat, lng, alt) {\n\t\tconst valid = LatLng.validate(lat, lng, alt);\n\t\tif (!valid) {\n\t\t\tthrow new Error(`Invalid LatLng object: (${lat}, ${lng})`);\n\t\t}\n\n\t\tlet _lat, _lng, _alt;\n\t\tif (lat instanceof LatLng) {\n\t\t\t_lat = lat.lat;\n\t\t\t_lng = lat.lng;\n\t\t\t_alt = lat.alt;\n\t\t} else if (Array.isArray(lat) && typeof lat[0] !== 'object') {\n\t\t\tif (lat.length === 3) {\n\t\t\t\t_lat = lat[0];\n\t\t\t\t_lng = lat[1];\n\t\t\t\t_alt = lat[2];\n\t\t\t} else if (lat.length === 2) {\n\t\t\t\t_lat = lat[0];\n\t\t\t\t_lng = lat[1];\n\t\t\t}\n\t\t} else if (typeof lat === 'object' && 'lat' in lat) {\n\t\t\t_lat = lat.lat;\n\t\t\t_lng = 'lng' in lat ? lat.lng : lat.lon;\n\t\t\t_alt = lat.alt;\n\t\t} else {\n\t\t\t_lat = lat;\n\t\t\t_lng = lng;\n\t\t\t_alt = alt;\n\t\t}\n\n\t\t/**\n\t\t * Latitude in degrees.\n\t\t * @type {number}\n\t\t */\n\t\tthis.lat = +_lat;\n\n\t\t/**\n\t\t * Longitude in degrees.\n\t\t * @type {number}\n\t\t */\n\t\tthis.lng = +_lng;\n\n\t\tif (_alt !== undefined) {\n\t\t\t/**\n\t\t\t * Altitude in meters (optional).\n\t\t\t * @type {number|undefined}\n\t\t\t */\n\t\t\tthis.alt = +_alt;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the given `LatLng` object as it is, or else a new `LatLng` object created\n\t * from the given arguments (the same as of the constructor) — unlike the\n\t * constructor, which always creates a new object.\n\t *\n\t * @example\n\t * ```js\n\t * LatLng.from(latlng) === latlng; // true\n\t * LatLng.from([50.5, 30.5]); // LatLng(50.5, 30.5)\n\t * ```\n\t * @param {number|LatLngExpression} lat Latitude in degrees, or the coordinates.\n\t * @param {number} [lng] Longitude in degrees.\n\t * @param {number} [alt] Altitude in meters.\n\t * @returns {LatLng}\n\t */\n\tstatic from(lat, lng, alt) {\n\t\treturn lat instanceof LatLng ? lat : new LatLng(lat, lng, alt);\n\t}\n\n\t/**\n\t * Returns `true` if the LatLng object can be properly initialized with the given\n\t * arguments (the same as of the constructor).\n\t * @param {any} lat\n\t * @param {any} [lng]\n\t * @param {any} [alt]\n\t * @returns {boolean}\n\t */\n\t// eslint-disable-next-line no-unused-vars\n\tstatic validate(lat, lng, alt) {\n\t\tif (lat instanceof LatLng || (typeof lat === 'object' && lat !== null && 'lat' in lat)) {\n\t\t\treturn true;\n\t\t} else if (lat && Array.isArray(lat) && typeof lat[0] !== 'object') {\n\t\t\tif (lat.length === 3 || lat.length === 2) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t} else if ((lat || lat === 0) && (lng || lng === 0)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Parses coordinates in decimal degrees: a pair of numbers (latitude first), e.g.\n\t * `'47.27, 11.4'` or `'47.27 11.4'`, with the hemispheres before or after the numbers,\n\t * e.g. `'N 47.27, E 11.4'`, `'47.27° S 11.4° W'` (also longitude first), or a\n\t * [geo URI](https://www.rfc-editor.org/rfc/rfc5870) like `'geo:47.27,11.4'` (with an\n\t * optional altitude). Returns `null` for other text and out-of-range coordinates.\n\t *\n\t * @example\n\t * ```js\n\t * LatLng.parse('47.2692 N, 11.4041 E'); // LatLng(47.2692, 11.4041)\n\t * LatLng.parse('geo:47.2692,11.4041?z=13'); // LatLng(47.2692, 11.4041)\n\t * ```\n\t * @param {string} text\n\t * @returns {LatLng|null}\n\t */\n\tstatic parse(text) {\n\t\ttext = text.trim();\n\t\tlet lat, lng, alt, match;\n\t\tif ((match = geoUriRe.exec(text))) {\n\t\t\t[lat, lng, alt] = match.slice(1).map(n => (n === undefined ? undefined : Number(n)));\n\t\t} else if ((match = plainRe.exec(text))) {\n\t\t\t[lat, lng] = match.slice(1).map(Number);\n\t\t} else if ((match = prefixRe.exec(text) ?? suffixRe.exec(text))) {\n\t\t\t// the hemisphere and the number of both coordinates\n\t\t\tconst prefixed = hemisphereRe.test(match[1]),\n\t\t\tcoords = prefixed ?\n\t\t\t\t[[match[1], match[2]], [match[3], match[4]]] :\n\t\t\t\t[[match[2], match[1]], [match[4], match[3]]];\n\t\t\tfor (const [hemisphere, number] of coords) {\n\t\t\t\tconst h = hemisphere.toUpperCase(),\n\t\t\t\tvalue = Math.abs(Number(number)) * (h === 'S' || h === 'W' ? -1 : 1);\n\t\t\t\tif (h === 'N' || h === 'S') {\n\t\t\t\t\tif (lat !== undefined) { return null; }\n\t\t\t\t\tlat = value;\n\t\t\t\t} else {\n\t\t\t\t\tif (lng !== undefined) { return null; }\n\t\t\t\t\tlng = value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (lat === undefined || Math.abs(lat) > 90 || Math.abs(lng) > 180) { return null; }\n\t\treturn new LatLng(lat, lng, alt);\n\t}\n\n\t/**\n\t * Returns `true` if the given `LatLng` point is at the same position (within a small\n\t * margin of error). The margin of error can be overridden by setting `maxMargin` to\n\t * a small number.\n\t * @param {LatLngExpression} obj\n\t * @param {number} [maxMargin]\n\t * @returns {boolean}\n\t */\n\tequals(obj, maxMargin) {\n\t\tif (!obj) { return false; }\n\n\t\tobj = LatLng.from(obj);\n\n\t\tconst margin = Math.max(\n\t\t\tMath.abs(this.lat - obj.lat),\n\t\t\tMath.abs(this.lng - obj.lng));\n\n\t\treturn margin <= (maxMargin ?? 1.0E-9);\n\t}\n\n\t/**\n\t * Returns a string representation of the point (for debugging purposes).\n\t * @param {number|false} [precision]\n\t * @returns {string}\n\t */\n\ttoString(precision) {\n\t\treturn `LatLng(${Util.formatNum(this.lat, precision)}, ${Util.formatNum(this.lng, precision)})`;\n\t}\n\n\t/**\n\t * Returns the distance (in meters) to the given `LatLng` calculated using the\n\t * [Haversine formula](https://en.wikipedia.org/wiki/Haversine_formula).\n\t * @param {LatLngExpression} other\n\t * @returns {number}\n\t */\n\tdistanceTo(other) {\n\t\treturn haversineDistance(this, LatLng.from(other), 6371000);\n\t}\n\n\t/**\n\t * Returns a new `LatLng` object with the longitude wrapped so it's always between\n\t * -180 and +180 degrees.\n\t * @returns {LatLng}\n\t */\n\twrap() {\n\t\treturn new LatLng(this.lat, Util.wrapNum(this.lng, [-180, 180], true), this.alt);\n\t}\n\n\t/**\n\t * Returns a new `LatLngBounds` object in which each boundary is `sizeInMeters/2`\n\t * meters apart from the `LatLng`.\n\t * @param {number} sizeInMeters\n\t * @returns {LatLngBounds}\n\t */\n\ttoBounds(sizeInMeters) {\n\t\tconst latAccuracy = 180 * sizeInMeters / 40075017,\n\t\tlngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat);\n\n\t\treturn new LatLngBounds(\n\t\t\t[this.lat - latAccuracy, this.lng - lngAccuracy],\n\t\t\t[this.lat + latAccuracy, this.lng + lngAccuracy]);\n\t}\n\n};\n\n/**\n * The great-circle distance on a sphere of radius `R`, shared with `EarthCRS.distance()`.\n * @param {LatLng} latlng1\n * @param {LatLng} latlng2\n * @param {number} R\n * @returns {number}\n */\nexport function haversineDistance(latlng1, latlng2, R) {\n\tconst rad = Math.PI / 180,\n\tlat1 = latlng1.lat * rad,\n\tlat2 = latlng2.lat * rad,\n\tsinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2),\n\tsinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2),\n\ta = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon,\n\tc = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\treturn R * c;\n}\n"],"mappings":";;;AAIA,MAAM,aAAa,OAAO,GAAG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AK,QAAQ,MAAM,QAAQ,OAAO,MAAM,CAAC,GACxD,IAAI,UAAU,UAAU,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,UAAU;CAEpE,OAAO,KADH,IAAI,KAAK,MAAM,KAAK,KAAK,CAAC,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC;AAElD"}
|
|
1
|
+
{"version":3,"file":"LatLng.js","names":["Util.toNumber","Util.formatNum","Util.wrapNum"],"sources":["../../../src/geo/LatLng.js"],"sourcesContent":["import * as Util from '../core/Util.js';\nimport {LatLngBounds} from './LatLngBounds.js';\n\n// a coordinate in decimal degrees, with an optional degree sign\nconst coordinate = String.raw`([+-]?\\d+(?:\\.\\d+)?)\\s*°?`,\nseparator = String.raw`(?:\\s*[,;]\\s*|\\s+)`,\n// `47.27 11.4`, `47.27, 11.4`, `+47.27;+11.4`\nplainRe = new RegExp(`^${coordinate}${separator}${coordinate}$`),\n// `N47.27 E11.4`, `N 47.27°, E 11.4°`\nprefixRe = new RegExp(`^([NSEW])\\\\s*${coordinate}${separator}([NSEW])\\\\s*${coordinate}$`, 'i'),\n// `47.27N 11.4E`, `47.27° N, 11.4° E`\nsuffixRe = new RegExp(`^${coordinate}\\\\s*([NSEW])${separator}${coordinate}\\\\s*([NSEW])$`, 'i'),\nhemisphereRe = /^[NSEW]$/i,\n// `geo:47.27,11.4`, `geo:47.27,11.4,500;u=35`, `geo:47.27,11.4?z=13` (RFC 5870)\ngeoUriRe = /^geo:([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?)(?:,([+-]?\\d+(?:\\.\\d+)?))?(?:[;?].*)?$/i;\n\n/**\n * A geographical point: a `LatLng`, an array of the form `[lat, lng]` or\n * `[lat, lng, alt]`, or a plain object of the form `{lat, lng}` or `{lat, lng, alt}`\n * (`lon` can be used in place of `lng`). Accepted by all Maplair methods which accept\n * `LatLng` objects (unless noted otherwise). Plain arrays (`number[]`) are accepted\n * for JavaScript, where array literals in variables are no tuples.\n * @typedef {LatLng|[number, number]|[number, number, number]|number[]|{lat: number, lng: number, alt?: number}|{lat: number, lon: number, alt?: number}} LatLngExpression\n */\n\n/**\n * Represents a geographical point with a certain latitude and longitude.\n *\n * @example\n * ```js\n * const latlng = new LatLng(50.5, 30.5);\n * ```\n *\n * All Maplair methods that accept LatLng objects also accept them in a simple Array\n * form and simple object form (unless noted otherwise), so these lines are equivalent:\n *\n * ```js\n * map.panTo([50, 30]);\n * map.panTo({lat: 50, lng: 30});\n * map.panTo({lat: 50, lon: 30});\n * map.panTo(new LatLng(50, 30));\n * ```\n *\n * Note that `LatLng` does not inherit from Maplair's `Class` object,\n * which means new classes can't inherit from it, and new methods\n * can't be added to it with the `include` function.\n */\nexport class LatLng {\n\t/**\n\t * Creates an object representing a geographical point with the given latitude and\n\t * longitude (and optionally altitude). Alternatively, expects a `LatLng` object, an\n\t * array of the form `[lat, lng]` or `[lat, lng, alt]`, or a plain object of the form\n\t * `{lat, lng}` or `{lat, lng, alt}` (`lon` can be used in place of `lng`) instead.\n\t * @param {number|LatLngExpression} lat Latitude in degrees, or the coordinates.\n\t * @param {number} [lng] Longitude in degrees.\n\t * @param {number} [alt] Altitude in meters.\n\t */\n\tconstructor(lat, lng, alt) {\n\t\tlet _lat = lat, _lng = lng, _alt = alt;\n\t\tif (lat instanceof LatLng) {\n\t\t\t({lat: _lat, lng: _lng, alt: _alt} = lat);\n\t\t} else if (Array.isArray(lat)) {\n\t\t\t_lat = lat.length <= 3 ? lat[0] : NaN;\n\t\t\t_lng = lat[1];\n\t\t\t_alt = lat[2];\n\t\t} else if (typeof lat === 'object' && lat !== null) {\n\t\t\t_lat = lat.lat;\n\t\t\t_lng = 'lng' in lat ? lat.lng : lat.lon;\n\t\t\t_alt = lat.alt;\n\t\t}\n\n\t\t/**\n\t\t * Latitude in degrees.\n\t\t * @type {number}\n\t\t */\n\t\tthis.lat = Util.toNumber(_lat);\n\n\t\t/**\n\t\t * Longitude in degrees.\n\t\t * @type {number}\n\t\t */\n\t\tthis.lng = Util.toNumber(_lng);\n\n\t\tif (isNaN(this.lat) || isNaN(this.lng)) {\n\t\t\tthrow new Error(`Invalid LatLng object: (${_lat}, ${_lng})`);\n\t\t}\n\n\t\tif (_alt != null) {\n\t\t\t/**\n\t\t\t * Altitude in meters (optional).\n\t\t\t * @type {number|undefined}\n\t\t\t */\n\t\t\tthis.alt = Util.toNumber(_alt);\n\n\t\t\tif (isNaN(this.alt)) {\n\t\t\t\tthrow new Error(`Invalid LatLng altitude: ${_alt}`);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns the given `LatLng` object as it is, or else a new `LatLng` object created\n\t * from the given arguments (the same as of the constructor) — unlike the\n\t * constructor, which always creates a new object.\n\t *\n\t * @example\n\t * ```js\n\t * LatLng.from(latlng) === latlng; // true\n\t * LatLng.from([50.5, 30.5]); // LatLng(50.5, 30.5)\n\t * ```\n\t * @param {number|LatLngExpression} lat Latitude in degrees, or the coordinates.\n\t * @param {number} [lng] Longitude in degrees.\n\t * @param {number} [alt] Altitude in meters.\n\t * @returns {LatLng}\n\t */\n\tstatic from(lat, lng, alt) {\n\t\treturn lat instanceof LatLng ? lat : new LatLng(lat, lng, alt);\n\t}\n\n\t/**\n\t * Returns `true` if the LatLng object can be properly initialized with the given\n\t * arguments (the same as of the constructor).\n\t * @param {any} lat\n\t * @param {any} [lng]\n\t * @param {any} [alt]\n\t * @returns {boolean}\n\t */\n\t// eslint-disable-next-line no-unused-vars\n\tstatic validate(lat, lng, alt) {\n\t\ttry {\n\t\t\treturn !!new LatLng(lat, lng, alt);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Parses coordinates in decimal degrees: a pair of numbers (latitude first), e.g.\n\t * `'47.27, 11.4'` or `'47.27 11.4'`, with the hemispheres before or after the numbers,\n\t * e.g. `'N 47.27, E 11.4'`, `'47.27° S 11.4° W'` (also longitude first), or a\n\t * [geo URI](https://www.rfc-editor.org/rfc/rfc5870) like `'geo:47.27,11.4'` (with an\n\t * optional altitude). Returns `null` for other text and out-of-range coordinates.\n\t *\n\t * @example\n\t * ```js\n\t * LatLng.parse('47.2692 N, 11.4041 E'); // LatLng(47.2692, 11.4041)\n\t * LatLng.parse('geo:47.2692,11.4041?z=13'); // LatLng(47.2692, 11.4041)\n\t * ```\n\t * @param {string} text\n\t * @returns {LatLng|null}\n\t */\n\tstatic parse(text) {\n\t\ttext = text.trim();\n\t\tlet lat, lng, alt, match;\n\t\tif ((match = geoUriRe.exec(text))) {\n\t\t\t[lat, lng, alt] = match.slice(1).map(n => (n === undefined ? undefined : Number(n)));\n\t\t} else if ((match = plainRe.exec(text))) {\n\t\t\t[lat, lng] = match.slice(1).map(Number);\n\t\t} else if ((match = prefixRe.exec(text) ?? suffixRe.exec(text))) {\n\t\t\t// the hemisphere and the number of both coordinates\n\t\t\tconst prefixed = hemisphereRe.test(match[1]),\n\t\t\tcoords = prefixed ?\n\t\t\t\t[[match[1], match[2]], [match[3], match[4]]] :\n\t\t\t\t[[match[2], match[1]], [match[4], match[3]]];\n\t\t\tfor (const [hemisphere, number] of coords) {\n\t\t\t\tconst h = hemisphere.toUpperCase(),\n\t\t\t\tvalue = Math.abs(Number(number)) * (h === 'S' || h === 'W' ? -1 : 1);\n\t\t\t\tif (h === 'N' || h === 'S') {\n\t\t\t\t\tif (lat !== undefined) { return null; }\n\t\t\t\t\tlat = value;\n\t\t\t\t} else {\n\t\t\t\t\tif (lng !== undefined) { return null; }\n\t\t\t\t\tlng = value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (lat === undefined || Math.abs(lat) > 90 || Math.abs(lng) > 180) { return null; }\n\t\treturn new LatLng(lat, lng, alt);\n\t}\n\n\t/**\n\t * Returns `true` if the given `LatLng` point is at the same position (within a small\n\t * margin of error). The margin of error can be overridden by setting `maxMargin` to\n\t * a small number.\n\t * @param {LatLngExpression} obj\n\t * @param {number} [maxMargin]\n\t * @returns {boolean}\n\t */\n\tequals(obj, maxMargin) {\n\t\tif (!obj) { return false; }\n\n\t\tobj = LatLng.from(obj);\n\n\t\tconst margin = Math.max(\n\t\t\tMath.abs(this.lat - obj.lat),\n\t\t\tMath.abs(this.lng - obj.lng));\n\n\t\treturn margin <= (maxMargin ?? 1.0E-9);\n\t}\n\n\t/**\n\t * Returns a string representation of the point (for debugging purposes).\n\t * @param {number|false} [precision]\n\t * @returns {string}\n\t */\n\ttoString(precision) {\n\t\treturn `LatLng(${Util.formatNum(this.lat, precision)}, ${Util.formatNum(this.lng, precision)})`;\n\t}\n\n\t/**\n\t * Returns the distance (in meters) to the given `LatLng` calculated using the\n\t * [Haversine formula](https://en.wikipedia.org/wiki/Haversine_formula).\n\t * @param {LatLngExpression} other\n\t * @returns {number}\n\t */\n\tdistanceTo(other) {\n\t\treturn haversineDistance(this, LatLng.from(other), 6371000);\n\t}\n\n\t/**\n\t * Returns a new `LatLng` object with the longitude wrapped so it's always between\n\t * -180 and +180 degrees.\n\t * @returns {LatLng}\n\t */\n\twrap() {\n\t\treturn new LatLng(this.lat, Util.wrapNum(this.lng, [-180, 180], true), this.alt);\n\t}\n\n\t/**\n\t * Returns a new `LatLngBounds` object in which each boundary is `sizeInMeters/2`\n\t * meters apart from the `LatLng`.\n\t * @param {number} sizeInMeters\n\t * @returns {LatLngBounds}\n\t */\n\ttoBounds(sizeInMeters) {\n\t\tconst latAccuracy = 180 * sizeInMeters / 40075017,\n\t\tlngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat);\n\n\t\treturn new LatLngBounds(\n\t\t\t[this.lat - latAccuracy, this.lng - lngAccuracy],\n\t\t\t[this.lat + latAccuracy, this.lng + lngAccuracy]);\n\t}\n\n};\n\n/**\n * The great-circle distance on a sphere of radius `R`, shared with `EarthCRS.distance()`.\n * @param {LatLng} latlng1\n * @param {LatLng} latlng2\n * @param {number} R\n * @returns {number}\n */\nexport function haversineDistance(latlng1, latlng2, R) {\n\tconst rad = Math.PI / 180,\n\tlat1 = latlng1.lat * rad,\n\tlat2 = latlng2.lat * rad,\n\tsinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2),\n\tsinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2),\n\ta = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon,\n\tc = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\treturn R * c;\n}\n"],"mappings":";;;AAIA,MAAM,aAAa,OAAO,GAAG;AAC7B,MAAA,YAAY,OAAO,GAAG;AAEtB,MAAA,UAAU,IAAI,OAAO,IAAI,aAAa,YAAY,WAAW,EAAE;AAE/D,MAAA,WAAW,IAAI,OAAO,gBAAgB,aAAa,UAAU,cAAc,WAAW,IAAI,GAAG;AAE7F,MAAA,WAAW,IAAI,OAAO,IAAI,WAAW,cAAc,YAAY,WAAW,gBAAgB,GAAG;AAC7F,MAAA,eAAe;AAEf,MAAA,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCX,IAAa,SAAb,MAAa,OAAO;;;;;;;;;;CAUnB,YAAY,KAAK,KAAK,KAAK;EAC1B,IAAI,OAAO,KAAK,OAAO,KAAK,OAAO;EACnC,IAAI,eAAe,QAClB,CAAC,CAAC,KAAK,MAAM,KAAK,MAAM,KAAK,QAAQ;OAC/B,IAAI,MAAM,QAAQ,GAAG,GAAG;GAC9B,OAAO,IAAI,UAAU,IAAI,IAAI,KAAK;GAClC,OAAO,IAAI;GACX,OAAO,IAAI;EACZ,OAAO,IAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;GACnD,OAAO,IAAI;GACX,OAAO,SAAS,MAAM,IAAI,MAAM,IAAI;GACpC,OAAO,IAAI;EACZ;;;;;EAMA,KAAK,MAAMA,SAAc,IAAI;;;;;EAM7B,KAAK,MAAMA,SAAc,IAAI;EAE7B,IAAI,MAAM,KAAK,GAAG,KAAK,MAAM,KAAK,GAAG,GACpC,MAAM,IAAI,MAAM,2BAA2B,KAAK,IAAI,KA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,UAAU,KAAK,KAAK,QAAQ,MAAM,QAAQ,OAAO,MAAM,CAAC,GACxD,UAAU,KAAK,KAAK,QAAQ,MAAM,QAAQ,OAAO,MAAM,CAAC,GACxD,IAAI,UAAU,UAAU,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,UAAU;CAEpE,OAAO,KADH,IAAI,KAAK,MAAM,KAAK,KAAK,CAAC,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC;AAElD"}
|
|
@@ -84,7 +84,7 @@ var LatLngBounds = class LatLngBounds {
|
|
|
84
84
|
({_southWest: sw2, _northEast: ne2} = obj);
|
|
85
85
|
if (!sw2) return this;
|
|
86
86
|
} else if (!obj) return this;
|
|
87
|
-
else if (
|
|
87
|
+
else if (isLatLngExpression(obj)) sw2 = ne2 = LatLng.from(obj);
|
|
88
88
|
else return this.extend(LatLngBounds.from(obj));
|
|
89
89
|
if (!sw) {
|
|
90
90
|
this._southWest = new LatLng(sw2.lat, sw2.lng);
|
|
@@ -177,7 +177,7 @@ var LatLngBounds = class LatLngBounds {
|
|
|
177
177
|
* @returns {boolean}
|
|
178
178
|
*/
|
|
179
179
|
contains(obj) {
|
|
180
|
-
if (
|
|
180
|
+
if (isLatLngExpression(obj)) obj = LatLng.from(obj);
|
|
181
181
|
else obj = LatLngBounds.from(obj);
|
|
182
182
|
const sw = this._southWest, ne = this._northEast;
|
|
183
183
|
let sw2, ne2;
|
|
@@ -206,7 +206,7 @@ var LatLngBounds = class LatLngBounds {
|
|
|
206
206
|
*/
|
|
207
207
|
overlaps(bounds) {
|
|
208
208
|
bounds = LatLngBounds.from(bounds);
|
|
209
|
-
const sw = this._southWest, ne = this._northEast, sw2 = bounds.getSouthWest(), ne2 = bounds.getNorthEast(), latOverlaps =
|
|
209
|
+
const sw = this._southWest, ne = this._northEast, sw2 = bounds.getSouthWest(), ne2 = bounds.getNorthEast(), latOverlaps = Math.max(sw.lat, sw2.lat) < Math.min(ne.lat, ne2.lat), lngOverlaps = Math.max(sw.lng, sw2.lng) < Math.min(ne.lng, ne2.lng);
|
|
210
210
|
return latOverlaps && lngOverlaps;
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
@@ -244,6 +244,9 @@ var LatLngBounds = class LatLngBounds {
|
|
|
244
244
|
return !!(this._southWest && this._northEast);
|
|
245
245
|
}
|
|
246
246
|
};
|
|
247
|
+
function isLatLngExpression(obj) {
|
|
248
|
+
return obj instanceof LatLng || (Array.isArray(obj) ? typeof obj[0] !== "object" : typeof obj === "object" && obj !== null && "lat" in obj);
|
|
249
|
+
}
|
|
247
250
|
export { LatLngBounds };
|
|
248
251
|
|
|
249
252
|
//# sourceMappingURL=LatLngBounds.js.map
|