maplair 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +118 -0
- package/dist/esm/Maplair.js +14 -14
- package/dist/esm/control/AttributionControl.js +24 -14
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +9 -11
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -3
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +9 -16
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +5 -7
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +144 -35
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +7 -9
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +14 -16
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +1 -3
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -9
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +99 -17
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +1 -3
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +5 -7
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +408 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +5 -7
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -37
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +21 -8
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +13 -11
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/Util.js +13 -1
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +8 -42
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +14 -68
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +17 -18
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +3 -25
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +15 -5
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3395.js +1 -1
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +1 -1
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +1 -1
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +2 -2
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +36 -30
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +8 -27
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +6 -8
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +15 -20
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/GeoJSON.js +9 -145
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +75 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +15 -17
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +20 -26
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +8 -10
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +51 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +26 -42
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +2 -5
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +15 -17
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +12 -15
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +15 -48
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +7 -9
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +7 -10
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +1 -2
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +61 -33
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +6 -8
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +85 -97
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +28 -36
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +1 -3
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +2 -2
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +17 -7
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +27 -20
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +20 -4
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
- package/dist/esm/layer/vector/Polyline.js +23 -7
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +5 -5
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +10 -6
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +116 -110
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +6 -8
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +19 -19
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +35 -35
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +12 -5
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +8009 -7369
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +10040 -9381
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +148 -98
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/cs.json +6 -0
- package/i18n/de.json +6 -0
- package/i18n/en.json +6 -0
- package/i18n/es.json +6 -0
- package/i18n/fr.json +6 -0
- package/i18n/hu.json +6 -0
- package/i18n/it.json +6 -0
- package/i18n/rm.json +6 -0
- package/i18n/sk.json +6 -0
- package/i18n/sl.json +6 -0
- package/package.json +9 -11
- package/src/control/AttributionControl.js +25 -18
- package/src/control/ButtonControl.js +9 -11
- package/src/control/ContextMenu.js +3 -5
- package/src/control/Control.js +9 -19
- package/src/control/FullscreenControl.js +5 -7
- package/src/control/LayersControl.js +159 -36
- package/src/control/LegendControl.js +7 -9
- package/src/control/MiniMapControl.js +9 -11
- package/src/control/RotateControl.js +3 -5
- package/src/control/ScaleControl.js +7 -9
- package/src/control/SearchControl.js +102 -19
- package/src/control/SideBySideControl.js +3 -5
- package/src/control/TextControl.js +5 -7
- package/src/control/TimeControl.js +471 -0
- package/src/control/ZoomControl.js +5 -7
- package/src/control/index.js +1 -0
- package/src/core/Class.js +35 -34
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +14 -12
- package/src/core/Util.js +19 -1
- package/src/core/index.js +0 -1
- package/src/dom/DomEvent.DoubleTap.js +18 -10
- package/src/dom/DomEvent.PointerEvents.js +3 -26
- package/src/dom/DomEvent.js +8 -66
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +27 -22
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +20 -3
- package/src/geo/crs/EPSG3395.js +1 -1
- package/src/geo/crs/EPSG3857.js +1 -1
- package/src/geo/crs/EPSG4326.js +1 -1
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +1 -1
- package/src/geo/projection/Projection.LonLat.js +1 -1
- package/src/geo/projection/Projection.Mercator.js +1 -1
- package/src/geo/projection/Projection.SphericalMercator.js +1 -1
- package/src/geometry/LineUtil.js +47 -48
- package/src/geometry/PolyUtil.js +14 -43
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +15 -26
- package/src/layer/GeoJSON.js +7 -205
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +9 -11
- package/src/layer/ImageOverlay.js +19 -30
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +71 -0
- package/src/layer/Popup.js +28 -43
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +15 -19
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +15 -61
- package/src/layer/marker/DivIcon.js +9 -11
- package/src/layer/marker/Icon.js +7 -10
- package/src/layer/marker/Marker.Drag.js +1 -1
- package/src/layer/marker/Marker.Move.js +1 -2
- package/src/layer/marker/Marker.js +81 -39
- package/src/layer/marker/MarkerClusterGroup.js +370 -0
- package/src/layer/marker/SvgIcon.js +7 -9
- package/src/layer/marker/index.js +1 -0
- package/src/layer/tile/GridLayer.js +103 -133
- package/src/layer/tile/TileLayer.js +35 -43
- package/src/layer/tile/WMSTileLayer.js +26 -24
- package/src/layer/vector/Canvas.js +3 -5
- package/src/layer/vector/Circle.js +5 -2
- package/src/layer/vector/CircleMarker.js +17 -6
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +28 -5
- package/src/layer/vector/Polyline.js +25 -6
- package/src/layer/vector/Renderer.getRenderer.js +17 -17
- package/src/layer/vector/SVG.js +5 -5
- package/src/map/Map.Rotation.js +12 -4
- package/src/map/Map.js +142 -133
- package/src/map/handler/BoxZoomHandler.js +9 -8
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +25 -28
- package/src/map/handler/KeyboardHandler.js +42 -48
- package/src/map/handler/PinchZoomHandler.js +16 -5
- package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
- package/src/map/handler/TapHoldHandler.js +15 -4
- package/src/map/index.js +1 -1
- package/src/maplair.css +148 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/images/layers.svg +0 -1
- package/dist/images/marker-icon.svg +0 -1
- package/dist/images/marker-shadow.svg +0 -1
- package/src/core/Browser.js +0 -110
- package/src/images/layers.svg +0 -1
- package/src/images/marker-icon.svg +0 -1
- package/src/images/marker-shadow.svg +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FullscreenControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/FullscreenControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n\nconst enterIcon = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"currentColor\"><path d=\"M2 2h5v2H4v3H2zm7 0h5v5h-2V4H9zM2 9h2v3h3v2H2zm10 0h2v5H9v-2h3z\"/></svg>';\nconst exitIcon = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"currentColor\"><path d=\"M5 2h2v5H2V5h3zm4 0h2v3h3v2H9zM2 9h5v5H5v-3H2zm7 0h5v2h-3v3H9z\"/></svg>';\n\n/**\n * Options of `FullscreenControl`.\n * @typedef {object} FullscreenControlOptions\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} [enterText] The HTML content of the button while the map is not in\n * fullscreen, by default an expand icon.\n * @property {string} [exitText] The HTML content of the button while the map is in\n * fullscreen, by default a collapse icon.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `FullscreenControl`.\n * @typedef {object} FullscreenControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [fullscreenControl=false] Whether a\n * [fullscreen control](#fullscreencontrol) is added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `FullscreenControl`.\n * @typedef {object} FullscreenControlMapProperties\n * @lends MaplairMap\n * @property {FullscreenControl} fullscreenControl The default fullscreen control (only\n * available if the [`fullscreenControl` option](#map-fullscreencontrol) was `true` when\n * creating the map).\n */\n\n/**\n * Methods of `MaplairMap` for the fullscreen view.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#enterfullscreen {MaplairEvent} Fired when the map enters fullscreen.\n * @fires MaplairMap#exitfullscreen {MaplairEvent} Fired when the map exits fullscreen.\n * @fires MaplairMap#fullscreenchange {MaplairEvent} Fired when the map enters or exits\n * fullscreen.\n */\nconst mapFullscreenMethods = {\n\t/**\n\t * Enters or exits the fullscreen view of the map, see `FullscreenControl`.\n\t * Browsers allow entering fullscreen only in response to a user interaction,\n\t * e.g. a click.\n\t * @group Methods for modifying map state\n\t * @returns {this}\n\t */\n\ttoggleFullscreen() {\n\t\tconst container = this._container;\n\n\t\tif (this._fullscreen === 'pseudo') {\n\t\t\tthis._setFullscreen(false);\n\t\t} else if (this._fullscreen) {\n\t\t\tdocument.exitFullscreen();\n\t\t} else if (document.fullscreenEnabled && container.requestFullscreen) {\n\t\t\tDomEvent.on(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\tcontainer.requestFullscreen().catch(() => {\n\t\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\t\tthis._setFullscreen('pseudo');\n\t\t\t});\n\t\t} else {\n\t\t\tthis._setFullscreen('pseudo');\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the map is viewed in fullscreen.\n\t * @group Other methods\n\t * @returns {boolean}\n\t */\n\tisFullscreen() {\n\t\treturn !!this._fullscreen;\n\t},\n\n\t_onFullscreenChange() {\n\t\tconst fullscreen = document.fullscreenElement === this._container;\n\t\tif (!fullscreen) {\n\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t}\n\t\tif (fullscreen !== this.isFullscreen()) {\n\t\t\tthis._setFullscreen(fullscreen && 'native');\n\t\t}\n\t},\n\n\t_onFullscreenKeyDown(e) {\n\t\tif (e.key === 'Escape') {\n\t\t\tthis._setFullscreen(false);\n\t\t}\n\t},\n\n\t// `mode` is `'native'` (Fullscreen API), `'pseudo'` (CSS) or `false`\n\t_setFullscreen(mode) {\n\t\tconst container = this._container;\n\t\tthis._fullscreen = mode;\n\n\t\tcontainer.classList.toggle('maplair-fullscreen', !!mode);\n\t\tcontainer.classList.toggle('maplair-pseudo-fullscreen', mode === 'pseudo');\n\t\tif (mode === 'pseudo') {\n\t\t\tDomEvent.on(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t} else {\n\t\t\tDomEvent.off(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t}\n\n\t\tthis.invalidateSize();\n\n\t\tthis.fire(mode ? 'enterfullscreen' : 'exitfullscreen');\n\t\tthis.fire('fullscreenchange');\n\t}\n};\n/** @typedef {typeof mapFullscreenMethods} MapFullscreenMethods */\n\n/**\n * A control with a button to view the map in fullscreen and to exit it again. It is\n * put on the map if you set its [`fullscreenControl` option](#map-fullscreencontrol)\n * to `true`. Where the browser does not support the\n * [Fullscreen API](https://developer.mozilla.org/docs/Web/API/Fullscreen_API)\n * (e.g. Safari on iPhone) or refuses fullscreen (e.g. in an iframe without\n * `allow=\"fullscreen\"`), the map is enlarged to the size of the window instead.\n *\n * @example\n * ```js\n * new FullscreenControl({position: 'topright'}).addTo(map);\n * ```\n */\nexport class FullscreenControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'topleft',\n\t\t\tenterText: enterIcon,\n\t\t\texitText: exitIcon\n\t\t});\n\t}\n\n\t/**\n\t * Creates a fullscreen control.\n\t * @param {...FullscreenControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(FullscreenControl);\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-control-fullscreen maplair-bar'),\n\t\tbutton = this._button = DomUtil.create('button', 'maplair-control-fullscreen-button', container);\n\t\tbutton.type = 'button';\n\n\t\tDomEvent.disableClickPropagation(button);\n\t\tDomEvent.on(button, 'click', DomEvent.stop);\n\t\tDomEvent.on(button, 'click', this._toggleFullscreen, this);\n\t\tDomEvent.on(button, 'click', this._refocusOnMap, this);\n\n\t\tthis._update();\n\t\tmap.on('fullscreenchange', this._update, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('fullscreenchange', this._update, this);\n\t}\n\n\t_toggleFullscreen() {\n\t\tthis._map.toggleFullscreen();\n\t}\n\n\t_update() {\n\t\tconst fullscreen = this._map.isFullscreen(),\n\t\ttitle = fullscreen ? I18n.translate('Exit fullscreen') : I18n.translate('View fullscreen');\n\n\t\tthis._button.innerHTML = fullscreen ? this.options.exitText : this.options.enterText;\n\t\tthis._button.title = title;\n\t\tthis._button.setAttribute('aria-label', title);\n\t\tthis._button.setAttribute('aria-pressed', fullscreen);\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\tfullscreenControl: false\n\t\t});\n\n\t\tMaplairMap.include(mapFullscreenMethods);\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tthis.on('unload', function () {\n\t\t\t\tif (this._fullscreen === 'native') {\n\t\t\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\t\t\tdocument.exitFullscreen();\n\t\t\t\t}\n\t\t\t\tthis._container.classList.remove('maplair-fullscreen', 'maplair-pseudo-fullscreen');\n\t\t\t\tDomEvent.off(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t\t\tthis._fullscreen = false;\n\t\t\t});\n\n\t\t\tif (this.options.fullscreenControl) {\n\t\t\t\tthis.fullscreenControl = new FullscreenControl();\n\t\t\t\tthis.addControl(this.fullscreenControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,YAAY;AAClB,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCjB,MAAM,uBAAuB;;;;;;;;CAQ5B,mBAAmB;EAClB,MAAM,YAAY,KAAK;EAEvB,IAAI,KAAK,gBAAgB,UACxB,KAAK,eAAe,KAAK;OACnB,IAAI,KAAK,aACf,SAAS,eAAe;OAClB,IAAI,SAAS,qBAAqB,UAAU,mBAAmB;GACrE,GAAY,UAAU,oBAAoB,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ourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n\nconst enterIcon = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"currentColor\"><path d=\"M2 2h5v2H4v3H2zm7 0h5v5h-2V4H9zM2 9h2v3h3v2H2zm10 0h2v5H9v-2h3z\"/></svg>';\nconst exitIcon = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"currentColor\"><path d=\"M5 2h2v5H2V5h3zm4 0h2v3h3v2H9zM2 9h5v5H5v-3H2zm7 0h5v2h-3v3H9z\"/></svg>';\n\n/**\n * Options of `FullscreenControl`.\n * @typedef {object} FullscreenControlOptions\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} [enterText] The HTML content of the button while the map is not in\n * fullscreen, by default an expand icon.\n * @property {string} [exitText] The HTML content of the button while the map is in\n * fullscreen, by default a collapse icon.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `FullscreenControl`.\n * @typedef {object} FullscreenControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [fullscreenControl=false] Whether a\n * [fullscreen control](#fullscreencontrol) is added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `FullscreenControl`.\n * @typedef {object} FullscreenControlMapProperties\n * @lends MaplairMap\n * @property {FullscreenControl} fullscreenControl The default fullscreen control (only\n * available if the [`fullscreenControl` option](#map-fullscreencontrol) was `true` when\n * creating the map).\n */\n\n/**\n * Methods of `MaplairMap` for the fullscreen view.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#enterfullscreen {MaplairEvent} Fired when the map enters fullscreen.\n * @fires MaplairMap#exitfullscreen {MaplairEvent} Fired when the map exits fullscreen.\n * @fires MaplairMap#fullscreenchange {MaplairEvent} Fired when the map enters or exits\n * fullscreen.\n */\nconst mapFullscreenMethods = {\n\t/**\n\t * Enters or exits the fullscreen view of the map, see `FullscreenControl`.\n\t * Browsers allow entering fullscreen only in response to a user interaction,\n\t * e.g. a click.\n\t * @group Methods for modifying map state\n\t * @returns {this}\n\t */\n\ttoggleFullscreen() {\n\t\tconst container = this._container;\n\n\t\tif (this._fullscreen === 'pseudo') {\n\t\t\tthis._setFullscreen(false);\n\t\t} else if (this._fullscreen) {\n\t\t\tdocument.exitFullscreen();\n\t\t} else if (document.fullscreenEnabled && container.requestFullscreen) {\n\t\t\tDomEvent.on(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\tcontainer.requestFullscreen().catch(() => {\n\t\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\t\tthis._setFullscreen('pseudo');\n\t\t\t});\n\t\t} else {\n\t\t\tthis._setFullscreen('pseudo');\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the map is viewed in fullscreen.\n\t * @group Other methods\n\t * @returns {boolean}\n\t */\n\tisFullscreen() {\n\t\treturn !!this._fullscreen;\n\t},\n\n\t_onFullscreenChange() {\n\t\tconst fullscreen = document.fullscreenElement === this._container;\n\t\tif (!fullscreen) {\n\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t}\n\t\tif (fullscreen !== this.isFullscreen()) {\n\t\t\tthis._setFullscreen(fullscreen && 'native');\n\t\t}\n\t},\n\n\t_onFullscreenKeyDown(e) {\n\t\tif (e.key === 'Escape') {\n\t\t\tthis._setFullscreen(false);\n\t\t}\n\t},\n\n\t// `mode` is `'native'` (Fullscreen API), `'pseudo'` (CSS) or `false`\n\t_setFullscreen(mode) {\n\t\tconst container = this._container;\n\t\tthis._fullscreen = mode;\n\n\t\tcontainer.classList.toggle('maplair-fullscreen', !!mode);\n\t\tcontainer.classList.toggle('maplair-pseudo-fullscreen', mode === 'pseudo');\n\t\tif (mode === 'pseudo') {\n\t\t\tDomEvent.on(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t} else {\n\t\t\tDomEvent.off(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t}\n\n\t\tthis.invalidateSize();\n\n\t\tthis.fire(mode ? 'enterfullscreen' : 'exitfullscreen');\n\t\tthis.fire('fullscreenchange');\n\t}\n};\n/** @typedef {typeof mapFullscreenMethods} MapFullscreenMethods */\n\n/**\n * A control with a button to view the map in fullscreen and to exit it again. It is\n * put on the map if you set its [`fullscreenControl` option](#map-fullscreencontrol)\n * to `true`. Where the browser does not support the\n * [Fullscreen API](https://developer.mozilla.org/docs/Web/API/Fullscreen_API)\n * (e.g. Safari on iPhone) or refuses fullscreen (e.g. in an iframe without\n * `allow=\"fullscreen\"`), the map is enlarged to the size of the window instead.\n *\n * @example\n * ```js\n * new FullscreenControl({position: 'topright'}).addTo(map);\n * ```\n */\nexport class FullscreenControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tenterText: enterIcon,\n\t\texitText: exitIcon\n\t};\n\n\t/**\n\t * Creates a fullscreen control.\n\t * @param {...FullscreenControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(FullscreenControl);\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-control-fullscreen maplair-bar'),\n\t\tbutton = this._button = DomUtil.create('button', 'maplair-control-fullscreen-button', container);\n\t\tbutton.type = 'button';\n\n\t\tDomEvent.disableClickPropagation(button);\n\t\tDomEvent.on(button, 'click', DomEvent.stop);\n\t\tDomEvent.on(button, 'click', this._toggleFullscreen, this);\n\t\tDomEvent.on(button, 'click', this._refocusOnMap, this);\n\n\t\tthis._update();\n\t\tmap.on('fullscreenchange', this._update, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('fullscreenchange', this._update, this);\n\t}\n\n\t_toggleFullscreen() {\n\t\tthis._map.toggleFullscreen();\n\t}\n\n\t_update() {\n\t\tconst fullscreen = this._map.isFullscreen(),\n\t\ttitle = fullscreen ? I18n.translate('Exit fullscreen') : I18n.translate('View fullscreen');\n\n\t\tthis._button.innerHTML = fullscreen ? this.options.exitText : this.options.enterText;\n\t\tthis._button.title = title;\n\t\tthis._button.setAttribute('aria-label', title);\n\t\tthis._button.setAttribute('aria-pressed', fullscreen);\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\tfullscreenControl: false\n\t\t});\n\n\t\tMaplairMap.include(mapFullscreenMethods);\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tthis.on('unload', function () {\n\t\t\t\tif (this._fullscreen === 'native') {\n\t\t\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\t\t\tdocument.exitFullscreen();\n\t\t\t\t}\n\t\t\t\tthis._container.classList.remove('maplair-fullscreen', 'maplair-pseudo-fullscreen');\n\t\t\t\tDomEvent.off(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t\t\tthis._fullscreen = false;\n\t\t\t});\n\n\t\t\tif (this.options.fullscreenControl) {\n\t\t\t\tthis.fullscreenControl = new FullscreenControl();\n\t\t\t\tthis.addControl(this.fullscreenControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,YAAY;AAClB,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCjB,MAAM,uBAAuB;;;;;;;;CAQ5B,mBAAmB;EAClB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kB;IAC/C,KAAK,WAAW,KAAK,iBAAiB;GACvC;EACD,CAAC;CACF;AACD"}
|
|
@@ -9,10 +9,40 @@ 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
|
+
* An entry of `LayersControl`, as returned by `getLayers()`.
|
|
13
|
+
* @typedef {object} LayersControlEntry
|
|
14
|
+
* @property {Layer} layer The layer.
|
|
15
|
+
* @property {string} name The name of the layer, as given to the control.
|
|
16
|
+
* @property {boolean} overlay Whether the layer is an overlay (checkbox) or a base layer
|
|
17
|
+
* (radio button).
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The group of an entry of `LayersControl`, as returned by the option `groupBy`.
|
|
21
|
+
* @typedef {object} LayersControlGroup
|
|
22
|
+
* @property {string} group The name of the group, rendered as text.
|
|
23
|
+
* @property {string} label The label of the entry within the group, may contain HTML
|
|
24
|
+
* (like layer names).
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
12
27
|
* Options of `LayersControl`.
|
|
13
28
|
* @typedef {object} LayersControlOptions
|
|
14
29
|
* @property {boolean} [collapsed=true] If `true`, the control will be collapsed into an
|
|
15
|
-
* icon and expanded on pointer hover, touch, or keyboard activation.
|
|
30
|
+
* icon and expanded on pointer hover, touch, or keyboard activation. Ignored if `inline`
|
|
31
|
+
* is `true`.
|
|
32
|
+
* @property {boolean} [inline=false] If `true`, the control is laid out like the
|
|
33
|
+
* attribution control: it is always expanded (without toggle button) and all entries are
|
|
34
|
+
* placed next to each other, wrapping onto multiple lines if necessary.
|
|
35
|
+
* @property {(name: string, layer: Layer, overlay: boolean) => LayersControlGroup | undefined} [groupBy]
|
|
36
|
+
* A function to group the entries. For each entry, it returns the name of its group and
|
|
37
|
+
* its label within the group, or `undefined` for an ungrouped entry. Consecutive entries
|
|
38
|
+
* of the same group (base layers and overlays separately) are rendered within one
|
|
39
|
+
* `maplair-control-layers-group` container, starting with the group name in a
|
|
40
|
+
* `maplair-control-layers-group-name` element, and each entry shows only its label.
|
|
41
|
+
* Events like `baselayerchange` still carry the full `name`. When combined with
|
|
42
|
+
* `sortLayers`, the entries are sorted first and grouped afterwards.
|
|
43
|
+
* @property {string|HTMLElement} [toggleContent] The content of the toggle button of a
|
|
44
|
+
* collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an
|
|
45
|
+
* element. String content is rendered as HTML; do not pass untrusted input.
|
|
16
46
|
* @property {number} [collapseDelay=0] Collapse delay in milliseconds. If greater than 0,
|
|
17
47
|
* the control will remain open longer, making it easier to scroll through long layer
|
|
18
48
|
* lists.
|
|
@@ -69,6 +99,19 @@ import { I18n } from "../core/I18n.js";
|
|
|
69
99
|
* {"<img src='my-layer-icon' /> <span class='my-layer-item'>My Layer</span>": myLayer}
|
|
70
100
|
* ```
|
|
71
101
|
*
|
|
102
|
+
* Layers can be grouped using the option `groupBy`, for example layer names of the form
|
|
103
|
+
* `"Group (label)"`:
|
|
104
|
+
*
|
|
105
|
+
* ```js
|
|
106
|
+
* new LayersControl(baseLayers, overlays, {
|
|
107
|
+
* inline: true,
|
|
108
|
+
* groupBy(name) {
|
|
109
|
+
* const [, group, label] = /^([^<>()]+) \((.+)\)$/.exec(name) ?? [];
|
|
110
|
+
* return group ? {group: `${group}:`, label} : undefined;
|
|
111
|
+
* }
|
|
112
|
+
* }).addTo(map);
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
72
115
|
* @fires MaplairMap#baselayerchange {LayersControlEvent} Fired when the base layer is
|
|
73
116
|
* changed through the [layers control](#control-layers).
|
|
74
117
|
* @fires MaplairMap#overlayadd {LayersControlEvent} Fired when an overlay is selected
|
|
@@ -77,19 +120,20 @@ import { I18n } from "../core/I18n.js";
|
|
|
77
120
|
* deselected through the [layers control](#control-layers).
|
|
78
121
|
*/
|
|
79
122
|
var LayersControl = class LayersControl extends Control {
|
|
80
|
-
static {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
123
|
+
static defaultOptions = {
|
|
124
|
+
collapsed: true,
|
|
125
|
+
inline: false,
|
|
126
|
+
groupBy: void 0,
|
|
127
|
+
toggleContent: void 0,
|
|
128
|
+
collapseDelay: 0,
|
|
129
|
+
position: "topright",
|
|
130
|
+
autoZIndex: true,
|
|
131
|
+
hideSingleBase: false,
|
|
132
|
+
sortLayers: false,
|
|
133
|
+
sortFunction(layerA, layerB, nameA, nameB) {
|
|
134
|
+
return nameA < nameB ? -1 : nameB < nameA ? 1 : 0;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
93
137
|
/**
|
|
94
138
|
* Creates a layers control with the given layers. Base layers will be switched with
|
|
95
139
|
* radio buttons, while overlays will be switched with checkboxes. Note that all base
|
|
@@ -121,7 +165,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
121
165
|
this._map = map;
|
|
122
166
|
map.on("zoomend", this._checkDisabledLayers, this);
|
|
123
167
|
for (const layer of this._layers) layer.layer.on("add remove", this._onLayerChange, this);
|
|
124
|
-
if (!this.
|
|
168
|
+
if (!this._isCollapsible()) map.on("resize", this._expandIfNotCollapsed, this);
|
|
125
169
|
return this._container;
|
|
126
170
|
}
|
|
127
171
|
/**
|
|
@@ -171,13 +215,41 @@ var LayersControl = class LayersControl extends Control {
|
|
|
171
215
|
return this._map ? this._update() : this;
|
|
172
216
|
}
|
|
173
217
|
/**
|
|
218
|
+
* Returns the entries of the control in the order they are displayed.
|
|
219
|
+
* @returns {LayersControlEntry[]}
|
|
220
|
+
*/
|
|
221
|
+
getLayers() {
|
|
222
|
+
return this._layers.map(({ layer, name, overlay }) => ({
|
|
223
|
+
layer,
|
|
224
|
+
name,
|
|
225
|
+
overlay
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Selects the given layer of the control like a click on its entry: a base layer
|
|
230
|
+
* replaces the current base layer, an overlay is added to the map. The events
|
|
231
|
+
* `baselayerchange` and `overlayadd` are fired as for a click, but without
|
|
232
|
+
* `originalEvent`. Has no effect if the control is not on a map or does not contain
|
|
233
|
+
* the layer.
|
|
234
|
+
* @param {Layer} layer
|
|
235
|
+
* @returns {this}
|
|
236
|
+
*/
|
|
237
|
+
selectLayer(layer) {
|
|
238
|
+
const input = this._layerControlInputs.find((input) => input.layerId === stamp(layer));
|
|
239
|
+
if (input && !input.checked) {
|
|
240
|
+
input.checked = true;
|
|
241
|
+
this._onInputClick();
|
|
242
|
+
}
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
174
246
|
* Expand the control container if collapsed.
|
|
175
247
|
* @returns {this}
|
|
176
248
|
*/
|
|
177
249
|
expand() {
|
|
178
250
|
clearTimeout(this._collapseDelayTimeout);
|
|
179
251
|
this._container.classList.add("maplair-control-layers-expanded");
|
|
180
|
-
this._section.style.height =
|
|
252
|
+
this._section.style.height = "";
|
|
181
253
|
const acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);
|
|
182
254
|
if (acceptableHeight < this._section.clientHeight) {
|
|
183
255
|
this._section.classList.add("maplair-control-layers-scrollbar");
|
|
@@ -193,6 +265,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
193
265
|
* @returns {this}
|
|
194
266
|
*/
|
|
195
267
|
collapse(ev) {
|
|
268
|
+
if (this.options.inline) return this;
|
|
196
269
|
if (!ev || !((ev.type === "pointerleave" || ev.type === "pointerout") && ev.pointerType === "touch")) {
|
|
197
270
|
if (this.options.collapseDelay > 0) {
|
|
198
271
|
this._collapseDelayTimeout = setTimeout(() => {
|
|
@@ -205,10 +278,12 @@ var LayersControl = class LayersControl extends Control {
|
|
|
205
278
|
return this;
|
|
206
279
|
}
|
|
207
280
|
_initLayout() {
|
|
208
|
-
const className = "maplair-control-layers", container = this._container = create("div", className), collapsed = this.
|
|
281
|
+
const className = "maplair-control-layers", container = this._container = create("div", className), collapsed = this._isCollapsible();
|
|
282
|
+
if (this.options.inline) container.classList.add(`${className}-inline`);
|
|
209
283
|
disableClickPropagation(container);
|
|
210
284
|
disableScrollPropagation(container);
|
|
211
285
|
const section = this._section = create("fieldset", `${className}-list`);
|
|
286
|
+
section.setAttribute("aria-label", I18n.translate("Layers"));
|
|
212
287
|
if (collapsed) {
|
|
213
288
|
this._map.on("click", this.collapse, this);
|
|
214
289
|
on(container, {
|
|
@@ -216,19 +291,24 @@ var LayersControl = class LayersControl extends Control {
|
|
|
216
291
|
pointerleave: this.collapse
|
|
217
292
|
}, this);
|
|
218
293
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
e
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
294
|
+
if (!this.options.inline) {
|
|
295
|
+
const link = this._layersLink = create("button", `${className}-toggle`, container);
|
|
296
|
+
link.type = "button";
|
|
297
|
+
link.title = I18n.translate("Layers");
|
|
298
|
+
link.setAttribute("aria-label", I18n.translate("Layers"));
|
|
299
|
+
const { toggleContent } = this.options;
|
|
300
|
+
if (typeof toggleContent === "string") link.innerHTML = toggleContent;
|
|
301
|
+
else if (toggleContent) link.replaceChildren(toggleContent);
|
|
302
|
+
on(link, {
|
|
303
|
+
keydown(e) {
|
|
304
|
+
if (e.code === "Enter") this._expandSafely();
|
|
305
|
+
},
|
|
306
|
+
click(e) {
|
|
307
|
+
e.preventDefault();
|
|
308
|
+
this._expandSafely();
|
|
309
|
+
}
|
|
310
|
+
}, this);
|
|
311
|
+
}
|
|
232
312
|
if (!collapsed) this.expand();
|
|
233
313
|
this._baseLayersList = create("div", `${className}-base`, section);
|
|
234
314
|
this._separator = create("div", `${className}-separator`, section);
|
|
@@ -243,7 +323,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
243
323
|
this._layers.push({
|
|
244
324
|
layer,
|
|
245
325
|
name,
|
|
246
|
-
overlay
|
|
326
|
+
overlay: !!overlay
|
|
247
327
|
});
|
|
248
328
|
if (this.options.sortLayers) this._layers.sort(((a, b) => this.options.sortFunction(a.layer, b.layer, a.name, b.name)));
|
|
249
329
|
if (this.options.autoZIndex && layer.setZIndex) {
|
|
@@ -257,6 +337,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
257
337
|
this._baseLayersList.replaceChildren();
|
|
258
338
|
this._overlaysList.replaceChildren();
|
|
259
339
|
this._layerControlInputs = [];
|
|
340
|
+
this._groupCount = 0;
|
|
260
341
|
let baseLayersPresent, overlaysPresent, baseLayersCount = 0;
|
|
261
342
|
for (const obj of this._layers) {
|
|
262
343
|
this._addItem(obj);
|
|
@@ -275,7 +356,10 @@ var LayersControl = class LayersControl extends Control {
|
|
|
275
356
|
if (!this._handlingClick) this._update();
|
|
276
357
|
const obj = this._getLayer(stamp(e.target));
|
|
277
358
|
const type = obj.overlay ? e.type === "add" ? "overlayadd" : "overlayremove" : e.type === "add" ? "baselayerchange" : null;
|
|
278
|
-
if (type) this._map.fire(type,
|
|
359
|
+
if (type) this._map.fire(type, this._clickEvent ? {
|
|
360
|
+
...obj,
|
|
361
|
+
originalEvent: this._clickEvent
|
|
362
|
+
} : obj);
|
|
279
363
|
}
|
|
280
364
|
_addItem(obj) {
|
|
281
365
|
const label = document.createElement("label"), checked = this._map.hasLayer(obj.layer);
|
|
@@ -287,20 +371,41 @@ var LayersControl = class LayersControl extends Control {
|
|
|
287
371
|
this._layerControlInputs.push(input);
|
|
288
372
|
input.layerId = stamp(obj.layer);
|
|
289
373
|
on(input, "click", this._onInputClick, this);
|
|
374
|
+
const group = this.options.groupBy?.(obj.name, obj.layer, obj.overlay);
|
|
290
375
|
const name = document.createElement("span");
|
|
291
|
-
name.innerHTML = ` ${obj.name}`;
|
|
376
|
+
name.innerHTML = ` ${group ? group.label : obj.name}`;
|
|
292
377
|
const holder = document.createElement("span");
|
|
293
378
|
label.appendChild(holder);
|
|
294
379
|
holder.appendChild(input);
|
|
295
380
|
holder.appendChild(name);
|
|
296
|
-
|
|
381
|
+
const list = obj.overlay ? this._overlaysList : this._baseLayersList;
|
|
382
|
+
(group ? this._getGroupContainer(list, group.group) : list).appendChild(label);
|
|
297
383
|
this._checkDisabledLayers();
|
|
298
384
|
return label;
|
|
299
385
|
}
|
|
386
|
+
/**
|
|
387
|
+
* Returns the container of the given group if it is the last element in `list`
|
|
388
|
+
* (continuing the group), otherwise appends a new group container to `list`.
|
|
389
|
+
* @param {HTMLElement} list
|
|
390
|
+
* @param {string} group
|
|
391
|
+
* @returns {HTMLElement}
|
|
392
|
+
*/
|
|
393
|
+
_getGroupContainer(list, group) {
|
|
394
|
+
const last = list.lastElementChild;
|
|
395
|
+
if (last?._maplairGroup === group) return last;
|
|
396
|
+
const className = "maplair-control-layers-group", container = create("div", className, list), name = create("span", `${className}-name`, container);
|
|
397
|
+
name.id = `${className}_${stamp(this)}_${++this._groupCount}`;
|
|
398
|
+
name.textContent = group;
|
|
399
|
+
container.setAttribute("role", "group");
|
|
400
|
+
container.setAttribute("aria-labelledby", name.id);
|
|
401
|
+
container._maplairGroup = group;
|
|
402
|
+
return container;
|
|
403
|
+
}
|
|
300
404
|
_onInputClick(e) {
|
|
301
405
|
if (this._preventClick) return;
|
|
302
406
|
const inputs = this._layerControlInputs, addedLayers = [], removedLayers = [];
|
|
303
407
|
this._handlingClick = true;
|
|
408
|
+
this._clickEvent = e;
|
|
304
409
|
for (const input of inputs) {
|
|
305
410
|
const layer = this._getLayer(input.layerId).layer;
|
|
306
411
|
if (input.checked) addedLayers.push(layer);
|
|
@@ -309,6 +414,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
309
414
|
for (const layer of removedLayers) if (this._map.hasLayer(layer)) this._map.removeLayer(layer);
|
|
310
415
|
for (const layer of addedLayers) if (!this._map.hasLayer(layer)) this._map.addLayer(layer);
|
|
311
416
|
this._handlingClick = false;
|
|
417
|
+
this._clickEvent = void 0;
|
|
312
418
|
this._refocusOnMap(e);
|
|
313
419
|
}
|
|
314
420
|
_checkDisabledLayers() {
|
|
@@ -318,8 +424,11 @@ var LayersControl = class LayersControl extends Control {
|
|
|
318
424
|
input.disabled = layer.options.minZoom !== void 0 && zoom < layer.options.minZoom || layer.options.maxZoom !== void 0 && zoom > layer.options.maxZoom;
|
|
319
425
|
}
|
|
320
426
|
}
|
|
427
|
+
_isCollapsible() {
|
|
428
|
+
return this.options.collapsed && !this.options.inline;
|
|
429
|
+
}
|
|
321
430
|
_expandIfNotCollapsed() {
|
|
322
|
-
if (this._map && !this.
|
|
431
|
+
if (this._map && !this._isCollapsible()) this.expand();
|
|
323
432
|
return this;
|
|
324
433
|
}
|
|
325
434
|
_expandSafely() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayersControl.js","names":["Util.stamp","DomUtil.create","DomEvent.preventDefault"],"sources":["../../../src/control/LayersControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as Util from '../core/Util.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/** @import {Layer} from '../layer/Layer.js' */\n/** @import {LayersControlEvent} from '../core/Events.js' */\n\n/**\n * Options of `LayersControl`.\n * @typedef {object} LayersControlOptions\n * @property {boolean} [collapsed=true] If `true`, the control will be collapsed into an\n * icon and expanded on pointer hover, touch, or keyboard activation.\n * @property {number} [collapseDelay=0] Collapse delay in milliseconds. If greater than 0,\n * the control will remain open longer, making it easier to scroll through long layer\n * lists.\n * @property {string} [position='topright'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {boolean} [autoZIndex=true] If `true`, the control will assign zIndexes in\n * increasing order to all of its layers so that the order is preserved when switching\n * them on/off.\n * @property {boolean} [hideSingleBase=false] If `true`, the base layers in the control\n * will be hidden when there is only one.\n * @property {boolean} [sortLayers=false] Whether to sort the layers. When `false`, layers\n * will keep the order in which they were added to the control.\n * @property {(layerA: Layer, layerB: Layer, nameA: string, nameB: string) => number} [sortFunction]\n * A [compare function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\n * that will be used for sorting the layers, when `sortLayers` is `true`. The function\n * receives both the `Layer` instances and their names, as in\n * `sortFunction(layerA, layerB, nameA, nameB)`. By default, it sorts layers\n * alphabetically by their name.\n * @extends ControlOptions\n */\n\n/**\n * The layers control gives users the ability to switch between different base layers\n * and switch overlays on/off (check out the\n * [detailed example](https://maplair.org/examples/layers-control/)).\n *\n * @example\n * ```js\n * const baseLayers = {\n * \t\"Mapbox\": mapbox,\n * \t\"OpenStreetMap\": osm\n * };\n *\n * const overlays = {\n * \t\"Marker\": marker,\n * \t\"Roads\": roadsLayer\n * };\n *\n * new LayersControl(baseLayers, overlays).addTo(map);\n * ```\n *\n * The `baseLayers` and `overlays` parameters are object literals with layer names as keys and `Layer` objects as values:\n *\n * ```js\n * {\n * \"<someName1>\": layer1,\n * \"<someName2>\": layer2\n * }\n * ```\n *\n * The layer names can contain HTML, which allows you to add additional styling to the items:\n *\n * ```js\n * {\"<img src='my-layer-icon' /> <span class='my-layer-item'>My Layer</span>\": myLayer}\n * ```\n *\n * @fires MaplairMap#baselayerchange {LayersControlEvent} Fired when the base layer is\n * changed through the [layers control](#control-layers).\n * @fires MaplairMap#overlayadd {LayersControlEvent} Fired when an overlay is selected\n * through the [layers control](#control-layers).\n * @fires MaplairMap#overlayremove {LayersControlEvent} Fired when an overlay is\n * deselected through the [layers control](#control-layers).\n */\nexport class LayersControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tcollapsed: true,\n\t\t\tcollapseDelay: 0,\n\t\t\tposition: 'topright',\n\t\t\tautoZIndex: true,\n\t\t\thideSingleBase: false,\n\t\t\tsortLayers: false,\n\t\t\tsortFunction(layerA, layerB, nameA, nameB) {\n\t\t\t\treturn nameA < nameB ? -1 : (nameB < nameA ? 1 : 0);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Creates a layers control with the given layers. Base layers will be switched with\n\t * radio buttons, while overlays will be switched with checkboxes. Note that all base\n\t * layers should be passed in the base layers object, but only one should be added to\n\t * the map during map instantiation.\n\t * @param {Record<string, Layer>} [baseLayers]\n\t * @param {Record<string, Layer>} [overlays]\n\t * @param {LayersControlOptions} [options]\n\t */\n\tconstructor(baseLayers, overlays, options) {\n\t\tsuper(options);\n\n\t\tthis._layerControlInputs = [];\n\t\tthis._layers = [];\n\t\tthis._lastZIndex = 0;\n\t\tthis._handlingClick = false;\n\t\tthis._preventClick = false;\n\n\t\tfor (const [name, layer] of Object.entries(baseLayers ?? {})) {\n\t\t\tthis._addLayer(layer, name);\n\t\t}\n\n\t\tfor (const [name, layer] of Object.entries(overlays ?? {})) {\n\t\t\tthis._addLayer(layer, name, true);\n\t\t}\n\n\t\tthis.callInitHooks(LayersControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tthis._initLayout();\n\t\tthis._update();\n\n\t\tthis._map = map;\n\t\tmap.on('zoomend', this._checkDisabledLayers, this);\n\n\t\tfor (const layer of this._layers) {\n\t\t\tlayer.layer.on('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tif (!this.options.collapsed) {\n\t\t\t// update the height of the container after resizing the window\n\t\t\tmap.on('resize', this._expandIfNotCollapsed, this);\n\t\t}\n\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Adds the control to the given map.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tsuper.addTo(map);\n\t\t// Trigger expand after Layers Control has been inserted into DOM so that is now has an actual height.\n\t\treturn this._expandIfNotCollapsed();\n\t}\n\n\t/** @internal */\n\tonRemove() {\n\t\tthis._map.off('zoomend', this._checkDisabledLayers, this);\n\n\t\tfor (const layer of this._layers) {\n\t\t\tlayer.layer.off('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tthis._map.off('resize', this._expandIfNotCollapsed, this);\n\t}\n\n\t/**\n\t * Adds a base layer (radio button entry) with the given name to the control.\n\t * @param {Layer} layer\n\t * @param {string} name\n\t * @returns {this}\n\t */\n\taddBaseLayer(layer, name) {\n\t\tthis._addLayer(layer, name);\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Adds an overlay (checkbox entry) with the given name to the control.\n\t * @param {Layer} layer\n\t * @param {string} name\n\t * @returns {this}\n\t */\n\taddOverlay(layer, name) {\n\t\tthis._addLayer(layer, name, true);\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Remove the given layer from the control.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tlayer.off('add remove', this._onLayerChange, this);\n\n\t\tconst obj = this._getLayer(Util.stamp(layer));\n\t\tif (obj) {\n\t\t\tthis._layers.splice(this._layers.indexOf(obj), 1);\n\t\t}\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Expand the control container if collapsed.\n\t * @returns {this}\n\t */\n\texpand() {\n\t\tclearTimeout(this._collapseDelayTimeout);\n\n\t\tthis._container.classList.add('maplair-control-layers-expanded');\n\t\tthis._section.style.height = null;\n\t\tconst acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);\n\t\tif (acceptableHeight < this._section.clientHeight) {\n\t\t\tthis._section.classList.add('maplair-control-layers-scrollbar');\n\t\t\tthis._section.style.height = `${acceptableHeight}px`;\n\t\t} else {\n\t\t\tthis._section.classList.remove('maplair-control-layers-scrollbar');\n\t\t}\n\t\tthis._checkDisabledLayers();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Collapse the control container if expanded.\n\t * @param {Event} [ev] The event causing the collapse, if any (collapsing is skipped\n\t * for `pointerleave` and `pointerout` of touch).\n\t * @returns {this}\n\t */\n\tcollapse(ev) {\n\t\t// On touch devices `pointerleave` & `pointerout` is fired while clicking on a checkbox.\n\t\t// The control was collapsed instead of adding the layer to the map.\n\t\t// So we allow collapse only if it is not touch.\n\t\tif (!ev || !((ev.type === 'pointerleave' || ev.type === 'pointerout') && ev.pointerType === 'touch')) {\n\t\t\tif (this.options.collapseDelay > 0) {\n\t\t\t\t// Collapse delayed\n\t\t\t\tthis._collapseDelayTimeout = setTimeout(() => {\n\t\t\t\t\tthis._container.classList.remove('maplair-control-layers-expanded');\n\t\t\t\t}, this.options.collapseDelay);\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\t// Collapse immediately\n\t\t\tthis._container.classList.remove('maplair-control-layers-expanded');\n\t\t}\n\t\treturn this;\n\t}\n\n\t_initLayout() {\n\t\tconst className = 'maplair-control-layers',\n\t\tcontainer = this._container = DomUtil.create('div', className),\n\t\tcollapsed = this.options.collapsed;\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\n\t\tconst section = this._section = DomUtil.create('fieldset', `${className}-list`);\n\n\t\tif (collapsed) {\n\t\t\tthis._map.on('click', this.collapse, this);\n\n\t\t\tDomEvent.on(container, {\n\t\t\t\tpointerenter: this._expandSafely,\n\t\t\t\tpointerleave: this.collapse\n\t\t\t}, this);\n\t\t}\n\n\t\tconst link = this._layersLink = DomUtil.create('button', `${className}-toggle`, container);\n\t\tlink.type = 'button';\n\t\tlink.title = I18n.translate('Layers');\n\t\tlink.setAttribute('aria-label', I18n.translate('Layers'));\n\n\t\tDomEvent.on(link, {\n\t\t\tkeydown(e) {\n\t\t\t\tif (e.code === 'Enter') {\n\t\t\t\t\tthis._expandSafely();\n\t\t\t\t}\n\t\t\t},\n\t\t\t// Certain screen readers intercept the key event and instead send a click event\n\t\t\tclick(e) {\n\t\t\t\te.preventDefault();\n\t\t\t\tthis._expandSafely();\n\t\t\t}\n\t\t}, this);\n\n\t\tif (!collapsed) {\n\t\t\tthis.expand();\n\t\t}\n\n\t\tthis._baseLayersList = DomUtil.create('div', `${className}-base`, section);\n\t\tthis._separator = DomUtil.create('div', `${className}-separator`, section);\n\t\tthis._overlaysList = DomUtil.create('div', `${className}-overlays`, section);\n\n\t\tcontainer.appendChild(section);\n\t}\n\n\t_getLayer(id) {\n\t\tfor (const layer of this._layers) {\n\t\t\tif (layer && Util.stamp(layer.layer) === id) {\n\t\t\t\treturn layer;\n\t\t\t}\n\t\t}\n\t}\n\n\t_addLayer(layer, name, overlay) {\n\t\tif (this._map) {\n\t\t\tlayer.on('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tthis._layers.push({\n\t\t\tlayer,\n\t\t\tname,\n\t\t\toverlay\n\t\t});\n\n\t\tif (this.options.sortLayers) {\n\t\t\tthis._layers.sort(((a, b) => this.options.sortFunction(a.layer, b.layer, a.name, b.name)));\n\t\t}\n\n\t\tif (this.options.autoZIndex && layer.setZIndex) {\n\t\t\tthis._lastZIndex++;\n\t\t\tlayer.setZIndex(this._lastZIndex);\n\t\t}\n\n\t\tthis._expandIfNotCollapsed();\n\t}\n\n\t_update() {\n\t\tif (!this._container) { return this; }\n\n\t\tthis._baseLayersList.replaceChildren();\n\t\tthis._overlaysList.replaceChildren();\n\n\t\tthis._layerControlInputs = [];\n\t\tlet baseLayersPresent, overlaysPresent, baseLayersCount = 0;\n\n\t\tfor (const obj of this._layers) {\n\t\t\tthis._addItem(obj);\n\t\t\toverlaysPresent ||= obj.overlay;\n\t\t\tbaseLayersPresent ||= !obj.overlay;\n\t\t\tbaseLayersCount += !obj.overlay ? 1 : 0;\n\t\t}\n\n\t\t// Hide base layers section if there's only one layer.\n\t\tif (this.options.hideSingleBase) {\n\t\t\tbaseLayersPresent = baseLayersPresent && baseLayersCount > 1;\n\t\t\tthis._baseLayersList.style.display = baseLayersPresent ? '' : 'none';\n\t\t}\n\n\t\tthis._separator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none';\n\n\t\treturn this;\n\t}\n\n\t_onLayerChange(e) {\n\t\tif (!this._handlingClick) {\n\t\t\tthis._update();\n\t\t}\n\n\t\tconst obj = this._getLayer(Util.stamp(e.target));\n\n\t\tconst type = obj.overlay ?\n\t\t\t(e.type === 'add' ? 'overlayadd' : 'overlayremove') :\n\t\t\t(e.type === 'add' ? 'baselayerchange' : null);\n\n\t\tif (type) {\n\t\t\tthis._map.fire(type, obj);\n\t\t}\n\t}\n\n\t_addItem(obj) {\n\t\tconst label = document.createElement('label'),\n\t\tchecked = this._map.hasLayer(obj.layer);\n\n\t\tconst input = document.createElement('input');\n\t\tinput.type = obj.overlay ? 'checkbox' : 'radio';\n\t\tinput.className = 'maplair-control-layers-selector';\n\t\tinput.defaultChecked = checked;\n\t\tif (!obj.overlay) {\n\t\t\tinput.name = `maplair-base-layers_${Util.stamp(this)}`;\n\t\t}\n\n\t\tthis._layerControlInputs.push(input);\n\t\tinput.layerId = Util.stamp(obj.layer);\n\n\t\tDomEvent.on(input, 'click', this._onInputClick, this);\n\n\t\tconst name = document.createElement('span');\n\t\tname.innerHTML = ` ${obj.name}`;\n\n\t\t// Helps from preventing layer control flicker when checkboxes are disabled\n\t\t// https://github.com/Leaflet/Leaflet/issues/2771\n\t\tconst holder = document.createElement('span');\n\n\t\tlabel.appendChild(holder);\n\t\tholder.appendChild(input);\n\t\tholder.appendChild(name);\n\n\t\tconst container = obj.overlay ? this._overlaysList : this._baseLayersList;\n\t\tcontainer.appendChild(label);\n\n\t\tthis._checkDisabledLayers();\n\t\treturn label;\n\t}\n\n\t_onInputClick(e) {\n\t\t// expanding the control on mobile with a click can cause adding a layer - we don't want this\n\t\tif (this._preventClick) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst inputs = this._layerControlInputs,\n\t\taddedLayers = [],\n\t\tremovedLayers = [];\n\n\t\tthis._handlingClick = true;\n\n\t\tfor (const input of inputs) {\n\t\t\tconst layer = this._getLayer(input.layerId).layer;\n\n\t\t\tif (input.checked) {\n\t\t\t\taddedLayers.push(layer);\n\t\t\t} else if (!input.checked) {\n\t\t\t\tremovedLayers.push(layer);\n\t\t\t}\n\t\t}\n\n\t\t// Bugfix issue 2318: Should remove all old layers before readding new ones\n\t\tfor (const layer of removedLayers) {\n\t\t\tif (this._map.hasLayer(layer)) {\n\t\t\t\tthis._map.removeLayer(layer);\n\t\t\t}\n\t\t}\n\t\tfor (const layer of addedLayers) {\n\t\t\tif (!this._map.hasLayer(layer)) {\n\t\t\t\tthis._map.addLayer(layer);\n\t\t\t}\n\t\t}\n\n\t\tthis._handlingClick = false;\n\n\t\tthis._refocusOnMap(e);\n\t}\n\n\t_checkDisabledLayers() {\n\t\tconst inputs = this._layerControlInputs,\n\t\tzoom = this._map.getZoom();\n\n\t\tfor (const input of inputs) {\n\t\t\tconst layer = this._getLayer(input.layerId).layer;\n\t\t\tinput.disabled = (layer.options.minZoom !== undefined && zoom < layer.options.minZoom) ||\n\t\t\t (layer.options.maxZoom !== undefined && zoom > layer.options.maxZoom);\n\n\t\t}\n\t}\n\n\t_expandIfNotCollapsed() {\n\t\tif (this._map && !this.options.collapsed) {\n\t\t\tthis.expand();\n\t\t}\n\t\treturn this;\n\t}\n\n\t_expandSafely() {\n\t\tconst section = this._section;\n\t\tthis._preventClick = true;\n\t\tDomEvent.on(section, 'click', DomEvent.preventDefault);\n\t\tthis.expand();\n\t\tsetTimeout(() => {\n\t\t\tDomEvent.off(section, 'click', DomEvent.preventDefault);\n\t\t\tthis._preventClick = false;\n\t\t});\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C;EACC,KAAK,kBAAkB;GACtB,WAAW;GACX,eAAe;GACf,UAAU;GACV,YAAY;GACZ,gBAAgB;GAChB,YAAY;GACZ,aAAa,QAAQ,QAAQ,OAAO,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AK;EACrB,KAAK,gBAAgB;EACrB,GAAY,SAAS,SAASE,cAAuB;EACrD,KAAK,OAAO;EACZ,iBAAiB;GAChB,IAAa,SAAS,SAASA,cAAuB;GACtD,KAAK,gBAAgB;EACtB,CAAC;CACF;AAED"}
|
|
1
|
+
{"version":3,"file":"LayersControl.js","names":["Util.stamp","DomUtil.create","DomEvent.preventDefault"],"sources":["../../../src/control/LayersControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as Util from '../core/Util.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/** @import {Layer} from '../layer/Layer.js' */\n/** @import {LayersControlEvent} from '../core/Events.js' */\n\n/**\n * An entry of `LayersControl`, as returned by `getLayers()`.\n * @typedef {object} LayersControlEntry\n * @property {Layer} layer The layer.\n * @property {string} name The name of the layer, as given to the control.\n * @property {boolean} overlay Whether the layer is an overlay (checkbox) or a base layer\n * (radio button).\n */\n\n/**\n * The group of an entry of `LayersControl`, as returned by the option `groupBy`.\n * @typedef {object} LayersControlGroup\n * @property {string} group The name of the group, rendered as text.\n * @property {string} label The label of the entry within the group, may contain HTML\n * (like layer names).\n */\n\n/**\n * Options of `LayersControl`.\n * @typedef {object} LayersControlOptions\n * @property {boolean} [collapsed=true] If `true`, the control will be collapsed into an\n * icon and expanded on pointer hover, touch, or keyboard activation. Ignored if `inline`\n * is `true`.\n * @property {boolean} [inline=false] If `true`, the control is laid out like the\n * attribution control: it is always expanded (without toggle button) and all entries are\n * placed next to each other, wrapping onto multiple lines if necessary.\n * @property {(name: string, layer: Layer, overlay: boolean) => LayersControlGroup | undefined} [groupBy]\n * A function to group the entries. For each entry, it returns the name of its group and\n * its label within the group, or `undefined` for an ungrouped entry. Consecutive entries\n * of the same group (base layers and overlays separately) are rendered within one\n * `maplair-control-layers-group` container, starting with the group name in a\n * `maplair-control-layers-group-name` element, and each entry shows only its label.\n * Events like `baselayerchange` still carry the full `name`. When combined with\n * `sortLayers`, the entries are sorted first and grouped afterwards.\n * @property {string|HTMLElement} [toggleContent] The content of the toggle button of a\n * collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an\n * element. String content is rendered as HTML; do not pass untrusted input.\n * @property {number} [collapseDelay=0] Collapse delay in milliseconds. If greater than 0,\n * the control will remain open longer, making it easier to scroll through long layer\n * lists.\n * @property {string} [position='topright'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {boolean} [autoZIndex=true] If `true`, the control will assign zIndexes in\n * increasing order to all of its layers so that the order is preserved when switching\n * them on/off.\n * @property {boolean} [hideSingleBase=false] If `true`, the base layers in the control\n * will be hidden when there is only one.\n * @property {boolean} [sortLayers=false] Whether to sort the layers. When `false`, layers\n * will keep the order in which they were added to the control.\n * @property {(layerA: Layer, layerB: Layer, nameA: string, nameB: string) => number} [sortFunction]\n * A [compare function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\n * that will be used for sorting the layers, when `sortLayers` is `true`. The function\n * receives both the `Layer` instances and their names, as in\n * `sortFunction(layerA, layerB, nameA, nameB)`. By default, it sorts layers\n * alphabetically by their name.\n * @extends ControlOptions\n */\n\n/**\n * The layers control gives users the ability to switch between different base layers\n * and switch overlays on/off (check out the\n * [detailed example](https://maplair.org/examples/layers-control/)).\n *\n * @example\n * ```js\n * const baseLayers = {\n * \t\"Mapbox\": mapbox,\n * \t\"OpenStreetMap\": osm\n * };\n *\n * const overlays = {\n * \t\"Marker\": marker,\n * \t\"Roads\": roadsLayer\n * };\n *\n * new LayersControl(baseLayers, overlays).addTo(map);\n * ```\n *\n * The `baseLayers` and `overlays` parameters are object literals with layer names as keys and `Layer` objects as values:\n *\n * ```js\n * {\n * \"<someName1>\": layer1,\n * \"<someName2>\": layer2\n * }\n * ```\n *\n * The layer names can contain HTML, which allows you to add additional styling to the items:\n *\n * ```js\n * {\"<img src='my-layer-icon' /> <span class='my-layer-item'>My Layer</span>\": myLayer}\n * ```\n *\n * Layers can be grouped using the option `groupBy`, for example layer names of the form\n * `\"Group (label)\"`:\n *\n * ```js\n * new LayersControl(baseLayers, overlays, {\n * \tinline: true,\n * \tgroupBy(name) {\n * \t\tconst [, group, label] = /^([^<>()]+) \\((.+)\\)$/.exec(name) ?? [];\n * \t\treturn group ? {group: `${group}:`, label} : undefined;\n * \t}\n * }).addTo(map);\n * ```\n *\n * @fires MaplairMap#baselayerchange {LayersControlEvent} Fired when the base layer is\n * changed through the [layers control](#control-layers).\n * @fires MaplairMap#overlayadd {LayersControlEvent} Fired when an overlay is selected\n * through the [layers control](#control-layers).\n * @fires MaplairMap#overlayremove {LayersControlEvent} Fired when an overlay is\n * deselected through the [layers control](#control-layers).\n */\nexport class LayersControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tcollapsed: true,\n\t\tinline: false,\n\t\tgroupBy: undefined,\n\t\ttoggleContent: undefined,\n\t\tcollapseDelay: 0,\n\t\tposition: 'topright',\n\t\tautoZIndex: true,\n\t\thideSingleBase: false,\n\t\tsortLayers: false,\n\t\tsortFunction(layerA, layerB, nameA, nameB) {\n\t\t\treturn nameA < nameB ? -1 : (nameB < nameA ? 1 : 0);\n\t\t}\n\t};\n\n\t/**\n\t * Creates a layers control with the given layers. Base layers will be switched with\n\t * radio buttons, while overlays will be switched with checkboxes. Note that all base\n\t * layers should be passed in the base layers object, but only one should be added to\n\t * the map during map instantiation.\n\t * @param {Record<string, Layer>} [baseLayers]\n\t * @param {Record<string, Layer>} [overlays]\n\t * @param {LayersControlOptions} [options]\n\t */\n\tconstructor(baseLayers, overlays, options) {\n\t\tsuper(options);\n\n\t\tthis._layerControlInputs = [];\n\t\tthis._layers = [];\n\t\tthis._lastZIndex = 0;\n\t\tthis._handlingClick = false;\n\t\tthis._preventClick = false;\n\n\t\tfor (const [name, layer] of Object.entries(baseLayers ?? {})) {\n\t\t\tthis._addLayer(layer, name);\n\t\t}\n\n\t\tfor (const [name, layer] of Object.entries(overlays ?? {})) {\n\t\t\tthis._addLayer(layer, name, true);\n\t\t}\n\n\t\tthis.callInitHooks(LayersControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tthis._initLayout();\n\t\tthis._update();\n\n\t\tthis._map = map;\n\t\tmap.on('zoomend', this._checkDisabledLayers, this);\n\n\t\tfor (const layer of this._layers) {\n\t\t\tlayer.layer.on('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tif (!this._isCollapsible()) {\n\t\t\t// update the height of the container after resizing the window\n\t\t\tmap.on('resize', this._expandIfNotCollapsed, this);\n\t\t}\n\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Adds the control to the given map.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tsuper.addTo(map);\n\t\t// Trigger expand after Layers Control has been inserted into DOM so that is now has an actual height.\n\t\treturn this._expandIfNotCollapsed();\n\t}\n\n\t/** @internal */\n\tonRemove() {\n\t\tthis._map.off('zoomend', this._checkDisabledLayers, this);\n\n\t\tfor (const layer of this._layers) {\n\t\t\tlayer.layer.off('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tthis._map.off('resize', this._expandIfNotCollapsed, this);\n\t}\n\n\t/**\n\t * Adds a base layer (radio button entry) with the given name to the control.\n\t * @param {Layer} layer\n\t * @param {string} name\n\t * @returns {this}\n\t */\n\taddBaseLayer(layer, name) {\n\t\tthis._addLayer(layer, name);\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Adds an overlay (checkbox entry) with the given name to the control.\n\t * @param {Layer} layer\n\t * @param {string} name\n\t * @returns {this}\n\t */\n\taddOverlay(layer, name) {\n\t\tthis._addLayer(layer, name, true);\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Remove the given layer from the control.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tlayer.off('add remove', this._onLayerChange, this);\n\n\t\tconst obj = this._getLayer(Util.stamp(layer));\n\t\tif (obj) {\n\t\t\tthis._layers.splice(this._layers.indexOf(obj), 1);\n\t\t}\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Returns the entries of the control in the order they are displayed.\n\t * @returns {LayersControlEntry[]}\n\t */\n\tgetLayers() {\n\t\treturn this._layers.map(({layer, name, overlay}) => ({layer, name, overlay}));\n\t}\n\n\t/**\n\t * Selects the given layer of the control like a click on its entry: a base layer\n\t * replaces the current base layer, an overlay is added to the map. The events\n\t * `baselayerchange` and `overlayadd` are fired as for a click, but without\n\t * `originalEvent`. Has no effect if the control is not on a map or does not contain\n\t * the layer.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tselectLayer(layer) {\n\t\tconst input = this._layerControlInputs.find(input => input.layerId === Util.stamp(layer));\n\t\tif (input && !input.checked) {\n\t\t\tinput.checked = true;\n\t\t\tthis._onInputClick();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Expand the control container if collapsed.\n\t * @returns {this}\n\t */\n\texpand() {\n\t\tclearTimeout(this._collapseDelayTimeout);\n\n\t\tthis._container.classList.add('maplair-control-layers-expanded');\n\t\tthis._section.style.height = '';\n\t\tconst acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);\n\t\tif (acceptableHeight < this._section.clientHeight) {\n\t\t\tthis._section.classList.add('maplair-control-layers-scrollbar');\n\t\t\tthis._section.style.height = `${acceptableHeight}px`;\n\t\t} else {\n\t\t\tthis._section.classList.remove('maplair-control-layers-scrollbar');\n\t\t}\n\t\tthis._checkDisabledLayers();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Collapse the control container if expanded.\n\t * @param {Event} [ev] The event causing the collapse, if any (collapsing is skipped\n\t * for `pointerleave` and `pointerout` of touch).\n\t * @returns {this}\n\t */\n\tcollapse(ev) {\n\t\tif (this.options.inline) {\n\t\t\treturn this;\n\t\t}\n\t\t// On touch devices `pointerleave` & `pointerout` is fired while clicking on a checkbox.\n\t\t// The control was collapsed instead of adding the layer to the map.\n\t\t// So we allow collapse only if it is not touch.\n\t\tif (!ev || !((ev.type === 'pointerleave' || ev.type === 'pointerout') && ev.pointerType === 'touch')) {\n\t\t\tif (this.options.collapseDelay > 0) {\n\t\t\t\t// Collapse delayed\n\t\t\t\tthis._collapseDelayTimeout = setTimeout(() => {\n\t\t\t\t\tthis._container.classList.remove('maplair-control-layers-expanded');\n\t\t\t\t}, this.options.collapseDelay);\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\t// Collapse immediately\n\t\t\tthis._container.classList.remove('maplair-control-layers-expanded');\n\t\t}\n\t\treturn this;\n\t}\n\n\t_initLayout() {\n\t\tconst className = 'maplair-control-layers',\n\t\tcontainer = this._container = DomUtil.create('div', className),\n\t\tcollapsed = this._isCollapsible();\n\n\t\tif (this.options.inline) {\n\t\t\tcontainer.classList.add(`${className}-inline`);\n\t\t}\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\n\t\tconst section = this._section = DomUtil.create('fieldset', `${className}-list`);\n\t\tsection.setAttribute('aria-label', I18n.translate('Layers'));\n\n\t\tif (collapsed) {\n\t\t\tthis._map.on('click', this.collapse, this);\n\n\t\t\tDomEvent.on(container, {\n\t\t\t\tpointerenter: this._expandSafely,\n\t\t\t\tpointerleave: this.collapse\n\t\t\t}, this);\n\t\t}\n\n\t\tif (!this.options.inline) {\n\t\t\tconst link = this._layersLink = DomUtil.create('button', `${className}-toggle`, container);\n\t\t\tlink.type = 'button';\n\t\t\tlink.title = I18n.translate('Layers');\n\t\t\tlink.setAttribute('aria-label', I18n.translate('Layers'));\n\n\t\t\tconst {toggleContent} = this.options;\n\t\t\tif (typeof toggleContent === 'string') {\n\t\t\t\tlink.innerHTML = toggleContent;\n\t\t\t} else if (toggleContent) {\n\t\t\t\tlink.replaceChildren(toggleContent);\n\t\t\t}\n\n\t\t\tDomEvent.on(link, {\n\t\t\t\tkeydown(e) {\n\t\t\t\t\tif (e.code === 'Enter') {\n\t\t\t\t\t\tthis._expandSafely();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t// Certain screen readers intercept the key event and instead send a click event\n\t\t\t\tclick(e) {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tthis._expandSafely();\n\t\t\t\t}\n\t\t\t}, this);\n\t\t}\n\n\t\tif (!collapsed) {\n\t\t\tthis.expand();\n\t\t}\n\n\t\tthis._baseLayersList = DomUtil.create('div', `${className}-base`, section);\n\t\tthis._separator = DomUtil.create('div', `${className}-separator`, section);\n\t\tthis._overlaysList = DomUtil.create('div', `${className}-overlays`, section);\n\n\t\tcontainer.appendChild(section);\n\t}\n\n\t_getLayer(id) {\n\t\tfor (const layer of this._layers) {\n\t\t\tif (layer && Util.stamp(layer.layer) === id) {\n\t\t\t\treturn layer;\n\t\t\t}\n\t\t}\n\t}\n\n\t_addLayer(layer, name, overlay) {\n\t\tif (this._map) {\n\t\t\tlayer.on('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tthis._layers.push({\n\t\t\tlayer,\n\t\t\tname,\n\t\t\toverlay: !!overlay\n\t\t});\n\n\t\tif (this.options.sortLayers) {\n\t\t\tthis._layers.sort(((a, b) => this.options.sortFunction(a.layer, b.layer, a.name, b.name)));\n\t\t}\n\n\t\tif (this.options.autoZIndex && layer.setZIndex) {\n\t\t\tthis._lastZIndex++;\n\t\t\tlayer.setZIndex(this._lastZIndex);\n\t\t}\n\n\t\tthis._expandIfNotCollapsed();\n\t}\n\n\t_update() {\n\t\tif (!this._container) { return this; }\n\n\t\tthis._baseLayersList.replaceChildren();\n\t\tthis._overlaysList.replaceChildren();\n\n\t\tthis._layerControlInputs = [];\n\t\tthis._groupCount = 0;\n\t\tlet baseLayersPresent, overlaysPresent, baseLayersCount = 0;\n\n\t\tfor (const obj of this._layers) {\n\t\t\tthis._addItem(obj);\n\t\t\toverlaysPresent ||= obj.overlay;\n\t\t\tbaseLayersPresent ||= !obj.overlay;\n\t\t\tbaseLayersCount += !obj.overlay ? 1 : 0;\n\t\t}\n\n\t\t// Hide base layers section if there's only one layer.\n\t\tif (this.options.hideSingleBase) {\n\t\t\tbaseLayersPresent = baseLayersPresent && baseLayersCount > 1;\n\t\t\tthis._baseLayersList.style.display = baseLayersPresent ? '' : 'none';\n\t\t}\n\n\t\tthis._separator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none';\n\n\t\treturn this;\n\t}\n\n\t_onLayerChange(e) {\n\t\tif (!this._handlingClick) {\n\t\t\tthis._update();\n\t\t}\n\n\t\tconst obj = this._getLayer(Util.stamp(e.target));\n\n\t\tconst type = obj.overlay ?\n\t\t\t(e.type === 'add' ? 'overlayadd' : 'overlayremove') :\n\t\t\t(e.type === 'add' ? 'baselayerchange' : null);\n\n\t\tif (type) {\n\t\t\tthis._map.fire(type, this._clickEvent ? {...obj, originalEvent: this._clickEvent} : obj);\n\t\t}\n\t}\n\n\t_addItem(obj) {\n\t\tconst label = document.createElement('label'),\n\t\tchecked = this._map.hasLayer(obj.layer);\n\n\t\tconst input = document.createElement('input');\n\t\tinput.type = obj.overlay ? 'checkbox' : 'radio';\n\t\tinput.className = 'maplair-control-layers-selector';\n\t\tinput.defaultChecked = checked;\n\t\tif (!obj.overlay) {\n\t\t\tinput.name = `maplair-base-layers_${Util.stamp(this)}`;\n\t\t}\n\n\t\tthis._layerControlInputs.push(input);\n\t\tinput.layerId = Util.stamp(obj.layer);\n\n\t\tDomEvent.on(input, 'click', this._onInputClick, this);\n\n\t\tconst group = this.options.groupBy?.(obj.name, obj.layer, obj.overlay);\n\n\t\tconst name = document.createElement('span');\n\t\tname.innerHTML = ` ${group ? group.label : obj.name}`;\n\n\t\t// Helps from preventing layer control flicker when checkboxes are disabled\n\t\t// https://github.com/Leaflet/Leaflet/issues/2771\n\t\tconst holder = document.createElement('span');\n\n\t\tlabel.appendChild(holder);\n\t\tholder.appendChild(input);\n\t\tholder.appendChild(name);\n\n\t\tconst list = obj.overlay ? this._overlaysList : this._baseLayersList;\n\t\tconst container = group ? this._getGroupContainer(list, group.group) : list;\n\t\tcontainer.appendChild(label);\n\n\t\tthis._checkDisabledLayers();\n\t\treturn label;\n\t}\n\n\t/**\n\t * Returns the container of the given group if it is the last element in `list`\n\t * (continuing the group), otherwise appends a new group container to `list`.\n\t * @param {HTMLElement} list\n\t * @param {string} group\n\t * @returns {HTMLElement}\n\t */\n\t_getGroupContainer(list, group) {\n\t\tconst last = list.lastElementChild;\n\t\tif (last?._maplairGroup === group) {\n\t\t\treturn last;\n\t\t}\n\n\t\tconst className = 'maplair-control-layers-group',\n\t\tcontainer = DomUtil.create('div', className, list),\n\t\tname = DomUtil.create('span', `${className}-name`, container);\n\t\tname.id = `${className}_${Util.stamp(this)}_${++this._groupCount}`;\n\t\tname.textContent = group;\n\t\tcontainer.setAttribute('role', 'group');\n\t\tcontainer.setAttribute('aria-labelledby', name.id);\n\t\tcontainer._maplairGroup = group;\n\t\treturn container;\n\t}\n\n\t_onInputClick(e) {\n\t\t// expanding the control on mobile with a click can cause adding a layer - we don't want this\n\t\tif (this._preventClick) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst inputs = this._layerControlInputs,\n\t\taddedLayers = [],\n\t\tremovedLayers = [];\n\n\t\tthis._handlingClick = true;\n\t\tthis._clickEvent = e;\n\n\t\tfor (const input of inputs) {\n\t\t\tconst layer = this._getLayer(input.layerId).layer;\n\n\t\t\tif (input.checked) {\n\t\t\t\taddedLayers.push(layer);\n\t\t\t} else if (!input.checked) {\n\t\t\t\tremovedLayers.push(layer);\n\t\t\t}\n\t\t}\n\n\t\t// Bugfix issue 2318: Should remove all old layers before readding new ones\n\t\tfor (const layer of removedLayers) {\n\t\t\tif (this._map.hasLayer(layer)) {\n\t\t\t\tthis._map.removeLayer(layer);\n\t\t\t}\n\t\t}\n\t\tfor (const layer of addedLayers) {\n\t\t\tif (!this._map.hasLayer(layer)) {\n\t\t\t\tthis._map.addLayer(layer);\n\t\t\t}\n\t\t}\n\n\t\tthis._handlingClick = false;\n\t\tthis._clickEvent = undefined;\n\n\t\tthis._refocusOnMap(e);\n\t}\n\n\t_checkDisabledLayers() {\n\t\tconst inputs = this._layerControlInputs,\n\t\tzoom = this._map.getZoom();\n\n\t\tfor (const input of inputs) {\n\t\t\tconst layer = this._getLayer(input.layerId).layer;\n\t\t\tinput.disabled = (layer.options.minZoom !== undefined && zoom < layer.options.minZoom) ||\n\t\t\t (layer.options.maxZoom !== undefined && zoom > layer.options.maxZoom);\n\n\t\t}\n\t}\n\n\t_isCollapsible() {\n\t\treturn this.options.collapsed && !this.options.inline;\n\t}\n\n\t_expandIfNotCollapsed() {\n\t\tif (this._map && !this._isCollapsible()) {\n\t\t\tthis.expand();\n\t\t}\n\t\treturn this;\n\t}\n\n\t_expandSafely() {\n\t\tconst section = this._section;\n\t\tthis._preventClick = true;\n\t\tDomEvent.on(section, 'click', DomEvent.preventDefault);\n\t\tthis.expand();\n\t\tsetTimeout(() => {\n\t\t\tDomEvent.off(section, 'click', DomEvent.preventDefault);\n\t\t\tthis._preventClick = false;\n\t\t});\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6HA,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C,OAAO,iBAAiB;EACvB,WAAW;EACX,QAAQ;EACR,SAAS,KAAA;EACT,eAAe,KAAA;EACf,eAAe;EACf,UAAU;EACV,YAAY;EACZ,gBAAgB;EAChB,YAAY;EACZ,aAAa,QAAQ,QAAQ,OAAO,OAAO;GAC1C,OAAO,QAAQ,QAAQ,KAAM,QAAQ,QAAQ,IAAI;EAClD;CACD;;;;;;;;;;CAW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,KAAK,OAAO;EAEb,OAAO;CACR;CAEA,gBAAgB;EACf,MAAM,UAAU,KAAK;EACrB,KAAK,gBAAgB;EACrB,GAAY,SAAS,SAASE,cAAuB;EACrD,KAAK,OAAO;EACZ,iBAAiB;GAChB,IAAa,SAAS,SAASA,cAAuB;GACtD,KAAK,gBAAgB;EACtB,CAAC;CACF;AAED"}
|
|
@@ -43,14 +43,12 @@ import { CircleMarker } from "../layer/vector/CircleMarker.js";
|
|
|
43
43
|
*/
|
|
44
44
|
const svgNS = "http://www.w3.org/2000/svg";
|
|
45
45
|
var LegendControl = class LegendControl extends Control {
|
|
46
|
-
static {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
}
|
|
46
|
+
static defaultOptions = {
|
|
47
|
+
position: "bottomright",
|
|
48
|
+
collapsed: false,
|
|
49
|
+
featureCount: false,
|
|
50
|
+
bar: false
|
|
51
|
+
};
|
|
54
52
|
/**
|
|
55
53
|
* Creates a legend control.
|
|
56
54
|
* @param {...LegendControlOptions} args The options.
|
|
@@ -186,7 +184,7 @@ function formatCount({ count, share }) {
|
|
|
186
184
|
function createPatch(layer, symbol, styled) {
|
|
187
185
|
while (layer?.getLayers) layer = layer.getLayers()[0];
|
|
188
186
|
if (!layer?.setStyle) layer = void 0;
|
|
189
|
-
const base = layer?.options ?? CircleMarker.
|
|
187
|
+
const base = layer?.options ?? new CircleMarker([0, 0]).options, options = Object.assign(Object.create(base), layer && styled ? {} : symbol), svg = document.createElementNS(svgNS, "svg");
|
|
190
188
|
svg.setAttribute("class", "maplair-control-legend-patch");
|
|
191
189
|
svg.setAttribute("width", 16);
|
|
192
190
|
svg.setAttribute("height", 16);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LegendControl.js","names":["DomUtil.create"],"sources":["../../../src/control/LegendControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\nimport {CircleMarker} from '../layer/vector/CircleMarker.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {FeatureGroup} from '../layer/FeatureGroup.js' */\n/** @import {Classification} from '../layer/Classification.js' */\n\n/**\n * Options of `LegendControl`.\n * @typedef {object} LegendControlOptions\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 {boolean} [collapsed=false] If `true`, the legend starts collapsed to its\n * title, which toggles it.\n * @property {boolean} [featureCount=false] If `true`, the number of features is shown\n * per class and per classification.\n * @property {boolean} [bar=false] If `true`, the feature count of each classification\n * is shown as a bar of the class symbols, each as wide as its share.\n * @extends ControlOptions\n */\n\n/**\n * A control showing the legend of the map: the classes of the layers added with\n * [`addClassification()`](#legendcontrol-addclassification), each with a patch in the\n * shape and symbol of its features and optionally the feature count, and the\n * legends of all layers on the map implementing [`getLegend()`](#layer-getlegend),\n * like the attribution control collects [`getAttribution()`](#layer-getattribution).\n * The legend is updated when features are added to or removed from the classified\n * layers (e.g. when reloading the data) and when a layer fires `legendchange`. It\n * is collapsible and hidden while empty. Placed at the bottom right, it sits right\n * above the attribution.\n *\n * Inspired by the legend of [QGIS](https://qgis.org/).\n *\n * @example\n * ```js\n * const legend = new LegendControl({featureCount: true, bar: true}).addTo(map);\n * legend.addClassification(stations, temperature);\n * ```\n */\n\nconst svgNS = 'http://www.w3.org/2000/svg';\n\nexport class LegendControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'bottomright',\n\t\t\tcollapsed: false,\n\t\t\tfeatureCount: false,\n\t\t\tbar: false\n\t\t});\n\t}\n\n\t/**\n\t * Creates a legend control.\n\t * @param {...LegendControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis._classifications = [];\n\t\tthis._legendLayers = new Set();\n\t\tthis.callInitHooks(LegendControl);\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-control-legend'),\n\t\tdetails = this._details = DomUtil.create('details', '', container),\n\t\tsummary = DomUtil.create('summary', 'maplair-control-legend-title', details);\n\t\tsummary.textContent = I18n.translate('Legend');\n\t\tdetails.open = !this.options.collapsed;\n\t\tthis._list = DomUtil.create('div', 'maplair-control-legend-list', details);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tthis._container = container;\n\n\t\tmap.on('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._update();\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('layeradd layerremove', this._scheduleUpdate, this);\n\t\tcancelAnimationFrame(this._frame);\n\t\tthis._frame = null;\n\t\tfor (const layer of this._legendLayers) {\n\t\t\tlayer.off('legendchange', this._scheduleUpdate, this);\n\t\t}\n\t\tthis._legendLayers.clear();\n\t}\n\n\t/**\n\t * Shows the classes of `classification` in the legend while `layer` is on the map,\n\t * with the feature count of the layers of `layer` (e.g. a `GeoJSON` layer styled\n\t * with [`classification.style`](#classification-style)), kept up to date when\n\t * layers are added and removed.\n\t * @param {FeatureGroup} layer\n\t * @param {Classification} classification\n\t * @returns {this}\n\t */\n\taddClassification(layer, classification) {\n\t\tthis._classifications.push({layer, classification});\n\t\tlayer.on('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._scheduleUpdate();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the classification of `layer` from the legend.\n\t * @param {FeatureGroup} layer\n\t * @returns {this}\n\t */\n\tremoveClassification(layer) {\n\t\tthis._classifications = this._classifications.filter(entry => entry.layer !== layer);\n\t\tlayer.off('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._scheduleUpdate();\n\t\treturn this;\n\t}\n\n\t// updates once per frame, e.g. once after adding all features of a GeoJSON\n\t_scheduleUpdate() {\n\t\tif (!this._map || this._frame) { return; }\n\t\tthis._frame = requestAnimationFrame(() => {\n\t\t\tthis._frame = null;\n\t\t\tthis._update();\n\t\t});\n\t}\n\n\t_update() {\n\t\tconst map = this._map;\n\t\tif (!map) { return; }\n\n\t\tconst sections = this._classifications\n\t\t\t.filter(({layer}) => map.hasLayer(layer))\n\t\t\t.map(({layer, classification}) => this._renderClassification(layer, classification));\n\n\t\tconst legendLayers = new Set(Object.values(map._layers).filter(layer => layer.getLegend));\n\t\tfor (const layer of this._legendLayers) {\n\t\t\tif (!legendLayers.has(layer)) { layer.off('legendchange', this._scheduleUpdate, this); }\n\t\t}\n\t\tfor (const layer of legendLayers) {\n\t\t\tif (!this._legendLayers.has(layer)) { layer.on('legendchange', this._scheduleUpdate, this); }\n\t\t\tconst legend = layer.getLegend();\n\t\t\tif (legend) {\n\t\t\t\tconst section = DomUtil.create('div', 'maplair-control-legend-section');\n\t\t\t\tif (typeof legend === 'string') {\n\t\t\t\t\tsection.innerHTML = legend;\n\t\t\t\t} else {\n\t\t\t\t\tsection.append(legend);\n\t\t\t\t}\n\t\t\t\tsections.push(section);\n\t\t\t}\n\t\t}\n\t\tthis._legendLayers = legendLayers;\n\n\t\tthis._list.replaceChildren(...sections);\n\t\tthis._container.hidden = !sections.length;\n\t}\n\n\t_renderClassification(layer, classification) {\n\t\tconst layers = layer.getLayers(),\n\t\titems = classification.featureCount(layers),\n\t\t{featureCount, bar} = this.options,\n\t\tsection = DomUtil.create('div', 'maplair-control-legend-section'),\n\t\t{name} = classification.options,\n\t\ttotal = items.reduce((sum, item) => sum + (item.counted ? item.count : 0), 0);\n\n\t\tif (name) {\n\t\t\tDomUtil.create('div', 'maplair-control-legend-name', section).textContent = name;\n\t\t}\n\t\tif (featureCount) {\n\t\t\tDomUtil.create('div', 'maplair-control-legend-total', section).textContent =\n\t\t\t\tI18n.translate('{n} features', {n: total});\n\t\t}\n\n\t\t// a feature of each item, to draw its patch in the shape and style of the map\n\t\tconst samples = new Map();\n\t\tfor (const feature of layers) {\n\t\t\tconst cls = classification.classify(feature),\n\t\t\titem = items.find(i => i.classes.includes(cls));\n\t\t\tif (item && !samples.has(item)) { samples.set(item, feature); }\n\t\t\tif (samples.size === items.length) { break; }\n\t\t}\n\n\t\tconst list = DomUtil.create('ul', 'maplair-control-legend-items', section);\n\t\tfor (const item of items) {\n\t\t\tconst li = DomUtil.create('li', '', list);\n\t\t\tli.append(createPatch(samples.get(item) ?? layers[0], item.symbol, Boolean(samples.get(item))));\n\t\t\tDomUtil.create('span', 'maplair-control-legend-label', li).textContent = item.legend;\n\t\t\tif (featureCount && item.counted) {\n\t\t\t\tDomUtil.create('span', 'maplair-control-legend-count', li).textContent = formatCount(item);\n\t\t\t}\n\t\t}\n\n\t\tif (bar && total) {\n\t\t\tconst barEl = DomUtil.create('div', 'maplair-control-legend-bar', section);\n\t\t\tbarEl.setAttribute('role', 'img');\n\t\t\tbarEl.setAttribute('aria-label', items.filter(item => item.counted && item.count)\n\t\t\t\t.map(item => `${item.legend}: ${formatCount(item)}`).join(', '));\n\t\t\tfor (const item of items) {\n\t\t\t\tif (!item.counted || !item.count) { continue; }\n\t\t\t\tconst part = DomUtil.create('div', '', barEl);\n\t\t\t\tpart.style.flexGrow = item.count;\n\t\t\t\tpart.style.backgroundColor = item.symbol.fillColor ?? item.symbol.color ?? '';\n\t\t\t\tpart.title = `${item.legend}: ${formatCount(item)}`;\n\t\t\t}\n\t\t}\n\n\t\treturn section;\n\t}\n}\n\nfunction formatCount({count, share}) {\n\tconst percent = new Intl.NumberFormat(I18n.getLocale() ?? undefined, {style: 'percent', maximumFractionDigits: 1});\n\treturn `${count} (${percent.format(share)})`;\n}\n\n// a small SVG in the shape of the layer (circle, square for polygons, line for\n// polylines) with the style of the layer, or of the symbol over it if `styled` is false\n// (e.g. for a class without features); a circle marker for other layers like markers.\n// Duck-typed, so that the legend does not bundle the vector layers.\nfunction createPatch(layer, symbol, styled) {\n\twhile (layer?.getLayers) { layer = layer.getLayers()[0]; }\n\tif (!layer?.setStyle) { layer = undefined; }\n\tconst base = layer?.options ?? CircleMarker.prototype.options,\n\toptions = Object.assign(Object.create(base), layer && styled ? {} : symbol),\n\tsvg = document.createElementNS(svgNS, 'svg');\n\tsvg.setAttribute('class', 'maplair-control-legend-patch');\n\tsvg.setAttribute('width', 16);\n\tsvg.setAttribute('height', 16);\n\tsvg.setAttribute('viewBox', '0 0 16 16');\n\tsvg.setAttribute('aria-hidden', 'true');\n\n\tlet shape;\n\tif (layer?.getLatLngs && options.fill) {\n\t\tshape = svgElement('rect', {x: 2, y: 2, width: 12, height: 12});\n\t} else if (layer?.getLatLngs) {\n\t\tshape = svgElement('line', {x1: 1, y1: 8, x2: 15, y2: 8});\n\t} else {\n\t\tshape = svgElement('circle', {cx: 8, cy: 8, r: 6});\n\t}\n\n\tshape.setAttribute('fill', options.fill ? options.fillColor ?? options.color : 'none');\n\tshape.setAttribute('fill-opacity', options.fillOpacity);\n\tshape.setAttribute('stroke', options.stroke ? options.color : 'none');\n\tshape.setAttribute('stroke-opacity', options.opacity);\n\tshape.setAttribute('stroke-width', Math.min(options.weight, 4));\n\tif (options.dashArray) { shape.setAttribute('stroke-dasharray', options.dashArray); }\n\tsvg.append(shape);\n\treturn svg;\n}\n\nfunction svgElement(name, attributes) {\n\tconst el = document.createElementNS(svgNS, name);\n\tfor (const [key, value] of Object.entries(attributes)) {\n\t\tel.setAttribute(key, value);\n\t}\n\treturn el;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,QAAQ;AAEd,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C;EACC,KAAK,kBAAkB;GACtB,UAAU;GACV,WAAW;GACX,cAAc;GACd,KAAK;EACN,CAAC;CACF;;;;;CAMA,YAAY,GA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AAkB,QAAQ,OAAO;CACpD,MAAM,aAAa,gBAAgB,KAAK,IAAI,QAAQ,QAAQ,CAAC,CAAC;CAC9D,IAAI,QAAQ,WAAa,MAAM,aAAa,oBAAoB,QAAQ,SAAS;CACjF,IAAI,OAAO,KAAK;CAChB,OAAO;AACR;AAEA,SAAS,WAAW,MAAM,YAAY;CACrC,MAAM,KAAK,SAAS,gBAAgB,OAAO,IAAI;CAC/C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,GACnD,GAAG,aAAa,KAAK,KAAK;CAE3B,OAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"LegendControl.js","names":["DomUtil.create"],"sources":["../../../src/control/LegendControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\nimport {CircleMarker} from '../layer/vector/CircleMarker.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {FeatureGroup} from '../layer/FeatureGroup.js' */\n/** @import {Classification} from '../layer/Classification.js' */\n\n/**\n * Options of `LegendControl`.\n * @typedef {object} LegendControlOptions\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 {boolean} [collapsed=false] If `true`, the legend starts collapsed to its\n * title, which toggles it.\n * @property {boolean} [featureCount=false] If `true`, the number of features is shown\n * per class and per classification.\n * @property {boolean} [bar=false] If `true`, the feature count of each classification\n * is shown as a bar of the class symbols, each as wide as its share.\n * @extends ControlOptions\n */\n\n/**\n * A control showing the legend of the map: the classes of the layers added with\n * [`addClassification()`](#legendcontrol-addclassification), each with a patch in the\n * shape and symbol of its features and optionally the feature count, and the\n * legends of all layers on the map implementing [`getLegend()`](#layer-getlegend),\n * like the attribution control collects [`getAttribution()`](#layer-getattribution).\n * The legend is updated when features are added to or removed from the classified\n * layers (e.g. when reloading the data) and when a layer fires `legendchange`. It\n * is collapsible and hidden while empty. Placed at the bottom right, it sits right\n * above the attribution.\n *\n * Inspired by the legend of [QGIS](https://qgis.org/).\n *\n * @example\n * ```js\n * const legend = new LegendControl({featureCount: true, bar: true}).addTo(map);\n * legend.addClassification(stations, temperature);\n * ```\n */\n\nconst svgNS = 'http://www.w3.org/2000/svg';\n\nexport class LegendControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'bottomright',\n\t\tcollapsed: false,\n\t\tfeatureCount: false,\n\t\tbar: false\n\t};\n\n\t/**\n\t * Creates a legend control.\n\t * @param {...LegendControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis._classifications = [];\n\t\tthis._legendLayers = new Set();\n\t\tthis.callInitHooks(LegendControl);\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-control-legend'),\n\t\tdetails = this._details = DomUtil.create('details', '', container),\n\t\tsummary = DomUtil.create('summary', 'maplair-control-legend-title', details);\n\t\tsummary.textContent = I18n.translate('Legend');\n\t\tdetails.open = !this.options.collapsed;\n\t\tthis._list = DomUtil.create('div', 'maplair-control-legend-list', details);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tthis._container = container;\n\n\t\tmap.on('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._update();\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('layeradd layerremove', this._scheduleUpdate, this);\n\t\tcancelAnimationFrame(this._frame);\n\t\tthis._frame = null;\n\t\tfor (const layer of this._legendLayers) {\n\t\t\tlayer.off('legendchange', this._scheduleUpdate, this);\n\t\t}\n\t\tthis._legendLayers.clear();\n\t}\n\n\t/**\n\t * Shows the classes of `classification` in the legend while `layer` is on the map,\n\t * with the feature count of the layers of `layer` (e.g. a `GeoJSON` layer styled\n\t * with [`classification.style`](#classification-style)), kept up to date when\n\t * layers are added and removed.\n\t * @param {FeatureGroup} layer\n\t * @param {Classification} classification\n\t * @returns {this}\n\t */\n\taddClassification(layer, classification) {\n\t\tthis._classifications.push({layer, classification});\n\t\tlayer.on('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._scheduleUpdate();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the classification of `layer` from the legend.\n\t * @param {FeatureGroup} layer\n\t * @returns {this}\n\t */\n\tremoveClassification(layer) {\n\t\tthis._classifications = this._classifications.filter(entry => entry.layer !== layer);\n\t\tlayer.off('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._scheduleUpdate();\n\t\treturn this;\n\t}\n\n\t// updates once per frame, e.g. once after adding all features of a GeoJSON\n\t_scheduleUpdate() {\n\t\tif (!this._map || this._frame) { return; }\n\t\tthis._frame = requestAnimationFrame(() => {\n\t\t\tthis._frame = null;\n\t\t\tthis._update();\n\t\t});\n\t}\n\n\t_update() {\n\t\tconst map = this._map;\n\t\tif (!map) { return; }\n\n\t\tconst sections = this._classifications\n\t\t\t.filter(({layer}) => map.hasLayer(layer))\n\t\t\t.map(({layer, classification}) => this._renderClassification(layer, classification));\n\n\t\tconst legendLayers = new Set(Object.values(map._layers).filter(layer => layer.getLegend));\n\t\tfor (const layer of this._legendLayers) {\n\t\t\tif (!legendLayers.has(layer)) { layer.off('legendchange', this._scheduleUpdate, this); }\n\t\t}\n\t\tfor (const layer of legendLayers) {\n\t\t\tif (!this._legendLayers.has(layer)) { layer.on('legendchange', this._scheduleUpdate, this); }\n\t\t\tconst legend = layer.getLegend();\n\t\t\tif (legend) {\n\t\t\t\tconst section = DomUtil.create('div', 'maplair-control-legend-section');\n\t\t\t\tif (typeof legend === 'string') {\n\t\t\t\t\tsection.innerHTML = legend;\n\t\t\t\t} else {\n\t\t\t\t\tsection.append(legend);\n\t\t\t\t}\n\t\t\t\tsections.push(section);\n\t\t\t}\n\t\t}\n\t\tthis._legendLayers = legendLayers;\n\n\t\tthis._list.replaceChildren(...sections);\n\t\tthis._container.hidden = !sections.length;\n\t}\n\n\t_renderClassification(layer, classification) {\n\t\tconst layers = layer.getLayers(),\n\t\titems = classification.featureCount(layers),\n\t\t{featureCount, bar} = this.options,\n\t\tsection = DomUtil.create('div', 'maplair-control-legend-section'),\n\t\t{name} = classification.options,\n\t\ttotal = items.reduce((sum, item) => sum + (item.counted ? item.count : 0), 0);\n\n\t\tif (name) {\n\t\t\tDomUtil.create('div', 'maplair-control-legend-name', section).textContent = name;\n\t\t}\n\t\tif (featureCount) {\n\t\t\tDomUtil.create('div', 'maplair-control-legend-total', section).textContent =\n\t\t\t\tI18n.translate('{n} features', {n: total});\n\t\t}\n\n\t\t// a feature of each item, to draw its patch in the shape and style of the map\n\t\tconst samples = new Map();\n\t\tfor (const feature of layers) {\n\t\t\tconst cls = classification.classify(feature),\n\t\t\titem = items.find(i => i.classes.includes(cls));\n\t\t\tif (item && !samples.has(item)) { samples.set(item, feature); }\n\t\t\tif (samples.size === items.length) { break; }\n\t\t}\n\n\t\tconst list = DomUtil.create('ul', 'maplair-control-legend-items', section);\n\t\tfor (const item of items) {\n\t\t\tconst li = DomUtil.create('li', '', list);\n\t\t\tli.append(createPatch(samples.get(item) ?? layers[0], item.symbol, Boolean(samples.get(item))));\n\t\t\tDomUtil.create('span', 'maplair-control-legend-label', li).textContent = item.legend;\n\t\t\tif (featureCount && item.counted) {\n\t\t\t\tDomUtil.create('span', 'maplair-control-legend-count', li).textContent = formatCount(item);\n\t\t\t}\n\t\t}\n\n\t\tif (bar && total) {\n\t\t\tconst barEl = DomUtil.create('div', 'maplair-control-legend-bar', section);\n\t\t\tbarEl.setAttribute('role', 'img');\n\t\t\tbarEl.setAttribute('aria-label', items.filter(item => item.counted && item.count)\n\t\t\t\t.map(item => `${item.legend}: ${formatCount(item)}`).join(', '));\n\t\t\tfor (const item of items) {\n\t\t\t\tif (!item.counted || !item.count) { continue; }\n\t\t\t\tconst part = DomUtil.create('div', '', barEl);\n\t\t\t\tpart.style.flexGrow = item.count;\n\t\t\t\tpart.style.backgroundColor = item.symbol.fillColor ?? item.symbol.color ?? '';\n\t\t\t\tpart.title = `${item.legend}: ${formatCount(item)}`;\n\t\t\t}\n\t\t}\n\n\t\treturn section;\n\t}\n}\n\nfunction formatCount({count, share}) {\n\tconst percent = new Intl.NumberFormat(I18n.getLocale() ?? undefined, {style: 'percent', maximumFractionDigits: 1});\n\treturn `${count} (${percent.format(share)})`;\n}\n\n// a small SVG in the shape of the layer (circle, square for polygons, line for\n// polylines) with the style of the layer, or of the symbol over it if `styled` is false\n// (e.g. for a class without features); a circle marker for other layers like markers.\n// Duck-typed, so that the legend does not bundle the vector layers.\nfunction createPatch(layer, symbol, styled) {\n\twhile (layer?.getLayers) { layer = layer.getLayers()[0]; }\n\tif (!layer?.setStyle) { layer = undefined; }\n\tconst base = layer?.options ?? new CircleMarker([0, 0]).options,\n\toptions = Object.assign(Object.create(base), layer && styled ? {} : symbol),\n\tsvg = document.createElementNS(svgNS, 'svg');\n\tsvg.setAttribute('class', 'maplair-control-legend-patch');\n\tsvg.setAttribute('width', 16);\n\tsvg.setAttribute('height', 16);\n\tsvg.setAttribute('viewBox', '0 0 16 16');\n\tsvg.setAttribute('aria-hidden', 'true');\n\n\tlet shape;\n\tif (layer?.getLatLngs && options.fill) {\n\t\tshape = svgElement('rect', {x: 2, y: 2, width: 12, height: 12});\n\t} else if (layer?.getLatLngs) {\n\t\tshape = svgElement('line', {x1: 1, y1: 8, x2: 15, y2: 8});\n\t} else {\n\t\tshape = svgElement('circle', {cx: 8, cy: 8, r: 6});\n\t}\n\n\tshape.setAttribute('fill', options.fill ? options.fillColor ?? options.color : 'none');\n\tshape.setAttribute('fill-opacity', options.fillOpacity);\n\tshape.setAttribute('stroke', options.stroke ? options.color : 'none');\n\tshape.setAttribute('stroke-opacity', options.opacity);\n\tshape.setAttribute('stroke-width', Math.min(options.weight, 4));\n\tif (options.dashArray) { shape.setAttribute('stroke-dasharray', options.dashArray); }\n\tsvg.append(shape);\n\treturn svg;\n}\n\nfunction svgElement(name, attributes) {\n\tconst el = document.createElementNS(svgNS, name);\n\tfor (const [key, value] of Object.entries(attributes)) {\n\t\tel.setAttribute(key, value);\n\t}\n\treturn el;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,QAAQ;AAEd,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C,OAAO,iBAAiB;EACvB,UAAU;EACV,WAAW;EACX,cAAc;EACd,KAAK;CACN;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,mBAAmB,CAAC;EACzB,KAAK,gCAAgB,IAAI,IAAI;EAC7B,KAAK,cAAc,aAAa;CACjC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAYA,OAAe,OAAO,wBAAwB,GAChE,UAAU,KAAK,WAAWA,OAAe,WAAW,IAAI,SAAS,GACjE,UAAUA,OAAe,WAAW,gCAAgC,OAAO;EAC3E,QAAQ,cAAc,KAAK,UAAU,QAAQ;EAC7C,QAAQ,OAAO,CAAC,KAAK,QAAQ;EAC7B,KAAK,QAAQA,OAAe,OAAO,+BAA+B,OAAO;EAEzE,wBAAiC,SAAS;EAC1C,yBAAkC,SAAS;EAC3C,KAAK,aAAa;EAElB,IAAI,GAAG,wBAAwB,KAAK,iBAAiB,IAAI;EACzD,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,SAAS,KAAK;EACb,IAAI,IAAI,wBAAwB,KAAK,iBAAiB,IAAI;EAC1D,qBAAqB,KAAK,MAAM;EAChC,KAAK,SAAS;EACd,KAAK,MAAM,SAAS,KAAK,eACxB,MAAM,IAAI,gBAAgB,KAAK,iBAAiB,IAAI;EAErD,KAAK,cAAc,MAAM;CAC1B;;;;;;;;;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AI;CACJ,IAAI,OAAO,cAAc,QAAQ,MAChC,QAAQ,WAAW,QAAQ;EAAC,GAAG;EAAG,GAAG;EAAG,OAAO;EAAI,QAAQ;CAAE,CAAC;MACxD,IAAI,OAAO,YACjB,QAAQ,WAAW,QAAQ;EAAC,IAAI;EAAG,IAAI;EAAG,IAAI;EAAI,IAAI;CAAC,CAAC;MAExD,QAAQ,WAAW,UAAU;EAAC,IAAI;EAAG,IAAI;EAAG,GAAG;CAAC,CAAC;CAGlD,MAAM,aAAa,QAAQ,QAAQ,OAAO,QAAQ,aAAa,QAAQ,QAAQ,MAAM;CACrF,MAAM,aAAa,gBAAgB,QAAQ,WAAW;CACtD,MAAM,aAAa,UAAU,QAAQ,SAAS,QAAQ,QAAQ,MAAM;CACpE,MAAM,aAAa,kBAAkB,QAAQ,OAAO;CACpD,MAAM,aAAa,gBAAgB,KAAK,IAAI,QAAQ,QAAQ,CAAC,CAAC;CAC9D,IAAI,QAAQ,WAAa,MAAM,aAAa,oBAAoB,QAAQ,SAAS;CACjF,IAAI,OAAO,KAAK;CAChB,OAAO;AACR;AAEA,SAAS,WAAW,MAAM,YAAY;CACrC,MAAM,KAAK,SAAS,gBAAgB,OAAO,IAAI;CAC/C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,GACnD,GAAG,aAAa,KAAK,KAAK;CAE3B,OAAO;AACR"}
|
|
@@ -2,7 +2,7 @@ import { disableClickPropagation, disableScrollPropagation, on, stop } from "../
|
|
|
2
2
|
import { create } from "../dom/DomUtil.js";
|
|
3
3
|
import { Control } from "./Control.js";
|
|
4
4
|
import { I18n } from "../core/I18n.js";
|
|
5
|
-
import { MaplairMap } from "../map/Map.js";
|
|
5
|
+
import { LeafletMap as MaplairMap } from "../map/Map.js";
|
|
6
6
|
import { Polygon } from "../layer/vector/Polygon.js";
|
|
7
7
|
//#region src/control/MiniMapControl.js
|
|
8
8
|
/** @import {ControlOptions} from './Control.js' */
|
|
@@ -41,21 +41,19 @@ import { Polygon } from "../layer/vector/Polygon.js";
|
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
43
|
var MiniMapControl = class MiniMapControl extends Control {
|
|
44
|
-
static {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
}
|
|
44
|
+
static defaultOptions = {
|
|
45
|
+
position: "bottomright",
|
|
46
|
+
width: 150,
|
|
47
|
+
height: 150,
|
|
48
|
+
zoomOffset: -5,
|
|
49
|
+
collapsed: false,
|
|
50
|
+
rectangleOptions: {
|
|
51
|
+
color: "#ff7800",
|
|
52
|
+
weight: 1,
|
|
53
|
+
fillOpacity: .2
|
|
54
|
+
},
|
|
55
|
+
mapOptions: {}
|
|
56
|
+
};
|
|
59
57
|
/**
|
|
60
58
|
* Creates an overview map control showing `layer` (which must not be on another map).
|
|
61
59
|
* @param {Layer} layer
|