maplair 4.0.0-alpha.1
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 +2804 -0
- package/LICENSE +27 -0
- package/README.md +40 -0
- package/dist/esm/Maplair.js +71 -0
- package/dist/esm/Maplair.js.map +1 -0
- package/dist/esm/_virtual/_rolldown/runtime.js +13 -0
- package/dist/esm/control/AttributionControl.js +79 -0
- package/dist/esm/control/AttributionControl.js.map +1 -0
- package/dist/esm/control/Control.js +81 -0
- package/dist/esm/control/Control.js.map +1 -0
- package/dist/esm/control/LayersControl.js +220 -0
- package/dist/esm/control/LayersControl.js.map +1 -0
- package/dist/esm/control/ScaleControl.js +72 -0
- package/dist/esm/control/ScaleControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +86 -0
- package/dist/esm/control/ZoomControl.js.map +1 -0
- package/dist/esm/core/Browser.js +31 -0
- package/dist/esm/core/Browser.js.map +1 -0
- package/dist/esm/core/Class.js +52 -0
- package/dist/esm/core/Class.js.map +1 -0
- package/dist/esm/core/Events.js +149 -0
- package/dist/esm/core/Events.js.map +1 -0
- package/dist/esm/core/Handler.js +32 -0
- package/dist/esm/core/Handler.js.map +1 -0
- package/dist/esm/core/I18n.js +36 -0
- package/dist/esm/core/I18n.js.map +1 -0
- package/dist/esm/core/Util.js +71 -0
- package/dist/esm/core/Util.js.map +1 -0
- package/dist/esm/dom/DomEvent.DoubleTap.js +74 -0
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -0
- package/dist/esm/dom/DomEvent.PointerEvents.js +46 -0
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -0
- package/dist/esm/dom/DomEvent.js +135 -0
- package/dist/esm/dom/DomEvent.js.map +1 -0
- package/dist/esm/dom/DomUtil.js +107 -0
- package/dist/esm/dom/DomUtil.js.map +1 -0
- package/dist/esm/dom/Draggable.js +107 -0
- package/dist/esm/dom/Draggable.js.map +1 -0
- package/dist/esm/dom/PosAnimation.js +56 -0
- package/dist/esm/dom/PosAnimation.js.map +1 -0
- package/dist/esm/geo/LatLng.js +65 -0
- package/dist/esm/geo/LatLng.js.map +1 -0
- package/dist/esm/geo/LatLngBounds.js +114 -0
- package/dist/esm/geo/LatLngBounds.js.map +1 -0
- package/dist/esm/geo/crs/CRS.js +51 -0
- package/dist/esm/geo/crs/CRS.js.map +1 -0
- package/dist/esm/geo/crs/EPSG3395.js +16 -0
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -0
- package/dist/esm/geo/crs/EPSG3857.js +19 -0
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -0
- package/dist/esm/geo/crs/EPSG4326.js +13 -0
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -0
- package/dist/esm/geo/crs/EarthCRS.js +14 -0
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -0
- package/dist/esm/geo/crs/SimpleCRS.js +23 -0
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -0
- package/dist/esm/geo/projection/Projection.LonLat.js +19 -0
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -0
- package/dist/esm/geo/projection/Projection.Mercator.js +33 -0
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -0
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +27 -0
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -0
- package/dist/esm/geo/projection/index.js +14 -0
- package/dist/esm/geo/projection/index.js.map +1 -0
- package/dist/esm/geometry/Bounds.js +91 -0
- package/dist/esm/geometry/Bounds.js.map +1 -0
- package/dist/esm/geometry/LineUtil.js +169 -0
- package/dist/esm/geometry/LineUtil.js.map +1 -0
- package/dist/esm/geometry/Point.js +119 -0
- package/dist/esm/geometry/Point.js.map +1 -0
- package/dist/esm/geometry/PolyUtil.js +89 -0
- package/dist/esm/geometry/PolyUtil.js.map +1 -0
- package/dist/esm/geometry/Transformation.js +34 -0
- package/dist/esm/geometry/Transformation.js.map +1 -0
- package/dist/esm/layer/BlanketOverlay.js +87 -0
- package/dist/esm/layer/BlanketOverlay.js.map +1 -0
- package/dist/esm/layer/DivOverlay.js +192 -0
- package/dist/esm/layer/DivOverlay.js.map +1 -0
- package/dist/esm/layer/FeatureGroup.js +40 -0
- package/dist/esm/layer/FeatureGroup.js.map +1 -0
- package/dist/esm/layer/GeoJSON.js +192 -0
- package/dist/esm/layer/GeoJSON.js.map +1 -0
- package/dist/esm/layer/ImageOverlay.js +140 -0
- package/dist/esm/layer/ImageOverlay.js.map +1 -0
- package/dist/esm/layer/Layer.js +119 -0
- package/dist/esm/layer/Layer.js.map +1 -0
- package/dist/esm/layer/LayerGroup.js +58 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -0
- package/dist/esm/layer/Popup.js +224 -0
- package/dist/esm/layer/Popup.js.map +1 -0
- package/dist/esm/layer/SVGOverlay.js +21 -0
- package/dist/esm/layer/SVGOverlay.js.map +1 -0
- package/dist/esm/layer/Tooltip.js +228 -0
- package/dist/esm/layer/Tooltip.js.map +1 -0
- package/dist/esm/layer/VideoOverlay.js +54 -0
- package/dist/esm/layer/VideoOverlay.js.map +1 -0
- package/dist/esm/layer/marker/DefaultIcon.js +50 -0
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -0
- package/dist/esm/layer/marker/DivIcon.js +37 -0
- package/dist/esm/layer/marker/DivIcon.js.map +1 -0
- package/dist/esm/layer/marker/Icon.js +65 -0
- package/dist/esm/layer/marker/Icon.js.map +1 -0
- package/dist/esm/layer/marker/Marker.Drag.js +77 -0
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -0
- package/dist/esm/layer/marker/Marker.js +235 -0
- package/dist/esm/layer/marker/Marker.js.map +1 -0
- package/dist/esm/layer/tile/GridLayer.js +447 -0
- package/dist/esm/layer/tile/GridLayer.js.map +1 -0
- package/dist/esm/layer/tile/TileLayer.js +139 -0
- package/dist/esm/layer/tile/TileLayer.js.map +1 -0
- package/dist/esm/layer/tile/WMSTileLayer.js +68 -0
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -0
- package/dist/esm/layer/vector/Canvas.js +292 -0
- package/dist/esm/layer/vector/Canvas.js.map +1 -0
- package/dist/esm/layer/vector/Circle.js +35 -0
- package/dist/esm/layer/vector/Circle.js.map +1 -0
- package/dist/esm/layer/vector/CircleMarker.js +69 -0
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -0
- package/dist/esm/layer/vector/Path.js +68 -0
- package/dist/esm/layer/vector/Path.js.map +1 -0
- package/dist/esm/layer/vector/Polygon.js +70 -0
- package/dist/esm/layer/vector/Polygon.js.map +1 -0
- package/dist/esm/layer/vector/Polyline.js +152 -0
- package/dist/esm/layer/vector/Polyline.js.map +1 -0
- package/dist/esm/layer/vector/Rectangle.js +25 -0
- package/dist/esm/layer/vector/Rectangle.js.map +1 -0
- package/dist/esm/layer/vector/Renderer.getRenderer.js +31 -0
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -0
- package/dist/esm/layer/vector/Renderer.js +39 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -0
- package/dist/esm/layer/vector/SVG.js +115 -0
- package/dist/esm/layer/vector/SVG.js.map +1 -0
- package/dist/esm/map/Map.js +844 -0
- package/dist/esm/map/Map.js.map +1 -0
- package/dist/esm/map/handler/BoxZoomHandler.js +105 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +27 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/DragHandler.js +133 -0
- package/dist/esm/map/handler/DragHandler.js.map +1 -0
- package/dist/esm/map/handler/KeyboardHandler.js +117 -0
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -0
- package/dist/esm/map/handler/PinchZoomHandler.js +96 -0
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +50 -0
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/TapHoldHandler.js +77 -0
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -0
- package/dist/esm/package.js +6 -0
- package/dist/esm/package.js.map +1 -0
- package/dist/images/layers.svg +1 -0
- package/dist/images/logo.svg +1 -0
- package/dist/images/marker-icon.svg +1 -0
- package/dist/images/marker-shadow.svg +1 -0
- package/dist/maplair-global-src.js +6810 -0
- package/dist/maplair-global-src.js.map +1 -0
- package/dist/maplair-global.js +12 -0
- package/dist/maplair-global.js.map +1 -0
- package/dist/maplair-src.js +6704 -0
- package/dist/maplair-src.js.map +1 -0
- package/dist/maplair.css +730 -0
- package/dist/maplair.js +7 -0
- package/dist/maplair.js.map +1 -0
- package/i18n/cs.json +12 -0
- package/i18n/de.json +12 -0
- package/i18n/en.json +12 -0
- package/i18n/es.json +12 -0
- package/i18n/fr.json +12 -0
- package/i18n/hu.json +12 -0
- package/i18n/it.json +12 -0
- package/i18n/rm.json +12 -0
- package/i18n/sk.json +12 -0
- package/i18n/sl.json +12 -0
- package/package.json +87 -0
- package/src/Maplair.js +24 -0
- package/src/control/AttributionControl.js +147 -0
- package/src/control/Control.js +174 -0
- package/src/control/LayersControl.js +444 -0
- package/src/control/ScaleControl.js +141 -0
- package/src/control/ZoomControl.js +147 -0
- package/src/control/index.js +5 -0
- package/src/core/Browser.js +75 -0
- package/src/core/Class.js +97 -0
- package/src/core/Events.js +334 -0
- package/src/core/Handler.js +59 -0
- package/src/core/I18n.js +76 -0
- package/src/core/Util.js +122 -0
- package/src/core/index.js +8 -0
- package/src/dom/DomEvent.DoubleTap.js +120 -0
- package/src/dom/DomEvent.PointerEvents.js +75 -0
- package/src/dom/DomEvent.js +282 -0
- package/src/dom/DomUtil.js +175 -0
- package/src/dom/Draggable.js +204 -0
- package/src/dom/PosAnimation.js +115 -0
- package/src/dom/index.js +9 -0
- package/src/geo/LatLng.js +163 -0
- package/src/geo/LatLngBounds.js +260 -0
- package/src/geo/crs/CRS.js +143 -0
- package/src/geo/crs/EPSG3395.js +19 -0
- package/src/geo/crs/EPSG3857.js +26 -0
- package/src/geo/crs/EPSG4326.js +21 -0
- package/src/geo/crs/EarthCRS.js +32 -0
- package/src/geo/crs/SimpleCRS.js +35 -0
- package/src/geo/crs/index.js +6 -0
- package/src/geo/index.js +7 -0
- package/src/geo/projection/Projection.LonLat.js +30 -0
- package/src/geo/projection/Projection.Mercator.js +53 -0
- package/src/geo/projection/Projection.SphericalMercator.js +46 -0
- package/src/geo/projection/index.js +26 -0
- package/src/geometry/Bounds.js +222 -0
- package/src/geometry/LineUtil.js +299 -0
- package/src/geometry/Point.js +239 -0
- package/src/geometry/PolyUtil.js +129 -0
- package/src/geometry/Transformation.js +67 -0
- package/src/geometry/index.js +8 -0
- package/src/images/layers.svg +1 -0
- package/src/images/logo.svg +1 -0
- package/src/images/marker-icon.svg +1 -0
- package/src/images/marker-shadow.svg +1 -0
- package/src/layer/BlanketOverlay.js +171 -0
- package/src/layer/DivOverlay.js +353 -0
- package/src/layer/FeatureGroup.js +93 -0
- package/src/layer/GeoJSON.js +432 -0
- package/src/layer/ImageOverlay.js +279 -0
- package/src/layer/Layer.js +273 -0
- package/src/layer/LayerGroup.js +129 -0
- package/src/layer/Popup.js +528 -0
- package/src/layer/SVGOverlay.js +47 -0
- package/src/layer/Tooltip.js +469 -0
- package/src/layer/VideoOverlay.js +111 -0
- package/src/layer/index.js +18 -0
- package/src/layer/marker/DefaultIcon.js +79 -0
- package/src/layer/marker/DivIcon.js +76 -0
- package/src/layer/marker/Icon.js +164 -0
- package/src/layer/marker/Marker.Drag.js +161 -0
- package/src/layer/marker/Marker.js +465 -0
- package/src/layer/marker/index.js +5 -0
- package/src/layer/tile/GridLayer.js +901 -0
- package/src/layer/tile/TileLayer.js +299 -0
- package/src/layer/tile/WMSTileLayer.js +133 -0
- package/src/layer/tile/index.js +3 -0
- package/src/layer/vector/Canvas.js +479 -0
- package/src/layer/vector/Circle.js +87 -0
- package/src/layer/vector/CircleMarker.js +110 -0
- package/src/layer/vector/Path.js +145 -0
- package/src/layer/vector/Polygon.js +160 -0
- package/src/layer/vector/Polyline.js +296 -0
- package/src/layer/vector/Rectangle.js +52 -0
- package/src/layer/vector/Renderer.getRenderer.js +48 -0
- package/src/layer/vector/Renderer.js +75 -0
- package/src/layer/vector/SVG.js +216 -0
- package/src/layer/vector/index.js +10 -0
- package/src/map/Map.js +1830 -0
- package/src/map/handler/BoxZoomHandler.js +156 -0
- package/src/map/handler/DoubleClickZoomHandler.js +62 -0
- package/src/map/handler/DragHandler.js +240 -0
- package/src/map/handler/KeyboardHandler.js +188 -0
- package/src/map/handler/PinchZoomHandler.js +157 -0
- package/src/map/handler/ScrollWheelZoomHandler.js +98 -0
- package/src/map/handler/TapHoldHandler.js +111 -0
- package/src/map/index.js +8 -0
- package/src/maplair.css +730 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TileLayer.js","names":["Util.setOptions","Browser","Util.template","Util.falseFn"],"sources":["../../../../src/layer/tile/TileLayer.js"],"sourcesContent":["import {GridLayer} from './GridLayer.js';\nimport Browser from '../../core/Browser.js';\nimport * as Util from '../../core/Util.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport {I18n} from '../../core/I18n.js';\n\n/*\n * @class TileLayer\n * @inherits GridLayer\n * Used to load and display tile layers on the map. Note that most tile servers require attribution, which you can set under `Layer`. Extends `GridLayer`.\n *\n * @example\n *\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 * @section URL template\n * @example\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 parallel requests per domain limitation; subdomain values are specified in options; `a`, `b` or `c` by default, can be omitted), `{z}` — zoom level, `{x}` and `{y}` — 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) from TileLayer options, like this:\n *\n * ```\n * new TileLayer('https://{s}.somedomain.com/{foo}/{z}/{x}/{y}.png', {foo: 'bar'});\n * ```\n */\n\n// @constructor TileLayer(urlTemplate: String, options?: TileLayer options)\n// Instantiates a tile layer object given a `URL template` and optionally an options object.\nexport class TileLayer extends GridLayer {\n\n\tstatic {\n\t\t// @section\n\t\t// @aka TileLayer options\n\t\tthis.setDefaultOptions({\n\t\t\t// @option minZoom: Number = 0\n\t\t\t// The minimum zoom level down to which this layer will be displayed (inclusive).\n\t\t\tminZoom: 0,\n\n\t\t\t// @option maxZoom: Number = 18\n\t\t\t// The maximum zoom level up to which this layer will be displayed (inclusive).\n\t\t\tmaxZoom: 18,\n\n\t\t\t// @option subdomains: String|String[] = 'abc'\n\t\t\t// Subdomains of the tile service. Can be passed in the form of one string (where each letter is a subdomain name) or an array of strings.\n\t\t\tsubdomains: 'abc',\n\n\t\t\t// @option errorTileUrl: String = ''\n\t\t\t// URL to the tile image to show in place of the tile that failed to load.\n\t\t\terrorTileUrl: '',\n\n\t\t\t// @option zoomOffset: Number = 0\n\t\t\t// The zoom number used in tile URLs will be offset with this value.\n\t\t\tzoomOffset: 0,\n\n\t\t\t// @option tms: Boolean = false\n\t\t\t// If `true`, inverses Y axis numbering for tiles (turn this on for [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) services).\n\t\t\ttms: false,\n\n\t\t\t// @option zoomReverse: Boolean = false\n\t\t\t// If set to true, the zoom number used in tile URLs will be reversed (`maxZoom - zoom` instead of `zoom`)\n\t\t\tzoomReverse: false,\n\n\t\t\t// @option detectRetina: Boolean = false\n\t\t\t// If `true` and user is on a retina display, it will request four tiles of half the specified size and a bigger zoom level in place of one to utilize the high resolution.\n\t\t\tdetectRetina: false,\n\n\t\t\t// @option crossOrigin: Boolean|String = false\n\t\t\t// Whether the crossOrigin attribute will be added to the tiles.\n\t\t\t// If a String is provided, all tiles will have their crossOrigin attribute set to the String provided. This is needed if you want to access tile pixel data.\n\t\t\t// Refer to [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) for valid String values.\n\t\t\tcrossOrigin: false,\n\n\t\t\t// @option referrerPolicy: String = 'strict-origin-when-cross-origin'\n\t\t\t// Sets the tiles' `referrerPolicy` attribute set to the String provided. See\n\t\t\t// [`HTMLImageElement.referrerPolicy`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy) for possible values.\n\t\t\t//\n\t\t\t// Tile providers might require you to use a specific referrer policy (e.g. to verify API tokens or prevent abuse).\n\t\t\t// Specifically, if you are using tiles from `tile.openstreetmap.org` or `tile.osm.org`, you [should not change this value](https://operations.osmfoundation.org/policies/tiles/).\n\t\t\treferrerPolicy: 'strict-origin-when-cross-origin'\n\t\t});\n\t}\n\n\tconstructor(url, options) {\n\t\tsuper(options);\n\n\t\tthis._url = url;\n\n\t\toptions = Util.setOptions(this, options);\n\n\t\t// Set required OpenStreetMap attribution if it hasn't been specified; upgrade to HTTPS so the referrer policy works.\n\t\tconst tileUrl = new URL(this._url, location.href);\n\t\tconst urlHostname = tileUrl.hostname;\n\t\tconst osmHosts = ['tile.openstreetmap.org', 'tile.osm.org'];\n\t\tif (osmHosts.some(host => urlHostname.endsWith(host))) {\n\t\t\tif (options.attribution === null) {\n\t\t\t\toptions.attribution = `© <a href=\"https://www.openstreetmap.org/copyright\">${I18n.translate('OpenStreetMap contributors')}</a>`;\n\t\t\t}\n\t\t\tif (tileUrl.protocol === 'http:') {\n\t\t\t\ttileUrl.protocol = 'https:';\n\t\t\t\tthis._url = tileUrl.toString();\n\t\t\t}\n\t\t}\n\n\t\t// detecting retina displays, adjusting tileSize and zoom levels\n\t\tif (this.options.detectRetina && Browser.retina && this.options.maxZoom > 0) {\n\n\t\t\tthis.options.tileSize = Math.floor(this.options.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\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\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.on('tileunload', this._onTileRemove);\n\n\t\tthis.callInitHooks(TileLayer);\n\t}\n\n\t// @method setUrl(url: String, noRedraw?: Boolean): this\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\tsetUrl(url, noRedraw) {\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.redraw();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// @method createTile(coords: Object, done?: Function): HTMLElement\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 `done`\n\t// callback is called when the tile has been loaded.\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\ttile.src = this.getTileUrl(coords);\n\n\t\treturn tile;\n\t}\n\n\t// @section Extension methods\n\t// @uninheritable\n\t// Layers extending `TileLayer` might reimplement the following method.\n\t// @method getTileUrl(coords: Object): String\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 naming schemes.\n\tgetTileUrl(coords) {\n\t\tconst data = Object.create(this.options);\n\t\tObject.assign(data, {\n\t\t\tr: Browser.retina ? '@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\tdone(null, tile);\n\t}\n\n\t_tileOnError(done, tile, e) {\n\t\tconst errorUrl = this.options.errorTileUrl;\n\t\tif (errorUrl && tile.getAttribute('src') !== errorUrl) {\n\t\t\ttile.src = errorUrl;\n\t\t}\n\t\tdone(e, tile);\n\t}\n\n\t_onTileRemove(e) {\n\t\te.tile.onload = null;\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 index = Math.abs(tilePoint.x + tilePoint.y) % this.options.subdomains.length;\n\t\treturn this.options.subdomains[index];\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\ttile.onload = Util.falseFn;\n\t\t\t\ttile.onerror = Util.falseFn;\n\n\t\t\t\tif (!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\t// @event tileabort: TileEvent\n\t\t\t\t\t// Fired when a tile was loading but is now not wanted.\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\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}\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":";;;;;;AAqCA,IAAa,YAAb,MAAa,kBAAkB,UAAU;CAExC;EAGC,KAAK,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IACvD;EAGD,OAAO,MAAM,WAAW,QAAQ,KAAK,IAAI;CAC1C;CAEA,WAAW,MAAM;EAChB,OAAO,KAAK,MAAM,MAAM,WAAW,IAAI,CAAC;CACzC;AACD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import Browser_default from "../../core/Browser.js";
|
|
2
|
+
import { Bounds } from "../../geometry/Bounds.js";
|
|
3
|
+
import { EPSG4326 } from "../../geo/crs/EPSG4326.js";
|
|
4
|
+
import { TileLayer } from "./TileLayer.js";
|
|
5
|
+
//#region src/layer/tile/WMSTileLayer.js
|
|
6
|
+
var WMSTileLayer = class WMSTileLayer extends TileLayer {
|
|
7
|
+
static {
|
|
8
|
+
this.prototype.defaultWmsParams = {
|
|
9
|
+
service: "WMS",
|
|
10
|
+
request: "GetMap",
|
|
11
|
+
layers: "",
|
|
12
|
+
styles: "",
|
|
13
|
+
format: "image/jpeg",
|
|
14
|
+
transparent: false,
|
|
15
|
+
version: "1.1.1"
|
|
16
|
+
};
|
|
17
|
+
this.setDefaultOptions({
|
|
18
|
+
crs: null,
|
|
19
|
+
uppercase: false
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
constructor(url, options) {
|
|
23
|
+
super(url, options);
|
|
24
|
+
const wmsParams = { ...this.defaultWmsParams };
|
|
25
|
+
for (const [key, value] of Object.entries(options)) if (!(key in WMSTileLayer.prototype.options)) wmsParams[key] = value;
|
|
26
|
+
const realRetina = this.options.detectRetina && Browser_default.retina ? 2 : 1;
|
|
27
|
+
const tileSize = this.getTileSize();
|
|
28
|
+
wmsParams.width = tileSize.x * realRetina;
|
|
29
|
+
wmsParams.height = tileSize.y * realRetina;
|
|
30
|
+
this.wmsParams = wmsParams;
|
|
31
|
+
this.callInitHooks(WMSTileLayer);
|
|
32
|
+
}
|
|
33
|
+
onAdd(map) {
|
|
34
|
+
this._crs = this.options.crs ?? map.options.crs;
|
|
35
|
+
this._wmsVersion = parseFloat(this.wmsParams.version);
|
|
36
|
+
const projectionKey = this._wmsVersion >= 1.3 ? "crs" : "srs";
|
|
37
|
+
this.wmsParams[projectionKey] = this._crs.code;
|
|
38
|
+
super.onAdd(map);
|
|
39
|
+
}
|
|
40
|
+
getTileUrl(coords) {
|
|
41
|
+
const tileBounds = this._tileCoordsToNwSe(coords), crs = this._crs, bounds = new Bounds(crs.project(tileBounds[0]), crs.project(tileBounds[1])), min = bounds.min, max = bounds.max, bbox = (this._wmsVersion >= 1.3 && this._crs === EPSG4326 ? [
|
|
42
|
+
min.y,
|
|
43
|
+
min.x,
|
|
44
|
+
max.y,
|
|
45
|
+
max.x
|
|
46
|
+
] : [
|
|
47
|
+
min.x,
|
|
48
|
+
min.y,
|
|
49
|
+
max.x,
|
|
50
|
+
max.y
|
|
51
|
+
]).join(",");
|
|
52
|
+
const url = new URL(super.getTileUrl(coords));
|
|
53
|
+
for (const [k, v] of Object.entries({
|
|
54
|
+
...this.wmsParams,
|
|
55
|
+
bbox
|
|
56
|
+
})) url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, v);
|
|
57
|
+
return url.toString();
|
|
58
|
+
}
|
|
59
|
+
setParams(params, noRedraw) {
|
|
60
|
+
Object.assign(this.wmsParams, params);
|
|
61
|
+
if (!noRedraw) this.redraw();
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
export { WMSTileLayer };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=WMSTileLayer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WMSTileLayer.js","names":["Browser"],"sources":["../../../../src/layer/tile/WMSTileLayer.js"],"sourcesContent":["import {TileLayer} from './TileLayer.js';\nimport Browser from '../../core/Browser.js';\nimport {EPSG4326} from '../../geo/crs/EPSG4326.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n\n/*\n * @class WMSTileLayer\n * @inherits TileLayer\n * Used to display [WMS](https://en.wikipedia.org/wiki/Web_Map_Service) services as tile layers on the map. Extends `TileLayer`.\n *\n * @example\n *\n * ```js\n * const nexrad = new WMSTileLayer(\"http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi\", {\n * \tlayers: 'nexrad-n0r-900913',\n * \tformat: 'image/png',\n * \ttransparent: true,\n * \tattribution: \"Weather data © 2012 IEM Nexrad\"\n * });\n * ```\n */\n\n// @constructor WMSTileLayer(baseUrl: String, options: WMSTileLayer options)\n// Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS parameters/options object.\nexport class WMSTileLayer extends TileLayer {\n\n\tstatic {\n\t\t// @section\n\t\t// @aka WMSTileLayer options\n\t\t// If any custom options not documented here are used, they will be sent to the\n\t\t// WMS server as extra parameters in each request URL. This can be useful for\n\t\t// [non-standard vendor WMS parameters](https://docs.geoserver.org/stable/en/user/services/wms/vendor.html).\n\t\tthis.prototype.defaultWmsParams = {\n\t\t\tservice: 'WMS',\n\t\t\trequest: 'GetMap',\n\n\t\t\t// @option layers: String = ''\n\t\t\t// **(required)** Comma-separated list of WMS layers to show.\n\t\t\tlayers: '',\n\n\t\t\t// @option styles: String = ''\n\t\t\t// Comma-separated list of WMS styles.\n\t\t\tstyles: '',\n\n\t\t\t// @option format: String = 'image/jpeg'\n\t\t\t// WMS image format (use `'image/png'` for layers with transparency).\n\t\t\tformat: 'image/jpeg',\n\n\t\t\t// @option transparent: Boolean = false\n\t\t\t// If `true`, the WMS service will return images with transparency.\n\t\t\ttransparent: false,\n\n\t\t\t// @option version: String = '1.1.1'\n\t\t\t// Version of the WMS service to use\n\t\t\tversion: '1.1.1'\n\t\t};\n\n\t\tthis.setDefaultOptions({\n\t\t\t// @option crs: CRS = null\n\t\t\t// Coordinate Reference System to use for the WMS requests, defaults to\n\t\t\t// map CRS. Don't change this if you're not sure what it means.\n\t\t\tcrs: null,\n\n\t\t\t// @option uppercase: Boolean = false\n\t\t\t// If `true`, WMS request parameter keys will be uppercase.\n\t\t\tuppercase: false\n\t\t});\n\t}\n\n\tconstructor(url, options) {\n\t\tsuper(url, options);\n\n\t\tconst wmsParams = {...this.defaultWmsParams};\n\n\t\t// Options that are unknown in the prototype chain are considered WMS params.\n\t\tfor (const [key, value] of Object.entries(options)) {\n\t\t\tif (!(key in WMSTileLayer.prototype.options)) {\n\t\t\t\twmsParams[key] = value;\n\t\t\t}\n\t\t}\n\n\t\tconst realRetina = this.options.detectRetina && Browser.retina ? 2 : 1;\n\t\tconst tileSize = this.getTileSize();\n\n\t\twmsParams.width = tileSize.x * realRetina;\n\t\twmsParams.height = tileSize.y * realRetina;\n\n\t\tthis.wmsParams = wmsParams;\n\n\t\tthis.callInitHooks(WMSTileLayer);\n\t}\n\n\tonAdd(map) {\n\n\t\tthis._crs = this.options.crs ?? map.options.crs;\n\t\tthis._wmsVersion = parseFloat(this.wmsParams.version);\n\n\t\tconst projectionKey = this._wmsVersion >= 1.3 ? 'crs' : 'srs';\n\t\tthis.wmsParams[projectionKey] = this._crs.code;\n\n\t\tsuper.onAdd(map);\n\t}\n\n\tgetTileUrl(coords) {\n\n\t\tconst tileBounds = this._tileCoordsToNwSe(coords),\n\t\tcrs = this._crs,\n\t\tbounds = new Bounds(crs.project(tileBounds[0]), crs.project(tileBounds[1])),\n\t\tmin = bounds.min,\n\t\tmax = bounds.max,\n\t\tbbox = (this._wmsVersion >= 1.3 && this._crs === EPSG4326 ?\n\t\t\t[min.y, min.x, max.y, max.x] :\n\t\t\t[min.x, min.y, max.x, max.y]).join(',');\n\t\tconst url = new URL(super.getTileUrl(coords));\n\t\tfor (const [k, v] of Object.entries({...this.wmsParams, bbox})) {\n\t\t\turl.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, v);\n\t\t}\n\t\treturn url.toString();\n\t}\n\n\t// @method setParams(params: Object, noRedraw?: Boolean): this\n\t// Merges an object with the new parameters and re-requests tiles on the current screen (unless `noRedraw` was set to true).\n\tsetParams(params, noRedraw) {\n\n\t\tObject.assign(this.wmsParams, params);\n\n\t\tif (!noRedraw) {\n\t\t\tth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IAAI;GAAG,IAAI;GAAG,IAAI;GAAG,IAAI;EAAC,EAAA,CAAG,KAAK,GAAG;EACvC,MAAM,MAAM,IAAI,IAAI,MAAM,WAAW,MAAM,CAAC;EAC5C,KAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ;GAAC,GAAG,KAAK;GAAW;EAAI,CAAC,GAC5D,IAAI,aAAa,OAAO,KAAK,QAAQ,YAAY,EAAE,YAAY,IAAI,GAAG,CAAC;EAExE,OAAO,IAAI,SAAS;CACrB;CAIA,UAAU,QAAQ,UAAU;EAE3B,OAAO,OAAO,KAAK,WAAW,MAAM;EAEpC,IAAI,CAAC,UACJ,KAAK,OAAO;EAGb,OAAO;CACR;AACD"}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { stamp } from "../../core/Util.js";
|
|
2
|
+
import { on } from "../../dom/DomEvent.js";
|
|
3
|
+
import { Bounds } from "../../geometry/Bounds.js";
|
|
4
|
+
import { Renderer } from "./Renderer.js";
|
|
5
|
+
//#region src/layer/vector/Canvas.js
|
|
6
|
+
const DASH_SEPARATOR_RE = /[, ]+/;
|
|
7
|
+
var Canvas = class Canvas extends Renderer {
|
|
8
|
+
static {
|
|
9
|
+
this.setDefaultOptions({ tolerance: 0 });
|
|
10
|
+
}
|
|
11
|
+
constructor(...args) {
|
|
12
|
+
super(...args);
|
|
13
|
+
this.callInitHooks(Canvas);
|
|
14
|
+
}
|
|
15
|
+
getEvents() {
|
|
16
|
+
const events = super.getEvents();
|
|
17
|
+
events.viewprereset = this._onViewPreReset;
|
|
18
|
+
return events;
|
|
19
|
+
}
|
|
20
|
+
_onViewPreReset() {
|
|
21
|
+
this._postponeUpdatePaths = true;
|
|
22
|
+
}
|
|
23
|
+
onAdd(map) {
|
|
24
|
+
super.onAdd(map);
|
|
25
|
+
this._draw();
|
|
26
|
+
}
|
|
27
|
+
onRemove() {
|
|
28
|
+
super.onRemove();
|
|
29
|
+
clearTimeout(this._pointerHoverThrottleTimeout);
|
|
30
|
+
}
|
|
31
|
+
_initContainer() {
|
|
32
|
+
const container = this._container = document.createElement("canvas");
|
|
33
|
+
on(container, "pointermove", this._onPointerMove, this);
|
|
34
|
+
on(container, "click dblclick pointerdown pointerup contextmenu", this._onClick, this);
|
|
35
|
+
on(container, "pointerout", this._handlePointerOut, this);
|
|
36
|
+
container["_maplair_disable_events"] = true;
|
|
37
|
+
this._ctx = container.getContext("2d");
|
|
38
|
+
}
|
|
39
|
+
_destroyContainer() {
|
|
40
|
+
cancelAnimationFrame(this._redrawRequest);
|
|
41
|
+
this._redrawRequest = null;
|
|
42
|
+
delete this._ctx;
|
|
43
|
+
super._destroyContainer();
|
|
44
|
+
}
|
|
45
|
+
_resizeContainer() {
|
|
46
|
+
const size = super._resizeContainer();
|
|
47
|
+
const m = this._ctxScale = window.devicePixelRatio;
|
|
48
|
+
this._container.width = m * size.x;
|
|
49
|
+
this._container.height = m * size.y;
|
|
50
|
+
}
|
|
51
|
+
_updatePaths() {
|
|
52
|
+
if (this._postponeUpdatePaths) return;
|
|
53
|
+
this._redrawBounds = null;
|
|
54
|
+
for (const layer of Object.values(this._layers)) layer._update();
|
|
55
|
+
this._redraw();
|
|
56
|
+
}
|
|
57
|
+
_update() {
|
|
58
|
+
if (this._map._animatingZoom && this._bounds) return;
|
|
59
|
+
const b = this._bounds, s = this._ctxScale;
|
|
60
|
+
this._ctx.setTransform(s, 0, 0, s, -b.min.x * s, -b.min.y * s);
|
|
61
|
+
this.fire("update");
|
|
62
|
+
}
|
|
63
|
+
_reset() {
|
|
64
|
+
super._reset();
|
|
65
|
+
if (this._postponeUpdatePaths) {
|
|
66
|
+
this._postponeUpdatePaths = false;
|
|
67
|
+
this._updatePaths();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
_initPath(layer) {
|
|
71
|
+
this._updateDashArray(layer);
|
|
72
|
+
this._layers[stamp(layer)] = layer;
|
|
73
|
+
const order = layer._order = {
|
|
74
|
+
layer,
|
|
75
|
+
prev: this._drawLast,
|
|
76
|
+
next: null
|
|
77
|
+
};
|
|
78
|
+
if (this._drawLast) this._drawLast.next = order;
|
|
79
|
+
this._drawLast = order;
|
|
80
|
+
this._drawFirst ??= this._drawLast;
|
|
81
|
+
}
|
|
82
|
+
_addPath(layer) {
|
|
83
|
+
this._requestRedraw(layer);
|
|
84
|
+
}
|
|
85
|
+
_removePath(layer) {
|
|
86
|
+
const order = layer._order;
|
|
87
|
+
const next = order.next;
|
|
88
|
+
const prev = order.prev;
|
|
89
|
+
if (next) next.prev = prev;
|
|
90
|
+
else this._drawLast = prev;
|
|
91
|
+
if (prev) prev.next = next;
|
|
92
|
+
else this._drawFirst = next;
|
|
93
|
+
delete layer._order;
|
|
94
|
+
delete this._layers[stamp(layer)];
|
|
95
|
+
this._requestRedraw(layer);
|
|
96
|
+
}
|
|
97
|
+
_updatePath(layer) {
|
|
98
|
+
this._extendRedrawBounds(layer);
|
|
99
|
+
layer._project();
|
|
100
|
+
layer._update();
|
|
101
|
+
this._requestRedraw(layer);
|
|
102
|
+
}
|
|
103
|
+
_updateStyle(layer) {
|
|
104
|
+
this._updateDashArray(layer);
|
|
105
|
+
this._requestRedraw(layer);
|
|
106
|
+
}
|
|
107
|
+
_updateDashArray(layer) {
|
|
108
|
+
if (typeof layer.options.dashArray === "string") {
|
|
109
|
+
const parts = layer.options.dashArray.split(DASH_SEPARATOR_RE);
|
|
110
|
+
layer.options._dashArray = parts.map((n) => Number(n)).filter((n) => !isNaN(n));
|
|
111
|
+
} else layer.options._dashArray = layer.options.dashArray;
|
|
112
|
+
}
|
|
113
|
+
_requestRedraw(layer) {
|
|
114
|
+
if (!this._map) return;
|
|
115
|
+
this._extendRedrawBounds(layer);
|
|
116
|
+
this._redrawRequest ??= requestAnimationFrame(this._redraw.bind(this));
|
|
117
|
+
}
|
|
118
|
+
_extendRedrawBounds(layer) {
|
|
119
|
+
if (layer._pxBounds) {
|
|
120
|
+
const padding = (layer.options.weight ?? 0) + 1;
|
|
121
|
+
this._redrawBounds ??= new Bounds();
|
|
122
|
+
this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));
|
|
123
|
+
this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
_redraw() {
|
|
127
|
+
this._redrawRequest = null;
|
|
128
|
+
if (this._redrawBounds) {
|
|
129
|
+
this._redrawBounds.min._floor();
|
|
130
|
+
this._redrawBounds.max._ceil();
|
|
131
|
+
}
|
|
132
|
+
this._clear();
|
|
133
|
+
this._draw();
|
|
134
|
+
this._redrawBounds = null;
|
|
135
|
+
}
|
|
136
|
+
_clear() {
|
|
137
|
+
const bounds = this._redrawBounds;
|
|
138
|
+
if (bounds) {
|
|
139
|
+
const size = bounds.getSize();
|
|
140
|
+
this._ctx.clearRect(bounds.min.x, bounds.min.y, size.x, size.y);
|
|
141
|
+
} else {
|
|
142
|
+
this._ctx.save();
|
|
143
|
+
this._ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
144
|
+
this._ctx.clearRect(0, 0, this._container.width, this._container.height);
|
|
145
|
+
this._ctx.restore();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
_draw() {
|
|
149
|
+
let layer;
|
|
150
|
+
const bounds = this._redrawBounds;
|
|
151
|
+
this._ctx.save();
|
|
152
|
+
if (bounds) {
|
|
153
|
+
const size = bounds.getSize();
|
|
154
|
+
this._ctx.beginPath();
|
|
155
|
+
this._ctx.rect(bounds.min.x, bounds.min.y, size.x, size.y);
|
|
156
|
+
this._ctx.clip();
|
|
157
|
+
}
|
|
158
|
+
this._drawing = true;
|
|
159
|
+
for (let order = this._drawFirst; order; order = order.next) {
|
|
160
|
+
layer = order.layer;
|
|
161
|
+
if (!bounds || layer._pxBounds && layer._pxBounds.intersects(bounds)) layer._updatePath();
|
|
162
|
+
}
|
|
163
|
+
this._drawing = false;
|
|
164
|
+
this._ctx.restore();
|
|
165
|
+
}
|
|
166
|
+
_updatePoly(layer, closed) {
|
|
167
|
+
if (!this._drawing) return;
|
|
168
|
+
const parts = layer._parts, ctx = this._ctx;
|
|
169
|
+
if (!parts.length) return;
|
|
170
|
+
ctx.beginPath();
|
|
171
|
+
parts.forEach((p0) => {
|
|
172
|
+
p0.forEach((p, j) => {
|
|
173
|
+
ctx[j ? "lineTo" : "moveTo"](p.x, p.y);
|
|
174
|
+
});
|
|
175
|
+
if (closed) ctx.closePath();
|
|
176
|
+
});
|
|
177
|
+
this._fillStroke(ctx, layer);
|
|
178
|
+
}
|
|
179
|
+
_updateCircle(layer) {
|
|
180
|
+
if (!this._drawing || layer._empty()) return;
|
|
181
|
+
const p = layer._point, ctx = this._ctx, r = Math.max(Math.round(layer._pxRadius), 1), s = (Math.max(Math.round(layer._pxRadiusY), 1) || r) / r;
|
|
182
|
+
if (s !== 1) {
|
|
183
|
+
ctx.save();
|
|
184
|
+
ctx.scale(1, s);
|
|
185
|
+
}
|
|
186
|
+
ctx.beginPath();
|
|
187
|
+
ctx.arc(p.x, p.y / s, r, 0, Math.PI * 2, false);
|
|
188
|
+
if (s !== 1) ctx.restore();
|
|
189
|
+
this._fillStroke(ctx, layer);
|
|
190
|
+
}
|
|
191
|
+
_fillStroke(ctx, layer) {
|
|
192
|
+
const options = layer.options;
|
|
193
|
+
if (options.fill) {
|
|
194
|
+
ctx.globalAlpha = options.fillOpacity;
|
|
195
|
+
ctx.fillStyle = options.fillColor ?? options.color;
|
|
196
|
+
ctx.fill(options.fillRule || "evenodd");
|
|
197
|
+
}
|
|
198
|
+
if (options.stroke && options.weight !== 0) {
|
|
199
|
+
ctx.lineDashOffset = Number(options.dashOffset ?? 0);
|
|
200
|
+
ctx.setLineDash(options._dashArray ?? []);
|
|
201
|
+
ctx.globalAlpha = options.opacity;
|
|
202
|
+
ctx.lineWidth = options.weight;
|
|
203
|
+
ctx.strokeStyle = options.color;
|
|
204
|
+
ctx.lineCap = options.lineCap;
|
|
205
|
+
ctx.lineJoin = options.lineJoin;
|
|
206
|
+
ctx.stroke();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
_onClick(e) {
|
|
210
|
+
const point = this._map.pointerEventToLayerPoint(e);
|
|
211
|
+
let layer, clickedLayer;
|
|
212
|
+
for (let order = this._drawFirst; order; order = order.next) {
|
|
213
|
+
layer = order.layer;
|
|
214
|
+
if (layer.options.interactive && layer._containsPoint(point)) {
|
|
215
|
+
if (!(e.type === "click" || e.type === "preclick") || !this._map._draggableMoved(layer)) clickedLayer = layer;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
this._fireEvent(clickedLayer ? [clickedLayer] : false, e);
|
|
219
|
+
}
|
|
220
|
+
_onPointerMove(e) {
|
|
221
|
+
if (!this._map || this._map.dragging.moving() || this._map._animatingZoom) return;
|
|
222
|
+
const point = this._map.pointerEventToLayerPoint(e);
|
|
223
|
+
this._handlePointerHover(e, point);
|
|
224
|
+
}
|
|
225
|
+
_handlePointerOut(e) {
|
|
226
|
+
const layer = this._hoveredLayer;
|
|
227
|
+
if (layer) {
|
|
228
|
+
this._container.classList.remove("maplair-interactive");
|
|
229
|
+
this._fireEvent([layer], e, "pointerout");
|
|
230
|
+
this._hoveredLayer = null;
|
|
231
|
+
this._pointerHoverThrottled = false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
_handlePointerHover(e, point) {
|
|
235
|
+
if (this._pointerHoverThrottled) return;
|
|
236
|
+
let layer, candidateHoveredLayer;
|
|
237
|
+
for (let order = this._drawFirst; order; order = order.next) {
|
|
238
|
+
layer = order.layer;
|
|
239
|
+
if (layer.options.interactive && layer._containsPoint(point)) candidateHoveredLayer = layer;
|
|
240
|
+
}
|
|
241
|
+
if (candidateHoveredLayer !== this._hoveredLayer) {
|
|
242
|
+
this._handlePointerOut(e);
|
|
243
|
+
if (candidateHoveredLayer) {
|
|
244
|
+
this._container.classList.add("maplair-interactive");
|
|
245
|
+
this._fireEvent([candidateHoveredLayer], e, "pointerover");
|
|
246
|
+
this._hoveredLayer = candidateHoveredLayer;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
this._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);
|
|
250
|
+
this._pointerHoverThrottled = true;
|
|
251
|
+
this._pointerHoverThrottleTimeout = setTimeout((() => {
|
|
252
|
+
this._pointerHoverThrottled = false;
|
|
253
|
+
}), 32);
|
|
254
|
+
}
|
|
255
|
+
_fireEvent(layers, e, type) {
|
|
256
|
+
this._map._fireDOMEvent(e, type || e.type, layers);
|
|
257
|
+
}
|
|
258
|
+
_bringToFront(layer) {
|
|
259
|
+
const order = layer._order;
|
|
260
|
+
if (!order) return;
|
|
261
|
+
const next = order.next;
|
|
262
|
+
const prev = order.prev;
|
|
263
|
+
if (next) next.prev = prev;
|
|
264
|
+
else return;
|
|
265
|
+
if (prev) prev.next = next;
|
|
266
|
+
else if (next) this._drawFirst = next;
|
|
267
|
+
order.prev = this._drawLast;
|
|
268
|
+
this._drawLast.next = order;
|
|
269
|
+
order.next = null;
|
|
270
|
+
this._drawLast = order;
|
|
271
|
+
this._requestRedraw(layer);
|
|
272
|
+
}
|
|
273
|
+
_bringToBack(layer) {
|
|
274
|
+
const order = layer._order;
|
|
275
|
+
if (!order) return;
|
|
276
|
+
const next = order.next;
|
|
277
|
+
const prev = order.prev;
|
|
278
|
+
if (prev) prev.next = next;
|
|
279
|
+
else return;
|
|
280
|
+
if (next) next.prev = prev;
|
|
281
|
+
else if (prev) this._drawLast = prev;
|
|
282
|
+
order.prev = null;
|
|
283
|
+
order.next = this._drawFirst;
|
|
284
|
+
this._drawFirst.prev = order;
|
|
285
|
+
this._drawFirst = order;
|
|
286
|
+
this._requestRedraw(layer);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
//#endregion
|
|
290
|
+
export { Canvas };
|
|
291
|
+
|
|
292
|
+
//# sourceMappingURL=Canvas.js.map
|
|
@@ -0,0 +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\nconst DASH_SEPARATOR_RE = /[, ]+/;\n\n/*\n * @class Canvas\n * @inherits Renderer\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 *\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 */\n\n// @constructor Canvas(options?: Renderer options)\n// Creates a Canvas renderer with the given options.\nexport class Canvas extends Renderer {\n\n\tstatic {\n\t\t// @section\n\t\t// @aka Canvas options\n\t\tthis.setDefaultOptions({\n\t\t\t// @option tolerance: Number = 0\n\t\t\t// How much to extend the click tolerance around a path/object on the map.\n\t\t\ttolerance: 0\n\t\t});\n\t}\n\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Canvas);\n\t}\n\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\t\tevents.viewprereset = this._onViewPreReset;\n\t\treturn events;\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\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\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.options._dashArray = parts.map(n => Number(n)).filter(n => !isNaN(n));\n\t\t} else {\n\t\t\tlayer.options._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\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 p = layer._point,\n\t\tctx = this._ctx,\n\t\tr = Math.max(Math.round(layer._pxRadius), 1),\n\t\ts = (Math.max(Math.round(layer._pxRadiusY), 1) || r) / r;\n\n\t\tif (s !== 1) {\n\t\t\tctx.save();\n\t\t\tctx.scale(1, s);\n\t\t}\n\n\t\tctx.beginPath();\n\t\tctx.arc(p.x, p.y / s, r, 0, Math.PI * 2, false);\n\n\t\tif (s !== 1) {\n\t\t\tctx.restore();\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(options._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// 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._requestRedraw(layer);\n\t}\n}\n"],"mappings":";;;;;AAKA,MAAM,oBAAoB;AA+B1B,IAAa,SAAb,MAAa,eAAe,SAAS;CAEpC;EAGC,KAAK,kBAAkB,EAGtB,WAAW,EACZ,CAAC;CACF;CAEA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,MAAM;CAC1B;CAEA,YAAY;EACX,MAAM,SAAS,MAAM,UAAU;EAC/B,OAAO,eAAe,KAAK;EAC3B,OAAO;CACR;CAEA,kBAAkB;EAEjB,KAAK,uBAAuB;CAC7B;CAEA,MAAM,KAAK;EACV,MAAM,MAAM,GA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ACtB;EACD;EAEA,KAAK,WAAW,KAAK,gBAAgB,CAAC,KAAK,aAAa,IAAI,OAAO,CAAC;EAEpE,KAAK,yBAAyB;EAC9B,KAAK,+BAA+B,kBAAkB;GACrD,KAAK,yBAAyB;EAC/B,IAAI,EAAE;CACP;CAEA,WAAW,QAAQ,GAAG,MAAM;EAC3B,KAAK,KAAK,cAAc,GAAG,QAAQ,EAAE,MAAM,MAAM;CAClD;CAEA,cAAc,OAAO;EACpB,MAAM,QAAQ,MAAM;EAEpB,IAAI,CAAC,OAAS;EAEd,MAAM,OAAO,MAAM;EACnB,MAAM,OAAO,MAAM;EAEnB,IAAI,MACH,KAAK,OAAO;OAGZ;EAED,IAAI,MACH,KAAK,OAAO;OACN,IAAI,MAGV,KAAK,aAAa;EAGnB,MAAM,OAAO,KAAK;EAClB,KAAK,UAAU,OAAO;EAEtB,MAAM,OAAO;EACb,KAAK,YAAY;EAEjB,KAAK,eAAe,KAAK;CAC1B;CAEA,aAAa,OAAO;EACnB,MAAM,QAAQ,MAAM;EAEpB,IAAI,CAAC,OAAS;EAEd,MAAM,OAAO,MAAM;EACnB,MAAM,OAAO,MAAM;EAEnB,IAAI,MACH,KAAK,OAAO;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"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LatLngBounds } from "../../geo/LatLngBounds.js";
|
|
2
|
+
import { EarthCRS } from "../../geo/crs/EarthCRS.js";
|
|
3
|
+
import { CircleMarker } from "./CircleMarker.js";
|
|
4
|
+
//#region src/layer/vector/Circle.js
|
|
5
|
+
var Circle = class Circle extends CircleMarker {
|
|
6
|
+
constructor(latlng, options) {
|
|
7
|
+
super(latlng, options);
|
|
8
|
+
if (isNaN(this.options.radius)) throw new Error("Circle radius cannot be NaN");
|
|
9
|
+
this.callInitHooks(Circle);
|
|
10
|
+
}
|
|
11
|
+
getBounds() {
|
|
12
|
+
const half = [this._pxRadius, this._pxRadiusY ?? this._pxRadius];
|
|
13
|
+
return new LatLngBounds(this._map.layerPointToLatLng(this._point.subtract(half)), this._map.layerPointToLatLng(this._point.add(half)));
|
|
14
|
+
}
|
|
15
|
+
_project() {
|
|
16
|
+
const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs;
|
|
17
|
+
if (crs.distance === EarthCRS.distance) {
|
|
18
|
+
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;
|
|
19
|
+
let lngR = Math.acos((Math.cos(latR * d) - Math.sin(lat * d) * Math.sin(lat2 * d)) / (Math.cos(lat * d) * Math.cos(lat2 * d))) / d;
|
|
20
|
+
if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(Math.PI / 180 * lat);
|
|
21
|
+
this._point = p.subtract(map.getPixelOrigin());
|
|
22
|
+
this._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x;
|
|
23
|
+
this._pxRadiusY = p.y - top.y;
|
|
24
|
+
} else {
|
|
25
|
+
const latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));
|
|
26
|
+
this._point = map.latLngToLayerPoint(this._latlng);
|
|
27
|
+
this._pxRadius = Math.abs(this._point.x - map.latLngToLayerPoint(latlng2).x);
|
|
28
|
+
}
|
|
29
|
+
this._updateBounds();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { Circle };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=Circle.js.map
|
|
@@ -0,0 +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\n\n/*\n * @class Circle\n * @inherits CircleMarker\n *\n * A class for drawing circle overlays on a map with radius specified in meters. Extends `CircleMarker`.\n *\n * It's an approximation and starts to diverge from a real circle closer to poles (due to projection distortion).\n *\n * @example\n *\n * ```js\n * new Circle([50.5, 30.5], {radius: 200}).addTo(map);\n * ```\n */\n\n// @constructor Circle(latlng: LatLng, options?: Circle options)\n// Instantiates a circle object given a geographical point, and an options object\n// which contains the circle radius.\nexport class Circle extends CircleMarker {\n\n\tconstructor(latlng, options) {\n\t\tsuper(latlng, options);\n\n\t\tif (isNaN(this.options.radius)) { throw new Error('Circle radius cannot be NaN'); }\n\n\t\t// @section\n\t\t// @aka Circle options\n\t\t// @option radius: Number; Radius of the circle, in meters.\n\n\t\tthis.callInitHooks(Circle);\n\t}\n\n\t// @method setRadius(radius: Number): this\n\t// Sets the radius of a circle. Units are in meters.\n\t// @method getRadius(): Number\n\t// Returns the current radius of a circle. Units are in meters.\n\n\t// @method getBounds(): LatLngBounds\n\t// Returns the `LatLngBounds` of the path.\n\tgetBounds() {\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\tlet lngR = Math.acos((Math.cos(latR * d) - Math.sin(lat * d) * Math.sin(lat2 * d)) /\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(Math.PI / 180 * lat); // Fallback for edge case, #2425\n\t\t\t}\n\n\t\t\tthis._point = p.subtract(map.getPixelOrigin());\n\t\t\tthis._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).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 = map.latLngToLayerPoint(this._latlng);\n\t\t\tthis._pxRadius = Math.abs(this._point.x - map.latLngToLayerPoint(latlng2).x);\n\t\t}\n\n\t\tthis._updateBounds();\n\t}\n}\n"],"mappings":";;;;AAuBA,IAAa,SAAb,MAAa,eAAe,aAAa;CAExC,YAAY,QAAQ,SAAS;EAC5B,MAAM,QAAQ,OAAO;EAErB,IAAI,MAAM,KAAK,QAAQ,MAAM,GAAK,MAAM,IAAI,MAAM,6BAA6B;EAM/E,KAAK,cAAc,MAAM;CAC1B;CASA,YAAY;EACX,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,CAAC;CACrD;CAEA,WAAW;EAEV,MAAM,MAAM,KAAK,QAAQ,KACzB,MAAM,KAAK,QAAQ,KACnB,MAAM,KAAK,MACX,MAAM,IAAI,QAAQ;EAElB,IAAI,IAAI,aAAa,SAAS,UAAU;GACvC,MAAM,IAAI,KAAK,KAAK,KACpB,OAAQ,KAAK,UAAU,SAAS,IAAK,GACrC,MAAM,IAAI,QAAQ,CAAC,MAAM,MAAM,GAAG,CAAC,GACnC,SAAS,IAAI,QAAQ,CAAC,MAAM,MAAM,GAAG,CAAC,GACtC,IAAI,IAAI,IAAI,MAAM,CAAC,CAAC,SAAS,CAAC,GAC9B,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC;GACxB,IAAI,OAAO,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC,MACtE,KAAK,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC,EAAE,IAAI;GAErD,IAAI,MAAM,IAAI,KAAK,SAAS,GAC3B,OAAO,OAAO,KAAK,IAAI,KAAK,KAAK,MAAM,GAAG;GAG3C,KAAK,SAAS,EAAE,SAAS,IAAI,eAAe,CAAC;GAC7C,KAAK,YAAY,MAAM,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,QAAQ,CAAC,MAAM,MAAM,IAAI,CAAC,CAAC,CAAC;GACzE,KAAK,aAAa,EAAE,IAAI,IAAI;EAE7B,OAAO;GACN,MAAM,UAAU,IAAI,UAAU,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC;GAEnF,KAAK,SAAS,IAAI,mBAAmB,KAAK,OAAO;GACjD,KAAK,YAAY,KAAK,IAAI,KAAK,OAAO,IAAI,IAAI,mBAAmB,OAAO,CAAC,CAAC,CAAC;EAC5E;EAEA,KAAK,cAAc;CACpB;AACD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { setOptions } from "../../core/Util.js";
|
|
2
|
+
import { Bounds } from "../../geometry/Bounds.js";
|
|
3
|
+
import { LatLng } from "../../geo/LatLng.js";
|
|
4
|
+
import { Path } from "./Path.js";
|
|
5
|
+
//#region src/layer/vector/CircleMarker.js
|
|
6
|
+
var CircleMarker = class CircleMarker extends Path {
|
|
7
|
+
static {
|
|
8
|
+
this.setDefaultOptions({
|
|
9
|
+
fill: true,
|
|
10
|
+
radius: 10
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
constructor(latlng, options) {
|
|
14
|
+
super();
|
|
15
|
+
setOptions(this, options);
|
|
16
|
+
this._latlng = new LatLng(latlng);
|
|
17
|
+
this._radius = this.options.radius;
|
|
18
|
+
this.callInitHooks(CircleMarker);
|
|
19
|
+
}
|
|
20
|
+
setLatLng(latlng) {
|
|
21
|
+
const oldLatLng = this._latlng;
|
|
22
|
+
this._latlng = new LatLng(latlng);
|
|
23
|
+
this.redraw();
|
|
24
|
+
return this.fire("move", {
|
|
25
|
+
oldLatLng,
|
|
26
|
+
latlng: this._latlng
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
getLatLng() {
|
|
30
|
+
return this._latlng;
|
|
31
|
+
}
|
|
32
|
+
setRadius(radius) {
|
|
33
|
+
this.options.radius = this._radius = radius;
|
|
34
|
+
return this.redraw();
|
|
35
|
+
}
|
|
36
|
+
getRadius() {
|
|
37
|
+
return this._radius;
|
|
38
|
+
}
|
|
39
|
+
setStyle(options) {
|
|
40
|
+
super.setStyle(options);
|
|
41
|
+
if (options?.radius !== void 0) this.setRadius(options.radius);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
_project() {
|
|
45
|
+
this._point = this._map.latLngToLayerPoint(this._latlng);
|
|
46
|
+
this._pxRadius = this._radius;
|
|
47
|
+
this._updateBounds();
|
|
48
|
+
}
|
|
49
|
+
_updateBounds() {
|
|
50
|
+
const r = this._pxRadius, r2 = this._pxRadiusY ?? r, w = this._clickTolerance(), p = [r + w, r2 + w];
|
|
51
|
+
this._pxBounds = new Bounds(this._point.subtract(p), this._point.add(p));
|
|
52
|
+
}
|
|
53
|
+
_update() {
|
|
54
|
+
if (this._map) this._updatePath();
|
|
55
|
+
}
|
|
56
|
+
_updatePath() {
|
|
57
|
+
this._renderer._updateCircle(this);
|
|
58
|
+
}
|
|
59
|
+
_empty() {
|
|
60
|
+
return this._pxRadius && !this._renderer._bounds.intersects(this._pxBounds);
|
|
61
|
+
}
|
|
62
|
+
_containsPoint(p) {
|
|
63
|
+
return p.distanceTo(this._point) <= this._pxRadius + this._clickTolerance();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { CircleMarker };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=CircleMarker.js.map
|
|
@@ -0,0 +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';\n\n\n/*\n * @class CircleMarker\n * @inherits Path\n *\n * A circle of a fixed size with radius specified in CSS pixels. Extends `Path`.\n */\n\n// @constructor CircleMarker(latlng: LatLng, options?: CircleMarker options)\n// Instantiates a circle marker object given a geographical point, and an optional options object.\nexport class CircleMarker extends Path {\n\n\tstatic {\n\t\t// @section\n\t\t// @aka CircleMarker options\n\t\tthis.setDefaultOptions({\n\t\t\tfill: true,\n\n\t\t\t// @option radius: Number = 10\n\t\t\t// Radius of the circle marker, in CSS pixels\n\t\t\tradius: 10\n\t\t});\n\t}\n\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// @method setLatLng(latLng: LatLng): this\n\t// Sets the position of a circle marker to a new location.\n\tsetLatLng(latlng) {\n\t\tconst oldLatLng = this._latlng;\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis.redraw();\n\n\t\t// @event move: Event\n\t\t// Fired when the marker is moved via [`setLatLng`](#circlemarker-setlatlng). Old and new coordinates are included in event arguments as `oldLatLng`, `latlng`.\n\t\treturn this.fire('move', {oldLatLng, latlng: this._latlng});\n\t}\n\n\t// @method getLatLng(): LatLng\n\t// Returns the current geographical position of the circle marker\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t// @method setRadius(radius: Number): this\n\t// Sets the radius of a circle marker. Units are in CSS pixels.\n\tsetRadius(radius) {\n\t\tthis.options.radius = this._radius = radius;\n\t\treturn this.redraw();\n\t}\n\n\t// @method getRadius(): Number\n\t// Returns the current radius of the circle. Units are in CSS pixels.\n\tgetRadius() {\n\t\treturn this._radius;\n\t}\n\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\tthis._point = this._map.latLngToLayerPoint(this._latlng);\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"],"mappings":";;;;;AAeA,IAAa,eAAb,MAAa,qBAAqB,KAAK;CAEtC;EAGC,KAAK,kBAAkB;GACtB,MAAM;GAIN,QAAQ;EACT,CAAC;CACF;CAEA,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;CAIA,UAAU,QAAQ;EACjB,MAAM,YAAY,KAAK;EACvB,KAAK,UAAU,IAAI,OAAO,MAAM;EAChC,KAAK,OAAO;EAIZ,OAAO,KAAK,KAAK,QAAQ;GAAC;GAAW,QAAQ,KAAK;EAAO,CAAC;CAC3D;CAIA,YAAY;EACX,OAAO,KAAK;CACb;CAIA,UAAU,QAAQ;EACjB,KAAK,QAAQ,SAAS,KAAK,UAAU;EACrC,OAAO,KAAK,OAAO;CACpB;CAIA,YAAY;EACX,OAAO,KAAK;CACb;CAEA,SAAS,SAAS;EACjB,MAAM,SAAS,OAAO;EACtB,IAAI,SAAS,WAAW,KAAA,GACvB,KAAK,UAAU,QAAQ,MAAM;EAE9B,OAAO;CACR;CAEA,WAAW;EACV,KAAK,SAAS,KAAK,KAAK,mBAAmB,KAAK,OAAO;EACvD,KAAK,YAAY,KAAK;EACtB,KAAK,cAAc;CACpB;CAEA,gBAAgB;EACf,MAAM,IAAI,KAAK,WACf,KAAK,KAAK,cAAc,GACxB,IAAI,KAAK,gBAAgB,GACzB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;EAClB,KAAK,YAAY,IAAI,OAAO,KAAK,OAAO,SAAS,CAAC,GAAG,KAAK,OAAO,IAAI,CAAC,CAAC;CACxE;CAEA,UAAU;EACT,IAAI,KAAK,MACR,KAAK,YAAY;CAEnB;CAEA,cAAc;EACb,KAAK,UAAU,cAAc,IAAI;CAClC;CAEA,SAAS;EACR,OAAO,KAAK,aAAa,CAAC,KAAK,UAAU,QAAQ,WAAW,KAAK,SAAS;CAC3E;CAGA,eAAe,GAAG;EACjB,OAAO,EAAE,WAAW,KAAK,MAAM,KAAK,KAAK,YAAY,KAAK,gBAAgB;CAC3E;AACD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { setOptions } from "../../core/Util.js";
|
|
2
|
+
import { Layer } from "../Layer.js";
|
|
3
|
+
//#region src/layer/vector/Path.js
|
|
4
|
+
var Path = class extends Layer {
|
|
5
|
+
static {
|
|
6
|
+
this.setDefaultOptions({
|
|
7
|
+
stroke: true,
|
|
8
|
+
color: "#3388ff",
|
|
9
|
+
weight: 3,
|
|
10
|
+
opacity: 1,
|
|
11
|
+
lineCap: "round",
|
|
12
|
+
lineJoin: "round",
|
|
13
|
+
dashArray: null,
|
|
14
|
+
dashOffset: null,
|
|
15
|
+
fill: false,
|
|
16
|
+
fillColor: null,
|
|
17
|
+
fillOpacity: .2,
|
|
18
|
+
fillRule: "evenodd",
|
|
19
|
+
interactive: true,
|
|
20
|
+
bubblingPointerEvents: true
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
beforeAdd(map) {
|
|
24
|
+
this._renderer = map.getRenderer(this);
|
|
25
|
+
}
|
|
26
|
+
onAdd() {
|
|
27
|
+
this._renderer._initPath(this);
|
|
28
|
+
this._reset();
|
|
29
|
+
this._renderer._addPath(this);
|
|
30
|
+
}
|
|
31
|
+
onRemove() {
|
|
32
|
+
this._renderer._removePath(this);
|
|
33
|
+
}
|
|
34
|
+
redraw() {
|
|
35
|
+
if (this._map) this._renderer._updatePath(this);
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
setStyle(style) {
|
|
39
|
+
setOptions(this, style);
|
|
40
|
+
if (this._renderer) {
|
|
41
|
+
this._renderer._updateStyle(this);
|
|
42
|
+
if (this.options.stroke && style && Object.hasOwn(style, "weight")) this._updateBounds();
|
|
43
|
+
}
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
bringToFront() {
|
|
47
|
+
this._renderer?._bringToFront(this);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
bringToBack() {
|
|
51
|
+
this._renderer?._bringToBack(this);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
getElement() {
|
|
55
|
+
return this._path;
|
|
56
|
+
}
|
|
57
|
+
_reset() {
|
|
58
|
+
this._project();
|
|
59
|
+
this._update();
|
|
60
|
+
}
|
|
61
|
+
_clickTolerance() {
|
|
62
|
+
return (this.options.stroke ? this.options.weight / 2 : 0) + (this._renderer.options.tolerance || 0);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
export { Path };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=Path.js.map
|