maplair 4.4.0 → 4.5.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 +62 -0
- package/dist/esm/control/AttributionControl.js +20 -3
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +35 -20
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +3 -3
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/ZoomControl.js +1 -0
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Util.js +1 -1
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +19 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/Draggable.js +6 -2
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +1 -1
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +1 -1
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +1 -1
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +4 -2
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +10 -3
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +2 -1
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +3 -3
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +1 -1
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +1 -1
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +3 -4
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +31 -22
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +25 -6
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +5 -5
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +5 -5
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +11 -5
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +10 -6
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +2 -2
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +2 -3
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +6 -3
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +3 -2
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +58 -26
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -1
- 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/DragHandler.js +7 -2
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +289 -140
- 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 +289 -140
- 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/package.json +1 -1
- package/src/control/AttributionControl.js +29 -3
- package/src/control/LayersControl.js +47 -27
- package/src/control/ScaleControl.js +6 -3
- package/src/control/ZoomControl.js +1 -0
- package/src/core/Util.js +1 -1
- package/src/dom/DomEvent.PointerEvents.js +22 -2
- package/src/dom/Draggable.js +6 -2
- package/src/geo/LatLng.js +2 -1
- package/src/geo/LatLngBounds.js +1 -1
- package/src/geometry/Bounds.js +1 -1
- package/src/geometry/Point.js +4 -2
- package/src/geometry/PolyUtil.js +12 -3
- package/src/layer/BlanketOverlay.js +5 -2
- package/src/layer/DivOverlay.js +3 -3
- package/src/layer/ImageOverlay.js +3 -2
- package/src/layer/Layer.js +1 -1
- package/src/layer/Popup.js +3 -4
- package/src/layer/Tooltip.js +34 -27
- package/src/layer/marker/Icon.js +25 -5
- package/src/layer/marker/Marker.Drag.js +6 -6
- package/src/layer/marker/Marker.js +5 -5
- package/src/layer/tile/GridLayer.js +20 -7
- package/src/layer/tile/TileLayer.js +14 -7
- package/src/layer/tile/WMSTileLayer.js +4 -2
- package/src/layer/vector/Canvas.js +2 -2
- package/src/layer/vector/Circle.js +3 -5
- package/src/layer/vector/CircleMarker.js +5 -2
- package/src/layer/vector/Path.ZoomStyles.js +5 -3
- package/src/map/Map.Rotation.js +6 -3
- package/src/map/Map.js +63 -32
- package/src/map/MapSync.js +1 -1
- package/src/map/handler/BoxZoomHandler.js +3 -0
- package/src/map/handler/DragHandler.js +5 -5
- package/src/map/handler/PinchZoomHandler.js +1 -1
- package/src/map/handler/ScrollWheelZoomHandler.js +1 -1
- package/src/map/handler/TapDragZoomHandler.js +1 -1
- package/src/maplair.css +12 -1
|
@@ -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\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\
|
|
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/**\n * Whether `el` is inside an element that `DomEvent.disableClickPropagation` was called\n * on (before reaching `container`), or detached from the DOM.\n * @internal\n * @param {Node|null} el\n * @param {EventTarget|null} container\n * @returns {boolean}\n */\nfunction isClickDisabled(el, container) {\n\twhile (el && el !== container) {\n\t\tif (el['_maplair_disable_click'] || !el.parentNode) { return true; }\n\t\tel = el.parentNode;\n\t}\n\treturn false;\n}\n\nfunction _onSet(e) {\n\tlastPointerType = e.pointerType;\n\t// pointers in controls and popups can't start map interactions, and capturing them breaks native widgets there\n\t// (like the clear button of a search input), so leave them to the browser\n\tif (isClickDisabled(e.target, e.currentTarget)) { return; }\n\t// capturing throws for synthetic pointers the browser doesn't know about, so only capture real ones\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\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\tisClickDisabled,\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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EAAE,WAAW,KAAK,oBAAoB,WAAW,OAAO,QAAQ,OAAO,GAAG;EAC7E,aAAa;EACb;CACD;CACA,MAAM,MAAM,KAAK,IAAI;CACrB,aAAa,MAAM,iBAAiB,OAAO,iBAAiB,eAAe,aAAa,IAAI;CAC5F,gBAAgB;CAChB,eAAe;CAEf,IAAI,eAAe,GAAG;EACrB,MAAM,OAAO,EAAC,QAAQ,EAAC;EACvB,KAAK,MAAM,QAAQ,eAAiB,KAAK,QAAQ,EAAE;EACnD,OAAO,cAAc,IAAI,WAAW,YAAY,IAAI,CAAC;CACtD;AACD"}
|
|
@@ -14,9 +14,13 @@ import { Evented } from "../core/Events.js";
|
|
|
14
14
|
* pointer drag).
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
17
|
-
* The event object of `dragstart`, `predrag` and `drag` of `Draggable
|
|
17
|
+
* The event object of `dragstart`, `predrag` and `drag` of `Draggable`, and of
|
|
18
|
+
* `movestart` and `dragstart` of draggable markers.
|
|
18
19
|
* @typedef {object} DraggableEvent
|
|
19
|
-
* @property {PointerEvent} originalEvent The DOM event of the pointer which
|
|
20
|
+
* @property {PointerEvent|KeyboardEvent} originalEvent The DOM event of the pointer which
|
|
21
|
+
* drags: for `dragstart`, the `pointermove` that moved the pointer past `clickTolerance`
|
|
22
|
+
* (not the `pointerdown`), or the `keydown` of an arrow key that moves a focused
|
|
23
|
+
* draggable marker.
|
|
20
24
|
* @extends MaplairEvent
|
|
21
25
|
*/
|
|
22
26
|
/**
|
|
@@ -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\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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til.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`, and of\n * `movestart` and `dragstart` of draggable markers.\n * @typedef {object} DraggableEvent\n * @property {PointerEvent|KeyboardEvent} originalEvent The DOM event of the pointer which\n * drags: for `dragstart`, the `pointermove` that moved the pointer past `clickTolerance`\n * (not the `pointerdown`), or the `keydown` of an arrow key that moves a focused\n * draggable marker.\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,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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AkB,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
|
@@ -206,7 +206,7 @@ var LatLng = class LatLng {
|
|
|
206
206
|
* @returns {number}
|
|
207
207
|
*/
|
|
208
208
|
function haversineDistance(latlng1, latlng2, R) {
|
|
209
|
-
const rad = Math.PI / 180, lat1 = latlng1.lat * rad, lat2 = latlng2.lat * rad, sinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2), sinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2), a = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon;
|
|
209
|
+
const rad = Math.PI / 180, lat1 = latlng1.lat * rad, lat2 = latlng2.lat * rad, sinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2), sinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2), a = Math.min(sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon, 1);
|
|
210
210
|
return R * (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
|
|
211
211
|
}
|
|
212
212
|
export { LatLng, haversineDistance };
|
|
@@ -1 +1 @@
|
|
|
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,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,MAAM,IAAI,GAAG,CAEhB,MAAM,aAAa;CAChC;;;;;;CAOA,SAAS,WAAW;EACnB,OAAO,UAAUC,UAAe,KAAK,KAAK,SAAS,EAAE,IAAIA,UAAe,KAAK,KAAK,SAAS,EAAE;CAC9F;;;;;;;CAQA,WAAW,OAAO;EACjB,OAAO,kBAAkB,MAAM,OAAO,KAAK,KAAK,GAAG,MAAO;CAC3D;;;;;;CAOA,OAAO;EACN,OAAO,IAAI,OAAO,KAAK,KAAKC,QAAa,KAAK,KAAK,CAAC,MAAM,GAAG,GAAG,IAAI,GAAG,KAAK,GAAG;CAChF;;;;;;;CAQA,SAAS,cAAc;EACtB,MAAM,cAAc,MAAM,eAAe,UACzC,cAAc,cAAc,KAAK,IAAK,KAAK,KAAK,MAAO,KAAK,GAAG;EAE/D,OAAO,IAAI,aACV,CAAC,KAAK,MAAM,aAAa,KAAK,MAAM,WAAW,GAC/C,CAAC,KAAK,MAAM,aAAa,KAAK,MAAM,WAAW,CAAC;CAClD;AAED;;;;;;;;AASA,SAAgB,kBAAkB,SAAS,SAAS,GAAG;CACtD,MAAM,MAAM,KAAK,KAAK,KACtB,OAAO,QAAQ,MAAM,KACrB,OAAO,QAAQ,MAAM,KACrB,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"}
|
|
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\t// clamp, since rounding can push this slightly above 1 for antipodal points and make `sqrt(1 - a)` NaN\n\ta = Math.min(sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon, 1),\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;A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245,7 +245,7 @@ var LatLngBounds = class LatLngBounds {
|
|
|
245
245
|
}
|
|
246
246
|
};
|
|
247
247
|
function isLatLngExpression(obj) {
|
|
248
|
-
return obj instanceof LatLng || (Array.isArray(obj) ? typeof obj[0] !== "object" : typeof obj === "object" && obj !== null && "lat" in obj);
|
|
248
|
+
return obj instanceof LatLng || (Array.isArray(obj) ? obj.length > 0 && typeof obj[0] !== "object" : typeof obj === "object" && obj !== null && "lat" in obj);
|
|
249
249
|
}
|
|
250
250
|
export { LatLngBounds };
|
|
251
251
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LatLngBounds.js","names":[],"sources":["../../../src/geo/LatLngBounds.js"],"sourcesContent":["import {LatLng} from './LatLng.js';\n/** @import {LatLngExpression} from './LatLng.js' */\n\n/**\n * A geographical area: a `LatLngBounds`, or an array of geographical points (usually\n * two diagonally opposite corners), e.g. `[[40.712, -74.227], [40.774, -74.125]]`.\n * Accepted by all Maplair methods which accept `LatLngBounds` objects (unless noted\n * otherwise).\n * @typedef {LatLngBounds|LatLngExpression[]} LatLngBoundsExpression\n */\n\n// TODO International date line?\n\n/**\n * Represents a rectangular geographical area on a map.\n *\n * @example\n * ```js\n * const corner1 = new LatLng(40.712, -74.227),\n * corner2 = new LatLng(40.774, -74.125),\n * bounds = new LatLngBounds(corner1, corner2);\n * ```\n *\n * All Maplair methods that accept LatLngBounds objects also accept them in a simple\n * Array form (unless noted otherwise), so the bounds example above can be passed like\n * this:\n *\n * ```js\n * map.fitBounds([\n * \t[40.712, -74.227],\n * \t[40.774, -74.125]\n * ]);\n * ```\n *\n * Caution: if the area crosses the antimeridian (often confused with the International\n * Date Line), you must specify corners _outside_ the [-180, 180] degrees longitude range.\n *\n * Note that `LatLngBounds` 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 LatLngBounds {\n\t/**\n\t * Creates a `LatLngBounds` object by defining two diagonally opposite corners of the\n\t * rectangle. Alternatively, creates a `LatLngBounds` object defined by the\n\t * geographical points it contains (very useful for zooming the map to fit a\n\t * particular set of locations with [`fitBounds`](#map-fitbounds)), or a copy of the\n\t * given `LatLngBounds` object.\n\t * @param {LatLngExpression|LatLngBoundsExpression} [corner1] The first corner, the\n\t * points or the bounds to copy.\n\t * @param {LatLngExpression} [corner2] The opposite corner.\n\t */\n\tconstructor(corner1, corner2) { // (LatLng, LatLng) or (LatLng[])\n\t\tif (!corner1) { return; }\n\n\t\tif (corner1 instanceof LatLngBounds) {\n\t\t\tif (corner1.isValid()) {\n\t\t\t\tthis._southWest = new LatLng(corner1._southWest);\n\t\t\t\tthis._northEast = new LatLng(corner1._northEast);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst latlngs = corner2 ? [corner1, corner2] : corner1;\n\n\t\tfor (const latlng of latlngs) {\n\t\t\tthis.extend(latlng);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the given `LatLngBounds` object as it is, or else a new `LatLngBounds`\n\t * object created from the given arguments (the same as of the constructor) — unlike\n\t * the constructor, which always creates a new object.\n\t * @param {LatLngExpression|LatLngBoundsExpression} [corner1] The first corner, the\n\t * points or the bounds.\n\t * @param {LatLngExpression} [corner2] The opposite corner.\n\t * @returns {LatLngBounds}\n\t */\n\tstatic from(corner1, corner2) {\n\t\treturn corner1 instanceof LatLngBounds ? corner1 : new LatLngBounds(corner1, corner2);\n\t}\n\n\t/**\n\t * Extend the bounds to contain the given point or bounds.\n\t * @param {LatLngExpression|LatLngBoundsExpression} obj\n\t * @returns {this}\n\t */\n\textend(obj) {\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast;\n\t\tlet sw2, ne2;\n\n\t\tif (obj instanceof LatLng) {\n\t\t\tsw2 = ne2 = obj;\n\t\t} else if (obj instanceof LatLngBounds) {\n\t\t\t({_southWest: sw2, _northEast: ne2} = obj);\n\t\t\tif (!sw2) { return this; }\n\t\t} else if (!obj) {\n\t\t\treturn this;\n\t\t} else if (isLatLngExpression(obj)) {\n\t\t\tsw2 = ne2 = LatLng.from(obj);\n\t\t} else {\n\t\t\treturn this.extend(LatLngBounds.from(obj));\n\t\t}\n\n\t\tif (!sw) {\n\t\t\tthis._southWest = new LatLng(sw2.lat, sw2.lng);\n\t\t\tthis._northEast = new LatLng(ne2.lat, ne2.lng);\n\t\t} else {\n\t\t\tsw.lat = Math.min(sw2.lat, sw.lat);\n\t\t\tsw.lng = Math.min(sw2.lng, sw.lng);\n\t\t\tne.lat = Math.max(ne2.lat, ne.lat);\n\t\t\tne.lng = Math.max(ne2.lng, ne.lng);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns bounds created by extending or retracting the current bounds by a given\n\t * ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in\n\t * each direction. Negative values will retract the bounds.\n\t * @param {number} bufferRatio\n\t * @returns {LatLngBounds}\n\t */\n\tpad(bufferRatio) {\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\theightBuffer = Math.abs(sw.lat - ne.lat) * bufferRatio,\n\t\twidthBuffer = Math.abs(sw.lng - ne.lng) * bufferRatio;\n\n\t\treturn new LatLngBounds(\n\t\t\tnew LatLng(sw.lat - heightBuffer, sw.lng - widthBuffer),\n\t\t\tnew LatLng(ne.lat + heightBuffer, ne.lng + widthBuffer));\n\t}\n\n\t/**\n\t * Returns the center point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\treturn new LatLng(\n\t\t\t(this._southWest.lat + this._northEast.lat) / 2,\n\t\t\t(this._southWest.lng + this._northEast.lng) / 2);\n\t}\n\n\t/**\n\t * Returns the south-west point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetSouthWest() {\n\t\treturn this._southWest;\n\t}\n\n\t/**\n\t * Returns the north-east point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetNorthEast() {\n\t\treturn this._northEast;\n\t}\n\n\t/**\n\t * Returns the north-west point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetNorthWest() {\n\t\treturn new LatLng(this.getNorth(), this.getWest());\n\t}\n\n\t/**\n\t * Returns the south-east point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetSouthEast() {\n\t\treturn new LatLng(this.getSouth(), this.getEast());\n\t}\n\n\t/**\n\t * Returns the west longitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetWest() {\n\t\treturn this._southWest.lng;\n\t}\n\n\t/**\n\t * Returns the south latitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetSouth() {\n\t\treturn this._southWest.lat;\n\t}\n\n\t/**\n\t * Returns the east longitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetEast() {\n\t\treturn this._northEast.lng;\n\t}\n\n\t/**\n\t * Returns the north latitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetNorth() {\n\t\treturn this._northEast.lat;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle contains the given bounds or point.\n\t * @param {LatLngBoundsExpression|LatLngExpression} obj\n\t * @returns {boolean}\n\t */\n\tcontains(obj) { // (LatLngBounds) or (LatLng) -> Boolean\n\t\tif (isLatLngExpression(obj)) {\n\t\t\tobj = LatLng.from(obj);\n\t\t} else {\n\t\t\tobj = LatLngBounds.from(obj);\n\t\t}\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast;\n\t\tlet sw2, ne2;\n\n\t\tif (obj instanceof LatLngBounds) {\n\t\t\tsw2 = obj.getSouthWest();\n\t\t\tne2 = obj.getNorthEast();\n\t\t} else {\n\t\t\tsw2 = ne2 = obj;\n\t\t}\n\n\t\treturn (sw2.lat >= sw.lat) && (ne2.lat <= ne.lat) &&\n\t\t (sw2.lng >= sw.lng) && (ne2.lng <= ne.lng);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle intersects the given bounds. Two bounds intersect\n\t * if they have at least one point in common.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tintersects(bounds) {\n\t\tbounds = LatLngBounds.from(bounds);\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\tsw2 = bounds.getSouthWest(),\n\t\tne2 = bounds.getNorthEast(),\n\n\t\tlatIntersects = (ne2.lat >= sw.lat) && (sw2.lat <= ne.lat),\n\t\tlngIntersects = (ne2.lng >= sw.lng) && (sw2.lng <= ne.lng);\n\n\t\treturn latIntersects && lngIntersects;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle overlaps the given bounds. Two bounds overlap if\n\t * their intersection is an area.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\toverlaps(bounds) {\n\t\tbounds = LatLngBounds.from(bounds);\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\tsw2 = bounds.getSouthWest(),\n\t\tne2 = bounds.getNorthEast(),\n\n\t\tlatOverlaps = Math.max(sw.lat, sw2.lat) < Math.min(ne.lat, ne2.lat),\n\t\tlngOverlaps = Math.max(sw.lng, sw2.lng) < Math.min(ne.lng, ne2.lng);\n\n\t\treturn latOverlaps && lngOverlaps;\n\t}\n\n\t/**\n\t * Returns a string with bounding box coordinates in a\n\t * 'southwest_lng,southwest_lat,northeast_lng,northeast_lat' format. Useful for\n\t * sending requests to web services that return geo data.\n\t * @returns {string}\n\t */\n\ttoBBoxString() {\n\t\treturn [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(',');\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle is equivalent (within a small margin of error) to\n\t * the given bounds. The margin of error can be overridden by setting `maxMargin` to\n\t * a small number.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {number} [maxMargin]\n\t * @returns {boolean}\n\t */\n\tequals(bounds, maxMargin) {\n\t\tif (!bounds) { return false; }\n\n\t\tbounds = LatLngBounds.from(bounds);\n\n\t\treturn this._southWest.equals(bounds.getSouthWest(), maxMargin) &&\n\t\t this._northEast.equals(bounds.getNorthEast(), maxMargin);\n\t}\n\n\t/**\n\t * Returns `true` if the bounds are properly initialized.\n\t * @returns {boolean}\n\t */\n\tisValid() {\n\t\treturn !!(this._southWest && this._northEast);\n\t}\n}\n\n// Whether `obj` has the shape of a `LatLngExpression` rather than of bounds.\nfunction isLatLngExpression(obj) {\n\treturn obj instanceof LatLng || (Array.isArray(obj) ? typeof obj[0] !== 'object' :\n\t\ttypeof obj === 'object' && obj !== null && 'lat' in obj);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,eAAb,MAAa,aAAa;;;;;;;;;;;CAWzB,YAAY,SAAS,SAAS;EAC7B,IAAI,CAAC,SAAW;EAEhB,IAAI,mBAAmB,cAAc;GACpC,IAAI,QAAQ,QAAQ,GAAG;IACtB,KAAK,aAAa,IAAI,OAAO,QAAQ,UAAU;IAC/C,KAAK,aAAa,IAAI,OAAO,QAAQ,UAAU;GAChD;GACA;EACD;EAEA,MAAM,UAAU,UAAU,CAAC,SAAS,OAAO,IAAI;EAE/C,KAAK,MAAM,UAAU,SACpB,KAAK,OAAO,MAAM;CAEpB;;;;;;;;;;CAWA,OAAO,KAAK,SAAS,SAAS;EAC7B,OAAO,mBAAmB,eAAe,UAAU,IAAI,aAAa,SAAS,OAAO;CACrF;;;;;;CAOA,OAAO,KAAK;EACX,MAAM,KAAK,KAAK,YAChB,KAAK,KAAK;EACV,IAAI,KAAK;EAET,IAAI,eAAe,QAClB,MAAM,MAAM;OACN,IAAI,eAAe,cAAc;GACvC,CAAC,CAAC,YAAY,KAAK,YAAY,OAAO;GACtC,IAAI,CAAC,KAAO,OAAO;EACpB,OAAO,IAAI,CAAC,KACX,OAAO;OACD,IAAI,mBAAmB,GAAG,GAChC,MAAM,MAAM,OAAO,KAAK,GAAG;OAE3B,OAAO,KAAK,OAAO,aAAa,KAAK,GAAG,CAAC;EAG1C,IAAI,CAAC,IAAI;GACR,KAAK,aAAa,IAAI,OAAO,IAAI,KAAK,IAAI,GAAG;GAC7C,KAAK,aAAa,IAAI,OAAO,IAAI,KAAK,IAAI,GAAG;EA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,GAAG,SAAS;CAC/D;;;;;CAMA,UAAU;EACT,OAAO,CAAC,EAAE,KAAK,cAAc,KAAK;CACnC;AACD;AAGA,SAAS,mBAAmB,KAAK;CAChC,OAAO,eAAe,WAAW,MAAM,QAAQ,GAAG,IAAI,OAAO,IAAI,OAAO,WACvE,OAAO,QAAQ,YAAY,QAAQ,QAAQ,SAAS;AACtD"}
|
|
1
|
+
{"version":3,"file":"LatLngBounds.js","names":[],"sources":["../../../src/geo/LatLngBounds.js"],"sourcesContent":["import {LatLng} from './LatLng.js';\n/** @import {LatLngExpression} from './LatLng.js' */\n\n/**\n * A geographical area: a `LatLngBounds`, or an array of geographical points (usually\n * two diagonally opposite corners), e.g. `[[40.712, -74.227], [40.774, -74.125]]`.\n * Accepted by all Maplair methods which accept `LatLngBounds` objects (unless noted\n * otherwise).\n * @typedef {LatLngBounds|LatLngExpression[]} LatLngBoundsExpression\n */\n\n// TODO International date line?\n\n/**\n * Represents a rectangular geographical area on a map.\n *\n * @example\n * ```js\n * const corner1 = new LatLng(40.712, -74.227),\n * corner2 = new LatLng(40.774, -74.125),\n * bounds = new LatLngBounds(corner1, corner2);\n * ```\n *\n * All Maplair methods that accept LatLngBounds objects also accept them in a simple\n * Array form (unless noted otherwise), so the bounds example above can be passed like\n * this:\n *\n * ```js\n * map.fitBounds([\n * \t[40.712, -74.227],\n * \t[40.774, -74.125]\n * ]);\n * ```\n *\n * Caution: if the area crosses the antimeridian (often confused with the International\n * Date Line), you must specify corners _outside_ the [-180, 180] degrees longitude range.\n *\n * Note that `LatLngBounds` 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 LatLngBounds {\n\t/**\n\t * Creates a `LatLngBounds` object by defining two diagonally opposite corners of the\n\t * rectangle. Alternatively, creates a `LatLngBounds` object defined by the\n\t * geographical points it contains (very useful for zooming the map to fit a\n\t * particular set of locations with [`fitBounds`](#map-fitbounds)), or a copy of the\n\t * given `LatLngBounds` object.\n\t * @param {LatLngExpression|LatLngBoundsExpression} [corner1] The first corner, the\n\t * points or the bounds to copy.\n\t * @param {LatLngExpression} [corner2] The opposite corner.\n\t */\n\tconstructor(corner1, corner2) { // (LatLng, LatLng) or (LatLng[])\n\t\tif (!corner1) { return; }\n\n\t\tif (corner1 instanceof LatLngBounds) {\n\t\t\tif (corner1.isValid()) {\n\t\t\t\tthis._southWest = new LatLng(corner1._southWest);\n\t\t\t\tthis._northEast = new LatLng(corner1._northEast);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst latlngs = corner2 ? [corner1, corner2] : corner1;\n\n\t\tfor (const latlng of latlngs) {\n\t\t\tthis.extend(latlng);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the given `LatLngBounds` object as it is, or else a new `LatLngBounds`\n\t * object created from the given arguments (the same as of the constructor) — unlike\n\t * the constructor, which always creates a new object.\n\t * @param {LatLngExpression|LatLngBoundsExpression} [corner1] The first corner, the\n\t * points or the bounds.\n\t * @param {LatLngExpression} [corner2] The opposite corner.\n\t * @returns {LatLngBounds}\n\t */\n\tstatic from(corner1, corner2) {\n\t\treturn corner1 instanceof LatLngBounds ? corner1 : new LatLngBounds(corner1, corner2);\n\t}\n\n\t/**\n\t * Extend the bounds to contain the given point or bounds.\n\t * @param {LatLngExpression|LatLngBoundsExpression} obj\n\t * @returns {this}\n\t */\n\textend(obj) {\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast;\n\t\tlet sw2, ne2;\n\n\t\tif (obj instanceof LatLng) {\n\t\t\tsw2 = ne2 = obj;\n\t\t} else if (obj instanceof LatLngBounds) {\n\t\t\t({_southWest: sw2, _northEast: ne2} = obj);\n\t\t\tif (!sw2) { return this; }\n\t\t} else if (!obj) {\n\t\t\treturn this;\n\t\t} else if (isLatLngExpression(obj)) {\n\t\t\tsw2 = ne2 = LatLng.from(obj);\n\t\t} else {\n\t\t\treturn this.extend(LatLngBounds.from(obj));\n\t\t}\n\n\t\tif (!sw) {\n\t\t\tthis._southWest = new LatLng(sw2.lat, sw2.lng);\n\t\t\tthis._northEast = new LatLng(ne2.lat, ne2.lng);\n\t\t} else {\n\t\t\tsw.lat = Math.min(sw2.lat, sw.lat);\n\t\t\tsw.lng = Math.min(sw2.lng, sw.lng);\n\t\t\tne.lat = Math.max(ne2.lat, ne.lat);\n\t\t\tne.lng = Math.max(ne2.lng, ne.lng);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns bounds created by extending or retracting the current bounds by a given\n\t * ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in\n\t * each direction. Negative values will retract the bounds.\n\t * @param {number} bufferRatio\n\t * @returns {LatLngBounds}\n\t */\n\tpad(bufferRatio) {\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\theightBuffer = Math.abs(sw.lat - ne.lat) * bufferRatio,\n\t\twidthBuffer = Math.abs(sw.lng - ne.lng) * bufferRatio;\n\n\t\treturn new LatLngBounds(\n\t\t\tnew LatLng(sw.lat - heightBuffer, sw.lng - widthBuffer),\n\t\t\tnew LatLng(ne.lat + heightBuffer, ne.lng + widthBuffer));\n\t}\n\n\t/**\n\t * Returns the center point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\treturn new LatLng(\n\t\t\t(this._southWest.lat + this._northEast.lat) / 2,\n\t\t\t(this._southWest.lng + this._northEast.lng) / 2);\n\t}\n\n\t/**\n\t * Returns the south-west point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetSouthWest() {\n\t\treturn this._southWest;\n\t}\n\n\t/**\n\t * Returns the north-east point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetNorthEast() {\n\t\treturn this._northEast;\n\t}\n\n\t/**\n\t * Returns the north-west point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetNorthWest() {\n\t\treturn new LatLng(this.getNorth(), this.getWest());\n\t}\n\n\t/**\n\t * Returns the south-east point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetSouthEast() {\n\t\treturn new LatLng(this.getSouth(), this.getEast());\n\t}\n\n\t/**\n\t * Returns the west longitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetWest() {\n\t\treturn this._southWest.lng;\n\t}\n\n\t/**\n\t * Returns the south latitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetSouth() {\n\t\treturn this._southWest.lat;\n\t}\n\n\t/**\n\t * Returns the east longitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetEast() {\n\t\treturn this._northEast.lng;\n\t}\n\n\t/**\n\t * Returns the north latitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetNorth() {\n\t\treturn this._northEast.lat;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle contains the given bounds or point.\n\t * @param {LatLngBoundsExpression|LatLngExpression} obj\n\t * @returns {boolean}\n\t */\n\tcontains(obj) { // (LatLngBounds) or (LatLng) -> Boolean\n\t\tif (isLatLngExpression(obj)) {\n\t\t\tobj = LatLng.from(obj);\n\t\t} else {\n\t\t\tobj = LatLngBounds.from(obj);\n\t\t}\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast;\n\t\tlet sw2, ne2;\n\n\t\tif (obj instanceof LatLngBounds) {\n\t\t\tsw2 = obj.getSouthWest();\n\t\t\tne2 = obj.getNorthEast();\n\t\t} else {\n\t\t\tsw2 = ne2 = obj;\n\t\t}\n\n\t\treturn (sw2.lat >= sw.lat) && (ne2.lat <= ne.lat) &&\n\t\t (sw2.lng >= sw.lng) && (ne2.lng <= ne.lng);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle intersects the given bounds. Two bounds intersect\n\t * if they have at least one point in common.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tintersects(bounds) {\n\t\tbounds = LatLngBounds.from(bounds);\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\tsw2 = bounds.getSouthWest(),\n\t\tne2 = bounds.getNorthEast(),\n\n\t\tlatIntersects = (ne2.lat >= sw.lat) && (sw2.lat <= ne.lat),\n\t\tlngIntersects = (ne2.lng >= sw.lng) && (sw2.lng <= ne.lng);\n\n\t\treturn latIntersects && lngIntersects;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle overlaps the given bounds. Two bounds overlap if\n\t * their intersection is an area.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\toverlaps(bounds) {\n\t\tbounds = LatLngBounds.from(bounds);\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\tsw2 = bounds.getSouthWest(),\n\t\tne2 = bounds.getNorthEast(),\n\n\t\tlatOverlaps = Math.max(sw.lat, sw2.lat) < Math.min(ne.lat, ne2.lat),\n\t\tlngOverlaps = Math.max(sw.lng, sw2.lng) < Math.min(ne.lng, ne2.lng);\n\n\t\treturn latOverlaps && lngOverlaps;\n\t}\n\n\t/**\n\t * Returns a string with bounding box coordinates in a\n\t * 'southwest_lng,southwest_lat,northeast_lng,northeast_lat' format. Useful for\n\t * sending requests to web services that return geo data.\n\t * @returns {string}\n\t */\n\ttoBBoxString() {\n\t\treturn [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(',');\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle is equivalent (within a small margin of error) to\n\t * the given bounds. The margin of error can be overridden by setting `maxMargin` to\n\t * a small number.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {number} [maxMargin]\n\t * @returns {boolean}\n\t */\n\tequals(bounds, maxMargin) {\n\t\tif (!bounds) { return false; }\n\n\t\tbounds = LatLngBounds.from(bounds);\n\n\t\treturn this._southWest.equals(bounds.getSouthWest(), maxMargin) &&\n\t\t this._northEast.equals(bounds.getNorthEast(), maxMargin);\n\t}\n\n\t/**\n\t * Returns `true` if the bounds are properly initialized.\n\t * @returns {boolean}\n\t */\n\tisValid() {\n\t\treturn !!(this._southWest && this._northEast);\n\t}\n}\n\n// Whether `obj` has the shape of a `LatLngExpression` rather than of bounds.\nfunction isLatLngExpression(obj) {\n\tretur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K;CAChC,OAAO,eAAe,WAAW,MAAM,QAAQ,GAAG,IAAI,IAAI,SAAS,KAAK,OAAO,IAAI,OAAO,WACzF,OAAO,QAAQ,YAAY,QAAQ,QAAQ,SAAS;AACtD"}
|
|
@@ -198,7 +198,7 @@ var Bounds = class Bounds {
|
|
|
198
198
|
}
|
|
199
199
|
};
|
|
200
200
|
function isPointExpression(obj) {
|
|
201
|
-
return obj instanceof Point || (Array.isArray(obj) ? typeof obj[0] !== "object" : "x" in obj);
|
|
201
|
+
return obj instanceof Point || (Array.isArray(obj) ? obj.length > 0 && typeof obj[0] !== "object" : "x" in obj);
|
|
202
202
|
}
|
|
203
203
|
export { Bounds };
|
|
204
204
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bounds.js","names":[],"sources":["../../../src/geometry/Bounds.js"],"sourcesContent":["import {Point} from './Point.js';\n/** @import {PointExpression} from './Point.js' */\n\n/**\n * A rectangular area in pixel coordinates: a `Bounds`, or an array of points (usually\n * two diagonally opposite corners), e.g. `[[10, 10], [40, 60]]`. Accepted by all\n * Maplair methods which accept `Bounds` objects (unless noted otherwise).\n * @typedef {Bounds|PointExpression[]} BoundsExpression\n */\n\n/**\n * Represents a rectangular area in pixel coordinates.\n *\n * @example\n * ```js\n * const p1 = new Point(10, 10),\n * p2 = new Point(40, 60),\n * bounds = new Bounds(p1, p2);\n * ```\n *\n * All Maplair methods that accept `Bounds` objects also accept them in a simple Array\n * form (unless noted otherwise), so the bounds example above can be passed like this:\n *\n * ```js\n * otherBounds.intersects([[10, 10], [40, 60]]);\n * ```\n *\n * Note that `Bounds` 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 Bounds {\n\t/**\n\t * Creates a Bounds object from two corners coordinate pairs. Alternatively, creates a\n\t * Bounds object from the given array of points, or a copy of the given Bounds object.\n\t * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the\n\t * bounds to copy.\n\t * @param {PointExpression} [b] The opposite corner.\n\t */\n\tconstructor(a, b) {\n\t\tif (!a) { return; }\n\n\t\tif (a instanceof Bounds) {\n\t\t\tif (a.isValid()) {\n\t\t\t\t/**\n\t\t\t\t * The top left corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\n\t\t\t\tthis.min = new Point(a.min);\n\t\t\t\t/**\n\t\t\t\t * The bottom right corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\n\t\t\t\tthis.max = new Point(a.max);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst points = b ? [a, b] : a;\n\t\tfor (const point of points) {\n\t\t\tthis.extend(point);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the given `Bounds` object as it is, or else a new `Bounds` 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 * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the\n\t * bounds.\n\t * @param {PointExpression} [b] The opposite corner.\n\t * @returns {Bounds}\n\t */\n\tstatic from(a, b) {\n\t\treturn a instanceof Bounds ? a : new Bounds(a, b);\n\t}\n\n\t/**\n\t * Extends the bounds to contain the given point or bounds.\n\t * @param {PointExpression|BoundsExpression} obj\n\t * @returns {this}\n\t */\n\textend(obj) {\n\t\tlet min2, max2;\n\t\tif (!obj) { return this; }\n\n\t\tif (isPointExpression(obj)) {\n\t\t\tmin2 = max2 = Point.from(obj);\n\t\t} else {\n\t\t\t({min: min2, max: max2} = Bounds.from(obj));\n\t\t\tif (!min2) { return this; }\n\t\t}\n\n\t\tif (!this.min) {\n\t\t\tthis.min = new Point(min2);\n\t\t\tthis.max = new Point(max2);\n\t\t} else {\n\t\t\tthis.min.x = Math.min(min2.x, this.min.x);\n\t\t\tthis.max.x = Math.max(max2.x, this.max.x);\n\t\t\tthis.min.y = Math.min(min2.y, this.min.y);\n\t\t\tthis.max.y = Math.max(max2.y, this.max.y);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the center point of the bounds.\n\t * @param {boolean} [round]\n\t * @returns {Point}\n\t */\n\tgetCenter(round) {\n\t\treturn new Point(\n\t\t\t(this.min.x + this.max.x) / 2,\n\t\t\t(this.min.y + this.max.y) / 2, round);\n\t}\n\n\t/**\n\t * Returns the bottom-left point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetBottomLeft() {\n\t\treturn new Point(this.min.x, this.max.y);\n\t}\n\n\t/**\n\t * Returns the top-right point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetTopRight() { // -> Point\n\t\treturn new Point(this.max.x, this.min.y);\n\t}\n\n\t/**\n\t * Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-min)).\n\t * @returns {Point}\n\t */\n\tgetTopLeft() {\n\t\treturn this.min; // left, top\n\t}\n\n\t/**\n\t * Returns the bottom-right point of the bounds (i.e. [`this.max`](#bounds-max)).\n\t * @returns {Point}\n\t */\n\tgetBottomRight() {\n\t\treturn this.max; // right, bottom\n\t}\n\n\t/**\n\t * Returns the size of the given bounds.\n\t * @returns {Point}\n\t */\n\tgetSize() {\n\t\treturn this.max.subtract(this.min);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle contains the given bounds or point.\n\t * @param {BoundsExpression|PointExpression} obj\n\t * @returns {boolean}\n\t */\n\tcontains(obj) {\n\t\tlet min, max;\n\n\t\tif (isPointExpression(obj)) {\n\t\t\tmin = max = Point.from(obj);\n\t\t} else {\n\t\t\t({min, max} = Bounds.from(obj));\n\t\t}\n\n\t\treturn (min.x >= this.min.x) &&\n\t\t (max.x <= this.max.x) &&\n\t\t (min.y >= this.min.y) &&\n\t\t (max.y <= this.max.y);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle intersects the given bounds. Two bounds\n\t * intersect if they have at least one point in common.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tintersects(bounds) { // (Bounds) -> Boolean\n\t\tbounds = Bounds.from(bounds);\n\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\tmin2 = bounds.min,\n\t\tmax2 = bounds.max,\n\t\txIntersects = (max2.x >= min.x) && (min2.x <= max.x),\n\t\tyIntersects = (max2.y >= min.y) && (min2.y <= max.y);\n\n\t\treturn xIntersects && yIntersects;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle overlaps the given bounds. Two bounds\n\t * overlap if their intersection is an area.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\toverlaps(bounds) { // (Bounds) -> Boolean\n\t\tbounds = Bounds.from(bounds);\n\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\tmin2 = bounds.min,\n\t\tmax2 = bounds.max,\n\t\txOverlaps = Math.max(min.x, min2.x) < Math.min(max.x, max2.x),\n\t\tyOverlaps = Math.max(min.y, min2.y) < Math.min(max.y, max2.y);\n\n\t\treturn xOverlaps && yOverlaps;\n\t}\n\n\t/**\n\t * Returns `true` if the bounds are properly initialized.\n\t * @returns {boolean}\n\t */\n\tisValid() {\n\t\treturn !!(this.min && this.max);\n\t}\n\n\n\t/**\n\t * Returns bounds created by extending or retracting the current bounds by a given\n\t * ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in\n\t * each direction. Negative values will retract the bounds.\n\t * @param {number} bufferRatio\n\t * @returns {Bounds}\n\t */\n\tpad(bufferRatio) {\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\theightBuffer = Math.abs(min.x - max.x) * bufferRatio,\n\t\twidthBuffer = Math.abs(min.y - max.y) * bufferRatio;\n\n\n\t\treturn new Bounds(\n\t\t\tnew Point(min.x - heightBuffer, min.y - widthBuffer),\n\t\t\tnew Point(max.x + heightBuffer, max.y + widthBuffer));\n\t}\n\n\n\t/**\n\t * Returns `true` if the rectangle is equivalent to the given bounds.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tequals(bounds) {\n\t\tif (!bounds) { return false; }\n\n\t\tbounds = Bounds.from(bounds);\n\n\t\treturn this.min.equals(bounds.getTopLeft()) &&\n\t\t\tthis.max.equals(bounds.getBottomRight());\n\t}\n}\n\n// Whether `obj` is a point (or an array or object literal of one) rather than bounds\nfunction isPointExpression(obj) {\n\treturn obj instanceof Point || (Array.isArray(obj) ? typeof obj[0] !== 'object' : 'x' in obj);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAa,SAAb,MAAa,OAAO;;;;;;;;CAQnB,YAAY,GAAG,GAAG;EACjB,IAAI,CAAC,GAAK;EAEV,IAAI,aAAa,QAAQ;GACxB,IAAI,EAAE,QAAQ,GAAG;;;;;IAKhB,KAAK,MAAM,IAAI,MAAM,EAAE,GAAG;;;;;IAK1B,KAAK,MAAM,IAAI,MAAM,EAAE,GAAG;GAC3B;GACA;EACD;EAEA,MAAM,SAAS,IAAI,CAAC,GAAG,CAAC,IAAI;EAC5B,KAAK,MAAM,SAAS,QACnB,KAAK,OAAO,KAAK;CAEnB;;;;;;;;;;CAWA,OAAO,KAAK,GAAG,GAAG;EACjB,OAAO,aAAa,SAAS,IAAI,IAAI,OAAO,GAAG,CAAC;CACjD;;;;;;CAOA,OAAO,KAAK;EACX,IAAI,MAAM;EACV,IAAI,CAAC,KAAO,OAAO;EAEnB,IAAI,kBAAkB,GAAG,GACxB,OAAO,OAAO,MAAM,KAAK,GAAG;OACtB;GACN,CAAC,CAAC,KAAK,MAAM,KAAK,QAAQ,OAAO,KAAK,GAAG;GACzC,IAAI,CAAC,MAAQ,OAAO;EACrB;EAEA,IAAI,CAAC,KAAK,KAAK;GACd,KAAK,MAAM,IAAI,MAAM,IAAI;GACzB,KAAK,MAAM,IAAI,MAAM,IAAI;EAC1B,OAAO;GACN,KAAK,IAAI,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC;GACxC,KAAK,IAAI,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC;GACxC,KAAK,IAAI,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC;GACxC,KAAK,IAA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AAI,IAAI,GAAG,KAAK,CAAC,IAAI,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC,GAC5D,YAAY,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC;EAE5D,OAAO,aAAa;CACrB;;;;;CAMA,UAAU;EACT,OAAO,CAAC,EAAE,KAAK,OAAO,KAAK;CAC5B;;;;;;;;CAUA,IAAI,aAAa;EAChB,MAAM,MAAM,KAAK,KACjB,MAAM,KAAK,KACX,eAAe,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,aACzC,cAAc,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI;EAGxC,OAAO,IAAI,OACV,IAAI,MAAM,IAAI,IAAI,cAAc,IAAI,IAAI,WAAW,GACnD,IAAI,MAAM,IAAI,IAAI,cAAc,IAAI,IAAI,WAAW,CAAC;CACtD;;;;;;CAQA,OAAO,QAAQ;EACd,IAAI,CAAC,QAAU,OAAO;EAEtB,SAAS,OAAO,KAAK,MAAM;EAE3B,OAAO,KAAK,IAAI,OAAO,OAAO,WAAW,CAAC,KACzC,KAAK,IAAI,OAAO,OAAO,eAAe,CAAC;CACzC;AACD;AAGA,SAAS,kBAAkB,KAAK;CAC/B,OAAO,eAAe,UAAU,MAAM,QAAQ,GAAG,IAAI,OAAO,IAAI,OAAO,WAAW,OAAO;AAC1F"}
|
|
1
|
+
{"version":3,"file":"Bounds.js","names":[],"sources":["../../../src/geometry/Bounds.js"],"sourcesContent":["import {Point} from './Point.js';\n/** @import {PointExpression} from './Point.js' */\n\n/**\n * A rectangular area in pixel coordinates: a `Bounds`, or an array of points (usually\n * two diagonally opposite corners), e.g. `[[10, 10], [40, 60]]`. Accepted by all\n * Maplair methods which accept `Bounds` objects (unless noted otherwise).\n * @typedef {Bounds|PointExpression[]} BoundsExpression\n */\n\n/**\n * Represents a rectangular area in pixel coordinates.\n *\n * @example\n * ```js\n * const p1 = new Point(10, 10),\n * p2 = new Point(40, 60),\n * bounds = new Bounds(p1, p2);\n * ```\n *\n * All Maplair methods that accept `Bounds` objects also accept them in a simple Array\n * form (unless noted otherwise), so the bounds example above can be passed like this:\n *\n * ```js\n * otherBounds.intersects([[10, 10], [40, 60]]);\n * ```\n *\n * Note that `Bounds` 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 Bounds {\n\t/**\n\t * Creates a Bounds object from two corners coordinate pairs. Alternatively, creates a\n\t * Bounds object from the given array of points, or a copy of the given Bounds object.\n\t * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the\n\t * bounds to copy.\n\t * @param {PointExpression} [b] The opposite corner.\n\t */\n\tconstructor(a, b) {\n\t\tif (!a) { return; }\n\n\t\tif (a instanceof Bounds) {\n\t\t\tif (a.isValid()) {\n\t\t\t\t/**\n\t\t\t\t * The top left corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\n\t\t\t\tthis.min = new Point(a.min);\n\t\t\t\t/**\n\t\t\t\t * The bottom right corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\n\t\t\t\tthis.max = new Point(a.max);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst points = b ? [a, b] : a;\n\t\tfor (const point of points) {\n\t\t\tthis.extend(point);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the given `Bounds` object as it is, or else a new `Bounds` 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 * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the\n\t * bounds.\n\t * @param {PointExpression} [b] The opposite corner.\n\t * @returns {Bounds}\n\t */\n\tstatic from(a, b) {\n\t\treturn a instanceof Bounds ? a : new Bounds(a, b);\n\t}\n\n\t/**\n\t * Extends the bounds to contain the given point or bounds.\n\t * @param {PointExpression|BoundsExpression} obj\n\t * @returns {this}\n\t */\n\textend(obj) {\n\t\tlet min2, max2;\n\t\tif (!obj) { return this; }\n\n\t\tif (isPointExpression(obj)) {\n\t\t\tmin2 = max2 = Point.from(obj);\n\t\t} else {\n\t\t\t({min: min2, max: max2} = Bounds.from(obj));\n\t\t\tif (!min2) { return this; }\n\t\t}\n\n\t\tif (!this.min) {\n\t\t\tthis.min = new Point(min2);\n\t\t\tthis.max = new Point(max2);\n\t\t} else {\n\t\t\tthis.min.x = Math.min(min2.x, this.min.x);\n\t\t\tthis.max.x = Math.max(max2.x, this.max.x);\n\t\t\tthis.min.y = Math.min(min2.y, this.min.y);\n\t\t\tthis.max.y = Math.max(max2.y, this.max.y);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the center point of the bounds.\n\t * @param {boolean} [round]\n\t * @returns {Point}\n\t */\n\tgetCenter(round) {\n\t\treturn new Point(\n\t\t\t(this.min.x + this.max.x) / 2,\n\t\t\t(this.min.y + this.max.y) / 2, round);\n\t}\n\n\t/**\n\t * Returns the bottom-left point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetBottomLeft() {\n\t\treturn new Point(this.min.x, this.max.y);\n\t}\n\n\t/**\n\t * Returns the top-right point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetTopRight() { // -> Point\n\t\treturn new Point(this.max.x, this.min.y);\n\t}\n\n\t/**\n\t * Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-min)).\n\t * @returns {Point}\n\t */\n\tgetTopLeft() {\n\t\treturn this.min; // left, top\n\t}\n\n\t/**\n\t * Returns the bottom-right point of the bounds (i.e. [`this.max`](#bounds-max)).\n\t * @returns {Point}\n\t */\n\tgetBottomRight() {\n\t\treturn this.max; // right, bottom\n\t}\n\n\t/**\n\t * Returns the size of the given bounds.\n\t * @returns {Point}\n\t */\n\tgetSize() {\n\t\treturn this.max.subtract(this.min);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle contains the given bounds or point.\n\t * @param {BoundsExpression|PointExpression} obj\n\t * @returns {boolean}\n\t */\n\tcontains(obj) {\n\t\tlet min, max;\n\n\t\tif (isPointExpression(obj)) {\n\t\t\tmin = max = Point.from(obj);\n\t\t} else {\n\t\t\t({min, max} = Bounds.from(obj));\n\t\t}\n\n\t\treturn (min.x >= this.min.x) &&\n\t\t (max.x <= this.max.x) &&\n\t\t (min.y >= this.min.y) &&\n\t\t (max.y <= this.max.y);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle intersects the given bounds. Two bounds\n\t * intersect if they have at least one point in common.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tintersects(bounds) { // (Bounds) -> Boolean\n\t\tbounds = Bounds.from(bounds);\n\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\tmin2 = bounds.min,\n\t\tmax2 = bounds.max,\n\t\txIntersects = (max2.x >= min.x) && (min2.x <= max.x),\n\t\tyIntersects = (max2.y >= min.y) && (min2.y <= max.y);\n\n\t\treturn xIntersects && yIntersects;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle overlaps the given bounds. Two bounds\n\t * overlap if their intersection is an area.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\toverlaps(bounds) { // (Bounds) -> Boolean\n\t\tbounds = Bounds.from(bounds);\n\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\tmin2 = bounds.min,\n\t\tmax2 = bounds.max,\n\t\txOverlaps = Math.max(min.x, min2.x) < Math.min(max.x, max2.x),\n\t\tyOverlaps = Math.max(min.y, min2.y) < Math.min(max.y, max2.y);\n\n\t\treturn xOverlaps && yOverlaps;\n\t}\n\n\t/**\n\t * Returns `true` if the bounds are properly initialized.\n\t * @returns {boolean}\n\t */\n\tisValid() {\n\t\treturn !!(this.min && this.max);\n\t}\n\n\n\t/**\n\t * Returns bounds created by extending or retracting the current bounds by a given\n\t * ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in\n\t * each direction. Negative values will retract the bounds.\n\t * @param {number} bufferRatio\n\t * @returns {Bounds}\n\t */\n\tpad(bufferRatio) {\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\theightBuffer = Math.abs(min.x - max.x) * bufferRatio,\n\t\twidthBuffer = Math.abs(min.y - max.y) * bufferRatio;\n\n\n\t\treturn new Bounds(\n\t\t\tnew Point(min.x - heightBuffer, min.y - widthBuffer),\n\t\t\tnew Point(max.x + heightBuffer, max.y + widthBuffer));\n\t}\n\n\n\t/**\n\t * Returns `true` if the rectangle is equivalent to the given bounds.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tequals(bounds) {\n\t\tif (!bounds) { return false; }\n\n\t\tbounds = Bounds.from(bounds);\n\n\t\treturn this.min.equals(bounds.getTopLeft()) &&\n\t\t\tthis.max.equals(bounds.getBottomRight());\n\t}\n}\n\n// Whether `obj` is a point (or an array or object literal of one) rather than bounds\nfunction isPointExpression(obj) {\n\treturn obj instanceof Point || (Array.isArray(obj) ? obj.length > 0 && typeof obj[0] !== 'object' : 'x' in obj);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAa,SAAb,MAAa,OAAO;;;;;;;;CAQnB,YAAY,GAAG,GAAG;EACjB,IAAI,CAAC,GAAK;EAEV,IAAI,aAAa,QAAQ;GACxB,IAAI,EAAE,QAAQ,GAAG;;;;;IAKhB,KAAK,MAAM,IAAI,MAAM,EAAE,GAAG;;;;;IAK1B,KAAK,MAAM,IAAI,MAAM,EAAE,GAAG;GAC3B;GACA;EACD;EAEA,MAAM,SAAS,IAAI,CAAC,GAAG,CAAC,IAAI;EAC5B,KAAK,MAAM,SAAS,QACnB,KAAK,OAAO,KAAK;CAEnB;;;;;;;;;;CAWA,OAAO,KAAK,GAAG,GAAG;EACjB,OAAO,aAAa,SAAS,IAAI,IAAI,OAAO,GAAG,CAAC;CACjD;;;;;;CAOA,OAAO,KAAK;EACX,IAAI,MAAM;EACV,IAAI,CAAC,KAAO,OAAO;EAEnB,IAAI,kBAAkB,GAAG,GACxB,OAAO,OAAO,MAAM,KAAK,GAAG;OAC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U,MAAM,QAAQ,GAAG,IAAI,IAAI,SAAS,KAAK,OAAO,IAAI,OAAO,WAAW,OAAO;AAC5G"}
|
|
@@ -146,19 +146,21 @@ var Point = class Point {
|
|
|
146
146
|
* `scale`. In linear algebra terms, multiply the point by the
|
|
147
147
|
* [scaling matrix](https://en.wikipedia.org/wiki/Scaling_%28geometry%29#Matrix_representation)
|
|
148
148
|
* defined by `scale`.
|
|
149
|
-
* @param {
|
|
149
|
+
* @param {PointExpression} point The scale.
|
|
150
150
|
* @returns {Point}
|
|
151
151
|
*/
|
|
152
152
|
scaleBy(point) {
|
|
153
|
+
point = Point.from(point);
|
|
153
154
|
return new Point(this.x * point.x, this.y * point.y);
|
|
154
155
|
}
|
|
155
156
|
/**
|
|
156
157
|
* Inverse of `scaleBy`. Divide each coordinate of the current point by
|
|
157
158
|
* each coordinate of `scale`.
|
|
158
|
-
* @param {
|
|
159
|
+
* @param {PointExpression} point The scale.
|
|
159
160
|
* @returns {Point}
|
|
160
161
|
*/
|
|
161
162
|
unscaleBy(point) {
|
|
163
|
+
point = Point.from(point);
|
|
162
164
|
return new Point(this.x / point.x, this.y / point.y);
|
|
163
165
|
}
|
|
164
166
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Point.js","names":["Util.toNumber","Util.formatNum"],"sources":["../../../src/geometry/Point.js"],"sourcesContent":["// a named import of toNumber makes Point#add ~10% slower in V8\nimport * as Util from '../core/Util.js';\n\n/**\n * A point in pixels: a `Point`, an array of the form `[x, y]`, or a plain object of\n * the form `{x, y}`. Accepted by all Maplair methods and options which accept `Point`\n * objects (unless noted otherwise).\n * @typedef {Point|[number, number]|number[]|{x: number, y: number}} PointExpression\n */\n\n/**\n * Represents a point with `x` and `y` coordinates in pixels.\n *\n * @example\n * ```js\n * const point = new Point(200, 300);\n * ```\n *\n * All Maplair methods and options that accept `Point` objects also accept them in a\n * simple Array form (unless noted otherwise), so these lines are equivalent:\n *\n * ```js\n * map.panBy([200, 300]);\n * map.panBy(new Point(200, 300));\n * ```\n *\n * Note that `Point` 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 Point {\n\t/**\n\t * Creates a Point object with the given `x` and `y` coordinates. If optional `round`\n\t * is set to true, rounds the `x` and `y` values. Alternatively, expects a Point\n\t * object, an array of the form `[x, y]` or a plain object of the form `{x, y}`\n\t * instead.\n\t * @param {number|PointExpression} x The `x` coordinate, or the coordinates.\n\t * @param {number} [y] The `y` coordinate.\n\t * @param {boolean} [round]\n\t */\n\tconstructor(x, y, round) {\n\t\tlet _x = x, _y = y;\n\t\tif (Array.isArray(x)) {\n\t\t\t_x = x[0];\n\t\t\t_y = x[1];\n\t\t} else if (typeof x === 'object' && x !== null) {\n\t\t\t_x = x.x;\n\t\t\t_y = x.y;\n\t\t}\n\n\t\t/**\n\t\t * The `x` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.x = round ? Math.round(Util.toNumber(_x)) : Util.toNumber(_x);\n\t\t/**\n\t\t * The `y` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.y = round ? Math.round(Util.toNumber(_y)) : Util.toNumber(_y);\n\n\t\t// NaN check; isNaN() here makes Point#add ~10% slower in V8\n\t\t// eslint-disable-next-line no-self-compare\n\t\tif (this.x !== this.x || this.y !== this.y) {\n\t\t\tthrow new Error(`Invalid Point object: (${_x}, ${_y})`);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the given `Point` object as it is (unless `round` is set), or else a new\n\t * `Point` object created from the given arguments (the same as of the constructor) —\n\t * unlike the constructor, which always creates a new object.\n\t *\n\t * @example\n\t * ```js\n\t * Point.from(point) === point; // true\n\t * Point.from([200, 300]); // Point(200, 300)\n\t * ```\n\t * @param {number|PointExpression} x The `x` coordinate, or the coordinates.\n\t * @param {number} [y] The `y` coordinate.\n\t * @param {boolean} [round]\n\t * @returns {Point}\n\t */\n\tstatic from(x, y, round) {\n\t\treturn x instanceof Point && !round ? x : new Point(x, y, round);\n\t}\n\n\t/**\n\t * Returns `true` if the Point object can be properly initialized with the given\n\t * arguments (the same as of the constructor).\n\t * @param {any} x\n\t * @param {any} [y]\n\t * @returns {boolean}\n\t */\n\tstatic validate(x, y) {\n\t\ttry {\n\t\t\treturn !!new Point(x, y);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the result of addition of the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\n\tadd(point) {\n\t\t// non-destructive, returns a new point\n\t\treturn new Point(this)._add(Point.from(point));\n\t}\n\n\t_add(point) {\n\t\t// destructive, used directly for performance in situations where it's safe to modify existing point\n\t\tthis.x += point.x;\n\t\tthis.y += point.y;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of subtraction of the given point from the current.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\n\tsubtract(point) {\n\t\treturn new Point(this)._subtract(Point.from(point));\n\t}\n\n\t_subtract(point) {\n\t\tthis.x -= point.x;\n\t\tthis.y -= point.y;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of division of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\n\tdivideBy(num) {\n\t\treturn new Point(this)._divideBy(num);\n\t}\n\n\t_divideBy(num) {\n\t\tthis.x /= num;\n\t\tthis.y /= num;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of multiplication of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\n\tmultiplyBy(num) {\n\t\treturn new Point(this)._multiplyBy(num);\n\t}\n\n\t_multiplyBy(num) {\n\t\tthis.x *= num;\n\t\tthis.y *= num;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Multiply each coordinate of the current point by each coordinate of\n\t * `scale`. In linear algebra terms, multiply the point by the\n\t * [scaling matrix](https://en.wikipedia.org/wiki/Scaling_%28geometry%29#Matrix_representation)\n\t * defined by `scale`.\n\t * @param {Point} point The scale.\n\t * @returns {Point}\n\t */\n\tscaleBy(point) {\n\t\treturn new Point(this.x * point.x, this.y * point.y);\n\t}\n\n\t/**\n\t * Inverse of `scaleBy`. Divide each coordinate of the current point by\n\t * each coordinate of `scale`.\n\t * @param {Point} point The scale.\n\t * @returns {Point}\n\t */\n\tunscaleBy(point) {\n\t\treturn new Point(this.x / point.x, this.y / point.y);\n\t}\n\n\t/**\n\t * Returns a copy of the current point with rounded coordinates.\n\t * @returns {Point}\n\t */\n\tround() {\n\t\treturn new Point(this)._round();\n\t}\n\n\t_round() {\n\t\tthis.x = Math.round(this.x);\n\t\tthis.y = Math.round(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with floored coordinates (rounded down).\n\t * @returns {Point}\n\t */\n\tfloor() {\n\t\treturn new Point(this)._floor();\n\t}\n\n\t_floor() {\n\t\tthis.x = Math.floor(this.x);\n\t\tthis.y = Math.floor(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with ceiled coordinates (rounded up).\n\t * @returns {Point}\n\t */\n\tceil() {\n\t\treturn new Point(this)._ceil();\n\t}\n\n\t_ceil() {\n\t\tthis.x = Math.ceil(this.x);\n\t\tthis.y = Math.ceil(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with truncated coordinates (rounded towards\n\t * zero).\n\t * @returns {Point}\n\t */\n\ttrunc() {\n\t\treturn new Point(this)._trunc();\n\t}\n\n\t_trunc() {\n\t\tthis.x = Math.trunc(this.x);\n\t\tthis.y = Math.trunc(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the cartesian distance between the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {number}\n\t */\n\tdistanceTo(point) {\n\t\tpoint = Point.from(point);\n\n\t\tconst x = point.x - this.x,\n\t\ty = point.y - this.y;\n\n\t\treturn Math.sqrt(x * x + y * y);\n\t}\n\n\t/**\n\t * Returns `true` if the given point has the same coordinates.\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\n\tequals(point) {\n\t\tpoint = Point.from(point);\n\n\t\treturn point.x === this.x &&\n\t\t point.y === this.y;\n\t}\n\n\t/**\n\t * Returns `true` if both coordinates of the given point are less than the\n\t * corresponding current point coordinates (in absolute values).\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\n\tcontains(point) {\n\t\tpoint = Point.from(point);\n\n\t\treturn Math.abs(point.x) <= Math.abs(this.x) &&\n\t\t Math.abs(point.y) <= Math.abs(this.y);\n\t}\n\n\t/**\n\t * Returns a string representation of the point for debugging purposes.\n\t * @returns {string}\n\t */\n\ttoString() {\n\t\treturn `Point(${Util.formatNum(this.x)}, ${Util.formatNum(this.y)})`;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAa,QAAb,MAAa,MAAM;;;;;;;;;;CAUlB,YAAY,GAAG,GAAG,OAAO;EACxB,IAAI,KAAK,GAAG,KAAK;EACjB,IAAI,MAAM,QAAQ,CAAC,GAAG;GACrB,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO,IAAI,OAAO,MAAM,YAAY,MAAM,MAAM;GAC/C,KAAK,EAAE;GACP,KAAK,EAAE;EACR;;;;;EAMA,KAAK,IAAI,QAAQ,KAAK,MAAMA,SAAc,EAAE,CAAC,IAAIA,SAAc,EAAE;;;;;EAKjE,KAAK,IAAI,QAAQ,KAAK,MAAMA,SAAc,EAAE,CAAC,IAAIA,SAAc,EAAE;EAIjE,IAAI,KAAK,MAAM,KAAK,KAAK,KAAK,MAAM,KAAK,GACxC,MAAM,IAAI,MAAM,0BAA0B,GAAG,IAAI,GAAG,EAAE;CAExD;;;;;;;;;;;;;;;;CAiBA,OAAO,KAAK,GAAG,GAAG,OAAO;EACxB,OAAO,aAAa,SAAS,CAAC,QAAQ,IAAI,IAAI,MAAM,GAAG,GAAG,KAAK;CAChE;;;;;;;;CASA,OAAO,SAAS,GAAG,GAAG;EACrB,IAAI;GACH,OA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AAK,IAAI,KAAK,MAAM,KAAK,CAAC;EAC1B,KAAK,IAAI,KAAK,MAAM,KAAK,CAAC;EAC1B,OAAO;CACR;;;;;CAMA,OAAO;EACN,OAAO,IAAI,MAAM,IAAI,CAAC,CAAC,MAAM;CAC9B;CAEA,QAAQ;EACP,KAAK,IAAI,KAAK,KAAK,KAAK,CAAC;EACzB,KAAK,IAAI,KAAK,KAAK,KAAK,CAAC;EACzB,OAAO;CACR;;;;;;CAOA,QAAQ;EACP,OAAO,IAAI,MAAM,IAAI,CAAC,CAAC,OAAO;CAC/B;CAEA,SAAS;EACR,KAAK,IAAI,KAAK,MAAM,KAAK,CAAC;EAC1B,KAAK,IAAI,KAAK,MAAM,KAAK,CAAC;EAC1B,OAAO;CACR;;;;;;CAOA,WAAW,OAAO;EACjB,QAAQ,MAAM,KAAK,KAAK;EAExB,MAAM,IAAI,MAAM,IAAI,KAAK,GACzB,IAAI,MAAM,IAAI,KAAK;EAEnB,OAAO,KAAK,KAAK,IAAI,IAAI,IAAI,CAAC;CAC/B;;;;;;CAOA,OAAO,OAAO;EACb,QAAQ,MAAM,KAAK,KAAK;EAExB,OAAO,MAAM,MAAM,KAAK,KACjB,MAAM,MAAM,KAAK;CACzB;;;;;;;CAQA,SAAS,OAAO;EACf,QAAQ,MAAM,KAAK,KAAK;EAExB,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,KAAK,CAAC,KACpC,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,KAAK,CAAC;CAC5C;;;;;CAMA,WAAW;EACV,OAAO,SAASC,UAAe,KAAK,CAAC,EAAE,IAAIA,UAAe,KAAK,CAAC,EAAE;CACnE;AACD"}
|
|
1
|
+
{"version":3,"file":"Point.js","names":["Util.toNumber","Util.formatNum"],"sources":["../../../src/geometry/Point.js"],"sourcesContent":["// a named import of toNumber makes Point#add ~10% slower in V8\nimport * as Util from '../core/Util.js';\n\n/**\n * A point in pixels: a `Point`, an array of the form `[x, y]`, or a plain object of\n * the form `{x, y}`. Accepted by all Maplair methods and options which accept `Point`\n * objects (unless noted otherwise).\n * @typedef {Point|[number, number]|number[]|{x: number, y: number}} PointExpression\n */\n\n/**\n * Represents a point with `x` and `y` coordinates in pixels.\n *\n * @example\n * ```js\n * const point = new Point(200, 300);\n * ```\n *\n * All Maplair methods and options that accept `Point` objects also accept them in a\n * simple Array form (unless noted otherwise), so these lines are equivalent:\n *\n * ```js\n * map.panBy([200, 300]);\n * map.panBy(new Point(200, 300));\n * ```\n *\n * Note that `Point` 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 Point {\n\t/**\n\t * Creates a Point object with the given `x` and `y` coordinates. If optional `round`\n\t * is set to true, rounds the `x` and `y` values. Alternatively, expects a Point\n\t * object, an array of the form `[x, y]` or a plain object of the form `{x, y}`\n\t * instead.\n\t * @param {number|PointExpression} x The `x` coordinate, or the coordinates.\n\t * @param {number} [y] The `y` coordinate.\n\t * @param {boolean} [round]\n\t */\n\tconstructor(x, y, round) {\n\t\tlet _x = x, _y = y;\n\t\tif (Array.isArray(x)) {\n\t\t\t_x = x[0];\n\t\t\t_y = x[1];\n\t\t} else if (typeof x === 'object' && x !== null) {\n\t\t\t_x = x.x;\n\t\t\t_y = x.y;\n\t\t}\n\n\t\t/**\n\t\t * The `x` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.x = round ? Math.round(Util.toNumber(_x)) : Util.toNumber(_x);\n\t\t/**\n\t\t * The `y` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.y = round ? Math.round(Util.toNumber(_y)) : Util.toNumber(_y);\n\n\t\t// NaN check; isNaN() here makes Point#add ~10% slower in V8\n\t\t// eslint-disable-next-line no-self-compare\n\t\tif (this.x !== this.x || this.y !== this.y) {\n\t\t\tthrow new Error(`Invalid Point object: (${_x}, ${_y})`);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the given `Point` object as it is (unless `round` is set), or else a new\n\t * `Point` object created from the given arguments (the same as of the constructor) —\n\t * unlike the constructor, which always creates a new object.\n\t *\n\t * @example\n\t * ```js\n\t * Point.from(point) === point; // true\n\t * Point.from([200, 300]); // Point(200, 300)\n\t * ```\n\t * @param {number|PointExpression} x The `x` coordinate, or the coordinates.\n\t * @param {number} [y] The `y` coordinate.\n\t * @param {boolean} [round]\n\t * @returns {Point}\n\t */\n\tstatic from(x, y, round) {\n\t\treturn x instanceof Point && !round ? x : new Point(x, y, round);\n\t}\n\n\t/**\n\t * Returns `true` if the Point object can be properly initialized with the given\n\t * arguments (the same as of the constructor).\n\t * @param {any} x\n\t * @param {any} [y]\n\t * @returns {boolean}\n\t */\n\tstatic validate(x, y) {\n\t\ttry {\n\t\t\treturn !!new Point(x, y);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the result of addition of the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\n\tadd(point) {\n\t\t// non-destructive, returns a new point\n\t\treturn new Point(this)._add(Point.from(point));\n\t}\n\n\t_add(point) {\n\t\t// destructive, used directly for performance in situations where it's safe to modify existing point\n\t\tthis.x += point.x;\n\t\tthis.y += point.y;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of subtraction of the given point from the current.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\n\tsubtract(point) {\n\t\treturn new Point(this)._subtract(Point.from(point));\n\t}\n\n\t_subtract(point) {\n\t\tthis.x -= point.x;\n\t\tthis.y -= point.y;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of division of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\n\tdivideBy(num) {\n\t\treturn new Point(this)._divideBy(num);\n\t}\n\n\t_divideBy(num) {\n\t\tthis.x /= num;\n\t\tthis.y /= num;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of multiplication of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\n\tmultiplyBy(num) {\n\t\treturn new Point(this)._multiplyBy(num);\n\t}\n\n\t_multiplyBy(num) {\n\t\tthis.x *= num;\n\t\tthis.y *= num;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Multiply each coordinate of the current point by each coordinate of\n\t * `scale`. In linear algebra terms, multiply the point by the\n\t * [scaling matrix](https://en.wikipedia.org/wiki/Scaling_%28geometry%29#Matrix_representation)\n\t * defined by `scale`.\n\t * @param {PointExpression} point The scale.\n\t * @returns {Point}\n\t */\n\tscaleBy(point) {\n\t\tpoint = Point.from(point);\n\t\treturn new Point(this.x * point.x, this.y * point.y);\n\t}\n\n\t/**\n\t * Inverse of `scaleBy`. Divide each coordinate of the current point by\n\t * each coordinate of `scale`.\n\t * @param {PointExpression} point The scale.\n\t * @returns {Point}\n\t */\n\tunscaleBy(point) {\n\t\tpoint = Point.from(point);\n\t\treturn new Point(this.x / point.x, this.y / point.y);\n\t}\n\n\t/**\n\t * Returns a copy of the current point with rounded coordinates.\n\t * @returns {Point}\n\t */\n\tround() {\n\t\treturn new Point(this)._round();\n\t}\n\n\t_round() {\n\t\tthis.x = Math.round(this.x);\n\t\tthis.y = Math.round(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with floored coordinates (rounded down).\n\t * @returns {Point}\n\t */\n\tfloor() {\n\t\treturn new Point(this)._floor();\n\t}\n\n\t_floor() {\n\t\tthis.x = Math.floor(this.x);\n\t\tthis.y = Math.floor(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with ceiled coordinates (rounded up).\n\t * @returns {Point}\n\t */\n\tceil() {\n\t\treturn new Point(this)._ceil();\n\t}\n\n\t_ceil() {\n\t\tthis.x = Math.ceil(this.x);\n\t\tthis.y = Math.ceil(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with truncated coordinates (rounded towards\n\t * zero).\n\t * @returns {Point}\n\t */\n\ttrunc() {\n\t\treturn new Point(this)._trunc();\n\t}\n\n\t_trunc() {\n\t\tthis.x = Math.trunc(this.x);\n\t\tthis.y = Math.trunc(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the cartesian distance between the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {number}\n\t */\n\tdistanceTo(point) {\n\t\tpoint = Point.from(point);\n\n\t\tconst x = point.x - this.x,\n\t\ty = point.y - this.y;\n\n\t\treturn Math.sqrt(x * x + y * y);\n\t}\n\n\t/**\n\t * Returns `true` if the given point has the same coordinates.\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\n\tequals(point) {\n\t\tpoint = Point.from(point);\n\n\t\treturn point.x === this.x &&\n\t\t point.y === this.y;\n\t}\n\n\t/**\n\t * Returns `true` if both coordinates of the given point are less than the\n\t * corresponding current point coordinates (in absolute values).\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\n\tcontains(point) {\n\t\tpoint = Point.from(point);\n\n\t\treturn Math.abs(point.x) <= Math.abs(this.x) &&\n\t\t Math.abs(point.y) <= Math.abs(this.y);\n\t}\n\n\t/**\n\t * Returns a string representation of the point for debugging purposes.\n\t * @returns {string}\n\t */\n\ttoString() {\n\t\treturn `Point(${Util.formatNum(this.x)}, ${Util.formatNum(this.y)})`;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAa,QAAb,MAAa,MAAM;;;;;;;;;;CAUlB,YAAY,GAAG,GAAG,OAAO;EACxB,IAAI,KAAK,GAAG,KAAK;EACjB,IAAI,MAAM,QAAQ,CAAC,GAAG;GACrB,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO,IAAI,OAAO,MAAM,YAAY,MAAM,MAAM;GAC/C,KAAK,EAAE;GACP,KAAK,EAAE;EACR;;;;;EAMA,KAAK,IAAI,QAAQ,KAAK,MAAMA,SAAc,EAAE,CAAC,IAAIA,SAAc,EAAE;;;;;EAKjE,KAAK,IAAI,QAAQ,KAAK,MAAMA,SAAc,E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AK,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,KAAK,CAAC,KACpC,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,KAAK,CAAC;CAC5C;;;;;CAMA,WAAW;EACV,OAAO,SAASC,UAAe,KAAK,CAAC,EAAE,IAAIA,UAAe,KAAK,CAAC,EAAE;CACnE;AACD"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { Point } from "./Point.js";
|
|
3
|
+
import { Bounds } from "./Bounds.js";
|
|
3
4
|
import { LatLng } from "../geo/LatLng.js";
|
|
4
|
-
import { _getEdgeIntersection, _projectRing } from "./LineUtil.js";
|
|
5
|
+
import { _getEdgeIntersection, _projectRing, _sqClosestPointOnSegment } from "./LineUtil.js";
|
|
5
6
|
// src/geometry/PolyUtil.js
|
|
6
7
|
var PolyUtil_exports = /* @__PURE__ */ __exportAll({
|
|
7
8
|
centroid: () => centroid,
|
|
@@ -9,7 +10,6 @@ var PolyUtil_exports = /* @__PURE__ */ __exportAll({
|
|
|
9
10
|
polygonCenter: () => polygonCenter
|
|
10
11
|
});
|
|
11
12
|
/** @import {LatLngExpression} from '../geo/LatLng.js' */
|
|
12
|
-
/** @import {Bounds} from './Bounds.js' */
|
|
13
13
|
/** @import {CRS} from '../geo/crs/CRS.js' */
|
|
14
14
|
/**
|
|
15
15
|
* Clips the polygon geometry defined by the given `points` by the given bounds (using
|
|
@@ -64,7 +64,14 @@ function polygonCenter(latlngs, crs) {
|
|
|
64
64
|
y += (p1.y + p2.y) * f;
|
|
65
65
|
area += f;
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
if (area !== 0) return crs.unproject(new Point(x / (3 * area), y / (3 * area))._add(origin));
|
|
68
|
+
const mid = new Bounds(points).getCenter();
|
|
69
|
+
let center = points[0];
|
|
70
|
+
for (let i = 0, j = len - 1; i < len; j = i++) {
|
|
71
|
+
const p = _sqClosestPointOnSegment(mid, points[j], points[i]);
|
|
72
|
+
if (p.distanceTo(mid) < center.distanceTo(mid)) center = p;
|
|
73
|
+
}
|
|
74
|
+
return crs.unproject(center._add(origin));
|
|
68
75
|
}
|
|
69
76
|
/**
|
|
70
77
|
* Returns the 'center of mass' of the passed LatLngs.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolyUtil.js","names":["LineUtil._getEdgeIntersection","LineUtil._projectRing"],"sources":["../../../src/geometry/PolyUtil.js"],"sourcesContent":["import * as LineUtil from './LineUtil.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from './Point.js';\
|
|
1
|
+
{"version":3,"file":"PolyUtil.js","names":["LineUtil._getEdgeIntersection","LineUtil._projectRing","LineUtil._sqClosestPointOnSegment"],"sources":["../../../src/geometry/PolyUtil.js"],"sourcesContent":["import * as LineUtil from './LineUtil.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from './Point.js';\nimport {Bounds} from './Bounds.js';\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// PolyUtil: various utility functions for polygon geometries.\n\n/**\n * Clips the polygon geometry defined by the given `points` by the given bounds (using\n * the [Sutherland-Hodgman algorithm](https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm)).\n * Used by Maplair to only show polygon points that are on the screen or near, increasing\n * performance. Note that polygon points needs different algorithm for clipping\n * than polyline, so there's a separate method for it.\n * @param {Point[]} points\n * @param {Bounds} bounds\n * @param {boolean} [round]\n * @returns {Point[]}\n */\nexport function clipPolygon(points, bounds, round) {\n\t// left, bottom, right, top\n\tfor (const edge of [1, 4, 2, 8]) {\n\t\tif (!points.length) { break; }\n\n\t\t/** @type {Point[]} */\n\t\tconst clippedPoints = [];\n\t\tlet b = points[points.length - 1],\n\t\tbOut = isOutside(b, edge, bounds);\n\n\t\tfor (const a of points) {\n\t\t\tconst aOut = isOutside(a, edge, bounds);\n\t\t\t// a->b crosses the edge\n\t\t\tif (aOut !== bOut) {\n\t\t\t\tclippedPoints.push(LineUtil._getEdgeIntersection(b, a, edge, bounds, round));\n\t\t\t}\n\t\t\tif (!aOut) {\n\t\t\t\tclippedPoints.push(a);\n\t\t\t}\n\t\t\tb = a;\n\t\t\tbOut = aOut;\n\t\t}\n\t\tpoints = clippedPoints;\n\t}\n\n\treturn points;\n}\n\n// Whether the point is outside the given edge of the bounds; the edge is a `LineUtil` clipping bit code\nfunction isOutside(p, edge, bounds) {\n\treturn edge === 1 ? p.x < bounds.min.x :\n\t\tedge === 2 ? p.x > bounds.max.x :\n\t\tedge === 4 ? p.y < bounds.min.y : p.y > bounds.max.y;\n}\n\n/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polygon.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\n */\nexport function polygonCenter(latlngs, crs) {\n\t// points relative to the first one, to avoid floating point errors on tiny polygons with large projected coordinates\n\tconst points = LineUtil._projectRing(latlngs, crs),\n\torigin = new Point(points[0]),\n\tlen = points.length;\n\n\tfor (const p of points) { p._subtract(origin); }\n\n\tlet area = 0, x = 0, y = 0;\n\n\t// polygon centroid algorithm\n\tfor (let i = 0, j = len - 1; i < len; j = i++) {\n\t\tconst p1 = points[i],\n\t\tp2 = points[j],\n\t\tf = p1.y * p2.x - p2.y * p1.x;\n\n\t\tx += (p1.x + p2.x) * f;\n\t\ty += (p1.y + p2.y) * f;\n\t\tarea += f;\n\t}\n\n\tif (area !== 0) { return crs.unproject(new Point(x / (3 * area), y / (3 * area))._add(origin)); }\n\n\t// area is 0 when all points lie on one line (or on the same spot), or when the ring goes back over its own edges;\n\t// take the middle of the points' extent and snap it to the closest point of the ring so it stays on the shape\n\tconst mid = new Bounds(points).getCenter();\n\tlet center = points[0];\n\tfor (let i = 0, j = len - 1; i < len; j = i++) {\n\t\tconst p = LineUtil._sqClosestPointOnSegment(mid, points[j], points[i]);\n\t\tif (p.distanceTo(mid) < center.distanceTo(mid)) { center = p; }\n\t}\n\treturn crs.unproject(center._add(origin));\n}\n\n/**\n * Returns the 'center of mass' of the passed LatLngs.\n * @param {LatLngExpression[]} coords\n * @returns {LatLng}\n */\nexport function centroid(coords) {\n\tlet latSum = 0;\n\tlet lngSum = 0;\n\tlet len = 0;\n\tfor (const coord of coords) {\n\t\tconst latlng = LatLng.from(coord);\n\t\tlatSum += latlng.lat;\n\t\tlngSum += latlng.lng;\n\t\tlen++;\n\t}\n\treturn new LatLng([latSum / len, lngSum / len]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,YAAY,QAAQ,QAAQ,OAAO;CAElD,KAAK,MAAM,QAAQ;EAAC;EAAG;EAAG;EAAG;CAAC,GAAG;EAChC,IAAI,CAAC,OAAO,QAAU;;EAGtB,MAAM,gBAAgB,CAAC;EACvB,IAAI,IAAI,OAAO,OAAO,SAAS,IAC/B,OAAO,UAAU,GAAG,MAAM,MAAM;EAEhC,KAAK,MAAM,KAAK,QAAQ;GACvB,MAAM,OAAO,UAAU,GAAG,MAAM,MAAM;GAEtC,IAAI,SAAS,MACZ,cAAc,KAAKA,qBAA8B,GAAG,GAAG,MAAM,QAAQ,KAAK,CAAC;GAE5E,IAAI,CAAC,MACJ,cAAc,KAAK,CAAC;GAErB,IAAI;GACJ,OAAO;EACR;EACA,SAAS;CACV;CAEA,OAAO;AACR;AAGA,SAAS,UAAU,GAAG,MAAM,QAAQ;CACnC,OAAO,SAAS,IAAI,EAAE,IAAI,OAAO,IAAI,IACpC,SAAS,IAAI,EAAE,IAAI,OAAO,IAAI,IAC9B,SAAS,IAAI,EAAE,IAAI,OAAO,IAAI,IAAI,EAAE,IAAI,OAAO,IAAI;AACrD;;;;;;;;AASA,SAAgB,cAAc,SAAS,KAAK;CAE3C,MAAM,SAASC,aAAsB,SAAS,GAAG,GACjD,SAAS,IAAI,MAAM,OAAO,EAAE,GAC5B,MAAM,OAAO;CAEb,KAAK,MAAM,KAAK,QAAU,EAAE,UAAU,MAAM;CAE5C,IAAI,OAAO,GAAG,IAAI,GAAG,IAAI;CAGzB,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,GAAG,IAAI,KAAK,IAAI,KAAK;EAC9C,MAAM,KAAK,OAAO,IAClB,KAAK,OAAO,IACZ,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG;EAE5B,MAAM,GAAG,IAAI,GAAG,KAAK;EACrB,MAAM,GAAG,IAAI,GAAG,KAAK;EACrB,QAAQ;CACT;CAEA,IAAI,SAAS,GAAK,OAAO,IAAI,UAAU,IAAI,MAAM,KAAK,IAAI,OAAO,KAAK,IAAI,KAAK,CAAC,CAAC,KAAK,MAAM,CAAC;CAI7F,MAAM,MAAM,IAAI,OAAO,MAAM,CAAC,CAAC,UAAU;CACzC,IAAI,SAAS,OAAO;CACpB,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,GAAG,IAAI,KAAK,IAAI,KAAK;EAC9C,MAAM,IAAIC,yBAAkC,KAAK,OAAO,IAAI,OAAO,EAAE;EACrE,IAAI,EAAE,WAAW,GAAG,IAAI,OAAO,WAAW,GAAG,GAAK,SAAS;CAC5D;CACA,OAAO,IAAI,UAAU,OAAO,KAAK,MAAM,CAAC;AACzC;;;;;;AAOA,SAAgB,SAAS,QAAQ;CAChC,IAAI,SAAS;CACb,IAAI,SAAS;CACb,IAAI,MAAM;CACV,KAAK,MAAM,SAAS,QAAQ;EAC3B,MAAM,SAAS,OAAO,KAAK,KAAK;EAChC,UAAU,OAAO;EACjB,UAAU,OAAO;EACjB;CACD;CACA,OAAO,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,GAAG,CAAC;AAC/C"}
|
|
@@ -98,7 +98,8 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
|
98
98
|
this._updateTransform(this._map.getCenter(), this._map.getZoom());
|
|
99
99
|
}
|
|
100
100
|
_updateTransform(center, zoom) {
|
|
101
|
-
const scale = this._map.getZoomScale(zoom, this._zoom), viewHalf = this._map.getSize().multiplyBy(.5 + this.options.padding), currentCenterPoint = this._map.project(this._center, zoom), topLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)._subtract(this._map._getNewPixelOrigin(center, zoom))
|
|
101
|
+
const scale = this._map.getZoomScale(zoom, this._zoom), viewHalf = this._map.getSize().multiplyBy(.5 + this.options.padding), currentCenterPoint = this._map.project(this._center, zoom), topLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)._subtract(this._map._getNewPixelOrigin(center, zoom));
|
|
102
|
+
if (scale === 1) this._map._snapLayerPoint(topLeftOffset);
|
|
102
103
|
setTransform(this._container, topLeftOffset, scale);
|
|
103
104
|
}
|
|
104
105
|
_onMoveEnd(ev) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlanketOverlay.js","names":["DomUtil.create"],"sources":["../../../src/layer/BlanketOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Bounds} from '../geometry/Bounds.js';\n/** @import {LayerOptions} from './Layer.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener} from '../core/Events.js' */\n\n/**\n * Options of `BlanketOverlay`.\n * @typedef {object} BlanketOverlayOptions\n * @property {number} [padding=0.1] How much to extend the clip area around the map\n * view (relative to its size) e.g. 0.1 would be 10% of map view in each direction.\n * @property {boolean} [continuous=false] When `false`, the blanket will update its\n * position only when the map state settles (*after* a pan/zoom animation). When\n * `true`, it will update when the map state changes (*during* pan/zoom animations).\n * @extends LayerOptions\n */\n\n/**\n * Represents an HTML element that covers (\"blankets\") the entire surface\n * of the map.\n *\n * Do not use this class directly. It's meant for `Renderer`, and for plugins\n * that rely on one single HTML element.\n *\n * Subclasses must define the following methods:\n *\n * * `_initContainer()` must initialize the HTML element to use as blanket, and store\n * it as `this._container`. The base implementation creates a blank `<div>`.\n * * `_destroyContainer()` must destroy the HTML element in `this._container` and free\n * any other resources. The base implementation destroys the element and removes\n * any event handlers attached to it.\n * * `_resizeContainer(): Point`: the base implementation resizes the container\n * (based on the map's size and taking into account the padding), returning the new\n * size in CSS pixels. Subclass implementations shall reset container parameters and\n * data structures as needed.\n * * `_onZoomEnd(ev?: PointerEvent)` (optional) runs on the map's `zoomend` event.\n * * `_onViewReset(ev?: PointerEvent)` (optional) runs on the map's `viewreset` event.\n * * `_onSettled()` runs whenever the map state settles after changing (at the end of\n * pan/zoom animations, etc). This should trigger the bulk of any rendering logic.\n * If the `continuous` option is set to `true`, then this also runs on any map\n * state change (including *during* pan/zoom animations).\n */\nexport class BlanketOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tpadding: 0.1,\n\t\tcontinuous: false,\n\t};\n\n\t/**\n\t * @param {BlanketOverlayOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(BlanketOverlay);\n\t}\n\n\t/**\n\t * Adds the blanket to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._container) {\n\t\t\tthis._initContainer(); // defined by renderer implementations\n\n\t\t\t// always keep transform-origin as 0 0, #8794\n\t\t\tthis._container.classList.add('maplair-zoom-animated');\n\t\t}\n\n\t\tthis.getPane().append(this._container);\n\t\tthis._resizeContainer();\n\t\tthis._onMoveEnd();\n\t}\n\n\t/**\n\t * Removes the blanket from the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonRemove() {\n\t\tthis._destroyContainer();\n\t}\n\n\t/**\n\t * Returns the map events the blanket listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tviewreset: this._reset,\n\t\t\tzoom: this._onZoom,\n\t\t\tmoveend: this._onMoveEnd,\n\t\t\tresize: this._resizeContainer,\n\t\t\tzoomend: this._onZoomEnd,\n\t\t\tzoomanim: this._onAnimZoom\n\t\t};\n\t\tif (this.options.continuous) {\n\t\t\tevents.move = this._onMoveEnd;\n\t\t}\n\t\treturn events;\n\t}\n\n\t_onAnimZoom(ev) {\n\t\tthis._updateTransform(ev.center, ev.zoom);\n\t}\n\n\t_onZoom() {\n\t\tthis._updateTransform(this._map.getCenter(), this._map.getZoom());\n\t}\n\n\t_updateTransform(center, zoom) {\n\t\tconst scale = this._map.getZoomScale(zoom, this._zoom),\n\t\tviewHalf = this._map.getSize().multiplyBy(0.5 + this.options.padding),\n\t\tcurrentCenterPoint = this._map.project(this._center, zoom),\n\t\ttopLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)\n\t\t\t._subtract(this._map._getNewPixelOrigin(center, zoom))\n\t\t\t.
|
|
1
|
+
{"version":3,"file":"BlanketOverlay.js","names":["DomUtil.create"],"sources":["../../../src/layer/BlanketOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Bounds} from '../geometry/Bounds.js';\n/** @import {LayerOptions} from './Layer.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener} from '../core/Events.js' */\n\n/**\n * Options of `BlanketOverlay`.\n * @typedef {object} BlanketOverlayOptions\n * @property {number} [padding=0.1] How much to extend the clip area around the map\n * view (relative to its size) e.g. 0.1 would be 10% of map view in each direction.\n * @property {boolean} [continuous=false] When `false`, the blanket will update its\n * position only when the map state settles (*after* a pan/zoom animation). When\n * `true`, it will update when the map state changes (*during* pan/zoom animations).\n * @extends LayerOptions\n */\n\n/**\n * Represents an HTML element that covers (\"blankets\") the entire surface\n * of the map.\n *\n * Do not use this class directly. It's meant for `Renderer`, and for plugins\n * that rely on one single HTML element.\n *\n * Subclasses must define the following methods:\n *\n * * `_initContainer()` must initialize the HTML element to use as blanket, and store\n * it as `this._container`. The base implementation creates a blank `<div>`.\n * * `_destroyContainer()` must destroy the HTML element in `this._container` and free\n * any other resources. The base implementation destroys the element and removes\n * any event handlers attached to it.\n * * `_resizeContainer(): Point`: the base implementation resizes the container\n * (based on the map's size and taking into account the padding), returning the new\n * size in CSS pixels. Subclass implementations shall reset container parameters and\n * data structures as needed.\n * * `_onZoomEnd(ev?: PointerEvent)` (optional) runs on the map's `zoomend` event.\n * * `_onViewReset(ev?: PointerEvent)` (optional) runs on the map's `viewreset` event.\n * * `_onSettled()` runs whenever the map state settles after changing (at the end of\n * pan/zoom animations, etc). This should trigger the bulk of any rendering logic.\n * If the `continuous` option is set to `true`, then this also runs on any map\n * state change (including *during* pan/zoom animations).\n */\nexport class BlanketOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tpadding: 0.1,\n\t\tcontinuous: false,\n\t};\n\n\t/**\n\t * @param {BlanketOverlayOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(BlanketOverlay);\n\t}\n\n\t/**\n\t * Adds the blanket to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._container) {\n\t\t\tthis._initContainer(); // defined by renderer implementations\n\n\t\t\t// always keep transform-origin as 0 0, #8794\n\t\t\tthis._container.classList.add('maplair-zoom-animated');\n\t\t}\n\n\t\tthis.getPane().append(this._container);\n\t\tthis._resizeContainer();\n\t\tthis._onMoveEnd();\n\t}\n\n\t/**\n\t * Removes the blanket from the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonRemove() {\n\t\tthis._destroyContainer();\n\t}\n\n\t/**\n\t * Returns the map events the blanket listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tviewreset: this._reset,\n\t\t\tzoom: this._onZoom,\n\t\t\tmoveend: this._onMoveEnd,\n\t\t\tresize: this._resizeContainer,\n\t\t\tzoomend: this._onZoomEnd,\n\t\t\tzoomanim: this._onAnimZoom\n\t\t};\n\t\tif (this.options.continuous) {\n\t\t\tevents.move = this._onMoveEnd;\n\t\t}\n\t\treturn events;\n\t}\n\n\t_onAnimZoom(ev) {\n\t\tthis._updateTransform(ev.center, ev.zoom);\n\t}\n\n\t_onZoom() {\n\t\tthis._updateTransform(this._map.getCenter(), this._map.getZoom());\n\t}\n\n\t_updateTransform(center, zoom) {\n\t\tconst scale = this._map.getZoomScale(zoom, this._zoom),\n\t\tviewHalf = this._map.getSize().multiplyBy(0.5 + this.options.padding),\n\t\tcurrentCenterPoint = this._map.project(this._center, zoom),\n\t\ttopLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)\n\t\t\t._subtract(this._map._getNewPixelOrigin(center, zoom));\n\n\t\t// a scaled container is resampled anyway, and rounding where its corner lands would make its content away\n\t\t// from the corner jitter against the zoom motion\n\t\tif (scale === 1) { this._map._snapLayerPoint(topLeftOffset); }\n\n\t\tDomUtil.setTransform(this._container, topLeftOffset, scale);\n\t}\n\n\t_onMoveEnd(ev) {\n\t\t// Update pixel bounds of renderer container (for positioning/sizing/clipping later)\n\t\tconst p = this.options.padding,\n\t\tsize = this._map.getSize(),\n\t\tmin = this._map.containerPointToLayerPoint(size.multiplyBy(-p)).round();\n\n\t\tthis._bounds = new Bounds(min, min.add(size.multiplyBy(1 + p * 2)).round());\n\n\t\tthis._center = this._map.getCenter();\n\t\tthis._zoom = this._map.getZoom();\n\t\tthis._updateTransform(this._center, this._zoom);\n\n\t\tthis._onSettled(ev);\n\t}\n\n\t_reset() {\n\t\tthis._onSettled();\n\t\tthis._updateTransform(this._center, this._zoom);\n\t\tthis._onViewReset();\n\t}\n\n\t// Subclass interface, see the class description.\n\t_initContainer() {\n\t\tthis._container = DomUtil.create('div');\n\t}\n\t_destroyContainer() {\n\t\tDomEvent.off(this._container);\n\t\tthis._container.remove();\n\t\tdelete this._container;\n\t}\n\t_resizeContainer() {\n\t\tconst p = this.options.padding,\n\t\tsize = this._map.getSize().multiplyBy(1 + p * 2).round();\n\t\tthis._container.style.width = `${size.x}px`;\n\t\tthis._container.style.height = `${size.y}px`;\n\t\treturn size;\n\t}\n\t_onZoomEnd() {}\n\t_onViewReset() {}\n\t_onSettled() {}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,iBAAb,MAAa,uBAAuB,MAAM;CAEzC,OAAO,iBAAiB;EACvB,SAAS;EACT,YAAY;CACb;;;;CAKA,YAAY,SAAS;EACpB,MAAM;EACN,WAAgB,MAAM,OAAO;EAE7B,KAAK,cAAc,cAAc;CAClC;;;;;CAMA,QAAQ;EACP,IAAI,CAAC,KAAK,YAAY;GACrB,KAAK,eAAe;GAGpB,KAAK,WAAW,UAAU,IAAI,uBAAuB;EACtD;EAEA,KAAK,QAAQ,CAAC,CAAC,OAAO,KAAK,UAAU;EACrC,KAAK,iBAAiB;EACtB,KAAK,WAAW;CACjB;;;;;CAMA,WAAW;EACV,KAAK,kBAAkB;CACxB;;;;;CAMA,YAAY;EACX,MAAM,SAAS;GACd,WAAW,KAAK;GAChB,MAAM,KAAK;GACX,SAAS,KAAK;GACd,QAAQ,KAAK;GACb,SAAS,KAAK;GACd,UAAU,KAAK;EAChB;EACA,IAAI,KAAK,QAAQ,YAChB,OAAO,OAAO,KAAK;EAEpB,OAAO;CACR;CAEA,YAAY,IAAI;EACf,KAAK,iBAAiB,GAAG,QAAQ,GAAG,IAAI;CACzC;CAEA,UAAU;EACT,KAAK,iBAAiB,KAAK,KAAK,UAAU,GAAG,KAAK,KAAK,QAAQ,CAAC;CACjE;CAEA,iBAAiB,QAAQ,MAAM;EAC9B,MAAM,QAAQ,KAAK,KAAK,aAAa,MAAM,KAAK,KAAK,GACrD,WAAW,KAAK,KAAK,QAAQ,CAAC,CAAC,WAAW,KAAM,KAAK,QAAQ,OAAO,GACpE,qBAAqB,KAAK,KAAK,QAAQ,KAAK,S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lay extends Layer {
|
|
|
228
228
|
}
|
|
229
229
|
/**
|
|
230
230
|
* Sets the HTML content of the overlay. A `String` argument is rendered as
|
|
231
|
-
* HTML; if it may contain untrusted input, sanitize it
|
|
232
|
-
*
|
|
231
|
+
* HTML; if it may contain untrusted input, sanitize it or pass an `HTMLElement`
|
|
232
|
+
* with safe `textContent` instead. A `DocumentFragment`
|
|
233
233
|
* can be passed as well. If a function is passed the source layer will be passed
|
|
234
234
|
* to the function. The function should return a `String`, `HTMLElement` or
|
|
235
235
|
* `DocumentFragment` to be used in the overlay.
|
|
@@ -343,7 +343,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
343
343
|
}
|
|
344
344
|
_updatePosition() {
|
|
345
345
|
if (!this._map) return;
|
|
346
|
-
const pos = this._map.latLngToLayerPoint(this._latlng)
|
|
346
|
+
const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng)), offset = Point.from(this.options.offset);
|
|
347
347
|
this._setContainerPosition(pos.add(this._getAnchor()));
|
|
348
348
|
const bottom = this._containerBottom = -offset.y, left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
|
|
349
349
|
if (this.options.overflow) {
|