maplair 4.0.0-alpha.1
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 +2804 -0
- package/LICENSE +27 -0
- package/README.md +40 -0
- package/dist/esm/Maplair.js +71 -0
- package/dist/esm/Maplair.js.map +1 -0
- package/dist/esm/_virtual/_rolldown/runtime.js +13 -0
- package/dist/esm/control/AttributionControl.js +79 -0
- package/dist/esm/control/AttributionControl.js.map +1 -0
- package/dist/esm/control/Control.js +81 -0
- package/dist/esm/control/Control.js.map +1 -0
- package/dist/esm/control/LayersControl.js +220 -0
- package/dist/esm/control/LayersControl.js.map +1 -0
- package/dist/esm/control/ScaleControl.js +72 -0
- package/dist/esm/control/ScaleControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +86 -0
- package/dist/esm/control/ZoomControl.js.map +1 -0
- package/dist/esm/core/Browser.js +31 -0
- package/dist/esm/core/Browser.js.map +1 -0
- package/dist/esm/core/Class.js +52 -0
- package/dist/esm/core/Class.js.map +1 -0
- package/dist/esm/core/Events.js +149 -0
- package/dist/esm/core/Events.js.map +1 -0
- package/dist/esm/core/Handler.js +32 -0
- package/dist/esm/core/Handler.js.map +1 -0
- package/dist/esm/core/I18n.js +36 -0
- package/dist/esm/core/I18n.js.map +1 -0
- package/dist/esm/core/Util.js +71 -0
- package/dist/esm/core/Util.js.map +1 -0
- package/dist/esm/dom/DomEvent.DoubleTap.js +74 -0
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -0
- package/dist/esm/dom/DomEvent.PointerEvents.js +46 -0
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -0
- package/dist/esm/dom/DomEvent.js +135 -0
- package/dist/esm/dom/DomEvent.js.map +1 -0
- package/dist/esm/dom/DomUtil.js +107 -0
- package/dist/esm/dom/DomUtil.js.map +1 -0
- package/dist/esm/dom/Draggable.js +107 -0
- package/dist/esm/dom/Draggable.js.map +1 -0
- package/dist/esm/dom/PosAnimation.js +56 -0
- package/dist/esm/dom/PosAnimation.js.map +1 -0
- package/dist/esm/geo/LatLng.js +65 -0
- package/dist/esm/geo/LatLng.js.map +1 -0
- package/dist/esm/geo/LatLngBounds.js +114 -0
- package/dist/esm/geo/LatLngBounds.js.map +1 -0
- package/dist/esm/geo/crs/CRS.js +51 -0
- package/dist/esm/geo/crs/CRS.js.map +1 -0
- package/dist/esm/geo/crs/EPSG3395.js +16 -0
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -0
- package/dist/esm/geo/crs/EPSG3857.js +19 -0
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -0
- package/dist/esm/geo/crs/EPSG4326.js +13 -0
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -0
- package/dist/esm/geo/crs/EarthCRS.js +14 -0
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -0
- package/dist/esm/geo/crs/SimpleCRS.js +23 -0
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -0
- package/dist/esm/geo/projection/Projection.LonLat.js +19 -0
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -0
- package/dist/esm/geo/projection/Projection.Mercator.js +33 -0
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -0
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +27 -0
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -0
- package/dist/esm/geo/projection/index.js +14 -0
- package/dist/esm/geo/projection/index.js.map +1 -0
- package/dist/esm/geometry/Bounds.js +91 -0
- package/dist/esm/geometry/Bounds.js.map +1 -0
- package/dist/esm/geometry/LineUtil.js +169 -0
- package/dist/esm/geometry/LineUtil.js.map +1 -0
- package/dist/esm/geometry/Point.js +119 -0
- package/dist/esm/geometry/Point.js.map +1 -0
- package/dist/esm/geometry/PolyUtil.js +89 -0
- package/dist/esm/geometry/PolyUtil.js.map +1 -0
- package/dist/esm/geometry/Transformation.js +34 -0
- package/dist/esm/geometry/Transformation.js.map +1 -0
- package/dist/esm/layer/BlanketOverlay.js +87 -0
- package/dist/esm/layer/BlanketOverlay.js.map +1 -0
- package/dist/esm/layer/DivOverlay.js +192 -0
- package/dist/esm/layer/DivOverlay.js.map +1 -0
- package/dist/esm/layer/FeatureGroup.js +40 -0
- package/dist/esm/layer/FeatureGroup.js.map +1 -0
- package/dist/esm/layer/GeoJSON.js +192 -0
- package/dist/esm/layer/GeoJSON.js.map +1 -0
- package/dist/esm/layer/ImageOverlay.js +140 -0
- package/dist/esm/layer/ImageOverlay.js.map +1 -0
- package/dist/esm/layer/Layer.js +119 -0
- package/dist/esm/layer/Layer.js.map +1 -0
- package/dist/esm/layer/LayerGroup.js +58 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -0
- package/dist/esm/layer/Popup.js +224 -0
- package/dist/esm/layer/Popup.js.map +1 -0
- package/dist/esm/layer/SVGOverlay.js +21 -0
- package/dist/esm/layer/SVGOverlay.js.map +1 -0
- package/dist/esm/layer/Tooltip.js +228 -0
- package/dist/esm/layer/Tooltip.js.map +1 -0
- package/dist/esm/layer/VideoOverlay.js +54 -0
- package/dist/esm/layer/VideoOverlay.js.map +1 -0
- package/dist/esm/layer/marker/DefaultIcon.js +50 -0
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -0
- package/dist/esm/layer/marker/DivIcon.js +37 -0
- package/dist/esm/layer/marker/DivIcon.js.map +1 -0
- package/dist/esm/layer/marker/Icon.js +65 -0
- package/dist/esm/layer/marker/Icon.js.map +1 -0
- package/dist/esm/layer/marker/Marker.Drag.js +77 -0
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -0
- package/dist/esm/layer/marker/Marker.js +235 -0
- package/dist/esm/layer/marker/Marker.js.map +1 -0
- package/dist/esm/layer/tile/GridLayer.js +447 -0
- package/dist/esm/layer/tile/GridLayer.js.map +1 -0
- package/dist/esm/layer/tile/TileLayer.js +139 -0
- package/dist/esm/layer/tile/TileLayer.js.map +1 -0
- package/dist/esm/layer/tile/WMSTileLayer.js +68 -0
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -0
- package/dist/esm/layer/vector/Canvas.js +292 -0
- package/dist/esm/layer/vector/Canvas.js.map +1 -0
- package/dist/esm/layer/vector/Circle.js +35 -0
- package/dist/esm/layer/vector/Circle.js.map +1 -0
- package/dist/esm/layer/vector/CircleMarker.js +69 -0
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -0
- package/dist/esm/layer/vector/Path.js +68 -0
- package/dist/esm/layer/vector/Path.js.map +1 -0
- package/dist/esm/layer/vector/Polygon.js +70 -0
- package/dist/esm/layer/vector/Polygon.js.map +1 -0
- package/dist/esm/layer/vector/Polyline.js +152 -0
- package/dist/esm/layer/vector/Polyline.js.map +1 -0
- package/dist/esm/layer/vector/Rectangle.js +25 -0
- package/dist/esm/layer/vector/Rectangle.js.map +1 -0
- package/dist/esm/layer/vector/Renderer.getRenderer.js +31 -0
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -0
- package/dist/esm/layer/vector/Renderer.js +39 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -0
- package/dist/esm/layer/vector/SVG.js +115 -0
- package/dist/esm/layer/vector/SVG.js.map +1 -0
- package/dist/esm/map/Map.js +844 -0
- package/dist/esm/map/Map.js.map +1 -0
- package/dist/esm/map/handler/BoxZoomHandler.js +105 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +27 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/DragHandler.js +133 -0
- package/dist/esm/map/handler/DragHandler.js.map +1 -0
- package/dist/esm/map/handler/KeyboardHandler.js +117 -0
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -0
- package/dist/esm/map/handler/PinchZoomHandler.js +96 -0
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +50 -0
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/TapHoldHandler.js +77 -0
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -0
- package/dist/esm/package.js +6 -0
- package/dist/esm/package.js.map +1 -0
- package/dist/images/layers.svg +1 -0
- package/dist/images/logo.svg +1 -0
- package/dist/images/marker-icon.svg +1 -0
- package/dist/images/marker-shadow.svg +1 -0
- package/dist/maplair-global-src.js +6810 -0
- package/dist/maplair-global-src.js.map +1 -0
- package/dist/maplair-global.js +12 -0
- package/dist/maplair-global.js.map +1 -0
- package/dist/maplair-src.js +6704 -0
- package/dist/maplair-src.js.map +1 -0
- package/dist/maplair.css +730 -0
- package/dist/maplair.js +7 -0
- package/dist/maplair.js.map +1 -0
- package/i18n/cs.json +12 -0
- package/i18n/de.json +12 -0
- package/i18n/en.json +12 -0
- package/i18n/es.json +12 -0
- package/i18n/fr.json +12 -0
- package/i18n/hu.json +12 -0
- package/i18n/it.json +12 -0
- package/i18n/rm.json +12 -0
- package/i18n/sk.json +12 -0
- package/i18n/sl.json +12 -0
- package/package.json +87 -0
- package/src/Maplair.js +24 -0
- package/src/control/AttributionControl.js +147 -0
- package/src/control/Control.js +174 -0
- package/src/control/LayersControl.js +444 -0
- package/src/control/ScaleControl.js +141 -0
- package/src/control/ZoomControl.js +147 -0
- package/src/control/index.js +5 -0
- package/src/core/Browser.js +75 -0
- package/src/core/Class.js +97 -0
- package/src/core/Events.js +334 -0
- package/src/core/Handler.js +59 -0
- package/src/core/I18n.js +76 -0
- package/src/core/Util.js +122 -0
- package/src/core/index.js +8 -0
- package/src/dom/DomEvent.DoubleTap.js +120 -0
- package/src/dom/DomEvent.PointerEvents.js +75 -0
- package/src/dom/DomEvent.js +282 -0
- package/src/dom/DomUtil.js +175 -0
- package/src/dom/Draggable.js +204 -0
- package/src/dom/PosAnimation.js +115 -0
- package/src/dom/index.js +9 -0
- package/src/geo/LatLng.js +163 -0
- package/src/geo/LatLngBounds.js +260 -0
- package/src/geo/crs/CRS.js +143 -0
- package/src/geo/crs/EPSG3395.js +19 -0
- package/src/geo/crs/EPSG3857.js +26 -0
- package/src/geo/crs/EPSG4326.js +21 -0
- package/src/geo/crs/EarthCRS.js +32 -0
- package/src/geo/crs/SimpleCRS.js +35 -0
- package/src/geo/crs/index.js +6 -0
- package/src/geo/index.js +7 -0
- package/src/geo/projection/Projection.LonLat.js +30 -0
- package/src/geo/projection/Projection.Mercator.js +53 -0
- package/src/geo/projection/Projection.SphericalMercator.js +46 -0
- package/src/geo/projection/index.js +26 -0
- package/src/geometry/Bounds.js +222 -0
- package/src/geometry/LineUtil.js +299 -0
- package/src/geometry/Point.js +239 -0
- package/src/geometry/PolyUtil.js +129 -0
- package/src/geometry/Transformation.js +67 -0
- package/src/geometry/index.js +8 -0
- package/src/images/layers.svg +1 -0
- package/src/images/logo.svg +1 -0
- package/src/images/marker-icon.svg +1 -0
- package/src/images/marker-shadow.svg +1 -0
- package/src/layer/BlanketOverlay.js +171 -0
- package/src/layer/DivOverlay.js +353 -0
- package/src/layer/FeatureGroup.js +93 -0
- package/src/layer/GeoJSON.js +432 -0
- package/src/layer/ImageOverlay.js +279 -0
- package/src/layer/Layer.js +273 -0
- package/src/layer/LayerGroup.js +129 -0
- package/src/layer/Popup.js +528 -0
- package/src/layer/SVGOverlay.js +47 -0
- package/src/layer/Tooltip.js +469 -0
- package/src/layer/VideoOverlay.js +111 -0
- package/src/layer/index.js +18 -0
- package/src/layer/marker/DefaultIcon.js +79 -0
- package/src/layer/marker/DivIcon.js +76 -0
- package/src/layer/marker/Icon.js +164 -0
- package/src/layer/marker/Marker.Drag.js +161 -0
- package/src/layer/marker/Marker.js +465 -0
- package/src/layer/marker/index.js +5 -0
- package/src/layer/tile/GridLayer.js +901 -0
- package/src/layer/tile/TileLayer.js +299 -0
- package/src/layer/tile/WMSTileLayer.js +133 -0
- package/src/layer/tile/index.js +3 -0
- package/src/layer/vector/Canvas.js +479 -0
- package/src/layer/vector/Circle.js +87 -0
- package/src/layer/vector/CircleMarker.js +110 -0
- package/src/layer/vector/Path.js +145 -0
- package/src/layer/vector/Polygon.js +160 -0
- package/src/layer/vector/Polyline.js +296 -0
- package/src/layer/vector/Rectangle.js +52 -0
- package/src/layer/vector/Renderer.getRenderer.js +48 -0
- package/src/layer/vector/Renderer.js +75 -0
- package/src/layer/vector/SVG.js +216 -0
- package/src/layer/vector/index.js +10 -0
- package/src/map/Map.js +1830 -0
- package/src/map/handler/BoxZoomHandler.js +156 -0
- package/src/map/handler/DoubleClickZoomHandler.js +62 -0
- package/src/map/handler/DragHandler.js +240 -0
- package/src/map/handler/KeyboardHandler.js +188 -0
- package/src/map/handler/PinchZoomHandler.js +157 -0
- package/src/map/handler/ScrollWheelZoomHandler.js +98 -0
- package/src/map/handler/TapHoldHandler.js +111 -0
- package/src/map/index.js +8 -0
- package/src/maplair.css +730 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { create } from "../dom/DomUtil.js";
|
|
2
|
+
import { Control } from "./Control.js";
|
|
3
|
+
import { I18n } from "../core/I18n.js";
|
|
4
|
+
//#region src/control/ScaleControl.js
|
|
5
|
+
var ScaleControl = class ScaleControl extends Control {
|
|
6
|
+
static {
|
|
7
|
+
this.setDefaultOptions({
|
|
8
|
+
position: "bottomleft",
|
|
9
|
+
maxWidth: 100,
|
|
10
|
+
metric: true,
|
|
11
|
+
imperial: true,
|
|
12
|
+
updateWhenIdle: false
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
constructor(...args) {
|
|
16
|
+
super(...args);
|
|
17
|
+
this.callInitHooks(ScaleControl);
|
|
18
|
+
}
|
|
19
|
+
onAdd(map) {
|
|
20
|
+
const className = "maplair-control-scale", container = create("div", className), options = this.options;
|
|
21
|
+
this._addScales(options, `${className}-line`, container);
|
|
22
|
+
map.on(options.updateWhenIdle ? "moveend" : "move", this._update, this);
|
|
23
|
+
map.whenReady(this._update, this);
|
|
24
|
+
return container;
|
|
25
|
+
}
|
|
26
|
+
onRemove(map) {
|
|
27
|
+
map.off(this.options.updateWhenIdle ? "moveend" : "move", this._update, this);
|
|
28
|
+
}
|
|
29
|
+
_addScales(options, className, container) {
|
|
30
|
+
if (options.metric) this._mScale = create("div", className, container);
|
|
31
|
+
if (options.imperial) this._iScale = create("div", className, container);
|
|
32
|
+
}
|
|
33
|
+
_update() {
|
|
34
|
+
const map = this._map, y = map.getSize().y / 2;
|
|
35
|
+
const maxMeters = map.distance(map.containerPointToLatLng([0, y]), map.containerPointToLatLng([this.options.maxWidth, y]));
|
|
36
|
+
this._updateScales(maxMeters);
|
|
37
|
+
}
|
|
38
|
+
_updateScales(maxMeters) {
|
|
39
|
+
if (this.options.metric && maxMeters) this._updateMetric(maxMeters);
|
|
40
|
+
if (this.options.imperial && maxMeters) this._updateImperial(maxMeters);
|
|
41
|
+
}
|
|
42
|
+
_updateMetric(maxMeters) {
|
|
43
|
+
const meters = this._getRoundNum(maxMeters), label = meters < 1e3 ? I18n.translate("{meters} m", { meters }) : I18n.translate("{kilometers} km", { kilometers: meters / 1e3 });
|
|
44
|
+
this._updateScale(this._mScale, label, meters / maxMeters);
|
|
45
|
+
}
|
|
46
|
+
_updateImperial(maxMeters) {
|
|
47
|
+
const maxFeet = maxMeters * 3.2808399;
|
|
48
|
+
let maxMiles, miles, feet;
|
|
49
|
+
if (maxFeet > 5280) {
|
|
50
|
+
maxMiles = maxFeet / 5280;
|
|
51
|
+
miles = this._getRoundNum(maxMiles);
|
|
52
|
+
this._updateScale(this._iScale, I18n.translate("{miles} mi", { miles }), miles / maxMiles);
|
|
53
|
+
} else {
|
|
54
|
+
feet = this._getRoundNum(maxFeet);
|
|
55
|
+
this._updateScale(this._iScale, I18n.translate("{feet} ft", { feet }), feet / maxFeet);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
_updateScale(scale, text, ratio) {
|
|
59
|
+
scale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;
|
|
60
|
+
scale.innerHTML = text;
|
|
61
|
+
}
|
|
62
|
+
_getRoundNum(num) {
|
|
63
|
+
const pow10 = 10 ** (`${Math.floor(num)}`.length - 1);
|
|
64
|
+
let d = num / pow10;
|
|
65
|
+
d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
|
|
66
|
+
return pow10 * d;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
export { ScaleControl };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=ScaleControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScaleControl.js","names":["DomUtil.create"],"sources":["../../../src/control/ScaleControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport {I18n} from '../core/I18n.js';\n\n/*\n * @class ScaleControl\n * @inherits Control\n *\n * A simple scale control that shows the scale of the current center of screen in metric (m/km) and imperial (mi/ft) systems. Extends `Control`.\n *\n * @example\n *\n * ```js\n * new ScaleControl().addTo(map);\n * ```\n */\n\n// @constructor ScaleControl(options?: ScaleControl options)\n// Creates an scale control with the given options.\nexport class ScaleControl extends Control {\n\n\tstatic {\n\t\t// @section\n\t\t// @aka ScaleControl options\n\t\tthis.setDefaultOptions({\n\t\t\t// @option position: String = 'bottomleft'\n\t\t\t// The position of the control (one of the map corners). Possible values are `'topleft'`,\n\t\t\t// `'topright'`, `'bottomleft'` or `'bottomright'`\n\t\t\tposition: 'bottomleft',\n\n\t\t\t// @option maxWidth: Number = 100\n\t\t\t// Maximum width of the control in pixels. The width is set dynamically to show round values (e.g. 100, 200, 500).\n\t\t\tmaxWidth: 100,\n\n\t\t\t// @option metric: Boolean = True\n\t\t\t// Whether to show the metric scale line (m/km).\n\t\t\tmetric: true,\n\n\t\t\t// @option imperial: Boolean = True\n\t\t\t// Whether to show the imperial scale line (mi/ft).\n\t\t\timperial: true,\n\n\t\t\t// @option updateWhenIdle: Boolean = false\n\t\t\t// If `true`, the control is updated on [`moveend`](#map-moveend), otherwise it's always up-to-date (updated on [`move`](#map-move)).\n\t\t\tupdateWhenIdle: false\n\t\t});\n\t}\n\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ScaleControl);\n\t}\n\n\tonAdd(map) {\n\t\tconst className = 'maplair-control-scale',\n\t\tcontainer = DomUtil.create('div', className),\n\t\toptions = this.options;\n\n\t\tthis._addScales(options, `${className}-line`, container);\n\n\t\tmap.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);\n\t\tmap.whenReady(this._update, this);\n\n\t\treturn container;\n\t}\n\n\tonRemove(map) {\n\t\tmap.off(this.options.updateWhenIdle ? 'moveend' : 'move', this._update, this);\n\t}\n\n\t_addScales(options, className, container) {\n\t\tif (options.metric) {\n\t\t\tthis._mScale = DomUtil.create('div', className, container);\n\t\t}\n\t\tif (options.imperial) {\n\t\t\tthis._iScale = DomUtil.create('div', className, container);\n\t\t}\n\t}\n\n\t_update() {\n\t\tconst map = this._map,\n\t\ty = map.getSize().y / 2;\n\n\t\tconst maxMeters = map.distance(\n\t\t\tmap.containerPointToLatLng([0, y]),\n\t\t\tmap.containerPointToLatLng([this.options.maxWidth, y]));\n\n\t\tthis._updateScales(maxMeters);\n\t}\n\n\t_updateScales(maxMeters) {\n\t\tif (this.options.metric && maxMeters) {\n\t\t\tthis._updateMetric(maxMeters);\n\t\t}\n\t\tif (this.options.imperial && maxMeters) {\n\t\t\tthis._updateImperial(maxMeters);\n\t\t}\n\t}\n\n\t_updateMetric(maxMeters) {\n\t\tconst meters = this._getRoundNum(maxMeters),\n\t\tlabel = meters < 1000 ?\n\t\t\tI18n.translate('{meters} m', {meters}) :\n\t\t\tI18n.translate('{kilometers} km', {kilometers: meters / 1000});\n\n\t\tthis._updateScale(this._mScale, label, meters / maxMeters);\n\t}\n\n\t_updateImperial(maxMeters) {\n\t\tconst maxFeet = maxMeters * 3.2808399;\n\t\tlet maxMiles, miles, feet;\n\n\t\tif (maxFeet > 5280) {\n\t\t\tmaxMiles = maxFeet / 5280;\n\t\t\tmiles = this._getRoundNum(maxMiles);\n\t\t\tthis._updateScale(this._iScale, I18n.translate('{miles} mi', {miles}), miles / maxMiles);\n\n\t\t} else {\n\t\t\tfeet = this._getRoundNum(maxFeet);\n\t\t\tthis._updateScale(this._iScale, I18n.translate('{feet} ft', {feet}), feet / maxFeet);\n\t\t}\n\t}\n\n\t_updateScale(scale, text, ratio) {\n\t\tscale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;\n\t\tscale.innerHTML = text;\n\t}\n\n\t_getRoundNum(num) {\n\t\tconst pow10 = 10 ** ((`${Math.floor(num)}`).length - 1);\n\t\tlet d = num / pow10;\n\n\t\td = d >= 10 ? 10 :\n\t\t\td >= 5 ? 5 :\n\t\t\td >= 3 ? 3 :\n\t\t\td >= 2 ? 2 : 1;\n\n\t\treturn pow10 * d;\n\t}\n}\n"],"mappings":";;;;AAoBA,IAAa,eAAb,MAAa,qBAAqB,QAAQ;CAEzC;EAGC,KAAK,kBAAkB;GAItB,UAAU;GAIV,UAAU;GAIV,QAAQ;GAIR,UAAU;GAIV,gBAAgB;EACjB,CAAC;CACF;CAEA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,YAAY;CAChC;CAEA,MAAM,KAAK;EACV,MAAM,YAAY,yBAClB,YAAYA,OAAe,OAAO,SAAS,GAC3C,UAAU,KAAK;EAEf,KAAK,WAAW,SAAS,GAAG,UAAU,QAAQ,SAAS;EAEvD,IAAI,GAAG,QAAQ,iBAAiB,YAAY,QAAQ,KAAK,SAAS,IAAI;EACtE,IAAI,UAAU,KAAK,SAAS,IAAI;EAEhC,OAAO;CACR;CAEA,SAAS,KAAK;EACb,IAAI,IAAI,KAAK,QAAQ,iBAAiB,YAAY,QAAQ,KAAK,SAAS,IAAI;CAC7E;CAEA,WAAW,SAAS,WAAW,WAAW;EACzC,IAAI,QAAQ,QACX,KAAK,UAAUA,OAAe,OAAO,WAAW,SAAS;EAE1D,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MAAM,GAAG,IAAK,SAAS;EACrD,IAAI,IAAI,MAAM;EAEd,IAAI,KAAK,KAAK,KACb,KAAK,IAAI,IACT,KAAK,IAAI,IACT,KAAK,IAAI,IAAI;EAEd,OAAO,QAAQ;CAChB;AACD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { disableClickPropagation, on, stop } from "../dom/DomEvent.js";
|
|
2
|
+
import { create } from "../dom/DomUtil.js";
|
|
3
|
+
import { Control } from "./Control.js";
|
|
4
|
+
import { I18n } from "../core/I18n.js";
|
|
5
|
+
//#region src/control/ZoomControl.js
|
|
6
|
+
var ZoomControl = class ZoomControl extends Control {
|
|
7
|
+
static {
|
|
8
|
+
this.setDefaultOptions({
|
|
9
|
+
position: "topleft",
|
|
10
|
+
zoomInText: "<span aria-hidden=\"true\">+</span>",
|
|
11
|
+
zoomOutText: "<span aria-hidden=\"true\">−</span>"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
constructor(...args) {
|
|
15
|
+
super(...args);
|
|
16
|
+
this.callInitHooks(ZoomControl);
|
|
17
|
+
}
|
|
18
|
+
onAdd(map) {
|
|
19
|
+
const zoomName = "maplair-control-zoom", container = create("div", `${zoomName} maplair-bar`), options = this.options;
|
|
20
|
+
this._zoomInButton = this._createButton(options.zoomInText, I18n.translate("Zoom in"), `${zoomName}-in`, container, this._zoomIn);
|
|
21
|
+
this._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate("Zoom out"), `${zoomName}-out`, container, this._zoomOut);
|
|
22
|
+
this._updateDisabled();
|
|
23
|
+
map.on("zoomend zoomlevelschange", this._updateDisabled, this);
|
|
24
|
+
return container;
|
|
25
|
+
}
|
|
26
|
+
onRemove(map) {
|
|
27
|
+
map.off("zoomend zoomlevelschange", this._updateDisabled, this);
|
|
28
|
+
}
|
|
29
|
+
disable() {
|
|
30
|
+
this._disabled = true;
|
|
31
|
+
this._updateDisabled();
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
enable() {
|
|
35
|
+
this._disabled = false;
|
|
36
|
+
this._updateDisabled();
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
_zoomIn(e) {
|
|
40
|
+
if (!this._disabled && this._map._zoom < this._map.getMaxZoom()) this._map.zoomIn(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));
|
|
41
|
+
}
|
|
42
|
+
_zoomOut(e) {
|
|
43
|
+
if (!this._disabled && this._map._zoom > this._map.getMinZoom()) this._map.zoomOut(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));
|
|
44
|
+
}
|
|
45
|
+
_createButton(html, title, className, container, fn) {
|
|
46
|
+
const link = create("a", className, container);
|
|
47
|
+
link.innerHTML = html;
|
|
48
|
+
link.href = "#";
|
|
49
|
+
link.title = title;
|
|
50
|
+
link.setAttribute("role", "button");
|
|
51
|
+
link.setAttribute("aria-label", title);
|
|
52
|
+
disableClickPropagation(link);
|
|
53
|
+
on(link, "click", stop);
|
|
54
|
+
on(link, "click", fn, this);
|
|
55
|
+
on(link, "click", this._refocusOnMap, this);
|
|
56
|
+
return link;
|
|
57
|
+
}
|
|
58
|
+
_updateDisabled() {
|
|
59
|
+
const map = this._map, className = "maplair-disabled";
|
|
60
|
+
this._zoomInButton.classList.remove(className);
|
|
61
|
+
this._zoomOutButton.classList.remove(className);
|
|
62
|
+
this._zoomInButton.setAttribute("aria-disabled", "false");
|
|
63
|
+
this._zoomOutButton.setAttribute("aria-disabled", "false");
|
|
64
|
+
if (this._disabled || map._zoom === map.getMinZoom()) {
|
|
65
|
+
this._zoomOutButton.classList.add(className);
|
|
66
|
+
this._zoomOutButton.setAttribute("aria-disabled", "true");
|
|
67
|
+
}
|
|
68
|
+
if (this._disabled || map._zoom === map.getMaxZoom()) {
|
|
69
|
+
this._zoomInButton.classList.add(className);
|
|
70
|
+
this._zoomInButton.setAttribute("aria-disabled", "true");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
static register(MaplairMap) {
|
|
74
|
+
MaplairMap.mergeOptions({ zoomControl: true });
|
|
75
|
+
MaplairMap.addInitHook(function() {
|
|
76
|
+
if (this.options.zoomControl) {
|
|
77
|
+
this.zoomControl = new ZoomControl();
|
|
78
|
+
this.addControl(this.zoomControl);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
export { ZoomControl };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=ZoomControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZoomControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/ZoomControl.js"],"sourcesContent":["\nimport {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\n/*\n * @class ZoomControl\n * @inherits Control\n *\n * A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by default unless you set its [`zoomControl` option](#map-zoomcontrol) to `false`. Extends `Control`.\n */\n\n// @namespace ZoomControl\n// @constructor ZoomControl(options: ZoomControl options)\n// Creates a zoom control\nexport class ZoomControl extends Control {\n\n\tstatic {\n\t\t// @section\n\t\t// @aka ZoomControl options\n\t\tthis.setDefaultOptions({\n\t\t\t// @option position: String = 'topleft'\n\t\t\t// The position of the control (one of the map corners). Possible values are `'topleft'`,\n\t\t\t// `'topright'`, `'bottomleft'` or `'bottomright'`\n\t\t\tposition: 'topleft',\n\n\t\t\t// @option zoomInText: String = '<span aria-hidden=\"true\">+</span>'\n\t\t\t// The text set on the 'zoom in' button.\n\t\t\tzoomInText: '<span aria-hidden=\"true\">+</span>',\n\n\t\t\t// @option zoomOutText: String = '<span aria-hidden=\"true\">−</span>'\n\t\t\t// The text set on the 'zoom out' button.\n\t\t\tzoomOutText: '<span aria-hidden=\"true\">−</span>',\n\t\t});\n\t}\n\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ZoomControl);\n\t}\n\n\tonAdd(map) {\n\t\tconst zoomName = 'maplair-control-zoom',\n\t\tcontainer = DomUtil.create('div', `${zoomName} maplair-bar`),\n\t\toptions = this.options;\n\n\t\tthis._zoomInButton = this._createButton(options.zoomInText, I18n.translate('Zoom in'),\n\t\t\t`${zoomName}-in`, container, this._zoomIn);\n\t\tthis._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate('Zoom out'),\n\t\t\t`${zoomName}-out`, container, this._zoomOut);\n\n\t\tthis._updateDisabled();\n\t\tmap.on('zoomend zoomlevelschange', this._updateDisabled, this);\n\n\t\treturn container;\n\t}\n\n\tonRemove(map) {\n\t\tmap.off('zoomend zoomlevelschange', this._updateDisabled, this);\n\t}\n\n\tdisable() {\n\t\tthis._disabled = true;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\tenable() {\n\t\tthis._disabled = false;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t_zoomIn(e) {\n\t\tif (!this._disabled && this._map._zoom < this._map.getMaxZoom()) {\n\t\t\tthis._map.zoomIn(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));\n\t\t}\n\t}\n\n\t_zoomOut(e) {\n\t\tif (!this._disabled && this._map._zoom > this._map.getMinZoom()) {\n\t\t\tthis._map.zoomOut(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));\n\t\t}\n\t}\n\n\t_createButton(html, title, className, container, fn) {\n\t\tconst link = DomUtil.create('a', className, container);\n\t\tlink.innerHTML = html;\n\t\tlink.href = '#';\n\t\tlink.title = title;\n\n\t\t/*\n\t\t * Will force screen readers like VoiceOver to read this as \"Zoom in - button\"\n\t\t */\n\t\tlink.setAttribute('role', 'button');\n\t\tlink.setAttribute('aria-label', title);\n\n\t\tDomEvent.disableClickPropagation(link);\n\t\tDomEvent.on(link, 'click', DomEvent.stop);\n\t\tDomEvent.on(link, 'click', fn, this);\n\t\tDomEvent.on(link, 'click', this._refocusOnMap, this);\n\n\t\treturn link;\n\t}\n\n\t_updateDisabled() {\n\t\tconst map = this._map,\n\t\tclassName = 'maplair-disabled';\n\n\t\tthis._zoomInButton.classList.remove(className);\n\t\tthis._zoomOutButton.classList.remove(className);\n\t\tthis._zoomInButton.setAttribute('aria-disabled', 'false');\n\t\tthis._zoomOutButton.setAttribute('aria-disabled', 'false');\n\n\t\tif (this._disabled || map._zoom === map.getMinZoom()) {\n\t\t\tthis._zoomOutButton.classList.add(className);\n\t\t\tthis._zoomOutButton.setAttribute('aria-disabled', 'true');\n\t\t}\n\t\tif (this._disabled || map._zoom === map.getMaxZoom()) {\n\t\t\tthis._zoomInButton.classList.add(className);\n\t\t\tthis._zoomInButton.setAttribute('aria-disabled', 'true');\n\t\t}\n\t}\n\n\t// Registers this default feature on the map class, called by `MaplairMap` itself.\n\tstatic register(MaplairMap) {\n\t\t// @namespace MaplairMap\n\t\t// @section Control options\n\t\t// @option zoomControl: Boolean = true\n\t\t// Whether a [zoom control](#control-zoom) is added to the map by default.\n\t\tMaplairMap.mergeOptions({\n\t\t\tzoomControl: true\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.zoomControl) {\n\t\t\t\t// @section Controls\n\t\t\t\t// @property zoomControl: ZoomControl\n\t\t\t\t// The default zoom control (only available if the\n\t\t\t\t// [`zoomControl` option](#map-zoomcontrol) was `true` when creating the map).\n\t\t\t\tthis.zoomControl = new ZoomControl();\n\t\t\t\tthis.addControl(this.zoomControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;AAgBA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;CAExC;EAGC,KAAK,kBAAkB;GAItB,UAAU;GAIV,YAAY;GAIZ,aAAa;EACd,CAAC;CACF;CAEA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;CAEA,MAAM,KAAK;EACV,MAAM,WAAW,wBACjB,YAAYA,OAAe,OAAO,GAAG,SAAS,aAAa,GAC3D,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KAAK,MACjB,YAAY;EAEZ,KAAK,cAAc,UAAU,OAAO,SAAS;EAC7C,KAAK,eAAe,UAAU,OAAO,SAAS;EAC9C,KAAK,cAAc,aAAa,iBAAiB,OAAO;EACxD,KAAK,eAAe,aAAa,iBAAiB,OAAO;EAEzD,IAAI,KAAK,aAAa,IAAI,UAAU,IAAI,WAAW,GAAG;GACrD,KAAK,eAAe,UAAU,IAAI,SAAS;GAC3C,KAAK,eAAe,aAAa,iBAAiB,MAAM;EACzD;EACA,IAAI,KAAK,aAAa,IAAI,UAAU,IAAI,WAAW,GAAG;GACrD,KAAK,cAAc,UAAU,IAAI,SAAS;GAC1C,KAAK,cAAc,aAAa,iBAAiB,MAAM;EACxD;CACD;CAGA,OAAO,SAAS,YAAY;EAK3B,WAAW,aAAa,EACvB,aAAa,KACd,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,aAAa;IAK7B,KAAK,cAAc,IAAI,YAAY;IACnC,KAAK,WAAW,KAAK,WAAW;GACjC;EACD,CAAC;CACF;AACD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/core/Browser.js
|
|
2
|
+
const chrome = userAgentContains("chrome");
|
|
3
|
+
const safari = !chrome && userAgentContains("safari");
|
|
4
|
+
const mobile = typeof orientation !== "undefined";
|
|
5
|
+
const reducedMotion = navigator.preferences?.reducedMotion?.value ? navigator.preferences.reducedMotion.value === "reduce" : typeof window === "undefined" ? true : window?.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
6
|
+
const pointer = typeof window === "undefined" ? false : !!window.PointerEvent;
|
|
7
|
+
const touchNative = typeof window === "undefined" ? false : "ontouchstart" in window || !!window.TouchEvent;
|
|
8
|
+
const touch = touchNative || pointer;
|
|
9
|
+
const retina = typeof window === "undefined" || typeof window.devicePixelRatio === "undefined" ? false : window.devicePixelRatio > 1;
|
|
10
|
+
const mac = typeof navigator === "undefined" || typeof navigator.platform === "undefined" ? false : navigator.platform.startsWith("Mac");
|
|
11
|
+
const linux = typeof navigator === "undefined" || typeof navigator.platform === "undefined" ? false : navigator.platform.startsWith("Linux");
|
|
12
|
+
function userAgentContains(str) {
|
|
13
|
+
if (typeof navigator === "undefined" || typeof navigator.userAgent === "undefined") return false;
|
|
14
|
+
return navigator.userAgent.toLowerCase().includes(str);
|
|
15
|
+
}
|
|
16
|
+
var Browser_default = {
|
|
17
|
+
chrome,
|
|
18
|
+
safari,
|
|
19
|
+
mobile,
|
|
20
|
+
reducedMotion,
|
|
21
|
+
pointer,
|
|
22
|
+
touch,
|
|
23
|
+
touchNative,
|
|
24
|
+
retina,
|
|
25
|
+
mac,
|
|
26
|
+
linux
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { Browser_default as default };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=Browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Browser.js","names":[],"sources":["../../../src/core/Browser.js"],"sourcesContent":["/*\n * @namespace Browser\n *\n * A namespace with static properties for browser/feature detection used by Maplair internally.\n *\n * @example\n *\n * ```js\n * if (Browser.chrome) {\n * alert('You are running Chrome!');\n * }\n * ```\n */\n\n// @property chrome: Boolean; `true` for the Chrome browser.\nconst chrome = userAgentContains('chrome');\n\n// @property safari: Boolean; `true` for the Safari browser.\nconst safari = !chrome && userAgentContains('safari');\n\n// @property mobile: Boolean; `true` for all browsers running in a mobile device.\nconst mobile = typeof orientation !== 'undefined';\n\n// @property reducedMotion: Boolean\n// `true` if the user has [configured their environment for reduced motion](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-reduced-motion#user_preferences).\n// Determines whether animations should play or not.\nconst reducedMotion = navigator.preferences?.reducedMotion?.value ?\n\tnavigator.preferences.reducedMotion.value === 'reduce' :\n\ttypeof window === 'undefined' ? true : window?.matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n// @property pointer: Boolean\n// `true` for all browsers supporting [pointer events](https://msdn.microsoft.com/en-us/library/dn433244%28v=vs.85%29.aspx).\nconst pointer = typeof window === 'undefined' ? false : !!window.PointerEvent;\n\n// @property touchNative: Boolean\n// `true` for all browsers supporting [touch events](https://developer.mozilla.org/docs/Web/API/Touch_events).\n// **This does not necessarily mean** that the browser is running in a computer with\n// a touchscreen, it only means that the browser is capable of understanding\n// touch events.\nconst touchNative = typeof window === 'undefined' ? false : 'ontouchstart' in window || !!(window.TouchEvent);\n\n// @property touch: Boolean\n// `true` for all browsers supporting either [touch](#browser-touch) or [pointer](#browser-pointer) events.\n// Note: pointer events will be preferred (if available), and processed for all `touch*` listeners.\nconst touch = touchNative || pointer;\n\n// @property retina: Boolean\n// `true` for browsers on a high-resolution \"retina\" screen or on any screen when browser's display zoom is more than 100%.\nconst retina = typeof window === 'undefined' || typeof window.devicePixelRatio === 'undefined' ? false : window.devicePixelRatio > 1;\n\n// @property mac: Boolean; `true` when the browser is running in a Mac platform\nconst mac = typeof navigator === 'undefined' || typeof navigator.platform === 'undefined' ? false : navigator.platform.startsWith('Mac');\n\n// @property linux: Boolean; `true` when the browser is running in a Linux platform\nconst linux = typeof navigator === 'undefined' || typeof navigator.platform === 'undefined' ? false : navigator.platform.startsWith('Linux');\n\nfunction userAgentContains(str) {\n\tif (typeof navigator === 'undefined' || typeof navigator.userAgent === 'undefined') {\n\t\treturn false;\n\t}\n\treturn navigator.userAgent.toLowerCase().includes(str);\n}\n\nexport default {\n\tchrome,\n\tsafari,\n\tmobile,\n\treducedMotion,\n\tpointer,\n\ttouch,\n\ttouchNative,\n\tretina,\n\tmac,\n\tlinux\n};\n"],"mappings":";AAeA,MAAM,SAAS,kBAAkB,QAAQ;AAGzC,MAAM,SAAS,CAAC,UAAU,kBAAkB,QAAQ;AAGpD,MAAM,SAAS,OAAO,gBAAgB;AAKtC,MAAM,gBAAgB,UAAU,aAAa,eAAe,QAC3D,UAAU,YAAY,cAAc,UAAU,WAC9C,OAAO,WAAW,cAAc,OAAO,QAAQ,WAAW,kCAAkC,CAAC,CAAC;AAI/F,MAAM,UAAU,OAAO,WAAW,cAAc,QAAQ,CAAC,CAAC,OAAO;AAOjE,MAAM,cAAc,OAAO,WAAW,cAAc,QAAQ,kBAAkB,UAAU,CAAC,CAAE,OAAO;AAKlG,MAAM,QAAQ,eAAe;AAI7B,MAAM,SAAS,OAAO,WAAW,eAAe,OAAO,OAAO,qBAAqB,cAAc,QAAQ,OAAO,mBAAmB;AAGnI,MAAM,MAAM,OAAO,cAAc,eAAe,OAAO,UAAU,aAAa,cAAc,QAAQ,UAAU,SAAS,WAAW,KAAK;AAGvI,MAAM,QAAQ,OAAO,cAAc,eAAe,OAAO,UAAU,aAAa,cAAc,QAAQ,UAAU,SAAS,WAAW,OAAO;AAE3I,SAAS,kBAAkB,KAAK;CAC/B,IAAI,OAAO,cAAc,eAAe,OAAO,UAAU,cAAc,aACtE,OAAO;CAER,OAAO,UAAU,UAAU,YAAY,CAAC,CAAC,SAAS,GAAG;AACtD;AAEA,IAAA,kBAAe;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { setOptions } from "./Util.js";
|
|
2
|
+
//#region src/core/Class.js
|
|
3
|
+
var Class = class {
|
|
4
|
+
static include(props) {
|
|
5
|
+
const parentOptions = this.prototype.options;
|
|
6
|
+
for (const k of getAllMethodNames(props)) this.prototype[k] = props[k];
|
|
7
|
+
if (props.options) {
|
|
8
|
+
this.prototype.options = parentOptions;
|
|
9
|
+
this.mergeOptions(props.options);
|
|
10
|
+
}
|
|
11
|
+
return this;
|
|
12
|
+
function* getAllMethodNames(obj) {
|
|
13
|
+
do {
|
|
14
|
+
if (obj === Object || obj === Object.prototype) break;
|
|
15
|
+
for (const k of Object.getOwnPropertyNames(obj)) yield k;
|
|
16
|
+
} while ((obj = Object.getPrototypeOf(obj)) !== void 0);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
static setDefaultOptions(options) {
|
|
20
|
+
setOptions(this.prototype, options);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
static mergeOptions(options) {
|
|
24
|
+
this.prototype.options ??= {};
|
|
25
|
+
Object.assign(this.prototype.options, options);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
static addInitHook(fn, ...args) {
|
|
29
|
+
const init = typeof fn === "function" ? fn : function() {
|
|
30
|
+
this[fn](...args);
|
|
31
|
+
};
|
|
32
|
+
if (!Object.hasOwn(this, "_initHooks")) this._initHooks = [];
|
|
33
|
+
this._initHooks.push(init);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
constructor() {
|
|
37
|
+
setOptions(this);
|
|
38
|
+
}
|
|
39
|
+
callInitHooks(cls = this.constructor) {
|
|
40
|
+
const done = this._initHooksCalledFor;
|
|
41
|
+
if (done && (done === cls || done.prototype instanceof cls)) return this;
|
|
42
|
+
const classes = [];
|
|
43
|
+
for (let c = cls; c && c !== Function.prototype && c !== done; c = Object.getPrototypeOf(c)) classes.unshift(c);
|
|
44
|
+
this._initHooksCalledFor = cls;
|
|
45
|
+
for (const c of classes) if (Object.hasOwn(c, "_initHooks")) for (const hook of c._initHooks) hook.call(this);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { Class };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=Class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Class.js","names":[],"sources":["../../../src/core/Class.js"],"sourcesContent":["import * as Util from './Util.js';\n\n// @class Class\n\n// @section\n// @uninheritable\n\n// Thanks to John Resig and Dean Edwards for inspiration!\n\nexport class Class {\n\t// @function include(properties: Object): this\n\t// [Includes a mixin](#class-includes) into the current class.\n\tstatic include(props) {\n\t\tconst parentOptions = this.prototype.options;\n\t\tfor (const k of getAllMethodNames(props)) {\n\t\t\tthis.prototype[k] = props[k];\n\t\t}\n\t\tif (props.options) {\n\t\t\tthis.prototype.options = parentOptions;\n\t\t\tthis.mergeOptions(props.options);\n\t\t}\n\t\treturn this;\n\n\t\tfunction *getAllMethodNames(obj) {\n\t\t\tdo {\n\t\t\t\tif (obj === Object || obj === Object.prototype) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tfor (const k of Object.getOwnPropertyNames(obj)) {\n\t\t\t\t\tyield k;\n\t\t\t\t}\n\t\t\t} while ((obj = Object.getPrototypeOf(obj)) !== undefined);\n\t\t}\n\t}\n\n\t// @function setDefaultOptions(options: Object): this\n\t// Configures the [default `options`](#class-options) on the prototype of this class.\n\tstatic setDefaultOptions(options) {\n\t\tUtil.setOptions(this.prototype, options);\n\t\treturn this;\n\t}\n\n\t// @function mergeOptions(options: Object): this\n\t// [Merges `options`](#class-options) into the defaults of the class.\n\tstatic mergeOptions(options) {\n\t\tthis.prototype.options ??= {};\n\t\tObject.assign(this.prototype.options, options);\n\t\treturn this;\n\t}\n\n\t// @function addInitHook(fn: Function): this\n\t// Adds a [constructor hook](#class-constructor-hooks) to the class.\n\tstatic addInitHook(fn, ...args) { // (Function) || (String, args...)\n\t\tconst init = typeof fn === 'function' ? fn : function () {\n\t\t\tthis[fn](...args);\n\t\t};\n\n\t\tif (!Object.hasOwn(this, '_initHooks')) { // do not use ??= here, which would find the parent class' hooks\n\t\t\tthis._initHooks = [];\n\t\t}\n\t\tthis._initHooks.push(init);\n\t\treturn this;\n\t}\n\n\tconstructor() {\n\t\tUtil.setOptions(this);\n\t}\n\n\t// @method callInitHooks(cls?: Function): this\n\t// Runs the [constructor hooks](#class-constructor-hooks) of the given class and\n\t// of its parent classes, which haven't run yet for this object. Classes call it\n\t// at the end of their constructor, e.g. `this.callInitHooks(MyClass)`.\n\t// Without `cls`, runs the hooks of all classes of this object.\n\tcallInitHooks(cls = this.constructor) {\n\t\tconst done = this._initHooksCalledFor;\n\t\tif (done && (done === cls || done.prototype instanceof cls)) {\n\t\t\treturn this; // the hooks of `cls` already ran\n\t\t}\n\n\t\t// parent classes first; stop at the class whose hooks (and whose parent\n\t\t// classes' hooks) already ran, e.g. in the constructor of a parent class\n\t\tconst classes = [];\n\t\tfor (let c = cls; c && c !== Function.prototype && c !== done; c = Object.getPrototypeOf(c)) {\n\t\t\tclasses.unshift(c);\n\t\t}\n\t\tthis._initHooksCalledFor = cls;\n\n\t\tfor (const c of classes) {\n\t\t\tif (Object.hasOwn(c, '_initHooks')) {\n\t\t\t\tfor (const hook of c._initHooks) {\n\t\t\t\t\thook.call(this);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n}\n"],"mappings":";;AASA,IAAa,QAAb,MAAmB;CAGlB,OAAO,QAAQ,OAAO;EACrB,MAAM,gBAAgB,KAAK,UAAU;EACrC,KAAK,MAAM,KAAK,kBAAkB,KAAK,GACtC,KAAK,UAAU,KAAK,MAAM;EAE3B,IAAI,MAAM,SAAS;GAClB,KAAK,UAAU,UAAU;GACzB,KAAK,aAAa,MAAM,OAAO;EAChC;EACA,OAAO;EAEP,UAAU,kBAAkB,KAAK;GAChC,GAAG;IACF,IAAI,QAAQ,UAAU,QAAQ,OAAO,WACpC;IAED,KAAK,MAAM,KAAK,OAAO,oBAAoB,GAAG,GAC7C,MAAM;GAER,UAAU,MAAM,OAAO,eAAe,GAAG,OAAO,KAAA;EACjD;CACD;CAIA,OAAO,kBAAkB,SAAS;EACjC,WAAgB,KAAK,WAAW,OAAO;EACvC,OAAO;CACR;CAIA,OAAO,aAAa,SAAS;EAC5B,KAAK,UAAU,YAAY,CAAC;EAC5B,OAAO,OAAO,KAAK,UAAU,SAAS,OAAO;EAC7C,OAAO;CACR;CAIA,OAAO,YAAY,IAAI,GAAG,MAAM;EAC/B,MAAM,OAAO,OAAO,OAAO,aAAa,KAAK,WAAY;GACxD,KAAK,GAAG,CAAC,GAAG,IAAI;EACjB;EAEA,IAAI,CAAC,OAAO,OAAO,MAAM,YAAY,GACpC,KAAK,aAAa,CAAC;EAEpB,KAAK,WAAW,KAAK,IAAI;EACzB,OAAO;CACR;CAEA,cAAc;EACb,WAAgB,IAAI;CACrB;CAOA,cAAc,MAAM,KAAK,aAAa;EACrC,MAAM,OAAO,KAAK;EAClB,IAAI,SAAS,SAAS,OAAO,KAAK,qBAAqB,MACtD,OAAO;EAKR,MAAM,UAAU,CAAC;EACjB,KAAK,IAAI,IAAI,KAAK,KAAK,MAAM,SAAS,aAAa,MAAM,MAAM,IAAI,OAAO,eAAe,CAAC,GACzF,QAAQ,QAAQ,CAAC;EAElB,KAAK,sBAAsB;EAE3B,KAAK,MAAM,KAAK,SACf,IAAI,OAAO,OAAO,GAAG,YAAY,GAChC,KAAK,MAAM,QAAQ,EAAE,YACpB,KAAK,KAAK,IAAI;EAIjB,OAAO;CACR;AACD"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { falseFn, splitWords, stamp } from "./Util.js";
|
|
2
|
+
import { Class } from "./Class.js";
|
|
3
|
+
//#region src/core/Events.js
|
|
4
|
+
var Evented = class Evented extends Class {
|
|
5
|
+
on(types, fn, context) {
|
|
6
|
+
if (typeof types === "object") for (const [type, f] of Object.entries(types)) this._on(type, f, fn);
|
|
7
|
+
else for (const type of splitWords(types)) this._on(type, fn, context);
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
off(types, fn, context) {
|
|
11
|
+
if (!arguments.length) {
|
|
12
|
+
delete this._events;
|
|
13
|
+
delete this._listenerIndex;
|
|
14
|
+
} else if (typeof types === "object") for (const [type, f] of Object.entries(types)) this._off(type, f, fn);
|
|
15
|
+
else {
|
|
16
|
+
const removeAll = arguments.length === 1;
|
|
17
|
+
for (const type of splitWords(types)) if (removeAll) this._off(type);
|
|
18
|
+
else this._off(type, fn, context);
|
|
19
|
+
}
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
static __REMOVED_EVENTS = [
|
|
23
|
+
"mousedown",
|
|
24
|
+
"mouseup",
|
|
25
|
+
"mouseover",
|
|
26
|
+
"mouseout",
|
|
27
|
+
"mousemove"
|
|
28
|
+
];
|
|
29
|
+
_on(type, fn, context, _once) {
|
|
30
|
+
if (Evented.__REMOVED_EVENTS.includes(type)) console.error(`The event ${type} has been removed. Use the PointerEvent variant instead.`);
|
|
31
|
+
if (typeof fn !== "function") {
|
|
32
|
+
console.warn(`wrong listener type: ${typeof fn}`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (context === this) context = void 0;
|
|
36
|
+
const contexts = this._getListenerIndex(type).get(fn);
|
|
37
|
+
if (contexts?.has(context)) return;
|
|
38
|
+
const newListener = {
|
|
39
|
+
fn,
|
|
40
|
+
ctx: context
|
|
41
|
+
};
|
|
42
|
+
if (_once) newListener.once = true;
|
|
43
|
+
this._events ??= {};
|
|
44
|
+
this._events[type] ??= /* @__PURE__ */ new Set();
|
|
45
|
+
this._events[type].add(newListener);
|
|
46
|
+
if (contexts) contexts.set(context, newListener);
|
|
47
|
+
else this._listenerIndex[type].set(fn, /* @__PURE__ */ new Map([[context, newListener]]));
|
|
48
|
+
}
|
|
49
|
+
_getListenerIndex(type) {
|
|
50
|
+
this._listenerIndex ??= {};
|
|
51
|
+
return this._listenerIndex[type] ??= /* @__PURE__ */ new Map();
|
|
52
|
+
}
|
|
53
|
+
_off(type, fn, context) {
|
|
54
|
+
if (!this._events) return;
|
|
55
|
+
let listeners = this._events[type];
|
|
56
|
+
if (!listeners) return;
|
|
57
|
+
if (arguments.length === 1) {
|
|
58
|
+
if (this._firingCount) for (const listener of listeners) listener.fn = falseFn;
|
|
59
|
+
delete this._events[type];
|
|
60
|
+
delete this._listenerIndex?.[type];
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (typeof fn !== "function") {
|
|
64
|
+
console.warn(`wrong listener type: ${typeof fn}`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (context === this) context = void 0;
|
|
68
|
+
const contexts = this._listenerIndex?.[type]?.get(fn), listener = contexts?.get(context);
|
|
69
|
+
if (listener) {
|
|
70
|
+
contexts.delete(context);
|
|
71
|
+
if (!contexts.size) this._listenerIndex[type].delete(fn);
|
|
72
|
+
if (this._firingCount) {
|
|
73
|
+
listener.fn = falseFn;
|
|
74
|
+
this._events[type] = listeners = new Set(listeners);
|
|
75
|
+
}
|
|
76
|
+
listeners.delete(listener);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
fire(type, data, propagate) {
|
|
80
|
+
if (!this.listens(type, propagate)) return this;
|
|
81
|
+
const event = {
|
|
82
|
+
...data,
|
|
83
|
+
type,
|
|
84
|
+
target: this,
|
|
85
|
+
sourceTarget: data?.sourceTarget || this
|
|
86
|
+
};
|
|
87
|
+
if (this._events) {
|
|
88
|
+
const listeners = this._events[type];
|
|
89
|
+
if (listeners) {
|
|
90
|
+
this._firingCount = this._firingCount + 1 || 1;
|
|
91
|
+
for (const l of listeners) {
|
|
92
|
+
const fn = l.fn;
|
|
93
|
+
if (l.once) this.off(type, fn, l.ctx);
|
|
94
|
+
fn.call(l.ctx || this, event);
|
|
95
|
+
}
|
|
96
|
+
this._firingCount--;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (propagate) this._propagateEvent(event);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
listens(type, fn, context, propagate) {
|
|
103
|
+
if (typeof type !== "string") console.warn("\"string\" type argument expected");
|
|
104
|
+
let _fn = fn;
|
|
105
|
+
if (typeof fn !== "function") {
|
|
106
|
+
propagate = !!fn;
|
|
107
|
+
_fn = void 0;
|
|
108
|
+
context = void 0;
|
|
109
|
+
}
|
|
110
|
+
if (this._events?.[type]?.size) {
|
|
111
|
+
if (this._listens(type, _fn, context) !== false) return true;
|
|
112
|
+
}
|
|
113
|
+
if (propagate) {
|
|
114
|
+
for (const p of Object.values(this._eventParents ?? {})) if (p.listens(type, fn, context, propagate)) return true;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
_listens(type, fn, context) {
|
|
119
|
+
if (!this._events) return false;
|
|
120
|
+
const listeners = this._events[type];
|
|
121
|
+
if (!fn) return !!listeners?.size;
|
|
122
|
+
if (context === this) context = void 0;
|
|
123
|
+
return !!this._listenerIndex?.[type]?.get(fn)?.has(context);
|
|
124
|
+
}
|
|
125
|
+
once(types, fn, context) {
|
|
126
|
+
if (typeof types === "object") for (const [type, f] of Object.entries(types)) this._on(type, f, fn, true);
|
|
127
|
+
else for (const type of splitWords(types)) this._on(type, fn, context, true);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
addEventParent(obj) {
|
|
131
|
+
this._eventParents ??= {};
|
|
132
|
+
this._eventParents[stamp(obj)] = obj;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
removeEventParent(obj) {
|
|
136
|
+
if (this._eventParents) delete this._eventParents[stamp(obj)];
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
_propagateEvent(e) {
|
|
140
|
+
for (const p of Object.values(this._eventParents ?? {})) p.fire(e.type, {
|
|
141
|
+
propagatedFrom: e.target,
|
|
142
|
+
...e
|
|
143
|
+
}, true);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
//#endregion
|
|
147
|
+
export { Evented };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=Events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Events.js","names":["Util.splitWords","Util.falseFn","Util.stamp"],"sources":["../../../src/core/Events.js"],"sourcesContent":["import {Class} from './Class.js';\nimport * as Util from './Util.js';\n\n/*\n * @class Evented\n * @inherits Class\n *\n * A set of methods shared between event-powered classes (like `Map` and `Marker`). Generally, events allow you to execute some function when something happens with an object (e.g. the user clicks on the map, causing the map to fire `'click'` event).\n *\n * @example\n *\n * ```js\n * map.on('click', function(e) {\n * \talert(e.latlng);\n * } );\n * ```\n *\n * Maplair deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function:\n *\n * ```js\n * function onClick(e) { ... }\n *\n * map.on('click', onClick);\n * map.off('click', onClick);\n * ```\n */\n\nexport class Evented extends Class {\n\t/* @method on(type: String, fn: Function, context?: Object): this\n\t * Adds a listener function (`fn`) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. `'click dblclick'`).\n\t *\n\t * @alternative\n\t * @method on(eventMap: Object): this\n\t * Adds a set of type/listener pairs, e.g. `{click: onClick, pointermove: onPointerMove}`\n\t */\n\ton(types, fn, context) {\n\n\t\t// types can be a map of types/handlers\n\t\tif (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\t// we don't process space-separated events here for performance;\n\t\t\t\t// it's a hot path since Layer uses the on(obj) syntax\n\t\t\t\tthis._on(type, f, fn);\n\t\t\t}\n\n\t\t} else {\n\t\t\t// types can be a string of space-separated words\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tthis._on(type, fn, context);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/* @method off(type: String, fn?: Function, context?: Object): this\n\t * Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to `on`, you must pass the same context to `off` in order to remove the listener.\n\t *\n\t * @alternative\n\t * @method off(eventMap: Object): this\n\t * Removes a set of type/listener pairs.\n\t *\n\t * @alternative\n\t * @method off: this\n\t * Removes all listeners to all events on the object. This includes implicitly attached events.\n\t */\n\toff(types, fn, context) {\n\n\t\tif (!arguments.length) {\n\t\t\t// clear all listeners if called without arguments\n\t\t\tdelete this._events;\n\t\t\tdelete this._listenerIndex;\n\n\t\t} else if (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\tthis._off(type, f, fn);\n\t\t\t}\n\n\t\t} else {\n\t\t\tconst removeAll = arguments.length === 1;\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tif (removeAll) {\n\t\t\t\t\tthis._off(type);\n\t\t\t\t} else {\n\t\t\t\t\tthis._off(type, fn, context);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tstatic __REMOVED_EVENTS = ['mousedown', 'mouseup', 'mouseover', 'mouseout', 'mousemove'];\n\n\t// attach listener (without syntactic sugar now)\n\t_on(type, fn, context, _once) {\n\t\t// To be removed in maplair 3\n\t\tif (Evented.__REMOVED_EVENTS.includes(type)) {\n\t\t\tconsole.error(`The event ${type} has been removed. Use the PointerEvent variant instead.`);\n\t\t}\n\n\t\tif (typeof fn !== 'function') {\n\t\t\tconsole.warn(`wrong listener type: ${typeof fn}`);\n\t\t\treturn;\n\t\t}\n\n\t\tif (context === this) {\n\t\t\t// Less memory footprint.\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\t// check if fn already there\n\t\tconst contexts = this._getListenerIndex(type).get(fn);\n\t\tif (contexts?.has(context)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newListener = {fn, ctx: context};\n\t\tif (_once) {\n\t\t\tnewListener.once = true;\n\t\t}\n\n\t\tthis._events ??= {};\n\t\t// a Set keeps the listeners in order, and allows removing them in constant time\n\t\tthis._events[type] ??= new Set();\n\t\tthis._events[type].add(newListener);\n\n\t\tif (contexts) {\n\t\t\tcontexts.set(context, newListener);\n\t\t} else {\n\t\t\tthis._listenerIndex[type].set(fn, new Map([[context, newListener]]));\n\t\t}\n\t}\n\n\t// Listeners of the given event type, indexed by function and context, so that\n\t// adding and removing listeners doesn't need to scan all listeners of the type\n\t// (e.g. each marker listens to the map's `zoom` events with the same function).\n\t_getListenerIndex(type) {\n\t\tthis._listenerIndex ??= {};\n\t\treturn (this._listenerIndex[type] ??= new Map());\n\t}\n\n\t_off(type, fn, context) {\n\t\tif (!this._events) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet listeners = this._events[type];\n\t\tif (!listeners) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (arguments.length === 1) { // remove all\n\t\t\tif (this._firingCount) {\n\t\t\t\t// Set all removed listeners to noop\n\t\t\t\t// so they are not called if remove happens in fire\n\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\tlistener.fn = Util.falseFn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// clear all listeners for a type if function isn't specified\n\t\t\tdelete this._events[type];\n\t\t\tdelete this._listenerIndex?.[type];\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof fn !== 'function') {\n\t\t\tconsole.warn(`wrong listener type: ${typeof fn}`);\n\t\t\treturn;\n\t\t}\n\n\t\t// find fn and remove it\n\t\tif (context === this) {\n\t\t\tcontext = undefined;\n\t\t}\n\t\tconst contexts = this._listenerIndex?.[type]?.get(fn),\n\t\tlistener = contexts?.get(context);\n\t\tif (listener) {\n\t\t\tcontexts.delete(context);\n\t\t\tif (!contexts.size) {\n\t\t\t\tthis._listenerIndex[type].delete(fn);\n\t\t\t}\n\t\t\tif (this._firingCount) {\n\t\t\t\t// set the removed listener to noop so that's not called if remove happens in fire\n\t\t\t\tlistener.fn = Util.falseFn;\n\n\t\t\t\t/* copy listeners in case events are being fired */\n\t\t\t\tthis._events[type] = listeners = new Set(listeners);\n\t\t\t}\n\t\t\tlisteners.delete(listener);\n\t\t}\n\t}\n\n\t// @method fire(type: String, data?: Object, propagate?: Boolean): this\n\t// Fires an event of the specified type. You can optionally provide a data\n\t// object — the first argument of the listener function will contain its\n\t// properties. The event can optionally be propagated to event parents.\n\tfire(type, data, propagate) {\n\t\tif (!this.listens(type, propagate)) { return this; }\n\n\t\tconst event = {\n\t\t\t...data,\n\t\t\ttype,\n\t\t\ttarget: this,\n\t\t\tsourceTarget: data?.sourceTarget || this\n\t\t};\n\n\t\tif (this._events) {\n\t\t\tconst listeners = this._events[type];\n\t\t\tif (listeners) {\n\t\t\t\tthis._firingCount = (this._firingCount + 1) || 1;\n\t\t\t\tfor (const l of listeners) {\n\t\t\t\t\t// off overwrites l.fn, so we need to copy fn to a variable\n\t\t\t\t\tconst fn = l.fn;\n\t\t\t\t\tif (l.once) {\n\t\t\t\t\t\tthis.off(type, fn, l.ctx);\n\t\t\t\t\t}\n\t\t\t\t\tfn.call(l.ctx || this, event);\n\t\t\t\t}\n\n\t\t\t\tthis._firingCount--;\n\t\t\t}\n\t\t}\n\n\t\tif (propagate) {\n\t\t\t// propagate the event to parents (set with addEventParent)\n\t\t\tthis._propagateEvent(event);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t// @method listens(type: String, propagate?: Boolean): Boolean\n\t// @method listens(type: String, fn: Function, context?: Object, propagate?: Boolean): Boolean\n\t// Returns `true` if a particular event type has any listeners attached to it.\n\t// The verification can optionally be propagated, it will return `true` if parents have the listener attached to it.\n\tlistens(type, fn, context, propagate) {\n\t\tif (typeof type !== 'string') {\n\t\t\tconsole.warn('\"string\" type argument expected');\n\t\t}\n\n\t\t// we don't overwrite the input `fn` value, because we need to use it for propagation\n\t\tlet _fn = fn;\n\t\tif (typeof fn !== 'function') {\n\t\t\tpropagate = !!fn;\n\t\t\t_fn = undefined;\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\tif (this._events?.[type]?.size) {\n\t\t\tif (this._listens(type, _fn, context) !== false) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tif (propagate) {\n\t\t\t// also check parents for listeners if event propagates\n\t\t\tfor (const p of Object.values(this._eventParents ?? {})) {\n\t\t\t\tif (p.listens(type, fn, context, propagate)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t// returns whether the given listener (or any listener, if no `fn` is given) is registered\n\t_listens(type, fn, context) {\n\t\tif (!this._events) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst listeners = this._events[type];\n\t\tif (!fn) {\n\t\t\treturn !!listeners?.size;\n\t\t}\n\n\t\tif (context === this) {\n\t\t\t// Less memory footprint.\n\t\t\tcontext = undefined;\n\t\t}\n\n\t\treturn !!this._listenerIndex?.[type]?.get(fn)?.has(context);\n\n\t}\n\n\t// @method once(…): this\n\t// Behaves as [`on(…)`](#evented-on), except the listener will only get fired once and then removed.\n\tonce(types, fn, context) {\n\n\t\t// types can be a map of types/handlers\n\t\tif (typeof types === 'object') {\n\t\t\tfor (const [type, f] of Object.entries(types)) {\n\t\t\t\t// we don't process space-separated events here for performance;\n\t\t\t\t// it's a hot path since Layer uses the on(obj) syntax\n\t\t\t\tthis._on(type, f, fn, true);\n\t\t\t}\n\n\t\t} else {\n\t\t\t// types can be a string of space-separated words\n\t\t\tfor (const type of Util.splitWords(types)) {\n\t\t\t\tthis._on(type, fn, context, true);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t// @method addEventParent(obj: Evented): this\n\t// Adds an event parent - an `Evented` that will receive propagated events\n\taddEventParent(obj) {\n\t\tthis._eventParents ??= {};\n\t\tthis._eventParents[Util.stamp(obj)] = obj;\n\t\treturn this;\n\t}\n\n\t// @method removeEventParent(obj: Evented): this\n\t// Removes an event parent, so it will stop receiving propagated events\n\tremoveEventParent(obj) {\n\t\tif (this._eventParents) {\n\t\t\tdelete this._eventParents[Util.stamp(obj)];\n\t\t}\n\t\treturn this;\n\t}\n\n\t_propagateEvent(e) {\n\t\tfor (const p of Object.values(this._eventParents ?? {})) {\n\t\t\tp.fire(e.type, {\n\t\t\t\tpropagatedFrom: e.target,\n\t\t\t\t...e\n\t\t\t}, true);\n\t\t}\n\t}\n};\n"],"mappings":";;;AA2BA,IAAa,UAAb,MAAa,gBAAgB,MAAM;CAQlC,GAAG,OAAO,IAAI,SAAS;EAGtB,IAAI,OAAO,UAAU,UACpB,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,QAAQ,KAAK,GAG3C,KAAK,IAAI,MAAM,GAAG,EAAE;OAKrB,KAAK,MAAM,QAAQA,WAAgB,KAAK,GACvC,KAAK,IAAI,MAAM,IAAI,OAAO;EAI5B,OAAO;CACR;CAaA,IAAI,OAAO,IAAI,SAAS;EAEvB,IAAI,CAAC,UAAU,QAAQ;GAEtB,OAAO,KAAK;G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EACJ,GAAG,IAAI;CAET;AACD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Class } from "./Class.js";
|
|
2
|
+
//#region src/core/Handler.js
|
|
3
|
+
var Handler = class Handler extends Class {
|
|
4
|
+
constructor(map) {
|
|
5
|
+
super();
|
|
6
|
+
this._map = map;
|
|
7
|
+
this.callInitHooks(Handler);
|
|
8
|
+
}
|
|
9
|
+
enable() {
|
|
10
|
+
if (this._enabled) return this;
|
|
11
|
+
this._enabled = true;
|
|
12
|
+
this.addHooks();
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
disable() {
|
|
16
|
+
if (!this._enabled) return this;
|
|
17
|
+
this._enabled = false;
|
|
18
|
+
this.removeHooks();
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
enabled() {
|
|
22
|
+
return !!this._enabled;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
Handler.addTo = function(map, name) {
|
|
26
|
+
map.addHandler(name, this);
|
|
27
|
+
return this;
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { Handler };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=Handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Handler.js","names":[],"sources":["../../../src/core/Handler.js"],"sourcesContent":["import {Class} from './Class.js';\n\n/*\n\tHandler is a base class for handler classes that are used internally to inject\n\tinteraction features like dragging to classes like Map and Marker.\n*/\n\n// @class Handler\n// Abstract class for map interaction handlers\n\nexport class Handler extends Class {\n\tconstructor(map) {\n\t\tsuper();\n\t\tthis._map = map;\n\n\t\tthis.callInitHooks(Handler);\n\t}\n\n\t// @method enable(): this\n\t// Enables the handler\n\tenable() {\n\t\tif (this._enabled) { return this; }\n\n\t\tthis._enabled = true;\n\t\tthis.addHooks();\n\t\treturn this;\n\t}\n\n\t// @method disable(): this\n\t// Disables the handler\n\tdisable() {\n\t\tif (!this._enabled) { return this; }\n\n\t\tthis._enabled = false;\n\t\tthis.removeHooks();\n\t\treturn this;\n\t}\n\n\t// @method enabled(): Boolean\n\t// Returns `true` if the handler is enabled\n\tenabled() {\n\t\treturn !!this._enabled;\n\t}\n\n\t// @section Extension methods\n\t// Classes inheriting from `Handler` must implement the two following methods:\n\t// @method addHooks()\n\t// Called when the handler is enabled, should add event hooks.\n\t// @method removeHooks()\n\t// Called when the handler is disabled, should remove the event hooks added previously.\n}\n\n// @section There is static function which can be called without instantiating Handler:\n// @function addTo(map: MaplairMap, name: String): this\n// Adds a new Handler to the given map with the given name.\nHandler.addTo = function (map, name) {\n\tmap.addHandler(name, this);\n\treturn this;\n};\n"],"mappings":";;AAUA,IAAa,UAAb,MAAa,gBAAgB,MAAM;CAClC,YAAY,KAAK;EAChB,MAAM;EACN,KAAK,OAAO;EAEZ,KAAK,cAAc,OAAO;CAC3B;CAIA,SAAS;EACR,IAAI,KAAK,UAAY,OAAO;EAE5B,KAAK,WAAW;EAChB,KAAK,SAAS;EACd,OAAO;CACR;CAIA,UAAU;EACT,IAAI,CAAC,KAAK,UAAY,OAAO;EAE7B,KAAK,WAAW;EAChB,KAAK,YAAY;EACjB,OAAO;CACR;CAIA,UAAU;EACT,OAAO,CAAC,CAAC,KAAK;CACf;AAQD;AAKA,QAAQ,QAAQ,SAAU,KAAK,MAAM;CACpC,IAAI,WAAW,MAAM,IAAI;CACzB,OAAO;AACR"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { template } from "./Util.js";
|
|
2
|
+
//#region src/core/I18n.js
|
|
3
|
+
var I18n = class {
|
|
4
|
+
static #messages = {};
|
|
5
|
+
static #locale = null;
|
|
6
|
+
static registerLocale(locale, messages) {
|
|
7
|
+
this.#messages[locale] = {
|
|
8
|
+
...this.#messages[locale],
|
|
9
|
+
...messages
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
static setLocale(locale) {
|
|
13
|
+
this.#locale = locale;
|
|
14
|
+
}
|
|
15
|
+
static getLocale() {
|
|
16
|
+
return this.#locale;
|
|
17
|
+
}
|
|
18
|
+
static translate(string, data = {}) {
|
|
19
|
+
if (this.#locale === null) return template(string, data);
|
|
20
|
+
const translation = this.#messages[this.#locale]?.[string];
|
|
21
|
+
if (!translation) {
|
|
22
|
+
console.warn(`No translation found for "${string}", falling back to the original string.`);
|
|
23
|
+
return template(string, data);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
return template(translation, data);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.error(`Error while translating "${translation}".`, err);
|
|
29
|
+
return translation;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { I18n };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=I18n.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"I18n.js","names":["Util.template"],"sources":["../../../src/core/I18n.js"],"sourcesContent":["import * as Util from './Util.js';\n\n/*\n * @namespace I18n\n *\n * Utility functions to deal with translations.\n *\n * @example\n *\n * Translations of Maplair's built-in strings are maintained on\n * [Transifex](https://app.transifex.com/simon04/maplair/) and published in the\n * `i18n` directory of the package. Load one before creating the map:\n *\n * ```js\n * import {I18n} from 'maplair';\n * import de from 'maplair/i18n/de.json' with {type: 'json'};\n *\n * I18n.registerLocale('de', de);\n * I18n.setLocale('de');\n * ```\n */\n\nexport class I18n {\n\t// @property messages: Object\n\t// All localized strings.\n\tstatic #messages = {};\n\n\t// @property locale: String\n\t// The current locale code, that will be used when translating strings.\n\tstatic #locale = null;\n\n\t// @function registerLocale(locale: String, messages?: Object): undefined\n\t// Define localized strings for a given locale, defined by `locale`.\n\tstatic registerLocale(locale, messages) {\n\t\tthis.#messages[locale] = {...this.#messages[locale], ...messages};\n\t}\n\n\t// @function setLocale(locale: String): undefined\n\t// Define or change the locale code to be used when translating strings.\n\t// Note that changing the locale does not affect already instantiated objects.\n\tstatic setLocale(locale) {\n\t\tthis.#locale = locale;\n\t}\n\n\t// @method getLocale(): String\n\t// Returns the current locale code, that will be used when translating strings.\n\tstatic getLocale() {\n\t\treturn this.#locale;\n\t}\n\n\t// @function translate(string: String, data?: Object): String\n\t// Actually try to translate the `string`, with optional variable passed in `data`.\n\tstatic translate(string, data = {}) {\n\t\t// If the locale is not set, localization is not enabled.\n\t\tif (this.#locale === null) {\n\t\t\treturn Util.template(string, data);\n\t\t}\n\n\t\tconst translation = this.#messages[this.#locale]?.[string];\n\n\t\tif (!translation) {\n\t\t\tconsole.warn(`No translation found for \"${string}\", falling back to the original string.`);\n\t\t\treturn Util.template(string, data);\n\t\t}\n\n\t\ttry {\n\t\t\t// Do not fail if some data is missing\n\t\t\t// a bad translation should not break the app\n\t\t\treturn Util.template(translation, data);\n\t\t} catch (err) {\n\t\t\tconsole.error(`Error while translating \"${translation}\".`, err);\n\t\t\treturn translation;\n\t\t}\n\t}\n\n}\n"],"mappings":";;AAsBA,IAAa,OAAb,MAAkB;CAGjB,OAAO,YAAY,CAAC;CAIpB,OAAO,UAAU;CAIjB,OAAO,eAAe,QAAQ,UAAU;EACvC,KAAK,UAAU,UAAU;GAAC,GAAG,KAAK,UAAU;GAAS,GAAG;EAAQ;CACjE;CAKA,OAAO,UAAU,QAAQ;EACxB,KAAK,UAAU;CAChB;CAIA,OAAO,YAAY;EAClB,OAAO,KAAK;CACb;CAIA,OAAO,UAAU,QAAQ,OAAO,CAAC,GAAG;EAEnC,IAAI,KAAK,YAAY,MACpB,OAAOA,SAAc,QAAQ,IAAI;EAGlC,MAAM,cAAc,KAAK,UAAU,KAAK,QAAQ,GAAG;EAEnD,IAAI,CAAC,aAAa;GACjB,QAAQ,KAAK,6BAA6B,OAAO,wCAAwC;GACzF,OAAOA,SAAc,QAAQ,IAAI;EAClC;EAEA,IAAI;GAGH,OAAOA,SAAc,aAAa,IAAI;EACvC,SAAS,KAAK;GACb,QAAQ,MAAM,4BAA4B,YAAY,KAAK,GAAG;GAC9D,OAAO;EACR;CACD;AAED"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
//#region src/core/Util.js
|
|
3
|
+
var Util_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
falseFn: () => falseFn,
|
|
5
|
+
formatNum: () => formatNum,
|
|
6
|
+
lastId: () => lastId,
|
|
7
|
+
setOptions: () => setOptions,
|
|
8
|
+
splitWords: () => splitWords,
|
|
9
|
+
stamp: () => stamp,
|
|
10
|
+
template: () => template,
|
|
11
|
+
throttle: () => throttle,
|
|
12
|
+
wrapNum: () => wrapNum
|
|
13
|
+
});
|
|
14
|
+
let lastId = 0;
|
|
15
|
+
function stamp(obj) {
|
|
16
|
+
if (!("_maplair_id" in obj)) obj["_maplair_id"] = ++lastId;
|
|
17
|
+
return obj._maplair_id;
|
|
18
|
+
}
|
|
19
|
+
function throttle(fn, time, context) {
|
|
20
|
+
let lock, queuedArgs;
|
|
21
|
+
function later() {
|
|
22
|
+
lock = false;
|
|
23
|
+
if (queuedArgs) {
|
|
24
|
+
wrapperFn.apply(context, queuedArgs);
|
|
25
|
+
queuedArgs = false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function wrapperFn(...args) {
|
|
29
|
+
if (lock) queuedArgs = args;
|
|
30
|
+
else {
|
|
31
|
+
fn.apply(context, args);
|
|
32
|
+
setTimeout(later, time);
|
|
33
|
+
lock = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return wrapperFn;
|
|
37
|
+
}
|
|
38
|
+
function wrapNum(x, range, includeMax) {
|
|
39
|
+
const max = range[1], min = range[0], d = max - min;
|
|
40
|
+
return x === max && includeMax ? x : ((x - min) % d + d) % d + min;
|
|
41
|
+
}
|
|
42
|
+
function falseFn() {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
function formatNum(num, precision) {
|
|
46
|
+
if (precision === false) return num;
|
|
47
|
+
const pow = 10 ** (precision === void 0 ? 6 : precision);
|
|
48
|
+
return Math.round(num * pow) / pow;
|
|
49
|
+
}
|
|
50
|
+
const WHITESPACE_RE = /\s+/;
|
|
51
|
+
function splitWords(str) {
|
|
52
|
+
return str.trim().split(WHITESPACE_RE);
|
|
53
|
+
}
|
|
54
|
+
function setOptions(obj, options) {
|
|
55
|
+
if (!Object.hasOwn(obj, "options")) obj.options = obj.options ? Object.create(obj.options) : {};
|
|
56
|
+
for (const i in options) if (Object.hasOwn(options, i)) obj.options[i] = options[i];
|
|
57
|
+
return obj.options;
|
|
58
|
+
}
|
|
59
|
+
const templateRe = /\{ *([\w_ -]+) *\}/g;
|
|
60
|
+
function template(str, data) {
|
|
61
|
+
return str.replace(templateRe, (str, key) => {
|
|
62
|
+
let value = data[key];
|
|
63
|
+
if (value === void 0) throw new Error(`No value provided for variable ${str}`);
|
|
64
|
+
else if (typeof value === "function") value = value(data);
|
|
65
|
+
return value;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { Util_exports, falseFn, formatNum, lastId, setOptions, splitWords, stamp, template, throttle, wrapNum };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=Util.js.map
|