maplair 4.0.0 → 4.1.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 +118 -0
- package/dist/esm/Maplair.js +14 -14
- package/dist/esm/control/AttributionControl.js +24 -14
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +9 -11
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -3
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +9 -16
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +5 -7
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +144 -35
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +7 -9
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +14 -16
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +1 -3
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -9
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +99 -17
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +1 -3
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +5 -7
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +408 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +5 -7
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -37
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +21 -8
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +13 -11
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/Util.js +13 -1
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +8 -42
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +14 -68
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +17 -18
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +3 -25
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +15 -5
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3395.js +1 -1
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +1 -1
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +1 -1
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +2 -2
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +36 -30
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +8 -27
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +6 -8
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +15 -20
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/GeoJSON.js +9 -145
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +75 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +15 -17
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +20 -26
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +8 -10
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +51 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +26 -42
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +2 -5
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +15 -17
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +12 -15
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +15 -48
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +7 -9
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +7 -10
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +1 -2
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +61 -33
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +6 -8
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +85 -97
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +28 -36
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +1 -3
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +2 -2
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +17 -7
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +27 -20
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +20 -4
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
- package/dist/esm/layer/vector/Polyline.js +23 -7
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +5 -5
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +10 -6
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +116 -110
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +6 -8
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +19 -19
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +35 -35
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +12 -5
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +8009 -7369
- 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 +10040 -9381
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +148 -98
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/cs.json +6 -0
- package/i18n/de.json +6 -0
- package/i18n/en.json +6 -0
- package/i18n/es.json +6 -0
- package/i18n/fr.json +6 -0
- package/i18n/hu.json +6 -0
- package/i18n/it.json +6 -0
- package/i18n/rm.json +6 -0
- package/i18n/sk.json +6 -0
- package/i18n/sl.json +6 -0
- package/package.json +9 -11
- package/src/control/AttributionControl.js +25 -18
- package/src/control/ButtonControl.js +9 -11
- package/src/control/ContextMenu.js +3 -5
- package/src/control/Control.js +9 -19
- package/src/control/FullscreenControl.js +5 -7
- package/src/control/LayersControl.js +159 -36
- package/src/control/LegendControl.js +7 -9
- package/src/control/MiniMapControl.js +9 -11
- package/src/control/RotateControl.js +3 -5
- package/src/control/ScaleControl.js +7 -9
- package/src/control/SearchControl.js +102 -19
- package/src/control/SideBySideControl.js +3 -5
- package/src/control/TextControl.js +5 -7
- package/src/control/TimeControl.js +471 -0
- package/src/control/ZoomControl.js +5 -7
- package/src/control/index.js +1 -0
- package/src/core/Class.js +35 -34
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +14 -12
- package/src/core/Util.js +19 -1
- package/src/core/index.js +0 -1
- package/src/dom/DomEvent.DoubleTap.js +18 -10
- package/src/dom/DomEvent.PointerEvents.js +3 -26
- package/src/dom/DomEvent.js +8 -66
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +27 -22
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +20 -3
- package/src/geo/crs/EPSG3395.js +1 -1
- package/src/geo/crs/EPSG3857.js +1 -1
- package/src/geo/crs/EPSG4326.js +1 -1
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +1 -1
- package/src/geo/projection/Projection.LonLat.js +1 -1
- package/src/geo/projection/Projection.Mercator.js +1 -1
- package/src/geo/projection/Projection.SphericalMercator.js +1 -1
- package/src/geometry/LineUtil.js +47 -48
- package/src/geometry/PolyUtil.js +14 -43
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +15 -26
- package/src/layer/GeoJSON.js +7 -205
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +9 -11
- package/src/layer/ImageOverlay.js +19 -30
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +71 -0
- package/src/layer/Popup.js +28 -43
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +15 -19
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +15 -61
- package/src/layer/marker/DivIcon.js +9 -11
- package/src/layer/marker/Icon.js +7 -10
- package/src/layer/marker/Marker.Drag.js +1 -1
- package/src/layer/marker/Marker.Move.js +1 -2
- package/src/layer/marker/Marker.js +81 -39
- package/src/layer/marker/MarkerClusterGroup.js +370 -0
- package/src/layer/marker/SvgIcon.js +7 -9
- package/src/layer/marker/index.js +1 -0
- package/src/layer/tile/GridLayer.js +103 -133
- package/src/layer/tile/TileLayer.js +35 -43
- package/src/layer/tile/WMSTileLayer.js +26 -24
- package/src/layer/vector/Canvas.js +3 -5
- package/src/layer/vector/Circle.js +5 -2
- package/src/layer/vector/CircleMarker.js +17 -6
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +28 -5
- package/src/layer/vector/Polyline.js +25 -6
- package/src/layer/vector/Renderer.getRenderer.js +17 -17
- package/src/layer/vector/SVG.js +5 -5
- package/src/map/Map.Rotation.js +12 -4
- package/src/map/Map.js +142 -133
- package/src/map/handler/BoxZoomHandler.js +9 -8
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +25 -28
- package/src/map/handler/KeyboardHandler.js +42 -48
- package/src/map/handler/PinchZoomHandler.js +16 -5
- package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
- package/src/map/handler/TapHoldHandler.js +15 -4
- package/src/map/index.js +1 -1
- package/src/maplair.css +148 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/images/layers.svg +0 -1
- package/dist/images/marker-icon.svg +0 -1
- package/dist/images/marker-shadow.svg +0 -1
- package/src/core/Browser.js +0 -110
- package/src/images/layers.svg +0 -1
- package/src/images/marker-icon.svg +0 -1
- package/src/images/marker-shadow.svg +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import Browser_default from "../../core/Browser.js";
|
|
1
|
+
import { setOptions, template } from "../../core/Util.js";
|
|
3
2
|
import { on } from "../../dom/DomEvent.js";
|
|
4
3
|
import { I18n } from "../../core/I18n.js";
|
|
5
4
|
import { GridLayer } from "./GridLayer.js";
|
|
@@ -7,6 +6,14 @@ import { GridLayer } from "./GridLayer.js";
|
|
|
7
6
|
/** @import {Point} from '../../geometry/Point.js' */
|
|
8
7
|
/** @import {GridLayerOptions, TileDoneCallback} from './GridLayer.js' */
|
|
9
8
|
/** @import {TileEvent} from '../../core/Events.js' */
|
|
9
|
+
const osmHosts = ["tile.openstreetmap.org", "tile.osm.org"];
|
|
10
|
+
const hostRe = /^(https?:)?\/\/([^/?#:]*)/i;
|
|
11
|
+
const httpRe = /^http:/i;
|
|
12
|
+
function isOSMUrl(url) {
|
|
13
|
+
const host = hostRe.exec(url)?.[2] ?? "";
|
|
14
|
+
return osmHosts.some((osmHost) => host === osmHost || host.endsWith(`.${osmHost}`));
|
|
15
|
+
}
|
|
16
|
+
const upgradeOSMUrl = (url) => isOSMUrl(url) ? url.replace(httpRe, "https:") : url;
|
|
10
17
|
/**
|
|
11
18
|
* Options of `TileLayer`.
|
|
12
19
|
* @typedef {object} TileLayerOptions
|
|
@@ -87,21 +94,19 @@ import { GridLayer } from "./GridLayer.js";
|
|
|
87
94
|
* @fires tileabort {TileEvent} Fired when a tile was loading but is now not wanted.
|
|
88
95
|
*/
|
|
89
96
|
var TileLayer = class TileLayer extends GridLayer {
|
|
90
|
-
static {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
}
|
|
97
|
+
static defaultOptions = {
|
|
98
|
+
minZoom: 0,
|
|
99
|
+
maxZoom: 18,
|
|
100
|
+
subdomains: "abc",
|
|
101
|
+
errorTileUrl: "",
|
|
102
|
+
zoomOffset: 0,
|
|
103
|
+
tms: false,
|
|
104
|
+
zoomReverse: false,
|
|
105
|
+
detectRetina: false,
|
|
106
|
+
crossOrigin: false,
|
|
107
|
+
referrerPolicy: "strict-origin-when-cross-origin",
|
|
108
|
+
fetchOptions: null
|
|
109
|
+
};
|
|
105
110
|
/**
|
|
106
111
|
* Instantiates a tile layer object given a [URL template](#tilelayer) and optionally an
|
|
107
112
|
* options object.
|
|
@@ -111,17 +116,9 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
111
116
|
*/
|
|
112
117
|
constructor(url, options) {
|
|
113
118
|
super(options);
|
|
114
|
-
this._url = url;
|
|
115
119
|
options = setOptions(this, options);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (["tile.openstreetmap.org", "tile.osm.org"].some((host) => urlHostname.endsWith(host))) {
|
|
119
|
-
if (options.attribution === null) options.attribution = `© <a href="https://www.openstreetmap.org/copyright">${I18n.translate("OpenStreetMap contributors")}</a>`;
|
|
120
|
-
if (tileUrl.protocol === "http:") {
|
|
121
|
-
tileUrl.protocol = "https:";
|
|
122
|
-
this._url = tileUrl.toString();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
120
|
+
if (isOSMUrl(url) && options.attribution === null) options.attribution = `© <a href="https://www.openstreetmap.org/copyright">${I18n.translate("OpenStreetMap contributors")}</a>`;
|
|
121
|
+
this._url = upgradeOSMUrl(url);
|
|
125
122
|
const { tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom } = this.options;
|
|
126
123
|
this._nonRetinaOptions = {
|
|
127
124
|
tileSize,
|
|
@@ -133,12 +130,11 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
133
130
|
};
|
|
134
131
|
this._applyRetina();
|
|
135
132
|
if (typeof this.options.subdomains === "string") this.options.subdomains = this.options.subdomains.split("");
|
|
136
|
-
this.on("tileunload", this._onTileRemove);
|
|
137
133
|
this.callInitHooks(TileLayer);
|
|
138
134
|
}
|
|
139
135
|
_applyRetina() {
|
|
140
136
|
Object.assign(this.options, this._nonRetinaOptions);
|
|
141
|
-
this._retina =
|
|
137
|
+
this._retina = window.devicePixelRatio > 1;
|
|
142
138
|
if (this.options.detectRetina && this._retina && this.options.maxZoom > 0) {
|
|
143
139
|
this.options.tileSize = Math.floor(this.options.tileSize / 2);
|
|
144
140
|
if (!this.options.zoomReverse) {
|
|
@@ -164,7 +160,7 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
164
160
|
return events;
|
|
165
161
|
}
|
|
166
162
|
_onPixelRatioChange() {
|
|
167
|
-
if (
|
|
163
|
+
if (window.devicePixelRatio > 1 === this._retina) return;
|
|
168
164
|
const map = this._map;
|
|
169
165
|
this._applyRetina();
|
|
170
166
|
if (this.options.detectRetina) {
|
|
@@ -184,6 +180,7 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
184
180
|
* @returns {this}
|
|
185
181
|
*/
|
|
186
182
|
setUrl(url, noRedraw) {
|
|
183
|
+
url = upgradeOSMUrl(url);
|
|
187
184
|
if (this._url === url && noRedraw === void 0) noRedraw = true;
|
|
188
185
|
this._url = url;
|
|
189
186
|
if (!noRedraw) {
|
|
@@ -247,7 +244,7 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
247
244
|
getTileUrl(coords) {
|
|
248
245
|
const data = Object.create(this.options);
|
|
249
246
|
Object.assign(data, {
|
|
250
|
-
r:
|
|
247
|
+
r: window.devicePixelRatio > 1 ? "@2x" : "",
|
|
251
248
|
s: this._getSubdomain(coords),
|
|
252
249
|
x: coords.x,
|
|
253
250
|
y: coords.y,
|
|
@@ -269,9 +266,6 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
269
266
|
if (errorUrl && tile.getAttribute("src") !== errorUrl) tile.src = errorUrl;
|
|
270
267
|
done(e, tile);
|
|
271
268
|
}
|
|
272
|
-
_onTileRemove(e) {
|
|
273
|
-
e.tile.onload = null;
|
|
274
|
-
}
|
|
275
269
|
_getZoomForUrl() {
|
|
276
270
|
let zoom = this._tileZoom;
|
|
277
271
|
const maxZoom = this.options.maxZoom, zoomReverse = this.options.zoomReverse, zoomOffset = this.options.zoomOffset;
|
|
@@ -286,8 +280,6 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
286
280
|
let i, tile;
|
|
287
281
|
for (i of Object.keys(this._tiles)) if (this._tiles[i].coords.z !== this._tileZoom) {
|
|
288
282
|
tile = this._tiles[i].el;
|
|
289
|
-
tile.onload = falseFn;
|
|
290
|
-
tile.onerror = falseFn;
|
|
291
283
|
if (this._abortTileFetch(tile) || !tile.complete) {
|
|
292
284
|
tile.setAttribute("src", "");
|
|
293
285
|
const coords = this._tiles[i].coords;
|
|
@@ -1 +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/** @import {Point} from '../../geometry/Point.js' */\n/** @import {GridLayerOptions, TileDoneCallback} from './GridLayer.js' */\n/** @import {TileEvent} from '../../core/Events.js' */\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 {\n\t\tthis.setDefaultOptions({\n\t\t\tminZoom: 0,\n\t\t\tmaxZoom: 18,\n\t\t\tsubdomains: 'abc',\n\t\t\terrorTileUrl: '',\n\t\t\tzoomOffset: 0,\n\t\t\ttms: false,\n\t\t\tzoomReverse: false,\n\t\t\tdetectRetina: false,\n\t\t\tcrossOrigin: false,\n\t\t\treferrerPolicy: 'strict-origin-when-cross-origin',\n\t\t\tfetchOptions: null\n\n\t\t});\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\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\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.on('tileunload', this._onTileRemove);\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 = Browser.retina;\n\n\t\tif (this.options.detectRetina && this._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\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 (Browser.retina === 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\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: 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\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\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 (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}\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,IAAa,YAAb,MAAa,kBAAkB,UAAU;CAExC;EACC,KAAK,kBAAkB;GACtB,SAAS;GACT,SAAS;GACT,YAAY;GACZ,cAAc;GACd,YAAY;GACZ,KAAK;GACL,aAAa;GACb,cAAc;GACd,aAAa;GACb,gBAAgB;GAChB,cAAc;EAEf,CAAC;CACF;;;;;;;;CASA,YAAY,KAAK,SAA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GACd,KAAK,UAAUA;GAEf,IAAI,KAAK,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,QAAS,QAAQ,KAAK,aAAa,KAAK,MAAM,IACvD;EAGD,OAAO,MAAM,WAAW,QAAQ,KAAK,IAAI;CAC1C;CAEA,WAAW,MAAM;EAChB,OAAO,KAAK,MAAM,MAAM,WAAW,IAAI,CAAC;CACzC;AACD"}
|
|
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';\n/** @import {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\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\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\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_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\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}\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}\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,IAAI,aACH,OAAO,UAAU;EAGlB,OAAO,OAAO;CACf;CAEA,cAAc,WAAW;EACxB,MAAM,QAAQ,KAAK,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,WAAW;EAC5E,OAAO,KAAK,QAAQ,WAAW;CAChC;CAGA,gBAAgB;EACf,IAAI,GAAG;EACP,KAAK,KAAK,OAAO,KAAK,KAAK,MAAM,GAChC,IAAI,KAAK,OAAO,EAAE,CAAC,OAAO,MAAM,KAAK,WAAW;GAC/C,OAAO,KAAK,OAAO,EAAE,CAAC;GAEtB,IAAI,KAAK,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,QAAS,QAAQ,KAAK,aAAa,KAAK,MAAM,IACvD;EAGD,OAAO,MAAM,WAAW,QAAQ,KAAK,IAAI;CAC1C;CAEA,WAAW,MAAM;EAChB,OAAO,KAAK,MAAM,MAAM,WAAW,IAAI,CAAC;CACzC;AACD"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import Browser_default from "../../core/Browser.js";
|
|
2
1
|
import { Bounds } from "../../geometry/Bounds.js";
|
|
3
2
|
import { EPSG4326 } from "../../geo/crs/EPSG4326.js";
|
|
4
3
|
import { TileLayer } from "./TileLayer.js";
|
|
@@ -42,21 +41,23 @@ import { TileLayer } from "./TileLayer.js";
|
|
|
42
41
|
* ```
|
|
43
42
|
*/
|
|
44
43
|
var WMSTileLayer = class WMSTileLayer extends TileLayer {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
44
|
+
/**
|
|
45
|
+
* The default WMS parameters, which the options override, see `WMSTileLayerOptions`.
|
|
46
|
+
* @type {Record<string, any>}
|
|
47
|
+
*/
|
|
48
|
+
static defaultWmsParams = {
|
|
49
|
+
service: "WMS",
|
|
50
|
+
request: "GetMap",
|
|
51
|
+
layers: "",
|
|
52
|
+
styles: "",
|
|
53
|
+
format: "image/jpeg",
|
|
54
|
+
transparent: false,
|
|
55
|
+
version: "1.1.1"
|
|
56
|
+
};
|
|
57
|
+
static defaultOptions = {
|
|
58
|
+
crs: null,
|
|
59
|
+
uppercase: false
|
|
60
|
+
};
|
|
60
61
|
/**
|
|
61
62
|
* Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS
|
|
62
63
|
* parameters/options object.
|
|
@@ -66,8 +67,8 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
|
|
|
66
67
|
*/
|
|
67
68
|
constructor(url, options) {
|
|
68
69
|
super(url, options);
|
|
69
|
-
const wmsParams = { ...
|
|
70
|
-
for (const [key, value] of Object.entries(options)) if (!(key in WMSTileLayer.
|
|
70
|
+
const wmsParams = { ...WMSTileLayer.defaultWmsParams };
|
|
71
|
+
for (const [key, value] of Object.entries(options)) if (!(key in WMSTileLayer.defaultOptions)) wmsParams[key] = value;
|
|
71
72
|
/**
|
|
72
73
|
* The parameters of the WMS requests, see `setParams()`.
|
|
73
74
|
* @type {Record<string, any>}
|
|
@@ -77,7 +78,7 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
|
|
|
77
78
|
this.callInitHooks(WMSTileLayer);
|
|
78
79
|
}
|
|
79
80
|
_updateWmsSize() {
|
|
80
|
-
const realRetina = this.options.detectRetina &&
|
|
81
|
+
const realRetina = this.options.detectRetina && window.devicePixelRatio > 1 ? 2 : 1;
|
|
81
82
|
const tileSize = this.getTileSize();
|
|
82
83
|
this.wmsParams.width = tileSize.x * realRetina;
|
|
83
84
|
this.wmsParams.height = tileSize.y * realRetina;
|
|
@@ -128,11 +129,11 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
|
|
|
128
129
|
max.x,
|
|
129
130
|
max.y
|
|
130
131
|
]).join(",");
|
|
131
|
-
const url = new URL(super.getTileUrl(coords));
|
|
132
|
+
const url = new URL(super.getTileUrl(coords), document.baseURI);
|
|
132
133
|
for (const [k, v] of Object.entries({
|
|
133
134
|
...this.wmsParams,
|
|
134
135
|
bbox
|
|
135
|
-
})) url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, v);
|
|
136
|
+
})) url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, `${v}`);
|
|
136
137
|
return url.toString();
|
|
137
138
|
}
|
|
138
139
|
/**
|
|
@@ -159,14 +160,18 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
|
|
|
159
160
|
}
|
|
160
161
|
/**
|
|
161
162
|
* Merges an object with the new parameters and re-requests tiles on the current screen
|
|
162
|
-
* (unless `noRedraw` was set to true).
|
|
163
|
+
* (unless `noRedraw` was set to true). The current tiles stay visible until the new
|
|
164
|
+
* tiles have loaded, to avoid flickering.
|
|
163
165
|
* @param {Record<string, any>} params
|
|
164
166
|
* @param {boolean} [noRedraw]
|
|
165
167
|
* @returns {this}
|
|
166
168
|
*/
|
|
167
169
|
setParams(params, noRedraw) {
|
|
168
170
|
Object.assign(this.wmsParams, params);
|
|
169
|
-
if (!noRedraw)
|
|
171
|
+
if (!noRedraw) {
|
|
172
|
+
this._keepCurrentTiles();
|
|
173
|
+
this.redraw();
|
|
174
|
+
}
|
|
170
175
|
return this;
|
|
171
176
|
}
|
|
172
177
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WMSTileLayer.js","names":[
|
|
1
|
+
{"version":3,"file":"WMSTileLayer.js","names":[],"sources":["../../../../src/layer/tile/WMSTileLayer.js"],"sourcesContent":["import {TileLayer} from './TileLayer.js';\nimport {EPSG4326} from '../../geo/crs/EPSG4326.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {CRS} from '../../geo/crs/CRS.js' */\n/** @import {Point} from '../../geometry/Point.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {TileLayerOptions} from './TileLayer.js' */\n\n/**\n * Options of `WMSTileLayer`. If any custom options not documented here are used, they\n * will be sent to the WMS server as extra parameters in each request URL. This can be\n * useful for\n * [non-standard vendor WMS parameters](https://docs.geoserver.org/stable/en/user/services/wms/vendor.html).\n * @typedef {object} WMSTileLayerOptions\n * @property {string} [layers=''] **(required)** Comma-separated list of WMS layers to\n * show.\n * @property {string} [styles=''] Comma-separated list of WMS styles.\n * @property {string} [format='image/jpeg'] WMS image format (use `'image/png'` for\n * layers with transparency).\n * @property {boolean} [transparent=false] If `true`, the WMS service will return images\n * with transparency.\n * @property {string} [version='1.1.1'] Version of the WMS service to use.\n * @property {CRS|null} [crs=null] Coordinate Reference System to use for the WMS\n * requests, defaults to map CRS. Don't change this if you're not sure what it means.\n * @property {boolean} [uppercase=false] If `true`, WMS request parameter keys will be\n * uppercase.\n * @extends TileLayerOptions\n */\n\n/**\n * Used to display [WMS](https://en.wikipedia.org/wiki/Web_Map_Service) services as tile\n * layers on the map. Extends `TileLayer`.\n *\n * @example\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 */\nexport class WMSTileLayer extends TileLayer {\n\n\t/**\n\t * The default WMS parameters, which the options override, see `WMSTileLayerOptions`.\n\t * @type {Record<string, any>}\n\t */\n\tstatic defaultWmsParams = {\n\t\tservice: 'WMS',\n\t\trequest: 'GetMap',\n\t\tlayers: '',\n\t\tstyles: '',\n\t\tformat: 'image/jpeg',\n\t\ttransparent: false,\n\t\tversion: '1.1.1'\n\t};\n\n\tstatic defaultOptions = {\n\t\tcrs: null,\n\t\tuppercase: false\n\t};\n\n\t/**\n\t * Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS\n\t * parameters/options object.\n\t * @param {string} url The base URL of the WMS service.\n\t * @param {WMSTileLayerOptions & Record<string, unknown>} options The options and WMS\n\t * parameters.\n\t */\n\tconstructor(url, options) {\n\t\tsuper(url, options);\n\n\t\tconst wmsParams = {...WMSTileLayer.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.defaultOptions)) {\n\t\t\t\twmsParams[key] = value;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * The parameters of the WMS requests, see `setParams()`.\n\t\t * @type {Record<string, any>}\n\t\t */\n\t\tthis.wmsParams = wmsParams;\n\t\tthis._updateWmsSize();\n\n\t\tthis.callInitHooks(WMSTileLayer);\n\t}\n\n\t// The size of the requested images: the tile size, doubled on retina displays with `detectRetina`.\n\t_updateWmsSize() {\n\t\tconst realRetina = this.options.detectRetina && window.devicePixelRatio > 1 ? 2 : 1;\n\t\tconst tileSize = this.getTileSize();\n\n\t\tthis.wmsParams.width = tileSize.x * realRetina;\n\t\tthis.wmsParams.height = tileSize.y * realRetina;\n\t}\n\n\t_applyRetina() {\n\t\tsuper._applyRetina();\n\t\tif (this.wmsParams) {\n\t\t\tthis._updateWmsSize();\n\t\t}\n\t}\n\n\t/**\n\t * Uses the CRS of the map (unless the `crs` option is set) and loads the tiles.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tthis._updateCrs();\n\t\tsuper.onAdd(map);\n\t}\n\n\t_updateCrs() {\n\t\tthis._crs = this.options.crs ?? this._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\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.crschange = this._updateCrs;\n\t\treturn events;\n\t}\n\n\t/**\n\t * Called only internally, returns the URL of the `GetMap` request for a tile given its\n\t * coordinates.\n\t * @group Extension methods\n\t * @param {Point} coords\n\t * @returns {string}\n\t */\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), document.baseURI);\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/**\n\t * Returns the URL of the legend image (a `GetLegendGraphic` request) of the first\n\t * of the `layers` (with its style, if any), with the version, format and `uppercase`\n\t * option of the layer. `params` change or add parameters, e.g. `{layer: 'roads',\n\t * width: 20, height: 20}` or vendor parameters like `legend_options`.\n\t * @param {Record<string, any>} [params]\n\t * @returns {string}\n\t */\n\tgetLegendUrl(params) {\n\t\tconst {version, format, layers, styles} = this.wmsParams,\n\t\turl = new URL(this._url, document.baseURI);\n\t\tfor (const [k, v] of Object.entries({\n\t\t\tservice: 'WMS',\n\t\t\trequest: 'GetLegendGraphic',\n\t\t\tversion,\n\t\t\tformat,\n\t\t\tlayer: layers.split(',')[0],\n\t\t\tstyle: styles?.split(',')[0] || undefined,\n\t\t\t// required by the WMS 1.3 profile of SLD\n\t\t\tsld_version: parseFloat(version) >= 1.3 ? '1.1.0' : undefined,\n\t\t\t...params\n\t\t})) {\n\t\t\tif (v !== undefined) {\n\t\t\t\turl.searchParams.set(this.options.uppercase ? k.toUpperCase() : k, v);\n\t\t\t}\n\t\t}\n\t\treturn url.toString();\n\t}\n\n\t/**\n\t * Merges an object with the new parameters and re-requests tiles on the current screen\n\t * (unless `noRedraw` was set to true). The current tiles stay visible until the new\n\t * tiles have loaded, to avoid flickering.\n\t * @param {Record<string, any>} params\n\t * @param {boolean} [noRedraw]\n\t * @returns {this}\n\t */\n\tsetParams(params, noRedraw) {\n\n\t\tObject.assign(this.wmsParams, params);\n\n\t\tif (!noRedraw) {\n\t\t\tthis._keepCurrentTiles();\n\t\t\tthis.redraw();\n\t\t}\n\n\t\treturn this;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,eAAb,MAAa,qBAAqB,UAAU;;;;;CAM3C,OAAO,mBAAmB;EACzB,SAAS;EACT,SAAS;EACT,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,aAAa;EACb,SAAS;CACV;CAEA,OAAO,iBAAiB;EACvB,KAAK;EACL,WAAW;CACZ;;;;;;;;CASA,YAAY,KAAK,SAAS;EACzB,MAAM,KAAK,OAAO;EAElB,MAAM,YAAY,EAAC,GAAG,aAAa,iBAAgB;EAGnD,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,GAChD,IAAI,EAAE,OAAO,aAAa,iBACzB,UAAU,OAAO;;;;;EAQnB,KAAK,YAAY;EACjB,KAAK,eAAe;EAEpB,KAAK,cAAc,YAAY;CAChC;CAGA,iBAAiB;EAChB,MAAM,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O,IAAI,SAAS;CACrB;;;;;;;;;CAUA,aAAa,QAAQ;EACpB,MAAM,EAAC,SAAS,QAAQ,QAAQ,WAAU,KAAK,WAC/C,MAAM,IAAI,IAAI,KAAK,MAAM,SAAS,OAAO;EACzC,KAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ;GACnC,SAAS;GACT,SAAS;GACT;GACA;GACA,OAAO,OAAO,MAAM,GAAG,CAAC,CAAC;GACzB,OAAO,QAAQ,MAAM,GAAG,CAAC,CAAC,MAAM,KAAA;GAEhC,aAAa,WAAW,OAAO,KAAK,MAAM,UAAU,KAAA;GACpD,GAAG;EACJ,CAAC,GACA,IAAI,MAAM,KAAA,GACT,IAAI,aAAa,IAAI,KAAK,QAAQ,YAAY,EAAE,YAAY,IAAI,GAAG,CAAC;EAGtE,OAAO,IAAI,SAAS;CACrB;;;;;;;;;CAUA,UAAU,QAAQ,UAAU;EAE3B,OAAO,OAAO,KAAK,WAAW,MAAM;EAEpC,IAAI,CAAC,UAAU;GACd,KAAK,kBAAkB;GACvB,KAAK,OAAO;EACb;EAEA,OAAO;CACR;AACD"}
|
|
@@ -37,9 +37,7 @@ const DASH_SEPARATOR_RE = /[, ]+/;
|
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
var Canvas = class Canvas extends Renderer {
|
|
40
|
-
static {
|
|
41
|
-
this.setDefaultOptions({ tolerance: 0 });
|
|
42
|
-
}
|
|
40
|
+
static defaultOptions = { tolerance: 0 };
|
|
43
41
|
/**
|
|
44
42
|
* Creates a Canvas renderer with the given options.
|
|
45
43
|
* @overload
|
|
@@ -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 {\n\t\tthis.setDefaultOptions({\n\t\t\ttolerance: 0\n\t\t});\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.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\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 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// 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._requestRedraw(layer);\n\t}\n}\n"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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"}
|
|
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.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\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 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// 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._requestRedraw(layer);\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgC1B,IAAa,SAAb,MAAa,eAAe,SAAS;CAEpC,OAAO,iBAAiB,EACvB,WAAW,EACZ;;;;;;;;;CAUA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,MAAM;CAC1B;;;;;CAMA,YAAY;EACX,MAAM,SAAS,MAAM,UAAU;EAC/B,OAAO,eAAe,KAAK;EAC3B,OAAO,mBAAmB,KAAK;EAC/B,OAAO;CACR;CAGA,sBAAsB;EACrB,KAAK,iBAAiB;EACtB,KAAK,QAAQ;CACd;CAEA,kBAAkB;EAEjB,KAAK,uBAAuB;CAC7B;;;;;CAMA,MAAM,KAAK;EACV,MAAM,MAAM,GAAG;EAIf,KAAK,MAAM;CACZ;;;;CAKA,WAAW;EACV,MAAM,SAAS;EAEf,aAAa,KAAK,4BAA4B;CAC/C;CAEA,iBAAiB;EAChB,MAAM,YAAY,KAAK,aAAa,SAAS,cAAc,QAAQ;EAEnE,GAAY,WAAW,eAAe,KAAK,gBAAgB,IAAI;EAC/D,GAAY,WAAW,oDAAoD,KAAK,UAAU,IAAI;EAC9F,GAAY,WAA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AAK,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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LatLngBounds } from "../../geo/LatLngBounds.js";
|
|
2
|
-
import { EarthCRS } from "../../geo/crs/EarthCRS.js";
|
|
3
2
|
import { CircleMarker } from "./CircleMarker.js";
|
|
3
|
+
import { EarthCRS } from "../../geo/crs/EarthCRS.js";
|
|
4
4
|
//#region src/layer/vector/Circle.js
|
|
5
5
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
6
6
|
/** @import {CircleMarkerOptions} from './CircleMarker.js' */
|
|
@@ -46,7 +46,7 @@ var Circle = class Circle extends CircleMarker {
|
|
|
46
46
|
const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs;
|
|
47
47
|
if (crs.distance === EarthCRS.distance) {
|
|
48
48
|
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;
|
|
49
|
-
let lngR = Math.
|
|
49
|
+
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;
|
|
50
50
|
if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(Math.PI / 180 * lat);
|
|
51
51
|
this._point = p.subtract(map.getPixelOrigin());
|
|
52
52
|
this._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x;
|
|
@@ -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\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.\n\t * @returns {LatLngBounds}\n\t */\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.
|
|
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\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.\n\t * @returns {LatLngBounds}\n\t */\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\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(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\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,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"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { setOptions } from "../../core/Util.js";
|
|
2
|
-
import { Path } from "./Path.js";
|
|
3
2
|
import { Bounds } from "../../geometry/Bounds.js";
|
|
3
|
+
import { Path } from "./Path.js";
|
|
4
4
|
import { LatLng } from "../../geo/LatLng.js";
|
|
5
|
+
import { pointToGeoJSON } from "../GeoJSONUtil.js";
|
|
5
6
|
//#region src/layer/vector/CircleMarker.js
|
|
7
|
+
/** @import {Feature} from 'geojson' */
|
|
6
8
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
7
9
|
/** @import {MaplairEvent} from '../../core/Events.js' */
|
|
8
10
|
/** @import {PathOptions} from './Path.js' */
|
|
@@ -28,12 +30,10 @@ import { LatLng } from "../../geo/LatLng.js";
|
|
|
28
30
|
* event arguments as `oldLatLng`, `latlng`.
|
|
29
31
|
*/
|
|
30
32
|
var CircleMarker = class CircleMarker extends Path {
|
|
31
|
-
static {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
}
|
|
33
|
+
static defaultOptions = {
|
|
34
|
+
fill: true,
|
|
35
|
+
radius: 10
|
|
36
|
+
};
|
|
37
37
|
/**
|
|
38
38
|
* Instantiates a circle marker object given a geographical point, and an optional
|
|
39
39
|
* options object.
|
|
@@ -115,6 +115,16 @@ var CircleMarker = class CircleMarker extends Path {
|
|
|
115
115
|
_containsPoint(p) {
|
|
116
116
|
return p.distanceTo(this._point) <= this._pxRadius + this._clickTolerance();
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
120
|
+
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
121
|
+
* representation of the circle marker (as a GeoJSON `Point` Feature).
|
|
122
|
+
* @param {number|false} [precision]
|
|
123
|
+
* @returns {Feature}
|
|
124
|
+
*/
|
|
125
|
+
toGeoJSON(precision) {
|
|
126
|
+
return pointToGeoJSON(this, precision);
|
|
127
|
+
}
|
|
118
128
|
};
|
|
119
129
|
//#endregion
|
|
120
130
|
export { CircleMarker };
|
|
@@ -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';\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 {\n\t\
|
|
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\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\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,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;;;;;;CAOA,UAAU,QAAQ;EACjB,MAAM,YAAY,KAAK;EACvB,KAAK,UAAU,IAAI,OAAO,MAAM;EAChC,KAAK,OAAO;EAEZ,OAAO,KAAK,KAAK,QAAQ;GAAC;GAAW,QAAQ,KAAK;EAAO,CAAC;CAC3D;;;;;CAMA,YAAY;EACX,OAAO,KAAK;CACb;;;;;;CAOA,UAAU,QAAQ;EACjB,KAAK,QAAQ,SAAS,KAAK,UAAU;EACrC,OAAO,KAAK,OAAO;CACpB;;;;;CAMA,YAAY;EACX,OAAO,KAAK;CACb;;;;;;CAOA,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,K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