maplair 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +178 -0
- package/dist/esm/Maplair.js +18 -17
- package/dist/esm/Maplair.js.map +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
- package/dist/esm/control/AttributionControl.js +25 -16
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +10 -13
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +2 -5
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +10 -18
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +6 -9
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +170 -65
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +8 -11
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +15 -18
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +2 -5
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +8 -11
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +100 -19
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +2 -5
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +6 -9
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +407 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +23 -36
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -44
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +22 -10
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +23 -14
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/I18n.js +1 -2
- package/dist/esm/core/Util.js +15 -4
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +26 -24
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +3 -18
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +18 -60
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +15 -70
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +21 -21
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +4 -27
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +16 -7
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +9 -15
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +1 -2
- package/dist/esm/geo/crs/EPSG3395.js +5 -6
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +5 -6
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +4 -5
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +3 -4
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +4 -5
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +5 -6
- package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +4 -5
- package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +5 -6
- package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
- package/dist/esm/geometry/Bounds.js +10 -14
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +37 -32
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +1 -2
- package/dist/esm/geometry/PolyUtil.js +24 -51
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -2
- package/dist/esm/layer/BlanketOverlay.js +7 -10
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/Classification.js +1 -2
- package/dist/esm/layer/DivOverlay.js +16 -22
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/FeatureGroup.js +5 -4
- package/dist/esm/layer/FeatureGroup.js.map +1 -1
- package/dist/esm/layer/GeoJSON.Load.js +1 -2
- package/dist/esm/layer/GeoJSON.js +17 -155
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +74 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +17 -20
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +22 -29
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +9 -12
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +53 -3
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +35 -58
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +3 -7
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +31 -34
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +13 -17
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +38 -49
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +8 -11
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +9 -12
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +44 -5
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +5 -8
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +115 -47
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +301 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +7 -10
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +89 -101
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +36 -44
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +33 -27
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +8 -17
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +6 -5
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +19 -10
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +3 -5
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
- package/dist/esm/layer/vector/Path.js +28 -22
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +22 -7
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +3 -4
- package/dist/esm/layer/vector/Polyline.js +25 -10
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Rectangle.js +1 -2
- package/dist/esm/layer/vector/Renderer.getRenderer.js +17 -17
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +1 -2
- package/dist/esm/layer/vector/SVG.js +12 -9
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Hash.js +1 -2
- package/dist/esm/map/Map.Rotation.js +41 -22
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +125 -126
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -2
- package/dist/esm/map/handler/BoxZoomHandler.js +25 -47
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +7 -10
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
- package/dist/esm/map/handler/DragHandler.js +20 -21
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +48 -68
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +13 -5
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -6
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
- package/dist/esm/map/handler/TapHoldHandler.js +13 -7
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +2 -3
- package/dist/maplair-global-src.js +6495 -5981
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +6206 -5673
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1213
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/cs.json +6 -0
- package/i18n/de.json +6 -0
- package/i18n/en.json +6 -0
- package/i18n/es.json +6 -0
- package/i18n/fr.json +6 -0
- package/i18n/hu.json +6 -0
- package/i18n/it.json +6 -0
- package/i18n/rm.json +6 -0
- package/i18n/sk.json +6 -0
- package/i18n/sl.json +6 -0
- package/package.json +11 -18
- package/src/Maplair.all.js +0 -1
- package/src/control/AttributionControl.js +25 -18
- package/src/control/ButtonControl.js +9 -11
- package/src/control/ContextMenu.js +3 -5
- package/src/control/Control.js +9 -19
- package/src/control/FullscreenControl.js +5 -7
- package/src/control/LayersControl.js +196 -86
- package/src/control/LegendControl.js +7 -9
- package/src/control/MiniMapControl.js +9 -11
- package/src/control/RotateControl.js +3 -5
- package/src/control/ScaleControl.js +7 -9
- package/src/control/SearchControl.js +102 -19
- package/src/control/SideBySideControl.js +3 -5
- package/src/control/TextControl.js +5 -7
- package/src/control/TimeControl.js +471 -0
- package/src/control/ZoomControl.js +22 -38
- package/src/control/index.js +1 -0
- package/src/core/Class.js +37 -45
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +25 -13
- package/src/core/Util.js +20 -2
- package/src/core/index.js +0 -1
- package/src/dom/DomEvent.DoubleTap.js +18 -10
- package/src/dom/DomEvent.PointerEvents.js +3 -26
- package/src/dom/DomEvent.js +17 -85
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +32 -23
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +20 -3
- package/src/geo/LatLngBounds.js +8 -15
- package/src/geo/crs/EPSG3395.js +4 -4
- package/src/geo/crs/EPSG3857.js +4 -4
- package/src/geo/crs/EPSG4326.js +3 -3
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +3 -3
- package/src/geo/index.js +1 -2
- package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +2 -2
- package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +2 -2
- package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +2 -2
- package/src/geo/projection/index.js +5 -5
- package/src/geometry/Bounds.js +12 -17
- package/src/geometry/LineUtil.js +48 -49
- package/src/geometry/PolyUtil.js +39 -76
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +16 -27
- package/src/layer/FeatureGroup.js +8 -2
- package/src/layer/GeoJSON.js +17 -218
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +10 -12
- package/src/layer/ImageOverlay.js +21 -32
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +72 -1
- package/src/layer/Popup.js +37 -62
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +34 -36
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +40 -58
- package/src/layer/marker/DivIcon.js +9 -11
- package/src/layer/marker/Icon.js +9 -10
- package/src/layer/marker/Marker.Drag.js +54 -6
- package/src/layer/marker/Marker.Move.js +4 -6
- package/src/layer/marker/Marker.js +145 -52
- package/src/layer/marker/MarkerClusterGroup.js +370 -0
- package/src/layer/marker/SvgIcon.js +7 -9
- package/src/layer/marker/index.js +1 -0
- package/src/layer/tile/GridLayer.js +108 -135
- package/src/layer/tile/TileLayer.js +44 -49
- package/src/layer/tile/WMSTileLayer.js +31 -26
- package/src/layer/vector/Canvas.js +13 -19
- package/src/layer/vector/Circle.js +9 -3
- package/src/layer/vector/CircleMarker.js +19 -7
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +29 -6
- package/src/layer/vector/Polyline.js +26 -7
- package/src/layer/vector/Renderer.getRenderer.js +20 -19
- package/src/layer/vector/SVG.js +17 -7
- package/src/map/Map.Rotation.js +40 -8
- package/src/map/Map.js +158 -153
- package/src/map/handler/BoxZoomHandler.js +30 -50
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +25 -28
- package/src/map/handler/KeyboardHandler.js +65 -90
- package/src/map/handler/PinchZoomHandler.js +16 -5
- package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
- package/src/map/handler/TapHoldHandler.js +15 -4
- package/src/map/index.js +1 -1
- package/src/maplair.css +153 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
- package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
- package/dist/esm/geo/projection/index.js +0 -14
- package/dist/esm/geo/projection/index.js.map +0 -1
- package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
- package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
- package/dist/images/layers.svg +0 -1
- package/dist/images/marker-icon.svg +0 -1
- package/dist/images/marker-shadow.svg +0 -1
- package/src/core/Browser.js +0 -110
- package/src/images/layers.svg +0 -1
- package/src/images/marker-icon.svg +0 -1
- package/src/images/marker-shadow.svg +0 -1
- package/src/layer/marker/Marker.Rotation.js +0 -103
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/ContextMenu.js"],"sourcesContent":["import {Class} from '../core/Class.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Layer} from '../layer/Layer.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {Point} from '../geometry/Point.js' */\n\n/**\n * Options of `ContextMenu`.\n * @typedef {object} ContextMenuOptions\n * @property {string} [className=''] A custom CSS class name to assign to the menu.\n */\n\n/**\n * The argument of the `callback` of a `ContextMenu` item, with the location of the\n * `contextmenu` event.\n * @typedef {object} ContextMenuEvent\n * @property {LatLng} latlng The geographical point of the event.\n * @property {Point} containerPoint Pixel coordinates of the event relative to the map\n * container.\n * @property {Point} layerPoint Pixel coordinates of the event relative to the map layer.\n * @property {MouseEvent|PointerEvent} originalEvent The original DOM event.\n * @property {Layer} [relatedTarget] The layer, for menus of layers.\n */\n\n/**\n * An item of a `ContextMenu`.\n * @typedef {object} ContextMenuItem\n * @property {string} text The text of the item.\n * @property {(this: ContextMenu, event: ContextMenuEvent) => void} [callback] Called\n * when the item is chosen.\n * @property {boolean} [disabled] Whether the item is disabled.\n */\n\n/**\n * A menu opened with the `contextmenu` event (right click, or long tap on touch\n * screens) on the map or on a layer. Each item calls a function with the location\n * of the event. The menu is a [popover](https://developer.mozilla.org/docs/Web/API/Popover_API),\n * closed by clicking outside of it or pressing Escape, and can be used with the\n * keyboard (arrow keys, Enter).\n *\n * Inspired by the [Leaflet.contextmenu](https://github.com/aratcliffe/Leaflet.contextmenu) plugin.\n *\n * @example\n * ```js\n * new ContextMenu([\n * \t{text: 'Center the map here', callback: e => map.panTo(e.latlng)},\n * \t'-',\n * \t{text: 'Zoom in', callback: () => map.zoomIn()}\n * ]).addTo(map);\n *\n * new ContextMenu([\n * \t{text: 'Remove', callback: e => e.relatedTarget.remove()}\n * ]).addTo(marker);\n * ```\n */\nexport class ContextMenu extends Class {\n\n\tstatic {\n\t\
|
|
1
|
+
{"version":3,"file":"ContextMenu.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/ContextMenu.js"],"sourcesContent":["import {Class} from '../core/Class.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Layer} from '../layer/Layer.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {Point} from '../geometry/Point.js' */\n\n/**\n * Options of `ContextMenu`.\n * @typedef {object} ContextMenuOptions\n * @property {string} [className=''] A custom CSS class name to assign to the menu.\n */\n\n/**\n * The argument of the `callback` of a `ContextMenu` item, with the location of the\n * `contextmenu` event.\n * @typedef {object} ContextMenuEvent\n * @property {LatLng} latlng The geographical point of the event.\n * @property {Point} containerPoint Pixel coordinates of the event relative to the map\n * container.\n * @property {Point} layerPoint Pixel coordinates of the event relative to the map layer.\n * @property {MouseEvent|PointerEvent} originalEvent The original DOM event.\n * @property {Layer} [relatedTarget] The layer, for menus of layers.\n */\n\n/**\n * An item of a `ContextMenu`.\n * @typedef {object} ContextMenuItem\n * @property {string} text The text of the item.\n * @property {(this: ContextMenu, event: ContextMenuEvent) => void} [callback] Called\n * when the item is chosen.\n * @property {boolean} [disabled] Whether the item is disabled.\n */\n\n/**\n * A menu opened with the `contextmenu` event (right click, or long tap on touch\n * screens) on the map or on a layer. Each item calls a function with the location\n * of the event. The menu is a [popover](https://developer.mozilla.org/docs/Web/API/Popover_API),\n * closed by clicking outside of it or pressing Escape, and can be used with the\n * keyboard (arrow keys, Enter).\n *\n * Inspired by the [Leaflet.contextmenu](https://github.com/aratcliffe/Leaflet.contextmenu) plugin.\n *\n * @example\n * ```js\n * new ContextMenu([\n * \t{text: 'Center the map here', callback: e => map.panTo(e.latlng)},\n * \t'-',\n * \t{text: 'Zoom in', callback: () => map.zoomIn()}\n * ]).addTo(map);\n *\n * new ContextMenu([\n * \t{text: 'Remove', callback: e => e.relatedTarget.remove()}\n * ]).addTo(marker);\n * ```\n */\nexport class ContextMenu extends Class {\n\n\tstatic defaultOptions = {\n\t\tclassName: ''\n\t};\n\n\t/**\n\t * Creates a context menu. Each item is an object with `text`, `callback` and the\n\t * optional `disabled`, or `'-'` for a separator. The `callback` gets an event with\n\t * `latlng`, `containerPoint`, `layerPoint`, `originalEvent` and `relatedTarget`\n\t * (the layer, for menus of layers).\n\t * @param {(ContextMenuItem|'-')[]} items\n\t * @param {ContextMenuOptions} [options]\n\t */\n\tconstructor(items, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._items = items;\n\t\tthis.callInitHooks(ContextMenu);\n\t}\n\n\t/**\n\t * Opens the menu on `contextmenu` events of the map or the layer.\n\t * @param {MaplairMap|Layer} target\n\t * @returns {this}\n\t */\n\taddTo(target) {\n\t\tthis.remove();\n\t\tthis._target = target;\n\t\ttarget.on('contextmenu', this._open, this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the menu from its map or layer.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\tthis.close();\n\t\tthis._target?.off('contextmenu', this._open, this);\n\t\tthis._target = null;\n\t\tthis._container?.remove();\n\t\tthis._container = null;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the menu.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tif (this._container?.matches(':popover-open')) {\n\t\t\tthis._container.hidePopover();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` if the menu is open.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._container?.matches(':popover-open');\n\t}\n\n\t_open(e) {\n\t\t// a menu of a layer replaces the one of the map\n\t\tDomEvent.stop(e);\n\t\tconst map = this._target instanceof Layer ? this._target._map : this._target;\n\t\tif (!map) { return; }\n\n\t\tthis._map = map;\n\t\tthis._event = {\n\t\t\tlatlng: e.latlng,\n\t\t\tcontainerPoint: e.containerPoint,\n\t\t\tlayerPoint: e.layerPoint,\n\t\t\toriginalEvent: e.originalEvent,\n\t\t\trelatedTarget: this._target instanceof Layer ? this._target : undefined\n\t\t};\n\n\t\tconst container = this._createMenu(map._container);\n\t\tif (!container.matches(':popover-open')) {\n\t\t\tcontainer.showPopover();\n\t\t}\n\t\tthis._position(e.originalEvent);\n\t\tcontainer.querySelector('button:not([disabled])')?.focus({preventScroll: true});\n\t\tmap.once('movestart', this.close, this);\n\t}\n\n\t_createMenu(parent) {\n\t\tconst container = this._container ??= DomUtil.create('div', `maplair-contextmenu ${this.options.className}`);\n\t\tif (container.parentNode !== parent) {\n\t\t\tparent.appendChild(container);\n\t\t}\n\t\tcontainer.popover = 'auto';\n\t\tcontainer.setAttribute('role', 'menu');\n\t\tcontainer.replaceChildren();\n\n\t\tfor (const item of this._items) {\n\t\t\tif (item === '-') {\n\t\t\t\tDomUtil.create('div', 'maplair-contextmenu-separator', container).setAttribute('role', 'separator');\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst button = DomUtil.create('button', 'maplair-contextmenu-item', container);\n\t\t\tbutton.type = 'button';\n\t\t\tbutton.setAttribute('role', 'menuitem');\n\t\t\tbutton.textContent = item.text;\n\t\t\tbutton.disabled = !!item.disabled;\n\t\t\tDomEvent.on(button, 'click', (ev) => {\n\t\t\t\tDomEvent.stop(ev);\n\t\t\t\tthis.close();\n\t\t\t\titem.callback?.call(this, this._event);\n\t\t\t});\n\t\t}\n\n\t\tDomEvent.on(container, 'keydown', this._onKeyDown, this);\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tDomEvent.on(container, 'contextmenu', DomEvent.stop);\n\t\treturn container;\n\t}\n\n\t// At the pointer, within the viewport\n\t_position(e) {\n\t\tconst container = this._container,\n\t\tviewport = document.documentElement,\n\t\tx = Math.min(e.clientX, viewport.clientWidth - container.offsetWidth),\n\t\ty = Math.min(e.clientY, viewport.clientHeight - container.offsetHeight);\n\t\tcontainer.style.left = `${Math.max(0, x)}px`;\n\t\tcontainer.style.top = `${Math.max(0, y)}px`;\n\t}\n\n\t_onKeyDown(e) {\n\t\tif (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') { return; }\n\t\tDomEvent.stop(e);\n\t\tconst buttons = [...this._container.querySelectorAll('button:not([disabled])')],\n\t\tindex = buttons.indexOf(document.activeElement),\n\t\tnext = e.key === 'ArrowD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AAc,CAAC;EACf,MAAM,UAAU,CAAC,GAAG,KAAK,WAAW,iBAAiB,wBAAwB,CAAC,GAC9E,QAAQ,QAAQ,QAAQ,SAAS,aAAa,GAC9C,OAAO,EAAE,QAAQ,cAAc,QAAQ,IAAI,QAAQ;EACnD,QAAQ,GAAG,OAAO,QAAQ,MAAM,CAAC,EAAE,MAAM;CAC1C;AACD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setOptions } from "../core/Util.js";
|
|
2
2
|
import { Class } from "../core/Class.js";
|
|
3
3
|
import { create } from "../dom/DomUtil.js";
|
|
4
|
-
|
|
4
|
+
// src/control/Control.js
|
|
5
5
|
/** @import {MaplairMap} from '../map/Map.js' */
|
|
6
6
|
/**
|
|
7
7
|
* Options of `Control`, inherited by all controls.
|
|
@@ -40,17 +40,9 @@ const mapControlMethods = {
|
|
|
40
40
|
},
|
|
41
41
|
_initControlPos() {
|
|
42
42
|
const corners = this._controlCorners = {}, l = "maplair-", container = this._controlContainer = create("div", `${l}control-container`, this._container);
|
|
43
|
-
|
|
44
|
-
const className = `${l + vSide} ${l}${hSide}`;
|
|
45
|
-
corners[vSide + hSide] = create("div", className, container);
|
|
46
|
-
}
|
|
47
|
-
createCorner("top", "left");
|
|
48
|
-
createCorner("top", "right");
|
|
49
|
-
createCorner("bottom", "left");
|
|
50
|
-
createCorner("bottom", "right");
|
|
43
|
+
for (const v of ["top", "bottom"]) for (const h of ["left", "right"]) corners[v + h] = create("div", `${l + v} ${l}${h}`, container);
|
|
51
44
|
},
|
|
52
45
|
_clearControlPos() {
|
|
53
|
-
for (const c of Object.values(this._controlCorners)) c.remove();
|
|
54
46
|
this._controlContainer.remove();
|
|
55
47
|
delete this._controlCorners;
|
|
56
48
|
delete this._controlContainer;
|
|
@@ -83,12 +75,10 @@ const controlOrders = /* @__PURE__ */ new WeakMap();
|
|
|
83
75
|
* [`control.remove()`](#control-remove).
|
|
84
76
|
*/
|
|
85
77
|
var Control = class Control extends Class {
|
|
86
|
-
static {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
91
|
-
}
|
|
78
|
+
static defaultOptions = {
|
|
79
|
+
position: "topright",
|
|
80
|
+
order: 0
|
|
81
|
+
};
|
|
92
82
|
/**
|
|
93
83
|
* @param {ControlOptions} [options]
|
|
94
84
|
*/
|
|
@@ -152,7 +142,10 @@ var Control = class Control extends Class {
|
|
|
152
142
|
return this;
|
|
153
143
|
}
|
|
154
144
|
_refocusOnMap(e) {
|
|
155
|
-
if (this._map && e && !(e.screenX === 0 && e.screenY === 0)) this._map.getContainer().focus(
|
|
145
|
+
if (this._map && e && !(e.screenX === 0 && e.screenY === 0)) this._map.getContainer().focus({
|
|
146
|
+
preventScroll: true,
|
|
147
|
+
focusVisible: false
|
|
148
|
+
});
|
|
156
149
|
}
|
|
157
150
|
/**
|
|
158
151
|
* Registers this default feature on the map class, called by `MaplairMap` itself.
|
|
@@ -163,7 +156,6 @@ var Control = class Control extends Class {
|
|
|
163
156
|
MaplairMap.include(mapControlMethods);
|
|
164
157
|
}
|
|
165
158
|
};
|
|
166
|
-
//#endregion
|
|
167
159
|
export { Control };
|
|
168
160
|
|
|
169
161
|
//# sourceMappingURL=Control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Control.js","names":["DomUtil.create"],"sources":["../../../src/control/Control.js"],"sourcesContent":["import {Class} from '../core/Class.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Options of `Control`, inherited by all controls.\n * @typedef {object} ControlOptions\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 {number} [order=0] The position of the control within its corner: controls\n * with a lower order are closer to the corner of the map, those with the same order in\n * the order of adding.\n */\n\n/**\n * Methods of `MaplairMap` for controls.\n * @lends MaplairMap.prototype\n */\nconst mapControlMethods = {\n\t/**\n\t * Adds the given control to the map.\n\t * @group Methods for layers and controls\n\t * @param {Control} control\n\t * @returns {this}\n\t */\n\taddControl(control) {\n\t\tcontrol.addTo(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the given control from the map.\n\t * @group Methods for layers and controls\n\t * @param {Control} control\n\t * @returns {this}\n\t */\n\tremoveControl(control) {\n\t\tcontrol.remove();\n\t\treturn this;\n\t},\n\n\t_initControlPos() {\n\t\tconst corners = this._controlCorners = {},\n\t\tl = 'maplair-',\n\t\tcontainer = this._controlContainer = DomUtil.create('div', `${l}control-container`, this._container);\n\n\t\
|
|
1
|
+
{"version":3,"file":"Control.js","names":["DomUtil.create"],"sources":["../../../src/control/Control.js"],"sourcesContent":["import {Class} from '../core/Class.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Options of `Control`, inherited by all controls.\n * @typedef {object} ControlOptions\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 {number} [order=0] The position of the control within its corner: controls\n * with a lower order are closer to the corner of the map, those with the same order in\n * the order of adding.\n */\n\n/**\n * Methods of `MaplairMap` for controls.\n * @lends MaplairMap.prototype\n */\nconst mapControlMethods = {\n\t/**\n\t * Adds the given control to the map.\n\t * @group Methods for layers and controls\n\t * @param {Control} control\n\t * @returns {this}\n\t */\n\taddControl(control) {\n\t\tcontrol.addTo(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the given control from the map.\n\t * @group Methods for layers and controls\n\t * @param {Control} control\n\t * @returns {this}\n\t */\n\tremoveControl(control) {\n\t\tcontrol.remove();\n\t\treturn this;\n\t},\n\n\t_initControlPos() {\n\t\tconst corners = this._controlCorners = {},\n\t\tl = 'maplair-',\n\t\tcontainer = this._controlContainer = DomUtil.create('div', `${l}control-container`, this._container);\n\n\t\tfor (const v of ['top', 'bottom']) {\n\t\t\tfor (const h of ['left', 'right']) {\n\t\t\t\tcorners[v + h] = DomUtil.create('div', `${l + v} ${l}${h}`, container);\n\t\t\t}\n\t\t}\n\t},\n\n\t_clearControlPos() {\n\t\tthis._controlContainer.remove();\n\t\tdelete this._controlCorners;\n\t\tdelete this._controlContainer;\n\t}\n};\n/** @typedef {typeof mapControlMethods} MapControlMethods */\n\n/**\n * The methods which controls implement, see `Control`.\n * @typedef {object} ControlExtensionMethods\n * @property {(map: MaplairMap) => HTMLElement} [onAdd] Should return the container DOM\n * element for the control and add listeners on relevant map events. Called on\n * [`control.addTo(map)`](#control-addto).\n * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that\n * removes the listeners previously added in `onAdd`. Called on\n * [`control.remove()`](#control-remove).\n * @lends Control\n */\n\n// The `order` option of the containers of added controls\nconst controlOrders = new WeakMap();\n\n/**\n * Control is a base class for implementing map controls. Handles positioning.\n * All other controls extend from this class.\n *\n * Every control should extend from `Control` and (re-)implement the following methods:\n *\n * * `onAdd(map: MaplairMap): HTMLElement` should return the container DOM element for\n * the control and add listeners on relevant map events. Called on\n * [`control.addTo(map)`](#control-addTo).\n * * `onRemove(map: MaplairMap)` (optional) should contain all clean up code that removes\n * the listeners previously added in [`onAdd`](#control-onadd). Called on\n * [`control.remove()`](#control-remove).\n */\nexport class Control extends Class {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topright',\n\t\torder: 0\n\t};\n\n\t/**\n\t * @param {ControlOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(Control);\n\t}\n\n\t/**\n\t * Returns the position of the control.\n\t * @returns {string}\n\t */\n\tgetPosition() {\n\t\treturn this.options.position;\n\t}\n\n\t/**\n\t * Sets the position of the control.\n\t * @param {string} position\n\t * @returns {this}\n\t */\n\tsetPosition(position) {\n\t\tconst map = this._map;\n\n\t\tmap?.removeControl(this);\n\n\t\tthis.options.position = position;\n\n\t\tmap?.addControl(this);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTMLElement that contains the control.\n\t * @returns {HTMLElement}\n\t */\n\tgetContainer() {\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\tthis.remove();\n\t\tthis._map = map;\n\n\t\tconst container = this._container = this.onAdd(map),\n\t\tpos = this.getPosition(),\n\t\tcorner = map._controlCorners[pos];\n\n\t\tcontainer.classList.add('maplair-control');\n\n\t\t// sorted by order from the corner of the map (bottom corners are filled upwards),\n\t\t// farther than the controls with the same order\n\t\tconst order = this.options.order ?? 0,\n\t\tbottom = pos.includes('bottom'),\n\t\tchildren = [...corner.children];\n\t\tcontrolOrders.set(container, order);\n\t\tcorner.insertBefore(container, children.find(el => bottom ?\n\t\t\t(controlOrders.get(el) ?? 0) <= order :\n\t\t\t(controlOrders.get(el) ?? 0) > order) ?? null);\n\n\t\tthis._map.on('unload', this.remove, this);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the control from the map it is currently active on.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\tif (!this._map) {\n\t\t\treturn this;\n\t\t}\n\n\t\tthis._container.remove();\n\n\t\tif (this.onRemove) {\n\t\t\tthis.onRemove(this._map);\n\t\t}\n\n\t\tthis._map.off('unload', this.remove, this);\n\t\tthis._map = null;\n\n\t\treturn this;\n\t}\n\n\t_refocusOnMap(e) {\n\t\t// We exclude keyboard-click event to keep the focus on the control for accessibility.\n\t\t// The position of keyboard-click events are x=0 and y=0.\n\t\tif (this._map && e && !(e.screenX === 0 && e.screenY === 0)) {\n\t\t\tthis._map.getContainer().focus({preventScroll: true, focusVisible: false});\n\t\t}\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\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IAAI,gBAAgB;EAE7B,UAAU,UAAU,IAAI,iBAAiB;EAIzC,MAAM,QAAQ,KAAK,QAAQ,SAAS,GACpC,SAAS,IAAI,SAAS,QAAQ,GAC9B,WAAW,CAAC,GAAG,OAAO,QAAQ;EAC9B,cAAc,IAAI,WAAW,KAAK;EAClC,OAAO,aAAa,WAAW,SAAS,MAAK,OAAM,UACjD,cAAc,IAAI,EAAE,KAAK,MAAM,SAC/B,cAAc,IAAI,EAAE,KAAK,KAAK,KAAK,KAAK,IAAI;EAE9C,KAAK,KAAK,GAAG,UAAU,KAAK,QAAQ,IAAI;EAExC,OAAO;CACR;;;;;CAMA,SAAS;EACR,IAAI,CAAC,KAAK,MACT,OAAO;EAGR,KAAK,WAAW,OAAO;EAEvB,IAAI,KAAK,UACR,KAAK,SAAS,KAAK,IAAI;EAGxB,KAAK,KAAK,IAAI,UAAU,KAAK,QAAQ,IAAI;EACzC,KAAK,OAAO;EAEZ,OAAO;CACR;CAEA,cAAc,GAAG;EAGhB,IAAI,KAAK,QAAQ,KAAK,EAAE,EAAE,YAAY,KAAK,EAAE,YAAY,IACxD,KAAK,KAAK,aAAa,CAAC,CAAC,MAAM;GAAC,eAAe;GAAM,cAAc;EAAK,CAAC;CAE3E;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,iBAAiB;CACrC;AACD"}
|
|
@@ -2,7 +2,7 @@ import { disableClickPropagation, off, on, stop } from "../dom/DomEvent.js";
|
|
|
2
2
|
import { create } from "../dom/DomUtil.js";
|
|
3
3
|
import { Control } from "./Control.js";
|
|
4
4
|
import { I18n } from "../core/I18n.js";
|
|
5
|
-
|
|
5
|
+
// src/control/FullscreenControl.js
|
|
6
6
|
/** @import {ControlOptions} from './Control.js' */
|
|
7
7
|
/** @import {MaplairMap} from '../map/Map.js' */
|
|
8
8
|
/** @import {MaplairEvent} from '../core/Events.js' */
|
|
@@ -107,13 +107,11 @@ const mapFullscreenMethods = {
|
|
|
107
107
|
* ```
|
|
108
108
|
*/
|
|
109
109
|
var FullscreenControl = class FullscreenControl extends Control {
|
|
110
|
-
static {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
}
|
|
110
|
+
static defaultOptions = {
|
|
111
|
+
position: "topleft",
|
|
112
|
+
enterText: enterIcon,
|
|
113
|
+
exitText: exitIcon
|
|
114
|
+
};
|
|
117
115
|
/**
|
|
118
116
|
* Creates a fullscreen control.
|
|
119
117
|
* @param {...FullscreenControlOptions} args The options.
|
|
@@ -180,7 +178,6 @@ var FullscreenControl = class FullscreenControl extends Control {
|
|
|
180
178
|
});
|
|
181
179
|
}
|
|
182
180
|
};
|
|
183
|
-
//#endregion
|
|
184
181
|
export { FullscreenControl };
|
|
185
182
|
|
|
186
183
|
//# sourceMappingURL=FullscreenControl.js.map
|
|
@@ -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,KAAK,qBAAqB,IAAI;GACxE,UAAU,kBAAkB,CAAC,CAAC,YAAY;IACzC,IAAa,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;IACzE,KAAK,eAAe,QAAQ;GAC7B,CAAC;EACF,OACC,KAAK,eAAe,QAAQ;EAE7B,OAAO;CACR;;;;;;CAOA,eAAe;EACd,OAAO,CAAC,CAAC,KAAK;CACf;CAEA,sBAAsB;EACrB,MAAM,aAAa,SAAS,sBAAsB,KAAK;EACvD,IAAI,CAAC,YACJ,IAAa,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;EAE1E,IAAI,eAAe,KAAK,a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1C,QAAQ,aAAa,KAAK,UAAU,iBAAiB,IAAI,KAAK,UAAU,iBAAiB;EAEzF,KAAK,QAAQ,YAAY,aAAa,KAAK,QAAQ,WAAW,KAAK,QAAQ;EAC3E,KAAK,QAAQ,QAAQ;EACrB,KAAK,QAAQ,aAAa,cAAc,KAAK;EAC7C,KAAK,QAAQ,aAAa,gBAAgB,UAAU;CACrD;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,mBAAmB,MACpB,CAAC;EAED,WAAW,QAAQ,oBAAoB;EAEvC,WAAW,YAAY,WAAY;GAClC,KAAK,GAAG,UAAU,WAAY;IAC7B,IAAI,KAAK,gBAAgB,UAAU;KAClC,IAAa,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;KACzE,SAAS,eAAe;IACzB;IACA,KAAK,WAAW,UAAU,OAAO,sBAAsB,2BAA2B;IAClF,IAAa,UAAU,WAAW,KAAK,sBAAsB,IAAI;IACjE,KAAK,cAAc;GACpB,CAAC;GAED,IAAI,KAAK,QAAQ,mBAAmB;IACnC,KAAK,oBAAoB,IAAI,kBAAkB;IAC/C,KAAK,WAAW,KAAK,iBAAiB;GACvC;EACD,CAAC;CACF;AACD"}
|
|
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 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,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,KAAK,qBAAqB,IAAI;GACxE,UAAU,kBAAkB,CAAC,CAAC,YAAY;IACzC,IAAa,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;IACzE,KAAK,eAAe,QAAQ;GAC7B,CAAC;EACF,OACC,KAAK,eAAe,QAAQ;EAE7B,OAAO;CACR;;;;;;CAOA,eAAe;EACd,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S,KAAK;EACb,IAAI,IAAI,oBAAoB,KAAK,SAAS,IAAI;CAC/C;CAEA,oBAAoB;EACnB,KAAK,KAAK,iBAAiB;CAC5B;CAEA,UAAU;EACT,MAAM,aAAa,KAAK,KAAK,aAAa,GAC1C,QAAQ,aAAa,KAAK,UAAU,iBAAiB,IAAI,KAAK,UAAU,iBAAiB;EAEzF,KAAK,QAAQ,YAAY,aAAa,KAAK,QAAQ,WAAW,KAAK,QAAQ;EAC3E,KAAK,QAAQ,QAAQ;EACrB,KAAK,QAAQ,aAAa,cAAc,KAAK;EAC7C,KAAK,QAAQ,aAAa,gBAAgB,UAAU;CACrD;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,mBAAmB,MACpB,CAAC;EAED,WAAW,QAAQ,oBAAoB;EAEvC,WAAW,YAAY,WAAY;GAClC,KAAK,GAAG,UAAU,WAAY;IAC7B,IAAI,KAAK,gBAAgB,UAAU;KAClC,IAAa,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;KACzE,SAAS,eAAe;IACzB;IACA,KAAK,WAAW,UAAU,OAAO,sBAAsB,2BAA2B;IAClF,IAAa,UAAU,WAAW,KAAK,sBAAsB,IAAI;IACjE,KAAK,cAAc;GACpB,CAAC;GAED,IAAI,KAAK,QAAQ,mBAAmB;IACnC,KAAK,oBAAoB,IAAI,kBAAkB;IAC/C,KAAK,WAAW,KAAK,iBAAiB;GACvC;EACD,CAAC;CACF;AACD"}
|
|
@@ -3,16 +3,46 @@ import { disableClickPropagation, disableScrollPropagation, off, on, preventDefa
|
|
|
3
3
|
import { create } from "../dom/DomUtil.js";
|
|
4
4
|
import { Control } from "./Control.js";
|
|
5
5
|
import { I18n } from "../core/I18n.js";
|
|
6
|
-
|
|
6
|
+
// src/control/LayersControl.js
|
|
7
7
|
/** @import {ControlOptions} from './Control.js' */
|
|
8
8
|
/** @import {MaplairMap} from '../map/Map.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
|
/**
|
|
@@ -138,6 +182,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
138
182
|
this._map.off("zoomend", this._checkDisabledLayers, this);
|
|
139
183
|
for (const layer of this._layers) layer.layer.off("add remove", this._onLayerChange, this);
|
|
140
184
|
this._map.off("resize", this._expandIfNotCollapsed, this);
|
|
185
|
+
this._map.off("click", this.collapse, this);
|
|
141
186
|
}
|
|
142
187
|
/**
|
|
143
188
|
* Adds a base layer (radio button entry) with the given name to the control.
|
|
@@ -166,18 +211,45 @@ var LayersControl = class LayersControl extends Control {
|
|
|
166
211
|
*/
|
|
167
212
|
removeLayer(layer) {
|
|
168
213
|
layer.off("add remove", this._onLayerChange, this);
|
|
169
|
-
|
|
170
|
-
if (obj) this._layers.splice(this._layers.indexOf(obj), 1);
|
|
214
|
+
this._layers = this._layers.filter((o) => o.layer !== layer);
|
|
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._layer === 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");
|
|
@@ -188,62 +260,62 @@ var LayersControl = class LayersControl extends Control {
|
|
|
188
260
|
}
|
|
189
261
|
/**
|
|
190
262
|
* Collapse the control container if expanded.
|
|
191
|
-
* @param {Event} [ev] The event causing the collapse, if any (collapsing is skipped
|
|
192
|
-
* for `pointerleave` and `pointerout` of touch).
|
|
193
263
|
* @returns {this}
|
|
194
264
|
*/
|
|
195
|
-
collapse(
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
this._collapseDelayTimeout = setTimeout(() => {
|
|
199
|
-
this._container.classList.remove("maplair-control-layers-expanded");
|
|
200
|
-
}, this.options.collapseDelay);
|
|
201
|
-
return this;
|
|
202
|
-
}
|
|
265
|
+
collapse() {
|
|
266
|
+
if (this.options.inline) return this;
|
|
267
|
+
if (this.options.collapseDelay > 0) this._collapseDelayTimeout = setTimeout(() => {
|
|
203
268
|
this._container.classList.remove("maplair-control-layers-expanded");
|
|
204
|
-
}
|
|
269
|
+
}, this.options.collapseDelay);
|
|
270
|
+
else this._container.classList.remove("maplair-control-layers-expanded");
|
|
205
271
|
return this;
|
|
206
272
|
}
|
|
207
273
|
_initLayout() {
|
|
208
|
-
const className = "maplair-control-layers", container = this._container = create("div", className), collapsed = this.
|
|
274
|
+
const className = "maplair-control-layers", container = this._container = create("div", className), collapsed = this._isCollapsible();
|
|
275
|
+
if (this.options.inline) container.classList.add(`${className}-inline`);
|
|
209
276
|
disableClickPropagation(container);
|
|
210
277
|
disableScrollPropagation(container);
|
|
211
278
|
const section = this._section = create("fieldset", `${className}-list`);
|
|
279
|
+
section.setAttribute("aria-label", I18n.translate("Layers"));
|
|
212
280
|
if (collapsed) {
|
|
213
281
|
this._map.on("click", this.collapse, this);
|
|
214
282
|
on(container, {
|
|
215
283
|
pointerenter: this._expandSafely,
|
|
216
|
-
pointerleave
|
|
284
|
+
pointerleave(e) {
|
|
285
|
+
if (e.pointerType !== "touch") this.collapse();
|
|
286
|
+
}
|
|
287
|
+
}, this);
|
|
288
|
+
}
|
|
289
|
+
if (!this.options.inline) {
|
|
290
|
+
const link = this._layersLink = create("button", `${className}-toggle`, container);
|
|
291
|
+
link.type = "button";
|
|
292
|
+
link.title = I18n.translate("Layers");
|
|
293
|
+
link.setAttribute("aria-label", I18n.translate("Layers"));
|
|
294
|
+
const { toggleContent } = this.options;
|
|
295
|
+
if (typeof toggleContent === "string") link.innerHTML = toggleContent;
|
|
296
|
+
else if (toggleContent) link.replaceChildren(toggleContent);
|
|
297
|
+
on(link, {
|
|
298
|
+
keydown(e) {
|
|
299
|
+
if (e.code === "Enter") this._expandSafely();
|
|
300
|
+
},
|
|
301
|
+
click(e) {
|
|
302
|
+
e.preventDefault();
|
|
303
|
+
this._expandSafely();
|
|
304
|
+
}
|
|
217
305
|
}, this);
|
|
218
306
|
}
|
|
219
|
-
const link = this._layersLink = create("button", `${className}-toggle`, container);
|
|
220
|
-
link.type = "button";
|
|
221
|
-
link.title = I18n.translate("Layers");
|
|
222
|
-
link.setAttribute("aria-label", I18n.translate("Layers"));
|
|
223
|
-
on(link, {
|
|
224
|
-
keydown(e) {
|
|
225
|
-
if (e.code === "Enter") this._expandSafely();
|
|
226
|
-
},
|
|
227
|
-
click(e) {
|
|
228
|
-
e.preventDefault();
|
|
229
|
-
this._expandSafely();
|
|
230
|
-
}
|
|
231
|
-
}, this);
|
|
232
307
|
if (!collapsed) this.expand();
|
|
233
308
|
this._baseLayersList = create("div", `${className}-base`, section);
|
|
234
309
|
this._separator = create("div", `${className}-separator`, section);
|
|
235
310
|
this._overlaysList = create("div", `${className}-overlays`, section);
|
|
236
311
|
container.appendChild(section);
|
|
237
312
|
}
|
|
238
|
-
_getLayer(id) {
|
|
239
|
-
for (const layer of this._layers) if (layer && stamp(layer.layer) === id) return layer;
|
|
240
|
-
}
|
|
241
313
|
_addLayer(layer, name, overlay) {
|
|
242
314
|
if (this._map) layer.on("add remove", this._onLayerChange, this);
|
|
243
315
|
this._layers.push({
|
|
244
316
|
layer,
|
|
245
317
|
name,
|
|
246
|
-
overlay
|
|
318
|
+
overlay: !!overlay
|
|
247
319
|
});
|
|
248
320
|
if (this.options.sortLayers) this._layers.sort(((a, b) => this.options.sortFunction(a.layer, b.layer, a.name, b.name)));
|
|
249
321
|
if (this.options.autoZIndex && layer.setZIndex) {
|
|
@@ -257,6 +329,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
257
329
|
this._baseLayersList.replaceChildren();
|
|
258
330
|
this._overlaysList.replaceChildren();
|
|
259
331
|
this._layerControlInputs = [];
|
|
332
|
+
this._groupCount = 0;
|
|
260
333
|
let baseLayersPresent, overlaysPresent, baseLayersCount = 0;
|
|
261
334
|
for (const obj of this._layers) {
|
|
262
335
|
this._addItem(obj);
|
|
@@ -273,9 +346,12 @@ var LayersControl = class LayersControl extends Control {
|
|
|
273
346
|
}
|
|
274
347
|
_onLayerChange(e) {
|
|
275
348
|
if (!this._handlingClick) this._update();
|
|
276
|
-
const obj = this.
|
|
349
|
+
const obj = this._layers.find((o) => o.layer === e.target);
|
|
277
350
|
const type = obj.overlay ? e.type === "add" ? "overlayadd" : "overlayremove" : e.type === "add" ? "baselayerchange" : null;
|
|
278
|
-
if (type) this._map.fire(type,
|
|
351
|
+
if (type) this._map.fire(type, this._clickEvent ? {
|
|
352
|
+
...obj,
|
|
353
|
+
originalEvent: this._clickEvent
|
|
354
|
+
} : obj);
|
|
279
355
|
}
|
|
280
356
|
_addItem(obj) {
|
|
281
357
|
const label = document.createElement("label"), checked = this._map.hasLayer(obj.layer);
|
|
@@ -285,41 +361,71 @@ var LayersControl = class LayersControl extends Control {
|
|
|
285
361
|
input.defaultChecked = checked;
|
|
286
362
|
if (!obj.overlay) input.name = `maplair-base-layers_${stamp(this)}`;
|
|
287
363
|
this._layerControlInputs.push(input);
|
|
288
|
-
input.
|
|
364
|
+
input._layer = obj.layer;
|
|
289
365
|
on(input, "click", this._onInputClick, this);
|
|
366
|
+
const group = this.options.groupBy?.(obj.name, obj.layer, obj.overlay);
|
|
290
367
|
const name = document.createElement("span");
|
|
291
|
-
name.innerHTML = ` ${obj.name}`;
|
|
368
|
+
name.innerHTML = ` ${group ? group.label : obj.name}`;
|
|
292
369
|
const holder = document.createElement("span");
|
|
293
370
|
label.appendChild(holder);
|
|
294
371
|
holder.appendChild(input);
|
|
295
372
|
holder.appendChild(name);
|
|
296
|
-
|
|
373
|
+
const list = obj.overlay ? this._overlaysList : this._baseLayersList;
|
|
374
|
+
(group ? this._getGroupContainer(list, group.group) : list).appendChild(label);
|
|
297
375
|
this._checkDisabledLayers();
|
|
298
376
|
return label;
|
|
299
377
|
}
|
|
378
|
+
/**
|
|
379
|
+
* Returns the container of the given group if it is the last element in `list`
|
|
380
|
+
* (continuing the group), otherwise appends a new group container to `list`.
|
|
381
|
+
* @param {HTMLElement} list
|
|
382
|
+
* @param {string} group
|
|
383
|
+
* @returns {HTMLElement}
|
|
384
|
+
*/
|
|
385
|
+
_getGroupContainer(list, group) {
|
|
386
|
+
const last = list.lastElementChild;
|
|
387
|
+
if (last?._maplairGroup === group) return last;
|
|
388
|
+
const className = "maplair-control-layers-group", container = create("div", className, list), name = create("span", `${className}-name`, container);
|
|
389
|
+
name.id = `${className}_${stamp(this)}_${++this._groupCount}`;
|
|
390
|
+
name.textContent = group;
|
|
391
|
+
container.setAttribute("role", "group");
|
|
392
|
+
container.setAttribute("aria-labelledby", name.id);
|
|
393
|
+
container._maplairGroup = group;
|
|
394
|
+
return container;
|
|
395
|
+
}
|
|
300
396
|
_onInputClick(e) {
|
|
301
397
|
if (this._preventClick) return;
|
|
302
|
-
const
|
|
303
|
-
this.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (input.checked) addedLayers.push(layer);
|
|
307
|
-
else if (!input.checked) removedLayers.push(layer);
|
|
398
|
+
const checked = /* @__PURE__ */ new Map();
|
|
399
|
+
for (const input of this._layerControlInputs) {
|
|
400
|
+
const layer = input._layer;
|
|
401
|
+
checked.set(layer, checked.get(layer) || input.checked);
|
|
308
402
|
}
|
|
309
|
-
|
|
310
|
-
for (const layer of
|
|
403
|
+
const addedLayers = [], removedLayers = [];
|
|
404
|
+
for (const [layer, on] of checked) if (on !== this._map.hasLayer(layer)) (on ? addedLayers : removedLayers).push(layer);
|
|
405
|
+
this._handlingClick = true;
|
|
406
|
+
this._clickEvent = e;
|
|
407
|
+
for (const layer of removedLayers) this._map.removeLayer(layer);
|
|
408
|
+
for (const layer of addedLayers) this._map.addLayer(layer);
|
|
311
409
|
this._handlingClick = false;
|
|
410
|
+
this._clickEvent = void 0;
|
|
411
|
+
for (const [layer, on] of checked) if (on !== this._map.hasLayer(layer)) {
|
|
412
|
+
this._update();
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
312
415
|
this._refocusOnMap(e);
|
|
313
416
|
}
|
|
314
417
|
_checkDisabledLayers() {
|
|
315
418
|
const inputs = this._layerControlInputs, zoom = this._map.getZoom();
|
|
316
419
|
for (const input of inputs) {
|
|
317
|
-
const layer =
|
|
420
|
+
const layer = input._layer;
|
|
318
421
|
input.disabled = layer.options.minZoom !== void 0 && zoom < layer.options.minZoom || layer.options.maxZoom !== void 0 && zoom > layer.options.maxZoom;
|
|
319
422
|
}
|
|
320
423
|
}
|
|
424
|
+
_isCollapsible() {
|
|
425
|
+
return this.options.collapsed && !this.options.inline;
|
|
426
|
+
}
|
|
321
427
|
_expandIfNotCollapsed() {
|
|
322
|
-
if (this._map && !this.
|
|
428
|
+
if (this._map && !this._isCollapsible()) this.expand();
|
|
323
429
|
return this;
|
|
324
430
|
}
|
|
325
431
|
_expandSafely() {
|
|
@@ -333,7 +439,6 @@ var LayersControl = class LayersControl extends Control {
|
|
|
333
439
|
});
|
|
334
440
|
}
|
|
335
441
|
};
|
|
336
|
-
//#endregion
|
|
337
442
|
export { LayersControl };
|
|
338
443
|
|
|
339
444
|
//# sourceMappingURL=LayersControl.js.map
|