maplair 4.0.0 → 4.2.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 +178 -0
- package/dist/esm/Maplair.js +18 -17
- package/dist/esm/Maplair.js.map +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
- package/dist/esm/control/AttributionControl.js +25 -16
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +10 -13
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +2 -5
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +10 -18
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +6 -9
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +170 -65
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +8 -11
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +15 -18
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +2 -5
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +8 -11
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +100 -19
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +2 -5
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +6 -9
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +407 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +23 -36
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -44
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +22 -10
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +23 -14
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/I18n.js +1 -2
- package/dist/esm/core/Util.js +15 -4
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +26 -24
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +3 -18
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +18 -60
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +15 -70
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +21 -21
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +4 -27
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +16 -7
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +9 -15
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +1 -2
- package/dist/esm/geo/crs/EPSG3395.js +5 -6
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +5 -6
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +4 -5
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +3 -4
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +4 -5
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +5 -6
- package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +4 -5
- package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +5 -6
- package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
- package/dist/esm/geometry/Bounds.js +10 -14
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +37 -32
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +1 -2
- package/dist/esm/geometry/PolyUtil.js +24 -51
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -2
- package/dist/esm/layer/BlanketOverlay.js +7 -10
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/Classification.js +1 -2
- package/dist/esm/layer/DivOverlay.js +16 -22
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/FeatureGroup.js +5 -4
- package/dist/esm/layer/FeatureGroup.js.map +1 -1
- package/dist/esm/layer/GeoJSON.Load.js +1 -2
- package/dist/esm/layer/GeoJSON.js +17 -155
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +74 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +17 -20
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +22 -29
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +9 -12
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +53 -3
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +35 -58
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +3 -7
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +31 -34
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +13 -17
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +38 -49
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +8 -11
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +9 -12
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +44 -5
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +5 -8
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +115 -47
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +301 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +7 -10
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +89 -101
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +36 -44
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +33 -27
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +8 -17
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +6 -5
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +19 -10
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +3 -5
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
- package/dist/esm/layer/vector/Path.js +28 -22
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +22 -7
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +3 -4
- package/dist/esm/layer/vector/Polyline.js +25 -10
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Rectangle.js +1 -2
- package/dist/esm/layer/vector/Renderer.getRenderer.js +17 -17
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +1 -2
- package/dist/esm/layer/vector/SVG.js +12 -9
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Hash.js +1 -2
- package/dist/esm/map/Map.Rotation.js +41 -22
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +125 -126
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -2
- package/dist/esm/map/handler/BoxZoomHandler.js +25 -47
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +7 -10
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
- package/dist/esm/map/handler/DragHandler.js +20 -21
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +48 -68
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +13 -5
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -6
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
- package/dist/esm/map/handler/TapHoldHandler.js +13 -7
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +2 -3
- package/dist/maplair-global-src.js +6495 -5981
- 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 +6206 -5673
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1213
- 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 +11 -18
- package/src/Maplair.all.js +0 -1
- 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 +196 -86
- 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 +22 -38
- package/src/control/index.js +1 -0
- package/src/core/Class.js +37 -45
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +25 -13
- package/src/core/Util.js +20 -2
- 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 +17 -85
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +32 -23
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +20 -3
- package/src/geo/LatLngBounds.js +8 -15
- package/src/geo/crs/EPSG3395.js +4 -4
- package/src/geo/crs/EPSG3857.js +4 -4
- package/src/geo/crs/EPSG4326.js +3 -3
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +3 -3
- package/src/geo/index.js +1 -2
- package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +2 -2
- package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +2 -2
- package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +2 -2
- package/src/geo/projection/index.js +5 -5
- package/src/geometry/Bounds.js +12 -17
- package/src/geometry/LineUtil.js +48 -49
- package/src/geometry/PolyUtil.js +39 -76
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +16 -27
- package/src/layer/FeatureGroup.js +8 -2
- package/src/layer/GeoJSON.js +17 -218
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +10 -12
- package/src/layer/ImageOverlay.js +21 -32
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +72 -1
- package/src/layer/Popup.js +37 -62
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +34 -36
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +40 -58
- package/src/layer/marker/DivIcon.js +9 -11
- package/src/layer/marker/Icon.js +9 -10
- package/src/layer/marker/Marker.Drag.js +54 -6
- package/src/layer/marker/Marker.Move.js +4 -6
- package/src/layer/marker/Marker.js +145 -52
- 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 +108 -135
- package/src/layer/tile/TileLayer.js +44 -49
- package/src/layer/tile/WMSTileLayer.js +31 -26
- package/src/layer/vector/Canvas.js +13 -19
- package/src/layer/vector/Circle.js +9 -3
- package/src/layer/vector/CircleMarker.js +19 -7
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +29 -6
- package/src/layer/vector/Polyline.js +26 -7
- package/src/layer/vector/Renderer.getRenderer.js +20 -19
- package/src/layer/vector/SVG.js +17 -7
- package/src/map/Map.Rotation.js +40 -8
- package/src/map/Map.js +158 -153
- package/src/map/handler/BoxZoomHandler.js +30 -50
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +25 -28
- package/src/map/handler/KeyboardHandler.js +65 -90
- 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 +153 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
- package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
- package/dist/esm/geo/projection/index.js +0 -14
- package/dist/esm/geo/projection/index.js.map +0 -1
- package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
- package/dist/esm/layer/marker/Marker.Rotation.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
- package/src/layer/marker/Marker.Rotation.js +0 -103
|
@@ -9,11 +9,43 @@ import {I18n} from '../core/I18n.js';
|
|
|
9
9
|
/** @import {Layer} from '../layer/Layer.js' */
|
|
10
10
|
/** @import {LayersControlEvent} from '../core/Events.js' */
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* An entry of `LayersControl`, as returned by `getLayers()`.
|
|
14
|
+
* @typedef {object} LayersControlEntry
|
|
15
|
+
* @property {Layer} layer The layer.
|
|
16
|
+
* @property {string} name The name of the layer, as given to the control.
|
|
17
|
+
* @property {boolean} overlay Whether the layer is an overlay (checkbox) or a base layer
|
|
18
|
+
* (radio button).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The group of an entry of `LayersControl`, as returned by the option `groupBy`.
|
|
23
|
+
* @typedef {object} LayersControlGroup
|
|
24
|
+
* @property {string} group The name of the group, rendered as text.
|
|
25
|
+
* @property {string} label The label of the entry within the group, may contain HTML
|
|
26
|
+
* (like layer names).
|
|
27
|
+
*/
|
|
28
|
+
|
|
12
29
|
/**
|
|
13
30
|
* Options of `LayersControl`.
|
|
14
31
|
* @typedef {object} LayersControlOptions
|
|
15
32
|
* @property {boolean} [collapsed=true] If `true`, the control will be collapsed into an
|
|
16
|
-
* icon and expanded on pointer hover, touch, or keyboard activation.
|
|
33
|
+
* icon and expanded on pointer hover, touch, or keyboard activation. Ignored if `inline`
|
|
34
|
+
* is `true`.
|
|
35
|
+
* @property {boolean} [inline=false] If `true`, the control is laid out like the
|
|
36
|
+
* attribution control: it is always expanded (without toggle button) and all entries are
|
|
37
|
+
* placed next to each other, wrapping onto multiple lines if necessary.
|
|
38
|
+
* @property {(name: string, layer: Layer, overlay: boolean) => LayersControlGroup | undefined} [groupBy]
|
|
39
|
+
* A function to group the entries. For each entry, it returns the name of its group and
|
|
40
|
+
* its label within the group, or `undefined` for an ungrouped entry. Consecutive entries
|
|
41
|
+
* of the same group (base layers and overlays separately) are rendered within one
|
|
42
|
+
* `maplair-control-layers-group` container, starting with the group name in a
|
|
43
|
+
* `maplair-control-layers-group-name` element, and each entry shows only its label.
|
|
44
|
+
* Events like `baselayerchange` still carry the full `name`. When combined with
|
|
45
|
+
* `sortLayers`, the entries are sorted first and grouped afterwards.
|
|
46
|
+
* @property {string|HTMLElement} [toggleContent] The content of the toggle button of a
|
|
47
|
+
* collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an
|
|
48
|
+
* element. String content is rendered as HTML; do not pass untrusted input.
|
|
17
49
|
* @property {number} [collapseDelay=0] Collapse delay in milliseconds. If greater than 0,
|
|
18
50
|
* the control will remain open longer, making it easier to scroll through long layer
|
|
19
51
|
* lists.
|
|
@@ -71,6 +103,19 @@ import {I18n} from '../core/I18n.js';
|
|
|
71
103
|
* {"<img src='my-layer-icon' /> <span class='my-layer-item'>My Layer</span>": myLayer}
|
|
72
104
|
* ```
|
|
73
105
|
*
|
|
106
|
+
* Layers can be grouped using the option `groupBy`, for example layer names of the form
|
|
107
|
+
* `"Group (label)"`:
|
|
108
|
+
*
|
|
109
|
+
* ```js
|
|
110
|
+
* new LayersControl(baseLayers, overlays, {
|
|
111
|
+
* inline: true,
|
|
112
|
+
* groupBy(name) {
|
|
113
|
+
* const [, group, label] = /^([^<>()]+) \((.+)\)$/.exec(name) ?? [];
|
|
114
|
+
* return group ? {group: `${group}:`, label} : undefined;
|
|
115
|
+
* }
|
|
116
|
+
* }).addTo(map);
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
74
119
|
* @fires MaplairMap#baselayerchange {LayersControlEvent} Fired when the base layer is
|
|
75
120
|
* changed through the [layers control](#control-layers).
|
|
76
121
|
* @fires MaplairMap#overlayadd {LayersControlEvent} Fired when an overlay is selected
|
|
@@ -80,19 +125,20 @@ import {I18n} from '../core/I18n.js';
|
|
|
80
125
|
*/
|
|
81
126
|
export class LayersControl extends Control {
|
|
82
127
|
|
|
83
|
-
static {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
128
|
+
static defaultOptions = {
|
|
129
|
+
collapsed: true,
|
|
130
|
+
inline: false,
|
|
131
|
+
groupBy: undefined,
|
|
132
|
+
toggleContent: undefined,
|
|
133
|
+
collapseDelay: 0,
|
|
134
|
+
position: 'topright',
|
|
135
|
+
autoZIndex: true,
|
|
136
|
+
hideSingleBase: false,
|
|
137
|
+
sortLayers: false,
|
|
138
|
+
sortFunction(layerA, layerB, nameA, nameB) {
|
|
139
|
+
return nameA < nameB ? -1 : (nameB < nameA ? 1 : 0);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
96
142
|
|
|
97
143
|
/**
|
|
98
144
|
* Creates a layers control with the given layers. Base layers will be switched with
|
|
@@ -139,7 +185,7 @@ export class LayersControl extends Control {
|
|
|
139
185
|
layer.layer.on('add remove', this._onLayerChange, this);
|
|
140
186
|
}
|
|
141
187
|
|
|
142
|
-
if (!this.
|
|
188
|
+
if (!this._isCollapsible()) {
|
|
143
189
|
// update the height of the container after resizing the window
|
|
144
190
|
map.on('resize', this._expandIfNotCollapsed, this);
|
|
145
191
|
}
|
|
@@ -167,6 +213,7 @@ export class LayersControl extends Control {
|
|
|
167
213
|
}
|
|
168
214
|
|
|
169
215
|
this._map.off('resize', this._expandIfNotCollapsed, this);
|
|
216
|
+
this._map.off('click', this.collapse, this);
|
|
170
217
|
}
|
|
171
218
|
|
|
172
219
|
/**
|
|
@@ -199,13 +246,36 @@ export class LayersControl extends Control {
|
|
|
199
246
|
removeLayer(layer) {
|
|
200
247
|
layer.off('add remove', this._onLayerChange, this);
|
|
201
248
|
|
|
202
|
-
|
|
203
|
-
if (obj) {
|
|
204
|
-
this._layers.splice(this._layers.indexOf(obj), 1);
|
|
205
|
-
}
|
|
249
|
+
this._layers = this._layers.filter(o => o.layer !== layer);
|
|
206
250
|
return (this._map) ? this._update() : this;
|
|
207
251
|
}
|
|
208
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Returns the entries of the control in the order they are displayed.
|
|
255
|
+
* @returns {LayersControlEntry[]}
|
|
256
|
+
*/
|
|
257
|
+
getLayers() {
|
|
258
|
+
return this._layers.map(({layer, name, overlay}) => ({layer, name, overlay}));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Selects the given layer of the control like a click on its entry: a base layer
|
|
263
|
+
* replaces the current base layer, an overlay is added to the map. The events
|
|
264
|
+
* `baselayerchange` and `overlayadd` are fired as for a click, but without
|
|
265
|
+
* `originalEvent`. Has no effect if the control is not on a map or does not contain
|
|
266
|
+
* the layer.
|
|
267
|
+
* @param {Layer} layer
|
|
268
|
+
* @returns {this}
|
|
269
|
+
*/
|
|
270
|
+
selectLayer(layer) {
|
|
271
|
+
const input = this._layerControlInputs.find(input => input._layer === layer);
|
|
272
|
+
if (input && !input.checked) {
|
|
273
|
+
input.checked = true;
|
|
274
|
+
this._onInputClick();
|
|
275
|
+
}
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
|
|
209
279
|
/**
|
|
210
280
|
* Expand the control container if collapsed.
|
|
211
281
|
* @returns {this}
|
|
@@ -214,7 +284,7 @@ export class LayersControl extends Control {
|
|
|
214
284
|
clearTimeout(this._collapseDelayTimeout);
|
|
215
285
|
|
|
216
286
|
this._container.classList.add('maplair-control-layers-expanded');
|
|
217
|
-
this._section.style.height =
|
|
287
|
+
this._section.style.height = '';
|
|
218
288
|
const acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);
|
|
219
289
|
if (acceptableHeight < this._section.clientHeight) {
|
|
220
290
|
this._section.classList.add('maplair-control-layers-scrollbar');
|
|
@@ -228,24 +298,17 @@ export class LayersControl extends Control {
|
|
|
228
298
|
|
|
229
299
|
/**
|
|
230
300
|
* Collapse the control container if expanded.
|
|
231
|
-
* @param {Event} [ev] The event causing the collapse, if any (collapsing is skipped
|
|
232
|
-
* for `pointerleave` and `pointerout` of touch).
|
|
233
301
|
* @returns {this}
|
|
234
302
|
*/
|
|
235
|
-
collapse(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}, this.options.collapseDelay);
|
|
245
|
-
return this;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Collapse immediately
|
|
303
|
+
collapse() {
|
|
304
|
+
if (this.options.inline) {
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
if (this.options.collapseDelay > 0) {
|
|
308
|
+
this._collapseDelayTimeout = setTimeout(() => {
|
|
309
|
+
this._container.classList.remove('maplair-control-layers-expanded');
|
|
310
|
+
}, this.options.collapseDelay);
|
|
311
|
+
} else {
|
|
249
312
|
this._container.classList.remove('maplair-control-layers-expanded');
|
|
250
313
|
}
|
|
251
314
|
return this;
|
|
@@ -254,39 +317,56 @@ export class LayersControl extends Control {
|
|
|
254
317
|
_initLayout() {
|
|
255
318
|
const className = 'maplair-control-layers',
|
|
256
319
|
container = this._container = DomUtil.create('div', className),
|
|
257
|
-
collapsed = this.
|
|
320
|
+
collapsed = this._isCollapsible();
|
|
321
|
+
|
|
322
|
+
if (this.options.inline) {
|
|
323
|
+
container.classList.add(`${className}-inline`);
|
|
324
|
+
}
|
|
258
325
|
|
|
259
326
|
DomEvent.disableClickPropagation(container);
|
|
260
327
|
DomEvent.disableScrollPropagation(container);
|
|
261
328
|
|
|
262
329
|
const section = this._section = DomUtil.create('fieldset', `${className}-list`);
|
|
330
|
+
section.setAttribute('aria-label', I18n.translate('Layers'));
|
|
263
331
|
|
|
264
332
|
if (collapsed) {
|
|
265
333
|
this._map.on('click', this.collapse, this);
|
|
266
334
|
|
|
267
335
|
DomEvent.on(container, {
|
|
268
336
|
pointerenter: this._expandSafely,
|
|
269
|
-
pointerleave
|
|
337
|
+
// on touch devices, pointerleave fires while clicking a checkbox, which shouldn't collapse the control
|
|
338
|
+
pointerleave(e) {
|
|
339
|
+
if (e.pointerType !== 'touch') { this.collapse(); }
|
|
340
|
+
}
|
|
270
341
|
}, this);
|
|
271
342
|
}
|
|
272
343
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
344
|
+
if (!this.options.inline) {
|
|
345
|
+
const link = this._layersLink = DomUtil.create('button', `${className}-toggle`, container);
|
|
346
|
+
link.type = 'button';
|
|
347
|
+
link.title = I18n.translate('Layers');
|
|
348
|
+
link.setAttribute('aria-label', I18n.translate('Layers'));
|
|
349
|
+
|
|
350
|
+
const {toggleContent} = this.options;
|
|
351
|
+
if (typeof toggleContent === 'string') {
|
|
352
|
+
link.innerHTML = toggleContent;
|
|
353
|
+
} else if (toggleContent) {
|
|
354
|
+
link.replaceChildren(toggleContent);
|
|
355
|
+
}
|
|
277
356
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
357
|
+
DomEvent.on(link, {
|
|
358
|
+
keydown(e) {
|
|
359
|
+
if (e.code === 'Enter') {
|
|
360
|
+
this._expandSafely();
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
// Certain screen readers intercept the key event and instead send a click event
|
|
364
|
+
click(e) {
|
|
365
|
+
e.preventDefault();
|
|
281
366
|
this._expandSafely();
|
|
282
367
|
}
|
|
283
|
-
},
|
|
284
|
-
|
|
285
|
-
click(e) {
|
|
286
|
-
e.preventDefault();
|
|
287
|
-
this._expandSafely();
|
|
288
|
-
}
|
|
289
|
-
}, this);
|
|
368
|
+
}, this);
|
|
369
|
+
}
|
|
290
370
|
|
|
291
371
|
if (!collapsed) {
|
|
292
372
|
this.expand();
|
|
@@ -299,14 +379,6 @@ export class LayersControl extends Control {
|
|
|
299
379
|
container.appendChild(section);
|
|
300
380
|
}
|
|
301
381
|
|
|
302
|
-
_getLayer(id) {
|
|
303
|
-
for (const layer of this._layers) {
|
|
304
|
-
if (layer && Util.stamp(layer.layer) === id) {
|
|
305
|
-
return layer;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
382
|
_addLayer(layer, name, overlay) {
|
|
311
383
|
if (this._map) {
|
|
312
384
|
layer.on('add remove', this._onLayerChange, this);
|
|
@@ -315,7 +387,7 @@ export class LayersControl extends Control {
|
|
|
315
387
|
this._layers.push({
|
|
316
388
|
layer,
|
|
317
389
|
name,
|
|
318
|
-
overlay
|
|
390
|
+
overlay: !!overlay
|
|
319
391
|
});
|
|
320
392
|
|
|
321
393
|
if (this.options.sortLayers) {
|
|
@@ -337,6 +409,7 @@ export class LayersControl extends Control {
|
|
|
337
409
|
this._overlaysList.replaceChildren();
|
|
338
410
|
|
|
339
411
|
this._layerControlInputs = [];
|
|
412
|
+
this._groupCount = 0;
|
|
340
413
|
let baseLayersPresent, overlaysPresent, baseLayersCount = 0;
|
|
341
414
|
|
|
342
415
|
for (const obj of this._layers) {
|
|
@@ -362,14 +435,14 @@ export class LayersControl extends Control {
|
|
|
362
435
|
this._update();
|
|
363
436
|
}
|
|
364
437
|
|
|
365
|
-
const obj = this.
|
|
438
|
+
const obj = this._layers.find(o => o.layer === e.target);
|
|
366
439
|
|
|
367
440
|
const type = obj.overlay ?
|
|
368
441
|
(e.type === 'add' ? 'overlayadd' : 'overlayremove') :
|
|
369
442
|
(e.type === 'add' ? 'baselayerchange' : null);
|
|
370
443
|
|
|
371
444
|
if (type) {
|
|
372
|
-
this._map.fire(type, obj);
|
|
445
|
+
this._map.fire(type, this._clickEvent ? {...obj, originalEvent: this._clickEvent} : obj);
|
|
373
446
|
}
|
|
374
447
|
}
|
|
375
448
|
|
|
@@ -386,12 +459,14 @@ export class LayersControl extends Control {
|
|
|
386
459
|
}
|
|
387
460
|
|
|
388
461
|
this._layerControlInputs.push(input);
|
|
389
|
-
input.
|
|
462
|
+
input._layer = obj.layer;
|
|
390
463
|
|
|
391
464
|
DomEvent.on(input, 'click', this._onInputClick, this);
|
|
392
465
|
|
|
466
|
+
const group = this.options.groupBy?.(obj.name, obj.layer, obj.overlay);
|
|
467
|
+
|
|
393
468
|
const name = document.createElement('span');
|
|
394
|
-
name.innerHTML = ` ${obj.name}`;
|
|
469
|
+
name.innerHTML = ` ${group ? group.label : obj.name}`;
|
|
395
470
|
|
|
396
471
|
// Helps from preventing layer control flicker when checkboxes are disabled
|
|
397
472
|
// https://github.com/Leaflet/Leaflet/issues/2771
|
|
@@ -401,48 +476,79 @@ export class LayersControl extends Control {
|
|
|
401
476
|
holder.appendChild(input);
|
|
402
477
|
holder.appendChild(name);
|
|
403
478
|
|
|
404
|
-
const
|
|
479
|
+
const list = obj.overlay ? this._overlaysList : this._baseLayersList;
|
|
480
|
+
const container = group ? this._getGroupContainer(list, group.group) : list;
|
|
405
481
|
container.appendChild(label);
|
|
406
482
|
|
|
407
483
|
this._checkDisabledLayers();
|
|
408
484
|
return label;
|
|
409
485
|
}
|
|
410
486
|
|
|
487
|
+
/**
|
|
488
|
+
* Returns the container of the given group if it is the last element in `list`
|
|
489
|
+
* (continuing the group), otherwise appends a new group container to `list`.
|
|
490
|
+
* @param {HTMLElement} list
|
|
491
|
+
* @param {string} group
|
|
492
|
+
* @returns {HTMLElement}
|
|
493
|
+
*/
|
|
494
|
+
_getGroupContainer(list, group) {
|
|
495
|
+
const last = list.lastElementChild;
|
|
496
|
+
if (last?._maplairGroup === group) {
|
|
497
|
+
return last;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const className = 'maplair-control-layers-group',
|
|
501
|
+
container = DomUtil.create('div', className, list),
|
|
502
|
+
name = DomUtil.create('span', `${className}-name`, container);
|
|
503
|
+
name.id = `${className}_${Util.stamp(this)}_${++this._groupCount}`;
|
|
504
|
+
name.textContent = group;
|
|
505
|
+
container.setAttribute('role', 'group');
|
|
506
|
+
container.setAttribute('aria-labelledby', name.id);
|
|
507
|
+
container._maplairGroup = group;
|
|
508
|
+
return container;
|
|
509
|
+
}
|
|
510
|
+
|
|
411
511
|
_onInputClick(e) {
|
|
412
512
|
// expanding the control on mobile with a click can cause adding a layer - we don't want this
|
|
413
513
|
if (this._preventClick) {
|
|
414
514
|
return;
|
|
415
515
|
}
|
|
416
516
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
for (const input of inputs) {
|
|
424
|
-
const layer = this._getLayer(input.layerId).layer;
|
|
517
|
+
// a layer can be listed under several inputs, so it should be on the map if any of them is checked
|
|
518
|
+
const checked = new Map();
|
|
519
|
+
for (const input of this._layerControlInputs) {
|
|
520
|
+
const layer = input._layer;
|
|
521
|
+
checked.set(layer, checked.get(layer) || input.checked);
|
|
522
|
+
}
|
|
425
523
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
524
|
+
// diff against the map upfront, so layers that event handlers add or remove below keep their state
|
|
525
|
+
const addedLayers = [], removedLayers = [];
|
|
526
|
+
for (const [layer, on] of checked) {
|
|
527
|
+
if (on !== this._map.hasLayer(layer)) {
|
|
528
|
+
(on ? addedLayers : removedLayers).push(layer);
|
|
430
529
|
}
|
|
431
530
|
}
|
|
432
531
|
|
|
532
|
+
this._handlingClick = true;
|
|
533
|
+
this._clickEvent = e;
|
|
534
|
+
|
|
433
535
|
// Bugfix issue 2318: Should remove all old layers before readding new ones
|
|
434
536
|
for (const layer of removedLayers) {
|
|
435
|
-
|
|
436
|
-
this._map.removeLayer(layer);
|
|
437
|
-
}
|
|
537
|
+
this._map.removeLayer(layer);
|
|
438
538
|
}
|
|
439
539
|
for (const layer of addedLayers) {
|
|
440
|
-
|
|
441
|
-
this._map.addLayer(layer);
|
|
442
|
-
}
|
|
540
|
+
this._map.addLayer(layer);
|
|
443
541
|
}
|
|
444
542
|
|
|
445
543
|
this._handlingClick = false;
|
|
544
|
+
this._clickEvent = undefined;
|
|
545
|
+
|
|
546
|
+
for (const [layer, on] of checked) {
|
|
547
|
+
if (on !== this._map.hasLayer(layer)) {
|
|
548
|
+
this._update();
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
446
552
|
|
|
447
553
|
this._refocusOnMap(e);
|
|
448
554
|
}
|
|
@@ -452,15 +558,19 @@ export class LayersControl extends Control {
|
|
|
452
558
|
zoom = this._map.getZoom();
|
|
453
559
|
|
|
454
560
|
for (const input of inputs) {
|
|
455
|
-
const layer =
|
|
561
|
+
const layer = input._layer;
|
|
456
562
|
input.disabled = (layer.options.minZoom !== undefined && zoom < layer.options.minZoom) ||
|
|
457
563
|
(layer.options.maxZoom !== undefined && zoom > layer.options.maxZoom);
|
|
458
564
|
|
|
459
565
|
}
|
|
460
566
|
}
|
|
461
567
|
|
|
568
|
+
_isCollapsible() {
|
|
569
|
+
return this.options.collapsed && !this.options.inline;
|
|
570
|
+
}
|
|
571
|
+
|
|
462
572
|
_expandIfNotCollapsed() {
|
|
463
|
-
if (this._map && !this.
|
|
573
|
+
if (this._map && !this._isCollapsible()) {
|
|
464
574
|
this.expand();
|
|
465
575
|
}
|
|
466
576
|
return this;
|
|
@@ -47,14 +47,12 @@ const svgNS = 'http://www.w3.org/2000/svg';
|
|
|
47
47
|
|
|
48
48
|
export class LegendControl extends Control {
|
|
49
49
|
|
|
50
|
-
static {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
}
|
|
50
|
+
static defaultOptions = {
|
|
51
|
+
position: 'bottomright',
|
|
52
|
+
collapsed: false,
|
|
53
|
+
featureCount: false,
|
|
54
|
+
bar: false
|
|
55
|
+
};
|
|
58
56
|
|
|
59
57
|
/**
|
|
60
58
|
* Creates a legend control.
|
|
@@ -236,7 +234,7 @@ function formatCount({count, share}) {
|
|
|
236
234
|
function createPatch(layer, symbol, styled) {
|
|
237
235
|
while (layer?.getLayers) { layer = layer.getLayers()[0]; }
|
|
238
236
|
if (!layer?.setStyle) { layer = undefined; }
|
|
239
|
-
const base = layer?.options ?? CircleMarker.
|
|
237
|
+
const base = layer?.options ?? new CircleMarker([0, 0]).options,
|
|
240
238
|
options = Object.assign(Object.create(base), layer && styled ? {} : symbol),
|
|
241
239
|
svg = document.createElementNS(svgNS, 'svg');
|
|
242
240
|
svg.setAttribute('class', 'maplair-control-legend-patch');
|
|
@@ -43,17 +43,15 @@ import {Polygon} from '../layer/vector/Polygon.js';
|
|
|
43
43
|
*/
|
|
44
44
|
export class MiniMapControl extends Control {
|
|
45
45
|
|
|
46
|
-
static {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
}
|
|
46
|
+
static defaultOptions = {
|
|
47
|
+
position: 'bottomright',
|
|
48
|
+
width: 150,
|
|
49
|
+
height: 150,
|
|
50
|
+
zoomOffset: -5,
|
|
51
|
+
collapsed: false,
|
|
52
|
+
rectangleOptions: {color: '#ff7800', weight: 1, fillOpacity: 0.2},
|
|
53
|
+
mapOptions: {}
|
|
54
|
+
};
|
|
57
55
|
|
|
58
56
|
/**
|
|
59
57
|
* Creates an overview map control showing `layer` (which must not be on another map).
|
|
@@ -44,11 +44,9 @@ const compass = '<svg aria-hidden="true" width="16" height="16" viewBox="0 0 16
|
|
|
44
44
|
*/
|
|
45
45
|
export class RotateControl extends Control {
|
|
46
46
|
|
|
47
|
-
static {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
}
|
|
47
|
+
static defaultOptions = {
|
|
48
|
+
position: 'topleft'
|
|
49
|
+
};
|
|
52
50
|
|
|
53
51
|
/**
|
|
54
52
|
* Creates a rotate control.
|
|
@@ -33,15 +33,13 @@ import {I18n} from '../core/I18n.js';
|
|
|
33
33
|
*/
|
|
34
34
|
export class ScaleControl extends Control {
|
|
35
35
|
|
|
36
|
-
static {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
}
|
|
36
|
+
static defaultOptions = {
|
|
37
|
+
position: 'bottomleft',
|
|
38
|
+
maxWidth: 100,
|
|
39
|
+
metric: true,
|
|
40
|
+
imperial: true,
|
|
41
|
+
updateWhenIdle: false
|
|
42
|
+
};
|
|
45
43
|
|
|
46
44
|
/**
|
|
47
45
|
* Creates a scale control with the given options.
|