maplair 4.0.0-alpha.1 → 4.0.0-alpha.2
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 +61 -1
- package/README.md +3 -1
- package/dist/esm/Maplair.js +52 -33
- package/dist/esm/Maplair.js.map +1 -1
- package/dist/esm/control/AttributionControl.js +76 -4
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +221 -0
- package/dist/esm/control/ButtonControl.js.map +1 -0
- package/dist/esm/control/ContextMenu.js +173 -0
- package/dist/esm/control/ContextMenu.js.map +1 -0
- package/dist/esm/control/Control.js +118 -30
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +186 -0
- package/dist/esm/control/FullscreenControl.js.map +1 -0
- package/dist/esm/control/LayersControl.js +122 -3
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +230 -0
- package/dist/esm/control/LegendControl.js.map +1 -0
- package/dist/esm/control/MiniMapControl.js +182 -0
- package/dist/esm/control/MiniMapControl.js.map +1 -0
- package/dist/esm/control/RotateControl.js +104 -0
- package/dist/esm/control/RotateControl.js.map +1 -0
- package/dist/esm/control/ScaleControl.js +40 -0
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +442 -0
- package/dist/esm/control/SearchControl.js.map +1 -0
- package/dist/esm/control/SideBySideControl.js +208 -0
- package/dist/esm/control/SideBySideControl.js.map +1 -0
- package/dist/esm/control/TextControl.js +83 -0
- package/dist/esm/control/TextControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +68 -5
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Browser.js +71 -2
- package/dist/esm/core/Browser.js.map +1 -1
- package/dist/esm/core/Class.js +193 -0
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +231 -0
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +34 -0
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/I18n.js +38 -0
- package/dist/esm/core/I18n.js.map +1 -1
- package/dist/esm/core/Util.js +62 -0
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +14 -0
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +25 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +95 -0
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +94 -0
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +55 -1
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +48 -0
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +134 -1
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +129 -0
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +100 -0
- package/dist/esm/geo/crs/CRS.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3395.js +8 -1
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +14 -1
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +15 -1
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +24 -0
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +28 -1
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +8 -0
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +5 -0
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +7 -0
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geo/projection/index.js +1 -1
- package/dist/esm/geo/projection/index.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +106 -0
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +55 -0
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +121 -0
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +26 -0
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +35 -0
- package/dist/esm/geometry/Transformation.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +54 -1
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/Classification.js +273 -0
- package/dist/esm/layer/Classification.js.map +1 -0
- package/dist/esm/layer/DivOverlay.js +218 -23
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/FeatureGroup.js +71 -0
- package/dist/esm/layer/FeatureGroup.js.map +1 -1
- package/dist/esm/layer/GeoJSON.Load.js +61 -0
- package/dist/esm/layer/GeoJSON.Load.js.map +1 -0
- package/dist/esm/layer/GeoJSON.js +218 -7
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/HeatLayer.js +198 -0
- package/dist/esm/layer/HeatLayer.js.map +1 -0
- package/dist/esm/layer/ImageOverlay.js +126 -1
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +273 -63
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +77 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +332 -89
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +33 -0
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +405 -149
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +49 -0
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +33 -0
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +44 -0
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +71 -0
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +29 -1
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +107 -0
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -0
- package/dist/esm/layer/marker/Marker.Rotation.js +70 -0
- package/dist/esm/layer/marker/Marker.Rotation.js.map +1 -0
- package/dist/esm/layer/marker/Marker.js +155 -1
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/SvgIcon.js +116 -0
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -0
- package/dist/esm/layer/tile/GridLayer.js +253 -4
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +190 -8
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +114 -6
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +58 -0
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +30 -0
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +54 -1
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +78 -0
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -0
- package/dist/esm/layer/vector/Path.ZoomStyles.js +77 -0
- package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -0
- package/dist/esm/layer/vector/Path.js +74 -0
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +67 -0
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +244 -0
- package/dist/esm/layer/vector/Polyline.Decorations.js.map +1 -0
- package/dist/esm/layer/vector/Polyline.js +90 -1
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Rectangle.js +28 -0
- package/dist/esm/layer/vector/Rectangle.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +52 -20
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +36 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +49 -0
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Hash.js +237 -0
- package/dist/esm/map/Hash.js.map +1 -0
- package/dist/esm/map/Map.Rotation.js +500 -0
- package/dist/esm/map/Map.Rotation.js.map +1 -0
- package/dist/esm/map/Map.js +790 -6
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +168 -0
- package/dist/esm/map/MapSync.js.map +1 -0
- package/dist/esm/map/handler/BoxZoomHandler.js +50 -1
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +349 -0
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +44 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +66 -4
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +90 -3
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +39 -0
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +161 -0
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +150 -0
- package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/TapHoldHandler.js +35 -0
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +15347 -4719
- 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 +15330 -4720
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +629 -146
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/cs.json +21 -1
- package/i18n/de.json +21 -1
- package/i18n/en.json +21 -1
- package/i18n/es.json +21 -1
- package/i18n/fr.json +21 -1
- package/i18n/hu.json +21 -1
- package/i18n/it.json +21 -1
- package/i18n/rm.json +21 -1
- package/i18n/sk.json +21 -1
- package/i18n/sl.json +21 -1
- package/package.json +81 -31
- package/src/Maplair.all.js +10 -0
- package/src/Maplair.js +4 -0
- package/src/control/AttributionControl.js +78 -31
- package/src/control/ButtonControl.js +248 -0
- package/src/control/ContextMenu.js +201 -0
- package/src/control/Control.js +132 -87
- package/src/control/FullscreenControl.js +227 -0
- package/src/control/LayersControl.js +92 -56
- package/src/control/LegendControl.js +273 -0
- package/src/control/MiniMapControl.js +198 -0
- package/src/control/RotateControl.js +122 -0
- package/src/control/ScaleControl.js +34 -25
- package/src/control/SearchControl.js +530 -0
- package/src/control/SideBySideControl.js +236 -0
- package/src/control/TextControl.js +91 -0
- package/src/control/ZoomControl.js +63 -35
- package/src/control/index.js +8 -0
- package/src/core/Browser.js +71 -36
- package/src/core/Class.js +193 -18
- package/src/core/Events.js +227 -35
- package/src/core/Handler.js +34 -24
- package/src/core/I18n.js +26 -19
- package/src/core/Util.js +63 -34
- package/src/dom/DomEvent.DoubleTap.js +15 -0
- package/src/dom/DomEvent.PointerEvents.js +30 -15
- package/src/dom/DomEvent.js +98 -62
- package/src/dom/DomUtil.js +102 -52
- package/src/dom/Draggable.js +49 -29
- package/src/dom/PosAnimation.js +27 -22
- package/src/geo/LatLng.js +130 -53
- package/src/geo/LatLngBounds.js +110 -63
- package/src/geo/crs/CRS.js +91 -53
- package/src/geo/crs/EPSG3395.js +5 -5
- package/src/geo/crs/EPSG3857.js +9 -6
- package/src/geo/crs/EPSG4326.js +11 -9
- package/src/geo/crs/EarthCRS.js +19 -9
- package/src/geo/crs/SimpleCRS.js +22 -5
- package/src/geo/projection/Projection.LonLat.js +5 -9
- package/src/geo/projection/Projection.Mercator.js +6 -6
- package/src/geo/projection/Projection.SphericalMercator.js +6 -7
- package/src/geo/projection/index.js +17 -15
- package/src/geometry/Bounds.js +89 -57
- package/src/geometry/LineUtil.js +56 -27
- package/src/geometry/Point.js +105 -65
- package/src/geometry/PolyUtil.js +21 -9
- package/src/geometry/Transformation.js +23 -18
- package/src/layer/BlanketOverlay.js +50 -51
- package/src/layer/Classification.js +302 -0
- package/src/layer/DivOverlay.js +246 -91
- package/src/layer/FeatureGroup.js +62 -26
- package/src/layer/GeoJSON.Load.js +109 -0
- package/src/layer/GeoJSON.js +219 -123
- package/src/layer/HeatLayer.js +231 -0
- package/src/layer/ImageOverlay.js +122 -62
- package/src/layer/Layer.js +311 -192
- package/src/layer/LayerGroup.js +66 -35
- package/src/layer/Popup.js +340 -267
- package/src/layer/SVGOverlay.js +22 -15
- package/src/layer/Tooltip.js +453 -298
- package/src/layer/VideoOverlay.js +41 -37
- package/src/layer/index.js +2 -0
- package/src/layer/marker/DefaultIcon.js +27 -11
- package/src/layer/marker/DivIcon.js +35 -19
- package/src/layer/marker/Icon.js +54 -59
- package/src/layer/marker/Marker.Drag.js +26 -29
- package/src/layer/marker/Marker.Move.js +153 -0
- package/src/layer/marker/Marker.Rotation.js +103 -0
- package/src/layer/marker/Marker.js +151 -92
- package/src/layer/marker/SvgIcon.js +122 -0
- package/src/layer/marker/index.js +1 -0
- package/src/layer/tile/GridLayer.js +223 -111
- package/src/layer/tile/TileLayer.js +204 -80
- package/src/layer/tile/WMSTileLayer.js +118 -44
- package/src/layer/vector/Canvas.js +44 -12
- package/src/layer/vector/Circle.js +24 -22
- package/src/layer/vector/CircleMarker.js +53 -22
- package/src/layer/vector/Path.DashAnimation.js +108 -0
- package/src/layer/vector/Path.ZoomStyles.js +103 -0
- package/src/layer/vector/Path.js +73 -57
- package/src/layer/vector/Polygon.js +32 -12
- package/src/layer/vector/Polyline.Decorations.js +299 -0
- package/src/layer/vector/Polyline.js +59 -36
- package/src/layer/vector/Rectangle.js +14 -14
- package/src/layer/vector/Renderer.getRenderer.js +65 -43
- package/src/layer/vector/Renderer.js +24 -9
- package/src/layer/vector/SVG.js +29 -19
- package/src/map/Hash.js +255 -0
- package/src/map/Map.Rotation.js +927 -0
- package/src/map/Map.js +837 -392
- package/src/map/MapSync.js +225 -0
- package/src/map/handler/BoxZoomHandler.js +50 -12
- package/src/map/handler/DisplaceHandler.js +416 -0
- package/src/map/handler/DoubleClickZoomHandler.js +43 -22
- package/src/map/handler/DragHandler.js +64 -39
- package/src/map/handler/KeyboardHandler.js +94 -16
- package/src/map/handler/PinchZoomHandler.js +39 -18
- package/src/map/handler/ScrollWheelZoomHandler.js +204 -21
- package/src/map/handler/TapDragZoomHandler.js +209 -0
- package/src/map/handler/TapHoldHandler.js +36 -17
- package/src/map/index.js +4 -0
- package/src/maplair.css +629 -146
package/CHANGELOG.md
CHANGED
|
@@ -3,11 +3,71 @@ Maplair Changelog
|
|
|
3
3
|
|
|
4
4
|
(all changes of Leaflet without author notice are by [@mourner](https://github.com/mourner))
|
|
5
5
|
|
|
6
|
+
## 4.0.0-alpha.2 (2026-10-17)
|
|
7
|
+
|
|
8
|
+
For an overview and a migration guide from Leaflet 1.9.4, see the blog post: https://maplair.org/2026/10/17/maplair-4.0.0-alpha.2.html
|
|
9
|
+
|
|
10
|
+
(changes without author notice are by [@simon04](https://github.com/simon04))
|
|
11
|
+
|
|
12
|
+
#### ❇️ New Features
|
|
13
|
+
|
|
14
|
+
* Add `FullscreenControl` with `toggleFullscreen()`, `isFullscreen()` and the events `enterfullscreen`, `exitfullscreen` and `fullscreenchange`
|
|
15
|
+
* Add `SearchControl` with custom geocoders and `SearchControl.nominatim()`, complying with the Nominatim usage policy (`acceptUsagePolicy`)
|
|
16
|
+
* Add `ButtonControl`, `ButtonBarControl` and `TextControl`, and the Control option `order`
|
|
17
|
+
* Add `MiniMapControl` with an overview map
|
|
18
|
+
* Add `SideBySideControl` to compare layers with a divider
|
|
19
|
+
* Add `Classification` and `LegendControl` for classified features with a legend
|
|
20
|
+
* Add `ContextMenu` for menus on right click or long tap
|
|
21
|
+
* Add `Hash` to keep the view and the layers in the URL hash (also as geo URI) or in the query string
|
|
22
|
+
* Add `MapSync` to synchronize the views of several maps, with the options `oneWay` and `fit`
|
|
23
|
+
* Add `SvgIcon` for markers in any color with a glyph
|
|
24
|
+
* Add `HeatLayer` for heatmaps of points
|
|
25
|
+
* Add `DisplaceHandler` for the displacement of overlapping circle markers
|
|
26
|
+
* Add `TapDragZoomHandler` to zoom by double tapping and dragging up/down
|
|
27
|
+
* Add `LatLng.parse()` for coordinates in decimal degrees and geo URIs
|
|
28
|
+
* Map: add rotation with `bearing`, `setBearing()`, `pinchRotate` and `RotateControl` (optional module `maplair/map-rotation`)
|
|
29
|
+
* Marker: add the options `rotationAngle` and `rotationOrigin` (optional module `maplair/marker-rotation`)
|
|
30
|
+
* Animate markers along routes with `moveTo()`/`moveAlong()` (optional module `maplair/marker-movement`) and dashes along paths with `dashSpeed` (optional module `maplair/dash-animation`)
|
|
31
|
+
* Path: add `arrowheads` and `text` along lines (optional module `maplair/path-decorations`)
|
|
32
|
+
* GeoJSON: add `load()` and the option `url` (optional module `maplair/geojson-loading`)
|
|
33
|
+
* Path: add zoom-dependent `weight` and `radius` (optional module `maplair/zoom-styles`)
|
|
34
|
+
* Map: add the option `continuousZoom` for zooming through fractional zoom levels
|
|
35
|
+
* Map: add `setCrs()` to change the CRS at runtime
|
|
36
|
+
* Map: add the `idle` event, and `originalEvent` to view changes caused by the user
|
|
37
|
+
* Map: follow changes of the `devicePixelRatio` and fire `pixelratiochange`
|
|
38
|
+
* Map: keep the view of a hidden map
|
|
39
|
+
* ScrollWheelZoom: support touchpad gestures, and `scrollWheelZoom: 'trackpad'`
|
|
40
|
+
* DivOverlay: add the option `overflow` to let popups and tooltips extend beyond the map
|
|
41
|
+
* Tooltip: choose the auto direction by the available space
|
|
42
|
+
* Layer: add `setInteractive()`, `setAttribution()` and the option `attributionOrder`
|
|
43
|
+
* TileLayer: add the option `fetchOptions` to load tiles with `fetch()`, swap tiles without flickering on `setUrl()`, and add the option `placeholder`
|
|
44
|
+
* Add the option `pixelated` for nearest-neighbour scaling of tiles and image overlays
|
|
45
|
+
* WMSTileLayer: add `getLegendUrl()`
|
|
46
|
+
* Accessibility: map label (`ariaLabel`), keyboard shortcuts help (<kbd>?</kbd>), `<button>` elements in controls, popup focus
|
|
47
|
+
* Use CSS variables for the colors, borders, shadows, fonts and spacing
|
|
48
|
+
* Ship TypeScript type declarations (`dist/types/`)
|
|
49
|
+
|
|
50
|
+
#### 🐞 Bugfixes
|
|
51
|
+
|
|
52
|
+
* TileLayer: with `detectRetina`, no longer request tiles beyond `maxNativeZoom`
|
|
53
|
+
* Release the pointer capture only if it is still active
|
|
54
|
+
|
|
55
|
+
#### 📝 Docs
|
|
56
|
+
|
|
57
|
+
* Replace Leafdoc with JSDoc, and generate the API reference from the type declarations
|
|
58
|
+
* Explain the name Maplair, mention tree-shaking and update the bundle sizes on the homepage
|
|
59
|
+
|
|
60
|
+
#### 🔧 Workflow
|
|
61
|
+
|
|
62
|
+
* Migrate from npm to pnpm 12, upgrade Vite+ to 1.3.0 and Vitest to 5.0.5
|
|
63
|
+
* Check that optional features are dropped by tree-shaking unless imported (`pnpm run test:tree-shaking`)
|
|
64
|
+
* Type-check the type declarations and the debug pages (`pnpm run types:check`)
|
|
65
|
+
|
|
6
66
|
## 4.0.0-alpha.1 (2026-10-15) 🍁 Maplair, a fork of Leaflet
|
|
7
67
|
|
|
8
68
|
The first pre-release of Maplair, a fork of Leaflet. It contains all changes since Leaflet 1.9.4: those of Leaflet 2.0.0-alpha and 2.0.0-alpha.1 (see below), the unreleased changes of Leaflet until the fork, and Maplair's own changes.
|
|
9
69
|
|
|
10
|
-
For an overview and a migration guide from Leaflet 1.9.4, see the blog post: https://maplair.org/2026/10/
|
|
70
|
+
For an overview and a migration guide from Leaflet 1.9.4, see the blog post: https://maplair.org/2026/10/17/maplair-4.0.0-alpha.2.html
|
|
11
71
|
|
|
12
72
|
### Maplair
|
|
13
73
|
|
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Maplair is the leading open-source JavaScript library for **building powerful interactive maps**.
|
|
4
4
|
|
|
5
|
-
Weighing just about
|
|
5
|
+
Weighing just about 39 kB of gzipped JS plus 3.1 kB of gzipped CSS code, it has all the mapping [features][] most developers ever need.
|
|
6
|
+
And since Maplair supports tree-shaking, your bundler shakes off the leaves you don't use 🍁
|
|
7
|
+
(a map with just a tile layer comes out about a quarter smaller).
|
|
6
8
|
|
|
7
9
|
Maplair is designed with *simplicity*, *performance* and *usability* in mind.
|
|
8
10
|
It works efficiently across all major desktop and mobile platforms out of the box,
|
package/dist/esm/Maplair.js
CHANGED
|
@@ -8,64 +8,83 @@ import { DomUtil_exports } from "./dom/DomUtil.js";
|
|
|
8
8
|
import { Control } from "./control/Control.js";
|
|
9
9
|
import { I18n } from "./core/I18n.js";
|
|
10
10
|
import { AttributionControl } from "./control/AttributionControl.js";
|
|
11
|
-
import {
|
|
12
|
-
import { ScaleControl } from "./control/ScaleControl.js";
|
|
13
|
-
import { ZoomControl } from "./control/ZoomControl.js";
|
|
11
|
+
import { ButtonBarControl, ButtonControl } from "./control/ButtonControl.js";
|
|
14
12
|
import { Evented } from "./core/Events.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
13
|
+
import { Layer } from "./layer/Layer.js";
|
|
14
|
+
import { ContextMenu } from "./control/ContextMenu.js";
|
|
15
|
+
import { FullscreenControl } from "./control/FullscreenControl.js";
|
|
16
|
+
import { LayersControl } from "./control/LayersControl.js";
|
|
17
|
+
import { Path } from "./layer/vector/Path.js";
|
|
18
18
|
import { Bounds } from "./geometry/Bounds.js";
|
|
19
|
-
import { Transformation } from "./geometry/Transformation.js";
|
|
20
19
|
import { LatLngBounds } from "./geo/LatLngBounds.js";
|
|
21
20
|
import { CRS } from "./geo/crs/CRS.js";
|
|
22
21
|
import { EarthCRS } from "./geo/crs/EarthCRS.js";
|
|
23
22
|
import { LatLng } from "./geo/LatLng.js";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import { EPSG3395 } from "./geo/crs/EPSG3395.js";
|
|
23
|
+
import { CircleMarker } from "./layer/vector/CircleMarker.js";
|
|
24
|
+
import { LegendControl } from "./control/LegendControl.js";
|
|
25
|
+
import { Transformation } from "./geometry/Transformation.js";
|
|
28
26
|
import { EPSG3857, EPSG900913 } from "./geo/crs/EPSG3857.js";
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import { Layer } from "./layer/Layer.js";
|
|
27
|
+
import { PosAnimation } from "./dom/PosAnimation.js";
|
|
28
|
+
import { ZoomControl } from "./control/ZoomControl.js";
|
|
32
29
|
import { LayerGroup } from "./layer/LayerGroup.js";
|
|
33
30
|
import { FeatureGroup } from "./layer/FeatureGroup.js";
|
|
34
|
-
import { Icon } from "./layer/marker/Icon.js";
|
|
35
|
-
import { DefaultIcon } from "./layer/marker/DefaultIcon.js";
|
|
36
|
-
import { Marker } from "./layer/marker/Marker.js";
|
|
37
|
-
import { Path } from "./layer/vector/Path.js";
|
|
38
|
-
import { CircleMarker } from "./layer/vector/CircleMarker.js";
|
|
39
|
-
import { Circle } from "./layer/vector/Circle.js";
|
|
40
|
-
import { Polyline } from "./layer/vector/Polyline.js";
|
|
41
|
-
import { Polygon } from "./layer/vector/Polygon.js";
|
|
42
|
-
import { GeoJSON } from "./layer/GeoJSON.js";
|
|
43
|
-
import { BlanketOverlay } from "./layer/BlanketOverlay.js";
|
|
44
|
-
import { ImageOverlay } from "./layer/ImageOverlay.js";
|
|
45
|
-
import { VideoOverlay } from "./layer/VideoOverlay.js";
|
|
46
|
-
import { SVGOverlay } from "./layer/SVGOverlay.js";
|
|
47
31
|
import { DivOverlay } from "./layer/DivOverlay.js";
|
|
48
32
|
import { Popup } from "./layer/Popup.js";
|
|
49
33
|
import { Tooltip } from "./layer/Tooltip.js";
|
|
50
|
-
import {
|
|
51
|
-
import { GridLayer } from "./layer/tile/GridLayer.js";
|
|
52
|
-
import { TileLayer } from "./layer/tile/TileLayer.js";
|
|
53
|
-
import { WMSTileLayer } from "./layer/tile/WMSTileLayer.js";
|
|
34
|
+
import { BlanketOverlay } from "./layer/BlanketOverlay.js";
|
|
54
35
|
import { Renderer } from "./layer/vector/Renderer.js";
|
|
55
36
|
import { Canvas } from "./layer/vector/Canvas.js";
|
|
56
37
|
import { SVG } from "./layer/vector/SVG.js";
|
|
57
|
-
import {
|
|
38
|
+
import { Handler } from "./core/Handler.js";
|
|
58
39
|
import { BoxZoomHandler } from "./map/handler/BoxZoomHandler.js";
|
|
59
40
|
import { DoubleClickZoomHandler } from "./map/handler/DoubleClickZoomHandler.js";
|
|
41
|
+
import { Draggable } from "./dom/Draggable.js";
|
|
60
42
|
import { DragHandler } from "./map/handler/DragHandler.js";
|
|
61
43
|
import { KeyboardHandler } from "./map/handler/KeyboardHandler.js";
|
|
62
44
|
import { PinchZoomHandler } from "./map/handler/PinchZoomHandler.js";
|
|
63
45
|
import { ScrollWheelZoomHandler } from "./map/handler/ScrollWheelZoomHandler.js";
|
|
64
46
|
import { TapHoldHandler } from "./map/handler/TapHoldHandler.js";
|
|
47
|
+
import { TapDragZoomHandler } from "./map/handler/TapDragZoomHandler.js";
|
|
65
48
|
import { Map, MaplairMap } from "./map/Map.js";
|
|
49
|
+
import { PolyUtil_exports } from "./geometry/PolyUtil.js";
|
|
50
|
+
import { LineUtil_exports } from "./geometry/LineUtil.js";
|
|
51
|
+
import { Polyline } from "./layer/vector/Polyline.js";
|
|
52
|
+
import { Polygon } from "./layer/vector/Polygon.js";
|
|
53
|
+
import { MiniMapControl } from "./control/MiniMapControl.js";
|
|
54
|
+
import { ScaleControl } from "./control/ScaleControl.js";
|
|
55
|
+
import { Icon } from "./layer/marker/Icon.js";
|
|
56
|
+
import { DefaultIcon } from "./layer/marker/DefaultIcon.js";
|
|
57
|
+
import { Marker } from "./layer/marker/Marker.js";
|
|
58
|
+
import { SearchControl } from "./control/SearchControl.js";
|
|
59
|
+
import { SideBySideControl } from "./control/SideBySideControl.js";
|
|
60
|
+
import { TextControl } from "./control/TextControl.js";
|
|
61
|
+
import { projection_exports } from "./geo/projection/index.js";
|
|
62
|
+
import { EPSG3395 } from "./geo/crs/EPSG3395.js";
|
|
63
|
+
import { EPSG4326 } from "./geo/crs/EPSG4326.js";
|
|
64
|
+
import { SimpleCRS } from "./geo/crs/SimpleCRS.js";
|
|
65
|
+
import { Circle } from "./layer/vector/Circle.js";
|
|
66
|
+
import { GeoJSON } from "./layer/GeoJSON.js";
|
|
67
|
+
import { Classification } from "./layer/Classification.js";
|
|
68
|
+
import { HeatLayer } from "./layer/HeatLayer.js";
|
|
69
|
+
import { ImageOverlay } from "./layer/ImageOverlay.js";
|
|
70
|
+
import { VideoOverlay } from "./layer/VideoOverlay.js";
|
|
71
|
+
import { SVGOverlay } from "./layer/SVGOverlay.js";
|
|
72
|
+
import { DivIcon } from "./layer/marker/DivIcon.js";
|
|
73
|
+
import { SvgIcon } from "./layer/marker/SvgIcon.js";
|
|
74
|
+
import { GridLayer } from "./layer/tile/GridLayer.js";
|
|
75
|
+
import { TileLayer } from "./layer/tile/TileLayer.js";
|
|
76
|
+
import { WMSTileLayer } from "./layer/tile/WMSTileLayer.js";
|
|
77
|
+
import { Rectangle } from "./layer/vector/Rectangle.js";
|
|
78
|
+
import { Hash } from "./map/Hash.js";
|
|
79
|
+
import { MapSync } from "./map/MapSync.js";
|
|
80
|
+
import { DisplaceHandler, displace } from "./map/handler/DisplaceHandler.js";
|
|
66
81
|
//#region src/Maplair.js
|
|
82
|
+
/**
|
|
83
|
+
* A constant that represents the Maplair version in use.
|
|
84
|
+
* @type {string}
|
|
85
|
+
*/
|
|
67
86
|
const version = version$1;
|
|
68
87
|
//#endregion
|
|
69
|
-
export { AttributionControl, BlanketOverlay, Bounds, BoxZoomHandler, Browser_default as Browser, CRS, Canvas, Circle, CircleMarker, Class, Control, DefaultIcon, DivIcon, DivOverlay, DomEvent_exports as DomEvent, DomUtil_exports as DomUtil, DoubleClickZoomHandler, DragHandler, Draggable, EPSG3395, EPSG3857, EPSG4326, EPSG900913, EarthCRS, Evented, FeatureGroup, GeoJSON, GridLayer, Handler, I18n, Icon, ImageOverlay, KeyboardHandler, LatLng, LatLngBounds, Layer, LayerGroup, LayersControl, LineUtil_exports as LineUtil, Map, MaplairMap, Marker, Path, PinchZoomHandler, Point, PolyUtil_exports as PolyUtil, Polygon, Polyline, Popup, PosAnimation, projection_exports as Projection, Rectangle, Renderer, SVG, SVGOverlay, ScaleControl, ScrollWheelZoomHandler, SimpleCRS, TapHoldHandler, TileLayer, Tooltip, Transformation, Util_exports as Util, VideoOverlay, WMSTileLayer, ZoomControl, version };
|
|
88
|
+
export { AttributionControl, BlanketOverlay, Bounds, BoxZoomHandler, Browser_default as Browser, ButtonBarControl, ButtonControl, CRS, Canvas, Circle, CircleMarker, Class, Classification, ContextMenu, Control, DefaultIcon, DisplaceHandler, DivIcon, DivOverlay, DomEvent_exports as DomEvent, DomUtil_exports as DomUtil, DoubleClickZoomHandler, DragHandler, Draggable, EPSG3395, EPSG3857, EPSG4326, EPSG900913, EarthCRS, Evented, FeatureGroup, FullscreenControl, GeoJSON, GridLayer, Handler, Hash, HeatLayer, I18n, Icon, ImageOverlay, KeyboardHandler, LatLng, LatLngBounds, Layer, LayerGroup, LayersControl, LegendControl, LineUtil_exports as LineUtil, Map, MapSync, MaplairMap, Marker, MiniMapControl, Path, PinchZoomHandler, Point, PolyUtil_exports as PolyUtil, Polygon, Polyline, Popup, PosAnimation, projection_exports as Projection, Rectangle, Renderer, SVG, SVGOverlay, ScaleControl, ScrollWheelZoomHandler, SearchControl, SideBySideControl, SimpleCRS, SvgIcon, TapDragZoomHandler, TapHoldHandler, TextControl, TileLayer, Tooltip, Transformation, Util_exports as Util, VideoOverlay, WMSTileLayer, ZoomControl, displace, version };
|
|
70
89
|
|
|
71
90
|
//# sourceMappingURL=Maplair.js.map
|
package/dist/esm/Maplair.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Maplair.js","names":["pkg.version"],"sources":["../../src/Maplair.js"],"sourcesContent":["import pkg from '../package.json' with {type: 'json'};\nexport const version = pkg.version;\n\n// control\nexport * from './control/index.js';\n\n// core\nexport * from './core/index.js';\n\n// dom\nexport * from './dom/index.js';\n\n// geometry\nexport * from './geometry/index.js';\n\n// geo\nexport * from './geo/index.js';\n\n// layer\nexport * from './layer/index.js';\n\n// map\nexport * from './map/index.js';\n\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Maplair.js","names":["pkg.version"],"sources":["../../src/Maplair.js"],"sourcesContent":["import pkg from '../package.json' with {type: 'json'};\n/**\n * A constant that represents the Maplair version in use.\n * @type {string}\n */\nexport const version = pkg.version;\n\n// control\nexport * from './control/index.js';\n\n// core\nexport * from './core/index.js';\n\n// dom\nexport * from './dom/index.js';\n\n// geometry\nexport * from './geometry/index.js';\n\n// geo\nexport * from './geo/index.js';\n\n// layer\nexport * from './layer/index.js';\n\n// map\nexport * from './map/index.js';\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAa,UAAUA"}
|
|
@@ -3,7 +3,41 @@ import { create } from "../dom/DomUtil.js";
|
|
|
3
3
|
import { Control } from "./Control.js";
|
|
4
4
|
import { I18n } from "../core/I18n.js";
|
|
5
5
|
//#region src/control/AttributionControl.js
|
|
6
|
+
/** @import {ControlOptions} from './Control.js' */
|
|
7
|
+
/** @import {MaplairMap} from '../map/Map.js' */
|
|
6
8
|
const mapleLeaf = "<span aria-hidden=\"true\" class=\"maplair-attribution-leaf\">🍁</span>";
|
|
9
|
+
/**
|
|
10
|
+
* Options of `AttributionControl`.
|
|
11
|
+
* @typedef {object} AttributionControlOptions
|
|
12
|
+
* @property {string} [position='bottomright'] The position of the control (one of the
|
|
13
|
+
* map corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or
|
|
14
|
+
* `'bottomright'`.
|
|
15
|
+
* @property {string|false|null} [prefix=null] The HTML text shown before the
|
|
16
|
+
* attributions. Pass `false` to disable. By default (`null`), a link to Maplair.
|
|
17
|
+
* @extends ControlOptions
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Map options of `AttributionControl`.
|
|
21
|
+
* @typedef {object} AttributionControlMapOptions
|
|
22
|
+
* @lends MaplairMapOptions
|
|
23
|
+
* @property {boolean} [attributionControl=true] Whether a
|
|
24
|
+
* [attribution control](#control-attribution) is added to the map by default.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Properties of `MaplairMap` set by `AttributionControl`.
|
|
28
|
+
* @typedef {object} AttributionControlMapProperties
|
|
29
|
+
* @lends MaplairMap
|
|
30
|
+
* @property {AttributionControl} attributionControl The attribution control of the map,
|
|
31
|
+
* the default one (if the [`attributionControl` option](#map-attributioncontrol) was
|
|
32
|
+
* `true` when creating the map) or the one added last.
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* The attribution control allows you to display attribution data in a small text box
|
|
36
|
+
* on a map. It is put on the map by default unless you set its
|
|
37
|
+
* [`attributionControl` option](#map-attributioncontrol) to `false`, and it fetches
|
|
38
|
+
* attribution texts from layers with the [`getAttribution` method](#layer-getattribution)
|
|
39
|
+
* automatically.
|
|
40
|
+
*/
|
|
7
41
|
var AttributionControl = class AttributionControl extends Control {
|
|
8
42
|
static {
|
|
9
43
|
this.setDefaultOptions({
|
|
@@ -11,6 +45,10 @@ var AttributionControl = class AttributionControl extends Control {
|
|
|
11
45
|
prefix: null
|
|
12
46
|
});
|
|
13
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates an attribution control.
|
|
50
|
+
* @param {AttributionControlOptions} [options]
|
|
51
|
+
*/
|
|
14
52
|
constructor(options) {
|
|
15
53
|
super(options);
|
|
16
54
|
if (this.options.prefix === null) {
|
|
@@ -18,38 +56,67 @@ var AttributionControl = class AttributionControl extends Control {
|
|
|
18
56
|
this.options.prefix = `<a target="_blank" href="https://maplair.org" title="${title}">${mapleLeaf}Maplair</a>`;
|
|
19
57
|
}
|
|
20
58
|
this._attributions = {};
|
|
59
|
+
this._orders = {};
|
|
21
60
|
this.callInitHooks(AttributionControl);
|
|
22
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
* @param {MaplairMap} map
|
|
65
|
+
* @returns {HTMLElement}
|
|
66
|
+
*/
|
|
23
67
|
onAdd(map) {
|
|
24
68
|
map.attributionControl = this;
|
|
25
69
|
this._container = create("div", "maplair-control-attribution");
|
|
26
70
|
disableClickPropagation(this._container);
|
|
27
|
-
for (const layer of Object.values(map._layers)) if (layer.getAttribution) this.addAttribution(layer.getAttribution());
|
|
71
|
+
for (const layer of Object.values(map._layers)) if (layer.getAttribution) this.addAttribution(layer.getAttribution(), layer.options?.attributionOrder);
|
|
28
72
|
this._update();
|
|
29
73
|
map.on("layeradd", this._addAttribution, this);
|
|
30
74
|
return this._container;
|
|
31
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* @internal
|
|
78
|
+
* @param {MaplairMap} map
|
|
79
|
+
*/
|
|
32
80
|
onRemove(map) {
|
|
33
81
|
map.off("layeradd", this._addAttribution, this);
|
|
34
82
|
}
|
|
35
83
|
_addAttribution(ev) {
|
|
36
84
|
if (ev.layer.getAttribution) {
|
|
37
|
-
this.addAttribution(ev.layer.getAttribution());
|
|
85
|
+
this.addAttribution(ev.layer.getAttribution(), ev.layer.options?.attributionOrder);
|
|
38
86
|
ev.layer.once("remove", () => this.removeAttribution(ev.layer.getAttribution()));
|
|
39
87
|
}
|
|
40
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* The HTML text shown before the attributions. Pass `false` to disable.
|
|
91
|
+
* @param {string|false} prefix
|
|
92
|
+
* @returns {this}
|
|
93
|
+
*/
|
|
41
94
|
setPrefix(prefix) {
|
|
42
95
|
this.options.prefix = prefix;
|
|
43
96
|
this._update();
|
|
44
97
|
return this;
|
|
45
98
|
}
|
|
46
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Adds an attribution text (e.g. `'© OpenStreetMap contributors'`). Attributions
|
|
101
|
+
* are sorted by `order` (see the layer option `attributionOrder`), then by the order
|
|
102
|
+
* of adding.
|
|
103
|
+
* @param {string} text
|
|
104
|
+
* @param {number} [order=0]
|
|
105
|
+
* @returns {this}
|
|
106
|
+
*/
|
|
107
|
+
addAttribution(text, order = 0) {
|
|
47
108
|
if (!text) return this;
|
|
109
|
+
this._orders[text] = order;
|
|
48
110
|
if (!this._attributions[text]) this._attributions[text] = 0;
|
|
49
111
|
this._attributions[text]++;
|
|
50
112
|
this._update();
|
|
51
113
|
return this;
|
|
52
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Removes an attribution text.
|
|
117
|
+
* @param {string} text
|
|
118
|
+
* @returns {this}
|
|
119
|
+
*/
|
|
53
120
|
removeAttribution(text) {
|
|
54
121
|
if (!text) return this;
|
|
55
122
|
if (this._attributions[text]) {
|
|
@@ -60,12 +127,17 @@ var AttributionControl = class AttributionControl extends Control {
|
|
|
60
127
|
}
|
|
61
128
|
_update() {
|
|
62
129
|
if (!this._map) return;
|
|
63
|
-
const attribs = Object.keys(this._attributions).filter((i) => this._attributions[i]);
|
|
130
|
+
const attribs = Object.keys(this._attributions).filter((i) => this._attributions[i]).sort((a, b) => this._orders[a] - this._orders[b]);
|
|
64
131
|
const prefixAndAttribs = [];
|
|
65
132
|
if (this.options.prefix) prefixAndAttribs.push(this.options.prefix);
|
|
66
133
|
if (attribs.length) prefixAndAttribs.push(attribs.join(", "));
|
|
67
134
|
this._container.innerHTML = prefixAndAttribs.join(" <span aria-hidden=\"true\">|</span> ");
|
|
68
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Registers this default feature on the map class, called by `MaplairMap` itself.
|
|
138
|
+
* @internal
|
|
139
|
+
* @param {typeof MaplairMap} MaplairMap
|
|
140
|
+
*/
|
|
69
141
|
static register(MaplairMap) {
|
|
70
142
|
MaplairMap.mergeOptions({ attributionControl: true });
|
|
71
143
|
MaplairMap.addInitHook(function() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttributionControl.js","names":["DomUtil.create"],"sources":["../../../src/control/AttributionControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport {I18n} from '../core/I18n.js';\n\nconst mapleLeaf = '<span aria-hidden=\"true\" class=\"maplair-attribution-leaf\">🍁</span>';\n\n
|
|
1
|
+
{"version":3,"file":"AttributionControl.js","names":["DomUtil.create"],"sources":["../../../src/control/AttributionControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\nconst mapleLeaf = '<span aria-hidden=\"true\" class=\"maplair-attribution-leaf\">🍁</span>';\n\n/**\n * Options of `AttributionControl`.\n * @typedef {object} AttributionControlOptions\n * @property {string} [position='bottomright'] The position of the control (one of the\n * map corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {string|false|null} [prefix=null] The HTML text shown before the\n * attributions. Pass `false` to disable. By default (`null`), a link to Maplair.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `AttributionControl`.\n * @typedef {object} AttributionControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [attributionControl=true] Whether a\n * [attribution control](#control-attribution) is added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `AttributionControl`.\n * @typedef {object} AttributionControlMapProperties\n * @lends MaplairMap\n * @property {AttributionControl} attributionControl The attribution control of the map,\n * the default one (if the [`attributionControl` option](#map-attributioncontrol) was\n * `true` when creating the map) or the one added last.\n */\n\n/**\n * The attribution control allows you to display attribution data in a small text box\n * on a map. It is put on the map by default unless you set its\n * [`attributionControl` option](#map-attributioncontrol) to `false`, and it fetches\n * attribution texts from layers with the [`getAttribution` method](#layer-getattribution)\n * automatically.\n */\nexport class AttributionControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'bottomright',\n\t\t\tprefix: null\n\t\t});\n\t}\n\n\t/**\n\t * Creates an attribution control.\n\t * @param {AttributionControlOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper(options);\n\t\tif (this.options.prefix === null) {\n\t\t\tconst title = I18n.translate('A JavaScript library for interactive maps');\n\t\t\tthis.options.prefix = `<a target=\"_blank\" href=\"https://maplair.org\" title=\"${title}\">${mapleLeaf}Maplair</a>`;\n\t\t}\n\n\t\tthis._attributions = {};\n\t\tthis._orders = {};\n\n\t\tthis.callInitHooks(AttributionControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tmap.attributionControl = this;\n\t\tthis._container = DomUtil.create('div', 'maplair-control-attribution');\n\t\tDomEvent.disableClickPropagation(this._container);\n\n\t\t// TODO ugly, refactor\n\t\tfor (const layer of Object.values(map._layers)) {\n\t\t\tif (layer.getAttribution) {\n\t\t\t\tthis.addAttribution(layer.getAttribution(), layer.options?.attributionOrder);\n\t\t\t}\n\t\t}\n\n\t\tthis._update();\n\n\t\tmap.on('layeradd', this._addAttribution, this);\n\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('layeradd', this._addAttribution, this);\n\t}\n\n\t_addAttribution(ev) {\n\t\tif (ev.layer.getAttribution) {\n\t\t\tthis.addAttribution(ev.layer.getAttribution(), ev.layer.options?.attributionOrder);\n\t\t\tev.layer.once('remove', () => this.removeAttribution(ev.layer.getAttribution()));\n\t\t}\n\t}\n\n\t/**\n\t * The HTML text shown before the attributions. Pass `false` to disable.\n\t * @param {string|false} prefix\n\t * @returns {this}\n\t */\n\tsetPrefix(prefix) {\n\t\tthis.options.prefix = prefix;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an attribution text (e.g. `'© OpenStreetMap contributors'`). Attributions\n\t * are sorted by `order` (see the layer option `attributionOrder`), then by the order\n\t * of adding.\n\t * @param {string} text\n\t * @param {number} [order=0]\n\t * @returns {this}\n\t */\n\taddAttribution(text, order = 0) {\n\t\tif (!text) { return this; }\n\n\t\tthis._orders[text] = order;\n\t\tif (!this._attributions[text]) {\n\t\t\tthis._attributions[text] = 0;\n\t\t}\n\t\tthis._attributions[text]++;\n\n\t\tthis._update();\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes an attribution text.\n\t * @param {string} text\n\t * @returns {this}\n\t */\n\tremoveAttribution(text) {\n\t\tif (!text) { return this; }\n\n\t\tif (this._attributions[text]) {\n\t\t\tthis._attributions[text]--;\n\t\t\tthis._update();\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t_update() {\n\t\tif (!this._map) { return; }\n\n\t\tconst attribs = Object.keys(this._attributions).filter(i => this._attributions[i])\n\t\t\t.sort((a, b) => this._orders[a] - this._orders[b]);\n\n\t\tconst prefixAndAttribs = [];\n\n\t\tif (this.options.prefix) {\n\t\t\tprefixAndAttribs.push(this.options.prefix);\n\t\t}\n\t\tif (attribs.length) {\n\t\t\tprefixAndAttribs.push(attribs.join(', '));\n\t\t}\n\n\t\tthis._container.innerHTML = prefixAndAttribs.join(' <span aria-hidden=\"true\">|</span> ');\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\tattributionControl: true\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.attributionControl) {\n\t\t\t\tnew AttributionControl().addTo(this);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;AAQA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqClB,IAAa,qBAAb,MAAa,2BAA2B,QAAQ;CAE/C;EACC,KAAK,kBAAkB;GACtB,UAAU;GACV,QAAQ;EACT,CAAC;CACF;;;;;CAMA,YAAY,SAAS;EACpB,MAAM,OAAO;EACb,IAAI,KAAK,QAAQ,WAAW,MAAM;GACjC,MAAM,QAAQ,KAAK,UAAU,2CAA2C;GACxE,KAAK,QAAQ,SAAS,wDAAwD,MAAM,IAAI,UAAU;EACnG;EAEA,KAAK,gBAAgB,CAAC;EACtB,KAAK,UAAU,CAAC;EAEhB,KAAK,cAAc,kBAAkB;CACtC;;;;;;CAOA,MAAM,KAAK;EACV,IAAI,qBAAqB;EACzB,KAAK,aAAaA,OAAe,OAAO,6BAA6B;EACrE,wBAAiC,KAAK,UAAU;EAGhD,KAAK,MAAM,SAAS,OAAO,OAAO,IAAI,OAAO,GAC5C,IAAI,MAAM,gBACT,KAAK,eAAe,MAAM,eAAe,GAAG,MAAM,SAAS,gBAAgB;EAI7E,KAAK,QAAQ;EAEb,IAAI,GAAG,YAAY,KAAK,iBAAiB,IAAI;EAE7C,OAAO,KAAK;CACb;;;;;CAMA,SAAS,KAAK;EACb,IAAI,IAAI,YAAY,KAAK,iBAAiB,IAAI;CAC/C;CAEA,gBAAgB,IAAI;EACnB,IAAI,GAAG,MAAM,gBAAgB;GAC5B,KAAK,eAAe,GAAG,MAAM,eAAe,GAAG,GAAG,MAAM,SAAS,gBAAgB;GACjF,GAAG,MAAM,KAAK,gBAAgB,KAAK,kBAAkB,GAAG,MAAM,eAAe,CAAC,CAAC;EAChF;CACD;;;;;;CAOA,UAAU,QAAQ;EACjB,KAAK,QAAQ,SAAS;EACtB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;;;;;CAUA,eAAe,MAAM,QAAQ,GAAG;EAC/B,IAAI,CAAC,MAAQ,OAAO;EAEpB,KAAK,QAAQ,QAAQ;EACrB,IAAI,CAAC,KAAK,cAAc,OACvB,KAAK,cAAc,QAAQ;EAE5B,KAAK,cAAc,KAAK;EAExB,KAAK,QAAQ;EAEb,OAAO;CACR;;;;;;CAOA,kBAAkB,MAAM;EACvB,IAAI,CAAC,MAAQ,OAAO;EAEpB,IAAI,KAAK,cAAc,OAAO;GAC7B,KAAK,cAAc,KAAK;GACxB,KAAK,QAAQ;EACd;EAEA,OAAO;CACR;CAEA,UAAU;EACT,IAAI,CAAC,KAAK,MAAQ;EAElB,MAAM,UAAU,OAAO,KAAK,KAAK,aAAa,CAAC,CAAC,QAAO,MAAK,KAAK,cAAc,EAAE,CAAC,CAChF,MAAM,GAAG,MAAM,KAAK,QAAQ,KAAK,KAAK,QAAQ,EAAE;EAElD,MAAM,mBAAmB,CAAC;EAE1B,IAAI,KAAK,QAAQ,QAChB,iBAAiB,KAAK,KAAK,QAAQ,MAAM;EAE1C,IAAI,QAAQ,QACX,iBAAiB,KAAK,QAAQ,KAAK,IAAI,CAAC;EAGzC,KAAK,WAAW,YAAY,iBAAiB,KAAK,uCAAqC;CACxF;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,oBAAoB,KACrB,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,oBAChB,IAAI,mBAAmB,CAAC,CAAC,MAAM,IAAI;EAErC,CAAC;CACF;AACD"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { disableClickPropagation, on, stop } from "../dom/DomEvent.js";
|
|
2
|
+
import { create } from "../dom/DomUtil.js";
|
|
3
|
+
import { Control } from "./Control.js";
|
|
4
|
+
//#region src/control/ButtonControl.js
|
|
5
|
+
/** @import {ControlOptions} from './Control.js' */
|
|
6
|
+
/** @import {MaplairMap} from '../map/Map.js' */
|
|
7
|
+
/**
|
|
8
|
+
* A state of a `ButtonControl`, see its `states` option.
|
|
9
|
+
* @typedef {object} ButtonControlState
|
|
10
|
+
* @property {string} name The name of the state, see `setState()`.
|
|
11
|
+
* @property {string|HTMLElement} [content] The content of the button in this state.
|
|
12
|
+
* @property {string} [title] The title of the button in this state.
|
|
13
|
+
* @property {(this: ButtonControl, e: MouseEvent, button: ButtonControl, map: MaplairMap) => void} [onClick]
|
|
14
|
+
* Called when clicking the button in this state.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Options of `ButtonControl`.
|
|
18
|
+
* @typedef {object} ButtonControlOptions
|
|
19
|
+
* @property {string} [position='topleft'] The position of the control (one of the map
|
|
20
|
+
* corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or
|
|
21
|
+
* `'bottomright'`.
|
|
22
|
+
* @property {string|HTMLElement} [content=''] The content of the button: HTML (e.g. an
|
|
23
|
+
* icon or a character) or an element. String content is rendered as HTML; do not pass
|
|
24
|
+
* untrusted input.
|
|
25
|
+
* @property {string} [title=''] The title (tooltip) and accessible name of the button.
|
|
26
|
+
* @property {(this: ButtonControl, e: MouseEvent, button: ButtonControl, map: MaplairMap) => void} [onClick]
|
|
27
|
+
* Called with the click event, the `ButtonControl` and the map when clicking the button.
|
|
28
|
+
* @property {ButtonControlState[]} [states] Alternative states of the button, each an
|
|
29
|
+
* object with `name` and with `content`, `title` and `onClick` like the options. The
|
|
30
|
+
* first state is the initial one, `setState()` switches them.
|
|
31
|
+
* @property {string} [className=''] A custom CSS class name to assign to the button.
|
|
32
|
+
* @property {string} [accessKey=''] A key to activate the button with the browser's
|
|
33
|
+
* [access key](https://developer.mozilla.org/docs/Web/HTML/Reference/Global_attributes/accesskey)
|
|
34
|
+
* modifiers (e.g. Alt+Shift+K), shown in the title.
|
|
35
|
+
* @extends ControlOptions
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* A control with a button, styled like the zoom control, calling a function when
|
|
39
|
+
* clicked. It can have several states with their own content, title and function,
|
|
40
|
+
* e.g. to toggle something. Several buttons can be grouped with `ButtonBarControl`.
|
|
41
|
+
*
|
|
42
|
+
* Inspired by the [Leaflet.EasyButton](https://github.com/CliffCloud/Leaflet.EasyButton) plugin.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```js
|
|
46
|
+
* new ButtonControl({
|
|
47
|
+
* content: '⌂',
|
|
48
|
+
* title: 'Home',
|
|
49
|
+
* onClick: (e, button, map) => map.setView([47.27, 11.40], 13)
|
|
50
|
+
* }).addTo(map);
|
|
51
|
+
*
|
|
52
|
+
* new ButtonControl({
|
|
53
|
+
* states: [{
|
|
54
|
+
* name: 'show',
|
|
55
|
+
* content: '👁',
|
|
56
|
+
* title: 'Show the markers',
|
|
57
|
+
* onClick(e, button, map) { markers.addTo(map); button.setState('hide'); }
|
|
58
|
+
* }, {
|
|
59
|
+
* name: 'hide',
|
|
60
|
+
* content: '🙈',
|
|
61
|
+
* title: 'Hide the markers',
|
|
62
|
+
* onClick(e, button) { markers.remove(); button.setState('show'); }
|
|
63
|
+
* }]
|
|
64
|
+
* }).addTo(map);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
var ButtonControl = class ButtonControl extends Control {
|
|
68
|
+
static {
|
|
69
|
+
this.setDefaultOptions({
|
|
70
|
+
position: "topleft",
|
|
71
|
+
content: "",
|
|
72
|
+
title: "",
|
|
73
|
+
onClick: void 0,
|
|
74
|
+
states: void 0,
|
|
75
|
+
className: "",
|
|
76
|
+
accessKey: ""
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates a button control.
|
|
81
|
+
* @param {...ButtonControlOptions} args The options.
|
|
82
|
+
*/
|
|
83
|
+
constructor(...args) {
|
|
84
|
+
super(...args);
|
|
85
|
+
this._state = this.options.states?.[0];
|
|
86
|
+
this.callInitHooks(ButtonControl);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @internal
|
|
90
|
+
* @returns {HTMLElement}
|
|
91
|
+
*/
|
|
92
|
+
onAdd() {
|
|
93
|
+
const container = create("div", "maplair-bar maplair-control-button");
|
|
94
|
+
this._createButton(container);
|
|
95
|
+
return container;
|
|
96
|
+
}
|
|
97
|
+
_createButton(container) {
|
|
98
|
+
const button = this._button = create("button", `maplair-control-button-button ${this.options.className}`, container);
|
|
99
|
+
button.type = "button";
|
|
100
|
+
button.accessKey = this.options.accessKey;
|
|
101
|
+
disableClickPropagation(button);
|
|
102
|
+
on(button, "click", stop);
|
|
103
|
+
on(button, "click", this._onClick, this);
|
|
104
|
+
on(button, "click", this._refocusOnMap, this);
|
|
105
|
+
this._update();
|
|
106
|
+
return button;
|
|
107
|
+
}
|
|
108
|
+
_onClick(e) {
|
|
109
|
+
if (this._disabled) return;
|
|
110
|
+
(this._state ?? this.options).onClick?.call(this, e, this, this._map);
|
|
111
|
+
}
|
|
112
|
+
_update() {
|
|
113
|
+
if (!this._button) return;
|
|
114
|
+
const { content, title } = this._state ?? this.options, button = this._button;
|
|
115
|
+
if (typeof content === "string") button.innerHTML = content;
|
|
116
|
+
else button.replaceChildren(content);
|
|
117
|
+
const key = button.accessKeyLabel || this.options.accessKey.toUpperCase();
|
|
118
|
+
button.title = [title, key && `[${key}]`].filter(Boolean).join(" ");
|
|
119
|
+
button.setAttribute("aria-label", title ?? "");
|
|
120
|
+
if (this._state) button.dataset.state = this._state.name;
|
|
121
|
+
button.classList.toggle("maplair-disabled", !!this._disabled);
|
|
122
|
+
button.setAttribute("aria-disabled", !!this._disabled);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Switches to the state with the given `name`, see the `states` option.
|
|
126
|
+
* @param {string} name
|
|
127
|
+
* @returns {this}
|
|
128
|
+
*/
|
|
129
|
+
setState(name) {
|
|
130
|
+
const state = this.options.states?.find((s) => s.name === name);
|
|
131
|
+
if (!state) throw new Error(`Unknown button state "${name}".`);
|
|
132
|
+
this._state = state;
|
|
133
|
+
this._update();
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns the name of the current state, see the `states` option.
|
|
138
|
+
* @returns {string|undefined}
|
|
139
|
+
*/
|
|
140
|
+
getState() {
|
|
141
|
+
return this._state?.name;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Disables the button, so that clicking it does nothing.
|
|
145
|
+
* @returns {this}
|
|
146
|
+
*/
|
|
147
|
+
disable() {
|
|
148
|
+
this._disabled = true;
|
|
149
|
+
this._update();
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Enables the button again.
|
|
154
|
+
* @returns {this}
|
|
155
|
+
*/
|
|
156
|
+
enable() {
|
|
157
|
+
this._disabled = false;
|
|
158
|
+
this._update();
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns the button element.
|
|
163
|
+
* @returns {HTMLElement}
|
|
164
|
+
*/
|
|
165
|
+
getButton() {
|
|
166
|
+
return this._button;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Groups several `ButtonControl`s in one bar, like the buttons of the zoom control.
|
|
171
|
+
*
|
|
172
|
+
* Inspired by the [Leaflet.EasyButton](https://github.com/CliffCloud/Leaflet.EasyButton) plugin.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```js
|
|
176
|
+
* new ButtonBarControl([
|
|
177
|
+
* new ButtonControl({content: 'A', title: 'First', onClick: () => {}}),
|
|
178
|
+
* new ButtonControl({content: 'B', title: 'Second', onClick: () => {}})
|
|
179
|
+
* ]).addTo(map);
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
var ButtonBarControl = class ButtonBarControl extends Control {
|
|
183
|
+
/**
|
|
184
|
+
* Creates a bar with the given buttons.
|
|
185
|
+
* @param {ButtonControl[]} buttons
|
|
186
|
+
* @param {ControlOptions} [options]
|
|
187
|
+
*/
|
|
188
|
+
constructor(buttons, options) {
|
|
189
|
+
super(options);
|
|
190
|
+
this._buttons = buttons;
|
|
191
|
+
this.callInitHooks(ButtonBarControl);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* @internal
|
|
195
|
+
* @param {MaplairMap} map
|
|
196
|
+
* @returns {HTMLElement}
|
|
197
|
+
*/
|
|
198
|
+
onAdd(map) {
|
|
199
|
+
const container = create("div", "maplair-bar maplair-control-button-bar");
|
|
200
|
+
for (const button of this._buttons) {
|
|
201
|
+
button._map = map;
|
|
202
|
+
button._createButton(container);
|
|
203
|
+
}
|
|
204
|
+
return container;
|
|
205
|
+
}
|
|
206
|
+
/** @internal */
|
|
207
|
+
onRemove() {
|
|
208
|
+
for (const button of this._buttons) button._map = null;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Returns the buttons of the bar.
|
|
212
|
+
* @returns {ButtonControl[]}
|
|
213
|
+
*/
|
|
214
|
+
getButtons() {
|
|
215
|
+
return this._buttons;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
//#endregion
|
|
219
|
+
export { ButtonBarControl, ButtonControl };
|
|
220
|
+
|
|
221
|
+
//# sourceMappingURL=ButtonControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ButtonControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/ButtonControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * A state of a `ButtonControl`, see its `states` option.\n * @typedef {object} ButtonControlState\n * @property {string} name The name of the state, see `setState()`.\n * @property {string|HTMLElement} [content] The content of the button in this state.\n * @property {string} [title] The title of the button in this state.\n * @property {(this: ButtonControl, e: MouseEvent, button: ButtonControl, map: MaplairMap) => void} [onClick]\n * Called when clicking the button in this state.\n */\n\n/**\n * Options of `ButtonControl`.\n * @typedef {object} ButtonControlOptions\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|HTMLElement} [content=''] The content of the button: HTML (e.g. an\n * icon or a character) or an element. String content is rendered as HTML; do not pass\n * untrusted input.\n * @property {string} [title=''] The title (tooltip) and accessible name of the button.\n * @property {(this: ButtonControl, e: MouseEvent, button: ButtonControl, map: MaplairMap) => void} [onClick]\n * Called with the click event, the `ButtonControl` and the map when clicking the button.\n * @property {ButtonControlState[]} [states] Alternative states of the button, each an\n * object with `name` and with `content`, `title` and `onClick` like the options. The\n * first state is the initial one, `setState()` switches them.\n * @property {string} [className=''] A custom CSS class name to assign to the button.\n * @property {string} [accessKey=''] A key to activate the button with the browser's\n * [access key](https://developer.mozilla.org/docs/Web/HTML/Reference/Global_attributes/accesskey)\n * modifiers (e.g. Alt+Shift+K), shown in the title.\n * @extends ControlOptions\n */\n\n/**\n * A control with a button, styled like the zoom control, calling a function when\n * clicked. It can have several states with their own content, title and function,\n * e.g. to toggle something. Several buttons can be grouped with `ButtonBarControl`.\n *\n * Inspired by the [Leaflet.EasyButton](https://github.com/CliffCloud/Leaflet.EasyButton) plugin.\n *\n * @example\n * ```js\n * new ButtonControl({\n * \tcontent: '⌂',\n * \ttitle: 'Home',\n * \tonClick: (e, button, map) => map.setView([47.27, 11.40], 13)\n * }).addTo(map);\n *\n * new ButtonControl({\n * \tstates: [{\n * \t\tname: 'show',\n * \t\tcontent: '👁',\n * \t\ttitle: 'Show the markers',\n * \t\tonClick(e, button, map) { markers.addTo(map); button.setState('hide'); }\n * \t}, {\n * \t\tname: 'hide',\n * \t\tcontent: '🙈',\n * \t\ttitle: 'Hide the markers',\n * \t\tonClick(e, button) { markers.remove(); button.setState('show'); }\n * \t}]\n * }).addTo(map);\n * ```\n */\nexport class ButtonControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'topleft',\n\t\t\tcontent: '',\n\t\t\ttitle: '',\n\t\t\tonClick: undefined,\n\t\t\tstates: undefined,\n\t\t\tclassName: '',\n\t\t\taccessKey: ''\n\t\t});\n\t}\n\n\t/**\n\t * Creates a button control.\n\t * @param {...ButtonControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis._state = this.options.states?.[0];\n\t\tthis.callInitHooks(ButtonControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {HTMLElement}\n\t */\n\tonAdd() {\n\t\tconst container = DomUtil.create('div', 'maplair-bar maplair-control-button');\n\t\tthis._createButton(container);\n\t\treturn container;\n\t}\n\n\t// Creates the button element in `container`, see `ButtonBarControl`\n\t_createButton(container) {\n\t\tconst button = this._button = DomUtil.create('button', `maplair-control-button-button ${this.options.className}`, container);\n\t\tbutton.type = 'button';\n\t\tbutton.accessKey = this.options.accessKey;\n\n\t\tDomEvent.disableClickPropagation(button);\n\t\tDomEvent.on(button, 'click', DomEvent.stop);\n\t\tDomEvent.on(button, 'click', this._onClick, this);\n\t\tDomEvent.on(button, 'click', this._refocusOnMap, this);\n\n\t\tthis._update();\n\t\treturn button;\n\t}\n\n\t_onClick(e) {\n\t\tif (this._disabled) { return; }\n\t\t(this._state ?? this.options).onClick?.call(this, e, this, this._map);\n\t}\n\n\t_update() {\n\t\tif (!this._button) { return; }\n\t\tconst {content, title} = this._state ?? this.options,\n\t\tbutton = this._button;\n\n\t\tif (typeof content === 'string') {\n\t\t\tbutton.innerHTML = content;\n\t\t} else {\n\t\t\tbutton.replaceChildren(content);\n\t\t}\n\t\tconst key = button.accessKeyLabel || this.options.accessKey.toUpperCase();\n\t\tbutton.title = [title, key && `[${key}]`].filter(Boolean).join(' ');\n\t\tbutton.setAttribute('aria-label', title ?? '');\n\t\tif (this._state) {\n\t\t\tbutton.dataset.state = this._state.name;\n\t\t}\n\t\tbutton.classList.toggle('maplair-disabled', !!this._disabled);\n\t\tbutton.setAttribute('aria-disabled', !!this._disabled);\n\t}\n\n\t/**\n\t * Switches to the state with the given `name`, see the `states` option.\n\t * @param {string} name\n\t * @returns {this}\n\t */\n\tsetState(name) {\n\t\tconst state = this.options.states?.find(s => s.name === name);\n\t\tif (!state) {\n\t\t\tthrow new Error(`Unknown button state \"${name}\".`);\n\t\t}\n\t\tthis._state = state;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the name of the current state, see the `states` option.\n\t * @returns {string|undefined}\n\t */\n\tgetState() {\n\t\treturn this._state?.name;\n\t}\n\n\t/**\n\t * Disables the button, so that clicking it does nothing.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tthis._disabled = true;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Enables the button again.\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tthis._disabled = false;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the button element.\n\t * @returns {HTMLElement}\n\t */\n\tgetButton() {\n\t\treturn this._button;\n\t}\n}\n\n/**\n * Groups several `ButtonControl`s in one bar, like the buttons of the zoom control.\n *\n * Inspired by the [Leaflet.EasyButton](https://github.com/CliffCloud/Leaflet.EasyButton) plugin.\n *\n * @example\n * ```js\n * new ButtonBarControl([\n * \tnew ButtonControl({content: 'A', title: 'First', onClick: () => {}}),\n * \tnew ButtonControl({content: 'B', title: 'Second', onClick: () => {}})\n * ]).addTo(map);\n * ```\n */\nexport class ButtonBarControl extends Control {\n\t/**\n\t * Creates a bar with the given buttons.\n\t * @param {ButtonControl[]} buttons\n\t * @param {ControlOptions} [options]\n\t */\n\tconstructor(buttons, options) {\n\t\tsuper(options);\n\t\tthis._buttons = buttons;\n\t\tthis.callInitHooks(ButtonBarControl);\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-button-bar');\n\t\tfor (const button of this._buttons) {\n\t\t\tbutton._map = map;\n\t\t\tbutton._createButton(container);\n\t\t}\n\t\treturn container;\n\t}\n\n\t/** @internal */\n\tonRemove() {\n\t\tfor (const button of this._buttons) {\n\t\t\tbutton._map = null;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the buttons of the bar.\n\t * @returns {ButtonControl[]}\n\t */\n\tgetButtons() {\n\t\treturn this._buttons;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C;EACC,KAAK,kBAAkB;GACtB,UAAU;GACV,SAAS;GACT,OAAO;GACP,SAAS,KAAA;GACT,QAAQ,KAAA;GACR,WAAW;GACX,WAAW;EACZ,CAAC;CACF;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,SAAS,KAAK,QAAQ,SAAS;EACpC,KAAK,cAAc,aAAa;CACjC;;;;;CAMA,QAAQ;EACP,MAAM,YAAYA,OAAe,OAAO,oCAAoC;EAC5E,KAAK,cAAc,SAAS;EAC5B,OAAO;CACR;CAGA,cAAc,WAAW;EACxB,MAAM,SAAS,KAAK,UAAUA,OAAe,UAAU,iCAAiC,KAAK,QAAQ,aAAa,SAAS;EAC3H,OAAO,OAAO;EACd,OAAO,YAAY,KAAK,QAAQ;EAEhC,wBAAiC,MAAM;EACvC,GAAY,QAAQ,SAASC,IAAa;EAC1C,GAAY,QAAQ,SAAS,KAAK,UAAU,IAAI;EAChD,GAAY,QAAQ,SAAS,KAAK,eAAe,IAAI;EAErD,KAAK,QAAQ;EACb,OAAO;CACR;CAEA,SAAS,GAAG;EACX,IAAI,KAAK,WAAa;EACtB,CAAC,KAAK,UAAU,KAAK,QAAA,CAAS,SAAS,KAAK,MAAM,GAAG,MAAM,KAAK,IAAI;CACrE;CAEA,UAAU;EACT,IAAI,CAAC,KAAK,SAAW;EACrB,MAAM,EAAC,SAAS,UAAS,KAAK,UAAU,KAAK,SAC7C,SAAS,KAAK;EAEd,IAAI,OAAO,YAAY,UACtB,OAAO,YAAY;OAEnB,OAAO,gBAAgB,OAAO;EAE/B,MAAM,MAAM,OAAO,kBAAkB,KAAK,QAAQ,UAAU,YAAY;EACxE,OAAO,QAAQ,CAAC,OAAO,OAAO,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;EAClE,OAAO,aAAa,cAAc,SAAS,EAAE;EAC7C,IAAI,KAAK,QACR,OAAO,QAAQ,QAAQ,KAAK,OAAO;EAEpC,OAAO,UAAU,OAAO,oBAAoB,CAAC,CAAC,KAAK,SAAS;EAC5D,OAAO,aAAa,iBAAiB,CAAC,CAAC,KAAK,SAAS;CACtD;;;;;;CAOA,SAAS,MAAM;EACd,MAAM,QAAQ,KAAK,QAAQ,QAAQ,MAAK,MAAK,EAAE,SAAS,IAAI;EAC5D,IAAI,CAAC,OACJ,MAAM,IAAI,MAAM,yBAAyB,KAAK,GAAG;EAElD,KAAK,SAAS;EACd,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,WAAW;EACV,OAAO,KAAK,QAAQ;CACrB;;;;;CAMA,UAAU;EACT,KAAK,YAAY;EACjB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,SAAS;EACR,KAAK,YAAY;EACjB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,YAAY;EACX,OAAO,KAAK;CACb;AACD;;;;;;;;;;;;;;AAeA,IAAa,mBAAb,MAAa,yBAAyB,QAAQ;;;;;;CAM7C,YAAY,SAAS,SAAS;EAC7B,MAAM,OAAO;EACb,KAAK,WAAW;EAChB,KAAK,cAAc,gBAAgB;CACpC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAYD,OAAe,OAAO,wCAAwC;EAChF,KAAK,MAAM,UAAU,KAAK,UAAU;GACnC,OAAO,OAAO;GACd,OAAO,cAAc,SAAS;EAC/B;EACA,OAAO;CACR;;CAGA,WAAW;EACV,KAAK,MAAM,UAAU,KAAK,UACzB,OAAO,OAAO;CAEhB;;;;;CAMA,aAAa;EACZ,OAAO,KAAK;CACb;AACD"}
|