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":"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.prevent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S,KAAK,qBACpB,OAAO,KAAK,KAAK,QAAQ;EAEzB,KAAK,MAAM,SAAS,QAAQ;GAC3B,MAAM,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC,CAAC;GAC5C,MAAM,WAAY,MAAM,QAAQ,YAAY,KAAA,KAAa,OAAO,MAAM,QAAQ,WAC5D,MAAM,QAAQ,YAAY,KAAA,KAAa,OAAO,MAAM,QAAQ;EAE/E;CACD;CAEA,wBAAwB;EACvB,IAAI,KAAK,QAAQ,CAAC,KAAK,QAAQ,WAC9B,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"}
|
|
1
|
+
{"version":3,"file":"LayersControl.js","names":["DomUtil.create","Util.stamp","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\tthis._map.off('click', this.collapse, 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\tthis._layers = this._layers.filter(o => o.layer !== layer);\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._layer === 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 * @returns {this}\n\t */\n\tcollapse() {\n\t\tif (this.options.inline) {\n\t\t\treturn this;\n\t\t}\n\t\tif (this.options.collapseDelay > 0) {\n\t\t\tthis._collapseDelayTimeout = setTimeout(() => {\n\t\t\t\tthis._container.classList.remove('maplair-control-layers-expanded');\n\t\t\t}, this.options.collapseDelay);\n\t\t} else {\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\t// on touch devices, pointerleave fires while clicking a checkbox, which shouldn't collapse the control\n\t\t\t\tpointerleave(e) {\n\t\t\t\t\tif (e.pointerType !== 'touch') { this.collapse(); }\n\t\t\t\t}\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_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._layers.find(o => o.layer === 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._layer = 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\t// a layer can be listed under several inputs, so it should be on the map if any of them is checked\n\t\tconst checked = new Map();\n\t\tfor (const input of this._layerControlInputs) {\n\t\t\tconst layer = input._layer;\n\t\t\tchecked.set(layer, checked.get(layer) || input.checked);\n\t\t}\n\n\t\t// diff against the map upfront, so layers that event handlers add or remove below keep their state\n\t\tconst addedLayers = [], removedLayers = [];\n\t\tfor (const [layer, on] of checked) {\n\t\t\tif (on !== this._map.hasLayer(layer)) {\n\t\t\t\t(on ? addedLayers : removedLayers).push(layer);\n\t\t\t}\n\t\t}\n\n\t\tthis._handlingClick = true;\n\t\tthis._clickEvent = e;\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\tthis._map.removeLayer(layer);\n\t\t}\n\t\tfor (const layer of addedLayers) {\n\t\t\tthis._map.addLayer(layer);\n\t\t}\n\n\t\tthis._handlingClick = false;\n\t\tthis._clickEvent = undefined;\n\n\t\tfor (const [layer, on] of checked) {\n\t\t\tif (on !== this._map.hasLayer(layer)) {\n\t\t\t\tthis._update();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\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 = input._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,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AAe,GACrC,KAAK,OAAO;EAEb,OAAO;CACR;CAEA,gBAAgB;EACf,MAAM,UAAU,KAAK;EACrB,KAAK,gBAAgB;EACrB,GAAY,SAAS,SAASC,cAAuB;EACrD,KAAK,OAAO;EACZ,iBAAiB;GAChB,IAAa,SAAS,SAASA,cAAuB;GACtD,KAAK,gBAAgB;EACtB,CAAC;CACF;AAED"}
|
|
@@ -3,7 +3,7 @@ import { create } from "../dom/DomUtil.js";
|
|
|
3
3
|
import { Control } from "./Control.js";
|
|
4
4
|
import { I18n } from "../core/I18n.js";
|
|
5
5
|
import { CircleMarker } from "../layer/vector/CircleMarker.js";
|
|
6
|
-
|
|
6
|
+
// src/control/LegendControl.js
|
|
7
7
|
/** @import {ControlOptions} from './Control.js' */
|
|
8
8
|
/** @import {MaplairMap} from '../map/Map.js' */
|
|
9
9
|
/** @import {FeatureGroup} from '../layer/FeatureGroup.js' */
|
|
@@ -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);
|
|
@@ -224,7 +222,6 @@ function svgElement(name, attributes) {
|
|
|
224
222
|
for (const [key, value] of Object.entries(attributes)) el.setAttribute(key, value);
|
|
225
223
|
return el;
|
|
226
224
|
}
|
|
227
|
-
//#endregion
|
|
228
225
|
export { LegendControl };
|
|
229
226
|
|
|
230
227
|
//# sourceMappingURL=LegendControl.js.map
|
|
@@ -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,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,SAA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I,aAAa,WAAW,WAAW;CACvC,IAAI,aAAa,eAAe,MAAM;CAEtC,IAAI;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"}
|
|
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,I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EA,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,9 +2,9 @@ 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
|
+
// src/control/MiniMapControl.js
|
|
8
8
|
/** @import {ControlOptions} from './Control.js' */
|
|
9
9
|
/** @import {MaplairMapOptions} from '../map/Map.js' */
|
|
10
10
|
/** @import {Layer} from '../layer/Layer.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
|
|
@@ -176,7 +174,6 @@ var MiniMapControl = class MiniMapControl extends Control {
|
|
|
176
174
|
if (!this._miniMap.dragging?.moved()) this._map.panTo(e.latlng);
|
|
177
175
|
}
|
|
178
176
|
};
|
|
179
|
-
//#endregion
|
|
180
177
|
export { MiniMapControl };
|
|
181
178
|
|
|
182
179
|
//# sourceMappingURL=MiniMapControl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MiniMapControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/MiniMapControl.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 {MaplairMap} from '../map/Map.js';\nimport {Polygon} from '../layer/vector/Polygon.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMapOptions} from '../map/Map.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {PathOptions} from '../layer/vector/Path.js' */\n\n/**\n * Options of `MiniMapControl`.\n * @typedef {object} MiniMapControlOptions\n * @property {string} [position='bottomright'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {number} [width=150] The width of the overview map in pixels.\n * @property {number} [height=150] The height of the overview map in pixels.\n * @property {number} [zoomOffset=-5] The zoom level of the overview map relative to the\n * map.\n * @property {boolean} [collapsed=false] Whether the overview map is collapsed initially.\n * @property {PathOptions} [rectangleOptions={color: '#ff7800', weight: 1, fillOpacity: 0.2}]\n * The style of the rectangle showing the view of the map.\n * @property {MaplairMapOptions} [mapOptions={}] Further options of the overview map.\n * @extends ControlOptions\n */\n\n/**\n * An overview map in a corner of the map, showing the view of the map as a\n * rectangle (or rotated rectangle on a rotated map) at a smaller zoom level.\n * Dragging the overview map pans the map, clicking it centers the map there, and\n * a button collapses it.\n *\n * Inspired by the [Leaflet-MiniMap](https://github.com/Norkart/Leaflet-MiniMap) plugin.\n *\n * @example\n * ```js\n * // a layer of its own, a layer can only be on one map\n * const overviewLayer = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png');\n * new MiniMapControl(overviewLayer).addTo(map);\n * ```\n */\nexport class MiniMapControl extends Control {\n\n\tstatic {\n\t\
|
|
1
|
+
{"version":3,"file":"MiniMapControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/MiniMapControl.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 {MaplairMap} from '../map/Map.js';\nimport {Polygon} from '../layer/vector/Polygon.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMapOptions} from '../map/Map.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {PathOptions} from '../layer/vector/Path.js' */\n\n/**\n * Options of `MiniMapControl`.\n * @typedef {object} MiniMapControlOptions\n * @property {string} [position='bottomright'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {number} [width=150] The width of the overview map in pixels.\n * @property {number} [height=150] The height of the overview map in pixels.\n * @property {number} [zoomOffset=-5] The zoom level of the overview map relative to the\n * map.\n * @property {boolean} [collapsed=false] Whether the overview map is collapsed initially.\n * @property {PathOptions} [rectangleOptions={color: '#ff7800', weight: 1, fillOpacity: 0.2}]\n * The style of the rectangle showing the view of the map.\n * @property {MaplairMapOptions} [mapOptions={}] Further options of the overview map.\n * @extends ControlOptions\n */\n\n/**\n * An overview map in a corner of the map, showing the view of the map as a\n * rectangle (or rotated rectangle on a rotated map) at a smaller zoom level.\n * Dragging the overview map pans the map, clicking it centers the map there, and\n * a button collapses it.\n *\n * Inspired by the [Leaflet-MiniMap](https://github.com/Norkart/Leaflet-MiniMap) plugin.\n *\n * @example\n * ```js\n * // a layer of its own, a layer can only be on one map\n * const overviewLayer = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png');\n * new MiniMapControl(overviewLayer).addTo(map);\n * ```\n */\nexport class MiniMapControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'bottomright',\n\t\twidth: 150,\n\t\theight: 150,\n\t\tzoomOffset: -5,\n\t\tcollapsed: false,\n\t\trectangleOptions: {color: '#ff7800', weight: 1, fillOpacity: 0.2},\n\t\tmapOptions: {}\n\t};\n\n\t/**\n\t * Creates an overview map control showing `layer` (which must not be on another map).\n\t * @param {Layer} layer\n\t * @param {MiniMapControlOptions} [options]\n\t */\n\tconstructor(layer, options) {\n\t\tsuper(options);\n\t\tthis._layer = layer;\n\t\tthis.callInitHooks(MiniMapControl);\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// the size of the overview map is known once it is on the page\n\t\tthis._miniMap.invalidateSize({pan: false});\n\t\tthis._update();\n\t\treturn this;\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-minimap'),\n\t\tmapContainer = DomUtil.create('div', 'maplair-control-minimap-map', container);\n\t\tcontainer.style.width = `${this.options.width}px`;\n\t\tcontainer.style.height = `${this.options.height}px`;\n\n\t\tconst toggle = this._toggle = DomUtil.create('button', 'maplair-control-minimap-toggle', container);\n\t\ttoggle.type = 'button';\n\t\tDomEvent.on(toggle, 'click', DomEvent.stop);\n\t\tDomEvent.on(toggle, 'click', this.toggle, this);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\n\t\tthis._miniMap = new MaplairMap(mapContainer, {\n\t\t\tattributionControl: false,\n\t\t\tzoomControl: false,\n\t\t\tdoubleClickZoom: false,\n\t\t\tscrollWheelZoom: false,\n\t\t\tboxZoom: false,\n\t\t\tkeyboard: false,\n\t\t\tpinchZoom: false,\n\t\t\ttapDragZoom: false,\n\t\t\tariaLabel: I18n.translate('Overview map'),\n\t\t\t...this.options.mapOptions,\n\t\t\tlayers: [this._layer]\n\t\t});\n\t\t// not part of the keyboard navigation, the map has its own\n\t\tmapContainer.tabIndex = -1;\n\n\t\tthis._rectangle = new Polygon([], {interactive: false, ...this.options.rectangleOptions});\n\n\t\tthis._miniMap.on({\n\t\t\tmoveend: this._onMiniMapMoveEnd,\n\t\t\tclick: this._onMiniMapClick\n\t\t}, this);\n\t\tmap.on('move zoom rotate resize', this._update, this);\n\t\tmap.whenReady(this._update, this);\n\n\t\tthis._setCollapsed(this.options.collapsed);\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('move zoom rotate resize', this._update, this);\n\t\tthis._miniMap.remove();\n\t\tthis._miniMap = null;\n\t}\n\n\t/**\n\t * Returns the overview map.\n\t * @returns {MaplairMap}\n\t */\n\tgetMiniMap() {\n\t\treturn this._miniMap;\n\t}\n\n\t/**\n\t * Collapses or expands the overview map.\n\t * @returns {this}\n\t */\n\ttoggle() {\n\t\treturn this._setCollapsed(!this._collapsed);\n\t}\n\n\t_setCollapsed(collapsed) {\n\t\tthis._collapsed = collapsed;\n\t\tconst container = this._container ?? this._toggle.parentNode,\n\t\ttitle = collapsed ? I18n.translate('Show the overview map') : I18n.translate('Hide the overview map');\n\t\tcontainer.classList.toggle('maplair-control-minimap-collapsed', collapsed);\n\t\tthis._toggle.title = title;\n\t\tthis._toggle.setAttribute('aria-label', title);\n\t\tthis._toggle.setAttribute('aria-expanded', !collapsed);\n\t\tif (!collapsed) {\n\t\t\tthis._miniMap.invalidateSize();\n\t\t\tthis._update();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Follows the view of the map\n\t_update() {\n\t\tconst map = this._map, miniMap = this._miniMap;\n\t\tif (!map?._loaded || !miniMap || this._collapsed) { return; }\n\n\t\tconst zoom = Math.max(miniMap.getMinZoom(), Math.min(map.getZoom() + this.options.zoomOffset, miniMap.getMaxZoom()));\n\t\tminiMap.setView(map.getCenter(), zoom, {animate: false});\n\n\t\tconst size = map.getSize();\n\t\tthis._rectangle.setLatLngs([[0, 0], [size.x, 0], size, [0, size.y]].map(p => map.containerPointToLatLng(p)));\n\t\tif (!miniMap.hasLayer(this._rectangle)) {\n\t\t\tthis._rectangle.addTo(miniMap);\n\t\t}\n\t}\n\n\t// Dragging the overview map pans the map (only when moved by the user)\n\t_onMiniMapMoveEnd(e) {\n\t\tif (e.originalEvent) {\n\t\t\tthis._map.panTo(this._miniMap.getCenter());\n\t\t}\n\t}\n\n\t_onMiniMapClick(e) {\n\t\tif (!this._miniMap.dragging?.moved()) {\n\t\t\tthis._map.panTo(e.latlng);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,iBAAb,MAAa,uBAAuB,QAAQ;CAE3C,OAAO,iBAAiB;EACvB,UAAU;EACV,OAAO;EACP,QAAQ;EACR,YAAY;EACZ,WAAW;EACX,kBAAkB;GAAC,OAAO;GAAW,QAAQ;GAAG,aAAa;EAAG;EAChE,YAAY,CAAC;CACd;;;;;;CAOA,YAAY,OAAO,SAAS;EAC3B,MAAM,OAAO;EACb,KAAK,SAAS;EACd,KAAK,cAAc,cAAc;CAClC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,MAAM,GAAG;EAEf,KAAK,SAAS,eAAe,EAAC,KAAK,MAAK,CAAC;EACzC,KAAK,QAAQ;EACb,OAAO;CACR;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAYA,OAAe,OAAO,yBAAyB,GACjE,eAAeA,OAAe,OAAO,+BAA+B,SAAS;EAC7E,UAAU,MAAM,QAAQ,GAAG,KAAK,QAAQ,MAAM;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EACrB,KAAK,QAAQ,aAAa,cAAc,KAAK;EAC7C,KAAK,QAAQ,aAAa,iBAAiB,CAAC,SAAS;EACrD,IAAI,CAAC,WAAW;GACf,KAAK,SAAS,eAAe;GAC7B,KAAK,QAAQ;EACd;EACA,OAAO;CACR;CAGA,UAAU;EACT,MAAM,MAAM,KAAK,MAAM,UAAU,KAAK;EACtC,IAAI,CAAC,KAAK,WAAW,CAAC,WAAW,KAAK,YAAc;EAEpD,MAAM,OAAO,KAAK,IAAI,QAAQ,WAAW,GAAG,KAAK,IAAI,IAAI,QAAQ,IAAI,KAAK,QAAQ,YAAY,QAAQ,WAAW,CAAC,CAAC;EACnH,QAAQ,QAAQ,IAAI,UAAU,GAAG,MAAM,EAAC,SAAS,MAAK,CAAC;EAEvD,MAAM,OAAO,IAAI,QAAQ;EACzB,KAAK,WAAW,WAAW;GAAC,CAAC,GAAG,CAAC;GAAG,CAAC,KAAK,GAAG,CAAC;GAAG;GAAM,CAAC,GAAG,KAAK,CAAC;EAAC,CAAC,CAAC,KAAI,MAAK,IAAI,uBAAuB,CAAC,CAAC,CAAC;EAC3G,IAAI,CAAC,QAAQ,SAAS,KAAK,UAAU,GACpC,KAAK,WAAW,MAAM,OAAO;CAE/B;CAGA,kBAAkB,GAAG;EACpB,IAAI,EAAE,eACL,KAAK,KAAK,MAAM,KAAK,SAAS,UAAU,CAAC;CAE3C;CAEA,gBAAgB,GAAG;EAClB,IAAI,CAAC,KAAK,SAAS,UAAU,MAAM,GAClC,KAAK,KAAK,MAAM,EAAE,MAAM;CAE1B;AACD"}
|
|
@@ -2,7 +2,7 @@ import { disableClickPropagation, 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/RotateControl.js
|
|
6
6
|
/** @import {ControlOptions} from './Control.js' */
|
|
7
7
|
/** @import {MaplairMap} from '../map/Map.js' */
|
|
8
8
|
const compass = "<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><path d=\"M8 1 11 8H5z\" fill=\"#d22\"/><path d=\"M8 15 5 8h6z\" fill=\"#999\"/></svg>";
|
|
@@ -39,9 +39,7 @@ const compass = "<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"
|
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
41
|
var RotateControl = class RotateControl extends Control {
|
|
42
|
-
static {
|
|
43
|
-
this.setDefaultOptions({ position: "topleft" });
|
|
44
|
-
}
|
|
42
|
+
static defaultOptions = { position: "topleft" };
|
|
45
43
|
/**
|
|
46
44
|
* Creates a rotate control.
|
|
47
45
|
* @param {...RotateControlOptions} args The options.
|
|
@@ -98,7 +96,6 @@ var RotateControl = class RotateControl extends Control {
|
|
|
98
96
|
});
|
|
99
97
|
}
|
|
100
98
|
};
|
|
101
|
-
//#endregion
|
|
102
99
|
export { RotateControl };
|
|
103
100
|
|
|
104
101
|
//# sourceMappingURL=RotateControl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RotateControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/RotateControl.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\nconst compass = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><path d=\"M8 1 11 8H5z\" fill=\"#d22\"/><path d=\"M8 15 5 8h6z\" fill=\"#999\"/></svg>';\n\n/**\n * Options of `RotateControl`.\n * @typedef {object} RotateControlOptions\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 * @extends ControlOptions\n */\n\n/**\n * Map options of `RotateControl`.\n * @typedef {object} RotateControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [rotateControl=false] Whether a [rotate control](#rotatecontrol)\n * is added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `RotateControl`.\n * @typedef {object} RotateControlMapProperties\n * @lends MaplairMap\n * @property {RotateControl} rotateControl The default rotate control (only available if\n * the [`rotateControl` option](#map-rotatecontrol) was `true` when creating the map).\n */\n\n/**\n * A compass showing the rotation of the map (see `MaplairMap.setBearing()`); clicking it\n * rotates the map back to north up. It is put on the map if you set its\n * [`rotateControl` option](#map-rotatecontrol) to `true`.\n *\n * @example\n * ```js\n * new RotateControl({position: 'topright'}).addTo(map);\n * ```\n */\nexport class RotateControl extends Control {\n\n\tstatic {\n\t\
|
|
1
|
+
{"version":3,"file":"RotateControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/RotateControl.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\nconst compass = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><path d=\"M8 1 11 8H5z\" fill=\"#d22\"/><path d=\"M8 15 5 8h6z\" fill=\"#999\"/></svg>';\n\n/**\n * Options of `RotateControl`.\n * @typedef {object} RotateControlOptions\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 * @extends ControlOptions\n */\n\n/**\n * Map options of `RotateControl`.\n * @typedef {object} RotateControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [rotateControl=false] Whether a [rotate control](#rotatecontrol)\n * is added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `RotateControl`.\n * @typedef {object} RotateControlMapProperties\n * @lends MaplairMap\n * @property {RotateControl} rotateControl The default rotate control (only available if\n * the [`rotateControl` option](#map-rotatecontrol) was `true` when creating the map).\n */\n\n/**\n * A compass showing the rotation of the map (see `MaplairMap.setBearing()`); clicking it\n * rotates the map back to north up. It is put on the map if you set its\n * [`rotateControl` option](#map-rotatecontrol) to `true`.\n *\n * @example\n * ```js\n * new RotateControl({position: 'topright'}).addTo(map);\n * ```\n */\nexport class RotateControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft'\n\t};\n\n\t/**\n\t * Creates a rotate control.\n\t * @param {...RotateControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(RotateControl);\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-rotate maplair-bar'),\n\t\tbutton = this._button = DomUtil.create('button', 'maplair-control-rotate-button', container),\n\t\ttitle = I18n.translate('Reset north');\n\t\tbutton.type = 'button';\n\t\tbutton.title = title;\n\t\tbutton.setAttribute('aria-label', title);\n\t\tbutton.innerHTML = compass;\n\n\t\tDomEvent.disableClickPropagation(button);\n\t\tDomEvent.on(button, 'click', DomEvent.stop);\n\t\tDomEvent.on(button, 'click', this._resetNorth, this);\n\t\tDomEvent.on(button, 'click', this._refocusOnMap, this);\n\n\t\tthis._update();\n\t\tmap.on('rotate', 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('rotate', this._update, this);\n\t}\n\n\t_resetNorth(e) {\n\t\tthis._map._setUserEvent(e);\n\t\tthis._map.setBearing(0, {animate: true});\n\t}\n\n\t_update() {\n\t\t// the needle points north\n\t\tthis._button.firstChild.style.transform = `rotate(${-this._map.getBearing()}deg)`;\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\trotateControl: false\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.rotateControl) {\n\t\t\t\tthis.rotateControl = new RotateControl();\n\t\t\t\tthis.addControl(this.rotateControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;AAOA,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqChB,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C,OAAO,iBAAiB,EACvB,UAAU,UACX;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,aAAa;CACjC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAYA,OAAe,OAAO,oCAAoC,GAC5E,SAAS,KAAK,UAAUA,OAAe,UAAU,iCAAiC,SAAS,GAC3F,QAAQ,KAAK,UAAU,aAAa;EACpC,OAAO,OAAO;EACd,OAAO,QAAQ;EACf,OAAO,aAAa,cAAc,KAAK;EACvC,OAAO,YAAY;EAEnB,wBAAiC,MAAM;EACvC,GAAY,QAAQ,SAASC,IAAa;EAC1C,GAAY,QAAQ,SAAS,KAAK,aAAa,IAAI;EACnD,GAAY,QAAQ,SAAS,KAAK,eAAe,IAAI;EAErD,KAAK,QAAQ;EACb,IAAI,GAAG,UAAU,KAAK,SAAS,IAAI;EAEnC,OAAO;CACR;;;;;CAMA,SAAS,KAAK;EACb,IAAI,IAAI,UAAU,KAAK,SAAS,IAAI;CACrC;CAEA,YAAY,GAAG;EACd,KAAK,KAAK,cAAc,CAAC;EACzB,KAAK,KAAK,WAAW,GAAG,EAAC,SAAS,KAAI,CAAC;CACxC;CAEA,UAAU;EAET,KAAK,QAAQ,WAAW,MAAM,YAAY,UAAU,CAAC,KAAK,KAAK,WAAW,EAAE;CAC7E;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,eAAe,MAChB,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,eAAe;IAC/B,KAAK,gBAAgB,IAAI,cAAc;IACvC,KAAK,WAAW,KAAK,aAAa;GACnC;EACD,CAAC;CACF;AACD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { create } from "../dom/DomUtil.js";
|
|
2
2
|
import { Control } from "./Control.js";
|
|
3
3
|
import { I18n } from "../core/I18n.js";
|
|
4
|
-
|
|
4
|
+
// src/control/ScaleControl.js
|
|
5
5
|
/** @import {ControlOptions} from './Control.js' */
|
|
6
6
|
/** @import {MaplairMap} from '../map/Map.js' */
|
|
7
7
|
/**
|
|
@@ -30,15 +30,13 @@ import { I18n } from "../core/I18n.js";
|
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
var ScaleControl = class ScaleControl extends Control {
|
|
33
|
-
static {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
}
|
|
33
|
+
static defaultOptions = {
|
|
34
|
+
position: "bottomleft",
|
|
35
|
+
maxWidth: 100,
|
|
36
|
+
metric: true,
|
|
37
|
+
imperial: true,
|
|
38
|
+
updateWhenIdle: false
|
|
39
|
+
};
|
|
42
40
|
/**
|
|
43
41
|
* Creates a scale control with the given options.
|
|
44
42
|
* @param {...ScaleControlOptions} args The options.
|
|
@@ -106,7 +104,6 @@ var ScaleControl = class ScaleControl extends Control {
|
|
|
106
104
|
return pow10 * d;
|
|
107
105
|
}
|
|
108
106
|
};
|
|
109
|
-
//#endregion
|
|
110
107
|
export { ScaleControl };
|
|
111
108
|
|
|
112
109
|
//# sourceMappingURL=ScaleControl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScaleControl.js","names":["DomUtil.create"],"sources":["../../../src/control/ScaleControl.js"],"sourcesContent":["\nimport {Control} from './Control.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\n/**\n * Options of `ScaleControl`.\n * @typedef {object} ScaleControlOptions\n * @property {string} [position='bottomleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {number} [maxWidth=100] Maximum width of the control in pixels. The width is\n * set dynamically to show round values (e.g. 100, 200, 500).\n * @property {boolean} [metric=true] Whether to show the metric scale line (m/km).\n * @property {boolean} [imperial=true] Whether to show the imperial scale line (mi/ft).\n * @property {boolean} [updateWhenIdle=false] If `true`, the control is updated on\n * [`moveend`](#map-moveend), otherwise it's always up-to-date (updated on\n * [`move`](#map-move)).\n * @extends ControlOptions\n */\n\n/**\n * A simple scale control that shows the scale of the current center of screen in metric\n * (m/km) and imperial (mi/ft) systems.\n *\n * @example\n *\n * ```js\n * new ScaleControl().addTo(map);\n * ```\n */\nexport class ScaleControl extends Control {\n\n\tstatic {\n\t\
|
|
1
|
+
{"version":3,"file":"ScaleControl.js","names":["DomUtil.create"],"sources":["../../../src/control/ScaleControl.js"],"sourcesContent":["\nimport {Control} from './Control.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\n/**\n * Options of `ScaleControl`.\n * @typedef {object} ScaleControlOptions\n * @property {string} [position='bottomleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {number} [maxWidth=100] Maximum width of the control in pixels. The width is\n * set dynamically to show round values (e.g. 100, 200, 500).\n * @property {boolean} [metric=true] Whether to show the metric scale line (m/km).\n * @property {boolean} [imperial=true] Whether to show the imperial scale line (mi/ft).\n * @property {boolean} [updateWhenIdle=false] If `true`, the control is updated on\n * [`moveend`](#map-moveend), otherwise it's always up-to-date (updated on\n * [`move`](#map-move)).\n * @extends ControlOptions\n */\n\n/**\n * A simple scale control that shows the scale of the current center of screen in metric\n * (m/km) and imperial (mi/ft) systems.\n *\n * @example\n *\n * ```js\n * new ScaleControl().addTo(map);\n * ```\n */\nexport class ScaleControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'bottomleft',\n\t\tmaxWidth: 100,\n\t\tmetric: true,\n\t\timperial: true,\n\t\tupdateWhenIdle: false\n\t};\n\n\t/**\n\t * Creates a scale control with the given options.\n\t * @param {...ScaleControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ScaleControl);\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 className = 'maplair-control-scale',\n\t\tcontainer = DomUtil.create('div', className),\n\t\toptions = this.options;\n\n\t\tthis._addScales(options, `${className}-line`, container);\n\n\t\tmap.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);\n\t\tmap.whenReady(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(this.options.updateWhenIdle ? 'moveend' : 'move', this._update, this);\n\t}\n\n\t_addScales(options, className, container) {\n\t\tif (options.metric) {\n\t\t\tthis._mScale = DomUtil.create('div', className, container);\n\t\t}\n\t\tif (options.imperial) {\n\t\t\tthis._iScale = DomUtil.create('div', className, container);\n\t\t}\n\t}\n\n\t_update() {\n\t\tconst map = this._map,\n\t\ty = map.getSize().y / 2;\n\n\t\tconst maxMeters = map.distance(\n\t\t\tmap.containerPointToLatLng([0, y]),\n\t\t\tmap.containerPointToLatLng([this.options.maxWidth, y]));\n\n\t\tthis._updateScales(maxMeters);\n\t}\n\n\t_updateScales(maxMeters) {\n\t\tif (this.options.metric && maxMeters) {\n\t\t\tthis._updateMetric(maxMeters);\n\t\t}\n\t\tif (this.options.imperial && maxMeters) {\n\t\t\tthis._updateImperial(maxMeters);\n\t\t}\n\t}\n\n\t_updateMetric(maxMeters) {\n\t\tconst meters = this._getRoundNum(maxMeters),\n\t\tlabel = meters < 1000 ?\n\t\t\tI18n.translate('{meters} m', {meters}) :\n\t\t\tI18n.translate('{kilometers} km', {kilometers: meters / 1000});\n\n\t\tthis._updateScale(this._mScale, label, meters / maxMeters);\n\t}\n\n\t_updateImperial(maxMeters) {\n\t\tconst maxFeet = maxMeters * 3.2808399;\n\t\tlet maxMiles, miles, feet;\n\n\t\tif (maxFeet > 5280) {\n\t\t\tmaxMiles = maxFeet / 5280;\n\t\t\tmiles = this._getRoundNum(maxMiles);\n\t\t\tthis._updateScale(this._iScale, I18n.translate('{miles} mi', {miles}), miles / maxMiles);\n\n\t\t} else {\n\t\t\tfeet = this._getRoundNum(maxFeet);\n\t\t\tthis._updateScale(this._iScale, I18n.translate('{feet} ft', {feet}), feet / maxFeet);\n\t\t}\n\t}\n\n\t_updateScale(scale, text, ratio) {\n\t\tscale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;\n\t\tscale.innerHTML = text;\n\t}\n\n\t_getRoundNum(num) {\n\t\tconst pow10 = 10 ** ((`${Math.floor(num)}`).length - 1);\n\t\tlet d = num / pow10;\n\n\t\td = d >= 10 ? 10 :\n\t\t\td >= 5 ? 5 :\n\t\t\td >= 3 ? 3 :\n\t\t\td >= 2 ? 2 : 1;\n\n\t\treturn pow10 * d;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAa,eAAb,MAAa,qBAAqB,QAAQ;CAEzC,OAAO,iBAAiB;EACvB,UAAU;EACV,UAAU;EACV,QAAQ;EACR,UAAU;EACV,gBAAgB;CACjB;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,YAAY;CAChC;;;;;;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