maplair 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2804 -0
- package/LICENSE +27 -0
- package/README.md +40 -0
- package/dist/esm/Maplair.js +71 -0
- package/dist/esm/Maplair.js.map +1 -0
- package/dist/esm/_virtual/_rolldown/runtime.js +13 -0
- package/dist/esm/control/AttributionControl.js +79 -0
- package/dist/esm/control/AttributionControl.js.map +1 -0
- package/dist/esm/control/Control.js +81 -0
- package/dist/esm/control/Control.js.map +1 -0
- package/dist/esm/control/LayersControl.js +220 -0
- package/dist/esm/control/LayersControl.js.map +1 -0
- package/dist/esm/control/ScaleControl.js +72 -0
- package/dist/esm/control/ScaleControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +86 -0
- package/dist/esm/control/ZoomControl.js.map +1 -0
- package/dist/esm/core/Browser.js +31 -0
- package/dist/esm/core/Browser.js.map +1 -0
- package/dist/esm/core/Class.js +52 -0
- package/dist/esm/core/Class.js.map +1 -0
- package/dist/esm/core/Events.js +149 -0
- package/dist/esm/core/Events.js.map +1 -0
- package/dist/esm/core/Handler.js +32 -0
- package/dist/esm/core/Handler.js.map +1 -0
- package/dist/esm/core/I18n.js +36 -0
- package/dist/esm/core/I18n.js.map +1 -0
- package/dist/esm/core/Util.js +71 -0
- package/dist/esm/core/Util.js.map +1 -0
- package/dist/esm/dom/DomEvent.DoubleTap.js +74 -0
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -0
- package/dist/esm/dom/DomEvent.PointerEvents.js +46 -0
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -0
- package/dist/esm/dom/DomEvent.js +135 -0
- package/dist/esm/dom/DomEvent.js.map +1 -0
- package/dist/esm/dom/DomUtil.js +107 -0
- package/dist/esm/dom/DomUtil.js.map +1 -0
- package/dist/esm/dom/Draggable.js +107 -0
- package/dist/esm/dom/Draggable.js.map +1 -0
- package/dist/esm/dom/PosAnimation.js +56 -0
- package/dist/esm/dom/PosAnimation.js.map +1 -0
- package/dist/esm/geo/LatLng.js +65 -0
- package/dist/esm/geo/LatLng.js.map +1 -0
- package/dist/esm/geo/LatLngBounds.js +114 -0
- package/dist/esm/geo/LatLngBounds.js.map +1 -0
- package/dist/esm/geo/crs/CRS.js +51 -0
- package/dist/esm/geo/crs/CRS.js.map +1 -0
- package/dist/esm/geo/crs/EPSG3395.js +16 -0
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -0
- package/dist/esm/geo/crs/EPSG3857.js +19 -0
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -0
- package/dist/esm/geo/crs/EPSG4326.js +13 -0
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -0
- package/dist/esm/geo/crs/EarthCRS.js +14 -0
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -0
- package/dist/esm/geo/crs/SimpleCRS.js +23 -0
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -0
- package/dist/esm/geo/projection/Projection.LonLat.js +19 -0
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -0
- package/dist/esm/geo/projection/Projection.Mercator.js +33 -0
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -0
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +27 -0
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -0
- package/dist/esm/geo/projection/index.js +14 -0
- package/dist/esm/geo/projection/index.js.map +1 -0
- package/dist/esm/geometry/Bounds.js +91 -0
- package/dist/esm/geometry/Bounds.js.map +1 -0
- package/dist/esm/geometry/LineUtil.js +169 -0
- package/dist/esm/geometry/LineUtil.js.map +1 -0
- package/dist/esm/geometry/Point.js +119 -0
- package/dist/esm/geometry/Point.js.map +1 -0
- package/dist/esm/geometry/PolyUtil.js +89 -0
- package/dist/esm/geometry/PolyUtil.js.map +1 -0
- package/dist/esm/geometry/Transformation.js +34 -0
- package/dist/esm/geometry/Transformation.js.map +1 -0
- package/dist/esm/layer/BlanketOverlay.js +87 -0
- package/dist/esm/layer/BlanketOverlay.js.map +1 -0
- package/dist/esm/layer/DivOverlay.js +192 -0
- package/dist/esm/layer/DivOverlay.js.map +1 -0
- package/dist/esm/layer/FeatureGroup.js +40 -0
- package/dist/esm/layer/FeatureGroup.js.map +1 -0
- package/dist/esm/layer/GeoJSON.js +192 -0
- package/dist/esm/layer/GeoJSON.js.map +1 -0
- package/dist/esm/layer/ImageOverlay.js +140 -0
- package/dist/esm/layer/ImageOverlay.js.map +1 -0
- package/dist/esm/layer/Layer.js +119 -0
- package/dist/esm/layer/Layer.js.map +1 -0
- package/dist/esm/layer/LayerGroup.js +58 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -0
- package/dist/esm/layer/Popup.js +224 -0
- package/dist/esm/layer/Popup.js.map +1 -0
- package/dist/esm/layer/SVGOverlay.js +21 -0
- package/dist/esm/layer/SVGOverlay.js.map +1 -0
- package/dist/esm/layer/Tooltip.js +228 -0
- package/dist/esm/layer/Tooltip.js.map +1 -0
- package/dist/esm/layer/VideoOverlay.js +54 -0
- package/dist/esm/layer/VideoOverlay.js.map +1 -0
- package/dist/esm/layer/marker/DefaultIcon.js +50 -0
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -0
- package/dist/esm/layer/marker/DivIcon.js +37 -0
- package/dist/esm/layer/marker/DivIcon.js.map +1 -0
- package/dist/esm/layer/marker/Icon.js +65 -0
- package/dist/esm/layer/marker/Icon.js.map +1 -0
- package/dist/esm/layer/marker/Marker.Drag.js +77 -0
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -0
- package/dist/esm/layer/marker/Marker.js +235 -0
- package/dist/esm/layer/marker/Marker.js.map +1 -0
- package/dist/esm/layer/tile/GridLayer.js +447 -0
- package/dist/esm/layer/tile/GridLayer.js.map +1 -0
- package/dist/esm/layer/tile/TileLayer.js +139 -0
- package/dist/esm/layer/tile/TileLayer.js.map +1 -0
- package/dist/esm/layer/tile/WMSTileLayer.js +68 -0
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -0
- package/dist/esm/layer/vector/Canvas.js +292 -0
- package/dist/esm/layer/vector/Canvas.js.map +1 -0
- package/dist/esm/layer/vector/Circle.js +35 -0
- package/dist/esm/layer/vector/Circle.js.map +1 -0
- package/dist/esm/layer/vector/CircleMarker.js +69 -0
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -0
- package/dist/esm/layer/vector/Path.js +68 -0
- package/dist/esm/layer/vector/Path.js.map +1 -0
- package/dist/esm/layer/vector/Polygon.js +70 -0
- package/dist/esm/layer/vector/Polygon.js.map +1 -0
- package/dist/esm/layer/vector/Polyline.js +152 -0
- package/dist/esm/layer/vector/Polyline.js.map +1 -0
- package/dist/esm/layer/vector/Rectangle.js +25 -0
- package/dist/esm/layer/vector/Rectangle.js.map +1 -0
- package/dist/esm/layer/vector/Renderer.getRenderer.js +31 -0
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -0
- package/dist/esm/layer/vector/Renderer.js +39 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -0
- package/dist/esm/layer/vector/SVG.js +115 -0
- package/dist/esm/layer/vector/SVG.js.map +1 -0
- package/dist/esm/map/Map.js +844 -0
- package/dist/esm/map/Map.js.map +1 -0
- package/dist/esm/map/handler/BoxZoomHandler.js +105 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +27 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/DragHandler.js +133 -0
- package/dist/esm/map/handler/DragHandler.js.map +1 -0
- package/dist/esm/map/handler/KeyboardHandler.js +117 -0
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -0
- package/dist/esm/map/handler/PinchZoomHandler.js +96 -0
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +50 -0
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/TapHoldHandler.js +77 -0
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -0
- package/dist/esm/package.js +6 -0
- package/dist/esm/package.js.map +1 -0
- package/dist/images/layers.svg +1 -0
- package/dist/images/logo.svg +1 -0
- package/dist/images/marker-icon.svg +1 -0
- package/dist/images/marker-shadow.svg +1 -0
- package/dist/maplair-global-src.js +6810 -0
- package/dist/maplair-global-src.js.map +1 -0
- package/dist/maplair-global.js +12 -0
- package/dist/maplair-global.js.map +1 -0
- package/dist/maplair-src.js +6704 -0
- package/dist/maplair-src.js.map +1 -0
- package/dist/maplair.css +730 -0
- package/dist/maplair.js +7 -0
- package/dist/maplair.js.map +1 -0
- package/i18n/cs.json +12 -0
- package/i18n/de.json +12 -0
- package/i18n/en.json +12 -0
- package/i18n/es.json +12 -0
- package/i18n/fr.json +12 -0
- package/i18n/hu.json +12 -0
- package/i18n/it.json +12 -0
- package/i18n/rm.json +12 -0
- package/i18n/sk.json +12 -0
- package/i18n/sl.json +12 -0
- package/package.json +87 -0
- package/src/Maplair.js +24 -0
- package/src/control/AttributionControl.js +147 -0
- package/src/control/Control.js +174 -0
- package/src/control/LayersControl.js +444 -0
- package/src/control/ScaleControl.js +141 -0
- package/src/control/ZoomControl.js +147 -0
- package/src/control/index.js +5 -0
- package/src/core/Browser.js +75 -0
- package/src/core/Class.js +97 -0
- package/src/core/Events.js +334 -0
- package/src/core/Handler.js +59 -0
- package/src/core/I18n.js +76 -0
- package/src/core/Util.js +122 -0
- package/src/core/index.js +8 -0
- package/src/dom/DomEvent.DoubleTap.js +120 -0
- package/src/dom/DomEvent.PointerEvents.js +75 -0
- package/src/dom/DomEvent.js +282 -0
- package/src/dom/DomUtil.js +175 -0
- package/src/dom/Draggable.js +204 -0
- package/src/dom/PosAnimation.js +115 -0
- package/src/dom/index.js +9 -0
- package/src/geo/LatLng.js +163 -0
- package/src/geo/LatLngBounds.js +260 -0
- package/src/geo/crs/CRS.js +143 -0
- package/src/geo/crs/EPSG3395.js +19 -0
- package/src/geo/crs/EPSG3857.js +26 -0
- package/src/geo/crs/EPSG4326.js +21 -0
- package/src/geo/crs/EarthCRS.js +32 -0
- package/src/geo/crs/SimpleCRS.js +35 -0
- package/src/geo/crs/index.js +6 -0
- package/src/geo/index.js +7 -0
- package/src/geo/projection/Projection.LonLat.js +30 -0
- package/src/geo/projection/Projection.Mercator.js +53 -0
- package/src/geo/projection/Projection.SphericalMercator.js +46 -0
- package/src/geo/projection/index.js +26 -0
- package/src/geometry/Bounds.js +222 -0
- package/src/geometry/LineUtil.js +299 -0
- package/src/geometry/Point.js +239 -0
- package/src/geometry/PolyUtil.js +129 -0
- package/src/geometry/Transformation.js +67 -0
- package/src/geometry/index.js +8 -0
- package/src/images/layers.svg +1 -0
- package/src/images/logo.svg +1 -0
- package/src/images/marker-icon.svg +1 -0
- package/src/images/marker-shadow.svg +1 -0
- package/src/layer/BlanketOverlay.js +171 -0
- package/src/layer/DivOverlay.js +353 -0
- package/src/layer/FeatureGroup.js +93 -0
- package/src/layer/GeoJSON.js +432 -0
- package/src/layer/ImageOverlay.js +279 -0
- package/src/layer/Layer.js +273 -0
- package/src/layer/LayerGroup.js +129 -0
- package/src/layer/Popup.js +528 -0
- package/src/layer/SVGOverlay.js +47 -0
- package/src/layer/Tooltip.js +469 -0
- package/src/layer/VideoOverlay.js +111 -0
- package/src/layer/index.js +18 -0
- package/src/layer/marker/DefaultIcon.js +79 -0
- package/src/layer/marker/DivIcon.js +76 -0
- package/src/layer/marker/Icon.js +164 -0
- package/src/layer/marker/Marker.Drag.js +161 -0
- package/src/layer/marker/Marker.js +465 -0
- package/src/layer/marker/index.js +5 -0
- package/src/layer/tile/GridLayer.js +901 -0
- package/src/layer/tile/TileLayer.js +299 -0
- package/src/layer/tile/WMSTileLayer.js +133 -0
- package/src/layer/tile/index.js +3 -0
- package/src/layer/vector/Canvas.js +479 -0
- package/src/layer/vector/Circle.js +87 -0
- package/src/layer/vector/CircleMarker.js +110 -0
- package/src/layer/vector/Path.js +145 -0
- package/src/layer/vector/Polygon.js +160 -0
- package/src/layer/vector/Polyline.js +296 -0
- package/src/layer/vector/Rectangle.js +52 -0
- package/src/layer/vector/Renderer.getRenderer.js +48 -0
- package/src/layer/vector/Renderer.js +75 -0
- package/src/layer/vector/SVG.js +216 -0
- package/src/layer/vector/index.js +10 -0
- package/src/map/Map.js +1830 -0
- package/src/map/handler/BoxZoomHandler.js +156 -0
- package/src/map/handler/DoubleClickZoomHandler.js +62 -0
- package/src/map/handler/DragHandler.js +240 -0
- package/src/map/handler/KeyboardHandler.js +188 -0
- package/src/map/handler/PinchZoomHandler.js +157 -0
- package/src/map/handler/ScrollWheelZoomHandler.js +98 -0
- package/src/map/handler/TapHoldHandler.js +111 -0
- package/src/map/index.js +8 -0
- package/src/maplair.css +730 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import {GridLayer} from './GridLayer.js';
|
|
2
|
+
import Browser from '../../core/Browser.js';
|
|
3
|
+
import * as Util from '../../core/Util.js';
|
|
4
|
+
import * as DomEvent from '../../dom/DomEvent.js';
|
|
5
|
+
import {I18n} from '../../core/I18n.js';
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* @class TileLayer
|
|
9
|
+
* @inherits GridLayer
|
|
10
|
+
* Used to load and display tile layers on the map. Note that most tile servers require attribution, which you can set under `Layer`. Extends `GridLayer`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```js
|
|
15
|
+
* 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);
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @section URL template
|
|
19
|
+
* @example
|
|
20
|
+
*
|
|
21
|
+
* A string of the following form:
|
|
22
|
+
*
|
|
23
|
+
* ```
|
|
24
|
+
* 'https://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png'
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* `{s}` means one of the available subdomains (used sequentially to help with browser parallel requests per domain limitation; subdomain values are specified in options; `a`, `b` or `c` by default, can be omitted), `{z}` — zoom level, `{x}` and `{y}` — tile coordinates. `{r}` can be used to add "@2x" to the URL to load retina tiles.
|
|
28
|
+
*
|
|
29
|
+
* You can use custom keys in the template, which will be [evaluated](#util-template) from TileLayer options, like this:
|
|
30
|
+
*
|
|
31
|
+
* ```
|
|
32
|
+
* new TileLayer('https://{s}.somedomain.com/{foo}/{z}/{x}/{y}.png', {foo: 'bar'});
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
// @constructor TileLayer(urlTemplate: String, options?: TileLayer options)
|
|
37
|
+
// Instantiates a tile layer object given a `URL template` and optionally an options object.
|
|
38
|
+
export class TileLayer extends GridLayer {
|
|
39
|
+
|
|
40
|
+
static {
|
|
41
|
+
// @section
|
|
42
|
+
// @aka TileLayer options
|
|
43
|
+
this.setDefaultOptions({
|
|
44
|
+
// @option minZoom: Number = 0
|
|
45
|
+
// The minimum zoom level down to which this layer will be displayed (inclusive).
|
|
46
|
+
minZoom: 0,
|
|
47
|
+
|
|
48
|
+
// @option maxZoom: Number = 18
|
|
49
|
+
// The maximum zoom level up to which this layer will be displayed (inclusive).
|
|
50
|
+
maxZoom: 18,
|
|
51
|
+
|
|
52
|
+
// @option subdomains: String|String[] = 'abc'
|
|
53
|
+
// Subdomains of the tile service. Can be passed in the form of one string (where each letter is a subdomain name) or an array of strings.
|
|
54
|
+
subdomains: 'abc',
|
|
55
|
+
|
|
56
|
+
// @option errorTileUrl: String = ''
|
|
57
|
+
// URL to the tile image to show in place of the tile that failed to load.
|
|
58
|
+
errorTileUrl: '',
|
|
59
|
+
|
|
60
|
+
// @option zoomOffset: Number = 0
|
|
61
|
+
// The zoom number used in tile URLs will be offset with this value.
|
|
62
|
+
zoomOffset: 0,
|
|
63
|
+
|
|
64
|
+
// @option tms: Boolean = false
|
|
65
|
+
// If `true`, inverses Y axis numbering for tiles (turn this on for [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) services).
|
|
66
|
+
tms: false,
|
|
67
|
+
|
|
68
|
+
// @option zoomReverse: Boolean = false
|
|
69
|
+
// If set to true, the zoom number used in tile URLs will be reversed (`maxZoom - zoom` instead of `zoom`)
|
|
70
|
+
zoomReverse: false,
|
|
71
|
+
|
|
72
|
+
// @option detectRetina: Boolean = false
|
|
73
|
+
// If `true` and user is on a retina display, it will request four tiles of half the specified size and a bigger zoom level in place of one to utilize the high resolution.
|
|
74
|
+
detectRetina: false,
|
|
75
|
+
|
|
76
|
+
// @option crossOrigin: Boolean|String = false
|
|
77
|
+
// Whether the crossOrigin attribute will be added to the tiles.
|
|
78
|
+
// If a String is provided, all tiles will have their crossOrigin attribute set to the String provided. This is needed if you want to access tile pixel data.
|
|
79
|
+
// Refer to [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) for valid String values.
|
|
80
|
+
crossOrigin: false,
|
|
81
|
+
|
|
82
|
+
// @option referrerPolicy: String = 'strict-origin-when-cross-origin'
|
|
83
|
+
// Sets the tiles' `referrerPolicy` attribute set to the String provided. See
|
|
84
|
+
// [`HTMLImageElement.referrerPolicy`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy) for possible values.
|
|
85
|
+
//
|
|
86
|
+
// Tile providers might require you to use a specific referrer policy (e.g. to verify API tokens or prevent abuse).
|
|
87
|
+
// Specifically, if you are using tiles from `tile.openstreetmap.org` or `tile.osm.org`, you [should not change this value](https://operations.osmfoundation.org/policies/tiles/).
|
|
88
|
+
referrerPolicy: 'strict-origin-when-cross-origin'
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
constructor(url, options) {
|
|
93
|
+
super(options);
|
|
94
|
+
|
|
95
|
+
this._url = url;
|
|
96
|
+
|
|
97
|
+
options = Util.setOptions(this, options);
|
|
98
|
+
|
|
99
|
+
// Set required OpenStreetMap attribution if it hasn't been specified; upgrade to HTTPS so the referrer policy works.
|
|
100
|
+
const tileUrl = new URL(this._url, location.href);
|
|
101
|
+
const urlHostname = tileUrl.hostname;
|
|
102
|
+
const osmHosts = ['tile.openstreetmap.org', 'tile.osm.org'];
|
|
103
|
+
if (osmHosts.some(host => urlHostname.endsWith(host))) {
|
|
104
|
+
if (options.attribution === null) {
|
|
105
|
+
options.attribution = `© <a href="https://www.openstreetmap.org/copyright">${I18n.translate('OpenStreetMap contributors')}</a>`;
|
|
106
|
+
}
|
|
107
|
+
if (tileUrl.protocol === 'http:') {
|
|
108
|
+
tileUrl.protocol = 'https:';
|
|
109
|
+
this._url = tileUrl.toString();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// detecting retina displays, adjusting tileSize and zoom levels
|
|
114
|
+
if (this.options.detectRetina && Browser.retina && this.options.maxZoom > 0) {
|
|
115
|
+
|
|
116
|
+
this.options.tileSize = Math.floor(this.options.tileSize / 2);
|
|
117
|
+
|
|
118
|
+
if (!this.options.zoomReverse) {
|
|
119
|
+
this.options.zoomOffset++;
|
|
120
|
+
this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);
|
|
121
|
+
} else {
|
|
122
|
+
this.options.zoomOffset--;
|
|
123
|
+
this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom + 1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
this.options.minZoom = Math.max(0, this.options.minZoom);
|
|
127
|
+
} else if (!this.options.zoomReverse) {
|
|
128
|
+
// make sure maxZoom is gte minZoom
|
|
129
|
+
this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom);
|
|
130
|
+
} else {
|
|
131
|
+
// make sure minZoom is lte maxZoom
|
|
132
|
+
this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (typeof this.options.subdomains === 'string') {
|
|
136
|
+
this.options.subdomains = this.options.subdomains.split('');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this.on('tileunload', this._onTileRemove);
|
|
140
|
+
|
|
141
|
+
this.callInitHooks(TileLayer);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// @method setUrl(url: String, noRedraw?: Boolean): this
|
|
145
|
+
// Updates the layer's URL template and redraws it (unless `noRedraw` is set to `true`).
|
|
146
|
+
// If the URL does not change, the layer will not be redrawn unless
|
|
147
|
+
// the noRedraw parameter is set to false.
|
|
148
|
+
setUrl(url, noRedraw) {
|
|
149
|
+
if (this._url === url && noRedraw === undefined) {
|
|
150
|
+
noRedraw = true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
this._url = url;
|
|
154
|
+
|
|
155
|
+
if (!noRedraw) {
|
|
156
|
+
this.redraw();
|
|
157
|
+
}
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// @method createTile(coords: Object, done?: Function): HTMLElement
|
|
162
|
+
// Called only internally, overrides GridLayer's [`createTile()`](#gridlayer-createtile)
|
|
163
|
+
// to return an `<img>` HTML element with the appropriate image URL given `coords`. The `done`
|
|
164
|
+
// callback is called when the tile has been loaded.
|
|
165
|
+
createTile(coords, done) {
|
|
166
|
+
const tile = document.createElement('img');
|
|
167
|
+
|
|
168
|
+
DomEvent.on(tile, 'load', this._tileOnLoad.bind(this, done, tile));
|
|
169
|
+
DomEvent.on(tile, 'error', this._tileOnError.bind(this, done, tile));
|
|
170
|
+
|
|
171
|
+
if (this.options.crossOrigin || this.options.crossOrigin === '') {
|
|
172
|
+
tile.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// for this new option we follow the documented behavior
|
|
176
|
+
// more closely by only setting the property when string
|
|
177
|
+
if (typeof this.options.referrerPolicy === 'string') {
|
|
178
|
+
tile.referrerPolicy = this.options.referrerPolicy;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// The alt attribute is set to the empty string,
|
|
182
|
+
// allowing screen readers to ignore the decorative image tiles.
|
|
183
|
+
// https://www.w3.org/WAI/tutorials/images/decorative/
|
|
184
|
+
// https://www.w3.org/TR/html-aria/#el-img-empty-alt
|
|
185
|
+
tile.alt = '';
|
|
186
|
+
|
|
187
|
+
tile.src = this.getTileUrl(coords);
|
|
188
|
+
|
|
189
|
+
return tile;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// @section Extension methods
|
|
193
|
+
// @uninheritable
|
|
194
|
+
// Layers extending `TileLayer` might reimplement the following method.
|
|
195
|
+
// @method getTileUrl(coords: Object): String
|
|
196
|
+
// Called only internally, returns the URL for a tile given its coordinates.
|
|
197
|
+
// Classes extending `TileLayer` can override this function to provide custom tile URL naming schemes.
|
|
198
|
+
getTileUrl(coords) {
|
|
199
|
+
const data = Object.create(this.options);
|
|
200
|
+
Object.assign(data, {
|
|
201
|
+
r: Browser.retina ? '@2x' : '',
|
|
202
|
+
s: this._getSubdomain(coords),
|
|
203
|
+
x: coords.x,
|
|
204
|
+
y: coords.y,
|
|
205
|
+
z: this._getZoomForUrl()
|
|
206
|
+
});
|
|
207
|
+
if (this._map && !this._map.options.crs.infinite) {
|
|
208
|
+
const invertedY = this._globalTileRange.max.y - coords.y;
|
|
209
|
+
if (this.options.tms) {
|
|
210
|
+
data['y'] = invertedY;
|
|
211
|
+
}
|
|
212
|
+
data['-y'] = invertedY;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return Util.template(this._url, data);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
_tileOnLoad(done, tile) {
|
|
219
|
+
done(null, tile);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
_tileOnError(done, tile, e) {
|
|
223
|
+
const errorUrl = this.options.errorTileUrl;
|
|
224
|
+
if (errorUrl && tile.getAttribute('src') !== errorUrl) {
|
|
225
|
+
tile.src = errorUrl;
|
|
226
|
+
}
|
|
227
|
+
done(e, tile);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
_onTileRemove(e) {
|
|
231
|
+
e.tile.onload = null;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
_getZoomForUrl() {
|
|
235
|
+
let zoom = this._tileZoom;
|
|
236
|
+
const maxZoom = this.options.maxZoom,
|
|
237
|
+
zoomReverse = this.options.zoomReverse,
|
|
238
|
+
zoomOffset = this.options.zoomOffset;
|
|
239
|
+
|
|
240
|
+
if (zoomReverse) {
|
|
241
|
+
zoom = maxZoom - zoom;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return zoom + zoomOffset;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
_getSubdomain(tilePoint) {
|
|
248
|
+
const index = Math.abs(tilePoint.x + tilePoint.y) % this.options.subdomains.length;
|
|
249
|
+
return this.options.subdomains[index];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// stops loading all tiles in the background layer
|
|
253
|
+
_abortLoading() {
|
|
254
|
+
let i, tile;
|
|
255
|
+
for (i of Object.keys(this._tiles)) {
|
|
256
|
+
if (this._tiles[i].coords.z !== this._tileZoom) {
|
|
257
|
+
tile = this._tiles[i].el;
|
|
258
|
+
|
|
259
|
+
tile.onload = Util.falseFn;
|
|
260
|
+
tile.onerror = Util.falseFn;
|
|
261
|
+
|
|
262
|
+
if (!tile.complete) {
|
|
263
|
+
tile.setAttribute('src', '');
|
|
264
|
+
const coords = this._tiles[i].coords;
|
|
265
|
+
tile.remove();
|
|
266
|
+
delete this._tiles[i];
|
|
267
|
+
// @event tileabort: TileEvent
|
|
268
|
+
// Fired when a tile was loading but is now not wanted.
|
|
269
|
+
this.fire('tileabort', {
|
|
270
|
+
tile,
|
|
271
|
+
coords
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
_removeTile(key) {
|
|
279
|
+
const tile = this._tiles[key];
|
|
280
|
+
if (!tile) { return; }
|
|
281
|
+
|
|
282
|
+
// Cancels any pending http requests associated with the tile
|
|
283
|
+
tile.el.setAttribute('src', '');
|
|
284
|
+
|
|
285
|
+
return super._removeTile(key);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
_tileReady(coords, err, tile) {
|
|
289
|
+
if (!this._map || (tile && tile.getAttribute('src') === '')) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return super._tileReady(coords, err, tile);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
_clampZoom(zoom) {
|
|
297
|
+
return Math.round(super._clampZoom(zoom));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import {TileLayer} from './TileLayer.js';
|
|
2
|
+
import Browser from '../../core/Browser.js';
|
|
3
|
+
import {EPSG4326} from '../../geo/crs/EPSG4326.js';
|
|
4
|
+
import {Bounds} from '../../geometry/Bounds.js';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* @class WMSTileLayer
|
|
8
|
+
* @inherits TileLayer
|
|
9
|
+
* Used to display [WMS](https://en.wikipedia.org/wiki/Web_Map_Service) services as tile layers on the map. Extends `TileLayer`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* ```js
|
|
14
|
+
* const nexrad = new WMSTileLayer("http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi", {
|
|
15
|
+
* layers: 'nexrad-n0r-900913',
|
|
16
|
+
* format: 'image/png',
|
|
17
|
+
* transparent: true,
|
|
18
|
+
* attribution: "Weather data © 2012 IEM Nexrad"
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// @constructor WMSTileLayer(baseUrl: String, options: WMSTileLayer options)
|
|
24
|
+
// Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS parameters/options object.
|
|
25
|
+
export class WMSTileLayer extends TileLayer {
|
|
26
|
+
|
|
27
|
+
static {
|
|
28
|
+
// @section
|
|
29
|
+
// @aka WMSTileLayer options
|
|
30
|
+
// If any custom options not documented here are used, they will be sent to the
|
|
31
|
+
// WMS server as extra parameters in each request URL. This can be useful for
|
|
32
|
+
// [non-standard vendor WMS parameters](https://docs.geoserver.org/stable/en/user/services/wms/vendor.html).
|
|
33
|
+
this.prototype.defaultWmsParams = {
|
|
34
|
+
service: 'WMS',
|
|
35
|
+
request: 'GetMap',
|
|
36
|
+
|
|
37
|
+
// @option layers: String = ''
|
|
38
|
+
// **(required)** Comma-separated list of WMS layers to show.
|
|
39
|
+
layers: '',
|
|
40
|
+
|
|
41
|
+
// @option styles: String = ''
|
|
42
|
+
// Comma-separated list of WMS styles.
|
|
43
|
+
styles: '',
|
|
44
|
+
|
|
45
|
+
// @option format: String = 'image/jpeg'
|
|
46
|
+
// WMS image format (use `'image/png'` for layers with transparency).
|
|
47
|
+
format: 'image/jpeg',
|
|
48
|
+
|
|
49
|
+
// @option transparent: Boolean = false
|
|
50
|
+
// If `true`, the WMS service will return images with transparency.
|
|
51
|
+
transparent: false,
|
|
52
|
+
|
|
53
|
+
// @option version: String = '1.1.1'
|
|
54
|
+
// Version of the WMS service to use
|
|
55
|
+
version: '1.1.1'
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
this.setDefaultOptions({
|
|
59
|
+
// @option crs: CRS = null
|
|
60
|
+
// Coordinate Reference System to use for the WMS requests, defaults to
|
|
61
|
+
// map CRS. Don't change this if you're not sure what it means.
|
|
62
|
+
crs: null,
|
|
63
|
+
|
|
64
|
+
// @option uppercase: Boolean = false
|
|
65
|
+
// If `true`, WMS request parameter keys will be uppercase.
|
|
66
|
+
uppercase: false
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
constructor(url, options) {
|
|
71
|
+
super(url, options);
|
|
72
|
+
|
|
73
|
+
const wmsParams = {...this.defaultWmsParams};
|
|
74
|
+
|
|
75
|
+
// Options that are unknown in the prototype chain are considered WMS params.
|
|
76
|
+
for (const [key, value] of Object.entries(options)) {
|
|
77
|
+
if (!(key in WMSTileLayer.prototype.options)) {
|
|
78
|
+
wmsParams[key] = value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const realRetina = this.options.detectRetina && Browser.retina ? 2 : 1;
|
|
83
|
+
const tileSize = this.getTileSize();
|
|
84
|
+
|
|
85
|
+
wmsParams.width = tileSize.x * realRetina;
|
|
86
|
+
wmsParams.height = tileSize.y * realRetina;
|
|
87
|
+
|
|
88
|
+
this.wmsParams = wmsParams;
|
|
89
|
+
|
|
90
|
+
this.callInitHooks(WMSTileLayer);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
onAdd(map) {
|
|
94
|
+
|
|
95
|
+
this._crs = this.options.crs ?? map.options.crs;
|
|
96
|
+
this._wmsVersion = parseFloat(this.wmsParams.version);
|
|
97
|
+
|
|
98
|
+
const projectionKey = this._wmsVersion >= 1.3 ? 'crs' : 'srs';
|
|
99
|
+
this.wmsParams[projectionKey] = this._crs.code;
|
|
100
|
+
|
|
101
|
+
super.onAdd(map);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getTileUrl(coords) {
|
|
105
|
+
|
|
106
|
+
const tileBounds = this._tileCoordsToNwSe(coords),
|
|
107
|
+
crs = this._crs,
|
|
108
|
+
bounds = new Bounds(crs.project(tileBounds[0]), crs.project(tileBounds[1])),
|
|
109
|
+
min = bounds.min,
|
|
110
|
+
max = bounds.max,
|
|
111
|
+
bbox = (this._wmsVersion >= 1.3 && this._crs === EPSG4326 ?
|
|
112
|
+
[min.y, min.x, max.y, max.x] :
|
|
113
|
+
[min.x, min.y, max.x, max.y]).join(',');
|
|
114
|
+
const url = new URL(super.getTileUrl(coords));
|
|
115
|
+
for (const [k, v] of Object.entries({...this.wmsParams, bbox})) {
|
|
116
|
+
url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, v);
|
|
117
|
+
}
|
|
118
|
+
return url.toString();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// @method setParams(params: Object, noRedraw?: Boolean): this
|
|
122
|
+
// Merges an object with the new parameters and re-requests tiles on the current screen (unless `noRedraw` was set to true).
|
|
123
|
+
setParams(params, noRedraw) {
|
|
124
|
+
|
|
125
|
+
Object.assign(this.wmsParams, params);
|
|
126
|
+
|
|
127
|
+
if (!noRedraw) {
|
|
128
|
+
this.redraw();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
}
|