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.
Files changed (270) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/dist/esm/Maplair.js +14 -14
  3. package/dist/esm/control/AttributionControl.js +24 -14
  4. package/dist/esm/control/AttributionControl.js.map +1 -1
  5. package/dist/esm/control/ButtonControl.js +9 -11
  6. package/dist/esm/control/ButtonControl.js.map +1 -1
  7. package/dist/esm/control/ContextMenu.js +1 -3
  8. package/dist/esm/control/ContextMenu.js.map +1 -1
  9. package/dist/esm/control/Control.js +9 -16
  10. package/dist/esm/control/Control.js.map +1 -1
  11. package/dist/esm/control/FullscreenControl.js +5 -7
  12. package/dist/esm/control/FullscreenControl.js.map +1 -1
  13. package/dist/esm/control/LayersControl.js +144 -35
  14. package/dist/esm/control/LayersControl.js.map +1 -1
  15. package/dist/esm/control/LegendControl.js +7 -9
  16. package/dist/esm/control/LegendControl.js.map +1 -1
  17. package/dist/esm/control/MiniMapControl.js +14 -16
  18. package/dist/esm/control/MiniMapControl.js.map +1 -1
  19. package/dist/esm/control/RotateControl.js +1 -3
  20. package/dist/esm/control/RotateControl.js.map +1 -1
  21. package/dist/esm/control/ScaleControl.js +7 -9
  22. package/dist/esm/control/ScaleControl.js.map +1 -1
  23. package/dist/esm/control/SearchControl.js +99 -17
  24. package/dist/esm/control/SearchControl.js.map +1 -1
  25. package/dist/esm/control/SideBySideControl.js +1 -3
  26. package/dist/esm/control/SideBySideControl.js.map +1 -1
  27. package/dist/esm/control/TextControl.js +5 -7
  28. package/dist/esm/control/TextControl.js.map +1 -1
  29. package/dist/esm/control/TimeControl.js +408 -0
  30. package/dist/esm/control/TimeControl.js.map +1 -0
  31. package/dist/esm/control/ZoomControl.js +5 -7
  32. package/dist/esm/control/ZoomControl.js.map +1 -1
  33. package/dist/esm/core/Class.js +28 -37
  34. package/dist/esm/core/Class.js.map +1 -1
  35. package/dist/esm/core/Events.js +21 -8
  36. package/dist/esm/core/Events.js.map +1 -1
  37. package/dist/esm/core/Handler.js +13 -11
  38. package/dist/esm/core/Handler.js.map +1 -1
  39. package/dist/esm/core/Util.js +13 -1
  40. package/dist/esm/core/Util.js.map +1 -1
  41. package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
  42. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
  43. package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
  44. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  45. package/dist/esm/dom/DomEvent.js +8 -42
  46. package/dist/esm/dom/DomEvent.js.map +1 -1
  47. package/dist/esm/dom/DomUtil.js +14 -68
  48. package/dist/esm/dom/DomUtil.js.map +1 -1
  49. package/dist/esm/dom/Draggable.js +17 -18
  50. package/dist/esm/dom/Draggable.js.map +1 -1
  51. package/dist/esm/dom/PosAnimation.js +3 -25
  52. package/dist/esm/dom/PosAnimation.js.map +1 -1
  53. package/dist/esm/geo/LatLng.js +15 -5
  54. package/dist/esm/geo/LatLng.js.map +1 -1
  55. package/dist/esm/geo/crs/EPSG3395.js +1 -1
  56. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  57. package/dist/esm/geo/crs/EPSG3857.js +1 -1
  58. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  59. package/dist/esm/geo/crs/EPSG4326.js +1 -1
  60. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  61. package/dist/esm/geo/crs/EarthCRS.js +2 -2
  62. package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
  63. package/dist/esm/geo/crs/SimpleCRS.js +1 -1
  64. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  65. package/dist/esm/geo/projection/Projection.LonLat.js +1 -1
  66. package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
  67. package/dist/esm/geo/projection/Projection.Mercator.js +1 -1
  68. package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
  69. package/dist/esm/geo/projection/Projection.SphericalMercator.js +1 -1
  70. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
  71. package/dist/esm/geometry/LineUtil.js +36 -30
  72. package/dist/esm/geometry/LineUtil.js.map +1 -1
  73. package/dist/esm/geometry/PolyUtil.js +8 -27
  74. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  75. package/dist/esm/layer/BlanketOverlay.js +6 -8
  76. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  77. package/dist/esm/layer/DivOverlay.js +15 -20
  78. package/dist/esm/layer/DivOverlay.js.map +1 -1
  79. package/dist/esm/layer/GeoJSON.js +9 -145
  80. package/dist/esm/layer/GeoJSON.js.map +1 -1
  81. package/dist/esm/layer/GeoJSONUtil.js +75 -0
  82. package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
  83. package/dist/esm/layer/HeatLayer.js +15 -17
  84. package/dist/esm/layer/HeatLayer.js.map +1 -1
  85. package/dist/esm/layer/ImageOverlay.js +20 -26
  86. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  87. package/dist/esm/layer/Layer.js +8 -10
  88. package/dist/esm/layer/Layer.js.map +1 -1
  89. package/dist/esm/layer/LayerGroup.js +51 -0
  90. package/dist/esm/layer/LayerGroup.js.map +1 -1
  91. package/dist/esm/layer/Popup.js +26 -42
  92. package/dist/esm/layer/Popup.js.map +1 -1
  93. package/dist/esm/layer/SVGOverlay.js +2 -5
  94. package/dist/esm/layer/SVGOverlay.js.map +1 -1
  95. package/dist/esm/layer/Tooltip.js +15 -17
  96. package/dist/esm/layer/Tooltip.js.map +1 -1
  97. package/dist/esm/layer/VideoOverlay.js +12 -15
  98. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  99. package/dist/esm/layer/marker/DefaultIcon.js +15 -48
  100. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  101. package/dist/esm/layer/marker/DivIcon.js +7 -9
  102. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  103. package/dist/esm/layer/marker/Icon.js +7 -10
  104. package/dist/esm/layer/marker/Icon.js.map +1 -1
  105. package/dist/esm/layer/marker/Marker.Drag.js +1 -1
  106. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  107. package/dist/esm/layer/marker/Marker.Move.js +1 -2
  108. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  109. package/dist/esm/layer/marker/Marker.js +61 -33
  110. package/dist/esm/layer/marker/Marker.js.map +1 -1
  111. package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
  112. package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
  113. package/dist/esm/layer/marker/SvgIcon.js +6 -8
  114. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  115. package/dist/esm/layer/tile/GridLayer.js +85 -97
  116. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  117. package/dist/esm/layer/tile/TileLayer.js +28 -36
  118. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  119. package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
  120. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  121. package/dist/esm/layer/vector/Canvas.js +1 -3
  122. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  123. package/dist/esm/layer/vector/Circle.js +2 -2
  124. package/dist/esm/layer/vector/Circle.js.map +1 -1
  125. package/dist/esm/layer/vector/CircleMarker.js +17 -7
  126. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  127. package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
  128. package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
  129. package/dist/esm/layer/vector/Path.js +27 -20
  130. package/dist/esm/layer/vector/Path.js.map +1 -1
  131. package/dist/esm/layer/vector/Polygon.js +20 -4
  132. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  133. package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
  134. package/dist/esm/layer/vector/Polyline.js +23 -7
  135. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  136. package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
  137. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  138. package/dist/esm/layer/vector/SVG.js +5 -5
  139. package/dist/esm/layer/vector/SVG.js.map +1 -1
  140. package/dist/esm/map/Map.Rotation.js +10 -6
  141. package/dist/esm/map/Map.Rotation.js.map +1 -1
  142. package/dist/esm/map/Map.js +116 -110
  143. package/dist/esm/map/Map.js.map +1 -1
  144. package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
  145. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  146. package/dist/esm/map/handler/DisplaceHandler.js +6 -8
  147. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  148. package/dist/esm/map/handler/DragHandler.js +19 -19
  149. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  150. package/dist/esm/map/handler/KeyboardHandler.js +35 -35
  151. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  152. package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
  153. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  154. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
  155. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  156. package/dist/esm/map/handler/TapHoldHandler.js +12 -5
  157. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  158. package/dist/esm/package.js +1 -1
  159. package/dist/maplair-global-src.js +8009 -7369
  160. package/dist/maplair-global-src.js.map +1 -1
  161. package/dist/maplair-global.js +2 -2
  162. package/dist/maplair-global.js.map +1 -1
  163. package/dist/maplair-src.js +10040 -9381
  164. package/dist/maplair-src.js.map +1 -1
  165. package/dist/maplair.css +148 -98
  166. package/dist/maplair.js +2 -2
  167. package/dist/maplair.js.map +1 -1
  168. package/i18n/cs.json +6 -0
  169. package/i18n/de.json +6 -0
  170. package/i18n/en.json +6 -0
  171. package/i18n/es.json +6 -0
  172. package/i18n/fr.json +6 -0
  173. package/i18n/hu.json +6 -0
  174. package/i18n/it.json +6 -0
  175. package/i18n/rm.json +6 -0
  176. package/i18n/sk.json +6 -0
  177. package/i18n/sl.json +6 -0
  178. package/package.json +9 -11
  179. package/src/control/AttributionControl.js +25 -18
  180. package/src/control/ButtonControl.js +9 -11
  181. package/src/control/ContextMenu.js +3 -5
  182. package/src/control/Control.js +9 -19
  183. package/src/control/FullscreenControl.js +5 -7
  184. package/src/control/LayersControl.js +159 -36
  185. package/src/control/LegendControl.js +7 -9
  186. package/src/control/MiniMapControl.js +9 -11
  187. package/src/control/RotateControl.js +3 -5
  188. package/src/control/ScaleControl.js +7 -9
  189. package/src/control/SearchControl.js +102 -19
  190. package/src/control/SideBySideControl.js +3 -5
  191. package/src/control/TextControl.js +5 -7
  192. package/src/control/TimeControl.js +471 -0
  193. package/src/control/ZoomControl.js +5 -7
  194. package/src/control/index.js +1 -0
  195. package/src/core/Class.js +35 -34
  196. package/src/core/Events.js +22 -3
  197. package/src/core/Handler.js +14 -12
  198. package/src/core/Util.js +19 -1
  199. package/src/core/index.js +0 -1
  200. package/src/dom/DomEvent.DoubleTap.js +18 -10
  201. package/src/dom/DomEvent.PointerEvents.js +3 -26
  202. package/src/dom/DomEvent.js +8 -66
  203. package/src/dom/DomUtil.js +22 -78
  204. package/src/dom/Draggable.js +27 -22
  205. package/src/dom/PosAnimation.js +3 -25
  206. package/src/dom/index.js +0 -1
  207. package/src/geo/LatLng.js +20 -3
  208. package/src/geo/crs/EPSG3395.js +1 -1
  209. package/src/geo/crs/EPSG3857.js +1 -1
  210. package/src/geo/crs/EPSG4326.js +1 -1
  211. package/src/geo/crs/EarthCRS.js +2 -8
  212. package/src/geo/crs/SimpleCRS.js +1 -1
  213. package/src/geo/projection/Projection.LonLat.js +1 -1
  214. package/src/geo/projection/Projection.Mercator.js +1 -1
  215. package/src/geo/projection/Projection.SphericalMercator.js +1 -1
  216. package/src/geometry/LineUtil.js +47 -48
  217. package/src/geometry/PolyUtil.js +14 -43
  218. package/src/layer/BlanketOverlay.js +6 -10
  219. package/src/layer/DivOverlay.js +15 -26
  220. package/src/layer/GeoJSON.js +7 -205
  221. package/src/layer/GeoJSONUtil.js +85 -0
  222. package/src/layer/HeatLayer.js +9 -11
  223. package/src/layer/ImageOverlay.js +19 -30
  224. package/src/layer/Layer.js +8 -10
  225. package/src/layer/LayerGroup.js +71 -0
  226. package/src/layer/Popup.js +28 -43
  227. package/src/layer/SVGOverlay.js +1 -5
  228. package/src/layer/Tooltip.js +15 -19
  229. package/src/layer/VideoOverlay.js +12 -15
  230. package/src/layer/marker/DefaultIcon.js +15 -61
  231. package/src/layer/marker/DivIcon.js +9 -11
  232. package/src/layer/marker/Icon.js +7 -10
  233. package/src/layer/marker/Marker.Drag.js +1 -1
  234. package/src/layer/marker/Marker.Move.js +1 -2
  235. package/src/layer/marker/Marker.js +81 -39
  236. package/src/layer/marker/MarkerClusterGroup.js +370 -0
  237. package/src/layer/marker/SvgIcon.js +7 -9
  238. package/src/layer/marker/index.js +1 -0
  239. package/src/layer/tile/GridLayer.js +103 -133
  240. package/src/layer/tile/TileLayer.js +35 -43
  241. package/src/layer/tile/WMSTileLayer.js +26 -24
  242. package/src/layer/vector/Canvas.js +3 -5
  243. package/src/layer/vector/Circle.js +5 -2
  244. package/src/layer/vector/CircleMarker.js +17 -6
  245. package/src/layer/vector/Path.DashAnimation.js +1 -2
  246. package/src/layer/vector/Path.js +30 -21
  247. package/src/layer/vector/Polygon.js +28 -5
  248. package/src/layer/vector/Polyline.js +25 -6
  249. package/src/layer/vector/Renderer.getRenderer.js +17 -17
  250. package/src/layer/vector/SVG.js +5 -5
  251. package/src/map/Map.Rotation.js +12 -4
  252. package/src/map/Map.js +142 -133
  253. package/src/map/handler/BoxZoomHandler.js +9 -8
  254. package/src/map/handler/DisplaceHandler.js +6 -8
  255. package/src/map/handler/DragHandler.js +25 -28
  256. package/src/map/handler/KeyboardHandler.js +42 -48
  257. package/src/map/handler/PinchZoomHandler.js +16 -5
  258. package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
  259. package/src/map/handler/TapHoldHandler.js +15 -4
  260. package/src/map/index.js +1 -1
  261. package/src/maplair.css +148 -98
  262. package/dist/esm/core/Browser.js +0 -100
  263. package/dist/esm/core/Browser.js.map +0 -1
  264. package/dist/images/layers.svg +0 -1
  265. package/dist/images/marker-icon.svg +0 -1
  266. package/dist/images/marker-shadow.svg +0 -1
  267. package/src/core/Browser.js +0 -110
  268. package/src/images/layers.svg +0 -1
  269. package/src/images/marker-icon.svg +0 -1
  270. package/src/images/marker-shadow.svg +0 -1
@@ -0,0 +1,408 @@
1
+ import { disableClickPropagation, disableScrollPropagation, on } from "../dom/DomEvent.js";
2
+ import { create } from "../dom/DomUtil.js";
3
+ import { Control } from "./Control.js";
4
+ import { I18n } from "../core/I18n.js";
5
+ import { ButtonControl } from "./ButtonControl.js";
6
+ //#region src/control/TimeControl.js
7
+ /** @import {ControlOptions} from './Control.js' */
8
+ /** @import {MaplairMap} from '../map/Map.js' */
9
+ /** @import {Layer} from '../layer/Layer.js' */
10
+ /** @import {MaplairEvent} from '../core/Events.js' */
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
+ const playIcon = icon("M4 2v12l10-6z");
14
+ const pauseIcon = icon("M4 3h3v10H4zm5 0h3v10H9z");
15
+ const nextIcon = icon("M11 3h2v10h-2zM3 3v10l7-5z");
16
+ const durationRe = /^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/;
17
+ function parseDuration(duration) {
18
+ const match = durationRe.exec(duration);
19
+ if (!match || duration === "P" || duration.endsWith("T")) throw new Error(`Invalid or unsupported ISO 8601 duration "${duration}".`);
20
+ const [years, months, weeks, days, hours, minutes, seconds] = match.slice(1).map((n) => Number(n ?? 0));
21
+ return {
22
+ years,
23
+ months,
24
+ ms: ((((weeks * 7 + days) * 24 + hours) * 60 + minutes) * 60 + seconds) * 1e3
25
+ };
26
+ }
27
+ function addDuration(time, duration, n) {
28
+ const date = new Date(time);
29
+ date.setUTCFullYear(date.getUTCFullYear() + n * duration.years, date.getUTCMonth() + n * duration.months);
30
+ return new Date(+date + n * duration.ms);
31
+ }
32
+ function parseDate(date) {
33
+ const time = Date.parse(date);
34
+ if (Number.isNaN(time)) throw new Error(`Invalid date "${date}".`);
35
+ return new Date(time);
36
+ }
37
+ function intervalTimes(interval, period) {
38
+ const parts = interval.split("/");
39
+ if (parts.length === 3) period = parts.pop();
40
+ if (parts.length !== 2) throw new Error(`Invalid ISO 8601 interval "${interval}".`);
41
+ const [first, second] = parts, step = parseDuration(period);
42
+ let start, end;
43
+ if (first.startsWith("P")) {
44
+ end = parseDate(second);
45
+ start = addDuration(end, parseDuration(first), -1);
46
+ } else {
47
+ start = parseDate(first);
48
+ end = second.startsWith("P") ? addDuration(start, parseDuration(second), 1) : parseDate(second);
49
+ }
50
+ if (!(addDuration(start, step, 1) > start)) throw new Error(`The period "${period}" has to be positive.`);
51
+ const times = [];
52
+ for (let i = 0, time = start; time <= end; time = addDuration(start, step, ++i)) times.push(time);
53
+ return times;
54
+ }
55
+ /**
56
+ * Options of `TimeControl`.
57
+ * @typedef {object} TimeControlOptions
58
+ * @property {string} [position='bottomleft'] The position of the control (one of the map
59
+ * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or
60
+ * `'bottomright'`.
61
+ * @property {(Date|number|string)[]} [times] The times to step through in ascending
62
+ * order: dates, timestamps or date strings (parsed with `Date.parse()`).
63
+ * @property {string} [interval] Instead of `times`, an ISO 8601 time interval whose times
64
+ * every [`period`](#timecontrol-period) from the start up to the end are stepped
65
+ * through: `start/end` (e.g. `'2026-10-17T00:00Z/2026-10-18T00:00Z'`), `start/duration`
66
+ * (e.g. `'2026-10-17T00:00Z/P1D'`) or `duration/end` (e.g. `'PT24H/2026-10-18T00:00Z'`).
67
+ * A third part is the period, as in the time dimension of WMS capabilities (e.g.
68
+ * `'2026-10-17T00:00Z/2026-10-18T00:00Z/PT5M'`). Start and end are parsed with
69
+ * `Date.parse()`, e.g. `2026-10-17`, `2026-10-17T12:00Z` or
70
+ * `2026-10-17T12:00:00.000+02:00` (without a time zone, times are local times).
71
+ * @property {string} [period='P1D'] The ISO 8601 duration between the times of the
72
+ * `interval`: integer numbers of years, months, weeks, days, hours, minutes and seconds,
73
+ * e.g. `'PT1H'`, `'PT5M'`, `'P1DT12H'` or `'P1M'` (years and months are added in UTC).
74
+ * @property {Date|number|string} [time] The initial time (the nearest of the times), by
75
+ * default the current time.
76
+ * @property {(Layer & TimeLayer)[]} [layers=[]] The layers showing the current time, see
77
+ * `addLayer()`.
78
+ * @property {number} [transitionTime=1000] The minimum time in milliseconds a time is
79
+ * shown while playing. The next time is shown only after the layers have loaded, too.
80
+ * @property {boolean} [loop=false] Whether playing starts over after the last time
81
+ * instead of stopping, and the buttons step from the last time to the first one and
82
+ * back.
83
+ * @property {(date: Date) => string} [formatTime] Returns the text of the label for a
84
+ * time, by default the date and time by `Intl.DateTimeFormat` in the [locale](#i18n)
85
+ * (or the browser's language) and the browser's time zone.
86
+ * @extends ControlOptions
87
+ */
88
+ /**
89
+ * A layer showing a given time, see `TimeControl`.
90
+ * @typedef {object} TimeLayer
91
+ * @property {(date: Date) => any} [setTime] Shows the given time.
92
+ */
93
+ /**
94
+ * The event object of `timechange`.
95
+ * @typedef {object} TimeChangeEvent
96
+ * @property {Date} time The current time.
97
+ * @property {number} index The index of the current time in the times of the control.
98
+ * @extends MaplairEvent
99
+ */
100
+ /**
101
+ * A control to step through or play the times of time-dependent layers, e.g. an
102
+ * animated weather radar from a WMS with a `TIME` dimension. It has buttons for the
103
+ * previous and next time and to play or pause, a slider (usable with the arrow, Home
104
+ * and End keys) and a label with the current time.
105
+ *
106
+ * Each of the `layers` shows the current time: by its method `setTime(date)` if it has
107
+ * one, otherwise by the parameter `time` set to the time in ISO 8601 format
108
+ * (`date.toISOString()`): the WMS parameter of a `WMSTileLayer` (with `setParams()`) or
109
+ * the variable of the URL template of a `TileLayer` (e.g.
110
+ * `'https://…/{time}/{z}/{x}/{y}.png'`, with `setUrl()`). The tiles of the previous
111
+ * time stay visible until the new ones have loaded, and playing waits for them (the
112
+ * `load` event), so that no time is skipped with slow servers.
113
+ *
114
+ * Replaces the [Leaflet.TimeDimension](https://github.com/socib/Leaflet.TimeDimension)
115
+ * plugin for the common use cases.
116
+ *
117
+ * @example
118
+ * ```js
119
+ * const radar = new WMSTileLayer('https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r-t.cgi', {
120
+ * layers: 'nexrad-n0r-wmst',
121
+ * format: 'image/png',
122
+ * transparent: true
123
+ * }).addTo(map);
124
+ *
125
+ * new TimeControl({
126
+ * interval: '2013-05-20T18:00Z/2013-05-20T22:00Z',
127
+ * period: 'PT5M',
128
+ * layers: [radar],
129
+ * loop: true
130
+ * }).addTo(map);
131
+ *
132
+ * map.on('timechange', e => console.log(e.time));
133
+ * ```
134
+ *
135
+ * @fires MaplairMap#timechange {TimeChangeEvent} Fired when the current time of a
136
+ * `TimeControl` changes.
137
+ */
138
+ var TimeControl = class TimeControl extends Control {
139
+ static defaultOptions = {
140
+ position: "bottomleft",
141
+ times: void 0,
142
+ interval: void 0,
143
+ period: "P1D",
144
+ time: void 0,
145
+ layers: [],
146
+ transitionTime: 1e3,
147
+ loop: false,
148
+ formatTime: void 0
149
+ };
150
+ /**
151
+ * Creates a time control.
152
+ * @param {...TimeControlOptions} args The options.
153
+ */
154
+ constructor(...args) {
155
+ super(...args);
156
+ const { times, interval, period, time, layers } = this.options;
157
+ this._layers = [];
158
+ this._playing = false;
159
+ this._times = [];
160
+ this._index = -1;
161
+ this.setTimes(interval ? intervalTimes(interval, period) : times ?? [], time);
162
+ for (const layer of layers) this.addLayer(layer);
163
+ this.callInitHooks(TimeControl);
164
+ }
165
+ /**
166
+ * @internal
167
+ * @param {MaplairMap} map
168
+ * @returns {HTMLElement}
169
+ */
170
+ onAdd(map) {
171
+ const container = create("div", "maplair-bar maplair-control-time");
172
+ disableClickPropagation(container);
173
+ disableScrollPropagation(container);
174
+ this._previousButton = new ButtonControl({
175
+ className: "maplair-control-time-previous",
176
+ content: previousIcon,
177
+ title: I18n.translate("Step back"),
178
+ onClick: () => this.previous()
179
+ });
180
+ this._playButton = new ButtonControl({
181
+ className: "maplair-control-time-play",
182
+ states: [{
183
+ name: "play",
184
+ content: playIcon,
185
+ title: I18n.translate("Play"),
186
+ onClick: () => this.play()
187
+ }, {
188
+ name: "pause",
189
+ content: pauseIcon,
190
+ title: I18n.translate("Pause"),
191
+ onClick: () => this.pause()
192
+ }]
193
+ });
194
+ this._nextButton = new ButtonControl({
195
+ className: "maplair-control-time-next",
196
+ content: nextIcon,
197
+ title: I18n.translate("Step forward"),
198
+ onClick: () => this.next()
199
+ });
200
+ for (const button of [
201
+ this._previousButton,
202
+ this._playButton,
203
+ this._nextButton
204
+ ]) {
205
+ button._map = map;
206
+ button._createButton(container);
207
+ }
208
+ const slider = this._slider = create("input", "maplair-control-time-slider", container);
209
+ slider.type = "range";
210
+ slider.min = "0";
211
+ slider.step = "1";
212
+ slider.setAttribute("aria-label", I18n.translate("Time"));
213
+ on(slider, "input", this._onSliderInput, this);
214
+ this._label = create("span", "maplair-control-time-label", container);
215
+ this._formatter = new Intl.DateTimeFormat(I18n.getLocale() ?? void 0, {
216
+ dateStyle: "short",
217
+ timeStyle: "short"
218
+ });
219
+ this._updateControl();
220
+ return container;
221
+ }
222
+ /**
223
+ * @internal
224
+ */
225
+ onRemove() {
226
+ this.pause();
227
+ this._slider = null;
228
+ }
229
+ _onSliderInput() {
230
+ this.pause();
231
+ this._setIndex(Number(this._slider.value));
232
+ }
233
+ _updateControl() {
234
+ if (!this._slider) return;
235
+ const index = this._index, last = this._times.length - 1, time = this.getTime(), text = time ? (this.options.formatTime ?? this._formatter.format)(time) : "", loop = this.options.loop;
236
+ this._slider.max = String(Math.max(last, 0));
237
+ this._slider.value = String(Math.max(index, 0));
238
+ this._slider.disabled = last < 1;
239
+ this._slider.setAttribute("aria-valuetext", text);
240
+ this._label.textContent = text;
241
+ this._playButton.setState(this._playing ? "pause" : "play");
242
+ this._setDisabled(this._playButton, last < 1);
243
+ this._setDisabled(this._previousButton, last < 1 || index === 0 && !loop);
244
+ this._setDisabled(this._nextButton, last < 1 || index === last && !loop);
245
+ }
246
+ _setDisabled(button, disabled) {
247
+ if (disabled) button.disable();
248
+ else button.enable();
249
+ }
250
+ /**
251
+ * Sets the times to step through, see the [`times` option](#timecontrol-times), and
252
+ * shows the nearest of them to `time`, by default to the current time of the control.
253
+ * @param {(Date|number|string)[]} times
254
+ * @param {Date|number|string} [time]
255
+ * @returns {this}
256
+ */
257
+ setTimes(times, time = this.getTime()) {
258
+ this._times = times.map((t) => new Date(t));
259
+ this._index = -1;
260
+ if (this._times.length < 2) this.pause();
261
+ return this.setTime(time ?? Date.now());
262
+ }
263
+ /**
264
+ * Returns the times to step through.
265
+ * @returns {Date[]}
266
+ */
267
+ getTimes() {
268
+ return this._times;
269
+ }
270
+ /**
271
+ * Shows the nearest of the times to the given time.
272
+ * @param {Date|number|string} time
273
+ * @returns {this}
274
+ */
275
+ setTime(time) {
276
+ const ms = +new Date(time);
277
+ let index = this._times.length ? 0 : -1;
278
+ this._times.forEach((t, i) => {
279
+ if (Math.abs(+t - ms) < Math.abs(+this._times[index] - ms)) index = i;
280
+ });
281
+ return this._setIndex(index);
282
+ }
283
+ /**
284
+ * Returns the current time.
285
+ * @returns {Date|undefined}
286
+ */
287
+ getTime() {
288
+ return this._times[this._index];
289
+ }
290
+ _setIndex(index) {
291
+ if (index !== this._index) {
292
+ this._index = index;
293
+ for (const layer of this._layers) this._updateLayer(layer);
294
+ if (index >= 0) this._map?.fire("timechange", {
295
+ time: this.getTime(),
296
+ index
297
+ });
298
+ if (this._playing) this._schedule();
299
+ }
300
+ this._updateControl();
301
+ return this;
302
+ }
303
+ /**
304
+ * Shows the next time (or the first one after the last one if looping).
305
+ * @returns {this}
306
+ */
307
+ next() {
308
+ if (this._index < this._times.length - 1) this._setIndex(this._index + 1);
309
+ else if (this.options.loop && this._times.length > 1) this._setIndex(0);
310
+ return this;
311
+ }
312
+ /**
313
+ * Shows the previous time (or the last one before the first one if looping).
314
+ * @returns {this}
315
+ */
316
+ previous() {
317
+ if (this._index > 0) this._setIndex(this._index - 1);
318
+ else if (this.options.loop && this._times.length > 1) this._setIndex(this._times.length - 1);
319
+ return this;
320
+ }
321
+ /**
322
+ * Plays the times one after the other, each for at least the
323
+ * [`transitionTime`](#timecontrol-transitiontime) and until the layers have loaded.
324
+ * Starts at the first time if the last one is shown. Stops at the last time unless
325
+ * [looping](#timecontrol-loop).
326
+ * @returns {this}
327
+ */
328
+ play() {
329
+ if (this._playing || this._times.length < 2) return this;
330
+ this._playing = true;
331
+ if (this._index === this._times.length - 1) this._setIndex(0);
332
+ else {
333
+ this._schedule();
334
+ this._updateControl();
335
+ }
336
+ return this;
337
+ }
338
+ /**
339
+ * Stops playing.
340
+ * @returns {this}
341
+ */
342
+ pause() {
343
+ clearTimeout(this._timeout);
344
+ this._timeout = null;
345
+ if (this._playing) {
346
+ this._playing = false;
347
+ this._updateControl();
348
+ }
349
+ return this;
350
+ }
351
+ /**
352
+ * Returns `true` while playing.
353
+ * @returns {boolean}
354
+ */
355
+ isPlaying() {
356
+ return this._playing;
357
+ }
358
+ _schedule() {
359
+ clearTimeout(this._timeout);
360
+ this._timeout = setTimeout(() => {
361
+ this._timeout = null;
362
+ this._advance();
363
+ }, this.options.transitionTime);
364
+ }
365
+ _advance() {
366
+ if (!this._playing || this._timeout || this._layers.some((layer) => layer._map && layer.isLoading?.())) return;
367
+ if (this._index < this._times.length - 1 || this.options.loop) this.next();
368
+ else this.pause();
369
+ }
370
+ _updateLayer(layer) {
371
+ const time = this.getTime();
372
+ if (!time) return;
373
+ if (typeof layer.setTime === "function") layer.setTime(time);
374
+ else if (typeof layer.setParams === "function") layer.setParams({ time: time.toISOString() });
375
+ else if (typeof layer.setUrl === "function") {
376
+ layer.options.time = time.toISOString();
377
+ layer.setUrl(layer._url, false);
378
+ }
379
+ }
380
+ /**
381
+ * Adds a layer showing the current time, see the [`layers` option](#timecontrol-layers).
382
+ * The layer still has to be added to the map.
383
+ * @param {Layer & TimeLayer} layer
384
+ * @returns {this}
385
+ */
386
+ addLayer(layer) {
387
+ if (this._layers.includes(layer)) return this;
388
+ this._layers.push(layer);
389
+ layer.on("load remove", this._advance, this);
390
+ this._updateLayer(layer);
391
+ return this;
392
+ }
393
+ /**
394
+ * Removes a layer from the layers showing the current time.
395
+ * @param {Layer} layer
396
+ * @returns {this}
397
+ */
398
+ removeLayer(layer) {
399
+ this._layers = this._layers.filter((l) => l !== layer);
400
+ layer.off("load remove", this._advance, this);
401
+ this._advance();
402
+ return this;
403
+ }
404
+ };
405
+ //#endregion
406
+ export { TimeControl };
407
+
408
+ //# sourceMappingURL=TimeControl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeControl.js","names":["DomUtil.create"],"sources":["../../../src/control/TimeControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport {ButtonControl} from './ButtonControl.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n\nconst icon = path => `<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"currentColor\"><path d=\"${path}\"/></svg>`;\nconst previousIcon = icon('M3 3h2v10H3zm10 0v10L6 8z'),\nplayIcon = icon('M4 2v12l10-6z'),\npauseIcon = icon('M4 3h3v10H4zm5 0h3v10H9z'),\nnextIcon = icon('M11 3h2v10h-2zM3 3v10l7-5z');\n\nconst durationRe = /^P(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?$/;\n\n// Parses an ISO 8601 duration like `'PT5M'` or `'P1Y2M'` into calendar years and months\n// and the milliseconds of the units with a fixed length\nfunction parseDuration(duration) {\n\tconst match = durationRe.exec(duration);\n\tif (!match || duration === 'P' || duration.endsWith('T')) {\n\t\tthrow new Error(`Invalid or unsupported ISO 8601 duration \"${duration}\".`);\n\t}\n\tconst [years, months, weeks, days, hours, minutes, seconds] = match.slice(1).map(n => Number(n ?? 0));\n\treturn {years, months, ms: ((((weeks * 7 + days) * 24 + hours) * 60 + minutes) * 60 + seconds) * 1000};\n}\n\n// Returns the time `n` times the duration after the given time, adding years and months in UTC\nfunction addDuration(time, duration, n) {\n\tconst date = new Date(time);\n\tdate.setUTCFullYear(date.getUTCFullYear() + n * duration.years, date.getUTCMonth() + n * duration.months);\n\treturn new Date(+date + n * duration.ms);\n}\n\nfunction parseDate(date) {\n\tconst time = Date.parse(date);\n\tif (Number.isNaN(time)) {\n\t\tthrow new Error(`Invalid date \"${date}\".`);\n\t}\n\treturn new Date(time);\n}\n\n// Returns the times of an ISO 8601 interval (start/end, start/duration or duration/end,\n// optionally with the period as third part), every period from the start\nfunction intervalTimes(interval, period) {\n\tconst parts = interval.split('/');\n\tif (parts.length === 3) {\n\t\tperiod = parts.pop();\n\t}\n\tif (parts.length !== 2) {\n\t\tthrow new Error(`Invalid ISO 8601 interval \"${interval}\".`);\n\t}\n\tconst [first, second] = parts,\n\tstep = parseDuration(period);\n\tlet start, end;\n\tif (first.startsWith('P')) {\n\t\tend = parseDate(second);\n\t\tstart = addDuration(end, parseDuration(first), -1);\n\t} else {\n\t\tstart = parseDate(first);\n\t\tend = second.startsWith('P') ? addDuration(start, parseDuration(second), 1) : parseDate(second);\n\t}\n\tif (!(addDuration(start, step, 1) > start)) {\n\t\tthrow new Error(`The period \"${period}\" has to be positive.`);\n\t}\n\tconst times = [];\n\tfor (let i = 0, time = start; time <= end; time = addDuration(start, step, ++i)) {\n\t\ttimes.push(time);\n\t}\n\treturn times;\n}\n\n/**\n * Options of `TimeControl`.\n * @typedef {object} TimeControlOptions\n * @property {string} [position='bottomleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {(Date|number|string)[]} [times] The times to step through in ascending\n * order: dates, timestamps or date strings (parsed with `Date.parse()`).\n * @property {string} [interval] Instead of `times`, an ISO 8601 time interval whose times\n * every [`period`](#timecontrol-period) from the start up to the end are stepped\n * through: `start/end` (e.g. `'2026-10-17T00:00Z/2026-10-18T00:00Z'`), `start/duration`\n * (e.g. `'2026-10-17T00:00Z/P1D'`) or `duration/end` (e.g. `'PT24H/2026-10-18T00:00Z'`).\n * A third part is the period, as in the time dimension of WMS capabilities (e.g.\n * `'2026-10-17T00:00Z/2026-10-18T00:00Z/PT5M'`). Start and end are parsed with\n * `Date.parse()`, e.g. `2026-10-17`, `2026-10-17T12:00Z` or\n * `2026-10-17T12:00:00.000+02:00` (without a time zone, times are local times).\n * @property {string} [period='P1D'] The ISO 8601 duration between the times of the\n * `interval`: integer numbers of years, months, weeks, days, hours, minutes and seconds,\n * e.g. `'PT1H'`, `'PT5M'`, `'P1DT12H'` or `'P1M'` (years and months are added in UTC).\n * @property {Date|number|string} [time] The initial time (the nearest of the times), by\n * default the current time.\n * @property {(Layer & TimeLayer)[]} [layers=[]] The layers showing the current time, see\n * `addLayer()`.\n * @property {number} [transitionTime=1000] The minimum time in milliseconds a time is\n * shown while playing. The next time is shown only after the layers have loaded, too.\n * @property {boolean} [loop=false] Whether playing starts over after the last time\n * instead of stopping, and the buttons step from the last time to the first one and\n * back.\n * @property {(date: Date) => string} [formatTime] Returns the text of the label for a\n * time, by default the date and time by `Intl.DateTimeFormat` in the [locale](#i18n)\n * (or the browser's language) and the browser's time zone.\n * @extends ControlOptions\n */\n\n/**\n * A layer showing a given time, see `TimeControl`.\n * @typedef {object} TimeLayer\n * @property {(date: Date) => any} [setTime] Shows the given time.\n */\n\n/**\n * The event object of `timechange`.\n * @typedef {object} TimeChangeEvent\n * @property {Date} time The current time.\n * @property {number} index The index of the current time in the times of the control.\n * @extends MaplairEvent\n */\n\n/**\n * A control to step through or play the times of time-dependent layers, e.g. an\n * animated weather radar from a WMS with a `TIME` dimension. It has buttons for the\n * previous and next time and to play or pause, a slider (usable with the arrow, Home\n * and End keys) and a label with the current time.\n *\n * Each of the `layers` shows the current time: by its method `setTime(date)` if it has\n * one, otherwise by the parameter `time` set to the time in ISO 8601 format\n * (`date.toISOString()`): the WMS parameter of a `WMSTileLayer` (with `setParams()`) or\n * the variable of the URL template of a `TileLayer` (e.g.\n * `'https://…/{time}/{z}/{x}/{y}.png'`, with `setUrl()`). The tiles of the previous\n * time stay visible until the new ones have loaded, and playing waits for them (the\n * `load` event), so that no time is skipped with slow servers.\n *\n * Replaces the [Leaflet.TimeDimension](https://github.com/socib/Leaflet.TimeDimension)\n * plugin for the common use cases.\n *\n * @example\n * ```js\n * const radar = new WMSTileLayer('https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r-t.cgi', {\n * \tlayers: 'nexrad-n0r-wmst',\n * \tformat: 'image/png',\n * \ttransparent: true\n * }).addTo(map);\n *\n * new TimeControl({\n * \tinterval: '2013-05-20T18:00Z/2013-05-20T22:00Z',\n * \tperiod: 'PT5M',\n * \tlayers: [radar],\n * \tloop: true\n * }).addTo(map);\n *\n * map.on('timechange', e => console.log(e.time));\n * ```\n *\n * @fires MaplairMap#timechange {TimeChangeEvent} Fired when the current time of a\n * `TimeControl` changes.\n */\nexport class TimeControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'bottomleft',\n\t\ttimes: undefined,\n\t\tinterval: undefined,\n\t\tperiod: 'P1D',\n\t\ttime: undefined,\n\t\tlayers: [],\n\t\ttransitionTime: 1000,\n\t\tloop: false,\n\t\tformatTime: undefined\n\t};\n\n\t/**\n\t * Creates a time control.\n\t * @param {...TimeControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tconst {times, interval, period, time, layers} = this.options;\n\t\tthis._layers = [];\n\t\tthis._playing = false;\n\t\tthis._times = [];\n\t\tthis._index = -1;\n\t\tthis.setTimes(interval ? intervalTimes(interval, period) : times ?? [], time);\n\t\tfor (const layer of layers) {\n\t\t\tthis.addLayer(layer);\n\t\t}\n\t\tthis.callInitHooks(TimeControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst container = DomUtil.create('div', 'maplair-bar maplair-control-time');\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\n\t\tthis._previousButton = new ButtonControl({\n\t\t\tclassName: 'maplair-control-time-previous',\n\t\t\tcontent: previousIcon,\n\t\t\ttitle: I18n.translate('Step back'),\n\t\t\tonClick: () => this.previous()\n\t\t});\n\t\tthis._playButton = new ButtonControl({\n\t\t\tclassName: 'maplair-control-time-play',\n\t\t\tstates: [\n\t\t\t\t{name: 'play', content: playIcon, title: I18n.translate('Play'), onClick: () => this.play()},\n\t\t\t\t{name: 'pause', content: pauseIcon, title: I18n.translate('Pause'), onClick: () => this.pause()}\n\t\t\t]\n\t\t});\n\t\tthis._nextButton = new ButtonControl({\n\t\t\tclassName: 'maplair-control-time-next',\n\t\t\tcontent: nextIcon,\n\t\t\ttitle: I18n.translate('Step forward'),\n\t\t\tonClick: () => this.next()\n\t\t});\n\t\tfor (const button of [this._previousButton, this._playButton, this._nextButton]) {\n\t\t\tbutton._map = map;\n\t\t\tbutton._createButton(container);\n\t\t}\n\n\t\tconst slider = this._slider = DomUtil.create('input', 'maplair-control-time-slider', container);\n\t\tslider.type = 'range';\n\t\tslider.min = '0';\n\t\tslider.step = '1';\n\t\tslider.setAttribute('aria-label', I18n.translate('Time'));\n\t\tDomEvent.on(slider, 'input', this._onSliderInput, this);\n\n\t\tthis._label = DomUtil.create('span', 'maplair-control-time-label', container);\n\n\t\tthis._formatter = new Intl.DateTimeFormat(I18n.getLocale() ?? undefined, {dateStyle: 'short', timeStyle: 'short'});\n\t\tthis._updateControl();\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t */\n\tonRemove() {\n\t\tthis.pause();\n\t\tthis._slider = null;\n\t}\n\n\t_onSliderInput() {\n\t\tthis.pause();\n\t\tthis._setIndex(Number(this._slider.value));\n\t}\n\n\t_updateControl() {\n\t\tif (!this._slider) { return; }\n\t\tconst index = this._index,\n\t\tlast = this._times.length - 1,\n\t\ttime = this.getTime(),\n\t\ttext = time ? (this.options.formatTime ?? this._formatter.format)(time) : '',\n\t\tloop = this.options.loop;\n\n\t\tthis._slider.max = String(Math.max(last, 0));\n\t\tthis._slider.value = String(Math.max(index, 0));\n\t\tthis._slider.disabled = last < 1;\n\t\tthis._slider.setAttribute('aria-valuetext', text);\n\t\tthis._label.textContent = text;\n\n\t\tthis._playButton.setState(this._playing ? 'pause' : 'play');\n\t\tthis._setDisabled(this._playButton, last < 1);\n\t\tthis._setDisabled(this._previousButton, last < 1 || (index === 0 && !loop));\n\t\tthis._setDisabled(this._nextButton, last < 1 || (index === last && !loop));\n\t}\n\n\t_setDisabled(button, disabled) {\n\t\tif (disabled) {\n\t\t\tbutton.disable();\n\t\t} else {\n\t\t\tbutton.enable();\n\t\t}\n\t}\n\n\t/**\n\t * Sets the times to step through, see the [`times` option](#timecontrol-times), and\n\t * shows the nearest of them to `time`, by default to the current time of the control.\n\t * @param {(Date|number|string)[]} times\n\t * @param {Date|number|string} [time]\n\t * @returns {this}\n\t */\n\tsetTimes(times, time = this.getTime()) {\n\t\tthis._times = times.map(t => new Date(t));\n\t\tthis._index = -1;\n\t\tif (this._times.length < 2) {\n\t\t\tthis.pause();\n\t\t}\n\t\treturn this.setTime(time ?? Date.now());\n\t}\n\n\t/**\n\t * Returns the times to step through.\n\t * @returns {Date[]}\n\t */\n\tgetTimes() {\n\t\treturn this._times;\n\t}\n\n\t/**\n\t * Shows the nearest of the times to the given time.\n\t * @param {Date|number|string} time\n\t * @returns {this}\n\t */\n\tsetTime(time) {\n\t\tconst ms = +new Date(time);\n\t\tlet index = this._times.length ? 0 : -1;\n\t\tthis._times.forEach((t, i) => {\n\t\t\tif (Math.abs(+t - ms) < Math.abs(+this._times[index] - ms)) {\n\t\t\t\tindex = i;\n\t\t\t}\n\t\t});\n\t\treturn this._setIndex(index);\n\t}\n\n\t/**\n\t * Returns the current time.\n\t * @returns {Date|undefined}\n\t */\n\tgetTime() {\n\t\treturn this._times[this._index];\n\t}\n\n\t_setIndex(index) {\n\t\tif (index !== this._index) {\n\t\t\tthis._index = index;\n\t\t\tfor (const layer of this._layers) {\n\t\t\t\tthis._updateLayer(layer);\n\t\t\t}\n\t\t\tif (index >= 0) {\n\t\t\t\tthis._map?.fire('timechange', {time: this.getTime(), index});\n\t\t\t}\n\t\t\tif (this._playing) {\n\t\t\t\tthis._schedule();\n\t\t\t}\n\t\t}\n\t\tthis._updateControl();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Shows the next time (or the first one after the last one if looping).\n\t * @returns {this}\n\t */\n\tnext() {\n\t\tif (this._index < this._times.length - 1) {\n\t\t\tthis._setIndex(this._index + 1);\n\t\t} else if (this.options.loop && this._times.length > 1) {\n\t\t\tthis._setIndex(0);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Shows the previous time (or the last one before the first one if looping).\n\t * @returns {this}\n\t */\n\tprevious() {\n\t\tif (this._index > 0) {\n\t\t\tthis._setIndex(this._index - 1);\n\t\t} else if (this.options.loop && this._times.length > 1) {\n\t\t\tthis._setIndex(this._times.length - 1);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Plays the times one after the other, each for at least the\n\t * [`transitionTime`](#timecontrol-transitiontime) and until the layers have loaded.\n\t * Starts at the first time if the last one is shown. Stops at the last time unless\n\t * [looping](#timecontrol-loop).\n\t * @returns {this}\n\t */\n\tplay() {\n\t\tif (this._playing || this._times.length < 2) { return this; }\n\t\tthis._playing = true;\n\t\tif (this._index === this._times.length - 1) {\n\t\t\t// also schedules the next time\n\t\t\tthis._setIndex(0);\n\t\t} else {\n\t\t\tthis._schedule();\n\t\t\tthis._updateControl();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Stops playing.\n\t * @returns {this}\n\t */\n\tpause() {\n\t\tclearTimeout(this._timeout);\n\t\tthis._timeout = null;\n\t\tif (this._playing) {\n\t\t\tthis._playing = false;\n\t\t\tthis._updateControl();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` while playing.\n\t * @returns {boolean}\n\t */\n\tisPlaying() {\n\t\treturn this._playing;\n\t}\n\n\t// Shows the next time after the transition time, once the layers have loaded\n\t_schedule() {\n\t\tclearTimeout(this._timeout);\n\t\tthis._timeout = setTimeout(() => {\n\t\t\tthis._timeout = null;\n\t\t\tthis._advance();\n\t\t}, this.options.transitionTime);\n\t}\n\n\t_advance() {\n\t\tif (!this._playing || this._timeout || this._layers.some(layer => layer._map && layer.isLoading?.())) { return; }\n\t\tif (this._index < this._times.length - 1 || this.options.loop) {\n\t\t\tthis.next();\n\t\t} else {\n\t\t\tthis.pause();\n\t\t}\n\t}\n\n\t_updateLayer(layer) {\n\t\tconst time = this.getTime();\n\t\tif (!time) { return; }\n\t\tif (typeof layer.setTime === 'function') {\n\t\t\tlayer.setTime(time);\n\t\t} else if (typeof layer.setParams === 'function') {\n\t\t\tlayer.setParams({time: time.toISOString()});\n\t\t} else if (typeof layer.setUrl === 'function') {\n\t\t\tlayer.options.time = time.toISOString();\n\t\t\tlayer.setUrl(layer._url, false);\n\t\t}\n\t}\n\n\t/**\n\t * Adds a layer showing the current time, see the [`layers` option](#timecontrol-layers).\n\t * The layer still has to be added to the map.\n\t * @param {Layer & TimeLayer} layer\n\t * @returns {this}\n\t */\n\taddLayer(layer) {\n\t\tif (this._layers.includes(layer)) { return this; }\n\t\tthis._layers.push(layer);\n\t\tlayer.on('load remove', this._advance, this);\n\t\tthis._updateLayer(layer);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes a layer from the layers showing the current time.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tthis._layers = this._layers.filter(l => l !== layer);\n\t\tlayer.off('load remove', this._advance, this);\n\t\tthis._advance();\n\t\treturn this;\n\t}\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAM,QAAO,SAAQ,mGAAmG,KAAK;AAC7H,MAAM,eAAe,KAAK,2BAA2B;AACrD,MAAA,WAAW,KAAK,eAAe;AAC/B,MAAA,YAAY,KAAK,0BAA0B;AAC3C,MAAA,WAAW,KAAK,4BAA4B;AAE5C,MAAM,aAAa;AAInB,SAAS,cAAc,UAAU;CAChC,MAAM,QAAQ,WAAW,KAAK,QAAQ;CACtC,IAAI,CAAC,SAAS,aAAa,OAAO,SAAS,SAAS,GAAG,GACtD,MAAM,IAAI,MAAM,6CAA6C,SAAS,GAAG;CAE1E,MAAM,CAAC,OAAO,QAAQ,OAAO,MAAM,OAAO,SAAS,WAAW,MAAM,MAAM,CAAC,CAAC,CAAC,KAAI,MAAK,OAAO,KAAK,CAAC,CAAC;CACpG,OAAO;EAAC;EAAO;EAAQ,QAAQ,QAAQ,IAAI,QAAQ,KAAK,SAAS,KAAK,WAAW,KAAK,WAAW;CAAI;AACtG;AAGA,SAAS,YAAY,MAAM,UAAU,GAAG;CACvC,MAAM,OAAO,IAAI,KAAK,IAAI;CAC1B,KAAK,eAAe,KAAK,eAAe,IAAI,IAAI,SAAS,OAAO,KAAK,YAAY,IAAI,IAAI,SAAS,MAAM;CACxG,OAAO,IAAI,KAAK,CAAC,OAAO,IAAI,SAAS,EAAE;AACxC;AAEA,SAAS,UAAU,MAAM;CACxB,MAAM,OAAO,KAAK,MAAM,IAAI;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AO,MAAK,MAAM,KAAK;EACnD,MAAM,IAAI,eAAe,KAAK,UAAU,IAAI;EAC5C,KAAK,SAAS;EACd,OAAO;CACR;AACD"}
@@ -36,13 +36,11 @@ import { I18n } from "../core/I18n.js";
36
36
  * default unless you set its [`zoomControl` option](#map-zoomcontrol) to `false`.
37
37
  */
38
38
  var ZoomControl = class ZoomControl extends Control {
39
- static {
40
- this.setDefaultOptions({
41
- position: "topleft",
42
- zoomInText: "<span aria-hidden=\"true\">+</span>",
43
- zoomOutText: "<span aria-hidden=\"true\">&#x2212;</span>"
44
- });
45
- }
39
+ static defaultOptions = {
40
+ position: "topleft",
41
+ zoomInText: "<span aria-hidden=\"true\">+</span>",
42
+ zoomOutText: "<span aria-hidden=\"true\">&#x2212;</span>"
43
+ };
46
44
  /**
47
45
  * Creates a zoom control.
48
46
  * @param {...ZoomControlOptions} args The options.
@@ -1 +1 @@
1
- {"version":3,"file":"ZoomControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/ZoomControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Options of `ZoomControl`.\n * @typedef {object} ZoomControlOptions\n * @property {string} [position='topleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {string} [zoomInText='<span aria-hidden=\"true\">+</span>'] The text set on\n * the 'zoom in' button.\n * @property {string} [zoomOutText='<span aria-hidden=\"true\">&#x2212;</span>'] The text\n * set on the 'zoom out' button.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `ZoomControl`.\n * @typedef {object} ZoomControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [zoomControl=true] Whether a [zoom control](#control-zoom) is\n * added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `ZoomControl`.\n * @typedef {object} ZoomControlMapProperties\n * @lends MaplairMap\n * @property {ZoomControl} zoomControl The default zoom control (only available if the\n * [`zoomControl` option](#map-zoomcontrol) was `true` when creating the map).\n */\n\n/**\n * A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by\n * default unless you set its [`zoomControl` option](#map-zoomcontrol) to `false`.\n */\nexport class ZoomControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'topleft',\n\t\t\tzoomInText: '<span aria-hidden=\"true\">+</span>',\n\t\t\tzoomOutText: '<span aria-hidden=\"true\">&#x2212;</span>',\n\t\t});\n\t}\n\n\t/**\n\t * Creates a zoom control.\n\t * @param {...ZoomControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ZoomControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst zoomName = 'maplair-control-zoom',\n\t\tcontainer = DomUtil.create('div', `${zoomName} maplair-bar`),\n\t\toptions = this.options;\n\n\t\tthis._zoomInButton = this._createButton(options.zoomInText, I18n.translate('Zoom in'),\n\t\t\t`${zoomName}-in`, container, this._zoomIn);\n\t\tthis._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate('Zoom out'),\n\t\t\t`${zoomName}-out`, container, this._zoomOut);\n\n\t\tthis._updateDisabled();\n\t\tmap.on('zoomend zoomlevelschange', this._updateDisabled, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('zoomend zoomlevelschange', this._updateDisabled, this);\n\t}\n\n\t/**\n\t * Disables the zoom buttons.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tthis._disabled = true;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Enables the zoom buttons (if the zoom level allows).\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tthis._disabled = false;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t_zoomIn(e) {\n\t\tif (!this._disabled && this._map._zoom < this._map.getMaxZoom()) {\n\t\t\tthis._map._setUserEvent(e);\n\t\t\tthis._map.zoomIn(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));\n\t\t}\n\t}\n\n\t_zoomOut(e) {\n\t\tif (!this._disabled && this._map._zoom > this._map.getMinZoom()) {\n\t\t\tthis._map._setUserEvent(e);\n\t\t\tthis._map.zoomOut(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));\n\t\t}\n\t}\n\n\t_createButton(html, title, className, container, fn) {\n\t\tconst link = DomUtil.create('button', className, container);\n\t\tlink.type = 'button';\n\t\tlink.innerHTML = html;\n\t\tlink.title = title;\n\t\tlink.setAttribute('aria-label', title);\n\n\t\tDomEvent.disableClickPropagation(link);\n\t\tDomEvent.on(link, 'click', DomEvent.stop);\n\t\tDomEvent.on(link, 'click', fn, this);\n\t\tDomEvent.on(link, 'click', this._refocusOnMap, this);\n\n\t\treturn link;\n\t}\n\n\t_updateDisabled() {\n\t\tconst map = this._map,\n\t\tclassName = 'maplair-disabled';\n\n\t\tthis._zoomInButton.classList.remove(className);\n\t\tthis._zoomOutButton.classList.remove(className);\n\t\tthis._zoomInButton.setAttribute('aria-disabled', 'false');\n\t\tthis._zoomOutButton.setAttribute('aria-disabled', 'false');\n\n\t\tif (this._disabled || map._zoom === map.getMinZoom()) {\n\t\t\tthis._zoomOutButton.classList.add(className);\n\t\t\tthis._zoomOutButton.setAttribute('aria-disabled', 'true');\n\t\t}\n\t\tif (this._disabled || map._zoom === map.getMaxZoom()) {\n\t\t\tthis._zoomInButton.classList.add(className);\n\t\t\tthis._zoomInButton.setAttribute('aria-disabled', 'true');\n\t\t}\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tzoomControl: true\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.zoomControl) {\n\t\t\t\tthis.zoomControl = new ZoomControl();\n\t\t\t\tthis.addControl(this.zoomControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;CAExC;EACC,KAAK,kBAAkB;GACtB,UAAU;GACV,YAAY;GACZ,aAAa;EACd,CAAC;CACF;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,WAAW,wBACjB,YAAYA,OAAe,OAAO,GAAG,SAAS,aAAa,GAC3D,UAAU,KAAK;EAEf,KAAK,gBAAiB,KAAK,cAAc,QAAQ,YAAY,KAAK,UAAU,SAAS,GACpF,GAAG,SAAS,MAAO,WAAW,KAAK,OAAO;EAC3C,KAAK,iBAAiB,KAAK,cAAc,QAAQ,aAAa,KAAK,UAAU,UAAU,GACtF,GAAG,SAAS,OAAO,WAAW,KAAK,QAAQ;EAE5C,KAAK,gBAAgB;EACrB,IAAI,GAAG,4BAA4B,KAAK,iBAAiB,IAAI;EAE7D,OAAO;CACR;;;;;CAMA,SAAS,KAAK;EACb,IAAI,IAAI,4BAA4B,KAAK,iBAAiB,IAAI;CAC/D;;;;;CAMA,UAAU;EACT,KAAK,YAAY;EACjB,KAAK,gBAAgB;EACrB,OAAO;CACR;;;;;CAMA,SAAS;EACR,KAAK,YAAY;EACjB,KAAK,gBAAgB;EACrB,OAAO;CACR;CAEA,QAAQ,GAAG;EACV,IAAI,CAAC,KAAK,aAAa,KAAK,KAAK,QAAQ,KAAK,KAAK,WAAW,GAAG;GAChE,KAAK,KAAK,cAAc,CAAC;GACz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AI,YAAY;IACnC,KAAK,WAAW,KAAK,WAAW;GACjC;EACD,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"ZoomControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/ZoomControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Options of `ZoomControl`.\n * @typedef {object} ZoomControlOptions\n * @property {string} [position='topleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {string} [zoomInText='<span aria-hidden=\"true\">+</span>'] The text set on\n * the 'zoom in' button.\n * @property {string} [zoomOutText='<span aria-hidden=\"true\">&#x2212;</span>'] The text\n * set on the 'zoom out' button.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `ZoomControl`.\n * @typedef {object} ZoomControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [zoomControl=true] Whether a [zoom control](#control-zoom) is\n * added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `ZoomControl`.\n * @typedef {object} ZoomControlMapProperties\n * @lends MaplairMap\n * @property {ZoomControl} zoomControl The default zoom control (only available if the\n * [`zoomControl` option](#map-zoomcontrol) was `true` when creating the map).\n */\n\n/**\n * A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by\n * default unless you set its [`zoomControl` option](#map-zoomcontrol) to `false`.\n */\nexport class ZoomControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tzoomInText: '<span aria-hidden=\"true\">+</span>',\n\t\tzoomOutText: '<span aria-hidden=\"true\">&#x2212;</span>',\n\t};\n\n\t/**\n\t * Creates a zoom control.\n\t * @param {...ZoomControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ZoomControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst zoomName = 'maplair-control-zoom',\n\t\tcontainer = DomUtil.create('div', `${zoomName} maplair-bar`),\n\t\toptions = this.options;\n\n\t\tthis._zoomInButton = this._createButton(options.zoomInText, I18n.translate('Zoom in'),\n\t\t\t`${zoomName}-in`, container, this._zoomIn);\n\t\tthis._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate('Zoom out'),\n\t\t\t`${zoomName}-out`, container, this._zoomOut);\n\n\t\tthis._updateDisabled();\n\t\tmap.on('zoomend zoomlevelschange', this._updateDisabled, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('zoomend zoomlevelschange', this._updateDisabled, this);\n\t}\n\n\t/**\n\t * Disables the zoom buttons.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tthis._disabled = true;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Enables the zoom buttons (if the zoom level allows).\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tthis._disabled = false;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t_zoomIn(e) {\n\t\tif (!this._disabled && this._map._zoom < this._map.getMaxZoom()) {\n\t\t\tthis._map._setUserEvent(e);\n\t\t\tthis._map.zoomIn(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));\n\t\t}\n\t}\n\n\t_zoomOut(e) {\n\t\tif (!this._disabled && this._map._zoom > this._map.getMinZoom()) {\n\t\t\tthis._map._setUserEvent(e);\n\t\t\tthis._map.zoomOut(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));\n\t\t}\n\t}\n\n\t_createButton(html, title, className, container, fn) {\n\t\tconst link = DomUtil.create('button', className, container);\n\t\tlink.type = 'button';\n\t\tlink.innerHTML = html;\n\t\tlink.title = title;\n\t\tlink.setAttribute('aria-label', title);\n\n\t\tDomEvent.disableClickPropagation(link);\n\t\tDomEvent.on(link, 'click', DomEvent.stop);\n\t\tDomEvent.on(link, 'click', fn, this);\n\t\tDomEvent.on(link, 'click', this._refocusOnMap, this);\n\n\t\treturn link;\n\t}\n\n\t_updateDisabled() {\n\t\tconst map = this._map,\n\t\tclassName = 'maplair-disabled';\n\n\t\tthis._zoomInButton.classList.remove(className);\n\t\tthis._zoomOutButton.classList.remove(className);\n\t\tthis._zoomInButton.setAttribute('aria-disabled', 'false');\n\t\tthis._zoomOutButton.setAttribute('aria-disabled', 'false');\n\n\t\tif (this._disabled || map._zoom === map.getMinZoom()) {\n\t\t\tthis._zoomOutButton.classList.add(className);\n\t\t\tthis._zoomOutButton.setAttribute('aria-disabled', 'true');\n\t\t}\n\t\tif (this._disabled || map._zoom === map.getMaxZoom()) {\n\t\t\tthis._zoomInButton.classList.add(className);\n\t\t\tthis._zoomInButton.setAttribute('aria-disabled', 'true');\n\t\t}\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tzoomControl: true\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.zoomControl) {\n\t\t\t\tthis.zoomControl = new ZoomControl();\n\t\t\t\tthis.addControl(this.zoomControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;CAExC,OAAO,iBAAiB;EACvB,UAAU;EACV,YAAY;EACZ,aAAa;CACd;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,WAAW,wBACjB,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IAAI,IAAI;EACnC,GAAY,MAAM,SAAS,KAAK,eAAe,IAAI;EAEnD,OAAO;CACR;CAEA,kBAAkB;EACjB,MAAM,MAAM,KAAK,MACjB,YAAY;EAEZ,KAAK,cAAc,UAAU,OAAO,SAAS;EAC7C,KAAK,eAAe,UAAU,OAAO,SAAS;EAC9C,KAAK,cAAc,aAAa,iBAAiB,OAAO;EACxD,KAAK,eAAe,aAAa,iBAAiB,OAAO;EAEzD,IAAI,KAAK,aAAa,IAAI,UAAU,IAAI,WAAW,GAAG;GACrD,KAAK,eAAe,UAAU,IAAI,SAAS;GAC3C,KAAK,eAAe,aAAa,iBAAiB,MAAM;EACzD;EACA,IAAI,KAAK,aAAa,IAAI,UAAU,IAAI,WAAW,GAAG;GACrD,KAAK,cAAc,UAAU,IAAI,SAAS;GAC1C,KAAK,cAAc,aAAa,iBAAiB,MAAM;EACxD;CACD;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,aAAa,KACd,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,aAAa;IAC7B,KAAK,cAAc,IAAI,YAAY;IACnC,KAAK,WAAW,KAAK,WAAW;GACjC;EACD,CAAC;CACF;AACD"}
@@ -10,28 +10,24 @@ import { setOptions } from "./Util.js";
10
10
  *
11
11
  * <h3 id="class-options">Options</h3>
12
12
  *
13
- * `options` is a special property that will be merged with the parent class options
14
- * instead of overriding them completely, which makes managing configuration of objects
15
- * and default values convenient. Use `setDefaultOptions()` in a static block to
16
- * configure options:
13
+ * `options` is a special property whose defaults, the static `defaultOptions` of the
14
+ * class, are merged with those of the parent class instead of overriding them
15
+ * completely, which makes managing configuration of objects and default values
16
+ * convenient:
17
17
  *
18
18
  * ```js
19
19
  * class MyClass extends Class {
20
- * static {
21
- * this.setDefaultOptions({
22
- * myOption1: 'foo',
23
- * myOption2: 'bar'
24
- * });
25
- * }
20
+ * static defaultOptions = {
21
+ * myOption1: 'foo',
22
+ * myOption2: 'bar'
23
+ * };
26
24
  * }
27
25
  *
28
26
  * class MyChildClass extends MyClass {
29
- * static {
30
- * this.setDefaultOptions({
31
- * myOption1: 'baz',
32
- * myOption3: 5
33
- * });
34
- * }
27
+ * static defaultOptions = {
28
+ * myOption1: 'baz',
29
+ * myOption3: 5
30
+ * };
35
31
  * }
36
32
  *
37
33
  * const a = new MyChildClass();
@@ -46,12 +42,10 @@ import { setOptions } from "./Util.js";
46
42
  *
47
43
  * ```js
48
44
  * class MyClass extends Class {
49
- * static {
50
- * this.setDefaultOptions({
51
- * foo: 'bar',
52
- * bla: 5
53
- * });
54
- * }
45
+ * static defaultOptions = {
46
+ * foo: 'bar',
47
+ * bla: 5
48
+ * };
55
49
  *
56
50
  * constructor(options) {
57
51
  * super();
@@ -163,42 +157,38 @@ var Class = class {
163
157
  * @returns {T}
164
158
  */
165
159
  static include(props) {
166
- const parentOptions = this.prototype.options;
167
- for (const k of getAllMethodNames(props)) this.prototype[k] = props[k];
168
- if (props.options) {
169
- this.prototype.options = parentOptions;
170
- this.mergeOptions(props.options);
171
- }
160
+ for (const k of getAllMethodNames(props)) if (k !== "constructor" && k !== "options") this.prototype[k] = props[k];
161
+ if (props.options) this.mergeOptions(props.options);
172
162
  return this;
173
163
  function* getAllMethodNames(obj) {
174
164
  do {
175
165
  if (obj === Object || obj === Object.prototype) break;
176
166
  for (const k of Object.getOwnPropertyNames(obj)) yield k;
177
- } while ((obj = Object.getPrototypeOf(obj)) !== void 0);
167
+ } while ((obj = Object.getPrototypeOf(obj)) !== null);
178
168
  }
179
169
  }
180
170
  /**
181
- * Configures the [default `options`](#class-options) on the prototype of this class.
171
+ * [Merges `options`](#class-options) into the `defaultOptions` of the class.
182
172
  * @template {typeof Class} T
183
173
  * @this {T}
184
174
  * @param {object} options
185
175
  * @returns {T}
186
176
  */
187
- static setDefaultOptions(options) {
188
- setOptions(this.prototype, options);
177
+ static mergeOptions(options) {
178
+ if (!Object.hasOwn(this, "defaultOptions")) this.defaultOptions = Object.create(this.defaultOptions ?? Object.prototype);
179
+ Object.assign(this.defaultOptions, options);
189
180
  return this;
190
181
  }
191
182
  /**
192
- * [Merges `options`](#class-options) into the defaults of the class.
183
+ * Deprecated alias of `mergeOptions()`, kept for code written for Maplair 4.0.
184
+ * @deprecated Use `static defaultOptions = {…}` or `mergeOptions()`.
193
185
  * @template {typeof Class} T
194
186
  * @this {T}
195
187
  * @param {object} options
196
188
  * @returns {T}
197
189
  */
198
- static mergeOptions(options) {
199
- this.prototype.options ??= {};
200
- Object.assign(this.prototype.options, options);
201
- return this;
190
+ static setDefaultOptions(options) {
191
+ return this.mergeOptions(options);
202
192
  }
203
193
  /**
204
194
  * Adds a [constructor hook](#class-constructor-hooks) to the class: a function
@@ -219,6 +209,7 @@ var Class = class {
219
209
  return this;
220
210
  }
221
211
  constructor() {
212
+ if (this.initialize) throw new Error(`${this.constructor.name}: initialize() is not called in Maplair. Rename it to constructor() and call super() at its start.`);
222
213
  setOptions(this);
223
214
  }
224
215
  /**