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
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import {Control} from './Control.js';
|
|
2
|
+
import {ButtonControl} from './ButtonControl.js';
|
|
3
|
+
import * as DomUtil from '../dom/DomUtil.js';
|
|
4
|
+
import * as DomEvent from '../dom/DomEvent.js';
|
|
5
|
+
import {I18n} from '../core/I18n.js';
|
|
6
|
+
/** @import {ControlOptions} from './Control.js' */
|
|
7
|
+
/** @import {MaplairMap} from '../map/Map.js' */
|
|
8
|
+
/** @import {Layer} from '../layer/Layer.js' */
|
|
9
|
+
/** @import {MaplairEvent} from '../core/Events.js' */
|
|
10
|
+
|
|
11
|
+
const icon = path => `<svg aria-hidden="true" width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="${path}"/></svg>`;
|
|
12
|
+
const previousIcon = icon('M3 3h2v10H3zm10 0v10L6 8z'),
|
|
13
|
+
playIcon = icon('M4 2v12l10-6z'),
|
|
14
|
+
pauseIcon = icon('M4 3h3v10H4zm5 0h3v10H9z'),
|
|
15
|
+
nextIcon = icon('M11 3h2v10h-2zM3 3v10l7-5z');
|
|
16
|
+
|
|
17
|
+
const durationRe = /^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/;
|
|
18
|
+
|
|
19
|
+
// Parses an ISO 8601 duration like `'PT5M'` or `'P1Y2M'` into calendar years and months
|
|
20
|
+
// and the milliseconds of the units with a fixed length
|
|
21
|
+
function parseDuration(duration) {
|
|
22
|
+
const match = durationRe.exec(duration);
|
|
23
|
+
if (!match || duration === 'P' || duration.endsWith('T')) {
|
|
24
|
+
throw new Error(`Invalid or unsupported ISO 8601 duration "${duration}".`);
|
|
25
|
+
}
|
|
26
|
+
const [years, months, weeks, days, hours, minutes, seconds] = match.slice(1).map(n => Number(n ?? 0));
|
|
27
|
+
return {years, months, ms: ((((weeks * 7 + days) * 24 + hours) * 60 + minutes) * 60 + seconds) * 1000};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Returns the time `n` times the duration after the given time, adding years and months in UTC
|
|
31
|
+
function addDuration(time, duration, n) {
|
|
32
|
+
const date = new Date(time);
|
|
33
|
+
date.setUTCFullYear(date.getUTCFullYear() + n * duration.years, date.getUTCMonth() + n * duration.months);
|
|
34
|
+
return new Date(+date + n * duration.ms);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parseDate(date) {
|
|
38
|
+
const time = Date.parse(date);
|
|
39
|
+
if (Number.isNaN(time)) {
|
|
40
|
+
throw new Error(`Invalid date "${date}".`);
|
|
41
|
+
}
|
|
42
|
+
return new Date(time);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Returns the times of an ISO 8601 interval (start/end, start/duration or duration/end,
|
|
46
|
+
// optionally with the period as third part), every period from the start
|
|
47
|
+
function intervalTimes(interval, period) {
|
|
48
|
+
const parts = interval.split('/');
|
|
49
|
+
if (parts.length === 3) {
|
|
50
|
+
period = parts.pop();
|
|
51
|
+
}
|
|
52
|
+
if (parts.length !== 2) {
|
|
53
|
+
throw new Error(`Invalid ISO 8601 interval "${interval}".`);
|
|
54
|
+
}
|
|
55
|
+
const [first, second] = parts,
|
|
56
|
+
step = parseDuration(period);
|
|
57
|
+
let start, end;
|
|
58
|
+
if (first.startsWith('P')) {
|
|
59
|
+
end = parseDate(second);
|
|
60
|
+
start = addDuration(end, parseDuration(first), -1);
|
|
61
|
+
} else {
|
|
62
|
+
start = parseDate(first);
|
|
63
|
+
end = second.startsWith('P') ? addDuration(start, parseDuration(second), 1) : parseDate(second);
|
|
64
|
+
}
|
|
65
|
+
if (!(addDuration(start, step, 1) > start)) {
|
|
66
|
+
throw new Error(`The period "${period}" has to be positive.`);
|
|
67
|
+
}
|
|
68
|
+
const times = [];
|
|
69
|
+
for (let i = 0, time = start; time <= end; time = addDuration(start, step, ++i)) {
|
|
70
|
+
times.push(time);
|
|
71
|
+
}
|
|
72
|
+
return times;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Options of `TimeControl`.
|
|
77
|
+
* @typedef {object} TimeControlOptions
|
|
78
|
+
* @property {string} [position='bottomleft'] The position of the control (one of the map
|
|
79
|
+
* corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or
|
|
80
|
+
* `'bottomright'`.
|
|
81
|
+
* @property {(Date|number|string)[]} [times] The times to step through in ascending
|
|
82
|
+
* order: dates, timestamps or date strings (parsed with `Date.parse()`).
|
|
83
|
+
* @property {string} [interval] Instead of `times`, an ISO 8601 time interval whose times
|
|
84
|
+
* every [`period`](#timecontrol-period) from the start up to the end are stepped
|
|
85
|
+
* through: `start/end` (e.g. `'2026-10-17T00:00Z/2026-10-18T00:00Z'`), `start/duration`
|
|
86
|
+
* (e.g. `'2026-10-17T00:00Z/P1D'`) or `duration/end` (e.g. `'PT24H/2026-10-18T00:00Z'`).
|
|
87
|
+
* A third part is the period, as in the time dimension of WMS capabilities (e.g.
|
|
88
|
+
* `'2026-10-17T00:00Z/2026-10-18T00:00Z/PT5M'`). Start and end are parsed with
|
|
89
|
+
* `Date.parse()`, e.g. `2026-10-17`, `2026-10-17T12:00Z` or
|
|
90
|
+
* `2026-10-17T12:00:00.000+02:00` (without a time zone, times are local times).
|
|
91
|
+
* @property {string} [period='P1D'] The ISO 8601 duration between the times of the
|
|
92
|
+
* `interval`: integer numbers of years, months, weeks, days, hours, minutes and seconds,
|
|
93
|
+
* e.g. `'PT1H'`, `'PT5M'`, `'P1DT12H'` or `'P1M'` (years and months are added in UTC).
|
|
94
|
+
* @property {Date|number|string} [time] The initial time (the nearest of the times), by
|
|
95
|
+
* default the current time.
|
|
96
|
+
* @property {(Layer & TimeLayer)[]} [layers=[]] The layers showing the current time, see
|
|
97
|
+
* `addLayer()`.
|
|
98
|
+
* @property {number} [transitionTime=1000] The minimum time in milliseconds a time is
|
|
99
|
+
* shown while playing. The next time is shown only after the layers have loaded, too.
|
|
100
|
+
* @property {boolean} [loop=false] Whether playing starts over after the last time
|
|
101
|
+
* instead of stopping, and the buttons step from the last time to the first one and
|
|
102
|
+
* back.
|
|
103
|
+
* @property {(date: Date) => string} [formatTime] Returns the text of the label for a
|
|
104
|
+
* time, by default the date and time by `Intl.DateTimeFormat` in the [locale](#i18n)
|
|
105
|
+
* (or the browser's language) and the browser's time zone.
|
|
106
|
+
* @extends ControlOptions
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A layer showing a given time, see `TimeControl`.
|
|
111
|
+
* @typedef {object} TimeLayer
|
|
112
|
+
* @property {(date: Date) => any} [setTime] Shows the given time.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The event object of `timechange`.
|
|
117
|
+
* @typedef {object} TimeChangeEvent
|
|
118
|
+
* @property {Date} time The current time.
|
|
119
|
+
* @property {number} index The index of the current time in the times of the control.
|
|
120
|
+
* @extends MaplairEvent
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A control to step through or play the times of time-dependent layers, e.g. an
|
|
125
|
+
* animated weather radar from a WMS with a `TIME` dimension. It has buttons for the
|
|
126
|
+
* previous and next time and to play or pause, a slider (usable with the arrow, Home
|
|
127
|
+
* and End keys) and a label with the current time.
|
|
128
|
+
*
|
|
129
|
+
* Each of the `layers` shows the current time: by its method `setTime(date)` if it has
|
|
130
|
+
* one, otherwise by the parameter `time` set to the time in ISO 8601 format
|
|
131
|
+
* (`date.toISOString()`): the WMS parameter of a `WMSTileLayer` (with `setParams()`) or
|
|
132
|
+
* the variable of the URL template of a `TileLayer` (e.g.
|
|
133
|
+
* `'https://…/{time}/{z}/{x}/{y}.png'`, with `setUrl()`). The tiles of the previous
|
|
134
|
+
* time stay visible until the new ones have loaded, and playing waits for them (the
|
|
135
|
+
* `load` event), so that no time is skipped with slow servers.
|
|
136
|
+
*
|
|
137
|
+
* Replaces the [Leaflet.TimeDimension](https://github.com/socib/Leaflet.TimeDimension)
|
|
138
|
+
* plugin for the common use cases.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```js
|
|
142
|
+
* const radar = new WMSTileLayer('https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r-t.cgi', {
|
|
143
|
+
* layers: 'nexrad-n0r-wmst',
|
|
144
|
+
* format: 'image/png',
|
|
145
|
+
* transparent: true
|
|
146
|
+
* }).addTo(map);
|
|
147
|
+
*
|
|
148
|
+
* new TimeControl({
|
|
149
|
+
* interval: '2013-05-20T18:00Z/2013-05-20T22:00Z',
|
|
150
|
+
* period: 'PT5M',
|
|
151
|
+
* layers: [radar],
|
|
152
|
+
* loop: true
|
|
153
|
+
* }).addTo(map);
|
|
154
|
+
*
|
|
155
|
+
* map.on('timechange', e => console.log(e.time));
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @fires MaplairMap#timechange {TimeChangeEvent} Fired when the current time of a
|
|
159
|
+
* `TimeControl` changes.
|
|
160
|
+
*/
|
|
161
|
+
export class TimeControl extends Control {
|
|
162
|
+
|
|
163
|
+
static defaultOptions = {
|
|
164
|
+
position: 'bottomleft',
|
|
165
|
+
times: undefined,
|
|
166
|
+
interval: undefined,
|
|
167
|
+
period: 'P1D',
|
|
168
|
+
time: undefined,
|
|
169
|
+
layers: [],
|
|
170
|
+
transitionTime: 1000,
|
|
171
|
+
loop: false,
|
|
172
|
+
formatTime: undefined
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Creates a time control.
|
|
177
|
+
* @param {...TimeControlOptions} args The options.
|
|
178
|
+
*/
|
|
179
|
+
constructor(...args) {
|
|
180
|
+
super(...args);
|
|
181
|
+
const {times, interval, period, time, layers} = this.options;
|
|
182
|
+
this._layers = [];
|
|
183
|
+
this._playing = false;
|
|
184
|
+
this._times = [];
|
|
185
|
+
this._index = -1;
|
|
186
|
+
this.setTimes(interval ? intervalTimes(interval, period) : times ?? [], time);
|
|
187
|
+
for (const layer of layers) {
|
|
188
|
+
this.addLayer(layer);
|
|
189
|
+
}
|
|
190
|
+
this.callInitHooks(TimeControl);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @internal
|
|
195
|
+
* @param {MaplairMap} map
|
|
196
|
+
* @returns {HTMLElement}
|
|
197
|
+
*/
|
|
198
|
+
onAdd(map) {
|
|
199
|
+
const container = DomUtil.create('div', 'maplair-bar maplair-control-time');
|
|
200
|
+
DomEvent.disableClickPropagation(container);
|
|
201
|
+
DomEvent.disableScrollPropagation(container);
|
|
202
|
+
|
|
203
|
+
this._previousButton = new ButtonControl({
|
|
204
|
+
className: 'maplair-control-time-previous',
|
|
205
|
+
content: previousIcon,
|
|
206
|
+
title: I18n.translate('Step back'),
|
|
207
|
+
onClick: () => this.previous()
|
|
208
|
+
});
|
|
209
|
+
this._playButton = new ButtonControl({
|
|
210
|
+
className: 'maplair-control-time-play',
|
|
211
|
+
states: [
|
|
212
|
+
{name: 'play', content: playIcon, title: I18n.translate('Play'), onClick: () => this.play()},
|
|
213
|
+
{name: 'pause', content: pauseIcon, title: I18n.translate('Pause'), onClick: () => this.pause()}
|
|
214
|
+
]
|
|
215
|
+
});
|
|
216
|
+
this._nextButton = new ButtonControl({
|
|
217
|
+
className: 'maplair-control-time-next',
|
|
218
|
+
content: nextIcon,
|
|
219
|
+
title: I18n.translate('Step forward'),
|
|
220
|
+
onClick: () => this.next()
|
|
221
|
+
});
|
|
222
|
+
for (const button of [this._previousButton, this._playButton, this._nextButton]) {
|
|
223
|
+
button._map = map;
|
|
224
|
+
button._createButton(container);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const slider = this._slider = DomUtil.create('input', 'maplair-control-time-slider', container);
|
|
228
|
+
slider.type = 'range';
|
|
229
|
+
slider.min = '0';
|
|
230
|
+
slider.step = '1';
|
|
231
|
+
slider.setAttribute('aria-label', I18n.translate('Time'));
|
|
232
|
+
DomEvent.on(slider, 'input', this._onSliderInput, this);
|
|
233
|
+
|
|
234
|
+
this._label = DomUtil.create('span', 'maplair-control-time-label', container);
|
|
235
|
+
|
|
236
|
+
this._formatter = new Intl.DateTimeFormat(I18n.getLocale() ?? undefined, {dateStyle: 'short', timeStyle: 'short'});
|
|
237
|
+
this._updateControl();
|
|
238
|
+
return container;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* @internal
|
|
243
|
+
*/
|
|
244
|
+
onRemove() {
|
|
245
|
+
this.pause();
|
|
246
|
+
this._slider = null;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
_onSliderInput() {
|
|
250
|
+
this.pause();
|
|
251
|
+
this._setIndex(Number(this._slider.value));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
_updateControl() {
|
|
255
|
+
if (!this._slider) { return; }
|
|
256
|
+
const index = this._index,
|
|
257
|
+
last = this._times.length - 1,
|
|
258
|
+
time = this.getTime(),
|
|
259
|
+
text = time ? (this.options.formatTime ?? this._formatter.format)(time) : '',
|
|
260
|
+
loop = this.options.loop;
|
|
261
|
+
|
|
262
|
+
this._slider.max = String(Math.max(last, 0));
|
|
263
|
+
this._slider.value = String(Math.max(index, 0));
|
|
264
|
+
this._slider.disabled = last < 1;
|
|
265
|
+
this._slider.setAttribute('aria-valuetext', text);
|
|
266
|
+
this._label.textContent = text;
|
|
267
|
+
|
|
268
|
+
this._playButton.setState(this._playing ? 'pause' : 'play');
|
|
269
|
+
this._setDisabled(this._playButton, last < 1);
|
|
270
|
+
this._setDisabled(this._previousButton, last < 1 || (index === 0 && !loop));
|
|
271
|
+
this._setDisabled(this._nextButton, last < 1 || (index === last && !loop));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
_setDisabled(button, disabled) {
|
|
275
|
+
if (disabled) {
|
|
276
|
+
button.disable();
|
|
277
|
+
} else {
|
|
278
|
+
button.enable();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Sets the times to step through, see the [`times` option](#timecontrol-times), and
|
|
284
|
+
* shows the nearest of them to `time`, by default to the current time of the control.
|
|
285
|
+
* @param {(Date|number|string)[]} times
|
|
286
|
+
* @param {Date|number|string} [time]
|
|
287
|
+
* @returns {this}
|
|
288
|
+
*/
|
|
289
|
+
setTimes(times, time = this.getTime()) {
|
|
290
|
+
this._times = times.map(t => new Date(t));
|
|
291
|
+
this._index = -1;
|
|
292
|
+
if (this._times.length < 2) {
|
|
293
|
+
this.pause();
|
|
294
|
+
}
|
|
295
|
+
return this.setTime(time ?? Date.now());
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Returns the times to step through.
|
|
300
|
+
* @returns {Date[]}
|
|
301
|
+
*/
|
|
302
|
+
getTimes() {
|
|
303
|
+
return this._times;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Shows the nearest of the times to the given time.
|
|
308
|
+
* @param {Date|number|string} time
|
|
309
|
+
* @returns {this}
|
|
310
|
+
*/
|
|
311
|
+
setTime(time) {
|
|
312
|
+
const ms = +new Date(time);
|
|
313
|
+
let index = this._times.length ? 0 : -1;
|
|
314
|
+
this._times.forEach((t, i) => {
|
|
315
|
+
if (Math.abs(+t - ms) < Math.abs(+this._times[index] - ms)) {
|
|
316
|
+
index = i;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
return this._setIndex(index);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Returns the current time.
|
|
324
|
+
* @returns {Date|undefined}
|
|
325
|
+
*/
|
|
326
|
+
getTime() {
|
|
327
|
+
return this._times[this._index];
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
_setIndex(index) {
|
|
331
|
+
if (index !== this._index) {
|
|
332
|
+
this._index = index;
|
|
333
|
+
for (const layer of this._layers) {
|
|
334
|
+
this._updateLayer(layer);
|
|
335
|
+
}
|
|
336
|
+
if (index >= 0) {
|
|
337
|
+
this._map?.fire('timechange', {time: this.getTime(), index});
|
|
338
|
+
}
|
|
339
|
+
if (this._playing) {
|
|
340
|
+
this._schedule();
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
this._updateControl();
|
|
344
|
+
return this;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Shows the next time (or the first one after the last one if looping).
|
|
349
|
+
* @returns {this}
|
|
350
|
+
*/
|
|
351
|
+
next() {
|
|
352
|
+
if (this._index < this._times.length - 1) {
|
|
353
|
+
this._setIndex(this._index + 1);
|
|
354
|
+
} else if (this.options.loop && this._times.length > 1) {
|
|
355
|
+
this._setIndex(0);
|
|
356
|
+
}
|
|
357
|
+
return this;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Shows the previous time (or the last one before the first one if looping).
|
|
362
|
+
* @returns {this}
|
|
363
|
+
*/
|
|
364
|
+
previous() {
|
|
365
|
+
if (this._index > 0) {
|
|
366
|
+
this._setIndex(this._index - 1);
|
|
367
|
+
} else if (this.options.loop && this._times.length > 1) {
|
|
368
|
+
this._setIndex(this._times.length - 1);
|
|
369
|
+
}
|
|
370
|
+
return this;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Plays the times one after the other, each for at least the
|
|
375
|
+
* [`transitionTime`](#timecontrol-transitiontime) and until the layers have loaded.
|
|
376
|
+
* Starts at the first time if the last one is shown. Stops at the last time unless
|
|
377
|
+
* [looping](#timecontrol-loop).
|
|
378
|
+
* @returns {this}
|
|
379
|
+
*/
|
|
380
|
+
play() {
|
|
381
|
+
if (this._playing || this._times.length < 2) { return this; }
|
|
382
|
+
this._playing = true;
|
|
383
|
+
if (this._index === this._times.length - 1) {
|
|
384
|
+
// also schedules the next time
|
|
385
|
+
this._setIndex(0);
|
|
386
|
+
} else {
|
|
387
|
+
this._schedule();
|
|
388
|
+
this._updateControl();
|
|
389
|
+
}
|
|
390
|
+
return this;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Stops playing.
|
|
395
|
+
* @returns {this}
|
|
396
|
+
*/
|
|
397
|
+
pause() {
|
|
398
|
+
clearTimeout(this._timeout);
|
|
399
|
+
this._timeout = null;
|
|
400
|
+
if (this._playing) {
|
|
401
|
+
this._playing = false;
|
|
402
|
+
this._updateControl();
|
|
403
|
+
}
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Returns `true` while playing.
|
|
409
|
+
* @returns {boolean}
|
|
410
|
+
*/
|
|
411
|
+
isPlaying() {
|
|
412
|
+
return this._playing;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Shows the next time after the transition time, once the layers have loaded
|
|
416
|
+
_schedule() {
|
|
417
|
+
clearTimeout(this._timeout);
|
|
418
|
+
this._timeout = setTimeout(() => {
|
|
419
|
+
this._timeout = null;
|
|
420
|
+
this._advance();
|
|
421
|
+
}, this.options.transitionTime);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
_advance() {
|
|
425
|
+
if (!this._playing || this._timeout || this._layers.some(layer => layer._map && layer.isLoading?.())) { return; }
|
|
426
|
+
if (this._index < this._times.length - 1 || this.options.loop) {
|
|
427
|
+
this.next();
|
|
428
|
+
} else {
|
|
429
|
+
this.pause();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
_updateLayer(layer) {
|
|
434
|
+
const time = this.getTime();
|
|
435
|
+
if (!time) { return; }
|
|
436
|
+
if (typeof layer.setTime === 'function') {
|
|
437
|
+
layer.setTime(time);
|
|
438
|
+
} else if (typeof layer.setParams === 'function') {
|
|
439
|
+
layer.setParams({time: time.toISOString()});
|
|
440
|
+
} else if (typeof layer.setUrl === 'function') {
|
|
441
|
+
layer.options.time = time.toISOString();
|
|
442
|
+
layer.setUrl(layer._url, false);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Adds a layer showing the current time, see the [`layers` option](#timecontrol-layers).
|
|
448
|
+
* The layer still has to be added to the map.
|
|
449
|
+
* @param {Layer & TimeLayer} layer
|
|
450
|
+
* @returns {this}
|
|
451
|
+
*/
|
|
452
|
+
addLayer(layer) {
|
|
453
|
+
if (this._layers.includes(layer)) { return this; }
|
|
454
|
+
this._layers.push(layer);
|
|
455
|
+
layer.on('load remove', this._advance, this);
|
|
456
|
+
this._updateLayer(layer);
|
|
457
|
+
return this;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Removes a layer from the layers showing the current time.
|
|
462
|
+
* @param {Layer} layer
|
|
463
|
+
* @returns {this}
|
|
464
|
+
*/
|
|
465
|
+
removeLayer(layer) {
|
|
466
|
+
this._layers = this._layers.filter(l => l !== layer);
|
|
467
|
+
layer.off('load remove', this._advance, this);
|
|
468
|
+
this._advance();
|
|
469
|
+
return this;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
@@ -41,13 +41,11 @@ import {I18n} from '../core/I18n.js';
|
|
|
41
41
|
*/
|
|
42
42
|
export class ZoomControl extends Control {
|
|
43
43
|
|
|
44
|
-
static {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
}
|
|
44
|
+
static defaultOptions = {
|
|
45
|
+
position: 'topleft',
|
|
46
|
+
zoomInText: '<span aria-hidden="true">+</span>',
|
|
47
|
+
zoomOutText: '<span aria-hidden="true">−</span>',
|
|
48
|
+
};
|
|
51
49
|
|
|
52
50
|
/**
|
|
53
51
|
* Creates a zoom control.
|
package/src/control/index.js
CHANGED
|
@@ -10,4 +10,5 @@ export {ScaleControl} from './ScaleControl.js';
|
|
|
10
10
|
export {SearchControl} from './SearchControl.js';
|
|
11
11
|
export {SideBySideControl} from './SideBySideControl.js';
|
|
12
12
|
export {TextControl} from './TextControl.js';
|
|
13
|
+
export {TimeControl} from './TimeControl.js';
|
|
13
14
|
export {ZoomControl} from './ZoomControl.js';
|
package/src/core/Class.js
CHANGED
|
@@ -12,28 +12,24 @@ import * as Util from './Util.js';
|
|
|
12
12
|
*
|
|
13
13
|
* <h3 id="class-options">Options</h3>
|
|
14
14
|
*
|
|
15
|
-
* `options` is a special property
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* `options` is a special property whose defaults, the static `defaultOptions` of the
|
|
16
|
+
* class, are merged with those of the parent class instead of overriding them
|
|
17
|
+
* completely, which makes managing configuration of objects and default values
|
|
18
|
+
* convenient:
|
|
19
19
|
*
|
|
20
20
|
* ```js
|
|
21
21
|
* class MyClass extends Class {
|
|
22
|
-
* static {
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* });
|
|
27
|
-
* }
|
|
22
|
+
* static defaultOptions = {
|
|
23
|
+
* myOption1: 'foo',
|
|
24
|
+
* myOption2: 'bar'
|
|
25
|
+
* };
|
|
28
26
|
* }
|
|
29
27
|
*
|
|
30
28
|
* class MyChildClass extends MyClass {
|
|
31
|
-
* static {
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* });
|
|
36
|
-
* }
|
|
29
|
+
* static defaultOptions = {
|
|
30
|
+
* myOption1: 'baz',
|
|
31
|
+
* myOption3: 5
|
|
32
|
+
* };
|
|
37
33
|
* }
|
|
38
34
|
*
|
|
39
35
|
* const a = new MyChildClass();
|
|
@@ -48,12 +44,10 @@ import * as Util from './Util.js';
|
|
|
48
44
|
*
|
|
49
45
|
* ```js
|
|
50
46
|
* class MyClass extends Class {
|
|
51
|
-
* static {
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* });
|
|
56
|
-
* }
|
|
47
|
+
* static defaultOptions = {
|
|
48
|
+
* foo: 'bar',
|
|
49
|
+
* bla: 5
|
|
50
|
+
* };
|
|
57
51
|
*
|
|
58
52
|
* constructor(options) {
|
|
59
53
|
* super();
|
|
@@ -165,12 +159,12 @@ export class Class {
|
|
|
165
159
|
* @returns {T}
|
|
166
160
|
*/
|
|
167
161
|
static include(props) {
|
|
168
|
-
const parentOptions = this.prototype.options;
|
|
169
162
|
for (const k of getAllMethodNames(props)) {
|
|
170
|
-
|
|
163
|
+
if (k !== 'constructor' && k !== 'options') {
|
|
164
|
+
this.prototype[k] = props[k];
|
|
165
|
+
}
|
|
171
166
|
}
|
|
172
167
|
if (props.options) {
|
|
173
|
-
this.prototype.options = parentOptions;
|
|
174
168
|
this.mergeOptions(props.options);
|
|
175
169
|
}
|
|
176
170
|
return this;
|
|
@@ -183,33 +177,35 @@ export class Class {
|
|
|
183
177
|
for (const k of Object.getOwnPropertyNames(obj)) {
|
|
184
178
|
yield k;
|
|
185
179
|
}
|
|
186
|
-
} while ((obj = Object.getPrototypeOf(obj)) !==
|
|
180
|
+
} while ((obj = Object.getPrototypeOf(obj)) !== null);
|
|
187
181
|
}
|
|
188
182
|
}
|
|
189
183
|
|
|
190
184
|
/**
|
|
191
|
-
*
|
|
185
|
+
* [Merges `options`](#class-options) into the `defaultOptions` of the class.
|
|
192
186
|
* @template {typeof Class} T
|
|
193
187
|
* @this {T}
|
|
194
188
|
* @param {object} options
|
|
195
189
|
* @returns {T}
|
|
196
190
|
*/
|
|
197
|
-
static
|
|
198
|
-
|
|
191
|
+
static mergeOptions(options) {
|
|
192
|
+
if (!Object.hasOwn(this, 'defaultOptions')) {
|
|
193
|
+
this.defaultOptions = Object.create(this.defaultOptions ?? Object.prototype);
|
|
194
|
+
}
|
|
195
|
+
Object.assign(this.defaultOptions, options);
|
|
199
196
|
return this;
|
|
200
197
|
}
|
|
201
198
|
|
|
202
199
|
/**
|
|
203
|
-
*
|
|
200
|
+
* Deprecated alias of `mergeOptions()`, kept for code written for Maplair 4.0.
|
|
201
|
+
* @deprecated Use `static defaultOptions = {…}` or `mergeOptions()`.
|
|
204
202
|
* @template {typeof Class} T
|
|
205
203
|
* @this {T}
|
|
206
204
|
* @param {object} options
|
|
207
205
|
* @returns {T}
|
|
208
206
|
*/
|
|
209
|
-
static
|
|
210
|
-
this.
|
|
211
|
-
Object.assign(this.prototype.options, options);
|
|
212
|
-
return this;
|
|
207
|
+
static setDefaultOptions(options) {
|
|
208
|
+
return this.mergeOptions(options);
|
|
213
209
|
}
|
|
214
210
|
|
|
215
211
|
/**
|
|
@@ -235,6 +231,11 @@ export class Class {
|
|
|
235
231
|
}
|
|
236
232
|
|
|
237
233
|
constructor() {
|
|
234
|
+
if (this.initialize) {
|
|
235
|
+
throw new Error(`${this.constructor.name}: initialize() is not called in Maplair. ` +
|
|
236
|
+
'Rename it to constructor() and call super() at its start.');
|
|
237
|
+
}
|
|
238
|
+
|
|
238
239
|
Util.setOptions(this);
|
|
239
240
|
}
|
|
240
241
|
|
package/src/core/Events.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {Class} from './Class.js';
|
|
2
2
|
import * as Util from './Util.js';
|
|
3
|
+
|
|
4
|
+
const warnedEvents = new Set();
|
|
3
5
|
/** @import {LatLng} from '../geo/LatLng.js' */
|
|
4
6
|
/** @import {LatLngBounds} from '../geo/LatLngBounds.js' */
|
|
5
7
|
/** @import {Point} from '../geometry/Point.js' */
|
|
@@ -95,6 +97,8 @@ import * as Util from './Util.js';
|
|
|
95
97
|
* @typedef {object} LayersControlEvent
|
|
96
98
|
* @property {Layer} layer The layer that was added or removed.
|
|
97
99
|
* @property {string} name The name of the layer that was added or removed.
|
|
100
|
+
* @property {Event} [originalEvent] The DOM event of the click on the entry in the
|
|
101
|
+
* layers control, `undefined` if the layer was added or removed by code.
|
|
98
102
|
* @extends MaplairEvent
|
|
99
103
|
*/
|
|
100
104
|
|
|
@@ -129,6 +133,13 @@ import * as Util from './Util.js';
|
|
|
129
133
|
* @extends MaplairEvent
|
|
130
134
|
*/
|
|
131
135
|
|
|
136
|
+
/**
|
|
137
|
+
* The event object of `worldcopyjump`.
|
|
138
|
+
* @typedef {object} WorldCopyJumpEvent
|
|
139
|
+
* @property {number} worlds The signed number of world widths by which the map pane moved.
|
|
140
|
+
* @extends MaplairEvent
|
|
141
|
+
*/
|
|
142
|
+
|
|
132
143
|
/**
|
|
133
144
|
* The event object of adding GeoJSON features.
|
|
134
145
|
* @typedef {object} GeoJSONEvent
|
|
@@ -259,13 +270,21 @@ export class Evented extends Class {
|
|
|
259
270
|
return this;
|
|
260
271
|
}
|
|
261
272
|
|
|
262
|
-
static __REMOVED_EVENTS =
|
|
273
|
+
static __REMOVED_EVENTS = {
|
|
274
|
+
mousedown: 'pointerdown',
|
|
275
|
+
mouseup: 'pointerup',
|
|
276
|
+
mouseover: 'pointerover',
|
|
277
|
+
mouseout: 'pointerout',
|
|
278
|
+
mousemove: 'pointermove',
|
|
279
|
+
keypress: 'keydown'
|
|
280
|
+
};
|
|
263
281
|
|
|
264
282
|
// attach listener (without syntactic sugar now)
|
|
265
283
|
_on(type, fn, context, _once) {
|
|
266
284
|
// To be removed in maplair 3
|
|
267
|
-
if (Evented.__REMOVED_EVENTS.
|
|
268
|
-
|
|
285
|
+
if (Object.hasOwn(Evented.__REMOVED_EVENTS, type) && !warnedEvents.has(type)) {
|
|
286
|
+
warnedEvents.add(type);
|
|
287
|
+
console.error(`The event ${type} has been removed in Maplair. Use ${Evented.__REMOVED_EVENTS[type]} instead.`);
|
|
269
288
|
}
|
|
270
289
|
|
|
271
290
|
if (typeof fn !== 'function') {
|