maplair 4.0.0-alpha.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +140 -38
- package/LICENSE +1 -1
- package/README.md +10 -9
- package/dist/esm/Maplair.js +14 -14
- package/dist/esm/control/AttributionControl.js +24 -14
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +9 -11
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -3
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +9 -16
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +5 -7
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +144 -35
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +7 -9
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +14 -16
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +1 -3
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -9
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +100 -18
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +1 -3
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +5 -7
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +408 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +5 -7
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -37
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +21 -8
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +13 -11
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/Util.js +13 -1
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +8 -42
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +14 -68
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +17 -18
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +3 -25
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +34 -6
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +19 -7
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +4 -3
- package/dist/esm/geo/crs/CRS.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3395.js +1 -1
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +1 -1
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +1 -1
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +2 -2
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +3 -3
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +3 -3
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +3 -3
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +19 -7
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +36 -30
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +23 -5
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +9 -28
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +6 -8
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +15 -20
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/GeoJSON.js +9 -145
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +75 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +15 -17
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +20 -26
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +8 -10
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +51 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +27 -43
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +2 -5
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +15 -17
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +12 -15
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +15 -48
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +8 -10
- 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 +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +2 -3
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +63 -35
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +6 -8
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +86 -98
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +28 -36
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +1 -3
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +2 -2
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +17 -7
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +27 -20
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +20 -4
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
- package/dist/esm/layer/vector/Polyline.js +24 -8
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +5 -5
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +15 -11
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +135 -129
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +6 -8
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +20 -20
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +37 -37
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +12 -5
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +6326 -5625
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +3 -3
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +9010 -8290
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +148 -98
- package/dist/maplair.js +3 -3
- 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 +12 -14
- package/src/control/AttributionControl.js +25 -18
- package/src/control/ButtonControl.js +9 -11
- package/src/control/ContextMenu.js +3 -5
- package/src/control/Control.js +9 -19
- package/src/control/FullscreenControl.js +5 -7
- package/src/control/LayersControl.js +159 -36
- package/src/control/LegendControl.js +7 -9
- package/src/control/MiniMapControl.js +9 -11
- package/src/control/RotateControl.js +3 -5
- package/src/control/ScaleControl.js +7 -9
- package/src/control/SearchControl.js +104 -21
- package/src/control/SideBySideControl.js +3 -5
- package/src/control/TextControl.js +5 -7
- package/src/control/TimeControl.js +471 -0
- package/src/control/ZoomControl.js +5 -7
- package/src/control/index.js +1 -0
- package/src/core/Class.js +35 -34
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +14 -12
- package/src/core/Util.js +19 -1
- package/src/core/index.js +0 -1
- package/src/dom/DomEvent.DoubleTap.js +18 -10
- package/src/dom/DomEvent.PointerEvents.js +3 -26
- package/src/dom/DomEvent.js +8 -66
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +27 -22
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +40 -4
- package/src/geo/LatLngBounds.js +20 -7
- package/src/geo/crs/CRS.js +4 -3
- package/src/geo/crs/EPSG3395.js +1 -1
- package/src/geo/crs/EPSG3857.js +1 -1
- package/src/geo/crs/EPSG4326.js +1 -1
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +1 -1
- package/src/geo/projection/Projection.LonLat.js +3 -3
- package/src/geo/projection/Projection.Mercator.js +3 -3
- package/src/geo/projection/Projection.SphericalMercator.js +3 -3
- package/src/geometry/Bounds.js +20 -7
- package/src/geometry/LineUtil.js +47 -48
- package/src/geometry/Point.js +24 -5
- package/src/geometry/PolyUtil.js +15 -44
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +15 -26
- package/src/layer/GeoJSON.js +7 -205
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +9 -11
- package/src/layer/ImageOverlay.js +19 -30
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +71 -0
- package/src/layer/Popup.js +31 -46
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +15 -19
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +15 -61
- package/src/layer/marker/DivIcon.js +10 -12
- package/src/layer/marker/Icon.js +9 -12
- package/src/layer/marker/Marker.Drag.js +1 -1
- package/src/layer/marker/Marker.Move.js +2 -3
- package/src/layer/marker/Marker.js +83 -41
- 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 +104 -134
- package/src/layer/tile/TileLayer.js +35 -43
- package/src/layer/tile/WMSTileLayer.js +26 -24
- package/src/layer/vector/Canvas.js +3 -5
- package/src/layer/vector/Circle.js +5 -2
- package/src/layer/vector/CircleMarker.js +17 -6
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +28 -5
- package/src/layer/vector/Polyline.js +26 -7
- package/src/layer/vector/Renderer.getRenderer.js +17 -17
- package/src/layer/vector/SVG.js +5 -5
- package/src/map/Map.Rotation.js +19 -11
- package/src/map/Map.js +163 -154
- package/src/map/handler/BoxZoomHandler.js +9 -8
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +26 -29
- package/src/map/handler/KeyboardHandler.js +44 -50
- package/src/map/handler/PinchZoomHandler.js +16 -5
- package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
- package/src/map/handler/TapHoldHandler.js +15 -4
- package/src/map/index.js +1 -1
- package/src/maplair.css +148 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/images/layers.svg +0 -1
- package/dist/images/marker-icon.svg +0 -1
- package/dist/images/marker-shadow.svg +0 -1
- package/src/core/Browser.js +0 -110
- package/src/images/layers.svg +0 -1
- package/src/images/marker-icon.svg +0 -1
- package/src/images/marker-shadow.svg +0 -1
|
@@ -43,14 +43,12 @@ import { CircleMarker } from "../layer/vector/CircleMarker.js";
|
|
|
43
43
|
*/
|
|
44
44
|
const svgNS = "http://www.w3.org/2000/svg";
|
|
45
45
|
var LegendControl = class LegendControl extends Control {
|
|
46
|
-
static {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
}
|
|
46
|
+
static defaultOptions = {
|
|
47
|
+
position: "bottomright",
|
|
48
|
+
collapsed: false,
|
|
49
|
+
featureCount: false,
|
|
50
|
+
bar: false
|
|
51
|
+
};
|
|
54
52
|
/**
|
|
55
53
|
* Creates a legend control.
|
|
56
54
|
* @param {...LegendControlOptions} args The options.
|
|
@@ -186,7 +184,7 @@ function formatCount({ count, share }) {
|
|
|
186
184
|
function createPatch(layer, symbol, styled) {
|
|
187
185
|
while (layer?.getLayers) layer = layer.getLayers()[0];
|
|
188
186
|
if (!layer?.setStyle) layer = void 0;
|
|
189
|
-
const base = layer?.options ?? CircleMarker.
|
|
187
|
+
const base = layer?.options ?? new CircleMarker([0, 0]).options, options = Object.assign(Object.create(base), layer && styled ? {} : symbol), svg = document.createElementNS(svgNS, "svg");
|
|
190
188
|
svg.setAttribute("class", "maplair-control-legend-patch");
|
|
191
189
|
svg.setAttribute("width", 16);
|
|
192
190
|
svg.setAttribute("height", 16);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LegendControl.js","names":["DomUtil.create"],"sources":["../../../src/control/LegendControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\nimport {CircleMarker} from '../layer/vector/CircleMarker.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {FeatureGroup} from '../layer/FeatureGroup.js' */\n/** @import {Classification} from '../layer/Classification.js' */\n\n/**\n * Options of `LegendControl`.\n * @typedef {object} LegendControlOptions\n * @property {string} [position='bottomright'] The position of the control (one of the\n * map corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {boolean} [collapsed=false] If `true`, the legend starts collapsed to its\n * title, which toggles it.\n * @property {boolean} [featureCount=false] If `true`, the number of features is shown\n * per class and per classification.\n * @property {boolean} [bar=false] If `true`, the feature count of each classification\n * is shown as a bar of the class symbols, each as wide as its share.\n * @extends ControlOptions\n */\n\n/**\n * A control showing the legend of the map: the classes of the layers added with\n * [`addClassification()`](#legendcontrol-addclassification), each with a patch in the\n * shape and symbol of its features and optionally the feature count, and the\n * legends of all layers on the map implementing [`getLegend()`](#layer-getlegend),\n * like the attribution control collects [`getAttribution()`](#layer-getattribution).\n * The legend is updated when features are added to or removed from the classified\n * layers (e.g. when reloading the data) and when a layer fires `legendchange`. It\n * is collapsible and hidden while empty. Placed at the bottom right, it sits right\n * above the attribution.\n *\n * Inspired by the legend of [QGIS](https://qgis.org/).\n *\n * @example\n * ```js\n * const legend = new LegendControl({featureCount: true, bar: true}).addTo(map);\n * legend.addClassification(stations, temperature);\n * ```\n */\n\nconst svgNS = 'http://www.w3.org/2000/svg';\n\nexport class LegendControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'bottomright',\n\t\t\tcollapsed: false,\n\t\t\tfeatureCount: false,\n\t\t\tbar: false\n\t\t});\n\t}\n\n\t/**\n\t * Creates a legend control.\n\t * @param {...LegendControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis._classifications = [];\n\t\tthis._legendLayers = new Set();\n\t\tthis.callInitHooks(LegendControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst container = DomUtil.create('div', 'maplair-control-legend'),\n\t\tdetails = this._details = DomUtil.create('details', '', container),\n\t\tsummary = DomUtil.create('summary', 'maplair-control-legend-title', details);\n\t\tsummary.textContent = I18n.translate('Legend');\n\t\tdetails.open = !this.options.collapsed;\n\t\tthis._list = DomUtil.create('div', 'maplair-control-legend-list', details);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tthis._container = container;\n\n\t\tmap.on('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._update();\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('layeradd layerremove', this._scheduleUpdate, this);\n\t\tcancelAnimationFrame(this._frame);\n\t\tthis._frame = null;\n\t\tfor (const layer of this._legendLayers) {\n\t\t\tlayer.off('legendchange', this._scheduleUpdate, this);\n\t\t}\n\t\tthis._legendLayers.clear();\n\t}\n\n\t/**\n\t * Shows the classes of `classification` in the legend while `layer` is on the map,\n\t * with the feature count of the layers of `layer` (e.g. a `GeoJSON` layer styled\n\t * with [`classification.style`](#classification-style)), kept up to date when\n\t * layers are added and removed.\n\t * @param {FeatureGroup} layer\n\t * @param {Classification} classification\n\t * @returns {this}\n\t */\n\taddClassification(layer, classification) {\n\t\tthis._classifications.push({layer, classification});\n\t\tlayer.on('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._scheduleUpdate();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the classification of `layer` from the legend.\n\t * @param {FeatureGroup} layer\n\t * @returns {this}\n\t */\n\tremoveClassification(layer) {\n\t\tthis._classifications = this._classifications.filter(entry => entry.layer !== layer);\n\t\tlayer.off('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._scheduleUpdate();\n\t\treturn this;\n\t}\n\n\t// updates once per frame, e.g. once after adding all features of a GeoJSON\n\t_scheduleUpdate() {\n\t\tif (!this._map || this._frame) { return; }\n\t\tthis._frame = requestAnimationFrame(() => {\n\t\t\tthis._frame = null;\n\t\t\tthis._update();\n\t\t});\n\t}\n\n\t_update() {\n\t\tconst map = this._map;\n\t\tif (!map) { return; }\n\n\t\tconst sections = this._classifications\n\t\t\t.filter(({layer}) => map.hasLayer(layer))\n\t\t\t.map(({layer, classification}) => this._renderClassification(layer, classification));\n\n\t\tconst legendLayers = new Set(Object.values(map._layers).filter(layer => layer.getLegend));\n\t\tfor (const layer of this._legendLayers) {\n\t\t\tif (!legendLayers.has(layer)) { layer.off('legendchange', this._scheduleUpdate, this); }\n\t\t}\n\t\tfor (const layer of legendLayers) {\n\t\t\tif (!this._legendLayers.has(layer)) { layer.on('legendchange', this._scheduleUpdate, this); }\n\t\t\tconst legend = layer.getLegend();\n\t\t\tif (legend) {\n\t\t\t\tconst section = DomUtil.create('div', 'maplair-control-legend-section');\n\t\t\t\tif (typeof legend === 'string') {\n\t\t\t\t\tsection.innerHTML = legend;\n\t\t\t\t} else {\n\t\t\t\t\tsection.append(legend);\n\t\t\t\t}\n\t\t\t\tsections.push(section);\n\t\t\t}\n\t\t}\n\t\tthis._legendLayers = legendLayers;\n\n\t\tthis._list.replaceChildren(...sections);\n\t\tthis._container.hidden = !sections.length;\n\t}\n\n\t_renderClassification(layer, classification) {\n\t\tconst layers = layer.getLayers(),\n\t\titems = classification.featureCount(layers),\n\t\t{featureCount, bar} = this.options,\n\t\tsection = DomUtil.create('div', 'maplair-control-legend-section'),\n\t\t{name} = classification.options,\n\t\ttotal = items.reduce((sum, item) => sum + (item.counted ? item.count : 0), 0);\n\n\t\tif (name) {\n\t\t\tDomUtil.create('div', 'maplair-control-legend-name', section).textContent = name;\n\t\t}\n\t\tif (featureCount) {\n\t\t\tDomUtil.create('div', 'maplair-control-legend-total', section).textContent =\n\t\t\t\tI18n.translate('{n} features', {n: total});\n\t\t}\n\n\t\t// a feature of each item, to draw its patch in the shape and style of the map\n\t\tconst samples = new Map();\n\t\tfor (const feature of layers) {\n\t\t\tconst cls = classification.classify(feature),\n\t\t\titem = items.find(i => i.classes.includes(cls));\n\t\t\tif (item && !samples.has(item)) { samples.set(item, feature); }\n\t\t\tif (samples.size === items.length) { break; }\n\t\t}\n\n\t\tconst list = DomUtil.create('ul', 'maplair-control-legend-items', section);\n\t\tfor (const item of items) {\n\t\t\tconst li = DomUtil.create('li', '', list);\n\t\t\tli.append(createPatch(samples.get(item) ?? layers[0], item.symbol, Boolean(samples.get(item))));\n\t\t\tDomUtil.create('span', 'maplair-control-legend-label', li).textContent = item.legend;\n\t\t\tif (featureCount && item.counted) {\n\t\t\t\tDomUtil.create('span', 'maplair-control-legend-count', li).textContent = formatCount(item);\n\t\t\t}\n\t\t}\n\n\t\tif (bar && total) {\n\t\t\tconst barEl = DomUtil.create('div', 'maplair-control-legend-bar', section);\n\t\t\tbarEl.setAttribute('role', 'img');\n\t\t\tbarEl.setAttribute('aria-label', items.filter(item => item.counted && item.count)\n\t\t\t\t.map(item => `${item.legend}: ${formatCount(item)}`).join(', '));\n\t\t\tfor (const item of items) {\n\t\t\t\tif (!item.counted || !item.count) { continue; }\n\t\t\t\tconst part = DomUtil.create('div', '', barEl);\n\t\t\t\tpart.style.flexGrow = item.count;\n\t\t\t\tpart.style.backgroundColor = item.symbol.fillColor ?? item.symbol.color ?? '';\n\t\t\t\tpart.title = `${item.legend}: ${formatCount(item)}`;\n\t\t\t}\n\t\t}\n\n\t\treturn section;\n\t}\n}\n\nfunction formatCount({count, share}) {\n\tconst percent = new Intl.NumberFormat(I18n.getLocale() ?? undefined, {style: 'percent', maximumFractionDigits: 1});\n\treturn `${count} (${percent.format(share)})`;\n}\n\n// a small SVG in the shape of the layer (circle, square for polygons, line for\n// polylines) with the style of the layer, or of the symbol over it if `styled` is false\n// (e.g. for a class without features); a circle marker for other layers like markers.\n// Duck-typed, so that the legend does not bundle the vector layers.\nfunction createPatch(layer, symbol, styled) {\n\twhile (layer?.getLayers) { layer = layer.getLayers()[0]; }\n\tif (!layer?.setStyle) { layer = undefined; }\n\tconst base = layer?.options ?? CircleMarker.prototype.options,\n\toptions = Object.assign(Object.create(base), layer && styled ? {} : symbol),\n\tsvg = document.createElementNS(svgNS, 'svg');\n\tsvg.setAttribute('class', 'maplair-control-legend-patch');\n\tsvg.setAttribute('width', 16);\n\tsvg.setAttribute('height', 16);\n\tsvg.setAttribute('viewBox', '0 0 16 16');\n\tsvg.setAttribute('aria-hidden', 'true');\n\n\tlet shape;\n\tif (layer?.getLatLngs && options.fill) {\n\t\tshape = svgElement('rect', {x: 2, y: 2, width: 12, height: 12});\n\t} else if (layer?.getLatLngs) {\n\t\tshape = svgElement('line', {x1: 1, y1: 8, x2: 15, y2: 8});\n\t} else {\n\t\tshape = svgElement('circle', {cx: 8, cy: 8, r: 6});\n\t}\n\n\tshape.setAttribute('fill', options.fill ? options.fillColor ?? options.color : 'none');\n\tshape.setAttribute('fill-opacity', options.fillOpacity);\n\tshape.setAttribute('stroke', options.stroke ? options.color : 'none');\n\tshape.setAttribute('stroke-opacity', options.opacity);\n\tshape.setAttribute('stroke-width', Math.min(options.weight, 4));\n\tif (options.dashArray) { shape.setAttribute('stroke-dasharray', options.dashArray); }\n\tsvg.append(shape);\n\treturn svg;\n}\n\nfunction svgElement(name, attributes) {\n\tconst el = document.createElementNS(svgNS, name);\n\tfor (const [key, value] of Object.entries(attributes)) {\n\t\tel.setAttribute(key, value);\n\t}\n\treturn el;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,QAAQ;AAEd,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C;EACC,KAAK,kBAAkB;GACtB,UAAU;GACV,WAAW;GACX,cAAc;GACd,KAAK;EACN,CAAC;CACF;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,mBAAmB,CAAC;EACzB,KAAK,gCAAgB,IAAI,IAAI;EAC7B,KAAK,cAAc,aAAa;CACjC;;;;;;CAOA,MAAM,KAAK;EAC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,IAAI,OAAO,KAAK;CAChB,OAAO;AACR;AAEA,SAAS,WAAW,MAAM,YAAY;CACrC,MAAM,KAAK,SAAS,gBAAgB,OAAO,IAAI;CAC/C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,GACnD,GAAG,aAAa,KAAK,KAAK;CAE3B,OAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"LegendControl.js","names":["DomUtil.create"],"sources":["../../../src/control/LegendControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\nimport {CircleMarker} from '../layer/vector/CircleMarker.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {FeatureGroup} from '../layer/FeatureGroup.js' */\n/** @import {Classification} from '../layer/Classification.js' */\n\n/**\n * Options of `LegendControl`.\n * @typedef {object} LegendControlOptions\n * @property {string} [position='bottomright'] The position of the control (one of the\n * map corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {boolean} [collapsed=false] If `true`, the legend starts collapsed to its\n * title, which toggles it.\n * @property {boolean} [featureCount=false] If `true`, the number of features is shown\n * per class and per classification.\n * @property {boolean} [bar=false] If `true`, the feature count of each classification\n * is shown as a bar of the class symbols, each as wide as its share.\n * @extends ControlOptions\n */\n\n/**\n * A control showing the legend of the map: the classes of the layers added with\n * [`addClassification()`](#legendcontrol-addclassification), each with a patch in the\n * shape and symbol of its features and optionally the feature count, and the\n * legends of all layers on the map implementing [`getLegend()`](#layer-getlegend),\n * like the attribution control collects [`getAttribution()`](#layer-getattribution).\n * The legend is updated when features are added to or removed from the classified\n * layers (e.g. when reloading the data) and when a layer fires `legendchange`. It\n * is collapsible and hidden while empty. Placed at the bottom right, it sits right\n * above the attribution.\n *\n * Inspired by the legend of [QGIS](https://qgis.org/).\n *\n * @example\n * ```js\n * const legend = new LegendControl({featureCount: true, bar: true}).addTo(map);\n * legend.addClassification(stations, temperature);\n * ```\n */\n\nconst svgNS = 'http://www.w3.org/2000/svg';\n\nexport class LegendControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'bottomright',\n\t\tcollapsed: false,\n\t\tfeatureCount: false,\n\t\tbar: false\n\t};\n\n\t/**\n\t * Creates a legend control.\n\t * @param {...LegendControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis._classifications = [];\n\t\tthis._legendLayers = new Set();\n\t\tthis.callInitHooks(LegendControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst container = DomUtil.create('div', 'maplair-control-legend'),\n\t\tdetails = this._details = DomUtil.create('details', '', container),\n\t\tsummary = DomUtil.create('summary', 'maplair-control-legend-title', details);\n\t\tsummary.textContent = I18n.translate('Legend');\n\t\tdetails.open = !this.options.collapsed;\n\t\tthis._list = DomUtil.create('div', 'maplair-control-legend-list', details);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tthis._container = container;\n\n\t\tmap.on('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._update();\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('layeradd layerremove', this._scheduleUpdate, this);\n\t\tcancelAnimationFrame(this._frame);\n\t\tthis._frame = null;\n\t\tfor (const layer of this._legendLayers) {\n\t\t\tlayer.off('legendchange', this._scheduleUpdate, this);\n\t\t}\n\t\tthis._legendLayers.clear();\n\t}\n\n\t/**\n\t * Shows the classes of `classification` in the legend while `layer` is on the map,\n\t * with the feature count of the layers of `layer` (e.g. a `GeoJSON` layer styled\n\t * with [`classification.style`](#classification-style)), kept up to date when\n\t * layers are added and removed.\n\t * @param {FeatureGroup} layer\n\t * @param {Classification} classification\n\t * @returns {this}\n\t */\n\taddClassification(layer, classification) {\n\t\tthis._classifications.push({layer, classification});\n\t\tlayer.on('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._scheduleUpdate();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the classification of `layer` from the legend.\n\t * @param {FeatureGroup} layer\n\t * @returns {this}\n\t */\n\tremoveClassification(layer) {\n\t\tthis._classifications = this._classifications.filter(entry => entry.layer !== layer);\n\t\tlayer.off('layeradd layerremove', this._scheduleUpdate, this);\n\t\tthis._scheduleUpdate();\n\t\treturn this;\n\t}\n\n\t// updates once per frame, e.g. once after adding all features of a GeoJSON\n\t_scheduleUpdate() {\n\t\tif (!this._map || this._frame) { return; }\n\t\tthis._frame = requestAnimationFrame(() => {\n\t\t\tthis._frame = null;\n\t\t\tthis._update();\n\t\t});\n\t}\n\n\t_update() {\n\t\tconst map = this._map;\n\t\tif (!map) { return; }\n\n\t\tconst sections = this._classifications\n\t\t\t.filter(({layer}) => map.hasLayer(layer))\n\t\t\t.map(({layer, classification}) => this._renderClassification(layer, classification));\n\n\t\tconst legendLayers = new Set(Object.values(map._layers).filter(layer => layer.getLegend));\n\t\tfor (const layer of this._legendLayers) {\n\t\t\tif (!legendLayers.has(layer)) { layer.off('legendchange', this._scheduleUpdate, this); }\n\t\t}\n\t\tfor (const layer of legendLayers) {\n\t\t\tif (!this._legendLayers.has(layer)) { layer.on('legendchange', this._scheduleUpdate, this); }\n\t\t\tconst legend = layer.getLegend();\n\t\t\tif (legend) {\n\t\t\t\tconst section = DomUtil.create('div', 'maplair-control-legend-section');\n\t\t\t\tif (typeof legend === 'string') {\n\t\t\t\t\tsection.innerHTML = legend;\n\t\t\t\t} else {\n\t\t\t\t\tsection.append(legend);\n\t\t\t\t}\n\t\t\t\tsections.push(section);\n\t\t\t}\n\t\t}\n\t\tthis._legendLayers = legendLayers;\n\n\t\tthis._list.replaceChildren(...sections);\n\t\tthis._container.hidden = !sections.length;\n\t}\n\n\t_renderClassification(layer, classification) {\n\t\tconst layers = layer.getLayers(),\n\t\titems = classification.featureCount(layers),\n\t\t{featureCount, bar} = this.options,\n\t\tsection = DomUtil.create('div', 'maplair-control-legend-section'),\n\t\t{name} = classification.options,\n\t\ttotal = items.reduce((sum, item) => sum + (item.counted ? item.count : 0), 0);\n\n\t\tif (name) {\n\t\t\tDomUtil.create('div', 'maplair-control-legend-name', section).textContent = name;\n\t\t}\n\t\tif (featureCount) {\n\t\t\tDomUtil.create('div', 'maplair-control-legend-total', section).textContent =\n\t\t\t\tI18n.translate('{n} features', {n: total});\n\t\t}\n\n\t\t// a feature of each item, to draw its patch in the shape and style of the map\n\t\tconst samples = new Map();\n\t\tfor (const feature of layers) {\n\t\t\tconst cls = classification.classify(feature),\n\t\t\titem = items.find(i => i.classes.includes(cls));\n\t\t\tif (item && !samples.has(item)) { samples.set(item, feature); }\n\t\t\tif (samples.size === items.length) { break; }\n\t\t}\n\n\t\tconst list = DomUtil.create('ul', 'maplair-control-legend-items', section);\n\t\tfor (const item of items) {\n\t\t\tconst li = DomUtil.create('li', '', list);\n\t\t\tli.append(createPatch(samples.get(item) ?? layers[0], item.symbol, Boolean(samples.get(item))));\n\t\t\tDomUtil.create('span', 'maplair-control-legend-label', li).textContent = item.legend;\n\t\t\tif (featureCount && item.counted) {\n\t\t\t\tDomUtil.create('span', 'maplair-control-legend-count', li).textContent = formatCount(item);\n\t\t\t}\n\t\t}\n\n\t\tif (bar && total) {\n\t\t\tconst barEl = DomUtil.create('div', 'maplair-control-legend-bar', section);\n\t\t\tbarEl.setAttribute('role', 'img');\n\t\t\tbarEl.setAttribute('aria-label', items.filter(item => item.counted && item.count)\n\t\t\t\t.map(item => `${item.legend}: ${formatCount(item)}`).join(', '));\n\t\t\tfor (const item of items) {\n\t\t\t\tif (!item.counted || !item.count) { continue; }\n\t\t\t\tconst part = DomUtil.create('div', '', barEl);\n\t\t\t\tpart.style.flexGrow = item.count;\n\t\t\t\tpart.style.backgroundColor = item.symbol.fillColor ?? item.symbol.color ?? '';\n\t\t\t\tpart.title = `${item.legend}: ${formatCount(item)}`;\n\t\t\t}\n\t\t}\n\n\t\treturn section;\n\t}\n}\n\nfunction formatCount({count, share}) {\n\tconst percent = new Intl.NumberFormat(I18n.getLocale() ?? undefined, {style: 'percent', maximumFractionDigits: 1});\n\treturn `${count} (${percent.format(share)})`;\n}\n\n// a small SVG in the shape of the layer (circle, square for polygons, line for\n// polylines) with the style of the layer, or of the symbol over it if `styled` is false\n// (e.g. for a class without features); a circle marker for other layers like markers.\n// Duck-typed, so that the legend does not bundle the vector layers.\nfunction createPatch(layer, symbol, styled) {\n\twhile (layer?.getLayers) { layer = layer.getLayers()[0]; }\n\tif (!layer?.setStyle) { layer = undefined; }\n\tconst base = layer?.options ?? new CircleMarker([0, 0]).options,\n\toptions = Object.assign(Object.create(base), layer && styled ? {} : symbol),\n\tsvg = document.createElementNS(svgNS, 'svg');\n\tsvg.setAttribute('class', 'maplair-control-legend-patch');\n\tsvg.setAttribute('width', 16);\n\tsvg.setAttribute('height', 16);\n\tsvg.setAttribute('viewBox', '0 0 16 16');\n\tsvg.setAttribute('aria-hidden', 'true');\n\n\tlet shape;\n\tif (layer?.getLatLngs && options.fill) {\n\t\tshape = svgElement('rect', {x: 2, y: 2, width: 12, height: 12});\n\t} else if (layer?.getLatLngs) {\n\t\tshape = svgElement('line', {x1: 1, y1: 8, x2: 15, y2: 8});\n\t} else {\n\t\tshape = svgElement('circle', {cx: 8, cy: 8, r: 6});\n\t}\n\n\tshape.setAttribute('fill', options.fill ? options.fillColor ?? options.color : 'none');\n\tshape.setAttribute('fill-opacity', options.fillOpacity);\n\tshape.setAttribute('stroke', options.stroke ? options.color : 'none');\n\tshape.setAttribute('stroke-opacity', options.opacity);\n\tshape.setAttribute('stroke-width', Math.min(options.weight, 4));\n\tif (options.dashArray) { shape.setAttribute('stroke-dasharray', options.dashArray); }\n\tsvg.append(shape);\n\treturn svg;\n}\n\nfunction svgElement(name, attributes) {\n\tconst el = document.createElementNS(svgNS, name);\n\tfor (const [key, value] of Object.entries(attributes)) {\n\t\tel.setAttribute(key, value);\n\t}\n\treturn el;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,QAAQ;AAEd,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C,OAAO,iBAAiB;EACvB,UAAU;EACV,WAAW;EACX,cAAc;EACd,KAAK;CACN;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,mBAAmB,CAAC;EACzB,KAAK,gCAAgB,IAAI,IAAI;EAC7B,KAAK,cAAc,aAAa;CACjC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAYA,OAAe,OAAO,wBAAwB,GAChE,UAAU,KAAK,WAAWA,OAAe,WAAW,IAAI,SAAS,GACjE,UAAUA,OAAe,WAAW,gCAAgC,OAAO;EAC3E,QAAQ,cAAc,KAAK,UAAU,QAAQ;EAC7C,QAAQ,OAAO,CAAC,KAAK,QAAQ;EAC7B,KAAK,QAAQA,OAAe,OAAO,+BAA+B,OAAO;EAEzE,wBAAiC,SAAS;EAC1C,yBAAkC,SAAS;EAC3C,KAAK,aAAa;EAElB,IAAI,GAAG,wBAAwB,KAAK,iBAAiB,IAAI;EACzD,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,SAAS,KAAK;EACb,IAAI,IAAI,wBAAwB,KAAK,iBAAiB,IAAI;EAC1D,qBAAqB,KAAK,MAAM;EAChC,KAAK,SAAS;EACd,KAAK,MAAM,SAAS,KAAK,eACxB,MAAM,IAAI,gBAAgB,KAAK,iBAAiB,IAAI;EAErD,KAAK,cAAc,MAAM;CAC1B;;;;;;;;;;CAWA,kBAAkB,OAAO,gBAAgB;EACxC,KAAK,iBAAiB,KAAK;GAAC;GAAO;EAAc,CAAC;EAClD,MAAM,GAAG,wBAAwB,KAAK,iBAAiB,IAAI;EAC3D,KAAK,gBAAgB;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AQ,WAAW,QAAQ;EAAC,IAAI;EAAG,IAAI;EAAG,IAAI;EAAI,IAAI;CAAC,CAAC;MAExD,QAAQ,WAAW,UAAU;EAAC,IAAI;EAAG,IAAI;EAAG,GAAG;CAAC,CAAC;CAGlD,MAAM,aAAa,QAAQ,QAAQ,OAAO,QAAQ,aAAa,QAAQ,QAAQ,MAAM;CACrF,MAAM,aAAa,gBAAgB,QAAQ,WAAW;CACtD,MAAM,aAAa,UAAU,QAAQ,SAAS,QAAQ,QAAQ,MAAM;CACpE,MAAM,aAAa,kBAAkB,QAAQ,OAAO;CACpD,MAAM,aAAa,gBAAgB,KAAK,IAAI,QAAQ,QAAQ,CAAC,CAAC;CAC9D,IAAI,QAAQ,WAAa,MAAM,aAAa,oBAAoB,QAAQ,SAAS;CACjF,IAAI,OAAO,KAAK;CAChB,OAAO;AACR;AAEA,SAAS,WAAW,MAAM,YAAY;CACrC,MAAM,KAAK,SAAS,gBAAgB,OAAO,IAAI;CAC/C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,GACnD,GAAG,aAAa,KAAK,KAAK;CAE3B,OAAO;AACR"}
|
|
@@ -2,7 +2,7 @@ import { disableClickPropagation, disableScrollPropagation, on, stop } from "../
|
|
|
2
2
|
import { create } from "../dom/DomUtil.js";
|
|
3
3
|
import { Control } from "./Control.js";
|
|
4
4
|
import { I18n } from "../core/I18n.js";
|
|
5
|
-
import { MaplairMap } from "../map/Map.js";
|
|
5
|
+
import { LeafletMap as MaplairMap } from "../map/Map.js";
|
|
6
6
|
import { Polygon } from "../layer/vector/Polygon.js";
|
|
7
7
|
//#region src/control/MiniMapControl.js
|
|
8
8
|
/** @import {ControlOptions} from './Control.js' */
|
|
@@ -41,21 +41,19 @@ import { Polygon } from "../layer/vector/Polygon.js";
|
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
43
|
var MiniMapControl = class MiniMapControl extends Control {
|
|
44
|
-
static {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
}
|
|
44
|
+
static defaultOptions = {
|
|
45
|
+
position: "bottomright",
|
|
46
|
+
width: 150,
|
|
47
|
+
height: 150,
|
|
48
|
+
zoomOffset: -5,
|
|
49
|
+
collapsed: false,
|
|
50
|
+
rectangleOptions: {
|
|
51
|
+
color: "#ff7800",
|
|
52
|
+
weight: 1,
|
|
53
|
+
fillOpacity: .2
|
|
54
|
+
},
|
|
55
|
+
mapOptions: {}
|
|
56
|
+
};
|
|
59
57
|
/**
|
|
60
58
|
* Creates an overview map control showing `layer` (which must not be on another map).
|
|
61
59
|
* @param {Layer} layer
|
|
@@ -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,KA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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.
|
|
@@ -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"}
|
|
@@ -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.
|
|
@@ -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 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AY,WAC5B,KAAK,gBAAgB,SAAS;CAEhC;CAEA,cAAc,WAAW;EACxB,MAAM,SAAS,KAAK,aAAa,SAAS,GAC1C,QAAQ,SAAS,MAChB,KAAK,UAAU,cAAc,EAAC,OAAM,CAAC,IACrC,KAAK,UAAU,mBAAmB,EAAC,YAAY,SAAS,IAAI,CAAC;EAE9D,KAAK,aAAa,KAAK,SAAS,OAAO,SAAS,SAAS;CAC1D;CAEA,gBAAgB,WAAW;EAC1B,MAAM,UAAU,YAAY;EAC5B,IAAI,UAAU,OAAO;EAErB,IAAI,UAAU,MAAM;GACnB,WAAW,UAAU;GACrB,QAAQ,KAAK,aAAa,QAAQ;GAClC,KAAK,aAAa,KAAK,SAAS,KAAK,UAAU,cAAc,EAAC,MAAK,CAAC,GAAG,QAAQ,QAAQ;EAExF,OAAO;GACN,OAAO,KAAK,aAAa,OAAO;GAChC,KAAK,aAAa,KAAK,SAAS,KAAK,UAAU,aAAa,EAAC,KAAI,CAAC,GAAG,OAAO,OAAO;EACpF;CACD;CAEA,aAAa,OAAO,MAAM,OAAO;EAChC,MAAM,MAAM,QAAQ,GAAG,KAAK,MAAM,KAAK,QAAQ,WAAW,KAAK,EAAE;EACjE,MAAM,YAAY;CACnB;CAEA,aAAa,KAAK;EACjB,MAAM,QAAQ,OAAQ,GAAG,KAAK,MAAM,GAAG,IAAK,SAAS;EACrD,IAAI,IAAI,MAAM;EAEd,IAAI,KAAK,KAAK,KACb,KAAK,IAAI,IACT,KAAK,IAAI,IACT,KAAK,IAAI,IAAI;EAEd,OAAO,QAAQ;CAChB;AACD"}
|
|
@@ -12,6 +12,8 @@ import { Marker } from "../layer/marker/Marker.js";
|
|
|
12
12
|
/** @import {MaplairEvent} from '../core/Events.js' */
|
|
13
13
|
/** @import {LatLngExpression} from '../geo/LatLng.js' */
|
|
14
14
|
/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */
|
|
15
|
+
/** @import {Layer} from '../layer/Layer.js' */
|
|
16
|
+
/** @import {LayerGroup} from '../layer/LayerGroup.js' */
|
|
15
17
|
const searchIcon = "<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><circle cx=\"6.5\" cy=\"6.5\" r=\"4.5\"/><path d=\"M10 10l4.5 4.5\"/></svg>";
|
|
16
18
|
const nextRequests = /* @__PURE__ */ new Map();
|
|
17
19
|
function delay(ms, signal) {
|
|
@@ -31,6 +33,8 @@ function delay(ms, signal) {
|
|
|
31
33
|
* @property {LatLngBoundsExpression} [bounds] The extent of the result, e.g. of a city,
|
|
32
34
|
* which the map fits to instead of zooming to the position.
|
|
33
35
|
* @property {any} [raw] The original result of the service, for use in event listeners.
|
|
36
|
+
* @property {Layer} [layer] The found layer, by [`SearchControl.layers()`](#searchcontrol-layers),
|
|
37
|
+
* e.g. to open its tooltip in a `searchresult` listener.
|
|
34
38
|
*/
|
|
35
39
|
/**
|
|
36
40
|
* A function searching places for a query, see the [`geocoder`](#searchcontrol-geocoder)
|
|
@@ -62,9 +66,17 @@ function delay(ms, signal) {
|
|
|
62
66
|
* [`autoComplete`](#searchcontrol-autocomplete).
|
|
63
67
|
* @property {number} [zoom=16] The zoom level for results without bounds, and the
|
|
64
68
|
* maximum zoom level for fitting the bounds of results.
|
|
65
|
-
* @property {boolean} [marker=true] Whether
|
|
69
|
+
* @property {boolean|((result: SearchResult) => Layer|null|undefined)} [marker=true] Whether
|
|
70
|
+
* to show a marker at the selected result, or a function returning the layer to show
|
|
71
|
+
* instead, e.g. a `CircleMarker` highlighting the result (or nothing for none). The
|
|
72
|
+
* layer is removed when the search is cleared or another result is selected.
|
|
73
|
+
* @property {boolean} [clearOnMapClick=false] If `true`, a click on the map clears the
|
|
74
|
+
* search (the field, the results and the marker) and collapses the control. By
|
|
75
|
+
* default, the click only hides the results and the marker stays.
|
|
66
76
|
* @property {string} [placeholder] The placeholder of the search field, by default
|
|
67
77
|
* the translation of "Search".
|
|
78
|
+
* @property {string} [noResultsText] The message shown if nothing is found, by
|
|
79
|
+
* default the translation of "No results".
|
|
68
80
|
* @extends ControlOptions
|
|
69
81
|
*/
|
|
70
82
|
/**
|
|
@@ -116,19 +128,19 @@ function delay(ms, signal) {
|
|
|
116
128
|
* [search control](#searchcontrol) is selected.
|
|
117
129
|
*/
|
|
118
130
|
var SearchControl = class SearchControl extends Control {
|
|
119
|
-
static {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
131
|
+
static defaultOptions = {
|
|
132
|
+
position: "topleft",
|
|
133
|
+
geocoder: void 0,
|
|
134
|
+
collapsed: true,
|
|
135
|
+
autoComplete: false,
|
|
136
|
+
autoCompleteDelay: 250,
|
|
137
|
+
minLength: 3,
|
|
138
|
+
zoom: 16,
|
|
139
|
+
marker: true,
|
|
140
|
+
clearOnMapClick: false,
|
|
141
|
+
placeholder: void 0,
|
|
142
|
+
noResultsText: void 0
|
|
143
|
+
};
|
|
132
144
|
/**
|
|
133
145
|
* Returns a [geocoder](#searchcontrol-geocoder) searching with
|
|
134
146
|
* [Nominatim](https://nominatim.org/release-docs/latest/api/Search/), by default the
|
|
@@ -192,6 +204,72 @@ var SearchControl = class SearchControl extends Control {
|
|
|
192
204
|
});
|
|
193
205
|
}
|
|
194
206
|
/**
|
|
207
|
+
* Returns a [geocoder](#searchcontrol-geocoder) searching the layers of a layer group,
|
|
208
|
+
* e.g. the markers of a `FeatureGroup` or the features of a `GeoJSON` layer, by their
|
|
209
|
+
* label: a property of their GeoJSON feature (`layer.feature.properties`) or the
|
|
210
|
+
* result of a function. The group is searched at the time of the search, so layers
|
|
211
|
+
* added later are found as well, and nested groups without a label are searched
|
|
212
|
+
* recursively. The search ignores the case and finds the query anywhere in the
|
|
213
|
+
* label; labels starting with it come first, then in alphabetical order. The results
|
|
214
|
+
* contain the found `layer` and its GeoJSON feature as `raw`; layers without a
|
|
215
|
+
* single position (e.g. polygons) have the `bounds` and their center as `latlng`.
|
|
216
|
+
* Combine it with [`autoComplete`](#searchcontrol-autocomplete) to search while
|
|
217
|
+
* typing, and with [`marker`](#searchcontrol-marker) `false` or a function to not
|
|
218
|
+
* cover the found marker with another one.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```js
|
|
222
|
+
* const stations = new GeoJSON(data, {
|
|
223
|
+
* onEachFeature: (feature, layer) => layer.bindTooltip(feature.properties.name)
|
|
224
|
+
* }).addTo(map);
|
|
225
|
+
* new SearchControl({
|
|
226
|
+
* geocoder: SearchControl.layers(stations, {property: 'name'}),
|
|
227
|
+
* autoComplete: true,
|
|
228
|
+
* minLength: 1,
|
|
229
|
+
* marker: false
|
|
230
|
+
* }).addTo(map);
|
|
231
|
+
* map.on('searchresult', ({result}) => result.layer.openTooltip());
|
|
232
|
+
* ```
|
|
233
|
+
* @param {LayerGroup} group The layer group to search.
|
|
234
|
+
* @param {object} [options]
|
|
235
|
+
* @param {string} [options.property='name'] The property of the GeoJSON features to
|
|
236
|
+
* search.
|
|
237
|
+
* @param {(layer: Layer) => string|number|null|undefined} [options.label] A function
|
|
238
|
+
* returning the label of a layer instead of the `property`, nothing to skip the
|
|
239
|
+
* layer (or to search its layers, if it is a group).
|
|
240
|
+
* @param {number} [options.limit=10] The maximum number of results.
|
|
241
|
+
* @returns {Geocoder}
|
|
242
|
+
*/
|
|
243
|
+
static layers(group, { property = "name", label = (layer) => layer.feature?.properties?.[property], limit = 10 } = {}) {
|
|
244
|
+
return (query) => {
|
|
245
|
+
query = query.toLocaleLowerCase();
|
|
246
|
+
const found = [];
|
|
247
|
+
group.eachLayer(function search(layer) {
|
|
248
|
+
const text = label(layer);
|
|
249
|
+
if (text === void 0 || text === null || text === "") {
|
|
250
|
+
layer.eachLayer?.(search);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const result = {
|
|
254
|
+
label: String(text),
|
|
255
|
+
layer,
|
|
256
|
+
raw: layer.feature
|
|
257
|
+
}, index = result.label.toLocaleLowerCase().indexOf(query);
|
|
258
|
+
if (index < 0) return;
|
|
259
|
+
if (layer.getLatLng) result.latlng = layer.getLatLng();
|
|
260
|
+
else if (layer.getBounds?.().isValid()) {
|
|
261
|
+
result.bounds = layer.getBounds();
|
|
262
|
+
result.latlng = result.bounds.getCenter();
|
|
263
|
+
} else return;
|
|
264
|
+
found.push({
|
|
265
|
+
result,
|
|
266
|
+
prefix: index === 0
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
return Promise.resolve(found.sort((a, b) => b.prefix - a.prefix || a.result.label.localeCompare(b.result.label)).slice(0, limit).map(({ result }) => result));
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
195
273
|
* Creates a search control.
|
|
196
274
|
* @param {...SearchControlOptions} args The options.
|
|
197
275
|
*/
|
|
@@ -300,7 +378,7 @@ var SearchControl = class SearchControl extends Control {
|
|
|
300
378
|
this._container.classList.add("maplair-control-search-loading");
|
|
301
379
|
try {
|
|
302
380
|
const results = await this.options.geocoder(query, { signal: controller.signal });
|
|
303
|
-
if (!controller.signal.aborted) this._showResults(results, I18n.translate("No results"));
|
|
381
|
+
if (!controller.signal.aborted) this._showResults(results, this.options.noResultsText ?? I18n.translate("No results"));
|
|
304
382
|
return results;
|
|
305
383
|
} catch (error) {
|
|
306
384
|
if (controller.signal.aborted) return [];
|
|
@@ -320,13 +398,14 @@ var SearchControl = class SearchControl extends Control {
|
|
|
320
398
|
* @returns {this}
|
|
321
399
|
*/
|
|
322
400
|
select(result) {
|
|
323
|
-
const map = this._map, latlng =
|
|
401
|
+
const map = this._map, latlng = LatLng.from(result.latlng), bounds = result.bounds ? LatLngBounds.from(result.bounds) : void 0;
|
|
324
402
|
this._input.value = result.label;
|
|
325
403
|
this._showResults([]);
|
|
326
404
|
if (bounds?.isValid() && !bounds.getNorthWest().equals(bounds.getSouthEast())) map.fitBounds(bounds, { maxZoom: this.options.zoom });
|
|
327
405
|
else map.setView(latlng, this.options.zoom);
|
|
328
406
|
this._marker?.remove();
|
|
329
|
-
|
|
407
|
+
const { marker } = this.options;
|
|
408
|
+
this._marker = typeof marker === "function" ? marker(result)?.addTo(map) ?? null : marker ? new Marker(latlng, { title: result.label }).addTo(map) : null;
|
|
330
409
|
map.fire("searchresult", {
|
|
331
410
|
result,
|
|
332
411
|
latlng,
|
|
@@ -432,7 +511,10 @@ var SearchControl = class SearchControl extends Control {
|
|
|
432
511
|
if (index >= 0) this.select(this._results[index]);
|
|
433
512
|
}
|
|
434
513
|
_onMapClick() {
|
|
435
|
-
if (this.
|
|
514
|
+
if (this.options.clearOnMapClick) {
|
|
515
|
+
this.clear();
|
|
516
|
+
this.collapse();
|
|
517
|
+
} else if (this._input.value) this._showResults([]);
|
|
436
518
|
else this.collapse();
|
|
437
519
|
}
|
|
438
520
|
};
|