maplair 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +89 -8
- package/dist/esm/control/AttributionControl.js +10 -10
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +0 -1
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -1
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +16 -11
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +0 -1
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +13 -9
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +0 -1
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +4 -5
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +3 -2
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/ZoomControl.js +13 -13
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Events.js +3 -2
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Util.js +16 -4
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +55 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +4 -7
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +5 -5
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +4 -6
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +23 -34
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +6 -3
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +2 -2
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +12 -17
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -7
- package/dist/esm/geometry/Transformation.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +1 -1
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +23 -23
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +7 -4
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +11 -6
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +30 -11
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +18 -35
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +2 -2
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +4 -8
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +16 -15
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +6 -7
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +49 -48
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/SvgIcon.js +1 -1
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +18 -16
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +9 -9
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +44 -93
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +7 -7
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +9 -1
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +10 -5
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +10 -11
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.js +19 -26
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +16 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +3 -3
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +6 -9
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +104 -49
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -4
- package/dist/esm/map/MapSync.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +2 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +68 -30
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +3 -5
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +3 -6
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -6
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -4
- package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +8 -20
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +698 -687
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +698 -687
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/en.json +1 -0
- package/package.json +1 -1
- package/src/control/AttributionControl.js +9 -9
- package/src/control/ButtonControl.js +0 -1
- package/src/control/ContextMenu.js +1 -1
- package/src/control/Control.js +13 -16
- package/src/control/FullscreenControl.js +0 -1
- package/src/control/LayersControl.js +14 -10
- package/src/control/RotateControl.js +0 -1
- package/src/control/ScaleControl.js +4 -5
- package/src/control/SideBySideControl.js +4 -2
- package/src/control/ZoomControl.js +10 -13
- package/src/core/Events.js +6 -2
- package/src/core/Util.js +16 -3
- package/src/dom/DomEvent.PointerEvents.js +47 -1
- package/src/dom/DomEvent.js +5 -17
- package/src/dom/DomUtil.js +5 -5
- package/src/dom/Draggable.js +5 -6
- package/src/geo/LatLng.js +22 -36
- package/src/geo/LatLngBounds.js +10 -4
- package/src/geometry/Bounds.js +3 -3
- package/src/geometry/Point.js +18 -26
- package/src/geometry/Transformation.js +1 -8
- package/src/layer/BlanketOverlay.js +1 -1
- package/src/layer/DivOverlay.js +28 -30
- package/src/layer/ImageOverlay.js +9 -7
- package/src/layer/Layer.js +18 -6
- package/src/layer/Popup.js +38 -17
- package/src/layer/Tooltip.js +17 -44
- package/src/layer/VideoOverlay.js +2 -2
- package/src/layer/marker/DivIcon.js +3 -6
- package/src/layer/marker/Icon.js +19 -18
- package/src/layer/marker/Marker.Drag.js +16 -18
- package/src/layer/marker/Marker.js +66 -59
- package/src/layer/marker/SvgIcon.js +1 -1
- package/src/layer/tile/GridLayer.js +21 -23
- package/src/layer/tile/TileLayer.js +17 -14
- package/src/layer/vector/Canvas.js +52 -148
- package/src/layer/vector/Circle.js +11 -9
- package/src/layer/vector/CircleMarker.js +11 -1
- package/src/layer/vector/Path.js +11 -5
- package/src/layer/vector/Polygon.js +11 -10
- package/src/layer/vector/Polyline.js +20 -21
- package/src/layer/vector/Renderer.getRenderer.js +2 -1
- package/src/layer/vector/Renderer.js +21 -3
- package/src/layer/vector/SVG.js +3 -3
- package/src/map/Map.Rotation.js +7 -6
- package/src/map/Map.js +135 -54
- package/src/map/MapSync.js +1 -1
- package/src/map/handler/BoxZoomHandler.js +2 -0
- package/src/map/handler/DisplaceHandler.js +53 -7
- package/src/map/handler/KeyboardHandler.js +5 -10
- package/src/map/handler/PinchZoomHandler.js +3 -3
- package/src/map/handler/ScrollWheelZoomHandler.js +3 -3
- package/src/map/handler/TapDragZoomHandler.js +1 -1
- package/src/map/handler/TapHoldHandler.js +13 -25
- package/src/maplair.css +38 -9
- package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
- package/src/dom/DomEvent.DoubleTap.js +0 -143
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileLayer.js","names":["Util.setOptions","Util.template"],"sources":["../../../../src/layer/tile/TileLayer.js"],"sourcesContent":["import {GridLayer} from './GridLayer.js';\nimport * as Util from '../../core/Util.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport {I18n} from '../../core/I18n.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {GridLayerOptions, TileDoneCallback} from './GridLayer.js' */\n/** @import {TileEvent} from '../../core/Events.js' */\n\nconst osmHosts = ['tile.openstreetmap.org', 'tile.osm.org'];\nconst hostRe = /^(https?:)?\\/\\/([^/?#:]*)/i;\nconst httpRe = /^http:/i;\n\nfunction isOSMUrl(url) {\n\tconst host = hostRe.exec(url)?.[2] ?? '';\n\treturn osmHosts.some(osmHost => host === osmHost || host.endsWith(`.${osmHost}`));\n}\n\n// OSM tiles are upgraded to HTTPS so that the referrer policy works\nconst upgradeOSMUrl = url => (isOSMUrl(url) ? url.replace(httpRe, 'https:') : url);\n\n/**\n * Options of `TileLayer`.\n * @typedef {object} TileLayerOptions\n * @property {number} [minZoom=0] The minimum zoom level down to which this layer will be\n * displayed (inclusive).\n * @property {number} [maxZoom=18] The maximum zoom level up to which this layer will be\n * displayed (inclusive).\n * @property {string|string[]} [subdomains='abc'] Subdomains of the tile service. Can be\n * passed in the form of one string (where each letter is a subdomain name) or an array\n * of strings.\n * @property {string} [errorTileUrl=''] URL to the tile image to show in place of the\n * tile that failed to load.\n * @property {number} [zoomOffset=0] The zoom number used in tile URLs will be offset\n * with this value.\n * @property {boolean} [tms=false] If `true`, inverses Y axis numbering for tiles (turn\n * this on for [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) services).\n * @property {boolean} [zoomReverse=false] If set to true, the zoom number used in tile\n * URLs will be reversed (`maxZoom - zoom` instead of `zoom`).\n * @property {boolean} [detectRetina=false] If `true` and user is on a retina display, it\n * will request four tiles of half the specified size and a bigger zoom level in place\n * of one to utilize the high resolution.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute will\n * be added to the tiles. If a String is provided, all tiles will have their crossOrigin\n * attribute set to the String provided. This is needed if you want to access tile pixel\n * data. Refer to\n * [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)\n * for valid String values.\n * @property {ReferrerPolicy} [referrerPolicy='strict-origin-when-cross-origin'] Sets the\n * tiles' `referrerPolicy` attribute set to the String provided. See\n * [`HTMLImageElement.referrerPolicy`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy)\n * for possible values.\n *\n * Tile providers might require you to use a specific referrer policy (e.g. to verify\n * API tokens or prevent abuse). Specifically, if you are using tiles from\n * `tile.openstreetmap.org` or `tile.osm.org`, you\n * [should not change this value](https://operations.osmfoundation.org/policies/tiles/).\n * @property {RequestInit|null} [fetchOptions=null] If set, the tiles are loaded with\n * [`fetch()`](https://developer.mozilla.org/docs/Web/API/Window/fetch) using these\n * options (see [`RequestInit`](https://developer.mozilla.org/docs/Web/API/RequestInit)),\n * e.g. `{headers: {Authorization: 'Bearer …'}}` for tile servers requiring custom HTTP\n * headers. Requests of tiles that are no longer needed (e.g. after panning or zooming\n * away) are aborted. Cross-origin tile servers have to allow such requests with\n * [CORS](https://developer.mozilla.org/docs/Web/HTTP/CORS) headers.\n * @extends GridLayerOptions\n */\n\n/**\n * Used to load and display tile layers on the map. Note that most tile servers require\n * attribution, which you can set under `Layer`. Extends `GridLayer`.\n *\n * ### URL template\n *\n * A string of the following form:\n *\n * ```\n * 'https://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png'\n * ```\n *\n * `{s}` means one of the available subdomains (used sequentially to help with browser\n * parallel requests per domain limitation; subdomain values are specified in options;\n * `a`, `b` or `c` by default, can be omitted), `{z}` — zoom level, `{x}` and `{y}` —\n * tile coordinates. `{r}` can be used to add \"@2x\" to the URL to load retina tiles.\n *\n * You can use custom keys in the template, which will be [evaluated](#util-template)\n * from TileLayer options, like this:\n *\n * ```\n * new TileLayer('https://{s}.somedomain.com/{foo}/{z}/{x}/{y}.png', {foo: 'bar'});\n * ```\n *\n * Layers extending `TileLayer` might reimplement the [`getTileUrl()`](#tilelayer-gettileurl)\n * method.\n *\n * @example\n * ```js\n * new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar', attribution: '© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap contributors</a>'}).addTo(map);\n * ```\n *\n * @fires tileabort {TileEvent} Fired when a tile was loading but is now not wanted.\n */\nexport class TileLayer extends GridLayer {\n\n\tstatic defaultOptions = {\n\t\tminZoom: 0,\n\t\tmaxZoom: 18,\n\t\tsubdomains: 'abc',\n\t\terrorTileUrl: '',\n\t\tzoomOffset: 0,\n\t\ttms: false,\n\t\tzoomReverse: false,\n\t\tdetectRetina: false,\n\t\tcrossOrigin: false,\n\t\treferrerPolicy: 'strict-origin-when-cross-origin',\n\t\tfetchOptions: null\n\n\t};\n\n\t/**\n\t * Instantiates a tile layer object given a [URL template](#tilelayer) and optionally an\n\t * options object.\n\t * @param {string} url The URL template.\n\t * @param {TileLayerOptions & Record<string, unknown>} [options] The options, and the values\n\t * of custom keys of the URL template.\n\t */\n\tconstructor(url, options) {\n\t\tsuper(options);\n\n\t\toptions = Util.setOptions(this, options);\n\n\t\t// Set required OpenStreetMap attribution if it hasn't been specified\n\t\tif (isOSMUrl(url) && options.attribution === null) {\n\t\t\toptions.attribution = `© <a href=\"https://www.openstreetmap.org/copyright\">${I18n.translate('OpenStreetMap contributors')}</a>`;\n\t\t}\n\t\tthis._url = upgradeOSMUrl(url);\n\n\t\tconst {tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom} = this.options;\n\t\tthis._nonRetinaOptions = {tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom};\n\t\tthis._applyRetina();\n\n\t\tif (typeof this.options.subdomains === 'string') {\n\t\t\tthis.options.subdomains = this.options.subdomains.split('');\n\t\t}\n\n\t\tthis.callInitHooks(TileLayer);\n\t}\n\n\t// Detects retina displays (if `detectRetina` is set), adjusting tileSize and zoom levels.\n\t_applyRetina() {\n\t\tObject.assign(this.options, this._nonRetinaOptions);\n\t\tthis._retina = window.devicePixelRatio > 1;\n\n\t\tif (this.options.detectRetina && this._retina && this.options.maxZoom > 0) {\n\n\t\t\tconst tileSize = this.options.tileSize;\n\t\t\tthis.options.tileSize = tileSize instanceof Point ? tileSize.divideBy(2).floor() : Math.floor(tileSize / 2);\n\n\t\t\tif (!this.options.zoomReverse) {\n\t\t\t\tthis.options.zoomOffset++;\n\t\t\t\tthis.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);\n\t\t\t\t// do not request tiles beyond the native zoom levels\n\t\t\t\tif (this.options.maxNativeZoom !== undefined) {\n\t\t\t\t\tthis.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);\n\t\t\t\t}\n\t\t\t\tif (this.options.minNativeZoom !== undefined) {\n\t\t\t\t\tthis.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.options.zoomOffset--;\n\t\t\t\tthis.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom + 1);\n\t\t\t}\n\n\t\t\tthis.options.minZoom = Math.max(0, this.options.minZoom);\n\t\t} else if (!this.options.zoomReverse) {\n\t\t\t// make sure maxZoom is gte minZoom\n\t\t\tthis.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom);\n\t\t} else {\n\t\t\t// make sure minZoom is lte maxZoom\n\t\t\tthis.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the layer listens to, see `Layer`.\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\t\tevents.pixelratiochange = this._onPixelRatioChange;\n\t\treturn events;\n\t}\n\n\t// Loads the tiles for the new resolution, see the map's `pixelratiochange` event.\n\t_onPixelRatioChange() {\n\t\tif ((window.devicePixelRatio > 1) === this._retina) { return; }\n\t\tconst map = this._map;\n\t\tthis._applyRetina();\n\t\tif (this.options.detectRetina) {\n\t\t\tmap._removeZoomLimit(this);\n\t\t\tmap._addZoomLimit(this);\n\t\t\tthis._invalidateAll();\n\t\t\tthis._resetView();\n\t\t} else if (this._url.includes('{r}')) {\n\t\t\tthis.redraw();\n\t\t}\n\t}\n\n\t/**\n\t * Updates the layer's URL template and redraws it (unless `noRedraw` is set to `true`).\n\t * If the URL does not change, the layer will not be redrawn unless\n\t * the noRedraw parameter is set to false.\n\t * The current tiles stay visible until the new tiles have loaded, to avoid flickering.\n\t * @param {string} url\n\t * @param {boolean} [noRedraw]\n\t * @returns {this}\n\t */\n\tsetUrl(url, noRedraw) {\n\t\turl = upgradeOSMUrl(url);\n\n\t\tif (this._url === url && noRedraw === undefined) {\n\t\t\tnoRedraw = true;\n\t\t}\n\n\t\tthis._url = url;\n\n\t\tif (!noRedraw) {\n\t\t\tthis._keepCurrentTiles();\n\t\t\tthis.redraw();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Called only internally, overrides GridLayer's [`createTile()`](#gridlayer-createtile)\n\t * to return an `<img>` HTML element with the appropriate image URL given `coords`. The\n\t * `done` callback is called when the tile has been loaded.\n\t * @param {Point} coords\n\t * @param {TileDoneCallback} [done]\n\t * @returns {HTMLImageElement}\n\t */\n\tcreateTile(coords, done) {\n\t\tconst tile = document.createElement('img');\n\n\t\tDomEvent.on(tile, 'load', this._tileOnLoad.bind(this, done, tile));\n\t\tDomEvent.on(tile, 'error', this._tileOnError.bind(this, done, tile));\n\n\t\tif (this.options.crossOrigin || this.options.crossOrigin === '') {\n\t\t\ttile.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;\n\t\t}\n\n\t\t// for this new option we follow the documented behavior\n\t\t// more closely by only setting the property when string\n\t\tif (typeof this.options.referrerPolicy === 'string') {\n\t\t\ttile.referrerPolicy = this.options.referrerPolicy;\n\t\t}\n\n\t\t// The alt attribute is set to the empty string,\n\t\t// allowing screen readers to ignore the decorative image tiles.\n\t\t// https://www.w3.org/WAI/tutorials/images/decorative/\n\t\t// https://www.w3.org/TR/html-aria/#el-img-empty-alt\n\t\ttile.alt = '';\n\n\t\tconst url = this.getTileUrl(coords);\n\t\tif (this.options.fetchOptions) {\n\t\t\tthis._fetchTile(tile, url, done);\n\t\t} else {\n\t\t\ttile.src = url;\n\t\t}\n\n\t\treturn tile;\n\t}\n\n\t// Loads the tile image with `fetch()`, see the `fetchOptions` option.\n\t_fetchTile(tile, url, done) {\n\t\tconst controller = new AbortController(),\n\t\toptions = {signal: controller.signal, ...this.options.fetchOptions};\n\t\tif (typeof this.options.referrerPolicy === 'string') {\n\t\t\toptions.referrerPolicy ??= this.options.referrerPolicy;\n\t\t}\n\n\t\tthis._tileFetches ??= new Map();\n\t\tthis._tileFetches.set(tile, controller);\n\n\t\tfetch(url, options)\n\t\t\t.then((response) => {\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(`Failed to load the tile ${url}: HTTP ${response.status}`);\n\t\t\t\t}\n\t\t\t\treturn response.blob();\n\t\t\t})\n\t\t\t.then((blob) => {\n\t\t\t\t// revoked in `_tileOnLoad()`\n\t\t\t\ttile.src = URL.createObjectURL(blob);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tif (!controller.signal.aborted) {\n\t\t\t\t\tthis._tileOnError(done, tile, error);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => this._tileFetches.delete(tile));\n\t}\n\n\t// Aborts the request of a tile loaded with `fetch()`, returns whether there was one.\n\t_abortTileFetch(tile) {\n\t\tconst controller = this._tileFetches?.get(tile);\n\t\tif (!controller) { return false; }\n\t\tcontroller.abort();\n\t\tthis._tileFetches.delete(tile);\n\t\treturn true;\n\t}\n\n\t/**\n\t * Called only internally, returns the URL for a tile given its coordinates.\n\t * Classes extending `TileLayer` can override this function to provide custom tile URL\n\t * naming schemes.\n\t * @group Extension methods\n\t * @param {Point} coords\n\t * @returns {string}\n\t */\n\tgetTileUrl(coords) {\n\t\tconst data = Object.create(this.options);\n\t\tObject.assign(data, {\n\t\t\tr: window.devicePixelRatio > 1 ? '@2x' : '',\n\t\t\ts: this._getSubdomain(coords),\n\t\t\tx: coords.x,\n\t\t\ty: coords.y,\n\t\t\tz: this._getZoomForUrl()\n\t\t});\n\t\tif (this._map && !this._map.options.crs.infinite) {\n\t\t\tconst invertedY = this._globalTileRange.max.y - coords.y;\n\t\t\tif (this.options.tms) {\n\t\t\t\tdata['y'] = invertedY;\n\t\t\t}\n\t\t\tdata['-y'] = invertedY;\n\t\t}\n\n\t\treturn Util.template(this._url, data);\n\t}\n\n\t_tileOnLoad(done, tile) {\n\t\tif (tile.src.startsWith('blob:')) {\n\t\t\t// the image keeps its data, see `_fetchTile()`\n\t\t\tURL.revokeObjectURL(tile.src);\n\t\t}\n\t\tdone(null, tile);\n\t}\n\n\t_tileOnError(done, tile, e) {\n\t\tconst errorUrl = this.options.errorTileUrl,\n\t\tsrc = tile.getAttribute('src');\n\t\t// removed tiles get an empty src to cancel their request, which fires error too\n\t\tif (errorUrl && src !== errorUrl && (src || tile.isConnected)) {\n\t\t\ttile.src = errorUrl;\n\t\t}\n\t\tdone(e, tile);\n\t}\n\n\t_getZoomForUrl() {\n\t\tlet zoom = this._tileZoom;\n\t\tconst maxZoom = this.options.maxZoom,\n\t\tzoomReverse = this.options.zoomReverse,\n\t\tzoomOffset = this.options.zoomOffset;\n\n\t\tif (zoomReverse) {\n\t\t\tzoom = maxZoom - zoom;\n\t\t}\n\n\t\treturn zoom + zoomOffset;\n\t}\n\n\t_getSubdomain(tilePoint) {\n\t\tconst {subdomains} = this.options;\n\t\treturn subdomains?.[Math.abs(tilePoint.x + tilePoint.y) % subdomains.length];\n\t}\n\n\t// stops loading all tiles in the background layer\n\t_abortLoading() {\n\t\tlet i, tile;\n\t\tfor (i of Object.keys(this._tiles)) {\n\t\t\tif (this._tiles[i].coords.z !== this._tileZoom) {\n\t\t\t\ttile = this._tiles[i].el;\n\n\t\t\t\tif (this._abortTileFetch(tile) || !tile.complete) {\n\t\t\t\t\ttile.setAttribute('src', '');\n\t\t\t\t\tconst coords = this._tiles[i].coords;\n\t\t\t\t\ttile.remove();\n\t\t\t\t\tdelete this._tiles[i];\n\t\t\t\t\tthis.fire('tileabort', {\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\tcoords\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t_removeTile(key) {\n\t\tconst tile = this._tiles[key];\n\t\tif (!tile) { return; }\n\n\t\t// Cancels any pending http requests associated with the tile\n\t\tthis._abortTileFetch(tile.el);\n\t\ttile.el.setAttribute('src', '');\n\n\t\treturn super._removeTile(key);\n\t}\n\n\t_tileReady(coords, err, tile) {\n\t\tif (!this._map || (tile && tile.getAttribute('src') === '')) {\n\t\t\treturn;\n\t\t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setOptions","Util.template"],"sources":["../../../../src/layer/tile/TileLayer.js"],"sourcesContent":["import {GridLayer} from './GridLayer.js';\nimport * as Util from '../../core/Util.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport {I18n} from '../../core/I18n.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {GridLayerOptions, TileDoneCallback} from './GridLayer.js' */\n/** @import {TileEvent} from '../../core/Events.js' */\n\nconst osmHosts = ['tile.openstreetmap.org', 'tile.osm.org'];\nconst hostRe = /^(https?:)?\\/\\/([^/?#:]*)/i;\nconst httpRe = /^http:/i;\n\nfunction isOSMUrl(url) {\n\tconst host = hostRe.exec(url)?.[2] ?? '';\n\treturn osmHosts.some(osmHost => host === osmHost || host.endsWith(`.${osmHost}`));\n}\n\n// OSM tiles are upgraded to HTTPS so that the referrer policy works\nconst upgradeOSMUrl = url => (isOSMUrl(url) ? url.replace(httpRe, 'https:') : url);\n\n/**\n * Options of `TileLayer`.\n * @typedef {object} TileLayerOptions\n * @property {number} [minZoom=0] The minimum zoom level down to which this layer will be\n * displayed (inclusive).\n * @property {number} [maxZoom=18] The maximum zoom level up to which this layer will be\n * displayed (inclusive).\n * @property {string|string[]} [subdomains='abc'] Subdomains of the tile service. Can be\n * passed in the form of one string (where each letter is a subdomain name) or an array\n * of strings.\n * @property {string} [errorTileUrl=''] URL to the tile image to show in place of the\n * tile that failed to load.\n * @property {number} [zoomOffset=0] The zoom number used in tile URLs will be offset\n * with this value.\n * @property {boolean} [tms=false] If `true`, inverses Y axis numbering for tiles (turn\n * this on for [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) services).\n * @property {boolean} [zoomReverse=false] If set to true, the zoom number used in tile\n * URLs will be reversed (`maxZoom - zoom` instead of `zoom`).\n * @property {boolean} [detectRetina=false] If `true` and user is on a retina display, it\n * will request four tiles of half the specified size and a bigger zoom level in place\n * of one to utilize the high resolution.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute will\n * be added to the tiles. If a String is provided, all tiles will have their crossOrigin\n * attribute set to the String provided. This is needed if you want to access tile pixel\n * data. Refer to\n * [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)\n * for valid String values.\n * @property {ReferrerPolicy} [referrerPolicy='strict-origin-when-cross-origin'] Sets the\n * tiles' `referrerPolicy` attribute set to the String provided. See\n * [`HTMLImageElement.referrerPolicy`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy)\n * for possible values.\n *\n * Tile providers might require you to use a specific referrer policy (e.g. to verify\n * API tokens or prevent abuse). Specifically, if you are using tiles from\n * `tile.openstreetmap.org` or `tile.osm.org`, you\n * [should not change this value](https://operations.osmfoundation.org/policies/tiles/).\n * @property {RequestInit|null} [fetchOptions=null] If set, the tiles are loaded with\n * [`fetch()`](https://developer.mozilla.org/docs/Web/API/Window/fetch) using these\n * options (see [`RequestInit`](https://developer.mozilla.org/docs/Web/API/RequestInit)),\n * e.g. `{headers: {Authorization: 'Bearer …'}}` for tile servers requiring custom HTTP\n * headers. Requests of tiles that are no longer needed (e.g. after panning or zooming\n * away) are aborted. Cross-origin tile servers have to allow such requests with\n * [CORS](https://developer.mozilla.org/docs/Web/HTTP/CORS) headers.\n * @extends GridLayerOptions\n */\n\n/**\n * Used to load and display tile layers on the map. Note that most tile servers require\n * attribution, which you can set under `Layer`. Extends `GridLayer`.\n *\n * ### URL template\n *\n * A string of the following form:\n *\n * ```\n * 'https://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png'\n * ```\n *\n * `{s}` means one of the available subdomains (used sequentially to help with browser\n * parallel requests per domain limitation; subdomain values are specified in options;\n * `a`, `b` or `c` by default, can be omitted), `{z}` — zoom level, `{x}` and `{y}` —\n * tile coordinates. `{r}` can be used to add \"@2x\" to the URL to load retina tiles.\n *\n * You can use custom keys in the template, which will be [evaluated](#util-template)\n * from TileLayer options, like this:\n *\n * ```\n * new TileLayer('https://{s}.somedomain.com/{foo}/{z}/{x}/{y}.png', {foo: 'bar'});\n * ```\n *\n * Layers extending `TileLayer` might reimplement the [`getTileUrl()`](#tilelayer-gettileurl)\n * method.\n *\n * @example\n * ```js\n * new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar', attribution: '© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap contributors</a>'}).addTo(map);\n * ```\n *\n * @fires tileabort {TileEvent} Fired when a tile was loading but is now not wanted.\n */\nexport class TileLayer extends GridLayer {\n\n\tstatic defaultOptions = {\n\t\tminZoom: 0,\n\t\tmaxZoom: 18,\n\t\tsubdomains: 'abc',\n\t\terrorTileUrl: '',\n\t\tzoomOffset: 0,\n\t\ttms: false,\n\t\tzoomReverse: false,\n\t\tdetectRetina: false,\n\t\tcrossOrigin: false,\n\t\treferrerPolicy: 'strict-origin-when-cross-origin',\n\t\tfetchOptions: null\n\n\t};\n\n\t/**\n\t * Instantiates a tile layer object given a [URL template](#tilelayer) and optionally an\n\t * options object.\n\t * @param {string} url The URL template.\n\t * @param {TileLayerOptions & Record<string, unknown>} [options] The options, and the values\n\t * of custom keys of the URL template.\n\t */\n\tconstructor(url, options) {\n\t\tsuper(options);\n\n\t\toptions = Util.setOptions(this, options);\n\n\t\t// Set required OpenStreetMap attribution if it hasn't been specified\n\t\tif (isOSMUrl(url) && options.attribution === null) {\n\t\t\toptions.attribution = `© <a href=\"https://www.openstreetmap.org/copyright\">${I18n.translate('OpenStreetMap contributors')}</a>`;\n\t\t}\n\t\tthis._url = upgradeOSMUrl(url);\n\n\t\tconst {tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom} = this.options;\n\t\tthis._nonRetinaOptions = {tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom};\n\t\tthis._applyRetina();\n\n\t\tif (typeof this.options.subdomains === 'string') {\n\t\t\tthis.options.subdomains = this.options.subdomains.split('');\n\t\t}\n\n\t\tthis.callInitHooks(TileLayer);\n\t}\n\n\t// Detects retina displays (if `detectRetina` is set), adjusting tileSize and zoom levels.\n\t_applyRetina() {\n\t\tObject.assign(this.options, this._nonRetinaOptions);\n\t\tthis._retina = window.devicePixelRatio > 1;\n\n\t\tif (this.options.detectRetina && this._retina && this.options.maxZoom > 0) {\n\n\t\t\tconst tileSize = this.options.tileSize;\n\t\t\tthis.options.tileSize = tileSize instanceof Point ? tileSize.divideBy(2).floor() : Math.floor(tileSize / 2);\n\n\t\t\tif (!this.options.zoomReverse) {\n\t\t\t\tthis.options.zoomOffset++;\n\t\t\t\tthis.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);\n\t\t\t} else {\n\t\t\t\tthis.options.zoomOffset--;\n\t\t\t\tthis.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom + 1);\n\t\t\t}\n\n\t\t\tthis.options.minZoom = Math.max(0, this.options.minZoom);\n\n\t\t\t// either way, the tile at zoom z is now the server's z + 1 tile, so native zooms shift down by one, so\n\t\t\t// that no tiles beyond the native zoom levels are requested\n\t\t\tif (this.options.maxNativeZoom !== undefined) {\n\t\t\t\tthis.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);\n\t\t\t}\n\t\t\tif (this.options.minNativeZoom !== undefined) {\n\t\t\t\tthis.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);\n\t\t\t}\n\t\t} else if (!this.options.zoomReverse) {\n\t\t\t// make sure maxZoom is gte minZoom\n\t\t\tthis.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom);\n\t\t} else {\n\t\t\t// make sure minZoom is lte maxZoom\n\t\t\tthis.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the layer listens to, see `Layer`.\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\t\tevents.pixelratiochange = this._onPixelRatioChange;\n\t\treturn events;\n\t}\n\n\t// Loads the tiles for the new resolution, see the map's `pixelratiochange` event.\n\t_onPixelRatioChange() {\n\t\tif ((window.devicePixelRatio > 1) === this._retina) { return; }\n\t\tconst map = this._map;\n\t\tthis._applyRetina();\n\t\tif (this.options.detectRetina) {\n\t\t\tmap._removeZoomLimit(this);\n\t\t\tmap._addZoomLimit(this);\n\t\t\tthis._invalidateAll();\n\t\t\tthis._resetView();\n\t\t} else if (this._url.includes('{r}')) {\n\t\t\tthis.redraw();\n\t\t}\n\t}\n\n\t/**\n\t * Updates the layer's URL template and redraws it (unless `noRedraw` is set to `true`).\n\t * If the URL does not change, the layer will not be redrawn unless\n\t * the noRedraw parameter is set to false.\n\t * The current tiles stay visible until the new tiles have loaded, to avoid flickering.\n\t * @param {string} url\n\t * @param {boolean} [noRedraw]\n\t * @returns {this}\n\t */\n\tsetUrl(url, noRedraw) {\n\t\turl = upgradeOSMUrl(url);\n\n\t\tif (this._url === url && noRedraw === undefined) {\n\t\t\tnoRedraw = true;\n\t\t}\n\n\t\tthis._url = url;\n\n\t\tif (!noRedraw) {\n\t\t\tthis._keepCurrentTiles();\n\t\t\tthis.redraw();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Called only internally, overrides GridLayer's [`createTile()`](#gridlayer-createtile)\n\t * to return an `<img>` HTML element with the appropriate image URL given `coords`. The\n\t * `done` callback is called when the tile has been loaded.\n\t * @param {Point} coords\n\t * @param {TileDoneCallback} [done]\n\t * @returns {HTMLImageElement}\n\t */\n\tcreateTile(coords, done) {\n\t\tconst tile = document.createElement('img');\n\n\t\tDomEvent.on(tile, 'load', this._tileOnLoad.bind(this, done, tile));\n\t\tDomEvent.on(tile, 'error', this._tileOnError.bind(this, done, tile));\n\n\t\tif (this.options.crossOrigin || this.options.crossOrigin === '') {\n\t\t\ttile.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;\n\t\t}\n\n\t\t// for this new option we follow the documented behavior\n\t\t// more closely by only setting the property when string\n\t\tif (typeof this.options.referrerPolicy === 'string') {\n\t\t\ttile.referrerPolicy = this.options.referrerPolicy;\n\t\t}\n\n\t\t// The alt attribute is set to the empty string,\n\t\t// allowing screen readers to ignore the decorative image tiles.\n\t\t// https://www.w3.org/WAI/tutorials/images/decorative/\n\t\t// https://www.w3.org/TR/html-aria/#el-img-empty-alt\n\t\ttile.alt = '';\n\n\t\tconst url = this.getTileUrl(coords);\n\t\tif (this.options.fetchOptions) {\n\t\t\tthis._fetchTile(tile, url, done);\n\t\t} else {\n\t\t\ttile.src = url;\n\t\t}\n\n\t\treturn tile;\n\t}\n\n\t// Loads the tile image with `fetch()`, see the `fetchOptions` option.\n\t_fetchTile(tile, url, done) {\n\t\tconst controller = new AbortController(),\n\t\toptions = {signal: controller.signal, ...this.options.fetchOptions};\n\t\tif (typeof this.options.referrerPolicy === 'string') {\n\t\t\toptions.referrerPolicy ??= this.options.referrerPolicy;\n\t\t}\n\n\t\tthis._tileFetches ??= new Map();\n\t\tthis._tileFetches.set(tile, controller);\n\n\t\tfetch(url, options)\n\t\t\t.then((response) => {\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(`Failed to load the tile ${url}: HTTP ${response.status}`);\n\t\t\t\t}\n\t\t\t\treturn response.blob();\n\t\t\t})\n\t\t\t.then((blob) => {\n\t\t\t\t// revoked in `_tileOnLoad()`\n\t\t\t\ttile.src = URL.createObjectURL(blob);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tif (!controller.signal.aborted) {\n\t\t\t\t\tthis._tileOnError(done, tile, error);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => this._tileFetches.delete(tile));\n\t}\n\n\t// Aborts the request of a tile loaded with `fetch()`, returns whether there was one.\n\t_abortTileFetch(tile) {\n\t\tconst controller = this._tileFetches?.get(tile);\n\t\tif (!controller) { return false; }\n\t\tcontroller.abort();\n\t\tthis._tileFetches.delete(tile);\n\t\treturn true;\n\t}\n\n\t/**\n\t * Called only internally, returns the URL for a tile given its coordinates.\n\t * Classes extending `TileLayer` can override this function to provide custom tile URL\n\t * naming schemes.\n\t * @group Extension methods\n\t * @param {Point} coords\n\t * @returns {string}\n\t */\n\tgetTileUrl(coords) {\n\t\tconst z = coords.z ?? this._tileZoom,\n\t\tdata = Object.create(this.options);\n\t\tObject.assign(data, {\n\t\t\tr: window.devicePixelRatio > 1 ? '@2x' : '',\n\t\t\ts: this._getSubdomain(coords),\n\t\t\tx: coords.x,\n\t\t\ty: coords.y,\n\t\t\tz: this._getZoomForUrl(z)\n\t\t});\n\t\tconst worldBounds = this._map?.getPixelWorldBounds(z);\n\t\tif (worldBounds) {\n\t\t\tconst invertedY = this._pxBoundsToTileRange(worldBounds).max.y - coords.y;\n\t\t\tif (this.options.tms) {\n\t\t\t\tdata['y'] = invertedY;\n\t\t\t}\n\t\t\tdata['-y'] = invertedY;\n\t\t}\n\n\t\treturn Util.template(this._url, data);\n\t}\n\n\t_tileOnLoad(done, tile) {\n\t\tif (tile.src.startsWith('blob:')) {\n\t\t\t// the image keeps its data, see `_fetchTile()`\n\t\t\tURL.revokeObjectURL(tile.src);\n\t\t}\n\t\tdone(null, tile);\n\t}\n\n\t_tileOnError(done, tile, e) {\n\t\tconst errorUrl = this.options.errorTileUrl,\n\t\tsrc = tile.getAttribute('src');\n\t\t// removed tiles get an empty src to cancel their request, which fires error too\n\t\tif (errorUrl && src !== errorUrl && (src || tile.isConnected)) {\n\t\t\ttile.src = errorUrl;\n\t\t}\n\t\tdone(e, tile);\n\t}\n\n\t_getZoomForUrl(zoom) {\n\t\tconst maxZoom = this.options.maxZoom,\n\t\tzoomReverse = this.options.zoomReverse,\n\t\tzoomOffset = this.options.zoomOffset;\n\n\t\tif (zoomReverse) {\n\t\t\tzoom = maxZoom - zoom;\n\t\t}\n\n\t\treturn zoom + zoomOffset;\n\t}\n\n\t_getSubdomain(tilePoint) {\n\t\tconst {subdomains} = this.options;\n\t\treturn subdomains?.[Math.abs(tilePoint.x + tilePoint.y) % subdomains.length];\n\t}\n\n\t// stops loading all tiles in the background layer\n\t_abortLoading() {\n\t\tlet i, tile;\n\t\tfor (i of Object.keys(this._tiles)) {\n\t\t\tif (this._tiles[i].coords.z !== this._tileZoom) {\n\t\t\t\ttile = this._tiles[i].el;\n\n\t\t\t\tif (this._abortTileFetch(tile) || !tile.complete) {\n\t\t\t\t\ttile.setAttribute('src', '');\n\t\t\t\t\tconst coords = this._tiles[i].coords;\n\t\t\t\t\ttile.remove();\n\t\t\t\t\tdelete this._tiles[i];\n\t\t\t\t\tthis.fire('tileabort', {\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\tcoords\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t_removeTile(key) {\n\t\tconst tile = this._tiles[key];\n\t\tif (!tile) { return; }\n\n\t\t// Cancels any pending http requests associated with the tile\n\t\tthis._abortTileFetch(tile.el);\n\t\ttile.el.setAttribute('src', '');\n\n\t\treturn super._removeTile(key);\n\t}\n\n\t_tileReady(coords, err, tile) {\n\t\tif (!this._map || tile?.getAttribute('src') === '') {\n\t\t\treturn;\n\t\t}\n\n\t\treturn super._tileReady(coords, err, tile);\n\t}\n\n\t_clampZoom(zoom) {\n\t\treturn Math.round(super._clampZoom(zoom));\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,WAAW,CAAC,0BAA0B,cAAc;AAC1D,MAAM,SAAS;AACf,MAAM,SAAS;AAEf,SAAS,SAAS,KAAK;CACtB,MAAM,OAAO,OAAO,KAAK,GAAG,CAAC,GAAG,MAAM;CACtC,OAAO,SAAS,MAAK,YAAW,SAAS,WAAW,KAAK,SAAS,IAAI,SAAS,CAAC;AACjF;AAGA,MAAM,iBAAgB,QAAQ,SAAS,GAAG,IAAI,IAAI,QAAQ,QAAQ,QAAQ,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkF9E,IAAa,YAAb,MAAa,kBAAkB,UAAU;CAExC,OAAO,iBAAiB;EACvB,SAAS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K,gBAAgB,IAAI,KAAK,CAAC,KAAK,UAAU;IACjD,KAAK,aAAa,OAAO,EAAE;IAC3B,MAAM,SAAS,KAAK,OAAO,EAAE,CAAC;IAC9B,KAAK,OAAO;IACZ,OAAO,KAAK,OAAO;IACnB,KAAK,KAAK,aAAa;KACtB;KACA;IACD,CAAC;GACF;EACD;CAEF;CAEA,YAAY,KAAK;EAChB,MAAM,OAAO,KAAK,OAAO;EACzB,IAAI,CAAC,MAAQ;EAGb,KAAK,gBAAgB,KAAK,EAAE;EAC5B,KAAK,GAAG,aAAa,OAAO,EAAE;EAE9B,OAAO,MAAM,YAAY,GAAG;CAC7B;CAEA,WAAW,QAAQ,KAAK,MAAM;EAC7B,IAAI,CAAC,KAAK,QAAQ,MAAM,aAAa,KAAK,MAAM,IAC/C;EAGD,OAAO,MAAM,WAAW,QAAQ,KAAK,IAAI;CAC1C;CAEA,WAAW,MAAM;EAChB,OAAO,KAAK,MAAM,MAAM,WAAW,IAAI,CAAC;CACzC;AACD"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { stamp } from "../../core/Util.js";
|
|
2
|
-
import { on } from "../../dom/DomEvent.js";
|
|
3
2
|
import { Bounds } from "../../geometry/Bounds.js";
|
|
4
3
|
import { Renderer } from "./Renderer.js";
|
|
5
4
|
// src/layer/vector/Canvas.js
|
|
@@ -73,22 +72,21 @@ var Canvas = class Canvas extends Renderer {
|
|
|
73
72
|
*/
|
|
74
73
|
onAdd(map) {
|
|
75
74
|
super.onAdd(map);
|
|
75
|
+
const z = (r) => +getComputedStyle(r._container.parentNode).zIndex || 0;
|
|
76
|
+
map._canvases.push(this);
|
|
77
|
+
map._canvases.sort((a, b) => z(b) - z(a) || (a._container.compareDocumentPosition(b._container) & 2) - 1);
|
|
76
78
|
this._draw();
|
|
77
79
|
}
|
|
80
|
+
_initContainer() {
|
|
81
|
+
const container = this._container = document.createElement("canvas");
|
|
82
|
+
this._ctx = container.getContext("2d");
|
|
83
|
+
}
|
|
78
84
|
/**
|
|
79
85
|
* Removes the canvas from the map.
|
|
80
86
|
*/
|
|
81
87
|
onRemove() {
|
|
88
|
+
this._map._canvases = this._map._canvases.filter((r) => r !== this);
|
|
82
89
|
super.onRemove();
|
|
83
|
-
clearTimeout(this._pointerHoverThrottleTimeout);
|
|
84
|
-
}
|
|
85
|
-
_initContainer() {
|
|
86
|
-
const container = this._container = document.createElement("canvas");
|
|
87
|
-
on(container, "pointermove", this._onPointerMove, this);
|
|
88
|
-
on(container, "click dblclick pointerdown pointerup contextmenu", this._onClick, this);
|
|
89
|
-
on(container, "pointerout", this._handlePointerOut, this);
|
|
90
|
-
container["_maplair_disable_events"] = true;
|
|
91
|
-
this._ctx = container.getContext("2d");
|
|
92
90
|
}
|
|
93
91
|
_destroyContainer() {
|
|
94
92
|
cancelAnimationFrame(this._redrawRequest);
|
|
@@ -124,26 +122,13 @@ var Canvas = class Canvas extends Renderer {
|
|
|
124
122
|
_initPath(layer) {
|
|
125
123
|
this._updateDashArray(layer);
|
|
126
124
|
this._layers[stamp(layer)] = layer;
|
|
127
|
-
|
|
128
|
-
layer,
|
|
129
|
-
prev: this._drawLast,
|
|
130
|
-
next: null
|
|
131
|
-
};
|
|
132
|
-
if (this._drawLast) this._drawLast.next = order;
|
|
133
|
-
this._drawLast = order;
|
|
134
|
-
this._drawFirst ??= this._drawLast;
|
|
125
|
+
this._append(layer._order = { layer });
|
|
135
126
|
}
|
|
136
127
|
_addPath(layer) {
|
|
137
128
|
this._requestRedraw(layer);
|
|
138
129
|
}
|
|
139
130
|
_removePath(layer) {
|
|
140
|
-
|
|
141
|
-
const next = order.next;
|
|
142
|
-
const prev = order.prev;
|
|
143
|
-
if (next) next.prev = prev;
|
|
144
|
-
else this._drawLast = prev;
|
|
145
|
-
if (prev) prev.next = next;
|
|
146
|
-
else this._drawFirst = next;
|
|
131
|
+
this._unlink(layer._order);
|
|
147
132
|
delete layer._order;
|
|
148
133
|
delete this._layers[stamp(layer)];
|
|
149
134
|
this._requestRedraw(layer);
|
|
@@ -169,7 +154,7 @@ var Canvas = class Canvas extends Renderer {
|
|
|
169
154
|
}
|
|
170
155
|
_extendRedrawBounds(layer) {
|
|
171
156
|
if (layer._pxBounds) {
|
|
172
|
-
const padding = (layer.options.weight
|
|
157
|
+
const padding = (+layer.options.weight || 0) + 1;
|
|
173
158
|
this._redrawBounds ??= new Bounds();
|
|
174
159
|
this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));
|
|
175
160
|
this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));
|
|
@@ -211,7 +196,7 @@ var Canvas = class Canvas extends Renderer {
|
|
|
211
196
|
this._drawing = true;
|
|
212
197
|
for (let order = this._drawFirst; order; order = order.next) {
|
|
213
198
|
layer = order.layer;
|
|
214
|
-
if (!bounds || layer._pxBounds
|
|
199
|
+
if (!bounds || layer._pxBounds?.intersects(bounds)) layer._updatePath();
|
|
215
200
|
}
|
|
216
201
|
this._drawing = false;
|
|
217
202
|
this._ctx.restore();
|
|
@@ -256,84 +241,50 @@ var Canvas = class Canvas extends Renderer {
|
|
|
256
241
|
}
|
|
257
242
|
}
|
|
258
243
|
_updateInteractive() {}
|
|
259
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Returns the topmost interactive layer under the pointer.
|
|
246
|
+
* @param {MouseEvent} e
|
|
247
|
+
* @param {boolean} [click] Skip layers that were just dragged, so the drag doesn't end with a click.
|
|
248
|
+
* @returns {Path|undefined}
|
|
249
|
+
*/
|
|
250
|
+
_layerAt(e, click) {
|
|
260
251
|
const point = this._map.pointerEventToLayerPoint(e);
|
|
261
|
-
let
|
|
262
|
-
|
|
263
|
-
layer
|
|
264
|
-
if (layer.options.interactive && layer._containsPoint(point)) {
|
|
265
|
-
if (!(e.type === "click" || e.type === "preclick") || !this._map._draggableMoved(layer)) clickedLayer = layer;
|
|
266
|
-
}
|
|
252
|
+
for (let order = this._drawLast; order; order = order.prev) {
|
|
253
|
+
const layer = order.layer;
|
|
254
|
+
if (layer.options.interactive && layer._containsPoint(point) && !(click && this._map._draggableMoved(layer))) return layer;
|
|
267
255
|
}
|
|
268
|
-
this._fireEvent(clickedLayer ? [clickedLayer] : false, e);
|
|
269
|
-
}
|
|
270
|
-
_onPointerMove(e) {
|
|
271
|
-
if (!this._map || this._map.dragging.moving() || this._map._animatingZoom) return;
|
|
272
|
-
const point = this._map.pointerEventToLayerPoint(e);
|
|
273
|
-
this._handlePointerHover(e, point);
|
|
274
256
|
}
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
if (
|
|
278
|
-
this.
|
|
279
|
-
this.
|
|
280
|
-
this.
|
|
281
|
-
this._pointerHoverThrottled = false;
|
|
257
|
+
_bringToFront(layer) {
|
|
258
|
+
const order = layer._order;
|
|
259
|
+
if (order?.next) {
|
|
260
|
+
this._unlink(order);
|
|
261
|
+
this._append(order);
|
|
262
|
+
this._requestRedraw(layer);
|
|
282
263
|
}
|
|
283
264
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
this.
|
|
293
|
-
if (candidateHoveredLayer) {
|
|
294
|
-
this._container.classList.add("maplair-interactive");
|
|
295
|
-
this._fireEvent([candidateHoveredLayer], e, "pointerover");
|
|
296
|
-
this._hoveredLayer = candidateHoveredLayer;
|
|
297
|
-
}
|
|
265
|
+
_bringToBack(layer) {
|
|
266
|
+
const order = layer._order;
|
|
267
|
+
if (order?.prev) {
|
|
268
|
+
this._unlink(order);
|
|
269
|
+
order.prev = null;
|
|
270
|
+
order.next = this._drawFirst;
|
|
271
|
+
this._drawFirst.prev = order;
|
|
272
|
+
this._drawFirst = order;
|
|
273
|
+
this._requestRedraw(layer);
|
|
298
274
|
}
|
|
299
|
-
this._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);
|
|
300
|
-
this._pointerHoverThrottled = true;
|
|
301
|
-
this._pointerHoverThrottleTimeout = setTimeout((() => {
|
|
302
|
-
this._pointerHoverThrottled = false;
|
|
303
|
-
}), 32);
|
|
304
|
-
}
|
|
305
|
-
_fireEvent(layers, e, type) {
|
|
306
|
-
this._map._fireDOMEvent(e, type || e.type, layers);
|
|
307
275
|
}
|
|
308
|
-
|
|
309
|
-
const order = layer._order;
|
|
310
|
-
if (!order) return;
|
|
311
|
-
const next = order.next;
|
|
312
|
-
const prev = order.prev;
|
|
313
|
-
if (next) next.prev = prev;
|
|
314
|
-
else return;
|
|
315
|
-
if (prev) prev.next = next;
|
|
316
|
-
else if (next) this._drawFirst = next;
|
|
276
|
+
_append(order) {
|
|
317
277
|
order.prev = this._drawLast;
|
|
318
|
-
this._drawLast.next = order;
|
|
319
278
|
order.next = null;
|
|
279
|
+
if (this._drawLast) this._drawLast.next = order;
|
|
320
280
|
this._drawLast = order;
|
|
321
|
-
this.
|
|
281
|
+
this._drawFirst ??= order;
|
|
322
282
|
}
|
|
323
|
-
|
|
324
|
-
const order = layer._order;
|
|
325
|
-
if (!order) return;
|
|
326
|
-
const next = order.next;
|
|
327
|
-
const prev = order.prev;
|
|
328
|
-
if (prev) prev.next = next;
|
|
329
|
-
else return;
|
|
283
|
+
_unlink({ prev, next }) {
|
|
330
284
|
if (next) next.prev = prev;
|
|
331
|
-
else
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
this._drawFirst.prev = order;
|
|
335
|
-
this._drawFirst = order;
|
|
336
|
-
this._requestRedraw(layer);
|
|
285
|
+
else this._drawLast = prev;
|
|
286
|
+
if (prev) prev.next = next;
|
|
287
|
+
else this._drawFirst = next;
|
|
337
288
|
}
|
|
338
289
|
};
|
|
339
290
|
export { Canvas };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canvas.js","names":["Util.stamp"],"sources":["../../../../src/layer/vector/Canvas.js"],"sourcesContent":["import {Renderer} from './Renderer.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as Util from '../../core/Util.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {EventListener} from '../../core/Events.js' */\n/** @import {RendererOptions} from './Renderer.js' */\n\nconst DASH_SEPARATOR_RE = /[, ]+/;\n\n/**\n * Options of `Canvas`.\n * @typedef {object} CanvasOptions\n * @property {number} [tolerance=0] How much to extend the click tolerance around a\n * path/object on the map.\n * @extends RendererOptions\n */\n\n/**\n * Allows vector layers to be displayed with [`<canvas>`](https://developer.mozilla.org/docs/Web/API/Canvas_API).\n * Inherits `Renderer`.\n *\n * @example\n * Use Canvas by default for all paths in the map:\n *\n * ```js\n * const map = new MaplairMap('map', {\n * \trenderer: new Canvas()\n * });\n * ```\n *\n * Use a Canvas renderer with extra padding for specific vector geometries:\n *\n * ```js\n * const map = new MaplairMap('map');\n * const myRenderer = new Canvas({ padding: 0.5 });\n * const line = new Polyline( coordinates, { renderer: myRenderer } );\n * const circle = new Circle( center, { renderer: myRenderer, radius: 100 } );\n * ```\n */\nexport class Canvas extends Renderer {\n\n\tstatic defaultOptions = {\n\t\ttolerance: 0\n\t};\n\n\t/**\n\t * Creates a Canvas renderer with the given options.\n\t * @overload\n\t * @param {CanvasOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Canvas);\n\t}\n\n\t/**\n\t * Returns the map events the renderer listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\t\tevents.viewprereset = this._onViewPreReset;\n\t\tevents.pixelratiochange = this._onPixelRatioChange;\n\t\treturn events;\n\t}\n\n\t// Redraws with the resolution of the new `devicePixelRatio`.\n\t_onPixelRatioChange() {\n\t\tthis._resizeContainer();\n\t\tthis._update();\n\t}\n\n\t_onViewPreReset() {\n\t\t// Set a flag so that a viewprereset+moveend+viewreset only updates&redraws once\n\t\tthis._postponeUpdatePaths = true;\n\t}\n\n\t/**\n\t * Adds the canvas to the map and draws the paths.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tsuper.onAdd(map);\n\n\t\t// Redraw vectors since canvas is cleared upon removal,\n\t\t// in case of removing the renderer itself from the map.\n\t\tthis._draw();\n\t}\n\n\t/**\n\t * Removes the canvas from the map.\n\t */\n\tonRemove() {\n\t\tsuper.onRemove();\n\n\t\tclearTimeout(this._pointerHoverThrottleTimeout);\n\t}\n\n\t_initContainer() {\n\t\tconst container = this._container = document.createElement('canvas');\n\n\t\tDomEvent.on(container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.on(container, 'click dblclick pointerdown pointerup contextmenu', this._onClick, this);\n\t\tDomEvent.on(container, 'pointerout', this._handlePointerOut, this);\n\t\tcontainer['_maplair_disable_events'] = true;\n\n\t\tthis._ctx = container.getContext('2d');\n\t}\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._redrawRequest);\n\t\tthis._redrawRequest = null;\n\t\tdelete this._ctx;\n\t\tsuper._destroyContainer();\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\t\tconst m = this._ctxScale = window.devicePixelRatio;\n\n\t\t// set canvas size (also clearing it); use double size on retina\n\t\tthis._container.width = m * size.x;\n\t\tthis._container.height = m * size.y;\n\t}\n\n\t_updatePaths() {\n\t\tif (this._postponeUpdatePaths) { return; }\n\n\t\tthis._redrawBounds = null;\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tlayer._update();\n\t\t}\n\t\tthis._redraw();\n\t}\n\n\t_update() {\n\t\tif (this._map._animatingZoom && this._bounds) { return; }\n\n\t\tconst b = this._bounds,\n\t\ts = this._ctxScale;\n\n\t\t// translate so we use the same path coordinates after canvas element moves\n\t\tthis._ctx.setTransform(\n\t\t\ts, 0, 0, s,\n\t\t\t-b.min.x * s,\n\t\t\t-b.min.y * s);\n\n\t\t// Tell paths to redraw themselves\n\t\tthis.fire('update');\n\t}\n\n\t_reset() {\n\t\tsuper._reset();\n\n\t\tif (this._postponeUpdatePaths) {\n\t\t\tthis._postponeUpdatePaths = false;\n\t\t\tthis._updatePaths();\n\t\t}\n\t}\n\n\t_initPath(layer) {\n\t\tthis._updateDashArray(layer);\n\t\tthis._layers[Util.stamp(layer)] = layer;\n\n\t\tconst order = layer._order = {\n\t\t\tlayer,\n\t\t\tprev: this._drawLast,\n\t\t\tnext: null\n\t\t};\n\t\tif (this._drawLast) { this._drawLast.next = order; }\n\t\tthis._drawLast = order;\n\t\tthis._drawFirst ??= this._drawLast;\n\t}\n\n\t_addPath(layer) {\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_removePath(layer) {\n\t\tconst order = layer._order;\n\t\tconst next = order.next;\n\t\tconst prev = order.prev;\n\n\t\tif (next) {\n\t\t\tnext.prev = prev;\n\t\t} else {\n\t\t\tthis._drawLast = prev;\n\t\t}\n\t\tif (prev) {\n\t\t\tprev.next = next;\n\t\t} else {\n\t\t\tthis._drawFirst = next;\n\t\t}\n\n\t\tdelete layer._order;\n\n\t\tdelete this._layers[Util.stamp(layer)];\n\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updatePath(layer) {\n\t\t// Redraw the union of the layer's old pixel\n\t\t// bounds and the new pixel bounds.\n\t\tthis._extendRedrawBounds(layer);\n\t\tlayer._project();\n\t\tlayer._update();\n\t\t// The redraw will extend the redraw bounds\n\t\t// with the new pixel bounds.\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updateStyle(layer) {\n\t\tthis._updateDashArray(layer);\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updateDashArray(layer) {\n\t\tif (typeof layer.options.dashArray === 'string') {\n\t\t\tconst parts = layer.options.dashArray.split(DASH_SEPARATOR_RE);\n\t\t\t// Ignore dash array containing invalid lengths\n\t\t\tlayer._dashArray = parts.map(n => Number(n)).filter(n => !isNaN(n));\n\t\t} else {\n\t\t\tlayer._dashArray = layer.options.dashArray;\n\t\t}\n\t}\n\n\t_requestRedraw(layer) {\n\t\tif (!this._map) { return; }\n\n\t\tthis._extendRedrawBounds(layer);\n\t\tthis._redrawRequest ??= requestAnimationFrame(this._redraw.bind(this));\n\t}\n\n\t_extendRedrawBounds(layer) {\n\t\tif (layer._pxBounds) {\n\t\t\tconst padding = (layer.options.weight ?? 0) + 1;\n\t\t\tthis._redrawBounds ??= new Bounds();\n\t\t\tthis._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));\n\t\t\tthis._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));\n\t\t}\n\t}\n\n\t_redraw() {\n\t\t// also when redrawing directly, see `_updatePaths()`\n\t\tcancelAnimationFrame(this._redrawRequest);\n\t\tthis._redrawRequest = null;\n\n\t\tif (this._redrawBounds) {\n\t\t\tthis._redrawBounds.min._floor();\n\t\t\tthis._redrawBounds.max._ceil();\n\t\t}\n\n\t\tthis._clear(); // clear layers in redraw bounds\n\t\tthis._draw(); // draw layers\n\n\t\tthis._redrawBounds = null;\n\t}\n\n\t_clear() {\n\t\tconst bounds = this._redrawBounds;\n\t\tif (bounds) {\n\t\t\tconst size = bounds.getSize();\n\t\t\tthis._ctx.clearRect(bounds.min.x, bounds.min.y, size.x, size.y);\n\t\t} else {\n\t\t\tthis._ctx.save();\n\t\t\tthis._ctx.setTransform(1, 0, 0, 1, 0, 0);\n\t\t\tthis._ctx.clearRect(0, 0, this._container.width, this._container.height);\n\t\t\tthis._ctx.restore();\n\t\t}\n\t}\n\n\t_draw() {\n\t\tlet layer;\n\t\tconst bounds = this._redrawBounds;\n\t\tthis._ctx.save();\n\t\tif (bounds) {\n\t\t\tconst size = bounds.getSize();\n\t\t\tthis._ctx.beginPath();\n\t\t\tthis._ctx.rect(bounds.min.x, bounds.min.y, size.x, size.y);\n\t\t\tthis._ctx.clip();\n\t\t}\n\n\t\tthis._drawing = true;\n\n\t\tfor (let order = this._drawFirst; order; order = order.next) {\n\t\t\tlayer = order.layer;\n\t\t\tif (!bounds || (layer._pxBounds && layer._pxBounds.intersects(bounds))) {\n\t\t\t\tlayer._updatePath();\n\t\t\t}\n\t\t}\n\n\t\tthis._drawing = false;\n\n\t\tthis._ctx.restore(); // Restore state before clipping.\n\t}\n\n\t_updatePoly(layer, closed) {\n\t\tif (!this._drawing) { return; }\n\n\t\tconst parts = layer._parts,\n\t\tctx = this._ctx;\n\n\t\tif (!parts.length) { return; }\n\n\t\tctx.beginPath();\n\n\t\tparts.forEach((p0) => {\n\t\t\tp0.forEach((p, j) => {\n\t\t\t\tctx[j ? 'lineTo' : 'moveTo'](p.x, p.y);\n\t\t\t});\n\t\t\tif (closed) {\n\t\t\t\tctx.closePath();\n\t\t\t}\n\t\t});\n\n\t\tthis._fillStroke(ctx, layer);\n\n\t\t// TODO optimization: 1 fill/stroke for all features with equal style instead of 1 for each feature\n\t}\n\n\t_updateCircle(layer) {\n\n\t\tif (!this._drawing || layer._empty()) { return; }\n\n\t\tconst {x, y} = layer._point,\n\t\tctx = this._ctx,\n\t\tr = Math.max(Math.round(layer._pxRadius), 1),\n\t\try = Math.max(Math.round(layer._pxRadiusY), 1) || r;\n\n\t\tctx.beginPath();\n\t\t// arc is faster for circles in Chrome and Firefox, ellipse for everything else\n\t\tif (ry === r) {\n\t\t\tctx.arc(x, y, r, 0, Math.PI * 2);\n\t\t} else {\n\t\t\tctx.ellipse(x, y, r, ry, 0, 0, Math.PI * 2);\n\t\t}\n\n\t\tthis._fillStroke(ctx, layer);\n\t}\n\n\t_fillStroke(ctx, layer) {\n\t\tconst options = layer.options;\n\n\t\tif (options.fill) {\n\t\t\tctx.globalAlpha = options.fillOpacity;\n\t\t\tctx.fillStyle = options.fillColor ?? options.color;\n\t\t\tctx.fill(options.fillRule || 'evenodd');\n\t\t}\n\n\t\tif (options.stroke && options.weight !== 0) {\n\t\t\tctx.lineDashOffset = Number(options.dashOffset ?? 0);\n\t\t\tctx.setLineDash(layer._dashArray ?? []);\n\t\t\tctx.globalAlpha = options.opacity;\n\t\t\tctx.lineWidth = options.weight;\n\t\t\tctx.strokeStyle = options.color;\n\t\t\tctx.lineCap = options.lineCap;\n\t\t\tctx.lineJoin = options.lineJoin;\n\t\t\tctx.stroke();\n\t\t}\n\t}\n\n\t// The hit detection checks the `interactive` option of the layers,\n\t// the hovered layer is left on the next pointer move.\n\t_updateInteractive() {}\n\n\t// Canvas obviously doesn't have pointer events for individual drawn objects,\n\t// so we emulate that by calculating what's under the pointer on pointermove/click manually\n\n\t_onClick(e) {\n\t\tconst point = this._map.pointerEventToLayerPoint(e);\n\t\tlet layer, clickedLayer;\n\n\t\tfor (let order = this._drawFirst; order; order = order.next) {\n\t\t\tlayer = order.layer;\n\t\t\tif (layer.options.interactive && layer._containsPoint(point)) {\n\t\t\t\tif (!(e.type === 'click' || e.type === 'preclick') || !this._map._draggableMoved(layer)) {\n\t\t\t\t\tclickedLayer = layer;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis._fireEvent(clickedLayer ? [clickedLayer] : false, e);\n\t}\n\n\t_onPointerMove(e) {\n\t\tif (!this._map || this._map.dragging.moving() || this._map._animatingZoom) { return; }\n\n\t\tconst point = this._map.pointerEventToLayerPoint(e);\n\t\tthis._handlePointerHover(e, point);\n\t}\n\n\n\t_handlePointerOut(e) {\n\t\tconst layer = this._hoveredLayer;\n\t\tif (layer) {\n\t\t\t// if we're leaving the layer, fire pointerout\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis._fireEvent([layer], e, 'pointerout');\n\t\t\tthis._hoveredLayer = null;\n\t\t\tthis._pointerHoverThrottled = false;\n\t\t}\n\t}\n\n\t_handlePointerHover(e, point) {\n\t\tif (this._pointerHoverThrottled) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet layer, candidateHoveredLayer;\n\n\t\tfor (let order = this._drawFirst; order; order = order.next) {\n\t\t\tlayer = order.layer;\n\t\t\tif (layer.options.interactive && layer._containsPoint(point)) {\n\t\t\t\tcandidateHoveredLayer = layer;\n\t\t\t}\n\t\t}\n\n\t\tif (candidateHoveredLayer !== this._hoveredLayer) {\n\t\t\tthis._handlePointerOut(e);\n\n\t\t\tif (candidateHoveredLayer) {\n\t\t\t\tthis._container.classList.add('maplair-interactive'); // change cursor\n\t\t\t\tthis._fireEvent([candidateHoveredLayer], e, 'pointerover');\n\t\t\t\tthis._hoveredLayer = candidateHoveredLayer;\n\t\t\t}\n\t\t}\n\n\t\tthis._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);\n\n\t\tthis._pointerHoverThrottled = true;\n\t\tthis._pointerHoverThrottleTimeout = setTimeout((() => {\n\t\t\tthis._pointerHoverThrottled = false;\n\t\t}), 32);\n\t}\n\n\t_fireEvent(layers, e, type) {\n\t\tthis._map._fireDOMEvent(e, type || e.type, layers);\n\t}\n\n\t_bringToFront(layer) {\n\t\tconst order = layer._order;\n\n\t\tif (!order) { return; }\n\n\t\tconst next = order.next;\n\t\tconst prev = order.prev;\n\n\t\tif (next) {\n\t\t\tnext.prev = prev;\n\t\t} else {\n\t\t\t// Already last\n\t\t\treturn;\n\t\t}\n\t\tif (prev) {\n\t\t\tprev.next = next;\n\t\t} else if (next) {\n\t\t\t// Update first entry unless this is the\n\t\t\t// single entry\n\t\t\tthis._drawFirst = next;\n\t\t}\n\n\t\torder.prev = this._drawLast;\n\t\tthis._drawLast.next = order;\n\n\t\torder.next = null;\n\t\tthis._drawLast = order;\n\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_bringToBack(layer) {\n\t\tconst order = layer._order;\n\n\t\tif (!order) { return; }\n\n\t\tconst next = order.next;\n\t\tconst prev = order.prev;\n\n\t\tif (prev) {\n\t\t\tprev.next = next;\n\t\t} else {\n\t\t\t// Already first\n\t\t\treturn;\n\t\t}\n\t\tif (next) {\n\t\t\tnext.prev = prev;\n\t\t} else if (prev) {\n\t\t\t// Update last entry unless this is the\n\t\t\t// single entry\n\t\t\tthis._drawLast = prev;\n\t\t}\n\n\t\torder.prev = null;\n\n\t\torder.next = this._drawFirst;\n\t\tthis._drawFirst.prev = order;\n\t\tthis._drawFirst = order;\n\n\t\tthis._requestRed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AO;OAGZ;EAED,IAAI,MACH,KAAK,OAAO;OACN,IAAI,MAGV,KAAK,YAAY;EAGlB,MAAM,OAAO;EAEb,MAAM,OAAO,KAAK;EAClB,KAAK,WAAW,OAAO;EACvB,KAAK,aAAa;EAElB,KAAK,eAAe,KAAK;CAC1B;AACD"}
|
|
1
|
+
{"version":3,"file":"Canvas.js","names":["Util.stamp"],"sources":["../../../../src/layer/vector/Canvas.js"],"sourcesContent":["import {Renderer} from './Renderer.js';\nimport * as Util from '../../core/Util.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {EventListener} from '../../core/Events.js' */\n/** @import {RendererOptions} from './Renderer.js' */\n\nconst DASH_SEPARATOR_RE = /[, ]+/;\n\n/**\n * Options of `Canvas`.\n * @typedef {object} CanvasOptions\n * @property {number} [tolerance=0] How much to extend the click tolerance around a\n * path/object on the map.\n * @extends RendererOptions\n */\n\n/**\n * Allows vector layers to be displayed with [`<canvas>`](https://developer.mozilla.org/docs/Web/API/Canvas_API).\n * Inherits `Renderer`.\n *\n * @example\n * Use Canvas by default for all paths in the map:\n *\n * ```js\n * const map = new MaplairMap('map', {\n * \trenderer: new Canvas()\n * });\n * ```\n *\n * Use a Canvas renderer with extra padding for specific vector geometries:\n *\n * ```js\n * const map = new MaplairMap('map');\n * const myRenderer = new Canvas({ padding: 0.5 });\n * const line = new Polyline( coordinates, { renderer: myRenderer } );\n * const circle = new Circle( center, { renderer: myRenderer, radius: 100 } );\n * ```\n */\nexport class Canvas extends Renderer {\n\n\tstatic defaultOptions = {\n\t\ttolerance: 0\n\t};\n\n\t/**\n\t * Creates a Canvas renderer with the given options.\n\t * @overload\n\t * @param {CanvasOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Canvas);\n\t}\n\n\t/**\n\t * Returns the map events the renderer listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\t\tevents.viewprereset = this._onViewPreReset;\n\t\tevents.pixelratiochange = this._onPixelRatioChange;\n\t\treturn events;\n\t}\n\n\t// Redraws with the resolution of the new `devicePixelRatio`.\n\t_onPixelRatioChange() {\n\t\tthis._resizeContainer();\n\t\tthis._update();\n\t}\n\n\t_onViewPreReset() {\n\t\t// Set a flag so that a viewprereset+moveend+viewreset only updates&redraws once\n\t\tthis._postponeUpdatePaths = true;\n\t}\n\n\t/**\n\t * Adds the canvas to the map and draws the paths.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tsuper.onAdd(map);\n\n\t\t// the map hit-tests canvas renderers topmost first: by pane z-index, then DOM order\n\t\tconst z = r => +getComputedStyle(r._container.parentNode).zIndex || 0;\n\t\tmap._canvases.push(this);\n\t\tmap._canvases.sort((a, b) => z(b) - z(a) || (a._container.compareDocumentPosition(b._container) & 2) - 1);\n\n\t\t// Redraw vectors since canvas is cleared upon removal,\n\t\t// in case of removing the renderer itself from the map.\n\t\tthis._draw();\n\t}\n\n\t_initContainer() {\n\t\tconst container = this._container = document.createElement('canvas');\n\n\t\tthis._ctx = container.getContext('2d');\n\t}\n\n\t/**\n\t * Removes the canvas from the map.\n\t */\n\tonRemove() {\n\t\tthis._map._canvases = this._map._canvases.filter(r => r !== this);\n\t\tsuper.onRemove();\n\t}\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._redrawRequest);\n\t\tthis._redrawRequest = null;\n\t\tdelete this._ctx;\n\t\tsuper._destroyContainer();\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\t\tconst m = this._ctxScale = window.devicePixelRatio;\n\n\t\t// set canvas size (also clearing it); use double size on retina\n\t\tthis._container.width = m * size.x;\n\t\tthis._container.height = m * size.y;\n\t}\n\n\t_updatePaths() {\n\t\tif (this._postponeUpdatePaths) { return; }\n\n\t\tthis._redrawBounds = null;\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tlayer._update();\n\t\t}\n\t\tthis._redraw();\n\t}\n\n\t_update() {\n\t\tif (this._map._animatingZoom && this._bounds) { return; }\n\n\t\tconst b = this._bounds,\n\t\ts = this._ctxScale;\n\n\t\t// translate so we use the same path coordinates after canvas element moves\n\t\tthis._ctx.setTransform(\n\t\t\ts, 0, 0, s,\n\t\t\t-b.min.x * s,\n\t\t\t-b.min.y * s);\n\n\t\t// Tell paths to redraw themselves\n\t\tthis.fire('update');\n\t}\n\n\t_reset() {\n\t\tsuper._reset();\n\n\t\tif (this._postponeUpdatePaths) {\n\t\t\tthis._postponeUpdatePaths = false;\n\t\t\tthis._updatePaths();\n\t\t}\n\t}\n\n\t_initPath(layer) {\n\t\tthis._updateDashArray(layer);\n\t\tthis._layers[Util.stamp(layer)] = layer;\n\n\t\tthis._append(layer._order = {layer});\n\t}\n\n\t_addPath(layer) {\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_removePath(layer) {\n\t\tthis._unlink(layer._order);\n\t\tdelete layer._order;\n\n\t\tdelete this._layers[Util.stamp(layer)];\n\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updatePath(layer) {\n\t\t// Redraw the union of the layer's old pixel\n\t\t// bounds and the new pixel bounds.\n\t\tthis._extendRedrawBounds(layer);\n\t\tlayer._project();\n\t\tlayer._update();\n\t\t// The redraw will extend the redraw bounds\n\t\t// with the new pixel bounds.\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updateStyle(layer) {\n\t\tthis._updateDashArray(layer);\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updateDashArray(layer) {\n\t\tif (typeof layer.options.dashArray === 'string') {\n\t\t\tconst parts = layer.options.dashArray.split(DASH_SEPARATOR_RE);\n\t\t\t// Ignore dash array containing invalid lengths\n\t\t\tlayer._dashArray = parts.map(n => Number(n)).filter(n => !isNaN(n));\n\t\t} else {\n\t\t\tlayer._dashArray = layer.options.dashArray;\n\t\t}\n\t}\n\n\t_requestRedraw(layer) {\n\t\tif (!this._map) { return; }\n\n\t\tthis._extendRedrawBounds(layer);\n\t\tthis._redrawRequest ??= requestAnimationFrame(this._redraw.bind(this));\n\t}\n\n\t_extendRedrawBounds(layer) {\n\t\tif (layer._pxBounds) {\n\t\t\tconst padding = (+layer.options.weight || 0) + 1;\n\t\t\tthis._redrawBounds ??= new Bounds();\n\t\t\tthis._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));\n\t\t\tthis._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));\n\t\t}\n\t}\n\n\t_redraw() {\n\t\t// also when redrawing directly, see `_updatePaths()`\n\t\tcancelAnimationFrame(this._redrawRequest);\n\t\tthis._redrawRequest = null;\n\n\t\tif (this._redrawBounds) {\n\t\t\tthis._redrawBounds.min._floor();\n\t\t\tthis._redrawBounds.max._ceil();\n\t\t}\n\n\t\tthis._clear(); // clear layers in redraw bounds\n\t\tthis._draw(); // draw layers\n\n\t\tthis._redrawBounds = null;\n\t}\n\n\t_clear() {\n\t\tconst bounds = this._redrawBounds;\n\t\tif (bounds) {\n\t\t\tconst size = bounds.getSize();\n\t\t\tthis._ctx.clearRect(bounds.min.x, bounds.min.y, size.x, size.y);\n\t\t} else {\n\t\t\tthis._ctx.save();\n\t\t\tthis._ctx.setTransform(1, 0, 0, 1, 0, 0);\n\t\t\tthis._ctx.clearRect(0, 0, this._container.width, this._container.height);\n\t\t\tthis._ctx.restore();\n\t\t}\n\t}\n\n\t_draw() {\n\t\tlet layer;\n\t\tconst bounds = this._redrawBounds;\n\t\tthis._ctx.save();\n\t\tif (bounds) {\n\t\t\tconst size = bounds.getSize();\n\t\t\tthis._ctx.beginPath();\n\t\t\tthis._ctx.rect(bounds.min.x, bounds.min.y, size.x, size.y);\n\t\t\tthis._ctx.clip();\n\t\t}\n\n\t\tthis._drawing = true;\n\n\t\tfor (let order = this._drawFirst; order; order = order.next) {\n\t\t\tlayer = order.layer;\n\t\t\tif (!bounds || layer._pxBounds?.intersects(bounds)) {\n\t\t\t\tlayer._updatePath();\n\t\t\t}\n\t\t}\n\n\t\tthis._drawing = false;\n\n\t\tthis._ctx.restore(); // Restore state before clipping.\n\t}\n\n\t_updatePoly(layer, closed) {\n\t\tif (!this._drawing) { return; }\n\n\t\tconst parts = layer._parts,\n\t\tctx = this._ctx;\n\n\t\tif (!parts.length) { return; }\n\n\t\tctx.beginPath();\n\n\t\tparts.forEach((p0) => {\n\t\t\tp0.forEach((p, j) => {\n\t\t\t\tctx[j ? 'lineTo' : 'moveTo'](p.x, p.y);\n\t\t\t});\n\t\t\tif (closed) {\n\t\t\t\tctx.closePath();\n\t\t\t}\n\t\t});\n\n\t\tthis._fillStroke(ctx, layer);\n\n\t\t// TODO optimization: 1 fill/stroke for all features with equal style instead of 1 for each feature\n\t}\n\n\t_updateCircle(layer) {\n\n\t\tif (!this._drawing || layer._empty()) { return; }\n\n\t\tconst {x, y} = layer._point,\n\t\tctx = this._ctx,\n\t\tr = Math.max(Math.round(layer._pxRadius), 1),\n\t\try = Math.max(Math.round(layer._pxRadiusY), 1) || r;\n\n\t\tctx.beginPath();\n\t\t// arc is faster for circles in Chrome and Firefox, ellipse for everything else\n\t\tif (ry === r) {\n\t\t\tctx.arc(x, y, r, 0, Math.PI * 2);\n\t\t} else {\n\t\t\tctx.ellipse(x, y, r, ry, 0, 0, Math.PI * 2);\n\t\t}\n\n\t\tthis._fillStroke(ctx, layer);\n\t}\n\n\t_fillStroke(ctx, layer) {\n\t\tconst options = layer.options;\n\n\t\tif (options.fill) {\n\t\t\tctx.globalAlpha = options.fillOpacity;\n\t\t\tctx.fillStyle = options.fillColor ?? options.color;\n\t\t\tctx.fill(options.fillRule || 'evenodd');\n\t\t}\n\n\t\tif (options.stroke && options.weight !== 0) {\n\t\t\tctx.lineDashOffset = Number(options.dashOffset ?? 0);\n\t\t\tctx.setLineDash(layer._dashArray ?? []);\n\t\t\tctx.globalAlpha = options.opacity;\n\t\t\tctx.lineWidth = options.weight;\n\t\t\tctx.strokeStyle = options.color;\n\t\t\tctx.lineCap = options.lineCap;\n\t\t\tctx.lineJoin = options.lineJoin;\n\t\t\tctx.stroke();\n\t\t}\n\t}\n\n\t// The hit detection checks the `interactive` option of the layers,\n\t// the hovered layer is left on the next pointer move.\n\t_updateInteractive() {}\n\n\t// Canvas obviously doesn't have pointer events for individual drawn objects,\n\t// so the map calls this on its own pointer events to find what's under the pointer\n\n\t/**\n\t * Returns the topmost interactive layer under the pointer.\n\t * @param {MouseEvent} e\n\t * @param {boolean} [click] Skip layers that were just dragged, so the drag doesn't end with a click.\n\t * @returns {Path|undefined}\n\t */\n\t_layerAt(e, click) {\n\t\tconst point = this._map.pointerEventToLayerPoint(e);\n\n\t\tfor (let order = this._drawLast; order; order = order.prev) {\n\t\t\tconst layer = order.layer;\n\t\t\tif (layer.options.interactive && layer._containsPoint(point) && !(click && this._map._draggableMoved(layer))) {\n\t\t\t\treturn layer;\n\t\t\t}\n\t\t}\n\t}\n\n\t_bringToFront(layer) {\n\t\tconst order = layer._order;\n\t\tif (order?.next) { // unless already last\n\t\t\tthis._unlink(order);\n\t\t\tthis._append(order);\n\t\t\tthis._requestRedraw(layer);\n\t\t}\n\t}\n\n\t_bringToBack(layer) {\n\t\tconst order = layer._order;\n\t\tif (order?.prev) { // unless already first\n\t\t\tthis._unlink(order);\n\t\t\torder.prev = null;\n\t\t\torder.next = this._drawFirst;\n\t\t\tthis._drawFirst.prev = order;\n\t\t\tthis._drawFirst = order;\n\t\t\tthis._requestRedraw(layer);\n\t\t}\n\t}\n\n\t_append(order) {\n\t\torder.prev = this._drawLast;\n\t\torder.next = null;\n\t\tif (this._drawLast) { this._drawLast.next = order; }\n\t\tthis._drawLast = order;\n\t\tthis._drawFirst ??= order;\n\t}\n\n\t_unlink({prev, next}) {\n\t\tif (next) {\n\t\t\tnext.prev = prev;\n\t\t} else {\n\t\t\tthis._drawLast = prev;\n\t\t}\n\t\tif (prev) {\n\t\t\tprev.next = next;\n\t\t} else {\n\t\t\tthis._drawFirst = next;\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KAAK,OAAO;OAEZ,KAAK,YAAY;EAElB,IAAI,MACH,KAAK,OAAO;OAEZ,KAAK,aAAa;CAEpB;AACD"}
|
|
@@ -46,18 +46,18 @@ var Circle = class Circle extends CircleMarker {
|
|
|
46
46
|
return new LatLngBounds(this._map.layerPointToLatLng(this._point.subtract(half)), this._map.layerPointToLatLng(this._point.add(half)));
|
|
47
47
|
}
|
|
48
48
|
_project() {
|
|
49
|
-
const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs;
|
|
49
|
+
const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs, renderer = this._renderer, zoom = renderer._pathZoom;
|
|
50
50
|
if (crs.distance === EarthCRS.distance) {
|
|
51
|
-
const d = Math.PI / 180, latR = this._radius / EarthCRS.R / d, top = map.project([lat + latR, lng]), bottom = map.project([lat - latR, lng]), p = top.add(bottom).divideBy(2), lat2 = map.unproject(p).lat;
|
|
51
|
+
const d = Math.PI / 180, latR = this._radius / EarthCRS.R / d, top = map.project([lat + latR, lng], zoom), bottom = map.project([lat - latR, lng], zoom), p = top.add(bottom).divideBy(2), lat2 = map.unproject(p, zoom).lat;
|
|
52
52
|
let lngR = 2 * Math.asin(Math.sqrt((Math.sin(latR * d / 2) ** 2 - Math.sin((lat2 - lat) * d / 2) ** 2) / (Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;
|
|
53
|
-
if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(
|
|
54
|
-
this._point = p.subtract(
|
|
55
|
-
this._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x;
|
|
53
|
+
if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(lat * d);
|
|
54
|
+
this._point = p.subtract(renderer._pathOrigin);
|
|
55
|
+
this._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR], zoom).x;
|
|
56
56
|
this._pxRadiusY = p.y - top.y;
|
|
57
57
|
} else {
|
|
58
58
|
const latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));
|
|
59
|
-
this._point =
|
|
60
|
-
this._pxRadius = Math.abs(this._point.x -
|
|
59
|
+
this._point = renderer._latLngToLayerPoint(this._latlng);
|
|
60
|
+
this._pxRadius = Math.abs(this._point.x - renderer._latLngToLayerPoint(latlng2).x);
|
|
61
61
|
}
|
|
62
62
|
this._updateBounds();
|
|
63
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Circle.js","names":[],"sources":["../../../../src/layer/vector/Circle.js"],"sourcesContent":["import {CircleMarker} from './CircleMarker.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {EarthCRS} from '../../geo/crs/EarthCRS.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {CircleMarkerOptions} from './CircleMarker.js' */\n\n\n/**\n * Options of `Circle`.\n * @typedef {object} CircleOptions\n * @property {number} [radius] Radius of the circle, in meters.\n * @extends CircleMarkerOptions\n */\n\n/**\n * A class for drawing circle overlays on a map with radius specified in meters.\n * Extends `CircleMarker`, its `setRadius()` and `getRadius()` use meters.\n *\n * It's an approximation and starts to diverge from a real circle closer to poles\n * (due to projection distortion).\n *\n * @example\n * ```js\n * new Circle([50.5, 30.5], {radius: 200}).addTo(map);\n * ```\n */\nexport class Circle extends CircleMarker {\n\n\t/**\n\t * Instantiates a circle object given a geographical point, and an options object\n\t * which contains the circle radius.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tif (typeof options === 'number') {\n\t\t\tthrow new Error('Circle: the radius is an option in Maplair. Use new Circle(latlng, {radius}).');\n\t\t}\n\t\tsuper(latlng, options);\n\n\t\tif (isNaN(this.options.radius)) { throw new Error('Circle radius cannot be NaN'); }\n\n\t\tthis.callInitHooks(Circle);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path. When the circle isn't on a map, they're\n\t * approximated on a sphere.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\tif (!this._map) { return this._latlng.toBounds(this._radius * 2); }\n\n\t\tconst half = [this._pxRadius, this._pxRadiusY ?? this._pxRadius];\n\n\t\treturn new LatLngBounds(\n\t\t\tthis._map.layerPointToLatLng(this._point.subtract(half)),\n\t\t\tthis._map.layerPointToLatLng(this._point.add(half)));\n\t}\n\n\t_project() {\n\n\t\tconst lng = this._latlng.lng,\n\t\tlat = this._latlng.lat,\n\t\tmap = this._map,\n\t\tcrs = map.options.crs;\n\n\t\tif (crs.distance === EarthCRS.distance) {\n\t\t\tconst d = Math.PI / 180,\n\t\t\tlatR = (this._radius / EarthCRS.R) / d,\n\t\t\ttop = map.project([lat + latR, lng]),\n\t\t\tbottom = map.project([lat - latR, lng]),\n\t\t\tp = top.add(bottom).divideBy(2),\n\t\t\tlat2 = map.unproject(p).lat;\n\t\t\t// Longitude span from the haversine form of the spherical law of cosines. The plain acos() form\n\t\t\t// loses precision for radii of about a metre and less, where cos(latR) is too close to 1 (#6120).\n\t\t\tlet lngR = 2 * Math.asin(Math.sqrt(\n\t\t\t\t(Math.sin(latR * d / 2) ** 2 - Math.sin((lat2 - lat) * d / 2) ** 2) /\n\t\t\t\t(Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;\n\n\t\t\tif (isNaN(lngR) || lngR === 0) {\n\t\t\t\tlngR = latR / Math.cos(
|
|
1
|
+
{"version":3,"file":"Circle.js","names":[],"sources":["../../../../src/layer/vector/Circle.js"],"sourcesContent":["import {CircleMarker} from './CircleMarker.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {EarthCRS} from '../../geo/crs/EarthCRS.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {CircleMarkerOptions} from './CircleMarker.js' */\n\n\n/**\n * Options of `Circle`.\n * @typedef {object} CircleOptions\n * @property {number} [radius] Radius of the circle, in meters.\n * @extends CircleMarkerOptions\n */\n\n/**\n * A class for drawing circle overlays on a map with radius specified in meters.\n * Extends `CircleMarker`, its `setRadius()` and `getRadius()` use meters.\n *\n * It's an approximation and starts to diverge from a real circle closer to poles\n * (due to projection distortion).\n *\n * @example\n * ```js\n * new Circle([50.5, 30.5], {radius: 200}).addTo(map);\n * ```\n */\nexport class Circle extends CircleMarker {\n\n\t/**\n\t * Instantiates a circle object given a geographical point, and an options object\n\t * which contains the circle radius.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tif (typeof options === 'number') {\n\t\t\tthrow new Error('Circle: the radius is an option in Maplair. Use new Circle(latlng, {radius}).');\n\t\t}\n\t\tsuper(latlng, options);\n\n\t\tif (isNaN(this.options.radius)) { throw new Error('Circle radius cannot be NaN'); }\n\n\t\tthis.callInitHooks(Circle);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path. When the circle isn't on a map, they're\n\t * approximated on a sphere.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\tif (!this._map) { return this._latlng.toBounds(this._radius * 2); }\n\n\t\tconst half = [this._pxRadius, this._pxRadiusY ?? this._pxRadius];\n\n\t\treturn new LatLngBounds(\n\t\t\tthis._map.layerPointToLatLng(this._point.subtract(half)),\n\t\t\tthis._map.layerPointToLatLng(this._point.add(half)));\n\t}\n\n\t_project() {\n\n\t\tconst lng = this._latlng.lng,\n\t\tlat = this._latlng.lat,\n\t\tmap = this._map,\n\t\tcrs = map.options.crs,\n\t\trenderer = this._renderer,\n\t\tzoom = renderer._pathZoom;\n\n\t\tif (crs.distance === EarthCRS.distance) {\n\t\t\tconst d = Math.PI / 180,\n\t\t\tlatR = (this._radius / EarthCRS.R) / d,\n\t\t\ttop = map.project([lat + latR, lng], zoom),\n\t\t\tbottom = map.project([lat - latR, lng], zoom),\n\t\t\tp = top.add(bottom).divideBy(2),\n\t\t\tlat2 = map.unproject(p, zoom).lat;\n\t\t\t// Longitude span from the haversine form of the spherical law of cosines. The plain acos() form\n\t\t\t// loses precision for radii of about a metre and less, where cos(latR) is too close to 1 (#6120).\n\t\t\tlet lngR = 2 * Math.asin(Math.sqrt(\n\t\t\t\t(Math.sin(latR * d / 2) ** 2 - Math.sin((lat2 - lat) * d / 2) ** 2) /\n\t\t\t\t(Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;\n\n\t\t\tif (isNaN(lngR) || lngR === 0) {\n\t\t\t\tlngR = latR / Math.cos(lat * d); // Fallback for edge case, #2425\n\t\t\t}\n\n\t\t\tthis._point = p.subtract(renderer._pathOrigin);\n\t\t\tthis._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR], zoom).x;\n\t\t\tthis._pxRadiusY = p.y - top.y;\n\n\t\t} else {\n\t\t\tconst latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));\n\n\t\t\tthis._point = renderer._latLngToLayerPoint(this._latlng);\n\t\t\tthis._pxRadius = Math.abs(this._point.x - renderer._latLngToLayerPoint(latlng2).x);\n\t\t}\n\n\t\tthis._updateBounds();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,SAAb,MAAa,eAAe,aAAa;;;;;;;CAQxC,YAAY,QAAQ,SAAS;EAC5B,IAAI,OAAO,YAAY,UACtB,MAAM,IAAI,MAAM,+EAA+E;EAEhG,MAAM,QAAQ,OAAO;EAErB,IAAI,MAAM,KAAK,QAAQ,MAAM,GAAK,MAAM,IAAI,MAAM,6BAA6B;EAE/E,KAAK,cAAc,MAAM;CAC1B;;;;;;CAOA,YAAY;EACX,IAAI,CAAC,KAAK,MAAQ,OAAO,KAAK,QAAQ,SAAS,KAAK,UAAU,CAAC;EAE/D,MAAM,OAAO,CAAC,KAAK,WAAW,KAAK,cAAc,KAAK,SAAS;EAE/D,OAAO,IAAI,aACV,KAAK,KAAK,mBAAmB,KAAK,OAAO,SAAS,IAAI,CAAC,GACvD,KAAK,KAAK,mBAAmB,KAAK,OAAO,IAAI,IAAI,CAAC,C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C;EAClF;EAEA,KAAK,cAAc;CACpB;AACD"}
|
|
@@ -4,6 +4,7 @@ import { Path } from "./Path.js";
|
|
|
4
4
|
import { LatLng } from "../../geo/LatLng.js";
|
|
5
5
|
import { pointToGeoJSON } from "../GeoJSONUtil.js";
|
|
6
6
|
// src/layer/vector/CircleMarker.js
|
|
7
|
+
/** @import {MaplairMap} from '../../map/Map.js' */
|
|
7
8
|
/** @import {Feature} from 'geojson' */
|
|
8
9
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
9
10
|
/** @import {MaplairEvent} from '../../core/Events.js' */
|
|
@@ -48,6 +49,13 @@ var CircleMarker = class CircleMarker extends Path {
|
|
|
48
49
|
this.callInitHooks(CircleMarker);
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
52
|
+
* @param {MaplairMap} map
|
|
53
|
+
*/
|
|
54
|
+
beforeAdd(map) {
|
|
55
|
+
super.beforeAdd(map);
|
|
56
|
+
map._displaceHandler?._beforeMarkerAdd(this);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
51
59
|
* Sets the position of a circle marker to a new location.
|
|
52
60
|
* @param {LatLngExpression} latlng
|
|
53
61
|
* @returns {this}
|
|
@@ -95,7 +103,7 @@ var CircleMarker = class CircleMarker extends Path {
|
|
|
95
103
|
return this;
|
|
96
104
|
}
|
|
97
105
|
_project() {
|
|
98
|
-
this._point = this.
|
|
106
|
+
this._point = this._renderer._latLngToLayerPoint(this._latlng)._round();
|
|
99
107
|
this._pxRadius = this._radius;
|
|
100
108
|
this._updateBounds();
|
|
101
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CircleMarker.js","names":[],"sources":["../../../../src/layer/vector/CircleMarker.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {pointToGeoJSON} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n/** @import {PathOptions} from './Path.js' */\n\n\n/**\n * Options of `CircleMarker`.\n * @typedef {object} CircleMarkerOptions\n * @property {boolean} [fill=true] Whether to fill the circle with color.\n * @property {number} [radius=10] Radius of the circle marker, in CSS pixels.\n * @extends PathOptions\n */\n\n/**\n * The event object of `move` of circle markers.\n * @typedef {object} CircleMarkerMoveEvent\n * @property {LatLng} oldLatLng The previous position of the circle marker.\n * @property {LatLng} latlng The new position of the circle marker.\n * @extends MaplairEvent\n */\n\n/**\n * A circle of a fixed size with radius specified in CSS pixels. Extends `Path`.\n *\n * @fires move {CircleMarkerMoveEvent} Fired when the marker is moved via\n * [`setLatLng`](#circlemarker-setlatlng). Old and new coordinates are included in\n * event arguments as `oldLatLng`, `latlng`.\n */\nexport class CircleMarker extends Path {\n\n\tstatic defaultOptions = {\n\t\tfill: true,\n\t\tradius: 10\n\t};\n\n\t/**\n\t * Instantiates a circle marker object given a geographical point, and an optional\n\t * options object.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleMarkerOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis._radius = this.options.radius;\n\n\t\tthis.callInitHooks(CircleMarker);\n\t}\n\n\t/**\n\t * Sets the position of a circle marker to a new location.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tconst oldLatLng = this._latlng;\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis.redraw();\n\n\t\treturn this.fire('move', {oldLatLng, latlng: this._latlng});\n\t}\n\n\t/**\n\t * Returns the current geographical position of the circle marker.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the radius of a circle marker. Units are in CSS pixels.\n\t * @param {number} radius\n\t * @returns {this}\n\t */\n\tsetRadius(radius) {\n\t\tthis.options.radius = this._radius = radius;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the current radius of the circle. Units are in CSS pixels.\n\t * @returns {number}\n\t */\n\tgetRadius() {\n\t\treturn this._radius;\n\t}\n\n\t/**\n\t * Changes the appearance of the circle marker, also its `radius`.\n\t * @param {CircleMarkerOptions} options\n\t * @returns {this}\n\t */\n\tsetStyle(options) {\n\t\tsuper.setStyle(options);\n\t\tif (options?.radius !== undefined) {\n\t\t\tthis.setRadius(options.radius);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_project() {\n\t\t// snapped to whole pixels: subpixel precision is invisible on markers but slows down rendering many of them\n\t\tthis._point = this.
|
|
1
|
+
{"version":3,"file":"CircleMarker.js","names":[],"sources":["../../../../src/layer/vector/CircleMarker.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {pointToGeoJSON} from '../GeoJSONUtil.js';\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n/** @import {PathOptions} from './Path.js' */\n\n\n/**\n * Options of `CircleMarker`.\n * @typedef {object} CircleMarkerOptions\n * @property {boolean} [fill=true] Whether to fill the circle with color.\n * @property {number} [radius=10] Radius of the circle marker, in CSS pixels.\n * @extends PathOptions\n */\n\n/**\n * The event object of `move` of circle markers.\n * @typedef {object} CircleMarkerMoveEvent\n * @property {LatLng} oldLatLng The previous position of the circle marker.\n * @property {LatLng} latlng The new position of the circle marker.\n * @extends MaplairEvent\n */\n\n/**\n * A circle of a fixed size with radius specified in CSS pixels. Extends `Path`.\n *\n * @fires move {CircleMarkerMoveEvent} Fired when the marker is moved via\n * [`setLatLng`](#circlemarker-setlatlng). Old and new coordinates are included in\n * event arguments as `oldLatLng`, `latlng`.\n */\nexport class CircleMarker extends Path {\n\n\tstatic defaultOptions = {\n\t\tfill: true,\n\t\tradius: 10\n\t};\n\n\t/**\n\t * Instantiates a circle marker object given a geographical point, and an optional\n\t * options object.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleMarkerOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis._radius = this.options.radius;\n\n\t\tthis.callInitHooks(CircleMarker);\n\t}\n\n\t/**\n\t * @param {MaplairMap} map\n\t */\n\tbeforeAdd(map) {\n\t\tsuper.beforeAdd(map);\n\t\t// before the marker is drawn, see `DisplaceHandler`\n\t\tmap._displaceHandler?._beforeMarkerAdd(this);\n\t}\n\n\t/**\n\t * Sets the position of a circle marker to a new location.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tconst oldLatLng = this._latlng;\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis.redraw();\n\n\t\treturn this.fire('move', {oldLatLng, latlng: this._latlng});\n\t}\n\n\t/**\n\t * Returns the current geographical position of the circle marker.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the radius of a circle marker. Units are in CSS pixels.\n\t * @param {number} radius\n\t * @returns {this}\n\t */\n\tsetRadius(radius) {\n\t\tthis.options.radius = this._radius = radius;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the current radius of the circle. Units are in CSS pixels.\n\t * @returns {number}\n\t */\n\tgetRadius() {\n\t\treturn this._radius;\n\t}\n\n\t/**\n\t * Changes the appearance of the circle marker, also its `radius`.\n\t * @param {CircleMarkerOptions} options\n\t * @returns {this}\n\t */\n\tsetStyle(options) {\n\t\tsuper.setStyle(options);\n\t\tif (options?.radius !== undefined) {\n\t\t\tthis.setRadius(options.radius);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_project() {\n\t\t// snapped to whole pixels: subpixel precision is invisible on markers but slows down rendering many of them\n\t\tthis._point = this._renderer._latLngToLayerPoint(this._latlng)._round();\n\t\tthis._pxRadius = this._radius;\n\t\tthis._updateBounds();\n\t}\n\n\t_updateBounds() {\n\t\tconst r = this._pxRadius,\n\t\tr2 = this._pxRadiusY ?? r,\n\t\tw = this._clickTolerance(),\n\t\tp = [r + w, r2 + w];\n\t\tthis._pxBounds = new Bounds(this._point.subtract(p), this._point.add(p));\n\t}\n\n\t_update() {\n\t\tif (this._map) {\n\t\t\tthis._updatePath();\n\t\t}\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updateCircle(this);\n\t}\n\n\t_empty() {\n\t\treturn this._pxRadius && !this._renderer._bounds.intersects(this._pxBounds);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p) {\n\t\treturn p.distanceTo(this._point) <= this._pxRadius + this._clickTolerance();\n\t}\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the circle marker (as a GeoJSON `Point` Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\treturn pointToGeoJSON(this, precision);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAa,eAAb,MAAa,qBAAqB,KAAK;CAEtC,OAAO,iBAAiB;EACvB,MAAM;EACN,QAAQ;CACT;;;;;;;CAQA,YAAY,QAAQ,SAAS;EAC5B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B,KAAK,UAAU,IAAI,OAAO,MAAM;EAChC,KAAK,UAAU,KAAK,QAAQ;EAE5B,KAAK,cAAc,YAAY;CAChC;;;;CAKA,UAAU,KAAK;EACd,MAAM,UAAU,GAAG;EAEnB,IAAI,kBAAkB,iBAAiB,IAAI;CAC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
36
36
|
* Applied when the element is created; [`setStyle`](#path-setstyle) does not update it
|
|
37
37
|
* afterwards.
|
|
38
38
|
* @property {Renderer} [renderer] Use this specific instance of `Renderer` for this
|
|
39
|
-
* path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)
|
|
40
|
-
*
|
|
39
|
+
* path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)
|
|
40
|
+
* (`SVG` by default), or in a custom pane, a renderer of the same kind created for
|
|
41
|
+
* that pane. If set, it overrides the `pane` option.
|
|
41
42
|
* @extends InteractiveLayerOptions
|
|
42
43
|
*/
|
|
43
44
|
/**
|
|
44
|
-
* An abstract class that contains options and
|
|
45
|
-
*
|
|
45
|
+
* An abstract class that contains options and methods shared between vector overlays
|
|
46
|
+
* (`Polyline`, `Polygon`, `Rectangle`, `Circle`, `CircleMarker`). Do not use it
|
|
47
|
+
* directly. Extends `Layer`.
|
|
46
48
|
*/
|
|
47
49
|
var Path = class extends Layer {
|
|
48
50
|
static defaultOptions = {
|
|
@@ -139,8 +141,11 @@ var Path = class extends Layer {
|
|
|
139
141
|
this._project();
|
|
140
142
|
this._update();
|
|
141
143
|
}
|
|
144
|
+
_togglesPopupOnClick() {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
142
147
|
_clickTolerance() {
|
|
143
|
-
return (this.options.stroke ? this.options.weight / 2 : 0) + (this._renderer.options.tolerance || 0);
|
|
148
|
+
return (this.options.stroke ? this.options.weight / 2 || 0 : 0) + (this._renderer.options.tolerance || 0);
|
|
144
149
|
}
|
|
145
150
|
};
|
|
146
151
|
export { Path };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Path.js","names":[],"sources":["../../../../src/layer/vector/Path.js"],"sourcesContent":["import {Layer} from '../Layer.js';\nimport {SVG} from './SVG.js';\nimport * as Util from '../../core/Util.js';\n/** @import {InteractiveLayerOptions} from '../Layer.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Renderer} from './Renderer.js' */\n\n/**\n * Options of `Path`, shared by all vector layers.\n * @typedef {object} PathOptions\n * @property {boolean} [stroke=true] Whether to draw stroke along the path. Set it to\n * `false` to disable borders on polygons or circles.\n * @property {string} [color='#3388ff'] Stroke color.\n * @property {number} [weight=3] Stroke width in pixels.\n * @property {number} [opacity=1] Stroke opacity.\n * @property {string} [lineCap='round'] A string that defines\n * [shape to be used at the end](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linecap)\n * of the stroke.\n * @property {string} [lineJoin='round'] A string that defines\n * [shape to be used at the corners](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linejoin)\n * of the stroke.\n * @property {string|null} [dashArray=null] A string that defines the stroke\n * [dash pattern](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dasharray).\n * @property {string|null} [dashOffset=null] A string that defines the\n * [distance into the dash pattern to start the dash](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dashoffset).\n * @property {boolean} [fill=false] Whether to fill the path with color. Set it to\n * `false` to disable filling on polygons or circles. The default depends on the\n * class: `true` for polygons and circles.\n * @property {string|null} [fillColor=null] Fill color. Defaults to the value of the\n * [`color`](#pathoptions-color) option.\n * @property {number} [fillOpacity=0.2] Fill opacity.\n * @property {string} [fillRule='evenodd'] A string that defines\n * [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule)\n * is determined.\n * @property {string} [className] Custom class name set on an element. Only for SVG renderer.\n * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it\n * afterwards.\n * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this\n * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)
|
|
1
|
+
{"version":3,"file":"Path.js","names":[],"sources":["../../../../src/layer/vector/Path.js"],"sourcesContent":["import {Layer} from '../Layer.js';\nimport {SVG} from './SVG.js';\nimport * as Util from '../../core/Util.js';\n/** @import {InteractiveLayerOptions} from '../Layer.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Renderer} from './Renderer.js' */\n\n/**\n * Options of `Path`, shared by all vector layers.\n * @typedef {object} PathOptions\n * @property {boolean} [stroke=true] Whether to draw stroke along the path. Set it to\n * `false` to disable borders on polygons or circles.\n * @property {string} [color='#3388ff'] Stroke color.\n * @property {number} [weight=3] Stroke width in pixels.\n * @property {number} [opacity=1] Stroke opacity.\n * @property {string} [lineCap='round'] A string that defines\n * [shape to be used at the end](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linecap)\n * of the stroke.\n * @property {string} [lineJoin='round'] A string that defines\n * [shape to be used at the corners](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linejoin)\n * of the stroke.\n * @property {string|null} [dashArray=null] A string that defines the stroke\n * [dash pattern](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dasharray).\n * @property {string|null} [dashOffset=null] A string that defines the\n * [distance into the dash pattern to start the dash](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dashoffset).\n * @property {boolean} [fill=false] Whether to fill the path with color. Set it to\n * `false` to disable filling on polygons or circles. The default depends on the\n * class: `true` for polygons and circles.\n * @property {string|null} [fillColor=null] Fill color. Defaults to the value of the\n * [`color`](#pathoptions-color) option.\n * @property {number} [fillOpacity=0.2] Fill opacity.\n * @property {string} [fillRule='evenodd'] A string that defines\n * [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule)\n * is determined.\n * @property {string} [className] Custom class name set on an element. Only for SVG renderer.\n * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it\n * afterwards.\n * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this\n * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)\n * (`SVG` by default), or in a custom pane, a renderer of the same kind created for\n * that pane. If set, it overrides the `pane` option.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * An abstract class that contains options and methods shared between vector overlays\n * (`Polyline`, `Polygon`, `Rectangle`, `Circle`, `CircleMarker`). Do not use it\n * directly. Extends `Layer`.\n */\nexport class Path extends Layer {\n\n\tstatic defaultOptions = {\n\t\tstroke: true,\n\t\tcolor: '#3388ff',\n\t\tweight: 3,\n\t\topacity: 1,\n\t\tlineCap: 'round',\n\t\tlineJoin: 'round',\n\t\tdashArray: null,\n\t\tdashOffset: null,\n\t\tfill: false,\n\t\tfillColor: null,\n\t\tfillOpacity: 0.2,\n\t\tfillRule: 'evenodd',\n\t\t// className: '',\n\t\tinteractive: true,\n\t\tbubblingPointerEvents: true\n\t};\n\n\t/**\n\t * Gets the renderer of the path from the map, before it is added.\n\t * @param {MaplairMap} map\n\t */\n\tbeforeAdd(map) {\n\t\t// Renderer is set here because we need to call renderer.getEvents\n\t\t// before this.getEvents.\n\t\tthis._renderer = map.getRenderer(this);\n\t}\n\n\t/**\n\t * Adds the path to its renderer.\n\t */\n\tonAdd() {\n\t\tthis._renderer._initPath(this);\n\t\tthis._reset();\n\t\tthis._renderer._addPath(this);\n\t}\n\n\t/**\n\t * Removes the path from its renderer.\n\t */\n\tonRemove() {\n\t\tthis._renderer._removePath(this);\n\t}\n\n\t/**\n\t * Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map) {\n\t\t\tthis._renderer._updatePath(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_updateInteractive() {\n\t\tthis._renderer._updateInteractive(this);\n\t}\n\n\t/**\n\t * Changes the appearance of a Path based on the options in the `PathOptions` object.\n\t * Note that [`className`](#pathoptions-classname) is an exception: it is applied only\n\t * when the path element is created, so passing it here updates the option but leaves\n\t * the element's class unchanged.\n\t * @param {PathOptions} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\tUtil.setOptions(this, style);\n\t\tif (this._renderer) {\n\t\t\tthis._renderer._updateStyle(this);\n\t\t\tif (this.options.stroke && style && Object.hasOwn(style, 'weight')) {\n\t\t\t\tthis._updateBounds();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all path layers.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tthis._renderer?._bringToFront(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all path layers.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tthis._renderer?._bringToBack(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the SVG `path` element of the layer, if it is rendered by the `SVG` renderer.\n\t * @returns {SVGPathElement|undefined}\n\t */\n\tgetElement() {\n\t\treturn this._path;\n\t}\n\n\t// the renderer of the path if neither the path nor the map has one\n\t_createRenderer(options) {\n\t\treturn new SVG(options);\n\t}\n\n\t_reset() {\n\t\t// defined in child classes\n\t\tthis._project();\n\t\tthis._update();\n\t}\n\n\t_togglesPopupOnClick() {\n\t\treturn false;\n\t}\n\n\t_clickTolerance() {\n\t\t// used when doing hit detection for Canvas layers\n\t\treturn (this.options.stroke ? this.options.weight / 2 || 0 : 0) +\n\t\t (this._renderer.options.tolerance || 0);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAa,OAAb,cAA0B,MAAM;CAE/B,OAAO,iBAAiB;EACvB,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,SAAS;EACT,SAAS;EACT,UAAU;EACV,WAAW;EACX,YAAY;EACZ,MAAM;EACN,WAAW;EACX,aAAa;EACb,UAAU;EAEV,aAAa;EACb,uBAAuB;CACxB;;;;;CAMA,UAAU,KAAK;EAGd,KAAK,YAAY,IAAI,YAAY,IAAI;CACtC;;;;CAKA,QAAQ;EACP,KAAK,UAAU,UAAU,IAAI;EAC7B,KAAK,OAAO;EACZ,KAAK,UAAU,SAAS,IAAI;CAC7B;;;;CAKA,WAAW;EACV,KAAK,UAAU,YAAY,IAAI;CAChC;;;;;CAMA,SAAS;EACR,IAAI,KAAK,MACR,KAAK,UAAU,YAAY,IAAI;EAEhC,OAAO;CACR;CAEA,qBAAqB;EACpB,KAAK,UAAU,mBAAmB,IAAI;CACvC;;;;;;;;;CAUA,SAAS,OAAO;EACf,WAAgB,MAAM,KAAK;EAC3B,IAAI,KAAK,WAAW;GACnB,KAAK,UAAU,aAAa,IAAI;GAChC,IAAI,KAAK,QAAQ,UAAU,SAAS,OAAO,OAAO,OAAO,QAAQ,GAChE,KAAK,cAAc;EAErB;EACA,OAAO;CACR;;;;;CAMA,eAAe;EACd,KAAK,WAAW,cAAc,IAAI;EAClC,OAAO;CACR;;;;;CAMA,cAAc;EACb,KAAK,WAAW,aAAa,IAAI;EACjC,OAAO;CACR;;;;;CAMA,aAAa;EACZ,OAAO,KAAK;CACb;CAGA,gBAAgB,SAAS;EACxB,OAAO,IAAI,IAAI,OAAO;CACvB;CAEA,SAAS;EAER,KAAK,SAAS;EACd,KAAK,QAAQ;CACd;CAEA,uBAAuB;EACtB,OAAO;CACR;CAEA,kBAAkB;EAEjB,QAAQ,KAAK,QAAQ,SAAS,KAAK,QAAQ,SAAS,KAAK,IAAI,MAC1D,KAAK,UAAU,QAAQ,aAAa;CACxC;AACD"}
|
|
@@ -101,10 +101,10 @@ var Polygon = class Polygon extends Polyline {
|
|
|
101
101
|
}
|
|
102
102
|
_clipPoints() {
|
|
103
103
|
let bounds = this._renderer._bounds;
|
|
104
|
-
const w = this.options.weight, p = new Point(w, w);
|
|
104
|
+
const w = +this.options.weight || 0, p = new Point(w, w);
|
|
105
105
|
bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));
|
|
106
106
|
this._parts = [];
|
|
107
|
-
if (!this._pxBounds
|
|
107
|
+
if (!this._pxBounds?.intersects(bounds)) return;
|
|
108
108
|
if (this.options.noClip) {
|
|
109
109
|
this._parts = this._rings;
|
|
110
110
|
return;
|
|
@@ -117,16 +117,15 @@ var Polygon = class Polygon extends Polyline {
|
|
|
117
117
|
_updatePath() {
|
|
118
118
|
this._renderer._updatePoly(this, true);
|
|
119
119
|
}
|
|
120
|
+
_isClosed() {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
120
123
|
_containsPoint(p) {
|
|
121
|
-
let inside = false
|
|
122
|
-
if (!this._pxBounds
|
|
123
|
-
for (
|
|
124
|
-
part =
|
|
125
|
-
|
|
126
|
-
p1 = part[j];
|
|
127
|
-
p2 = part[k];
|
|
128
|
-
if (p1.y > p.y !== p2.y > p.y && p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x) inside = !inside;
|
|
129
|
-
}
|
|
124
|
+
let inside = false;
|
|
125
|
+
if (!this._pxBounds?.contains(p)) return false;
|
|
126
|
+
for (const part of this._parts) for (let j = 0, len = part.length, k = len - 1; j < len; k = j++) {
|
|
127
|
+
const p1 = part[j], p2 = part[k];
|
|
128
|
+
if (p1.y > p.y !== p2.y > p.y && p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x) inside = !inside;
|
|
130
129
|
}
|
|
131
130
|
return inside || super._containsPoint(p, true);
|
|
132
131
|
}
|