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
|
@@ -6,12 +6,14 @@ import { I18n } from "../core/I18n.js";
|
|
|
6
6
|
import { LatLngBounds } from "../geo/LatLngBounds.js";
|
|
7
7
|
import { LatLng } from "../geo/LatLng.js";
|
|
8
8
|
import { Marker } from "../layer/marker/Marker.js";
|
|
9
|
-
|
|
9
|
+
// src/control/SearchControl.js
|
|
10
10
|
/** @import {ControlOptions} from './Control.js' */
|
|
11
11
|
/** @import {MaplairMap} from '../map/Map.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 [];
|
|
@@ -326,7 +404,8 @@ var SearchControl = class SearchControl extends Control {
|
|
|
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,11 +511,13 @@ 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
|
};
|
|
439
|
-
//#endregion
|
|
440
521
|
export { SearchControl };
|
|
441
522
|
|
|
442
523
|
//# sourceMappingURL=SearchControl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchControl.js","names":["DomUtil.create","Util.stamp","Util.falseFn"],"sources":["../../../src/control/SearchControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport {Marker} from '../layer/marker/Marker.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n\nconst 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>';\n\n// the time of the next allowed request to each Nominatim server, shared by all geocoders\nconst nextRequests = new Map();\n\n// Resolves after `ms` milliseconds, rejects when the signal aborts\nfunction delay(ms, signal) {\n\treturn new Promise((resolve, reject) => {\n\t\tconst timeout = setTimeout(resolve, ms);\n\t\tsignal.addEventListener('abort', () => {\n\t\t\tclearTimeout(timeout);\n\t\t\treject(signal.reason);\n\t\t}, {once: true});\n\t});\n}\n\n/**\n * A result of a search, returned by a [geocoder](#searchcontrol-geocoder).\n * @typedef {object} SearchResult\n * @property {string} label The text shown in the list of results, e.g. an address.\n * @property {LatLngExpression} latlng The position of the result.\n * @property {LatLngBoundsExpression} [bounds] The extent of the result, e.g. of a city,\n * which the map fits to instead of zooming to the position.\n * @property {any} [raw] The original result of the service, for use in event listeners.\n */\n\n/**\n * A function searching places for a query, see the [`geocoder`](#searchcontrol-geocoder)\n * option. It should pass the `signal` to `fetch()`: searches are aborted when the user\n * starts another one. Optional properties of the function: `attribution`, an attribution\n * text which the control adds to the map, and `autoComplete: false` if the service\n * forbids searching while typing (overriding the\n * [`autoComplete`](#searchcontrol-autocomplete) option).\n * @typedef {((query: string, options: {signal: AbortSignal}) => Promise<SearchResult[]>) & {attribution?: string, autoComplete?: boolean}} Geocoder\n */\n\n/**\n * Options of `SearchControl`.\n * @typedef {object} SearchControlOptions\n * @property {string} [position='topleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {Geocoder} geocoder The function searching places (required), e.g.\n * [Nominatim](#searchcontrol-nominatim). Coordinates (see\n * [`LatLng.parse()`](#latlng-parse)) are found without it.\n * @property {boolean} [collapsed=true] If `true`, the control is collapsed into a button\n * and expanded on click.\n * @property {boolean} [autoComplete=false] Whether to search while typing instead of\n * on <kbd>Enter</kbd>. Not with the public Nominatim service, its\n * [usage policy](https://operations.osmfoundation.org/policies/nominatim/) forbids\n * auto-complete.\n * @property {number} [autoCompleteDelay=250] The delay in milliseconds after typing\n * before searching with [`autoComplete`](#searchcontrol-autocomplete).\n * @property {number} [minLength=3] The minimum length of queries searched with\n * [`autoComplete`](#searchcontrol-autocomplete).\n * @property {number} [zoom=16] The zoom level for results without bounds, and the\n * maximum zoom level for fitting the bounds of results.\n * @property {boolean} [marker=true] Whether to show a marker at the selected result.\n * @property {string} [placeholder] The placeholder of the search field, by default\n * the translation of \"Search\".\n * @extends ControlOptions\n */\n\n/**\n * The event object of `searchresult`.\n * @typedef {object} SearchResultEvent\n * @property {SearchResult} result The selected result.\n * @property {LatLng} latlng The position of the result.\n * @property {LatLngBounds|undefined} bounds The extent of the result, if any.\n * @extends MaplairEvent\n */\n\n/**\n * A control with a search field for places, showing the results in a list to select\n * one with the pointer or the keyboard. The selected result is shown on the map with a\n * marker. It searches with a [`geocoder`](#searchcontrol-geocoder), e.g.\n * [Nominatim](#searchcontrol-nominatim) of OpenStreetMap or any other service.\n * Coordinates like `47.27, 11.4` or `geo:47.27,11.4` are found without a service.\n *\n * The public Nominatim service is free, but limited by its\n * [usage policy](https://operations.osmfoundation.org/policies/nominatim/): it is for\n * occasional searches of users, not for heavy use (an absolute maximum of one request\n * per second for all users of an app), and forbids auto-complete. The\n * [Nominatim geocoder](#searchcontrol-nominatim) follows the technical requirements,\n * but you are responsible for your use of the service, which you confirm with the\n * `acceptUsagePolicy` option: for more traffic, use your own Nominatim server or a\n * commercial provider.\n *\n * @example\n * ```js\n * new SearchControl({\n * geocoder: SearchControl.nominatim({acceptUsagePolicy: true})\n * }).addTo(map);\n *\n * // Photon of Komoot, which allows auto-complete\n * new SearchControl({\n * autoComplete: true,\n * async geocoder(query, {signal}) {\n * const response = await fetch(`https://photon.komoot.io/api/?q=${encodeURIComponent(query)}`, {signal});\n * const {features} = await response.json();\n * return features.map(({geometry, properties}) => ({\n * label: [properties.name, properties.city, properties.country].filter(Boolean).join(', '),\n * latlng: [geometry.coordinates[1], geometry.coordinates[0]],\n * raw: properties\n * }));\n * }\n * }).addTo(map);\n * ```\n *\n * @fires MaplairMap#searchresult {SearchResultEvent} Fired when a result of the\n * [search control](#searchcontrol) is selected.\n */\nexport class SearchControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'topleft',\n\t\t\tgeocoder: undefined,\n\t\t\tcollapsed: true,\n\t\t\tautoComplete: false,\n\t\t\tautoCompleteDelay: 250,\n\t\t\tminLength: 3,\n\t\t\tzoom: 16,\n\t\t\tmarker: true,\n\t\t\tplaceholder: undefined\n\t\t});\n\t}\n\n\t/**\n\t * Returns a [geocoder](#searchcontrol-geocoder) searching with\n\t * [Nominatim](https://nominatim.org/release-docs/latest/api/Search/), by default the\n\t * public service of OpenStreetMap. Using it requires that you read and accept its\n\t * [usage policy](https://operations.osmfoundation.org/policies/nominatim/) with the\n\t * `acceptUsagePolicy` option, otherwise this throws an error. The geocoder sends at most one request per second, caches the results of the last 100\n\t * queries, adds the OpenStreetMap attribution to the map and does not search while\n\t * typing with the public service. For more traffic, use your own Nominatim server or a\n\t * commercial provider.\n\t *\n\t * @example\n\t * ```js\n\t * new SearchControl({\n\t * geocoder: SearchControl.nominatim({acceptUsagePolicy: true, params: {countrycodes: 'at,de'}})\n\t * }).addTo(map);\n\t * ```\n\t * @param {object} [options]\n\t * @param {string} [options.url='https://nominatim.openstreetmap.org/search'] The URL\n\t * of the search endpoint.\n\t * @param {Record<string, string>} [options.params] Further query parameters, e.g.\n\t * `countrycodes`, `viewbox` or `limit` (5 by default).\n\t * @param {boolean} [options.acceptUsagePolicy=false] Confirms that your use of the\n\t * public service complies with its\n\t * [usage policy](https://operations.osmfoundation.org/policies/nominatim/), required\n\t * for the public service.\n\t * @returns {Geocoder}\n\t */\n\tstatic nominatim({url = 'https://nominatim.openstreetmap.org/search', params = {}, acceptUsagePolicy = false} = {}) {\n\t\tconst {host} = new URL(url),\n\t\tpublicService = host === 'nominatim.openstreetmap.org';\n\t\tif (publicService && !acceptUsagePolicy) {\n\t\t\tthrow new Error('Using the public Nominatim service requires that you read and accept its usage policy (https://operations.osmfoundation.org/policies/nominatim/) with the acceptUsagePolicy option.');\n\t\t}\n\t\t// the results of recent queries\n\t\tconst cache = new Map();\n\n\t\tasync function geocoder(query, {signal}) {\n\t\t\tconst search = new URLSearchParams({q: query, format: 'jsonv2', limit: '5', ...params}),\n\t\t\trequestUrl = `${url}?${search}`;\n\t\t\tif (cache.has(requestUrl)) {\n\t\t\t\treturn cache.get(requestUrl);\n\t\t\t}\n\n\t\t\t// at most one request per second\n\t\t\tconst now = Date.now(), next = nextRequests.get(host) ?? 0, wait = next - now;\n\t\t\tnextRequests.set(host, Math.max(now, next) + 1000);\n\t\t\tif (wait > 0) {\n\t\t\t\tawait delay(wait, signal);\n\t\t\t}\n\n\t\t\tconst response = await fetch(requestUrl, {signal});\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`Nominatim: ${response.status} ${response.statusText}`);\n\t\t\t}\n\t\t\tconst results = (await response.json()).map((place) => {\n\t\t\t\t// [south, north, west, east]\n\t\t\t\tconst [s, n, w, e] = place.boundingbox.map(Number);\n\t\t\t\treturn {\n\t\t\t\t\tlabel: place.display_name,\n\t\t\t\t\tlatlng: [Number(place.lat), Number(place.lon)],\n\t\t\t\t\tbounds: [[s, w], [n, e]],\n\t\t\t\t\traw: place\n\t\t\t\t};\n\t\t\t});\n\t\t\tcache.set(requestUrl, results);\n\t\t\tif (cache.size > 100) {\n\t\t\t\tcache.delete(cache.keys().next().value);\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n\n\t\treturn Object.defineProperties(geocoder, {\n\t\t\t// the same as of OpenStreetMap tiles, translated when added\n\t\t\tattribution: {get: () => `© <a href=\"https://www.openstreetmap.org/copyright\">${I18n.translate('OpenStreetMap contributors')}</a>`},\n\t\t\tautoComplete: {value: !publicService}\n\t\t});\n\t}\n\n\t/**\n\t * Creates a search control.\n\t * @param {...SearchControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tif (!this.options.geocoder) {\n\t\t\tthrow new Error('SearchControl: the geocoder option is required, e.g. SearchControl.nominatim().');\n\t\t}\n\t\tthis.callInitHooks(SearchControl);\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-search',\n\t\tcontainer = this._container = DomUtil.create('div', `${className} maplair-bar`),\n\t\tform = DomUtil.create('form', `${className}-form`, container),\n\t\ttoggle = this._toggle = DomUtil.create('button', `${className}-toggle`, form),\n\t\tinput = this._input = DomUtil.create('input', `${className}-input`, form),\n\t\treset = DomUtil.create('button', `${className}-reset`, form),\n\t\tlist = this._list = DomUtil.create('ul', `${className}-results`, container),\n\t\tlistId = `${className}-results-${Util.stamp(this)}`,\n\t\ttitle = I18n.translate('Search');\n\n\t\tform.role = 'search';\n\t\ttoggle.type = 'button';\n\t\ttoggle.innerHTML = searchIcon;\n\t\ttoggle.title = title;\n\t\ttoggle.setAttribute('aria-label', title);\n\n\t\tinput.type = 'search';\n\t\tinput.placeholder = this.options.placeholder ?? title;\n\t\tinput.autocomplete = 'off';\n\t\tinput.enterKeyHint = 'search';\n\t\tinput.role = 'combobox';\n\t\tinput.setAttribute('aria-label', title);\n\t\tinput.setAttribute('aria-autocomplete', 'list');\n\t\tinput.setAttribute('aria-controls', listId);\n\n\t\treset.type = 'reset';\n\t\treset.innerHTML = '<span aria-hidden=\"true\">×</span>';\n\t\treset.title = I18n.translate('Clear the search');\n\t\treset.setAttribute('aria-label', reset.title);\n\n\t\tlist.id = listId;\n\t\tlist.role = 'listbox';\n\t\tlist.setAttribute('aria-label', I18n.translate('Search results'));\n\n\t\tthis._message = DomUtil.create('div', `${className}-message`, container);\n\t\tthis._message.role = 'status';\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tDomEvent.on(toggle, 'click', this._onToggle, this);\n\t\tDomEvent.on(form, 'submit', this._onSubmit, this);\n\t\tDomEvent.on(form, 'reset', this._onReset, this);\n\t\tDomEvent.on(input, 'input', this._onInput, this);\n\t\tDomEvent.on(input, 'keydown', this._onKeyDown, this);\n\t\tDomEvent.on(list, 'click', this._onListClick, this);\n\t\tmap.on('click', this._onMapClick, this);\n\t\tthis._attribution = this.options.geocoder.attribution;\n\t\tmap.attributionControl?.addAttribution(this._attribution);\n\n\t\tthis._showResults([]);\n\t\tthis._setExpanded(!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('click', this._onMapClick, this);\n\t\tmap.attributionControl?.removeAttribution(this._attribution);\n\t\tthis._abort();\n\t\tthis._marker?.remove();\n\t}\n\n\t/**\n\t * Expands the search field of a [collapsed](#searchcontrol-collapsed) control and\n\t * focuses it.\n\t * @returns {this}\n\t */\n\texpand() {\n\t\tthis._setExpanded(true);\n\t\tthis._input.focus();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Collapses the control into its button, if [collapsed](#searchcontrol-collapsed),\n\t * and hides the results.\n\t * @returns {this}\n\t */\n\tcollapse() {\n\t\tthis._showResults([]);\n\t\tthis._setExpanded(!this.options.collapsed);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Searches the given text and shows the results in the list. Resolves to the results.\n\t * @param {string} query\n\t * @returns {Promise<SearchResult[]>}\n\t */\n\tasync search(query) {\n\t\tthis._abort();\n\t\tthis._input.value = query;\n\t\tquery = query.trim();\n\t\tif (!query) {\n\t\t\tthis._showResults([]);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst latlng = LatLng.parse(query);\n\t\tif (latlng) {\n\t\t\tconst results = [{label: query, latlng}];\n\t\t\tthis._showResults(results);\n\t\t\treturn results;\n\t\t}\n\n\t\tconst controller = this._controller = new AbortController();\n\t\tthis._container.classList.add('maplair-control-search-loading');\n\t\ttry {\n\t\t\tconst results = await this.options.geocoder(query, {signal: controller.signal});\n\t\t\tif (!controller.signal.aborted) {\n\t\t\t\tthis._showResults(results, I18n.translate('No results'));\n\t\t\t}\n\t\t\treturn results;\n\t\t} catch (error) {\n\t\t\tif (controller.signal.aborted) { return []; }\n\t\t\tthis._showResults([], I18n.translate('The search failed'));\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tif (this._controller === controller) {\n\t\t\t\tthis._controller = null;\n\t\t\t\tthis._container.classList.remove('maplair-control-search-loading');\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Shows the given result on the map: zooms to it, shows a\n\t * [marker](#searchcontrol-marker) and fires `searchresult` on the map.\n\t * @param {SearchResult} result\n\t * @returns {this}\n\t */\n\tselect(result) {\n\t\tconst map = this._map,\n\t\tlatlng = LatLng.from(result.latlng),\n\t\tbounds = result.bounds ? LatLngBounds.from(result.bounds) : undefined;\n\n\t\tthis._input.value = result.label;\n\t\tthis._showResults([]);\n\n\t\tif (bounds?.isValid() && !bounds.getNorthWest().equals(bounds.getSouthEast())) {\n\t\t\tmap.fitBounds(bounds, {maxZoom: this.options.zoom});\n\t\t} else {\n\t\t\tmap.setView(latlng, this.options.zoom);\n\t\t}\n\n\t\tthis._marker?.remove();\n\t\tif (this.options.marker) {\n\t\t\tthis._marker = new Marker(latlng, {title: result.label}).addTo(map);\n\t\t}\n\n\t\tmap.fire('searchresult', {result, latlng, bounds});\n\t\treturn this;\n\t}\n\n\t/**\n\t * Clears the search field, the results and the marker.\n\t * @returns {this}\n\t */\n\tclear() {\n\t\tthis._abort();\n\t\tthis._input.value = '';\n\t\tthis._showResults([]);\n\t\tthis._marker?.remove();\n\t\tthis._marker = null;\n\t\treturn this;\n\t}\n\n\t_setExpanded(expanded) {\n\t\tthis._container.classList.toggle('maplair-control-search-expanded', expanded);\n\t\tthis._toggle.setAttribute('aria-expanded', expanded);\n\t}\n\n\t_abort() {\n\t\tclearTimeout(this._autoCompleteTimeout);\n\t\tthis._controller?.abort();\n\t\tthis._controller = null;\n\t\tthis._container?.classList.remove('maplair-control-search-loading');\n\t}\n\n\t// Shows the results, or the message if there are none\n\t_showResults(results, message = '') {\n\t\tthis._results = results;\n\t\tthis._list.replaceChildren(...results.map((result, i) => {\n\t\t\tconst item = DomUtil.create('li', 'maplair-control-search-result');\n\t\t\titem.id = `${this._list.id}-${i}`;\n\t\t\titem.role = 'option';\n\t\t\titem.textContent = result.label;\n\t\t\treturn item;\n\t\t}));\n\t\tthis._list.hidden = !results.length;\n\t\tthis._message.textContent = results.length ? '' : message;\n\t\tthis._message.hidden = !this._message.textContent;\n\t\tthis._input.setAttribute('aria-expanded', !!results.length);\n\t\tthis._setActive(-1);\n\t}\n\n\t_setActive(index) {\n\t\tthis._active = index;\n\t\tfor (const [i, item] of [...this._list.children].entries()) {\n\t\t\titem.setAttribute('aria-selected', i === index);\n\t\t}\n\t\tif (index < 0) {\n\t\t\tthis._input.removeAttribute('aria-activedescendant');\n\t\t} else {\n\t\t\tconst item = this._list.children[index];\n\t\t\tthis._input.setAttribute('aria-activedescendant', item.id);\n\t\t\titem.scrollIntoView({block: 'nearest'});\n\t\t}\n\t}\n\n\t_onToggle() {\n\t\tif (this.options.collapsed && !this._container.classList.contains('maplair-control-search-expanded')) {\n\t\t\tthis.expand();\n\t\t} else {\n\t\t\tthis._onSubmit();\n\t\t}\n\t}\n\n\t_onSubmit(e) {\n\t\tif (e) { DomEvent.preventDefault(e); }\n\t\tconst query = this._input.value,\n\t\tresult = this._results[this._active],\n\t\tlatlng = LatLng.parse(query);\n\t\tif (result) {\n\t\t\tthis.select(result);\n\t\t} else if (latlng) {\n\t\t\tthis.select({label: query.trim(), latlng});\n\t\t} else {\n\t\t\t// errors are shown in the control\n\t\t\tthis.search(query).catch(Util.falseFn);\n\t\t}\n\t}\n\n\t_onReset() {\n\t\tthis.clear();\n\t\tthis._input.focus();\n\t}\n\n\t_onInput() {\n\t\tclearTimeout(this._autoCompleteTimeout);\n\t\tconst query = this._input.value.trim();\n\t\tif (!this.options.autoComplete || this.options.geocoder.autoComplete === false) {\n\t\t\tthis._showResults([]);\n\t\t} else if (query.length >= this.options.minLength || LatLng.parse(query)) {\n\t\t\tthis._autoCompleteTimeout = setTimeout(() => {\n\t\t\t\tthis.search(this._input.value).catch(Util.falseFn);\n\t\t\t}, this.options.autoCompleteDelay);\n\t\t} else {\n\t\t\tthis._abort();\n\t\t\tthis._showResults([]);\n\t\t}\n\t}\n\n\t_onKeyDown(e) {\n\t\tconst n = this._results.length;\n\t\tif ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && n) {\n\t\t\tDomEvent.preventDefault(e);\n\t\t\tconst step = e.key === 'ArrowDown' ? 1 : -1;\n\t\t\t// from no active result, the first or the last one\n\t\t\tthis._setActive(((this._active < 0 && step < 0 ? n : this._active) + step + n) % n);\n\t\t} else if (e.key === 'Escape') {\n\t\t\tDomEvent.preventDefault(e);\n\t\t\tif (n || !this._message.hidden) {\n\t\t\t\tthis._showResults([]);\n\t\t\t} else if (this._input.value) {\n\t\t\t\tthis.clear();\n\t\t\t} else if (this.options.collapsed) {\n\t\t\t\tthis.collapse();\n\t\t\t\tthis._map.getContainer().focus();\n\t\t\t}\n\t\t}\n\t}\n\n\t_onListClick(e) {\n\t\tconst item = e.target.closest('.maplair-control-search-result'),\n\t\tindex = [...this._list.children].indexOf(item);\n\t\tif (index >= 0) {\n\t\t\tthis.select(this._results[index]);\n\t\t}\n\t}\n\n\t_onMapClick() {\n\t\tif (this._input.value) {\n\t\t\tthis._showResults([]);\n\t\t} else {\n\t\t\tthis.collapse();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,aAAa;AAGnB,MAAM,+BAAe,IAAI,IAAI;AAG7B,SAAS,MAAM,IAAI,QAAQ;CAC1B,OAAO,IAAI,SAAS,SAAS,WAAW;EACvC,MAAM,UAAU,WAAW,SAAS,EAAE;EACtC,OAAO,iBAAiB,eAAe;GACtC,aAAa,OAAO;GACpB,OAAO,OAA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,OAAO;GACZ,KAAK,aAAa,CAAC,CAAC;EACrB;CACD;CAEA,WAAW,GAAG;EACb,MAAM,IAAI,KAAK,SAAS;EACxB,KAAK,EAAE,QAAQ,eAAe,EAAE,QAAQ,cAAc,GAAG;GACxD,eAAwB,CAAC;GACzB,MAAM,OAAO,EAAE,QAAQ,cAAc,IAAI;GAEzC,KAAK,aAAa,KAAK,UAAU,KAAK,OAAO,IAAI,IAAI,KAAK,WAAW,OAAO,KAAK,CAAC;EACnF,OAAO,IAAI,EAAE,QAAQ,UAAU;GAC9B,eAAwB,CAAC;GACzB,IAAI,KAAK,CAAC,KAAK,SAAS,QACvB,KAAK,aAAa,CAAC,CAAC;QACd,IAAI,KAAK,OAAO,OACtB,KAAK,MAAM;QACL,IAAI,KAAK,QAAQ,WAAW;IAClC,KAAK,SAAS;IACd,KAAK,KAAK,aAAa,CAAC,CAAC,MAAM;GAChC;EACD;CACD;CAEA,aAAa,GAAG;EACf,MAAM,OAAO,EAAE,OAAO,QAAQ,gCAAgC,GAC9D,QAAQ,CAAC,GAAG,KAAK,MAAM,QAAQ,CAAC,CAAC,QAAQ,IAAI;EAC7C,IAAI,SAAS,GACZ,KAAK,OAAO,KAAK,SAAS,MAAM;CAElC;CAEA,cAAc;EACb,IAAI,KAAK,OAAO,OACf,KAAK,aAAa,CAAC,CAAC;OAEpB,KAAK,SAAS;CAEhB;AACD"}
|
|
1
|
+
{"version":3,"file":"SearchControl.js","names":["DomUtil.create","Util.stamp","Util.falseFn"],"sources":["../../../src/control/SearchControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport {Marker} from '../layer/marker/Marker.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {LayerGroup} from '../layer/LayerGroup.js' */\n\nconst 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>';\n\n// the time of the next allowed request to each Nominatim server, shared by all geocoders\nconst nextRequests = new Map();\n\n// Resolves after `ms` milliseconds, rejects when the signal aborts\nfunction delay(ms, signal) {\n\treturn new Promise((resolve, reject) => {\n\t\tconst timeout = setTimeout(resolve, ms);\n\t\tsignal.addEventListener('abort', () => {\n\t\t\tclearTimeout(timeout);\n\t\t\treject(signal.reason);\n\t\t}, {once: true});\n\t});\n}\n\n/**\n * A result of a search, returned by a [geocoder](#searchcontrol-geocoder).\n * @typedef {object} SearchResult\n * @property {string} label The text shown in the list of results, e.g. an address.\n * @property {LatLngExpression} latlng The position of the result.\n * @property {LatLngBoundsExpression} [bounds] The extent of the result, e.g. of a city,\n * which the map fits to instead of zooming to the position.\n * @property {any} [raw] The original result of the service, for use in event listeners.\n * @property {Layer} [layer] The found layer, by [`SearchControl.layers()`](#searchcontrol-layers),\n * e.g. to open its tooltip in a `searchresult` listener.\n */\n\n/**\n * A function searching places for a query, see the [`geocoder`](#searchcontrol-geocoder)\n * option. It should pass the `signal` to `fetch()`: searches are aborted when the user\n * starts another one. Optional properties of the function: `attribution`, an attribution\n * text which the control adds to the map, and `autoComplete: false` if the service\n * forbids searching while typing (overriding the\n * [`autoComplete`](#searchcontrol-autocomplete) option).\n * @typedef {((query: string, options: {signal: AbortSignal}) => Promise<SearchResult[]>) & {attribution?: string, autoComplete?: boolean}} Geocoder\n */\n\n/**\n * Options of `SearchControl`.\n * @typedef {object} SearchControlOptions\n * @property {string} [position='topleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {Geocoder} geocoder The function searching places (required), e.g.\n * [Nominatim](#searchcontrol-nominatim). Coordinates (see\n * [`LatLng.parse()`](#latlng-parse)) are found without it.\n * @property {boolean} [collapsed=true] If `true`, the control is collapsed into a button\n * and expanded on click.\n * @property {boolean} [autoComplete=false] Whether to search while typing instead of\n * on <kbd>Enter</kbd>. Not with the public Nominatim service, its\n * [usage policy](https://operations.osmfoundation.org/policies/nominatim/) forbids\n * auto-complete.\n * @property {number} [autoCompleteDelay=250] The delay in milliseconds after typing\n * before searching with [`autoComplete`](#searchcontrol-autocomplete).\n * @property {number} [minLength=3] The minimum length of queries searched with\n * [`autoComplete`](#searchcontrol-autocomplete).\n * @property {number} [zoom=16] The zoom level for results without bounds, and the\n * maximum zoom level for fitting the bounds of results.\n * @property {boolean|((result: SearchResult) => Layer|null|undefined)} [marker=true] Whether\n * to show a marker at the selected result, or a function returning the layer to show\n * instead, e.g. a `CircleMarker` highlighting the result (or nothing for none). The\n * layer is removed when the search is cleared or another result is selected.\n * @property {boolean} [clearOnMapClick=false] If `true`, a click on the map clears the\n * search (the field, the results and the marker) and collapses the control. By\n * default, the click only hides the results and the marker stays.\n * @property {string} [placeholder] The placeholder of the search field, by default\n * the translation of \"Search\".\n * @property {string} [noResultsText] The message shown if nothing is found, by\n * default the translation of \"No results\".\n * @extends ControlOptions\n */\n\n/**\n * The event object of `searchresult`.\n * @typedef {object} SearchResultEvent\n * @property {SearchResult} result The selected result.\n * @property {LatLng} latlng The position of the result.\n * @property {LatLngBounds|undefined} bounds The extent of the result, if any.\n * @extends MaplairEvent\n */\n\n/**\n * A control with a search field for places, showing the results in a list to select\n * one with the pointer or the keyboard. The selected result is shown on the map with a\n * marker. It searches with a [`geocoder`](#searchcontrol-geocoder), e.g.\n * [Nominatim](#searchcontrol-nominatim) of OpenStreetMap or any other service.\n * Coordinates like `47.27, 11.4` or `geo:47.27,11.4` are found without a service.\n *\n * The public Nominatim service is free, but limited by its\n * [usage policy](https://operations.osmfoundation.org/policies/nominatim/): it is for\n * occasional searches of users, not for heavy use (an absolute maximum of one request\n * per second for all users of an app), and forbids auto-complete. The\n * [Nominatim geocoder](#searchcontrol-nominatim) follows the technical requirements,\n * but you are responsible for your use of the service, which you confirm with the\n * `acceptUsagePolicy` option: for more traffic, use your own Nominatim server or a\n * commercial provider.\n *\n * @example\n * ```js\n * new SearchControl({\n * geocoder: SearchControl.nominatim({acceptUsagePolicy: true})\n * }).addTo(map);\n *\n * // Photon of Komoot, which allows auto-complete\n * new SearchControl({\n * autoComplete: true,\n * async geocoder(query, {signal}) {\n * const response = await fetch(`https://photon.komoot.io/api/?q=${encodeURIComponent(query)}`, {signal});\n * const {features} = await response.json();\n * return features.map(({geometry, properties}) => ({\n * label: [properties.name, properties.city, properties.country].filter(Boolean).join(', '),\n * latlng: [geometry.coordinates[1], geometry.coordinates[0]],\n * raw: properties\n * }));\n * }\n * }).addTo(map);\n * ```\n *\n * @fires MaplairMap#searchresult {SearchResultEvent} Fired when a result of the\n * [search control](#searchcontrol) is selected.\n */\nexport class SearchControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tgeocoder: undefined,\n\t\tcollapsed: true,\n\t\tautoComplete: false,\n\t\tautoCompleteDelay: 250,\n\t\tminLength: 3,\n\t\tzoom: 16,\n\t\tmarker: true,\n\t\tclearOnMapClick: false,\n\t\tplaceholder: undefined,\n\t\tnoResultsText: undefined\n\t};\n\n\t/**\n\t * Returns a [geocoder](#searchcontrol-geocoder) searching with\n\t * [Nominatim](https://nominatim.org/release-docs/latest/api/Search/), by default the\n\t * public service of OpenStreetMap. Using it requires that you read and accept its\n\t * [usage policy](https://operations.osmfoundation.org/policies/nominatim/) with the\n\t * `acceptUsagePolicy` option, otherwise this throws an error. The geocoder sends at most one request per second, caches the results of the last 100\n\t * queries, adds the OpenStreetMap attribution to the map and does not search while\n\t * typing with the public service. For more traffic, use your own Nominatim server or a\n\t * commercial provider.\n\t *\n\t * @example\n\t * ```js\n\t * new SearchControl({\n\t * geocoder: SearchControl.nominatim({acceptUsagePolicy: true, params: {countrycodes: 'at,de'}})\n\t * }).addTo(map);\n\t * ```\n\t * @param {object} [options]\n\t * @param {string} [options.url='https://nominatim.openstreetmap.org/search'] The URL\n\t * of the search endpoint.\n\t * @param {Record<string, string>} [options.params] Further query parameters, e.g.\n\t * `countrycodes`, `viewbox` or `limit` (5 by default).\n\t * @param {boolean} [options.acceptUsagePolicy=false] Confirms that your use of the\n\t * public service complies with its\n\t * [usage policy](https://operations.osmfoundation.org/policies/nominatim/), required\n\t * for the public service.\n\t * @returns {Geocoder}\n\t */\n\tstatic nominatim({url = 'https://nominatim.openstreetmap.org/search', params = {}, acceptUsagePolicy = false} = {}) {\n\t\tconst {host} = new URL(url),\n\t\tpublicService = host === 'nominatim.openstreetmap.org';\n\t\tif (publicService && !acceptUsagePolicy) {\n\t\t\tthrow new Error('Using the public Nominatim service requires that you read and accept its usage policy (https://operations.osmfoundation.org/policies/nominatim/) with the acceptUsagePolicy option.');\n\t\t}\n\t\t// the results of recent queries\n\t\tconst cache = new Map();\n\n\t\tasync function geocoder(query, {signal}) {\n\t\t\tconst search = new URLSearchParams({q: query, format: 'jsonv2', limit: '5', ...params}),\n\t\t\trequestUrl = `${url}?${search}`;\n\t\t\tif (cache.has(requestUrl)) {\n\t\t\t\treturn cache.get(requestUrl);\n\t\t\t}\n\n\t\t\t// at most one request per second\n\t\t\tconst now = Date.now(), next = nextRequests.get(host) ?? 0, wait = next - now;\n\t\t\tnextRequests.set(host, Math.max(now, next) + 1000);\n\t\t\tif (wait > 0) {\n\t\t\t\tawait delay(wait, signal);\n\t\t\t}\n\n\t\t\tconst response = await fetch(requestUrl, {signal});\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`Nominatim: ${response.status} ${response.statusText}`);\n\t\t\t}\n\t\t\tconst results = (await response.json()).map((place) => {\n\t\t\t\t// [south, north, west, east]\n\t\t\t\tconst [s, n, w, e] = place.boundingbox.map(Number);\n\t\t\t\treturn {\n\t\t\t\t\tlabel: place.display_name,\n\t\t\t\t\tlatlng: [Number(place.lat), Number(place.lon)],\n\t\t\t\t\tbounds: [[s, w], [n, e]],\n\t\t\t\t\traw: place\n\t\t\t\t};\n\t\t\t});\n\t\t\tcache.set(requestUrl, results);\n\t\t\tif (cache.size > 100) {\n\t\t\t\tcache.delete(cache.keys().next().value);\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n\n\t\treturn Object.defineProperties(geocoder, {\n\t\t\t// the same as of OpenStreetMap tiles, translated when added\n\t\t\tattribution: {get: () => `© <a href=\"https://www.openstreetmap.org/copyright\">${I18n.translate('OpenStreetMap contributors')}</a>`},\n\t\t\tautoComplete: {value: !publicService}\n\t\t});\n\t}\n\n\t/**\n\t * Returns a [geocoder](#searchcontrol-geocoder) searching the layers of a layer group,\n\t * e.g. the markers of a `FeatureGroup` or the features of a `GeoJSON` layer, by their\n\t * label: a property of their GeoJSON feature (`layer.feature.properties`) or the\n\t * result of a function. The group is searched at the time of the search, so layers\n\t * added later are found as well, and nested groups without a label are searched\n\t * recursively. The search ignores the case and finds the query anywhere in the\n\t * label; labels starting with it come first, then in alphabetical order. The results\n\t * contain the found `layer` and its GeoJSON feature as `raw`; layers without a\n\t * single position (e.g. polygons) have the `bounds` and their center as `latlng`.\n\t * Combine it with [`autoComplete`](#searchcontrol-autocomplete) to search while\n\t * typing, and with [`marker`](#searchcontrol-marker) `false` or a function to not\n\t * cover the found marker with another one.\n\t *\n\t * @example\n\t * ```js\n\t * const stations = new GeoJSON(data, {\n\t * onEachFeature: (feature, layer) => layer.bindTooltip(feature.properties.name)\n\t * }).addTo(map);\n\t * new SearchControl({\n\t * geocoder: SearchControl.layers(stations, {property: 'name'}),\n\t * autoComplete: true,\n\t * minLength: 1,\n\t * marker: false\n\t * }).addTo(map);\n\t * map.on('searchresult', ({result}) => result.layer.openTooltip());\n\t * ```\n\t * @param {LayerGroup} group The layer group to search.\n\t * @param {object} [options]\n\t * @param {string} [options.property='name'] The property of the GeoJSON features to\n\t * search.\n\t * @param {(layer: Layer) => string|number|null|undefined} [options.label] A function\n\t * returning the label of a layer instead of the `property`, nothing to skip the\n\t * layer (or to search its layers, if it is a group).\n\t * @param {number} [options.limit=10] The maximum number of results.\n\t * @returns {Geocoder}\n\t */\n\tstatic layers(group, {property = 'name', label = layer => layer.feature?.properties?.[property], limit = 10} = {}) {\n\t\treturn (query) => {\n\t\t\tquery = query.toLocaleLowerCase();\n\t\t\tconst found = [];\n\t\t\tgroup.eachLayer(function search(layer) {\n\t\t\t\tconst text = label(layer);\n\t\t\t\tif (text === undefined || text === null || text === '') {\n\t\t\t\t\tlayer.eachLayer?.(search);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst result = {label: String(text), layer, raw: layer.feature},\n\t\t\t\tindex = result.label.toLocaleLowerCase().indexOf(query);\n\t\t\t\tif (index < 0) { return; }\n\t\t\t\tif (layer.getLatLng) {\n\t\t\t\t\tresult.latlng = layer.getLatLng();\n\t\t\t\t} else if (layer.getBounds?.().isValid()) {\n\t\t\t\t\tresult.bounds = layer.getBounds();\n\t\t\t\t\tresult.latlng = result.bounds.getCenter();\n\t\t\t\t} else {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tfound.push({result, prefix: index === 0});\n\t\t\t});\n\t\t\treturn Promise.resolve(found\n\t\t\t\t.sort((a, b) => b.prefix - a.prefix || a.result.label.localeCompare(b.result.label))\n\t\t\t\t.slice(0, limit)\n\t\t\t\t.map(({result}) => result));\n\t\t};\n\t}\n\n\t/**\n\t * Creates a search control.\n\t * @param {...SearchControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tif (!this.options.geocoder) {\n\t\t\tthrow new Error('SearchControl: the geocoder option is required, e.g. SearchControl.nominatim().');\n\t\t}\n\t\tthis.callInitHooks(SearchControl);\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-search',\n\t\tcontainer = this._container = DomUtil.create('div', `${className} maplair-bar`),\n\t\tform = DomUtil.create('form', `${className}-form`, container),\n\t\ttoggle = this._toggle = DomUtil.create('button', `${className}-toggle`, form),\n\t\tinput = this._input = DomUtil.create('input', `${className}-input`, form),\n\t\treset = DomUtil.create('button', `${className}-reset`, form),\n\t\tlist = this._list = DomUtil.create('ul', `${className}-results`, container),\n\t\tlistId = `${className}-results-${Util.stamp(this)}`,\n\t\ttitle = I18n.translate('Search');\n\n\t\tform.role = 'search';\n\t\ttoggle.type = 'button';\n\t\ttoggle.innerHTML = searchIcon;\n\t\ttoggle.title = title;\n\t\ttoggle.setAttribute('aria-label', title);\n\n\t\tinput.type = 'search';\n\t\tinput.placeholder = this.options.placeholder ?? title;\n\t\tinput.autocomplete = 'off';\n\t\tinput.enterKeyHint = 'search';\n\t\tinput.role = 'combobox';\n\t\tinput.setAttribute('aria-label', title);\n\t\tinput.setAttribute('aria-autocomplete', 'list');\n\t\tinput.setAttribute('aria-controls', listId);\n\n\t\treset.type = 'reset';\n\t\treset.innerHTML = '<span aria-hidden=\"true\">×</span>';\n\t\treset.title = I18n.translate('Clear the search');\n\t\treset.setAttribute('aria-label', reset.title);\n\n\t\tlist.id = listId;\n\t\tlist.role = 'listbox';\n\t\tlist.setAttribute('aria-label', I18n.translate('Search results'));\n\n\t\tthis._message = DomUtil.create('div', `${className}-message`, container);\n\t\tthis._message.role = 'status';\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tDomEvent.on(toggle, 'click', this._onToggle, this);\n\t\tDomEvent.on(form, 'submit', this._onSubmit, this);\n\t\tDomEvent.on(form, 'reset', this._onReset, this);\n\t\tDomEvent.on(input, 'input', this._onInput, this);\n\t\tDomEvent.on(input, 'keydown', this._onKeyDown, this);\n\t\tDomEvent.on(list, 'click', this._onListClick, this);\n\t\tmap.on('click', this._onMapClick, this);\n\t\tthis._attribution = this.options.geocoder.attribution;\n\t\tmap.attributionControl?.addAttribution(this._attribution);\n\n\t\tthis._showResults([]);\n\t\tthis._setExpanded(!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('click', this._onMapClick, this);\n\t\tmap.attributionControl?.removeAttribution(this._attribution);\n\t\tthis._abort();\n\t\tthis._marker?.remove();\n\t}\n\n\t/**\n\t * Expands the search field of a [collapsed](#searchcontrol-collapsed) control and\n\t * focuses it.\n\t * @returns {this}\n\t */\n\texpand() {\n\t\tthis._setExpanded(true);\n\t\tthis._input.focus();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Collapses the control into its button, if [collapsed](#searchcontrol-collapsed),\n\t * and hides the results.\n\t * @returns {this}\n\t */\n\tcollapse() {\n\t\tthis._showResults([]);\n\t\tthis._setExpanded(!this.options.collapsed);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Searches the given text and shows the results in the list. Resolves to the results.\n\t * @param {string} query\n\t * @returns {Promise<SearchResult[]>}\n\t */\n\tasync search(query) {\n\t\tthis._abort();\n\t\tthis._input.value = query;\n\t\tquery = query.trim();\n\t\tif (!query) {\n\t\t\tthis._showResults([]);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst latlng = LatLng.parse(query);\n\t\tif (latlng) {\n\t\t\tconst results = [{label: query, latlng}];\n\t\t\tthis._showResults(results);\n\t\t\treturn results;\n\t\t}\n\n\t\tconst controller = this._controller = new AbortController();\n\t\tthis._container.classList.add('maplair-control-search-loading');\n\t\ttry {\n\t\t\tconst results = await this.options.geocoder(query, {signal: controller.signal});\n\t\t\tif (!controller.signal.aborted) {\n\t\t\t\tthis._showResults(results, this.options.noResultsText ?? I18n.translate('No results'));\n\t\t\t}\n\t\t\treturn results;\n\t\t} catch (error) {\n\t\t\tif (controller.signal.aborted) { return []; }\n\t\t\tthis._showResults([], I18n.translate('The search failed'));\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tif (this._controller === controller) {\n\t\t\t\tthis._controller = null;\n\t\t\t\tthis._container.classList.remove('maplair-control-search-loading');\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Shows the given result on the map: zooms to it, shows a\n\t * [marker](#searchcontrol-marker) and fires `searchresult` on the map.\n\t * @param {SearchResult} result\n\t * @returns {this}\n\t */\n\tselect(result) {\n\t\tconst map = this._map,\n\t\tlatlng = LatLng.from(result.latlng),\n\t\tbounds = result.bounds ? LatLngBounds.from(result.bounds) : undefined;\n\n\t\tthis._input.value = result.label;\n\t\tthis._showResults([]);\n\n\t\tif (bounds?.isValid() && !bounds.getNorthWest().equals(bounds.getSouthEast())) {\n\t\t\tmap.fitBounds(bounds, {maxZoom: this.options.zoom});\n\t\t} else {\n\t\t\tmap.setView(latlng, this.options.zoom);\n\t\t}\n\n\t\tthis._marker?.remove();\n\t\tconst {marker} = this.options;\n\t\tthis._marker = typeof marker === 'function' ?\n\t\t\tmarker(result)?.addTo(map) ?? null :\n\t\t\tmarker ? new Marker(latlng, {title: result.label}).addTo(map) : null;\n\n\t\tmap.fire('searchresult', {result, latlng, bounds});\n\t\treturn this;\n\t}\n\n\t/**\n\t * Clears the search field, the results and the marker.\n\t * @returns {this}\n\t */\n\tclear() {\n\t\tthis._abort();\n\t\tthis._input.value = '';\n\t\tthis._showResults([]);\n\t\tthis._marker?.remove();\n\t\tthis._marker = null;\n\t\treturn this;\n\t}\n\n\t_setExpanded(expanded) {\n\t\tthis._container.classList.toggle('maplair-control-search-expanded', expanded);\n\t\tthis._toggle.setAttribute('aria-expanded', expanded);\n\t}\n\n\t_abort() {\n\t\tclearTimeout(this._autoCompleteTimeout);\n\t\tthis._controller?.abort();\n\t\tthis._controller = null;\n\t\tthis._container?.classList.remove('maplair-control-search-loading');\n\t}\n\n\t// Shows the results, or the message if there are none\n\t_showResults(results, message = '') {\n\t\tthis._results = results;\n\t\tthis._list.replaceChildren(...results.map((result, i) => {\n\t\t\tconst item = DomUtil.create('li', 'maplair-control-search-result');\n\t\t\titem.id = `${this._list.id}-${i}`;\n\t\t\titem.role = 'option';\n\t\t\titem.textContent = result.label;\n\t\t\treturn item;\n\t\t}));\n\t\tthis._list.hidden = !results.length;\n\t\tthis._message.textContent = results.length ? '' : message;\n\t\tthis._message.hidden = !this._message.textContent;\n\t\tthis._input.setAttribute('aria-expanded', !!results.length);\n\t\tthis._setActive(-1);\n\t}\n\n\t_setActive(index) {\n\t\tthis._active = index;\n\t\tfor (const [i, item] of [...this._list.children].entries()) {\n\t\t\titem.setAttribute('aria-selected', i === index);\n\t\t}\n\t\tif (index < 0) {\n\t\t\tthis._input.removeAttribute('aria-activedescendant');\n\t\t} else {\n\t\t\tconst item = this._list.children[index];\n\t\t\tthis._input.setAttribute('aria-activedescendant', item.id);\n\t\t\titem.scrollIntoView({block: 'nearest'});\n\t\t}\n\t}\n\n\t_onToggle() {\n\t\tif (this.options.collapsed && !this._container.classList.contains('maplair-control-search-expanded')) {\n\t\t\tthis.expand();\n\t\t} else {\n\t\t\tthis._onSubmit();\n\t\t}\n\t}\n\n\t_onSubmit(e) {\n\t\tif (e) { DomEvent.preventDefault(e); }\n\t\tconst query = this._input.value,\n\t\tresult = this._results[this._active],\n\t\tlatlng = LatLng.parse(query);\n\t\tif (result) {\n\t\t\tthis.select(result);\n\t\t} else if (latlng) {\n\t\t\tthis.select({label: query.trim(), latlng});\n\t\t} else {\n\t\t\t// errors are shown in the control\n\t\t\tthis.search(query).catch(Util.falseFn);\n\t\t}\n\t}\n\n\t_onReset() {\n\t\tthis.clear();\n\t\tthis._input.focus();\n\t}\n\n\t_onInput() {\n\t\tclearTimeout(this._autoCompleteTimeout);\n\t\tconst query = this._input.value.trim();\n\t\tif (!this.options.autoComplete || this.options.geocoder.autoComplete === false) {\n\t\t\tthis._showResults([]);\n\t\t} else if (query.length >= this.options.minLength || LatLng.parse(query)) {\n\t\t\tthis._autoCompleteTimeout = setTimeout(() => {\n\t\t\t\tthis.search(this._input.value).catch(Util.falseFn);\n\t\t\t}, this.options.autoCompleteDelay);\n\t\t} else {\n\t\t\tthis._abort();\n\t\t\tthis._showResults([]);\n\t\t}\n\t}\n\n\t_onKeyDown(e) {\n\t\tconst n = this._results.length;\n\t\tif ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && n) {\n\t\t\tDomEvent.preventDefault(e);\n\t\t\tconst step = e.key === 'ArrowDown' ? 1 : -1;\n\t\t\t// from no active result, the first or the last one\n\t\t\tthis._setActive(((this._active < 0 && step < 0 ? n : this._active) + step + n) % n);\n\t\t} else if (e.key === 'Escape') {\n\t\t\tDomEvent.preventDefault(e);\n\t\t\tif (n || !this._message.hidden) {\n\t\t\t\tthis._showResults([]);\n\t\t\t} else if (this._input.value) {\n\t\t\t\tthis.clear();\n\t\t\t} else if (this.options.collapsed) {\n\t\t\t\tthis.collapse();\n\t\t\t\tthis._map.getContainer().focus();\n\t\t\t}\n\t\t}\n\t}\n\n\t_onListClick(e) {\n\t\tconst item = e.target.closest('.maplair-control-search-result'),\n\t\tindex = [...this._list.children].indexOf(item);\n\t\tif (index >= 0) {\n\t\t\tthis.select(this._results[index]);\n\t\t}\n\t}\n\n\t_onMapClick() {\n\t\tif (this.options.clearOnMapClick) {\n\t\t\tthis.clear();\n\t\t\tthis.collapse();\n\t\t} else if (this._input.value) {\n\t\t\tthis._showResults([]);\n\t\t} else {\n\t\t\tthis.collapse();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAM,aAAa;AAGnB,MAAM,+BAAe,IAAI,IAAI;AAG7B,SAAS,MAAM,IAAI,QAAQ;CAC1B,OAAO,IAAI,SAAS,SAAS,WAAW;EACvC,MAAM,UAAU,WAAW,SAAS,EAAE;EACtC,OAAO,iBAAiB,eAAe;GACtC,aAAa,OAA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ACxB,KAAK,EAAE,QAAQ,eAAe,EAAE,QAAQ,cAAc,GAAG;GACxD,eAAwB,CAAC;GACzB,MAAM,OAAO,EAAE,QAAQ,cAAc,IAAI;GAEzC,KAAK,aAAa,KAAK,UAAU,KAAK,OAAO,IAAI,IAAI,KAAK,WAAW,OAAO,KAAK,CAAC;EACnF,OAAO,IAAI,EAAE,QAAQ,UAAU;GAC9B,eAAwB,CAAC;GACzB,IAAI,KAAK,CAAC,KAAK,SAAS,QACvB,KAAK,aAAa,CAAC,CAAC;QACd,IAAI,KAAK,OAAO,OACtB,KAAK,MAAM;QACL,IAAI,KAAK,QAAQ,WAAW;IAClC,KAAK,SAAS;IACd,KAAK,KAAK,aAAa,CAAC,CAAC,MAAM;GAChC;EACD;CACD;CAEA,aAAa,GAAG;EACf,MAAM,OAAO,EAAE,OAAO,QAAQ,gCAAgC,GAC9D,QAAQ,CAAC,GAAG,KAAK,MAAM,QAAQ,CAAC,CAAC,QAAQ,IAAI;EAC7C,IAAI,SAAS,GACZ,KAAK,OAAO,KAAK,SAAS,MAAM;CAElC;CAEA,cAAc;EACb,IAAI,KAAK,QAAQ,iBAAiB;GACjC,KAAK,MAAM;GACX,KAAK,SAAS;EACf,OAAO,IAAI,KAAK,OAAO,OACtB,KAAK,aAAa,CAAC,CAAC;OAEpB,KAAK,SAAS;CAEhB;AACD"}
|
|
@@ -2,7 +2,7 @@ import { disableClickPropagation, off, on, stop } from "../dom/DomEvent.js";
|
|
|
2
2
|
import { create, getPosition } from "../dom/DomUtil.js";
|
|
3
3
|
import { Control } from "./Control.js";
|
|
4
4
|
import { I18n } from "../core/I18n.js";
|
|
5
|
-
|
|
5
|
+
// src/control/SideBySideControl.js
|
|
6
6
|
/** @import {ControlOptions} from './Control.js' */
|
|
7
7
|
/** @import {MaplairMap} from '../map/Map.js' */
|
|
8
8
|
/** @import {Layer} from '../layer/Layer.js' */
|
|
@@ -40,9 +40,7 @@ import { I18n } from "../core/I18n.js";
|
|
|
40
40
|
* `SideBySideControl` moves.
|
|
41
41
|
*/
|
|
42
42
|
var SideBySideControl = class SideBySideControl extends Control {
|
|
43
|
-
static {
|
|
44
|
-
this.setDefaultOptions({ ratio: .5 });
|
|
45
|
-
}
|
|
43
|
+
static defaultOptions = { ratio: .5 };
|
|
46
44
|
/**
|
|
47
45
|
* Creates a side-by-side control for the given layers (which have to be added to the
|
|
48
46
|
* map separately).
|
|
@@ -202,7 +200,6 @@ var SideBySideControl = class SideBySideControl extends Control {
|
|
|
202
200
|
function getElement(layer) {
|
|
203
201
|
return layer.getContainer?.() ?? layer.getElement?.();
|
|
204
202
|
}
|
|
205
|
-
//#endregion
|
|
206
203
|
export { SideBySideControl };
|
|
207
204
|
|
|
208
205
|
//# sourceMappingURL=SideBySideControl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SideBySideControl.js","names":["DomUtil.create","DomUtil.getPosition"],"sources":["../../../src/control/SideBySideControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `SideBySideControl`.\n * @typedef {object} SideBySideControlOptions\n * @property {number} [ratio=0.5] The initial position of the divider, from `0` (left) to\n * `1` (right).\n * @extends ControlOptions\n */\n\n/**\n * The event object of `dividermove`.\n * @typedef {object} DividerMoveEvent\n * @property {number} ratio The position of the divider, from `0` (left) to `1` (right).\n * @property {number} x The position of the divider in container pixels.\n * @extends MaplairEvent\n */\n\n/**\n * Compares layers side by side: a vertical divider across the map shows the\n * \"left\" layers on its left and the \"right\" layers on its right side. The divider\n * can be dragged, or moved with the arrow keys. Works with layers having a\n * container or element of their own, e.g. tile layers and image overlays.\n *\n * Inspired by the [leaflet-side-by-side](https://github.com/digidem/leaflet-side-by-side) plugin.\n *\n * @example\n * ```js\n * const before = new TileLayer('https://…/2020/{z}/{x}/{y}.png').addTo(map);\n * const after = new TileLayer('https://…/2025/{z}/{x}/{y}.png').addTo(map);\n * new SideBySideControl(before, after).addTo(map);\n * ```\n *\n * @fires MaplairMap#dividermove {DividerMoveEvent} Fired when the divider of a\n * `SideBySideControl` moves.\n */\nexport class SideBySideControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tratio: 0.5\n\t\t});\n\t}\n\n\t/**\n\t * Creates a side-by-side control for the given layers (which have to be added to the\n\t * map separately).\n\t * @param {Layer|Layer[]} [leftLayers]\n\t * @param {Layer|Layer[]} [rightLayers]\n\t * @param {SideBySideControlOptions} [options]\n\t */\n\tconstructor(leftLayers, rightLayers, options) {\n\t\tsuper(options);\n\t\tthis._leftLayers = [leftLayers ?? []].flat();\n\t\tthis._rightLayers = [rightLayers ?? []].flat();\n\t\tthis._ratio = this.options.ratio;\n\t\tthis.callInitHooks(SideBySideControl);\n\t}\n\n\t/**\n\t * Adds the control to the given map. The divider spans the map instead of being in\n\t * a corner.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tthis.remove();\n\t\tthis._map = map;\n\t\tthis._container = this.onAdd(map);\n\t\tmap._container.appendChild(this._container);\n\t\tmap.on('unload', this.remove, this);\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 divider = DomUtil.create('div', 'maplair-sidebyside-divider'),\n\t\tlabel = I18n.translate('Divider between the compared layers');\n\t\tdivider.tabIndex = 0;\n\t\tdivider.setAttribute('role', 'slider');\n\t\tdivider.setAttribute('aria-label', label);\n\t\tdivider.setAttribute('aria-valuemin', 0);\n\t\tdivider.setAttribute('aria-valuemax', 100);\n\n\t\tDomEvent.disableClickPropagation(divider);\n\t\tDomEvent.on(divider, 'pointerdown', this._onPointerDown, this);\n\t\tDomEvent.on(divider, 'keydown', this._onKeyDown, this);\n\n\t\tmap.on('move zoom viewreset resize rotate layeradd', this._update, this);\n\t\tthis._container = divider;\n\t\tthis._update();\n\t\treturn divider;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tthis._onPointerUp();\n\t\tmap.off('move zoom viewreset resize rotate layeradd', this._update, this);\n\t\tfor (const layer of [...this._leftLayers, ...this._rightLayers]) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (el) {\n\t\t\t\tel.style.clipPath = '';\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Sets the layers shown on the left side of the divider.\n\t * @param {Layer|Layer[]} layers\n\t * @returns {this}\n\t */\n\tsetLeftLayers(layers) {\n\t\tthis._clear(this._leftLayers);\n\t\tthis._leftLayers = [layers].flat();\n\t\treturn this._update();\n\t}\n\n\t/**\n\t * Sets the layers shown on the right side of the divider.\n\t * @param {Layer|Layer[]} layers\n\t * @returns {this}\n\t */\n\tsetRightLayers(layers) {\n\t\tthis._clear(this._rightLayers);\n\t\tthis._rightLayers = [layers].flat();\n\t\treturn this._update();\n\t}\n\n\t/**\n\t * Returns the position of the divider, from `0` (left) to `1` (right).\n\t * @returns {number}\n\t */\n\tgetRatio() {\n\t\treturn this._ratio;\n\t}\n\n\t/**\n\t * Moves the divider, from `0` (left) to `1` (right).\n\t * @param {number} ratio\n\t * @returns {this}\n\t */\n\tsetRatio(ratio) {\n\t\tthis._ratio = Math.min(1, Math.max(0, ratio));\n\t\tthis._update();\n\t\tthis._map?.fire('dividermove', {ratio: this._ratio, x: this._x});\n\t\treturn this;\n\t}\n\n\t_clear(layers) {\n\t\tfor (const layer of layers) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (el) {\n\t\t\t\tel.style.clipPath = '';\n\t\t\t}\n\t\t}\n\t}\n\n\t_update() {\n\t\tconst map = this._map;\n\t\tif (!map?._loaded || !this._container) { return this; }\n\n\t\tconst size = map.getSize(),\n\t\tx = this._x = Math.round(size.x * this._ratio);\n\t\tthis._container.style.left = `${x}px`;\n\t\tthis._container.setAttribute('aria-valuenow', Math.round(this._ratio * 100));\n\n\t\tthis._clip(this._leftLayers, 0, x, size.y);\n\t\tthis._clip(this._rightLayers, x, size.x, size.y);\n\t\treturn this;\n\t}\n\n\t// Clips the layers to the area from `x1` to `x2` (in container pixels)\n\t_clip(layers, x1, x2, height) {\n\t\tconst map = this._map;\n\t\tfor (const layer of layers) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (!el || !map.hasLayer(layer)) { continue; }\n\t\t\t// relative to the element, which is positioned in layer pixels\n\t\t\tconst offset = DomUtil.getPosition(el),\n\t\t\tcorners = [[x1, 0], [x2, 0], [x2, height], [x1, height]].map((p) => {\n\t\t\t\tconst point = map.containerPointToLayerPoint(p).subtract(offset);\n\t\t\t\treturn `${point.x}px ${point.y}px`;\n\t\t\t});\n\t\t\tel.style.clipPath = `polygon(${corners.join(', ')})`;\n\t\t}\n\t}\n\n\t_onPointerDown(e) {\n\t\tDomEvent.stop(e);\n\t\tthis._container.focus({preventScroll: true});\n\t\t// on the document, to follow the pointer outside of the divider\n\t\tDomEvent.on(document, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.on(document, 'pointerup pointercancel', this._onPointerUp, this);\n\t}\n\n\t_onPointerMove(e) {\n\t\tconst rect = this._map._container.getBoundingClientRect();\n\t\tthis.setRatio((e.clientX - rect.left) / rect.width);\n\t}\n\n\t_onPointerUp() {\n\t\tDomEvent.off(document, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(document, 'pointerup pointercancel', this._onPointerUp, this);\n\t}\n\n\t_onKeyDown(e) {\n\t\tconst step = e.shiftKey ? 0.01 : 0.05;\n\t\tif (e.key === 'ArrowLeft') {\n\t\t\tthis.setRatio(this._ratio - step);\n\t\t} else if (e.key === 'ArrowRight') {\n\t\t\tthis.setRatio(this._ratio + step);\n\t\t} else {\n\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MAAM,aAAa;AACrD"}
|
|
1
|
+
{"version":3,"file":"SideBySideControl.js","names":["DomUtil.create","DomUtil.getPosition"],"sources":["../../../src/control/SideBySideControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `SideBySideControl`.\n * @typedef {object} SideBySideControlOptions\n * @property {number} [ratio=0.5] The initial position of the divider, from `0` (left) to\n * `1` (right).\n * @extends ControlOptions\n */\n\n/**\n * The event object of `dividermove`.\n * @typedef {object} DividerMoveEvent\n * @property {number} ratio The position of the divider, from `0` (left) to `1` (right).\n * @property {number} x The position of the divider in container pixels.\n * @extends MaplairEvent\n */\n\n/**\n * Compares layers side by side: a vertical divider across the map shows the\n * \"left\" layers on its left and the \"right\" layers on its right side. The divider\n * can be dragged, or moved with the arrow keys. Works with layers having a\n * container or element of their own, e.g. tile layers and image overlays.\n *\n * Inspired by the [leaflet-side-by-side](https://github.com/digidem/leaflet-side-by-side) plugin.\n *\n * @example\n * ```js\n * const before = new TileLayer('https://…/2020/{z}/{x}/{y}.png').addTo(map);\n * const after = new TileLayer('https://…/2025/{z}/{x}/{y}.png').addTo(map);\n * new SideBySideControl(before, after).addTo(map);\n * ```\n *\n * @fires MaplairMap#dividermove {DividerMoveEvent} Fired when the divider of a\n * `SideBySideControl` moves.\n */\nexport class SideBySideControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tratio: 0.5\n\t};\n\n\t/**\n\t * Creates a side-by-side control for the given layers (which have to be added to the\n\t * map separately).\n\t * @param {Layer|Layer[]} [leftLayers]\n\t * @param {Layer|Layer[]} [rightLayers]\n\t * @param {SideBySideControlOptions} [options]\n\t */\n\tconstructor(leftLayers, rightLayers, options) {\n\t\tsuper(options);\n\t\tthis._leftLayers = [leftLayers ?? []].flat();\n\t\tthis._rightLayers = [rightLayers ?? []].flat();\n\t\tthis._ratio = this.options.ratio;\n\t\tthis.callInitHooks(SideBySideControl);\n\t}\n\n\t/**\n\t * Adds the control to the given map. The divider spans the map instead of being in\n\t * a corner.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tthis.remove();\n\t\tthis._map = map;\n\t\tthis._container = this.onAdd(map);\n\t\tmap._container.appendChild(this._container);\n\t\tmap.on('unload', this.remove, this);\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 divider = DomUtil.create('div', 'maplair-sidebyside-divider'),\n\t\tlabel = I18n.translate('Divider between the compared layers');\n\t\tdivider.tabIndex = 0;\n\t\tdivider.setAttribute('role', 'slider');\n\t\tdivider.setAttribute('aria-label', label);\n\t\tdivider.setAttribute('aria-valuemin', 0);\n\t\tdivider.setAttribute('aria-valuemax', 100);\n\n\t\tDomEvent.disableClickPropagation(divider);\n\t\tDomEvent.on(divider, 'pointerdown', this._onPointerDown, this);\n\t\tDomEvent.on(divider, 'keydown', this._onKeyDown, this);\n\n\t\tmap.on('move zoom viewreset resize rotate layeradd', this._update, this);\n\t\tthis._container = divider;\n\t\tthis._update();\n\t\treturn divider;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tthis._onPointerUp();\n\t\tmap.off('move zoom viewreset resize rotate layeradd', this._update, this);\n\t\tfor (const layer of [...this._leftLayers, ...this._rightLayers]) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (el) {\n\t\t\t\tel.style.clipPath = '';\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Sets the layers shown on the left side of the divider.\n\t * @param {Layer|Layer[]} layers\n\t * @returns {this}\n\t */\n\tsetLeftLayers(layers) {\n\t\tthis._clear(this._leftLayers);\n\t\tthis._leftLayers = [layers].flat();\n\t\treturn this._update();\n\t}\n\n\t/**\n\t * Sets the layers shown on the right side of the divider.\n\t * @param {Layer|Layer[]} layers\n\t * @returns {this}\n\t */\n\tsetRightLayers(layers) {\n\t\tthis._clear(this._rightLayers);\n\t\tthis._rightLayers = [layers].flat();\n\t\treturn this._update();\n\t}\n\n\t/**\n\t * Returns the position of the divider, from `0` (left) to `1` (right).\n\t * @returns {number}\n\t */\n\tgetRatio() {\n\t\treturn this._ratio;\n\t}\n\n\t/**\n\t * Moves the divider, from `0` (left) to `1` (right).\n\t * @param {number} ratio\n\t * @returns {this}\n\t */\n\tsetRatio(ratio) {\n\t\tthis._ratio = Math.min(1, Math.max(0, ratio));\n\t\tthis._update();\n\t\tthis._map?.fire('dividermove', {ratio: this._ratio, x: this._x});\n\t\treturn this;\n\t}\n\n\t_clear(layers) {\n\t\tfor (const layer of layers) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (el) {\n\t\t\t\tel.style.clipPath = '';\n\t\t\t}\n\t\t}\n\t}\n\n\t_update() {\n\t\tconst map = this._map;\n\t\tif (!map?._loaded || !this._container) { return this; }\n\n\t\tconst size = map.getSize(),\n\t\tx = this._x = Math.round(size.x * this._ratio);\n\t\tthis._container.style.left = `${x}px`;\n\t\tthis._container.setAttribute('aria-valuenow', Math.round(this._ratio * 100));\n\n\t\tthis._clip(this._leftLayers, 0, x, size.y);\n\t\tthis._clip(this._rightLayers, x, size.x, size.y);\n\t\treturn this;\n\t}\n\n\t// Clips the layers to the area from `x1` to `x2` (in container pixels)\n\t_clip(layers, x1, x2, height) {\n\t\tconst map = this._map;\n\t\tfor (const layer of layers) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (!el || !map.hasLayer(layer)) { continue; }\n\t\t\t// relative to the element, which is positioned in layer pixels\n\t\t\tconst offset = DomUtil.getPosition(el),\n\t\t\tcorners = [[x1, 0], [x2, 0], [x2, height], [x1, height]].map((p) => {\n\t\t\t\tconst point = map.containerPointToLayerPoint(p).subtract(offset);\n\t\t\t\treturn `${point.x}px ${point.y}px`;\n\t\t\t});\n\t\t\tel.style.clipPath = `polygon(${corners.join(', ')})`;\n\t\t}\n\t}\n\n\t_onPointerDown(e) {\n\t\tDomEvent.stop(e);\n\t\tthis._container.focus({preventScroll: true});\n\t\t// on the document, to follow the pointer outside of the divider\n\t\tDomEvent.on(document, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.on(document, 'pointerup pointercancel', this._onPointerUp, this);\n\t}\n\n\t_onPointerMove(e) {\n\t\tconst rect = this._map._container.getBoundingClientRect();\n\t\tthis.setRatio((e.clientX - rect.left) / rect.width);\n\t}\n\n\t_onPointerUp() {\n\t\tDomEvent.off(document, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(document, 'pointerup pointercancel', this._onPointerUp, this);\n\t}\n\n\t_onKeyDown(e) {\n\t\tconst step = e.shiftKey ? 0.01 : 0.05;\n\t\tif (e.key === 'ArrowLeft') {\n\t\t\tthis.setRatio(this._ratio - step);\n\t\t} else if (e.key === 'ArrowRight') {\n\t\t\tthis.setRatio(this._ratio + step);\n\t\t} else {\n\t\t\treturn;\n\t\t}\n\t\t// not panning the map\n\t\tDomEvent.stop(e);\n\t}\n}\n\nfunction getElement(layer) {\n\treturn layer.getContainer?.() ?? layer.getElement?.();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,oBAAb,MAAa,0BAA0B,QAAQ;CAE9C,OAAO,iBAAiB,EACvB,OAAO,GACR;;;;;;;;CASA,YAAY,YAAY,aAAa,SAAS;EAC7C,MAAM,OAAO;EACb,KAAK,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK;EAC3C,KAAK,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,KAAK;EAC7C,KAAK,SAAS,KAAK,QAAQ;EAC3B,KAAK,cAAc,iBAAiB;CACrC;;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AQ,KAAK,IAAI,EAAE;EACnD;CACD;CAEA,eAAe,GAAG;EACjB,KAAc,CAAC;EACf,KAAK,WAAW,MAAM,EAAC,eAAe,KAAI,CAAC;EAE3C,GAAY,UAAU,eAAe,KAAK,gBAAgB,IAAI;EAC9D,GAAY,UAAU,2BAA2B,KAAK,cAAc,IAAI;CACzE;CAEA,eAAe,GAAG;EACjB,MAAM,OAAO,KAAK,KAAK,WAAW,sBAAsB;EACxD,KAAK,UAAU,EAAE,UAAU,KAAK,QAAQ,KAAK,KAAK;CACnD;CAEA,eAAe;EACd,IAAa,UAAU,eAAe,KAAK,gBAAgB,IAAI;EAC/D,IAAa,UAAU,2BAA2B,KAAK,cAAc,IAAI;CAC1E;CAEA,WAAW,GAAG;EACb,MAAM,OAAO,EAAE,WAAW,MAAO;EACjC,IAAI,EAAE,QAAQ,aACb,KAAK,SAAS,KAAK,SAAS,IAAI;OAC1B,IAAI,EAAE,QAAQ,cACpB,KAAK,SAAS,KAAK,SAAS,IAAI;OAEhC;EAGD,KAAc,CAAC;CAChB;AACD;AAEA,SAAS,WAAW,OAAO;CAC1B,OAAO,MAAM,eAAe,KAAK,MAAM,aAAa;AACrD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { disableClickPropagation, disableScrollPropagation } from "../dom/DomEvent.js";
|
|
2
2
|
import { create } from "../dom/DomUtil.js";
|
|
3
3
|
import { Control } from "./Control.js";
|
|
4
|
-
|
|
4
|
+
// src/control/TextControl.js
|
|
5
5
|
/** @import {ControlOptions} from './Control.js' */
|
|
6
6
|
/**
|
|
7
7
|
* Options of `TextControl`.
|
|
@@ -25,13 +25,11 @@ import { Control } from "./Control.js";
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
var TextControl = class TextControl extends Control {
|
|
28
|
-
static {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
}
|
|
28
|
+
static defaultOptions = {
|
|
29
|
+
position: "topright",
|
|
30
|
+
content: "",
|
|
31
|
+
className: ""
|
|
32
|
+
};
|
|
35
33
|
/**
|
|
36
34
|
* Creates a text control.
|
|
37
35
|
* @param {...TextControlOptions} args The options.
|
|
@@ -77,7 +75,6 @@ var TextControl = class TextControl extends Control {
|
|
|
77
75
|
container.hidden = !content;
|
|
78
76
|
}
|
|
79
77
|
};
|
|
80
|
-
//#endregion
|
|
81
78
|
export { TextControl };
|
|
82
79
|
|
|
83
80
|
//# sourceMappingURL=TextControl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextControl.js","names":["DomUtil.create"],"sources":["../../../src/control/TextControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\n/** @import {ControlOptions} from './Control.js' */\n\n/**\n * Options of `TextControl`.\n * @typedef {object} TextControlOptions\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 {string|HTMLElement} [content=''] The content of the control: HTML or an\n * element. String content is rendered as HTML; do not pass untrusted input.\n * @property {string} [className=''] A custom CSS class name to assign to the control.\n * @extends ControlOptions\n */\n\n/**\n * A control showing a text or any content in a box, e.g. a title, a note on the\n * data or a status. It is hidden while its content is empty.\n *\n * @example\n * ```js\n * const status = new TextControl({position: 'topright', content: 'Loading…'}).addTo(map);\n * status.setContent(`Updated at ${new Date().toLocaleTimeString()}`);\n * ```\n */\nexport class TextControl extends Control {\n\n\tstatic {\n\t\
|
|
1
|
+
{"version":3,"file":"TextControl.js","names":["DomUtil.create"],"sources":["../../../src/control/TextControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\n/** @import {ControlOptions} from './Control.js' */\n\n/**\n * Options of `TextControl`.\n * @typedef {object} TextControlOptions\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 {string|HTMLElement} [content=''] The content of the control: HTML or an\n * element. String content is rendered as HTML; do not pass untrusted input.\n * @property {string} [className=''] A custom CSS class name to assign to the control.\n * @extends ControlOptions\n */\n\n/**\n * A control showing a text or any content in a box, e.g. a title, a note on the\n * data or a status. It is hidden while its content is empty.\n *\n * @example\n * ```js\n * const status = new TextControl({position: 'topright', content: 'Loading…'}).addTo(map);\n * status.setContent(`Updated at ${new Date().toLocaleTimeString()}`);\n * ```\n */\nexport class TextControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topright',\n\t\tcontent: '',\n\t\tclassName: ''\n\t};\n\n\t/**\n\t * Creates a text control.\n\t * @param {...TextControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(TextControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {HTMLElement}\n\t */\n\tonAdd() {\n\t\tconst container = DomUtil.create('div', `maplair-control-text ${this.options.className}`);\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tthis._container = container;\n\t\tthis._update();\n\t\treturn container;\n\t}\n\n\t/**\n\t * Changes the [content](#textcontrol-content) of the control.\n\t * @param {string|HTMLElement} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis.options.content = content;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the control.\n\t * @returns {string|HTMLElement}\n\t */\n\tgetContent() {\n\t\treturn this.options.content;\n\t}\n\n\t_update() {\n\t\tconst container = this._container,\n\t\t{content} = this.options;\n\t\tif (!container) { return; }\n\n\t\tif (typeof content === 'string') {\n\t\t\tcontainer.innerHTML = content;\n\t\t} else {\n\t\t\tcontainer.replaceChildren(content ?? '');\n\t\t}\n\t\tcontainer.hidden = !content;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;CAExC,OAAO,iBAAiB;EACvB,UAAU;EACV,SAAS;EACT,WAAW;CACZ;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;;CAMA,QAAQ;EACP,MAAM,YAAYA,OAAe,OAAO,wBAAwB,KAAK,QAAQ,WAAW;EACxF,wBAAiC,SAAS;EAC1C,yBAAkC,SAAS;EAC3C,KAAK,aAAa;EAClB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,QAAQ,UAAU;EACvB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,aAAa;EACZ,OAAO,KAAK,QAAQ;CACrB;CAEA,UAAU;EACT,MAAM,YAAY,KAAK,YACvB,EAAC,YAAW,KAAK;EACjB,IAAI,CAAC,WAAa;EAElB,IAAI,OAAO,YAAY,UACtB,UAAU,YAAY;OAEtB,UAAU,gBAAgB,WAAW,EAAE;EAExC,UAAU,SAAS,CAAC;CACrB;AACD"}
|