maplair 4.3.0 → 4.5.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 +151 -8
- package/dist/esm/control/AttributionControl.js +30 -13
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +0 -1
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -1
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +16 -11
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +0 -1
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +46 -27
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +0 -1
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -8
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +3 -2
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/ZoomControl.js +14 -13
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Events.js +3 -2
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Util.js +17 -5
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +72 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +4 -7
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +5 -5
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +10 -8
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +24 -35
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +6 -3
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +2 -2
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +16 -19
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +10 -3
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -7
- package/dist/esm/geometry/Transformation.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +3 -2
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +25 -25
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +8 -5
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +12 -7
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +33 -15
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +48 -56
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +2 -2
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +4 -8
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +37 -17
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +11 -12
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +54 -53
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/SvgIcon.js +1 -1
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +29 -21
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +19 -15
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +45 -94
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +8 -9
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +15 -4
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +10 -5
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +10 -11
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.js +19 -26
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +16 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +3 -3
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +9 -11
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +158 -71
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +2 -5
- package/dist/esm/map/MapSync.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +4 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +68 -30
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +7 -2
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +3 -5
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +4 -7
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -7
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +2 -5
- package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +8 -20
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +970 -810
- 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 +970 -810
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/en.json +1 -0
- package/package.json +1 -1
- package/src/control/AttributionControl.js +37 -11
- package/src/control/ButtonControl.js +0 -1
- package/src/control/ContextMenu.js +1 -1
- package/src/control/Control.js +13 -16
- package/src/control/FullscreenControl.js +0 -1
- package/src/control/LayersControl.js +61 -37
- package/src/control/RotateControl.js +0 -1
- package/src/control/ScaleControl.js +10 -8
- package/src/control/SideBySideControl.js +4 -2
- package/src/control/ZoomControl.js +11 -13
- package/src/core/Events.js +6 -2
- package/src/core/Util.js +17 -4
- package/src/dom/DomEvent.PointerEvents.js +68 -2
- package/src/dom/DomEvent.js +5 -17
- package/src/dom/DomUtil.js +5 -5
- package/src/dom/Draggable.js +11 -8
- package/src/geo/LatLng.js +24 -37
- package/src/geo/LatLngBounds.js +10 -4
- package/src/geometry/Bounds.js +3 -3
- package/src/geometry/Point.js +22 -28
- package/src/geometry/PolyUtil.js +12 -3
- package/src/geometry/Transformation.js +1 -8
- package/src/layer/BlanketOverlay.js +6 -3
- package/src/layer/DivOverlay.js +30 -32
- package/src/layer/ImageOverlay.js +12 -9
- package/src/layer/Layer.js +19 -7
- package/src/layer/Popup.js +41 -21
- package/src/layer/Tooltip.js +50 -70
- package/src/layer/VideoOverlay.js +2 -2
- package/src/layer/marker/DivIcon.js +3 -6
- package/src/layer/marker/Icon.js +41 -20
- package/src/layer/marker/Marker.Drag.js +22 -24
- package/src/layer/marker/Marker.js +71 -64
- package/src/layer/marker/SvgIcon.js +1 -1
- package/src/layer/tile/GridLayer.js +41 -30
- package/src/layer/tile/TileLayer.js +31 -21
- package/src/layer/tile/WMSTileLayer.js +4 -2
- package/src/layer/vector/Canvas.js +53 -149
- package/src/layer/vector/Circle.js +13 -13
- package/src/layer/vector/CircleMarker.js +16 -3
- package/src/layer/vector/Path.ZoomStyles.js +5 -3
- package/src/layer/vector/Path.js +11 -5
- package/src/layer/vector/Polygon.js +11 -10
- package/src/layer/vector/Polyline.js +20 -21
- package/src/layer/vector/Renderer.getRenderer.js +2 -1
- package/src/layer/vector/Renderer.js +21 -3
- package/src/layer/vector/SVG.js +3 -3
- package/src/map/Map.Rotation.js +13 -9
- package/src/map/Map.js +195 -83
- package/src/map/MapSync.js +2 -2
- package/src/map/handler/BoxZoomHandler.js +5 -0
- package/src/map/handler/DisplaceHandler.js +53 -7
- package/src/map/handler/DragHandler.js +5 -5
- package/src/map/handler/KeyboardHandler.js +5 -10
- package/src/map/handler/PinchZoomHandler.js +4 -4
- package/src/map/handler/ScrollWheelZoomHandler.js +4 -4
- package/src/map/handler/TapDragZoomHandler.js +2 -2
- package/src/map/handler/TapHoldHandler.js +13 -25
- package/src/maplair.css +50 -10
- package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
- package/src/dom/DomEvent.DoubleTap.js +0 -143
|
@@ -18,6 +18,12 @@ function isOSMUrl(url) {
|
|
|
18
18
|
// OSM tiles are upgraded to HTTPS so that the referrer policy works
|
|
19
19
|
const upgradeOSMUrl = url => (isOSMUrl(url) ? url.replace(httpRe, 'https:') : url);
|
|
20
20
|
|
|
21
|
+
// 0 at a pixel ratio of 1, 1 above it (the `{r}` of tile URLs), 2 from 1.5 on (`detectRetina`)
|
|
22
|
+
function retinaLevel() {
|
|
23
|
+
const dpr = window.devicePixelRatio;
|
|
24
|
+
return dpr >= 1.5 ? 2 : dpr > 1 ? 1 : 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
21
27
|
/**
|
|
22
28
|
* Options of `TileLayer`.
|
|
23
29
|
* @typedef {object} TileLayerOptions
|
|
@@ -36,9 +42,9 @@ const upgradeOSMUrl = url => (isOSMUrl(url) ? url.replace(httpRe, 'https:') : ur
|
|
|
36
42
|
* this on for [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) services).
|
|
37
43
|
* @property {boolean} [zoomReverse=false] If set to true, the zoom number used in tile
|
|
38
44
|
* URLs will be reversed (`maxZoom - zoom` instead of `zoom`).
|
|
39
|
-
* @property {boolean} [detectRetina=false] If `true` and
|
|
40
|
-
* will request four tiles of half the specified size and a bigger zoom level
|
|
41
|
-
* of one to utilize the high resolution.
|
|
45
|
+
* @property {boolean} [detectRetina=false] If `true` and the device pixel ratio is 1.5 or
|
|
46
|
+
* higher, it will request four tiles of half the specified size and a bigger zoom level
|
|
47
|
+
* in place of one to utilize the high resolution.
|
|
42
48
|
* @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute will
|
|
43
49
|
* be added to the tiles. If a String is provided, all tiles will have their crossOrigin
|
|
44
50
|
* attribute set to the String provided. This is needed if you want to access tile pixel
|
|
@@ -144,12 +150,13 @@ export class TileLayer extends GridLayer {
|
|
|
144
150
|
this.callInitHooks(TileLayer);
|
|
145
151
|
}
|
|
146
152
|
|
|
147
|
-
// Detects retina displays (if `detectRetina` is set), adjusting tileSize and zoom levels.
|
|
153
|
+
// Detects retina displays (if `detectRetina` is set), adjusting tileSize and zoom levels. Below a
|
|
154
|
+
// pixel ratio of 1.5 (e.g. 125% scaling), half-size tiles of the next zoom make labels too small to read.
|
|
148
155
|
_applyRetina() {
|
|
149
156
|
Object.assign(this.options, this._nonRetinaOptions);
|
|
150
|
-
this._retina =
|
|
157
|
+
this._retina = retinaLevel();
|
|
151
158
|
|
|
152
|
-
if (this.options.detectRetina && this._retina && this.options.maxZoom > 0) {
|
|
159
|
+
if (this.options.detectRetina && this._retina === 2 && this.options.maxZoom > 0) {
|
|
153
160
|
|
|
154
161
|
const tileSize = this.options.tileSize;
|
|
155
162
|
this.options.tileSize = tileSize instanceof Point ? tileSize.divideBy(2).floor() : Math.floor(tileSize / 2);
|
|
@@ -157,19 +164,21 @@ export class TileLayer extends GridLayer {
|
|
|
157
164
|
if (!this.options.zoomReverse) {
|
|
158
165
|
this.options.zoomOffset++;
|
|
159
166
|
this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);
|
|
160
|
-
// do not request tiles beyond the native zoom levels
|
|
161
|
-
if (this.options.maxNativeZoom !== undefined) {
|
|
162
|
-
this.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);
|
|
163
|
-
}
|
|
164
|
-
if (this.options.minNativeZoom !== undefined) {
|
|
165
|
-
this.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);
|
|
166
|
-
}
|
|
167
167
|
} else {
|
|
168
168
|
this.options.zoomOffset--;
|
|
169
169
|
this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom + 1);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
this.options.minZoom = Math.max(0, this.options.minZoom);
|
|
173
|
+
|
|
174
|
+
// either way, the tile at zoom z is now the server's z + 1 tile, so native zooms shift down by one, so
|
|
175
|
+
// that no tiles beyond the native zoom levels are requested
|
|
176
|
+
if (this.options.maxNativeZoom !== undefined) {
|
|
177
|
+
this.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);
|
|
178
|
+
}
|
|
179
|
+
if (this.options.minNativeZoom !== undefined) {
|
|
180
|
+
this.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);
|
|
181
|
+
}
|
|
173
182
|
} else if (!this.options.zoomReverse) {
|
|
174
183
|
// make sure maxZoom is gte minZoom
|
|
175
184
|
this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom);
|
|
@@ -191,7 +200,7 @@ export class TileLayer extends GridLayer {
|
|
|
191
200
|
|
|
192
201
|
// Loads the tiles for the new resolution, see the map's `pixelratiochange` event.
|
|
193
202
|
_onPixelRatioChange() {
|
|
194
|
-
if ((
|
|
203
|
+
if (retinaLevel() === this._retina) { return; }
|
|
195
204
|
const map = this._map;
|
|
196
205
|
this._applyRetina();
|
|
197
206
|
if (this.options.detectRetina) {
|
|
@@ -317,16 +326,18 @@ export class TileLayer extends GridLayer {
|
|
|
317
326
|
* @returns {string}
|
|
318
327
|
*/
|
|
319
328
|
getTileUrl(coords) {
|
|
320
|
-
const
|
|
329
|
+
const z = coords.z ?? this._tileZoom,
|
|
330
|
+
data = Object.create(this.options);
|
|
321
331
|
Object.assign(data, {
|
|
322
332
|
r: window.devicePixelRatio > 1 ? '@2x' : '',
|
|
323
333
|
s: this._getSubdomain(coords),
|
|
324
334
|
x: coords.x,
|
|
325
335
|
y: coords.y,
|
|
326
|
-
z: this._getZoomForUrl()
|
|
336
|
+
z: this._getZoomForUrl(z)
|
|
327
337
|
});
|
|
328
|
-
|
|
329
|
-
|
|
338
|
+
const worldBounds = this._map?.getPixelWorldBounds(z);
|
|
339
|
+
if (worldBounds) {
|
|
340
|
+
const invertedY = this._pxBoundsToTileRange(worldBounds).max.y - coords.y;
|
|
330
341
|
if (this.options.tms) {
|
|
331
342
|
data['y'] = invertedY;
|
|
332
343
|
}
|
|
@@ -354,8 +365,7 @@ export class TileLayer extends GridLayer {
|
|
|
354
365
|
done(e, tile);
|
|
355
366
|
}
|
|
356
367
|
|
|
357
|
-
_getZoomForUrl() {
|
|
358
|
-
let zoom = this._tileZoom;
|
|
368
|
+
_getZoomForUrl(zoom) {
|
|
359
369
|
const maxZoom = this.options.maxZoom,
|
|
360
370
|
zoomReverse = this.options.zoomReverse,
|
|
361
371
|
zoomOffset = this.options.zoomOffset;
|
|
@@ -405,7 +415,7 @@ export class TileLayer extends GridLayer {
|
|
|
405
415
|
}
|
|
406
416
|
|
|
407
417
|
_tileReady(coords, err, tile) {
|
|
408
|
-
if (!this._map ||
|
|
418
|
+
if (!this._map || tile?.getAttribute('src') === '') {
|
|
409
419
|
return;
|
|
410
420
|
}
|
|
411
421
|
|
|
@@ -93,7 +93,7 @@ export class WMSTileLayer extends TileLayer {
|
|
|
93
93
|
|
|
94
94
|
// The size of the requested images: the tile size, doubled on retina displays with `detectRetina`.
|
|
95
95
|
_updateWmsSize() {
|
|
96
|
-
const realRetina = this.options.detectRetina && window.devicePixelRatio
|
|
96
|
+
const realRetina = this.options.detectRetina && window.devicePixelRatio >= 1.5 ? 2 : 1;
|
|
97
97
|
const tileSize = this.getTileSize();
|
|
98
98
|
|
|
99
99
|
this.wmsParams.width = tileSize.x * realRetina;
|
|
@@ -154,6 +154,7 @@ export class WMSTileLayer extends TileLayer {
|
|
|
154
154
|
[min.x, min.y, max.x, max.y]).join(',');
|
|
155
155
|
const url = new URL(super.getTileUrl(coords), document.baseURI);
|
|
156
156
|
for (const [k, v] of Object.entries({...this.wmsParams, bbox})) {
|
|
157
|
+
if (v == null) { continue; } // unset, e.g. cleared with `setParams`
|
|
157
158
|
url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, `${v}`);
|
|
158
159
|
}
|
|
159
160
|
return url.toString();
|
|
@@ -191,7 +192,8 @@ export class WMSTileLayer extends TileLayer {
|
|
|
191
192
|
/**
|
|
192
193
|
* Merges an object with the new parameters and re-requests tiles on the current screen
|
|
193
194
|
* (unless `noRedraw` was set to true). The current tiles stay visible until the new
|
|
194
|
-
* tiles have loaded, to avoid flickering.
|
|
195
|
+
* tiles have loaded, to avoid flickering. Set a parameter to `undefined` or `null` to
|
|
196
|
+
* leave it out of the requests.
|
|
195
197
|
* @param {Record<string, any>} params
|
|
196
198
|
* @param {boolean} [noRedraw]
|
|
197
199
|
* @returns {this}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {Renderer} from './Renderer.js';
|
|
2
|
-
import * as DomEvent from '../../dom/DomEvent.js';
|
|
3
2
|
import * as Util from '../../core/Util.js';
|
|
4
3
|
import {Bounds} from '../../geometry/Bounds.js';
|
|
5
4
|
/** @import {MaplairMap} from '../../map/Map.js' */
|
|
@@ -86,29 +85,28 @@ export class Canvas extends Renderer {
|
|
|
86
85
|
onAdd(map) {
|
|
87
86
|
super.onAdd(map);
|
|
88
87
|
|
|
88
|
+
// the map hit-tests canvas renderers topmost first: by pane z-index, then DOM order
|
|
89
|
+
const z = r => +getComputedStyle(r._container.parentNode).zIndex || 0;
|
|
90
|
+
map._canvases.push(this);
|
|
91
|
+
map._canvases.sort((a, b) => z(b) - z(a) || 1 - (a._container.compareDocumentPosition(b._container) & 2));
|
|
92
|
+
|
|
89
93
|
// Redraw vectors since canvas is cleared upon removal,
|
|
90
94
|
// in case of removing the renderer itself from the map.
|
|
91
95
|
this._draw();
|
|
92
96
|
}
|
|
93
97
|
|
|
98
|
+
_initContainer() {
|
|
99
|
+
const container = this._container = document.createElement('canvas');
|
|
100
|
+
|
|
101
|
+
this._ctx = container.getContext('2d');
|
|
102
|
+
}
|
|
103
|
+
|
|
94
104
|
/**
|
|
95
105
|
* Removes the canvas from the map.
|
|
96
106
|
*/
|
|
97
107
|
onRemove() {
|
|
108
|
+
this._map._canvases = this._map._canvases.filter(r => r !== this);
|
|
98
109
|
super.onRemove();
|
|
99
|
-
|
|
100
|
-
clearTimeout(this._pointerHoverThrottleTimeout);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_initContainer() {
|
|
104
|
-
const container = this._container = document.createElement('canvas');
|
|
105
|
-
|
|
106
|
-
DomEvent.on(container, 'pointermove', this._onPointerMove, this);
|
|
107
|
-
DomEvent.on(container, 'click dblclick pointerdown pointerup contextmenu', this._onClick, this);
|
|
108
|
-
DomEvent.on(container, 'pointerout', this._handlePointerOut, this);
|
|
109
|
-
container['_maplair_disable_events'] = true;
|
|
110
|
-
|
|
111
|
-
this._ctx = container.getContext('2d');
|
|
112
110
|
}
|
|
113
111
|
|
|
114
112
|
_destroyContainer() {
|
|
@@ -166,14 +164,7 @@ export class Canvas extends Renderer {
|
|
|
166
164
|
this._updateDashArray(layer);
|
|
167
165
|
this._layers[Util.stamp(layer)] = layer;
|
|
168
166
|
|
|
169
|
-
|
|
170
|
-
layer,
|
|
171
|
-
prev: this._drawLast,
|
|
172
|
-
next: null
|
|
173
|
-
};
|
|
174
|
-
if (this._drawLast) { this._drawLast.next = order; }
|
|
175
|
-
this._drawLast = order;
|
|
176
|
-
this._drawFirst ??= this._drawLast;
|
|
167
|
+
this._append(layer._order = {layer});
|
|
177
168
|
}
|
|
178
169
|
|
|
179
170
|
_addPath(layer) {
|
|
@@ -181,21 +172,7 @@ export class Canvas extends Renderer {
|
|
|
181
172
|
}
|
|
182
173
|
|
|
183
174
|
_removePath(layer) {
|
|
184
|
-
|
|
185
|
-
const next = order.next;
|
|
186
|
-
const prev = order.prev;
|
|
187
|
-
|
|
188
|
-
if (next) {
|
|
189
|
-
next.prev = prev;
|
|
190
|
-
} else {
|
|
191
|
-
this._drawLast = prev;
|
|
192
|
-
}
|
|
193
|
-
if (prev) {
|
|
194
|
-
prev.next = next;
|
|
195
|
-
} else {
|
|
196
|
-
this._drawFirst = next;
|
|
197
|
-
}
|
|
198
|
-
|
|
175
|
+
this._unlink(layer._order);
|
|
199
176
|
delete layer._order;
|
|
200
177
|
|
|
201
178
|
delete this._layers[Util.stamp(layer)];
|
|
@@ -238,7 +215,7 @@ export class Canvas extends Renderer {
|
|
|
238
215
|
|
|
239
216
|
_extendRedrawBounds(layer) {
|
|
240
217
|
if (layer._pxBounds) {
|
|
241
|
-
const padding = (layer.options.weight
|
|
218
|
+
const padding = (+layer.options.weight || 0) + 1;
|
|
242
219
|
this._redrawBounds ??= new Bounds();
|
|
243
220
|
this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));
|
|
244
221
|
this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));
|
|
@@ -289,7 +266,7 @@ export class Canvas extends Renderer {
|
|
|
289
266
|
|
|
290
267
|
for (let order = this._drawFirst; order; order = order.next) {
|
|
291
268
|
layer = order.layer;
|
|
292
|
-
if (!bounds ||
|
|
269
|
+
if (!bounds || layer._pxBounds?.intersects(bounds)) {
|
|
293
270
|
layer._updatePath();
|
|
294
271
|
}
|
|
295
272
|
}
|
|
@@ -352,7 +329,7 @@ export class Canvas extends Renderer {
|
|
|
352
329
|
ctx.fill(options.fillRule || 'evenodd');
|
|
353
330
|
}
|
|
354
331
|
|
|
355
|
-
if (options.stroke && options.weight !== 0) {
|
|
332
|
+
if (options.stroke && +options.weight !== 0) {
|
|
356
333
|
ctx.lineDashOffset = Number(options.dashOffset ?? 0);
|
|
357
334
|
ctx.setLineDash(layer._dashArray ?? []);
|
|
358
335
|
ctx.globalAlpha = options.opacity;
|
|
@@ -369,137 +346,64 @@ export class Canvas extends Renderer {
|
|
|
369
346
|
_updateInteractive() {}
|
|
370
347
|
|
|
371
348
|
// Canvas obviously doesn't have pointer events for individual drawn objects,
|
|
372
|
-
// so
|
|
349
|
+
// so the map calls this on its own pointer events to find what's under the pointer
|
|
373
350
|
|
|
374
|
-
|
|
351
|
+
/**
|
|
352
|
+
* Returns the topmost interactive layer under the pointer.
|
|
353
|
+
* @param {MouseEvent} e
|
|
354
|
+
* @param {boolean} [click] Skip layers that were just dragged, so the drag doesn't end with a click.
|
|
355
|
+
* @returns {Path|undefined}
|
|
356
|
+
*/
|
|
357
|
+
_layerAt(e, click) {
|
|
375
358
|
const point = this._map.pointerEventToLayerPoint(e);
|
|
376
|
-
let layer, clickedLayer;
|
|
377
359
|
|
|
378
|
-
for (let order = this.
|
|
379
|
-
layer = order.layer;
|
|
380
|
-
if (layer.options.interactive && layer._containsPoint(point)) {
|
|
381
|
-
|
|
382
|
-
clickedLayer = layer;
|
|
383
|
-
}
|
|
360
|
+
for (let order = this._drawLast; order; order = order.prev) {
|
|
361
|
+
const layer = order.layer;
|
|
362
|
+
if (layer.options.interactive && layer._containsPoint(point) && !(click && this._map._draggableMoved(layer))) {
|
|
363
|
+
return layer;
|
|
384
364
|
}
|
|
385
365
|
}
|
|
386
|
-
this._fireEvent(clickedLayer ? [clickedLayer] : false, e);
|
|
387
366
|
}
|
|
388
367
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
_handlePointerOut(e) {
|
|
398
|
-
const layer = this._hoveredLayer;
|
|
399
|
-
if (layer) {
|
|
400
|
-
// if we're leaving the layer, fire pointerout
|
|
401
|
-
this._container.classList.remove('maplair-interactive');
|
|
402
|
-
this._fireEvent([layer], e, 'pointerout');
|
|
403
|
-
this._hoveredLayer = null;
|
|
404
|
-
this._pointerHoverThrottled = false;
|
|
368
|
+
_bringToFront(layer) {
|
|
369
|
+
const order = layer._order;
|
|
370
|
+
if (order?.next) { // unless already last
|
|
371
|
+
this._unlink(order);
|
|
372
|
+
this._append(order);
|
|
373
|
+
this._requestRedraw(layer);
|
|
405
374
|
}
|
|
406
375
|
}
|
|
407
376
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
if (layer.options.interactive && layer._containsPoint(point)) {
|
|
418
|
-
candidateHoveredLayer = layer;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
if (candidateHoveredLayer !== this._hoveredLayer) {
|
|
423
|
-
this._handlePointerOut(e);
|
|
424
|
-
|
|
425
|
-
if (candidateHoveredLayer) {
|
|
426
|
-
this._container.classList.add('maplair-interactive'); // change cursor
|
|
427
|
-
this._fireEvent([candidateHoveredLayer], e, 'pointerover');
|
|
428
|
-
this._hoveredLayer = candidateHoveredLayer;
|
|
429
|
-
}
|
|
377
|
+
_bringToBack(layer) {
|
|
378
|
+
const order = layer._order;
|
|
379
|
+
if (order?.prev) { // unless already first
|
|
380
|
+
this._unlink(order);
|
|
381
|
+
order.prev = null;
|
|
382
|
+
order.next = this._drawFirst;
|
|
383
|
+
this._drawFirst.prev = order;
|
|
384
|
+
this._drawFirst = order;
|
|
385
|
+
this._requestRedraw(layer);
|
|
430
386
|
}
|
|
431
|
-
|
|
432
|
-
this._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);
|
|
433
|
-
|
|
434
|
-
this._pointerHoverThrottled = true;
|
|
435
|
-
this._pointerHoverThrottleTimeout = setTimeout((() => {
|
|
436
|
-
this._pointerHoverThrottled = false;
|
|
437
|
-
}), 32);
|
|
438
387
|
}
|
|
439
388
|
|
|
440
|
-
|
|
441
|
-
|
|
389
|
+
_append(order) {
|
|
390
|
+
order.prev = this._drawLast;
|
|
391
|
+
order.next = null;
|
|
392
|
+
if (this._drawLast) { this._drawLast.next = order; }
|
|
393
|
+
this._drawLast = order;
|
|
394
|
+
this._drawFirst ??= order;
|
|
442
395
|
}
|
|
443
396
|
|
|
444
|
-
|
|
445
|
-
const order = layer._order;
|
|
446
|
-
|
|
447
|
-
if (!order) { return; }
|
|
448
|
-
|
|
449
|
-
const next = order.next;
|
|
450
|
-
const prev = order.prev;
|
|
451
|
-
|
|
397
|
+
_unlink({prev, next}) {
|
|
452
398
|
if (next) {
|
|
453
399
|
next.prev = prev;
|
|
454
400
|
} else {
|
|
455
|
-
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
if (prev) {
|
|
459
|
-
prev.next = next;
|
|
460
|
-
} else if (next) {
|
|
461
|
-
// Update first entry unless this is the
|
|
462
|
-
// single entry
|
|
463
|
-
this._drawFirst = next;
|
|
401
|
+
this._drawLast = prev;
|
|
464
402
|
}
|
|
465
|
-
|
|
466
|
-
order.prev = this._drawLast;
|
|
467
|
-
this._drawLast.next = order;
|
|
468
|
-
|
|
469
|
-
order.next = null;
|
|
470
|
-
this._drawLast = order;
|
|
471
|
-
|
|
472
|
-
this._requestRedraw(layer);
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
_bringToBack(layer) {
|
|
476
|
-
const order = layer._order;
|
|
477
|
-
|
|
478
|
-
if (!order) { return; }
|
|
479
|
-
|
|
480
|
-
const next = order.next;
|
|
481
|
-
const prev = order.prev;
|
|
482
|
-
|
|
483
403
|
if (prev) {
|
|
484
404
|
prev.next = next;
|
|
485
405
|
} else {
|
|
486
|
-
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
if (next) {
|
|
490
|
-
next.prev = prev;
|
|
491
|
-
} else if (prev) {
|
|
492
|
-
// Update last entry unless this is the
|
|
493
|
-
// single entry
|
|
494
|
-
this._drawLast = prev;
|
|
406
|
+
this._drawFirst = next;
|
|
495
407
|
}
|
|
496
|
-
|
|
497
|
-
order.prev = null;
|
|
498
|
-
|
|
499
|
-
order.next = this._drawFirst;
|
|
500
|
-
this._drawFirst.prev = order;
|
|
501
|
-
this._drawFirst = order;
|
|
502
|
-
|
|
503
|
-
this._requestRedraw(layer);
|
|
504
408
|
}
|
|
505
409
|
}
|
|
@@ -37,9 +37,6 @@ export class Circle extends CircleMarker {
|
|
|
37
37
|
throw new Error('Circle: the radius is an option in Maplair. Use new Circle(latlng, {radius}).');
|
|
38
38
|
}
|
|
39
39
|
super(latlng, options);
|
|
40
|
-
|
|
41
|
-
if (isNaN(this.options.radius)) { throw new Error('Circle radius cannot be NaN'); }
|
|
42
|
-
|
|
43
40
|
this.callInitHooks(Circle);
|
|
44
41
|
}
|
|
45
42
|
|
|
@@ -63,15 +60,17 @@ export class Circle extends CircleMarker {
|
|
|
63
60
|
const lng = this._latlng.lng,
|
|
64
61
|
lat = this._latlng.lat,
|
|
65
62
|
map = this._map,
|
|
66
|
-
crs = map.options.crs
|
|
63
|
+
crs = map.options.crs,
|
|
64
|
+
renderer = this._renderer,
|
|
65
|
+
zoom = renderer._pathZoom;
|
|
67
66
|
|
|
68
67
|
if (crs.distance === EarthCRS.distance) {
|
|
69
68
|
const d = Math.PI / 180,
|
|
70
69
|
latR = (this._radius / EarthCRS.R) / d,
|
|
71
|
-
top = map.project([lat + latR, lng]),
|
|
72
|
-
bottom = map.project([lat - latR, lng]),
|
|
70
|
+
top = map.project([lat + latR, lng], zoom),
|
|
71
|
+
bottom = map.project([lat - latR, lng], zoom),
|
|
73
72
|
p = top.add(bottom).divideBy(2),
|
|
74
|
-
lat2 = map.unproject(p).lat;
|
|
73
|
+
lat2 = map.unproject(p, zoom).lat;
|
|
75
74
|
// Longitude span from the haversine form of the spherical law of cosines. The plain acos() form
|
|
76
75
|
// loses precision for radii of about a metre and less, where cos(latR) is too close to 1 (#6120).
|
|
77
76
|
let lngR = 2 * Math.asin(Math.sqrt(
|
|
@@ -79,18 +78,19 @@ export class Circle extends CircleMarker {
|
|
|
79
78
|
(Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;
|
|
80
79
|
|
|
81
80
|
if (isNaN(lngR) || lngR === 0) {
|
|
82
|
-
lngR = latR / Math.cos(
|
|
81
|
+
lngR = latR / Math.cos(lat * d); // Fallback for edge case, #2425
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
this._point = p.subtract(
|
|
86
|
-
|
|
87
|
-
this.
|
|
84
|
+
this._point = p.subtract(renderer._pathOrigin);
|
|
85
|
+
// distances rather than x/y deltas, for projections that rotate the axes
|
|
86
|
+
this._pxRadius = isNaN(lngR) ? 0 : p.distanceTo(map.project([lat2, lng - lngR], zoom));
|
|
87
|
+
this._pxRadiusY = p.distanceTo(top);
|
|
88
88
|
|
|
89
89
|
} else {
|
|
90
90
|
const latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));
|
|
91
91
|
|
|
92
|
-
this._point =
|
|
93
|
-
this._pxRadius = Math.abs(this._point.x -
|
|
92
|
+
this._point = renderer._latLngToLayerPoint(this._latlng);
|
|
93
|
+
this._pxRadius = Math.abs(this._point.x - renderer._latLngToLayerPoint(latlng2).x);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
this._updateBounds();
|
|
@@ -3,6 +3,7 @@ import * as Util from '../../core/Util.js';
|
|
|
3
3
|
import {LatLng} from '../../geo/LatLng.js';
|
|
4
4
|
import {Bounds} from '../../geometry/Bounds.js';
|
|
5
5
|
import {pointToGeoJSON} from '../GeoJSONUtil.js';
|
|
6
|
+
/** @import {MaplairMap} from '../../map/Map.js' */
|
|
6
7
|
/** @import {Feature} from 'geojson' */
|
|
7
8
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
8
9
|
/** @import {MaplairEvent} from '../../core/Events.js' */
|
|
@@ -49,11 +50,20 @@ export class CircleMarker extends Path {
|
|
|
49
50
|
super();
|
|
50
51
|
Util.setOptions(this, options);
|
|
51
52
|
this._latlng = new LatLng(latlng);
|
|
52
|
-
this.
|
|
53
|
+
this.setRadius(this.options.radius);
|
|
53
54
|
|
|
54
55
|
this.callInitHooks(CircleMarker);
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @param {MaplairMap} map
|
|
60
|
+
*/
|
|
61
|
+
beforeAdd(map) {
|
|
62
|
+
super.beforeAdd(map);
|
|
63
|
+
// before the marker is drawn, see `DisplaceHandler`
|
|
64
|
+
map._displaceHandler?._beforeMarkerAdd(this);
|
|
65
|
+
}
|
|
66
|
+
|
|
57
67
|
/**
|
|
58
68
|
* Sets the position of a circle marker to a new location.
|
|
59
69
|
* @param {LatLngExpression} latlng
|
|
@@ -81,7 +91,10 @@ export class CircleMarker extends Path {
|
|
|
81
91
|
* @returns {this}
|
|
82
92
|
*/
|
|
83
93
|
setRadius(radius) {
|
|
84
|
-
|
|
94
|
+
const r = Util.toNumber(radius);
|
|
95
|
+
if (isNaN(r)) { throw new Error(`Invalid radius: ${radius}`); }
|
|
96
|
+
/** @type {number} */
|
|
97
|
+
this._radius = this.options.radius = r;
|
|
85
98
|
return this.redraw();
|
|
86
99
|
}
|
|
87
100
|
|
|
@@ -108,7 +121,7 @@ export class CircleMarker extends Path {
|
|
|
108
121
|
|
|
109
122
|
_project() {
|
|
110
123
|
// snapped to whole pixels: subpixel precision is invisible on markers but slows down rendering many of them
|
|
111
|
-
this._point = this.
|
|
124
|
+
this._point = this._renderer._latLngToLayerPoint(this._latlng)._round();
|
|
112
125
|
this._pxRadius = this._radius;
|
|
113
126
|
this._updateBounds();
|
|
114
127
|
}
|
|
@@ -92,9 +92,11 @@ Path.include({
|
|
|
92
92
|
CircleMarker.include({
|
|
93
93
|
setRadius(radius) {
|
|
94
94
|
this._takeZoomStyles({radius});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
if (!this._zoomStyles?.radius) { return setRadius.call(this, radius); }
|
|
96
|
+
if (this._map) { return setRadius.call(this, evaluate(radius, this._map.getZoom())); }
|
|
97
|
+
// evaluated when the circle marker is added to a map
|
|
98
|
+
this.options.radius = this._radius = radius;
|
|
99
|
+
return this;
|
|
98
100
|
}
|
|
99
101
|
});
|
|
100
102
|
|
package/src/layer/vector/Path.js
CHANGED
|
@@ -36,14 +36,16 @@ import * as Util from '../../core/Util.js';
|
|
|
36
36
|
* Applied when the element is created; [`setStyle`](#path-setstyle) does not update it
|
|
37
37
|
* afterwards.
|
|
38
38
|
* @property {Renderer} [renderer] Use this specific instance of `Renderer` for this
|
|
39
|
-
* path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)
|
|
40
|
-
*
|
|
39
|
+
* path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)
|
|
40
|
+
* (`SVG` by default), or in a custom pane, a renderer of the same kind created for
|
|
41
|
+
* that pane. If set, it overrides the `pane` option.
|
|
41
42
|
* @extends InteractiveLayerOptions
|
|
42
43
|
*/
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
|
-
* An abstract class that contains options and
|
|
46
|
-
*
|
|
46
|
+
* An abstract class that contains options and methods shared between vector overlays
|
|
47
|
+
* (`Polyline`, `Polygon`, `Rectangle`, `Circle`, `CircleMarker`). Do not use it
|
|
48
|
+
* directly. Extends `Layer`.
|
|
47
49
|
*/
|
|
48
50
|
export class Path extends Layer {
|
|
49
51
|
|
|
@@ -162,9 +164,13 @@ export class Path extends Layer {
|
|
|
162
164
|
this._update();
|
|
163
165
|
}
|
|
164
166
|
|
|
167
|
+
_togglesPopupOnClick() {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
|
|
165
171
|
_clickTolerance() {
|
|
166
172
|
// used when doing hit detection for Canvas layers
|
|
167
|
-
return (this.options.stroke ? this.options.weight / 2 : 0) +
|
|
173
|
+
return (this.options.stroke ? this.options.weight / 2 || 0 : 0) +
|
|
168
174
|
(this._renderer.options.tolerance || 0);
|
|
169
175
|
}
|
|
170
176
|
}
|
|
@@ -124,14 +124,14 @@ export class Polygon extends Polyline {
|
|
|
124
124
|
// polygons need a different clipping algorithm so we redefine that
|
|
125
125
|
|
|
126
126
|
let bounds = this._renderer._bounds;
|
|
127
|
-
const w = this.options.weight,
|
|
127
|
+
const w = +this.options.weight || 0,
|
|
128
128
|
p = new Point(w, w);
|
|
129
129
|
|
|
130
130
|
// increase clip padding by stroke width to avoid stroke on clip edges
|
|
131
131
|
bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));
|
|
132
132
|
|
|
133
133
|
this._parts = [];
|
|
134
|
-
if (!this._pxBounds
|
|
134
|
+
if (!this._pxBounds?.intersects(bounds)) {
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
137
|
|
|
@@ -152,19 +152,20 @@ export class Polygon extends Polyline {
|
|
|
152
152
|
this._renderer._updatePoly(this, true);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
_isClosed() {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
|
|
155
159
|
// Needed by the `Canvas` renderer for interactivity
|
|
156
160
|
_containsPoint(p) {
|
|
157
|
-
let inside = false
|
|
158
|
-
part, p1, p2, i, j, k, len, len2;
|
|
161
|
+
let inside = false;
|
|
159
162
|
|
|
160
|
-
if (!this._pxBounds
|
|
163
|
+
if (!this._pxBounds?.contains(p)) { return false; }
|
|
161
164
|
|
|
162
165
|
// ray casting algorithm for detecting if point is in polygon
|
|
163
|
-
for (
|
|
164
|
-
part =
|
|
165
|
-
|
|
166
|
-
for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
|
|
167
|
-
p1 = part[j];
|
|
166
|
+
for (const part of this._parts) {
|
|
167
|
+
for (let j = 0, len = part.length, k = len - 1; j < len; k = j++) {
|
|
168
|
+
const p1 = part[j],
|
|
168
169
|
p2 = part[k];
|
|
169
170
|
|
|
170
171
|
if (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {
|