maplair 4.2.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -8
- package/dist/esm/control/AttributionControl.js +10 -10
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +0 -1
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -1
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +16 -11
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +0 -1
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +13 -9
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +0 -1
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +4 -5
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +3 -2
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/ZoomControl.js +13 -13
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Events.js +4 -2
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Util.js +16 -4
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +55 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +4 -7
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +5 -5
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +4 -6
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +23 -34
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +6 -3
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +2 -2
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +12 -17
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -7
- package/dist/esm/geometry/Transformation.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +1 -1
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +23 -23
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +7 -4
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +11 -6
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +30 -11
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +18 -35
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +2 -2
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +4 -8
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +16 -15
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +6 -7
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +49 -48
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/SvgIcon.js +1 -1
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +18 -16
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +9 -9
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +44 -93
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +8 -7
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +9 -1
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +10 -5
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +10 -11
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.js +19 -26
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +16 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +3 -3
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +6 -9
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +104 -49
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -4
- package/dist/esm/map/MapSync.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +2 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +68 -30
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +3 -5
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +3 -6
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -6
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -4
- package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +8 -20
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +700 -687
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +700 -687
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/en.json +1 -0
- package/package.json +2 -1
- package/src/control/AttributionControl.js +9 -9
- package/src/control/ButtonControl.js +0 -1
- package/src/control/ContextMenu.js +1 -1
- package/src/control/Control.js +13 -16
- package/src/control/FullscreenControl.js +0 -1
- package/src/control/LayersControl.js +14 -10
- package/src/control/RotateControl.js +0 -1
- package/src/control/ScaleControl.js +4 -5
- package/src/control/SideBySideControl.js +4 -2
- package/src/control/ZoomControl.js +10 -13
- package/src/core/Events.js +8 -2
- package/src/core/Util.js +16 -3
- package/src/dom/DomEvent.PointerEvents.js +47 -1
- package/src/dom/DomEvent.js +5 -17
- package/src/dom/DomUtil.js +5 -5
- package/src/dom/Draggable.js +5 -6
- package/src/geo/LatLng.js +22 -36
- package/src/geo/LatLngBounds.js +10 -4
- package/src/geometry/Bounds.js +3 -3
- package/src/geometry/Point.js +18 -26
- package/src/geometry/Transformation.js +1 -8
- package/src/layer/BlanketOverlay.js +1 -1
- package/src/layer/DivOverlay.js +28 -30
- package/src/layer/ImageOverlay.js +9 -7
- package/src/layer/Layer.js +18 -6
- package/src/layer/Popup.js +38 -17
- package/src/layer/Tooltip.js +17 -44
- package/src/layer/VideoOverlay.js +2 -2
- package/src/layer/marker/DivIcon.js +3 -6
- package/src/layer/marker/Icon.js +19 -18
- package/src/layer/marker/Marker.Drag.js +16 -18
- package/src/layer/marker/Marker.js +66 -59
- package/src/layer/marker/SvgIcon.js +1 -1
- package/src/layer/tile/GridLayer.js +21 -23
- package/src/layer/tile/TileLayer.js +17 -14
- package/src/layer/vector/Canvas.js +52 -148
- package/src/layer/vector/Circle.js +14 -9
- package/src/layer/vector/CircleMarker.js +11 -1
- package/src/layer/vector/Path.js +11 -5
- package/src/layer/vector/Polygon.js +11 -10
- package/src/layer/vector/Polyline.js +20 -21
- package/src/layer/vector/Renderer.getRenderer.js +2 -1
- package/src/layer/vector/Renderer.js +21 -3
- package/src/layer/vector/SVG.js +3 -3
- package/src/map/Map.Rotation.js +7 -6
- package/src/map/Map.js +135 -54
- package/src/map/MapSync.js +1 -1
- package/src/map/handler/BoxZoomHandler.js +2 -0
- package/src/map/handler/DisplaceHandler.js +53 -7
- package/src/map/handler/KeyboardHandler.js +5 -10
- package/src/map/handler/PinchZoomHandler.js +3 -3
- package/src/map/handler/ScrollWheelZoomHandler.js +3 -3
- package/src/map/handler/TapDragZoomHandler.js +1 -1
- package/src/map/handler/TapHoldHandler.js +13 -25
- package/src/maplair.css +38 -9
- package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
- package/src/dom/DomEvent.DoubleTap.js +0 -143
|
@@ -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 (LatLng.validate(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 (LatLng.validate(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 = (ne2.lat > sw.lat) && (sw2.lat < ne.lat),\n\t\tlngOverlaps = (ne2.lng > sw.lng) && (sw2.lng < ne.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"],"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,OAAO,SAAS,GAAG,GAC7B,MAAM,MAAM,OAAO,KAAK,GAAG;OAE3B,OAAO,KAAK,OAAO,aAAa,KAAK,GAAG,CAAC;EAG1C,IAAI,CAAC,IAAI;GACR,KA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KACvD,KAAK,WAAW,OAAO,OAAO,aAAa,GAAG,SAAS;CAC/D;;;;;CAMA,UAAU;EACT,OAAO,CAAC,EAAE,KAAK,cAAc,KAAK;CACnC;AACD"}
|
|
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":";;;;;;;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}
|
|
@@ -165,7 +165,7 @@ var Bounds = class Bounds {
|
|
|
165
165
|
*/
|
|
166
166
|
overlaps(bounds) {
|
|
167
167
|
bounds = Bounds.from(bounds);
|
|
168
|
-
const min = this.min, max = this.max, min2 = bounds.min, max2 = bounds.max, xOverlaps =
|
|
168
|
+
const min = this.min, max = this.max, min2 = bounds.min, max2 = bounds.max, xOverlaps = Math.max(min.x, min2.x) < Math.min(max.x, max2.x), yOverlaps = Math.max(min.y, min2.y) < Math.min(max.y, max2.y);
|
|
169
169
|
return xOverlaps && yOverlaps;
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
@@ -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]
|
|
201
|
+
return obj instanceof Point || (Array.isArray(obj) ? 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 = (max2.x > min.x) && (min2.x < max.x),\n\t\tyOverlaps = (max2.y > min.y) && (min2.y < max.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] === 'number' : '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,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K,KAAK,IAAI;EAElD,OAAO,eAAe;CACvB;;;;;;;CAQA,SAAS,QAAQ;EAChB,SAAS,OAAO,KAAK,MAAM;EAE3B,MAAM,MAAM,KAAK,KACjB,MAAM,KAAK,KACX,OAAO,OAAO,KACd,OAAO,OAAO,KACd,YAAa,KAAK,IAAI,IAAI,KAAO,KAAK,IAAI,IAAI,GAC9C,YAAa,KAAK,IAAI,IAAI,KAAO,KAAK,IAAI,IAAI;EAE9C,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) ? 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,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AAC,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,4 +1,4 @@
|
|
|
1
|
-
import { formatNum } from "../core/Util.js";
|
|
1
|
+
import { formatNum, toNumber } from "../core/Util.js";
|
|
2
2
|
// src/geometry/Point.js
|
|
3
3
|
/**
|
|
4
4
|
* A point in pixels: a `Point`, an array of the form `[x, y]`, or a plain object of
|
|
@@ -37,31 +37,25 @@ var Point = class Point {
|
|
|
37
37
|
* @param {boolean} [round]
|
|
38
38
|
*/
|
|
39
39
|
constructor(x, y, round) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (x instanceof Point) {
|
|
43
|
-
_x = x.x;
|
|
44
|
-
_y = x.y;
|
|
45
|
-
} else if (Array.isArray(x)) {
|
|
40
|
+
let _x = x, _y = y;
|
|
41
|
+
if (Array.isArray(x)) {
|
|
46
42
|
_x = x[0];
|
|
47
43
|
_y = x[1];
|
|
48
|
-
} else if (typeof x === "object" &&
|
|
44
|
+
} else if (typeof x === "object" && x !== null) {
|
|
49
45
|
_x = x.x;
|
|
50
46
|
_y = x.y;
|
|
51
|
-
} else {
|
|
52
|
-
_x = x;
|
|
53
|
-
_y = y;
|
|
54
47
|
}
|
|
55
48
|
/**
|
|
56
49
|
* The `x` coordinate of the point.
|
|
57
50
|
* @type {number}
|
|
58
51
|
*/
|
|
59
|
-
this.x = round ? Math.round(_x) : _x;
|
|
52
|
+
this.x = round ? Math.round(toNumber(_x)) : toNumber(_x);
|
|
60
53
|
/**
|
|
61
54
|
* The `y` coordinate of the point.
|
|
62
55
|
* @type {number}
|
|
63
56
|
*/
|
|
64
|
-
this.y = round ? Math.round(_y) : _y;
|
|
57
|
+
this.y = round ? Math.round(toNumber(_y)) : toNumber(_y);
|
|
58
|
+
if (this.x !== this.x || this.y !== this.y) throw new Error(`Invalid Point object: (${_x}, ${_y})`);
|
|
65
59
|
}
|
|
66
60
|
/**
|
|
67
61
|
* Returns the given `Point` object as it is (unless `round` is set), or else a new
|
|
@@ -89,10 +83,11 @@ var Point = class Point {
|
|
|
89
83
|
* @returns {boolean}
|
|
90
84
|
*/
|
|
91
85
|
static validate(x, y) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
try {
|
|
87
|
+
return !!new Point(x, y);
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
96
91
|
}
|
|
97
92
|
/**
|
|
98
93
|
* Returns the result of addition of the current and the given points.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Point.js","names":[],"sources":["../../../src/geometry/Point.js"],"sourcesContent":["import {formatNum} 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\n\t\tconst valid = Point.validate(x, y);\n\t\tif (!valid) {\n\t\t\tthrow new Error(`Invalid Point object: (${x}, ${y})`);\n\t\t}\n\n\t\tlet _x, _y;\n\t\tif (x instanceof Point) {\n\t\t\t_x = x.x;\n\t\t\t_y = x.y;\n\t\t} else if (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' in x && 'y' in x) {\n\t\t\t_x = x.x;\n\t\t\t_y = x.y;\n\t\t} else {\n\t\t\t_x = x;\n\t\t\t_y = 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(_x) : _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(_y) : _y);\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\tif (x instanceof Point || Array.isArray(x)) {\n\t\t\treturn true;\n\t\t} else if (x && typeof x === 'object' && 'x' in x && 'y' in x) {\n\t\t\treturn true;\n\t\t} else if ((x || x === 0) && (y || y === 0)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\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(${formatNum(this.x)}, ${formatNum(this.y)})`;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,QAAb,MAAa,MAAM;;;;;;;;;;CAUlB,YAAY,GAAG,GAAG,OAAO;EAGxB,IAAI,CADU,MAAM,SAAS,GAAG,CACvB,GACR,MAAM,IAAI,MAAM,0BAA0B,EAAE,IAAI,EAAE,EAAE;EAGrD,IAAI,IAAI;EACR,IAAI,aAAa,OAAO;GACvB,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO,IAAI,MAAM,QAAQ,CAAC,GAAG;GAC5B,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO,IAAI,OAAO,MAAM,YAAY,OAAO,KAAK,OAAO,GAAG;GACzD,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO;GACN,KAAK;GACL,KAAK;EACN;;;;;EAMA,KAAK,IAAK,QAAQ,KAAK,MAAM,EAAE,IAAI;;;;;EAKnC,KAAK,IAAK,QAAQ,KAAK,MAAM,EAAE,IAAI;CACpC;;;;;;;;;;;;;;;;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,aAAa,SAAS,MAAM,QAAQ,CAAC,GACxC,OAAO;OACD,IAAI,KAAK,OAAO,MAAM,YAAY,OAAO,KAAK,OAAO,GAC3D,OAAO;OACD,KAAK,KAAK,MAAM,OAAO,KAAK,MAAM,IACxC,OAAO;EAER,OAAO;CACR;;;;;;CAOA,IAAI,OAAO;EAEV,OAAO,IAAI,MAAM,IA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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,SAAS,UAAU,KAAK,CAAC,EAAE,IAAI,UAAU,KAAK,CAAC,EAAE;CACzD;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 {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,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+23,7 @@ var Transformation = class {
|
|
|
23
23
|
* @param {number} [d]
|
|
24
24
|
*/
|
|
25
25
|
constructor(a, b, c, d) {
|
|
26
|
-
if (Array.isArray(a))
|
|
27
|
-
this._a = a[0];
|
|
28
|
-
this._b = a[1];
|
|
29
|
-
this._c = a[2];
|
|
30
|
-
this._d = a[3];
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
26
|
+
if (Array.isArray(a)) [a, b, c, d] = a;
|
|
33
27
|
this._a = a;
|
|
34
28
|
this._b = b;
|
|
35
29
|
this._c = c;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transformation.js","names":[],"sources":["../../../src/geometry/Transformation.js"],"sourcesContent":["import {Point} from './Point.js';\n\n/**\n * Represents an affine transformation: a set of coefficients `a`, `b`, `c`, `d`\n * for transforming a point of a form `(x, y)` into `(a*x + b, c*y + d)` and doing\n * the reverse. Used by Maplair in its projections code.\n *\n * @example\n * ```js\n * const transformation = new Transformation(2, 5, -1, 10),\n * \tp = new Point(1, 2),\n * \tp2 = transformation.transform(p), // new Point(7, 8)\n * \tp3 = transformation.untransform(p2); // new Point(1, 2)\n * ```\n */\nexport class Transformation {\n\t/**\n\t * Instantiates a Transformation object with the given coefficients. Alternatively,\n\t * expects a coefficients array of the form `[a, b, c, d]`.\n\t * @param {number|[number, number, number, number]} a\n\t * @param {number} [b]\n\t * @param {number} [c]\n\t * @param {number} [d]\n\t */\n\tconstructor(a, b, c, d) {\n\t\tif (Array.isArray(a)) {
|
|
1
|
+
{"version":3,"file":"Transformation.js","names":[],"sources":["../../../src/geometry/Transformation.js"],"sourcesContent":["import {Point} from './Point.js';\n\n/**\n * Represents an affine transformation: a set of coefficients `a`, `b`, `c`, `d`\n * for transforming a point of a form `(x, y)` into `(a*x + b, c*y + d)` and doing\n * the reverse. Used by Maplair in its projections code.\n *\n * @example\n * ```js\n * const transformation = new Transformation(2, 5, -1, 10),\n * \tp = new Point(1, 2),\n * \tp2 = transformation.transform(p), // new Point(7, 8)\n * \tp3 = transformation.untransform(p2); // new Point(1, 2)\n * ```\n */\nexport class Transformation {\n\t/**\n\t * Instantiates a Transformation object with the given coefficients. Alternatively,\n\t * expects a coefficients array of the form `[a, b, c, d]`.\n\t * @param {number|[number, number, number, number]} a\n\t * @param {number} [b]\n\t * @param {number} [c]\n\t * @param {number} [d]\n\t */\n\tconstructor(a, b, c, d) {\n\t\tif (Array.isArray(a)) { [a, b, c, d] = a; }\n\t\tthis._a = a;\n\t\tthis._b = b;\n\t\tthis._c = c;\n\t\tthis._d = d;\n\t}\n\n\t/**\n\t * Returns a transformed point, optionally multiplied by the given scale.\n\t * Only accepts actual `Point` instances, not arrays.\n\t * @param {Point} point\n\t * @param {number} [scale]\n\t * @returns {Point}\n\t */\n\ttransform(point, scale) { // (Point, Number) -> Point\n\t\treturn this._transform(new Point(point), scale);\n\t}\n\n\t// destructive transform (faster)\n\t_transform(point, scale) {\n\t\tscale ||= 1;\n\t\tpoint.x = scale * (this._a * point.x + this._b);\n\t\tpoint.y = scale * (this._c * point.y + this._d);\n\t\treturn point;\n\t}\n\n\t/**\n\t * Returns the reverse transformation of the given point, optionally divided\n\t * by the given scale. Only accepts actual `Point` instances, not arrays.\n\t * @param {Point} point\n\t * @param {number} [scale]\n\t * @returns {Point}\n\t */\n\tuntransform(point, scale) {\n\t\tscale ||= 1;\n\t\treturn new Point(\n\t\t\t(point.x / scale - this._b) / this._a,\n\t\t\t(point.y / scale - this._d) / this._c);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,iBAAb,MAA4B;;;;;;;;;CAS3B,YAAY,GAAG,GAAG,GAAG,GAAG;EACvB,IAAI,MAAM,QAAQ,CAAC,GAAK,CAAC,GAAG,GAAG,GAAG,KAAK;EACvC,KAAK,KAAK;EACV,KAAK,KAAK;EACV,KAAK,KAAK;EACV,KAAK,KAAK;CACX;;;;;;;;CASA,UAAU,OAAO,OAAO;EACvB,OAAO,KAAK,WAAW,IAAI,MAAM,KAAK,GAAG,KAAK;CAC/C;CAGA,WAAW,OAAO,OAAO;EACxB,UAAU;EACV,MAAM,IAAI,SAAS,KAAK,KAAK,MAAM,IAAI,KAAK;EAC5C,MAAM,IAAI,SAAS,KAAK,KAAK,MAAM,IAAI,KAAK;EAC5C,OAAO;CACR;;;;;;;;CASA,YAAY,OAAO,OAAO;EACzB,UAAU;EACV,OAAO,IAAI,OACT,MAAM,IAAI,QAAQ,KAAK,MAAM,KAAK,KAClC,MAAM,IAAI,QAAQ,KAAK,MAAM,KAAK,EAAE;CACvC;AACD"}
|
|
@@ -64,7 +64,7 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
|
64
64
|
this._initContainer();
|
|
65
65
|
this._container.classList.add("maplair-zoom-animated");
|
|
66
66
|
}
|
|
67
|
-
this.getPane().
|
|
67
|
+
this.getPane().append(this._container);
|
|
68
68
|
this._resizeContainer();
|
|
69
69
|
this._onMoveEnd();
|
|
70
70
|
}
|
|
@@ -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().
|
|
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._round();\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;EA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AAmB;EAClB,MAAM,IAAI,KAAK,QAAQ,SACvB,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM;EACvD,KAAK,WAAW,MAAM,QAAQ,GAAG,KAAK,EAAE;EACxC,KAAK,WAAW,MAAM,SAAS,GAAG,KAAK,EAAE;EACzC,OAAO;CACR;CACA,aAAa,CAAC;CACd,eAAe,CAAC;CAChB,aAAa,CAAC;AACf"}
|
|
@@ -12,9 +12,12 @@ import { FeatureGroup } from "./FeatureGroup.js";
|
|
|
12
12
|
/** @import {EventListener, MaplairEvent} from '../core/Events.js' */
|
|
13
13
|
/**
|
|
14
14
|
* The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an
|
|
15
|
-
* `HTMLElement`, or a function receiving the source layer and
|
|
16
|
-
*
|
|
15
|
+
* `HTMLElement` or `DocumentFragment`, or a function receiving the source layer and
|
|
16
|
+
* returning one of them.
|
|
17
|
+
* @typedef {string|HTMLElement|DocumentFragment|
|
|
18
|
+
* ((layer: Layer) => string|HTMLElement|DocumentFragment)} DivOverlayContent
|
|
17
19
|
*/
|
|
20
|
+
const fragmentNodes = /* @__PURE__ */ new WeakMap();
|
|
18
21
|
/**
|
|
19
22
|
* Options of `DivOverlay`.
|
|
20
23
|
* @typedef {object} DivOverlayOptions
|
|
@@ -30,8 +33,8 @@ import { FeatureGroup } from "./FeatureGroup.js";
|
|
|
30
33
|
* in the DOM (for styling and events).
|
|
31
34
|
* @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while
|
|
32
35
|
* initializing. If a function is passed the source layer will be passed to the
|
|
33
|
-
* function. The function should return a `String` or `
|
|
34
|
-
* overlay. String content is rendered as HTML; sanitize untrusted input or pass an
|
|
36
|
+
* function. The function should return a `String`, `HTMLElement` or `DocumentFragment`
|
|
37
|
+
* to be used in the overlay. String content is rendered as HTML; sanitize untrusted input or pass an
|
|
35
38
|
* `HTMLElement` with safe `textContent` instead.
|
|
36
39
|
* @extends InteractiveLayerOptions
|
|
37
40
|
*/
|
|
@@ -63,7 +66,8 @@ const layerDivOverlayMethods = { _initOverlay(OverlayClass, old, content, option
|
|
|
63
66
|
} };
|
|
64
67
|
/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */
|
|
65
68
|
/**
|
|
66
|
-
* Base model for Popup and Tooltip
|
|
69
|
+
* Base model for `Popup` and `Tooltip`; use those to show content on the map. Inherit
|
|
70
|
+
* from it for custom overlays like plugins.
|
|
67
71
|
*
|
|
68
72
|
* @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.
|
|
69
73
|
*/
|
|
@@ -140,8 +144,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
140
144
|
else {
|
|
141
145
|
if (arguments.length) this._source = layer;
|
|
142
146
|
else layer = this._source;
|
|
143
|
-
this._prepareOpen();
|
|
144
|
-
this.openOn(layer._map);
|
|
147
|
+
if (this._prepareOpen()) this.openOn(layer._map);
|
|
145
148
|
}
|
|
146
149
|
return this;
|
|
147
150
|
}
|
|
@@ -153,7 +156,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
153
156
|
if (!this._container) this._initLayout();
|
|
154
157
|
if (map._fadeAnimated) this._container.style.opacity = "0";
|
|
155
158
|
clearTimeout(this._removeTimeout);
|
|
156
|
-
this.getPane().
|
|
159
|
+
this.getPane().append(this._container);
|
|
157
160
|
if (this.options.overflow) {
|
|
158
161
|
this._container.classList.add("maplair-overflow");
|
|
159
162
|
this._container.popover = "manual";
|
|
@@ -226,9 +229,10 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
226
229
|
/**
|
|
227
230
|
* Sets the HTML content of the overlay. A `String` argument is rendered as
|
|
228
231
|
* HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)
|
|
229
|
-
* or pass an `HTMLElement` with safe `textContent` instead.
|
|
230
|
-
* passed
|
|
231
|
-
* return a `String
|
|
232
|
+
* or pass an `HTMLElement` with safe `textContent` instead. A `DocumentFragment`
|
|
233
|
+
* can be passed as well. If a function is passed the source layer will be passed
|
|
234
|
+
* to the function. The function should return a `String`, `HTMLElement` or
|
|
235
|
+
* `DocumentFragment` to be used in the overlay.
|
|
232
236
|
* @param {DivOverlayContent} content
|
|
233
237
|
* @returns {this}
|
|
234
238
|
*/
|
|
@@ -276,7 +280,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
276
280
|
* @returns {boolean}
|
|
277
281
|
*/
|
|
278
282
|
isOpen() {
|
|
279
|
-
return !!this._map
|
|
283
|
+
return !!this._map?.hasLayer(this);
|
|
280
284
|
}
|
|
281
285
|
/**
|
|
282
286
|
* Brings this overlay in front of other overlays (in the same map pane).
|
|
@@ -320,25 +324,21 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
320
324
|
if (!source) return false;
|
|
321
325
|
this._source = source;
|
|
322
326
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
else if (source.getLatLng) latlng = source.getLatLng();
|
|
326
|
-
else if (source.getBounds) latlng = source.getBounds().getCenter();
|
|
327
|
-
else throw new Error("Unable to get source layer LatLng.");
|
|
328
|
-
}
|
|
327
|
+
latlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();
|
|
328
|
+
if (!latlng) throw new Error("Unable to get source layer LatLng.");
|
|
329
329
|
this.setLatLng(latlng);
|
|
330
330
|
if (this._map) this.update();
|
|
331
331
|
return true;
|
|
332
332
|
}
|
|
333
333
|
_updateContent() {
|
|
334
|
-
if (
|
|
334
|
+
if (this._content == null) return;
|
|
335
335
|
const node = this._contentNode;
|
|
336
336
|
const content = typeof this._content === "function" ? this._content(this._source ?? this) : this._content;
|
|
337
337
|
if (typeof content === "string") node.innerHTML = content;
|
|
338
|
-
else {
|
|
339
|
-
|
|
340
|
-
node.
|
|
341
|
-
}
|
|
338
|
+
else if (content instanceof DocumentFragment) {
|
|
339
|
+
if (content.hasChildNodes()) fragmentNodes.set(content, [...content.childNodes]);
|
|
340
|
+
node.replaceChildren(...fragmentNodes.get(content) ?? []);
|
|
341
|
+
} else node.replaceChildren(content);
|
|
342
342
|
this.fire("contentupdate");
|
|
343
343
|
}
|
|
344
344
|
_updatePosition() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement`, or a function receiving the source layer and returning one of them.\n * @typedef {string|HTMLElement|((layer: Layer) => string|HTMLElement)} DivOverlayContent\n */\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String` or `HTMLElement` to be used in the\n * overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tinteractive: false,\n\t\toffset: [0, 0],\n\t\tclassName: '',\n\t\tpane: undefined,\n\t\toverflow: false,\n\t\tcontent: ''\n\t};\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tthis._prepareOpen();\n\n\t\t\t// open the overlay on the map\n\t\t\tthis.openOn(layer._map);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().appendChild(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '1';\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)\n\t * or pass an `HTMLElement` with safe `textContent` instead. If a function is\n\t * passed the source layer will be passed to the function. The function should\n\t * return a `String` or `HTMLElement` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map && this._map.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tif (!latlng) {\n\t\t\tif (source.getCenter) {\n\t\t\t\tlatlng = source.getCenter();\n\t\t\t} else if (source.getLatLng) {\n\t\t\t\tlatlng = source.getLatLng();\n\t\t\t} else if (source.getBounds) {\n\t\t\t\tlatlng = source.getBounds().getCenter();\n\t\t\t} else {\n\t\t\t\tthrow new Error('Unable to get source layer LatLng.');\n\t\t\t}\n\t\t}\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (!this._content) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else {\n\t\t\twhile (node.hasChildNodes()) {\n\t\t\t\tnode.removeChild(node.firstChild);\n\t\t\t}\n\t\t\tnode.appendChild(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng)._round(),\n\t\toffset = Point.from(this.options.offset);\n\n\t\tthis._setContainerPosition(pos.add(this._getAnchor()));\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [0, 0];\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAM,uBAAuB,EAC5B,aAAa,cAAc,SAAS,QAAQ,SAAS;CACpD,IAAI,UAAU;CACd,IAAI,EAAE,mBAAmB,eACxB,UAAU,IAAI,aAAa,OAAO,CAAC,CAAC,WAAW,OAAO;CAEvD,IAAI,QACH,QAAQ,UAAU,MAAM;CAEzB,OAAO;AACR,EACD;;;;;;AAOA,MAAM,yBAAyB,EAC9B,aAAa,cAAc,KAAK,SAAS,SAAS;CACjD,IAAI,UAAU;CACd,IAAI,mBAAmB,cAAc;EACpC,WAAgB,SAAS,OAAO;EAChC,QAAQ,UAAU;CACnB,OAAO;EACN,UAAW,OAAO,CAAC,UAAW,MAAM,IAAI,aAAa,SAAS,IAAI;EAClE,QAAQ,WAAW,OAAO;CAC3B;CACA,OAAO;AACR,EACD;;;;;;;AAQA,IAAa,aAAb,MAAa,mBAAmB,MAAM;CAErC,OAAO,iBAAiB;EACvB,aAAa;EACb,QAAQ,CAAC,GAAG,CAAC;EACb,WAAW;EACX,MAAM,KAAA;EACN,UAAU;EACV,SAAS;CACV;;;;;;;;;;;;;;;;;;;;CAqBA,YAAY,SAAS,QAAQ;EAC5B,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AGA,wBAAwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
|
|
1
|
+
{"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement` or `DocumentFragment`, or a function receiving the source layer and\n * returning one of them.\n * @typedef {string|HTMLElement|DocumentFragment|\n * ((layer: Layer) => string|HTMLElement|DocumentFragment)} DivOverlayContent\n */\n\nconst fragmentNodes = new WeakMap();\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String`, `HTMLElement` or `DocumentFragment`\n * to be used in the overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for `Popup` and `Tooltip`; use those to show content on the map. Inherit\n * from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tinteractive: false,\n\t\toffset: [0, 0],\n\t\tclassName: '',\n\t\tpane: undefined,\n\t\toverflow: false,\n\t\tcontent: ''\n\t};\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tif (this._prepareOpen()) {\n\t\t\t\t// open the overlay on the map\n\t\t\t\tthis.openOn(layer._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().append(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '1';\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)\n\t * or pass an `HTMLElement` with safe `textContent` instead. A `DocumentFragment`\n\t * can be passed as well. If a function is passed the source layer will be passed\n\t * to the function. The function should return a `String`, `HTMLElement` or\n\t * `DocumentFragment` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map?.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tlatlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();\n\t\tif (!latlng) { throw new Error('Unable to get source layer LatLng.'); }\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (this._content == null) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else if (content instanceof DocumentFragment) {\n\t\t\t// inserting a fragment empties it, so keep its nodes to insert them again on later updates\n\t\t\tif (content.hasChildNodes()) { fragmentNodes.set(content, [...content.childNodes]); }\n\t\t\tnode.replaceChildren(...fragmentNodes.get(content) ?? []);\n\t\t} else {\n\t\t\tnode.replaceChildren(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng)._round(),\n\t\toffset = Point.from(this.options.offset);\n\n\t\tthis._setContainerPosition(pos.add(this._getAnchor()));\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [0, 0];\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAM,gCAAgB,IAAI,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;AA2BlC,MAAM,uBAAuB,EAC5B,aAAa,cAAc,SAAS,QAAQ,SAAS;CACpD,IAAI,UAAU;CACd,IAAI,EAAE,mBAAmB,eACxB,UAAU,IAAI,aAAa,OAAO,CAAC,CAAC,WAAW,OAAO;CAEvD,IAAI,QACH,QAAQ,UAAU,MAAM;CAEzB,OAAO;AACR,EACD;;;;;;AAOA,MAAM,yBAAyB,EAC9B,aAAa,cAAc,KAAK,SAAS,SAAS;CACjD,IAAI,UAAU;CACd,IAAI,mBAAmB,cAAc;EACpC,WAAgB,SAAS,OAAO;EAChC,QAAQ,UAAU;CACnB,OAAO;EACN,UAAW,OAAO,CAAC,UAAW,MAAM,IAAI,aAAa,SAAS,IAAI;EAClE,QAAQ,WAAW,OAAO;CAC3B;CACA,OAAO;AACR,EACD;;;;;;;;A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AQ,UAAU;GAC1B,MAAM,eAAe,KAAK,KAAK,YAC/B,OAAO,aAAa,sBAAsB;GAC1C,MAAM,KAAK,KAAK,2BAA2B,GAAG,CAAC,CAC7C,KAAK,IAAI,MAAM,KAAK,OAAO,aAAa,YAAY,KAAK,MAAM,aAAa,SAAS,CAAC;EACzF;EACA,YAAoB,KAAK,YAAY,GAAG;CACzC;CAGA,wBAAwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
|
|
@@ -87,6 +87,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
87
87
|
onAdd() {
|
|
88
88
|
if (!this._image) {
|
|
89
89
|
this._initImage();
|
|
90
|
+
this._updateZIndex();
|
|
90
91
|
if (this.options.opacity < 1) this._updateOpacity();
|
|
91
92
|
}
|
|
92
93
|
if (this.options.interactive) {
|
|
@@ -94,7 +95,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
94
95
|
this.addInteractiveTarget(this._image);
|
|
95
96
|
}
|
|
96
97
|
this._image.classList.toggle("maplair-pixelated", !!this.options.pixelated);
|
|
97
|
-
this.getPane().
|
|
98
|
+
this.getPane().append(this._image);
|
|
98
99
|
this._reset();
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
@@ -127,7 +128,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
127
128
|
* @returns {this}
|
|
128
129
|
*/
|
|
129
130
|
setStyle(styleOpts) {
|
|
130
|
-
if (styleOpts.opacity) this.setOpacity(styleOpts.opacity);
|
|
131
|
+
if (styleOpts.opacity != null) this.setOpacity(styleOpts.opacity);
|
|
131
132
|
return this;
|
|
132
133
|
}
|
|
133
134
|
/**
|
|
@@ -213,7 +214,6 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
213
214
|
img.onerror = this._overlayOnError.bind(this);
|
|
214
215
|
if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
|
|
215
216
|
img.decoding = this.options.decoding;
|
|
216
|
-
if (this.options.zIndex) this._updateZIndex();
|
|
217
217
|
if (wasElementSupplied) {
|
|
218
218
|
this._url = img.src;
|
|
219
219
|
return;
|
|
@@ -235,7 +235,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
235
235
|
this._image.style.opacity = `${this.options.opacity}`;
|
|
236
236
|
}
|
|
237
237
|
_updateZIndex() {
|
|
238
|
-
if (this._image && this.options.zIndex
|
|
238
|
+
if (this._image && this.options.zIndex != null) this._image.style.zIndex = `${this.options.zIndex}`;
|
|
239
239
|
}
|
|
240
240
|
_overlayOnError() {
|
|
241
241
|
this.fire("error");
|
|
@@ -252,6 +252,9 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
252
252
|
getCenter() {
|
|
253
253
|
return this._bounds.getCenter();
|
|
254
254
|
}
|
|
255
|
+
_togglesPopupOnClick() {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
255
258
|
};
|
|
256
259
|
export { ImageOverlay };
|
|
257
260
|
|