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,228 @@
|
|
|
1
|
+
import { stamp } from "../core/Util.js";
|
|
2
|
+
import { Point } from "../geometry/Point.js";
|
|
3
|
+
import { off, on } from "../dom/DomEvent.js";
|
|
4
|
+
import { create, setPosition } from "../dom/DomUtil.js";
|
|
5
|
+
import { Layer } from "./Layer.js";
|
|
6
|
+
import { FeatureGroup } from "./FeatureGroup.js";
|
|
7
|
+
import { DivOverlay } from "./DivOverlay.js";
|
|
8
|
+
//#region src/layer/Tooltip.js
|
|
9
|
+
var Tooltip = class Tooltip extends DivOverlay {
|
|
10
|
+
static {
|
|
11
|
+
this.setDefaultOptions({
|
|
12
|
+
pane: "tooltipPane",
|
|
13
|
+
offset: [0, 0],
|
|
14
|
+
direction: "auto",
|
|
15
|
+
permanent: false,
|
|
16
|
+
sticky: false,
|
|
17
|
+
opacity: .9
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
constructor(...args) {
|
|
21
|
+
super(...args);
|
|
22
|
+
this.callInitHooks(Tooltip);
|
|
23
|
+
}
|
|
24
|
+
onAdd(map) {
|
|
25
|
+
super.onAdd(map);
|
|
26
|
+
this.setOpacity(this.options.opacity);
|
|
27
|
+
map.fire("tooltipopen", { tooltip: this });
|
|
28
|
+
if (this._source) {
|
|
29
|
+
this.addEventParent(this._source);
|
|
30
|
+
this._source.fire("tooltipopen", { tooltip: this }, true);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
onRemove(map) {
|
|
34
|
+
super.onRemove(map);
|
|
35
|
+
map.fire("tooltipclose", { tooltip: this });
|
|
36
|
+
if (this._source) {
|
|
37
|
+
this.removeEventParent(this._source);
|
|
38
|
+
this._source.fire("tooltipclose", { tooltip: this }, true);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
getEvents() {
|
|
42
|
+
const events = super.getEvents();
|
|
43
|
+
if (!this.options.permanent) events.preclick = this.close;
|
|
44
|
+
return events;
|
|
45
|
+
}
|
|
46
|
+
_initLayout() {
|
|
47
|
+
const className = `maplair-tooltip ${this.options.className || ""} maplair-zoom-${this._zoomAnimated ? "animated" : "hide"}`;
|
|
48
|
+
this._contentNode = this._container = create("div", className);
|
|
49
|
+
this._container.setAttribute("role", "tooltip");
|
|
50
|
+
this._container.setAttribute("id", `maplair-tooltip-${stamp(this)}`);
|
|
51
|
+
}
|
|
52
|
+
_updateLayout() {}
|
|
53
|
+
_adjustPan() {}
|
|
54
|
+
_setPosition(pos) {
|
|
55
|
+
let subX, subY, direction = this.options.direction;
|
|
56
|
+
const map = this._map, container = this._container, centerPoint = map.latLngToContainerPoint(map.getCenter()), tooltipPoint = map.layerPointToContainerPoint(pos), tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset), anchor = this._getAnchor();
|
|
57
|
+
if (direction === "top") {
|
|
58
|
+
subX = tooltipWidth / 2;
|
|
59
|
+
subY = tooltipHeight;
|
|
60
|
+
} else if (direction === "bottom") {
|
|
61
|
+
subX = tooltipWidth / 2;
|
|
62
|
+
subY = 0;
|
|
63
|
+
} else if (direction === "center") {
|
|
64
|
+
subX = tooltipWidth / 2;
|
|
65
|
+
subY = tooltipHeight / 2;
|
|
66
|
+
} else if (direction === "right") {
|
|
67
|
+
subX = 0;
|
|
68
|
+
subY = tooltipHeight / 2;
|
|
69
|
+
} else if (direction === "left") {
|
|
70
|
+
subX = tooltipWidth;
|
|
71
|
+
subY = tooltipHeight / 2;
|
|
72
|
+
} else if (tooltipPoint.x < centerPoint.x) {
|
|
73
|
+
direction = "right";
|
|
74
|
+
subX = 0;
|
|
75
|
+
subY = tooltipHeight / 2;
|
|
76
|
+
} else {
|
|
77
|
+
direction = "left";
|
|
78
|
+
subX = tooltipWidth + (offset.x + anchor.x) * 2;
|
|
79
|
+
subY = tooltipHeight / 2;
|
|
80
|
+
}
|
|
81
|
+
pos = pos.subtract(new Point(subX, subY, true)).add(offset).add(anchor);
|
|
82
|
+
container.classList.remove("maplair-tooltip-right", "maplair-tooltip-left", "maplair-tooltip-top", "maplair-tooltip-bottom");
|
|
83
|
+
container.classList.add(`maplair-tooltip-${direction}`);
|
|
84
|
+
setPosition(container, pos);
|
|
85
|
+
}
|
|
86
|
+
_updatePosition() {
|
|
87
|
+
const pos = this._map.latLngToLayerPoint(this._latlng);
|
|
88
|
+
this._setPosition(pos);
|
|
89
|
+
}
|
|
90
|
+
setOpacity(opacity) {
|
|
91
|
+
this.options.opacity = opacity;
|
|
92
|
+
if (this._container) this._container.style.opacity = opacity;
|
|
93
|
+
}
|
|
94
|
+
_animateZoom(e) {
|
|
95
|
+
const pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);
|
|
96
|
+
this._setPosition(pos);
|
|
97
|
+
}
|
|
98
|
+
_getAnchor() {
|
|
99
|
+
return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]);
|
|
100
|
+
}
|
|
101
|
+
static register(MaplairMap) {
|
|
102
|
+
MaplairMap.include({
|
|
103
|
+
openTooltip(tooltip, latlng, options) {
|
|
104
|
+
this._initOverlay(Tooltip, tooltip, latlng, options).openOn(this);
|
|
105
|
+
return this;
|
|
106
|
+
},
|
|
107
|
+
closeTooltip(tooltip) {
|
|
108
|
+
tooltip.close();
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
Layer.include({
|
|
113
|
+
bindTooltip(content, options) {
|
|
114
|
+
if (this._tooltip && this.isTooltipOpen()) this.unbindTooltip();
|
|
115
|
+
this._tooltip = this._initOverlay(Tooltip, this._tooltip, content, options);
|
|
116
|
+
this._initTooltipInteractions();
|
|
117
|
+
if (this._tooltip.options.permanent && this._map && this._map.hasLayer(this)) this.openTooltip();
|
|
118
|
+
return this;
|
|
119
|
+
},
|
|
120
|
+
unbindTooltip() {
|
|
121
|
+
if (this._tooltip) {
|
|
122
|
+
this._initTooltipInteractions(true);
|
|
123
|
+
this.closeTooltip();
|
|
124
|
+
this._tooltip = null;
|
|
125
|
+
}
|
|
126
|
+
return this;
|
|
127
|
+
},
|
|
128
|
+
_initTooltipInteractions(remove) {
|
|
129
|
+
if (!remove && this._tooltipHandlersAdded) return;
|
|
130
|
+
const onOff = remove ? "off" : "on", events = {
|
|
131
|
+
remove: this.closeTooltip,
|
|
132
|
+
move: this._moveTooltip
|
|
133
|
+
};
|
|
134
|
+
if (!this._tooltip.options.permanent) {
|
|
135
|
+
events.pointerover = this._openTooltip;
|
|
136
|
+
events.pointerout = this.closeTooltip;
|
|
137
|
+
events.click = this._openTooltip;
|
|
138
|
+
if (this._map) this._addFocusListeners(remove);
|
|
139
|
+
else events.add = () => this._addFocusListeners(remove);
|
|
140
|
+
} else events.add = this._openTooltip;
|
|
141
|
+
if (this._tooltip.options.sticky) events.pointermove = this._moveTooltip;
|
|
142
|
+
this[onOff](events);
|
|
143
|
+
this._tooltipHandlersAdded = !remove;
|
|
144
|
+
},
|
|
145
|
+
openTooltip(latlng) {
|
|
146
|
+
if (this._tooltip) {
|
|
147
|
+
if (!(this instanceof FeatureGroup)) this._tooltip._source = this;
|
|
148
|
+
if (this._tooltip._prepareOpen(latlng)) {
|
|
149
|
+
this._tooltip.openOn(this._map);
|
|
150
|
+
if (this.getElement) this._setAriaDescribedByOnLayer(this);
|
|
151
|
+
else if (this.eachLayer) this.eachLayer(this._setAriaDescribedByOnLayer, this);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return this;
|
|
155
|
+
},
|
|
156
|
+
closeTooltip() {
|
|
157
|
+
if (this._tooltip) return this._tooltip.close();
|
|
158
|
+
},
|
|
159
|
+
toggleTooltip() {
|
|
160
|
+
this._tooltip?.toggle(this);
|
|
161
|
+
return this;
|
|
162
|
+
},
|
|
163
|
+
isTooltipOpen() {
|
|
164
|
+
return this._tooltip.isOpen();
|
|
165
|
+
},
|
|
166
|
+
setTooltipContent(content) {
|
|
167
|
+
this._tooltip?.setContent(content);
|
|
168
|
+
return this;
|
|
169
|
+
},
|
|
170
|
+
getTooltip() {
|
|
171
|
+
return this._tooltip;
|
|
172
|
+
},
|
|
173
|
+
_addFocusListeners(remove) {
|
|
174
|
+
if (this.getElement) this._addFocusListenersOnLayer(this, remove);
|
|
175
|
+
else if (this.eachLayer) this.eachLayer((layer) => this._addFocusListenersOnLayer(layer, remove), this);
|
|
176
|
+
},
|
|
177
|
+
_addFocusListenersOnLayer(layer, remove) {
|
|
178
|
+
const el = typeof layer.getElement === "function" && layer.getElement();
|
|
179
|
+
if (el) {
|
|
180
|
+
const toggle = remove ? off : on;
|
|
181
|
+
if (!remove) {
|
|
182
|
+
el._maplair_focus_handler && off(el, "focus", el._maplair_focus_handler, this);
|
|
183
|
+
el._maplair_focus_handler = () => {
|
|
184
|
+
if (this._tooltip) {
|
|
185
|
+
this._tooltip._source = layer;
|
|
186
|
+
this.openTooltip();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
el._maplair_focus_handler && toggle(el, "focus", el._maplair_focus_handler, this);
|
|
191
|
+
toggle(el, "blur", this.closeTooltip, this);
|
|
192
|
+
if (remove) delete el._maplair_focus_handler;
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
_setAriaDescribedByOnLayer(layer) {
|
|
196
|
+
(typeof layer.getElement === "function" && layer.getElement())?.setAttribute?.("aria-describedby", this._tooltip._container.id);
|
|
197
|
+
},
|
|
198
|
+
_openTooltip(e) {
|
|
199
|
+
if (!this._tooltip || !this._map) return;
|
|
200
|
+
if (this._map.dragging?.moving()) {
|
|
201
|
+
if (e.type === "add" && !this._moveEndOpensTooltip) {
|
|
202
|
+
this._moveEndOpensTooltip = true;
|
|
203
|
+
this._map.once("moveend", () => {
|
|
204
|
+
this._moveEndOpensTooltip = false;
|
|
205
|
+
this._openTooltip(e);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
this._tooltip._source = e.propagatedFrom ?? e.target;
|
|
211
|
+
this.openTooltip(this._tooltip.options.sticky ? e.latlng : void 0);
|
|
212
|
+
},
|
|
213
|
+
_moveTooltip(e) {
|
|
214
|
+
let latlng = e.latlng, containerPoint, layerPoint;
|
|
215
|
+
if (this._tooltip.options.sticky && e.originalEvent) {
|
|
216
|
+
containerPoint = this._map.pointerEventToContainerPoint(e.originalEvent);
|
|
217
|
+
layerPoint = this._map.containerPointToLayerPoint(containerPoint);
|
|
218
|
+
latlng = this._map.layerPointToLatLng(layerPoint);
|
|
219
|
+
}
|
|
220
|
+
this._tooltip.setLatLng(latlng);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
//#endregion
|
|
226
|
+
export { Tooltip };
|
|
227
|
+
|
|
228
|
+
//# sourceMappingURL=Tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tooltip.js","names":["DomUtil.create","Util.stamp","DomEvent.off","DomEvent.on"],"sources":["../../../src/layer/Tooltip.js"],"sourcesContent":["import {DivOverlay} from './DivOverlay.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as Util from '../core/Util.js';\nimport {FeatureGroup} from './FeatureGroup.js';\n\n/*\n * @class Tooltip\n * @inherits DivOverlay\n * Used to display small texts on top of map layers.\n *\n * @example\n * If you want to just bind a tooltip to marker:\n *\n * ```js\n * marker.bindTooltip(\"my tooltip text\").openTooltip();\n * ```\n * Path overlays like polylines also have a `bindTooltip` method.\n *\n * A tooltip can be also standalone:\n *\n * ```js\n * const tooltip = new Tooltip()\n * \t.setLatLng(latlng)\n * \t.setContent('Hello world!<br />This is a nice tooltip.')\n * \t.addTo(map);\n * ```\n * or\n * ```js\n * const tooltip = new Tooltip(latlng, {content: 'Hello world!<br />This is a nice tooltip.'})\n * \t.addTo(map);\n * ```\n *\n * **Security note.** Tooltip string content is rendered as HTML. If your content\n * may include untrusted input (e.g. data from users or external APIs), sanitize\n * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or\n * build a DOM element using `textContent` to render it as plain text:\n *\n * ```js\n * const el = document.createElement('div');\n * el.textContent = untrustedString;\n * marker.bindTooltip(el);\n * ```\n *\n * Note about tooltip offset. Maplair takes two options in consideration\n * for computing tooltip offsetting:\n * - the `offset` Tooltip option: it defaults to [0, 0], and it's specific to one tooltip.\n * Add a positive x offset to move the tooltip to the right, and a positive y offset to\n * move it to the bottom. Negatives will move to the left and top.\n * - the `tooltipAnchor` Icon option: this will only be considered for Marker. You\n * should adapt this value if you use a custom icon.\n */\n\n// @namespace Tooltip\n// @constructor Tooltip(options?: Tooltip options, source?: Layer)\n// Instantiates a `Tooltip` object given an optional `options` object that describes its appearance and location and an optional `source` object that is used to tag the tooltip with a reference to the Layer to which it refers.\n// @alternative\n// @constructor Tooltip(latlng: LatLng, options?: Tooltip options)\n// Instantiates a `Tooltip` object given `latlng` where the tooltip will open and an optional `options` object that describes its appearance and location.\nexport class Tooltip extends DivOverlay {\n\n\tstatic {\n\t\t// @section\n\t\t// @aka Tooltip options\n\t\tthis.setDefaultOptions({\n\t\t\t// @option pane: String = 'tooltipPane'\n\t\t\t// `Map pane` where the tooltip will be added.\n\t\t\tpane: 'tooltipPane',\n\n\t\t\t// @option offset: Point = Point(0, 0)\n\t\t\t// Optional offset of the tooltip position.\n\t\t\toffset: [0, 0],\n\n\t\t\t// @option direction: String = 'auto'\n\t\t\t// Direction where to open the tooltip. Possible values are: `right`, `left`,\n\t\t\t// `top`, `bottom`, `center`, `auto`.\n\t\t\t// `auto` will dynamically switch between `right` and `left` according to the tooltip\n\t\t\t// position on the map.\n\t\t\tdirection: 'auto',\n\n\t\t\t// @option permanent: Boolean = false\n\t\t\t// Whether to open the tooltip permanently or only on pointerover.\n\t\t\tpermanent: false,\n\n\t\t\t// @option sticky: Boolean = false\n\t\t\t// If true, the tooltip will follow the pointer instead of being fixed at the feature center.\n\t\t\tsticky: false,\n\n\t\t\t// @option opacity: Number = 0.9\n\t\t\t// Tooltip container opacity.\n\t\t\topacity: 0.9\n\t\t});\n\t}\n\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Tooltip);\n\t}\n\n\tonAdd(map) {\n\t\tsuper.onAdd(map);\n\t\tthis.setOpacity(this.options.opacity);\n\n\t\t// @namespace MaplairMap\n\t\t// @section Tooltip events\n\t\t// @event tooltipopen: TooltipEvent\n\t\t// Fired when a tooltip is opened in the map.\n\t\tmap.fire('tooltipopen', {tooltip: this});\n\n\t\tif (this._source) {\n\t\t\tthis.addEventParent(this._source);\n\n\t\t\t// @namespace Layer\n\t\t\t// @section Tooltip events\n\t\t\t// @event tooltipopen: TooltipEvent\n\t\t\t// Fired when a tooltip bound to this layer is opened.\n\t\t\tthis._source.fire('tooltipopen', {tooltip: this}, true);\n\t\t}\n\t}\n\n\tonRemove(map) {\n\t\tsuper.onRemove(map);\n\n\t\t// @namespace MaplairMap\n\t\t// @section Tooltip events\n\t\t// @event tooltipclose: TooltipEvent\n\t\t// Fired when a tooltip in the map is closed.\n\t\tmap.fire('tooltipclose', {tooltip: this});\n\n\t\tif (this._source) {\n\t\t\tthis.removeEventParent(this._source);\n\n\t\t\t// @namespace Layer\n\t\t\t// @section Tooltip events\n\t\t\t// @event tooltipclose: TooltipEvent\n\t\t\t// Fired when a tooltip bound to this layer is closed.\n\t\t\tthis._source.fire('tooltipclose', {tooltip: this}, true);\n\t\t}\n\t}\n\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\n\t\tif (!this.options.permanent) {\n\t\t\tevents.preclick = this.close;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t_initLayout() {\n\t\tconst prefix = 'maplair-tooltip',\n\t\tclassName = `${prefix} ${this.options.className || ''} maplair-zoom-${this._zoomAnimated ? 'animated' : 'hide'}`;\n\n\t\tthis._contentNode = this._container = DomUtil.create('div', className);\n\n\t\tthis._container.setAttribute('role', 'tooltip');\n\t\tthis._container.setAttribute('id', `maplair-tooltip-${Util.stamp(this)}`);\n\t}\n\n\t_updateLayout() {}\n\n\t_adjustPan() {}\n\n\t_setPosition(pos) {\n\t\tlet subX, subY, direction = this.options.direction;\n\t\tconst map = this._map,\n\t\tcontainer = this._container,\n\t\tcenterPoint = map.latLngToContainerPoint(map.getCenter()),\n\t\ttooltipPoint = map.layerPointToContainerPoint(pos),\n\t\ttooltipWidth = container.offsetWidth,\n\t\ttooltipHeight = container.offsetHeight,\n\t\toffset = new Point(this.options.offset),\n\t\tanchor = this._getAnchor();\n\n\t\tif (direction === 'top') {\n\t\t\tsubX = tooltipWidth / 2;\n\t\t\tsubY = tooltipHeight;\n\t\t} else if (direction === 'bottom') {\n\t\t\tsubX = tooltipWidth / 2;\n\t\t\tsubY = 0;\n\t\t} else if (direction === 'center') {\n\t\t\tsubX = tooltipWidth / 2;\n\t\t\tsubY = tooltipHeight / 2;\n\t\t} else if (direction === 'right') {\n\t\t\tsubX = 0;\n\t\t\tsubY = tooltipHeight / 2;\n\t\t} else if (direction === 'left') {\n\t\t\tsubX = tooltipWidth;\n\t\t\tsubY = tooltipHeight / 2;\n\t\t} else if (tooltipPoint.x < centerPoint.x) {\n\t\t\tdirection = 'right';\n\t\t\tsubX = 0;\n\t\t\tsubY = tooltipHeight / 2;\n\t\t} else {\n\t\t\tdirection = 'left';\n\t\t\tsubX = tooltipWidth + (offset.x + anchor.x) * 2;\n\t\t\tsubY = tooltipHeight / 2;\n\t\t}\n\n\t\tpos = pos.subtract(new Point(subX, subY, true)).add(offset).add(anchor);\n\n\t\tcontainer.classList.remove(\n\t\t\t'maplair-tooltip-right',\n\t\t\t'maplair-tooltip-left',\n\t\t\t'maplair-tooltip-top',\n\t\t\t'maplair-tooltip-bottom'\n\t\t);\n\t\tcontainer.classList.add(`maplair-tooltip-${direction}`);\n\t\tDomUtil.setPosition(container, pos);\n\t}\n\n\t_updatePosition() {\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng);\n\t\tthis._setPosition(pos);\n\t}\n\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\n\t\tif (this._container) {\n\t\t\tthis._container.style.opacity = opacity;\n\t\t}\n\t}\n\n\t_animateZoom(e) {\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);\n\t\tthis._setPosition(pos);\n\t}\n\n\t_getAnchor() {\n\t\t// Where should we anchor the tooltip on the source layer?\n\t\treturn new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]);\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 Methods for Layers and Controls\n\t\tMaplairMap.include({\n\n\t\t\t// @method openTooltip(tooltip: Tooltip): this\n\t\t\t// Opens the specified tooltip.\n\t\t\t// @alternative\n\t\t\t// @method openTooltip(content: String|HTMLElement, latlng: LatLng, options?: Tooltip options): this\n\t\t\t// Creates a tooltip with the specified content and options and open it.\n\t\t\t// String content is rendered as HTML; sanitize untrusted input or pass an `HTMLElement` with safe `textContent` instead.\n\t\t\topenTooltip(tooltip, latlng, options) {\n\t\t\t\tthis._initOverlay(Tooltip, tooltip, latlng, options)\n\t\t\t\t\t.openOn(this);\n\n\t\t\t\treturn this;\n\t\t\t},\n\n\t\t\t// @method closeTooltip(tooltip: Tooltip): this\n\t\t\t// Closes the tooltip given as parameter.\n\t\t\tcloseTooltip(tooltip) {\n\t\t\t\ttooltip.close();\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t});\n\n\t\t/*\n\t\t * @namespace Layer\n\t\t * @section Tooltip methods example\n\t\t *\n\t\t * All layers share a set of methods convenient for binding tooltips to it.\n\t\t *\n\t\t * ```js\n\t\t * const layer = new Polygon(latlngs).bindTooltip('Hi There!').addTo(map);\n\t\t * layer.openTooltip();\n\t\t * layer.closeTooltip();\n\t\t * ```\n\t\t */\n\n\t\t// @section Tooltip methods\n\t\tLayer.include({\n\n\t\t\t// @method bindTooltip(content: String|HTMLElement|Function|Tooltip, options?: Tooltip options): this\n\t\t\t// Binds a tooltip to the layer with the passed `content` and sets up the\n\t\t\t// necessary event listeners. A `String` argument is rendered as HTML; if it\n\t\t\t// may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an\n\t\t\t// `HTMLElement` with safe `textContent` instead. If a `Function` is passed\n\t\t\t// it will receive the layer as the first argument and should return a\n\t\t\t// `String` or `HTMLElement`.\n\t\t\tbindTooltip(content, options) {\n\n\t\t\t\tif (this._tooltip && this.isTooltipOpen()) {\n\t\t\t\t\tthis.unbindTooltip();\n\t\t\t\t}\n\n\t\t\t\tthis._tooltip = this._initOverlay(Tooltip, this._tooltip, content, options);\n\t\t\t\tthis._initTooltipInteractions();\n\n\t\t\t\tif (this._tooltip.options.permanent && this._map && this._map.hasLayer(this)) {\n\t\t\t\t\tthis.openTooltip();\n\t\t\t\t}\n\n\t\t\t\treturn this;\n\t\t\t},\n\n\t\t\t// @method unbindTooltip(): this\n\t\t\t// Removes the tooltip previously bound with `bindTooltip`.\n\t\t\tunbindTooltip() {\n\t\t\t\tif (this._tooltip) {\n\t\t\t\t\tthis._initTooltipInteractions(true);\n\t\t\t\t\tthis.closeTooltip();\n\t\t\t\t\tthis._tooltip = null;\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t},\n\n\t\t\t_initTooltipInteractions(remove) {\n\t\t\t\tif (!remove && this._tooltipHandlersAdded) { return; }\n\t\t\t\tconst onOff = remove ? 'off' : 'on',\n\t\t\t\tevents = {\n\t\t\t\t\tremove: this.closeTooltip,\n\t\t\t\t\tmove: this._moveTooltip\n\t\t\t\t};\n\t\t\t\tif (!this._tooltip.options.permanent) {\n\t\t\t\t\tevents.pointerover = this._openTooltip;\n\t\t\t\t\tevents.pointerout = this.closeTooltip;\n\t\t\t\t\tevents.click = this._openTooltip;\n\t\t\t\t\tif (this._map) {\n\t\t\t\t\t\tthis._addFocusListeners(remove);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tevents.add = () => this._addFocusListeners(remove);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tevents.add = this._openTooltip;\n\t\t\t\t}\n\t\t\t\tif (this._tooltip.options.sticky) {\n\t\t\t\t\tevents.pointermove = this._moveTooltip;\n\t\t\t\t}\n\t\t\t\tthis[onOff](events);\n\t\t\t\tthis._tooltipHandlersAdded = !remove;\n\t\t\t},\n\n\t\t\t// @method openTooltip(latlng?: LatLng): this\n\t\t\t// Opens the bound tooltip at the specified `latlng` or at the default tooltip anchor if no `latlng` is passed.\n\t\t\topenTooltip(latlng) {\n\t\t\t\tif (this._tooltip) {\n\t\t\t\t\tif (!(this instanceof FeatureGroup)) {\n\t\t\t\t\t\tthis._tooltip._source = this;\n\t\t\t\t\t}\n\t\t\t\t\tif (this._tooltip._prepareOpen(latlng)) {\n\t\t\t\t\t\t// open the tooltip on the map\n\t\t\t\t\t\tthis._tooltip.openOn(this._map);\n\n\t\t\t\t\t\tif (this.getElement) {\n\t\t\t\t\t\t\tthis._setAriaDescribedByOnLayer(this);\n\t\t\t\t\t\t} else if (this.eachLayer) {\n\t\t\t\t\t\t\tthis.eachLayer(this._setAriaDescribedByOnLayer, this);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t},\n\n\t\t\t// @method closeTooltip(): this\n\t\t\t// Closes the tooltip bound to this layer if it is open.\n\t\t\tcloseTooltip() {\n\t\t\t\tif (this._tooltip) {\n\t\t\t\t\treturn this._tooltip.close();\n\t\t\t\t}\n\t\t\t},\n\n\t\t\t// @method toggleTooltip(): this\n\t\t\t// Opens or closes the tooltip bound to this layer depending on its current state.\n\t\t\ttoggleTooltip() {\n\t\t\t\tthis._tooltip?.toggle(this);\n\t\t\t\treturn this;\n\t\t\t},\n\n\t\t\t// @method isTooltipOpen(): boolean\n\t\t\t// Returns `true` if the tooltip bound to this layer is currently open.\n\t\t\tisTooltipOpen() {\n\t\t\t\treturn this._tooltip.isOpen();\n\t\t\t},\n\n\t\t\t// @method setTooltipContent(content: String|HTMLElement|Tooltip): this\n\t\t\t// Sets the content of the tooltip bound to this layer.\n\t\t\t// String content is rendered as HTML; sanitize untrusted input or pass an `HTMLElement` with safe `textContent` instead.\n\t\t\tsetTooltipContent(content) {\n\t\t\t\tthis._tooltip?.setContent(content);\n\t\t\t\treturn this;\n\t\t\t},\n\n\t\t\t// @method getTooltip(): Tooltip\n\t\t\t// Returns the tooltip bound to this layer.\n\t\t\tgetTooltip() {\n\t\t\t\treturn this._tooltip;\n\t\t\t},\n\n\t\t\t_addFocusListeners(remove) {\n\t\t\t\tif (this.getElement) {\n\t\t\t\t\tthis._addFocusListenersOnLayer(this, remove);\n\t\t\t\t} else if (this.eachLayer) {\n\t\t\t\t\tthis.eachLayer(layer => this._addFocusListenersOnLayer(layer, remove), this);\n\t\t\t\t}\n\t\t\t},\n\n\t\t\t_addFocusListenersOnLayer(layer, remove) {\n\t\t\t\tconst el = typeof layer.getElement === 'function' && layer.getElement();\n\t\t\t\tif (el) {\n\t\t\t\t\tconst toggle = remove ? DomEvent.off : DomEvent.on;\n\t\t\t\t\tif (!remove) {\n\t\t\t\t\t\t// Remove focus listener, if already existing\n\t\t\t\t\t\tel._maplair_focus_handler && DomEvent.off(el, 'focus', el._maplair_focus_handler, this);\n\n\t\t\t\t\t\tel._maplair_focus_handler = () => {\n\t\t\t\t\t\t\tif (this._tooltip) {\n\t\t\t\t\t\t\t\tthis._tooltip._source = layer;\n\t\t\t\t\t\t\t\tthis.openTooltip();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tel._maplair_focus_handler && toggle(el, 'focus', el._maplair_focus_handler, this);\n\t\t\t\t\ttoggle(el, 'blur', this.closeTooltip, this);\n\n\t\t\t\t\tif (remove) {\n\t\t\t\t\t\tdelete el._maplair_focus_handler;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\n\t\t\t_setAriaDescribedByOnLayer(layer) {\n\t\t\t\tconst el = typeof layer.getElement === 'function' && layer.getElement();\n\t\t\t\tel?.setAttribute?.('aria-describedby', this._tooltip._container.id);\n\t\t\t},\n\n\t\t\t_openTooltip(e) {\n\t\t\t\tif (!this._tooltip || !this._map) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// If the map is moving, we will show the tooltip after it's done.\n\t\t\t\tif (this._map.dragging?.moving()) {\n\t\t\t\t\tif (e.type === 'add' && !this._moveEndOpensTooltip) {\n\t\t\t\t\t\tthis._moveEndOpensTooltip = true;\n\t\t\t\t\t\tthis._map.once('moveend', () => {\n\t\t\t\t\t\t\tthis._moveEndOpensTooltip = false;\n\t\t\t\t\t\t\tthis._openTooltip(e);\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis._tooltip._source = e.propagatedFrom ?? e.target;\n\n\t\t\t\tthis.openTooltip(this._tooltip.options.sticky ? e.latlng : undefined);\n\t\t\t},\n\n\t\t\t_moveTooltip(e) {\n\t\t\t\tlet latlng = e.latlng, containerPoint, layerPoint;\n\t\t\t\tif (this._tooltip.options.sticky && e.originalEvent) {\n\t\t\t\t\tcontainerPoint = this._map.pointerEventToContainerPoint(e.originalEvent);\n\t\t\t\t\tlayerPoint = this._map.containerPointToLayerPoint(containerPoint);\n\t\t\t\t\tlatlng = this._map.layerPointToLatLng(layerPoint);\n\t\t\t\t}\n\t\t\t\tthis._tooltip.setLatLng(latlng);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;AA6DA,IAAa,UAAb,MAAa,gBAAgB,WAAW;CAEvC;EAGC,KAAK,kBAAkB;GAGtB,MAAM;GAIN,QAAQ,CAAC,GAAG,CAAC;GAOb,WAAW;GAIX,WAAW;GAIX,QAAQ;GAIR,SAAS;EACV,CAAC;CACF;CAEA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,OAAO;CAC3B;CAEA,MAAM,KAAK;EACV,MAAM,MAAM,GAAG;EACf,KAAK,WAAW,KAAK,QAAQ,OAAO;EAMpC,IAAI,KAAK,eAAe,EAAC,SAAS,KAAI,CAAC;EAEvC,IAAI,KAAK,SAAS;GACjB,KAAK,eAAe,KAAK,OAAO;GAMhC,KAAK,QAAQ,KAAK,eAAe,EAAC,SAAS,KAAI,GAAG,IAAI;EACvD;CACD;CAEA,SAAS,KAAK;EACb,MAAM,SAAS,GAAG;EAMlB,IAAI,KAAK,gBAAgB,EAAC,SAAS,KAAI,CAAC;EAExC,IAAI,KAAK,SAAS;GACjB,KAAK,kBAAkB,KAAK,OAAO;GAMnC,KAAK,QAAQ,KAAK,gBAAgB,EAAC,SAAS,KAAI,GAAG,IAAI;EACxD;CACD;CAEA,YAAY;EACX,MAAM,SAAS,MAAM,UAAU;EAE/B,IAAI,CAAC,KAAK,QAAQ,WACjB,OAAO,WAAW,KAAK;EAGxB,OAAO;CACR;CAEA,cAAc;EACb,MACA,YAAY,mBAAa,KAAK,QAAQ,aAAa,GAAG,gBAAgB,KAAK,gBAAgB,aAAa;EAExG,K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import { create } from "../dom/DomUtil.js";
|
|
4
|
+
import { ImageOverlay } from "./ImageOverlay.js";
|
|
5
|
+
//#region src/layer/VideoOverlay.js
|
|
6
|
+
var VideoOverlay = class VideoOverlay extends ImageOverlay {
|
|
7
|
+
static {
|
|
8
|
+
this.setDefaultOptions({
|
|
9
|
+
autoplay: true,
|
|
10
|
+
controls: false,
|
|
11
|
+
loop: true,
|
|
12
|
+
keepAspectRatio: true,
|
|
13
|
+
muted: false,
|
|
14
|
+
playsInline: true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
constructor(...args) {
|
|
18
|
+
super(...args);
|
|
19
|
+
this.callInitHooks(VideoOverlay);
|
|
20
|
+
}
|
|
21
|
+
_initImage() {
|
|
22
|
+
const wasElementSupplied = this._url.tagName === "VIDEO";
|
|
23
|
+
const vid = this._image = wasElementSupplied ? this._url : create("video");
|
|
24
|
+
vid.classList.add("maplair-image-layer");
|
|
25
|
+
if (this._zoomAnimated) vid.classList.add("maplair-zoom-animated");
|
|
26
|
+
if (this.options.className) vid.classList.add(...splitWords(this.options.className));
|
|
27
|
+
on(vid, "pointerdown", (e) => {
|
|
28
|
+
if (vid.controls) stopPropagation(e);
|
|
29
|
+
});
|
|
30
|
+
vid.onloadeddata = this.fire.bind(this, "load");
|
|
31
|
+
if (wasElementSupplied) {
|
|
32
|
+
const sourceElements = vid.getElementsByTagName("source");
|
|
33
|
+
const sources = sourceElements.map((e) => e.src);
|
|
34
|
+
this._url = sourceElements.length > 0 ? sources : [vid.src];
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!Array.isArray(this._url)) this._url = [this._url];
|
|
38
|
+
if (!this.options.keepAspectRatio && Object.hasOwn(vid.style, "objectFit")) vid.style["objectFit"] = "fill";
|
|
39
|
+
vid.autoplay = !!this.options.autoplay;
|
|
40
|
+
vid.controls = !!this.options.controls;
|
|
41
|
+
vid.loop = !!this.options.loop;
|
|
42
|
+
vid.muted = !!this.options.muted;
|
|
43
|
+
vid.playsInline = !!this.options.playsInline;
|
|
44
|
+
for (const url of this._url) {
|
|
45
|
+
const source = create("source");
|
|
46
|
+
source.src = url;
|
|
47
|
+
vid.appendChild(source);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { VideoOverlay };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=VideoOverlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VideoOverlay.js","names":["DomUtil.create","Util.splitWords"],"sources":["../../../src/layer/VideoOverlay.js"],"sourcesContent":["import {ImageOverlay} from './ImageOverlay.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as Util from '../core/Util.js';\n\n/*\n * @class VideoOverlay\n * @inherits ImageOverlay\n *\n * Used to load and display a video player over specific bounds of the map. Extends `ImageOverlay`.\n *\n * A video overlay uses the [`<video>`](https://developer.mozilla.org/docs/Web/HTML/Element/video)\n * HTML element.\n *\n * @example\n *\n * ```js\n * const videoUrl = 'https://www.mapbox.com/bites/00188/patricia_nasa.webm',\n * \tvideoBounds = [[ 32, -130], [ 13, -100]];\n * new VideoOverlay(videoUrl, videoBounds ).addTo(map);\n * ```\n */\n\n// @constructor VideoOverlay(video: String|Array|HTMLVideoElement, bounds: LatLngBounds, options?: VideoOverlay options)\n// Instantiates an image overlay object given the URL of the video (or array of URLs, or even a video element) and the\n// geographical bounds it is tied to.\nexport class VideoOverlay extends ImageOverlay {\n\n\tstatic {\n\t\t// @section\n\t\t// @aka VideoOverlay options\n\t\tthis.setDefaultOptions({\n\t\t\t// @option autoplay: Boolean = true\n\t\t\t// Whether the video starts playing automatically when loaded.\n\t\t\t// On some browsers autoplay will only work with `muted: true`\n\t\t\tautoplay: true,\n\n\t\t\t// @option controls: Boolean = false\n\t\t\t// Whether the browser will offer controls to allow the user to control video playback, including volume, seeking, and pause/resume playback.\n\t\t\tcontrols: false,\n\n\t\t\t// @option loop: Boolean = true\n\t\t\t// Whether the video will loop back to the beginning when played.\n\t\t\tloop: true,\n\n\t\t\t// @option keepAspectRatio: Boolean = true\n\t\t\t// Whether the video will save aspect ratio after the projection.\n\t\t\tkeepAspectRatio: true,\n\n\t\t\t// @option muted: Boolean = false\n\t\t\t// Whether the video starts on mute when loaded.\n\t\t\tmuted: false,\n\n\t\t\t// @option playsInline: Boolean = true\n\t\t\t// Mobile browsers will play the video right where it is instead of open it up in fullscreen mode.\n\t\t\tplaysInline: true\n\t\t});\n\t}\n\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(VideoOverlay);\n\t}\n\n\t_initImage() {\n\t\tconst wasElementSupplied = this._url.tagName === 'VIDEO';\n\t\tconst vid = this._image = wasElementSupplied ? this._url : DomUtil.create('video');\n\n\t\tvid.classList.add('maplair-image-layer');\n\t\tif (this._zoomAnimated) { vid.classList.add('maplair-zoom-animated'); }\n\t\tif (this.options.className) { vid.classList.add(...Util.splitWords(this.options.className)); }\n\n\t\tDomEvent.on(vid, 'pointerdown', (e) => {\n\t\t\tif (vid.controls) {\n\t\t\t\t// Prevent the map from moving when the video or the seekbar is moved\n\t\t\t\tDomEvent.stopPropagation(e);\n\t\t\t}\n\t\t});\n\n\t\t// @event load: Event\n\t\t// Fired when the video has finished loading the first frame\n\t\tvid.onloadeddata = this.fire.bind(this, 'load');\n\n\t\tif (wasElementSupplied) {\n\t\t\tconst sourceElements = vid.getElementsByTagName('source');\n\t\t\tconst sources = sourceElements.map(e => e.src);\n\t\t\tthis._url = (sourceElements.length > 0) ? sources : [vid.src];\n\t\t\treturn;\n\t\t}\n\n\t\tif (!Array.isArray(this._url)) { this._url = [this._url]; }\n\n\t\tif (!this.options.keepAspectRatio && Object.hasOwn(vid.style, 'objectFit')) {\n\t\t\tvid.style['objectFit'] = 'fill';\n\t\t}\n\t\tvid.autoplay = !!this.options.autoplay;\n\t\tvid.controls = !!this.options.controls;\n\t\tvid.loop = !!this.options.loop;\n\t\tvid.muted = !!this.options.muted;\n\t\tvid.playsInline = !!this.options.playsInline;\n\t\tfor (const url of this._url) {\n\t\t\tconst source = DomUtil.create('source');\n\t\t\tsource.src = url;\n\t\t\tvid.appendChild(source);\n\t\t}\n\t}\n\n\t// @method getElement(): HTMLVideoElement\n\t// Returns the instance of [`HTMLVideoElement`](https://developer.mozilla.org/docs/Web/API/HTMLVideoElement)\n\t// used by this overlay.\n}\n"],"mappings":";;;;;AA0BA,IAAa,eAAb,MAAa,qBAAqB,aAAa;CAE9C;EAGC,KAAK,kBAAkB;GAItB,UAAU;GAIV,UAAU;GAIV,MAAM;GAIN,iBAAiB;GAIjB,OAAO;GAIP,aAAa;EACd,CAAC;CACF;CAEA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,YAAY;CAChC;CAEA,aAAa;EACZ,MAAM,qBAAqB,KAAK,KAAK,YAAY;EACjD,MAAM,MAAM,KAAK,SAAS,qBAAqB,KAAK,OAAOA,OAAe,OAAO;EAEjF,IAAI,UAAU,IAAI,qBAAqB;EACvC,IAAI,KAAK,eAAiB,IAAI,UAAU,IAAI,uBAAuB;EACnE,IAAI,KAAK,QAAQ,WAAa,IAAI,UAAU,IAAI,GAAGC,WAAgB,KAAK,QAAQ,SAAS,CAAC;EAE1F,GAAY,KAAK,gBAAgB,MAAM;GACtC,IAAI,IAAI,UAEP,gBAAyB,CAAC;EAE5B,CAAC;EAID,IAAI,eAAe,KAAK,KAAK,KAAK,MAAM,MAAM;EAE9C,IAAI,oBAAoB;GACvB,MAAM,iBAAiB,IAAI,qBAAqB,QAAQ;GACxD,MAAM,UAAU,eAAe,KAAI,MAAK,EAAE,GAAG;GAC7C,KAAK,OAAQ,eAAe,SAAS,IAAK,UAAU,CAAC,IAAI,GAAG;GAC5D;EACD;EAEA,IAAI,CAAC,MAAM,QAAQ,KAAK,IAAI,GAAK,KAAK,OAAO,CAAC,KAAK,IAAI;EAEvD,IAAI,CAAC,KAAK,QAAQ,mBAAmB,OAAO,OAAO,IAAI,OAAO,WAAW,GACxE,IAAI,MAAM,eAAe;EAE1B,IAAI,WAAW,CAAC,CAAC,KAAK,QAAQ;EAC9B,IAAI,WAAW,CAAC,CAAC,KAAK,QAAQ;EAC9B,IAAI,OAAO,CAAC,CAAC,KAAK,QAAQ;EAC1B,IAAI,QAAQ,CAAC,CAAC,KAAK,QAAQ;EAC3B,IAAI,cAAc,CAAC,CAAC,KAAK,QAAQ;EACjC,KAAK,MAAM,OAAO,KAAK,MAAM;GAC5B,MAAM,SAASD,OAAe,QAAQ;GACtC,OAAO,MAAM;GACb,IAAI,YAAY,MAAM;EACvB;CACD;AAKD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { create } from "../../dom/DomUtil.js";
|
|
2
|
+
import { Icon } from "./Icon.js";
|
|
3
|
+
//#region src/layer/marker/DefaultIcon.js
|
|
4
|
+
const URL_RE = /^url\((['"])?(.+)\1\)$/;
|
|
5
|
+
const MARKER_ICON_RE = /^(.*)marker-icon\.svg$/;
|
|
6
|
+
var DefaultIcon = class DefaultIcon extends Icon {
|
|
7
|
+
static {
|
|
8
|
+
this.setDefaultOptions({
|
|
9
|
+
iconUrl: "marker-icon.svg",
|
|
10
|
+
iconRetinaUrl: "marker-icon.svg",
|
|
11
|
+
shadowUrl: "marker-shadow.svg",
|
|
12
|
+
iconSize: [25, 41],
|
|
13
|
+
iconAnchor: [12, 41],
|
|
14
|
+
popupAnchor: [1, -34],
|
|
15
|
+
tooltipAnchor: [16, -28],
|
|
16
|
+
shadowSize: [41, 41]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
constructor(...args) {
|
|
20
|
+
super(...args);
|
|
21
|
+
this.callInitHooks(DefaultIcon);
|
|
22
|
+
}
|
|
23
|
+
_getIconUrl(name) {
|
|
24
|
+
if (!DefaultIcon.imagePath) DefaultIcon.imagePath = this._detectIconPath();
|
|
25
|
+
const url = super._getIconUrl(name);
|
|
26
|
+
if (!url) return null;
|
|
27
|
+
return (this.options.imagePath ?? DefaultIcon.imagePath) + url;
|
|
28
|
+
}
|
|
29
|
+
_stripUrl(path) {
|
|
30
|
+
const strip = function(str, re, idx) {
|
|
31
|
+
const match = re.exec(str);
|
|
32
|
+
return match && match[idx];
|
|
33
|
+
};
|
|
34
|
+
path = strip(path, URL_RE, 2);
|
|
35
|
+
return path && strip(path, MARKER_ICON_RE, 1);
|
|
36
|
+
}
|
|
37
|
+
_detectIconPath() {
|
|
38
|
+
const el = create("div", "maplair-default-icon-path", document.body);
|
|
39
|
+
const path = this._stripUrl(getComputedStyle(el).backgroundImage);
|
|
40
|
+
document.body.removeChild(el);
|
|
41
|
+
if (path) return path;
|
|
42
|
+
const link = document.querySelector("link[href$=\"maplair.css\"]");
|
|
43
|
+
if (!link) return "";
|
|
44
|
+
return link.href.substring(0, link.href.length - 11 - 1);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { DefaultIcon };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=DefaultIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultIcon.js","names":["DomUtil.create"],"sources":["../../../../src/layer/marker/DefaultIcon.js"],"sourcesContent":["import {Icon} from './Icon.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\n\nconst URL_RE = /^url\\((['\"])?(.+)\\1\\)$/;\nconst MARKER_ICON_RE = /^(.*)marker-icon\\.svg$/;\n\n/*\n * @miniclass DefaultIcon (Icon)\n * @section\n *\n * A trivial subclass of `Icon`, represents the icon to use in `Marker`s when\n * no icon is specified. Points to the blue marker image distributed with Maplair\n * releases.\n *\n * In order to customize the default icon, just change the properties of `DefaultIcon.prototype.options`\n * (which is a set of `Icon options`).\n *\n * If you want to _completely_ replace the default icon, override the\n * `Marker.prototype.options.icon` with your own icon instead.\n */\n\nexport class DefaultIcon extends Icon {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\ticonUrl: 'marker-icon.svg',\n\t\t\ticonRetinaUrl: 'marker-icon.svg',\n\t\t\tshadowUrl: 'marker-shadow.svg',\n\t\t\ticonSize: [25, 41],\n\t\t\ticonAnchor: [12, 41],\n\t\t\tpopupAnchor: [1, -34],\n\t\t\ttooltipAnchor: [16, -28],\n\t\t\tshadowSize: [41, 41]\n\t\t});\n\t}\n\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(DefaultIcon);\n\t}\n\n\t_getIconUrl(name) {\n\t\t// only detect once\n\t\tif (!DefaultIcon.imagePath) {\n\t\t\tDefaultIcon.imagePath = this._detectIconPath();\n\t\t}\n\n\t\tconst url = super._getIconUrl(name);\n\t\tif (!url) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// @option imagePath: String\n\t\t// `DefaultIcon` will try to auto-detect the location of the\n\t\t// blue icon images. If you are placing these images in a non-standard\n\t\t// way, set this option to point to the right path.\n\t\treturn (this.options.imagePath ?? DefaultIcon.imagePath) + url;\n\t}\n\n\t_stripUrl(path) {\t// separate function to use in tests\n\t\tconst strip = function (str, re, idx) {\n\t\t\tconst match = re.exec(str);\n\t\t\treturn match && match[idx];\n\t\t};\n\t\tpath = strip(path, URL_RE, 2);\n\t\treturn path && strip(path, MARKER_ICON_RE, 1);\n\t}\n\n\t_detectIconPath() {\n\t\tconst el = DomUtil.create('div', 'maplair-default-icon-path', document.body);\n\t\tconst path = this._stripUrl(getComputedStyle(el).backgroundImage);\n\n\t\tdocument.body.removeChild(el);\n\t\tif (path) { return path; }\n\t\tconst link = document.querySelector('link[href$=\"maplair.css\"]');\n\t\tif (!link) { return ''; }\n\t\treturn link.href.substring(0, link.href.length - 'maplair.css'.length - 1);\n\t}\n}\n"],"mappings":";;;AAGA,MAAM,SAAS;AACf,MAAM,iBAAiB;AAiBvB,IAAa,cAAb,MAAa,oBAAoB,KAAK;CAErC;EACC,KAAK,kBAAkB;GACtB,SAAS;GACT,eAAe;GACf,WAAW;GACX,UAAU,CAAC,IAAI,EAAE;GACjB,YAAY,CAAC,IAAI,EAAE;GACnB,aAAa,CAAC,GAAG,GAAG;GACpB,eAAe,CAAC,IAAI,GAAG;GACvB,YAAY,CAAC,IAAI,EAAE;EACpB,CAAC;CACF;CAEA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;CAEA,YAAY,MAAM;EAEjB,IAAI,CAAC,YAAY,WAChB,YAAY,YAAY,KAAK,gBAAgB;EAG9C,MAAM,MAAM,MAAM,YAAY,IAAI;EAClC,IAAI,CAAC,KACJ,OAAO;EAOR,QAAQ,KAAK,QAAQ,aAAa,YAAY,aAAa;CAC5D;CAEA,UAAU,MAAM;EACf,MAAM,QAAQ,SAAU,KAAK,IAAI,KAAK;GACrC,MAAM,QAAQ,GAAG,KAAK,GAAG;GACzB,OAAO,SAAS,MAAM;EACvB;EACA,OAAO,MAAM,MAAM,QAAQ,CAAC;EAC5B,OAAO,QAAQ,MAAM,MAAM,gBAAgB,CAAC;CAC7C;CAEA,kBAAkB;EACjB,MAAM,KAAKA,OAAe,OAAQ,6BAA6B,SAAS,IAAI;EAC5E,MAAM,OAAO,KAAK,UAAU,iBAAiB,EAAE,CAAC,CAAC,eAAe;EAEhE,SAAS,KAAK,YAAY,EAAE;EAC5B,IAAI,MAAQ,OAAO;EACnB,MAAM,OAAO,SAAS,cAAc,6BAA2B;EAC/D,IAAI,CAAC,MAAQ,OAAO;EACpB,OAAO,KAAK,KAAK,UAAU,GAAG,KAAK,KAAK,SAAS,KAAuB,CAAC;CAC1E;AACD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Point } from "../../geometry/Point.js";
|
|
2
|
+
import { Icon } from "./Icon.js";
|
|
3
|
+
//#region src/layer/marker/DivIcon.js
|
|
4
|
+
var DivIcon = class DivIcon extends Icon {
|
|
5
|
+
static {
|
|
6
|
+
this.setDefaultOptions({
|
|
7
|
+
iconSize: [12, 12],
|
|
8
|
+
html: false,
|
|
9
|
+
bgPos: null,
|
|
10
|
+
className: "maplair-div-icon"
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
constructor(...args) {
|
|
14
|
+
super(...args);
|
|
15
|
+
this.callInitHooks(DivIcon);
|
|
16
|
+
}
|
|
17
|
+
createIcon(oldIcon) {
|
|
18
|
+
const div = oldIcon && oldIcon.tagName === "DIV" ? oldIcon : document.createElement("div"), options = this.options;
|
|
19
|
+
if (options.html instanceof Element) {
|
|
20
|
+
div.replaceChildren();
|
|
21
|
+
div.appendChild(options.html);
|
|
22
|
+
} else div.innerHTML = options.html !== false ? options.html : "";
|
|
23
|
+
if (options.bgPos) {
|
|
24
|
+
const bgPos = new Point(options.bgPos);
|
|
25
|
+
div.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;
|
|
26
|
+
}
|
|
27
|
+
this._setIconStyles(div, "icon");
|
|
28
|
+
return div;
|
|
29
|
+
}
|
|
30
|
+
createShadow() {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { DivIcon };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=DivIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DivIcon.js","names":[],"sources":["../../../../src/layer/marker/DivIcon.js"],"sourcesContent":["import {Icon} from './Icon.js';\nimport {Point} from '../../geometry/Point.js';\n\n/*\n * @class DivIcon\n * @inherits Icon\n *\n * Represents a lightweight icon for markers that uses a simple `<div>`\n * element instead of an image. Inherits from `Icon` but ignores the `iconUrl` and shadow options.\n *\n * @example\n * ```js\n * const myIcon = new DivIcon({className: 'my-div-icon'});\n * // you can set .my-div-icon styles in CSS\n *\n * new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);\n * ```\n *\n * By default, it has a 'maplair-div-icon' CSS class and is styled as a little white square with a shadow.\n */\n\n// @constructor DivIcon(options: DivIcon options)\n// Creates a `DivIcon` instance with the given options.\nexport class DivIcon extends Icon {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\t// @section\n\t\t\t// @aka DivIcon options\n\t\t\ticonSize: [12, 12], // also can be set through CSS\n\n\t\t\t// iconAnchor: (Point),\n\t\t\t// popupAnchor: (Point),\n\n\t\t\t// @option html: String|HTMLElement = ''\n\t\t\t// Custom HTML code to put inside the div element, empty by default. Alternatively,\n\t\t\t// an instance of `HTMLElement`.\n\t\t\thtml: false,\n\n\t\t\t// @option bgPos: Point = [0, 0]\n\t\t\t// Optional relative position of the background, in pixels\n\t\t\tbgPos: null,\n\n\t\t\tclassName: 'maplair-div-icon'\n\t\t});\n\t}\n\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(DivIcon);\n\t}\n\n\tcreateIcon(oldIcon) {\n\t\tconst div = (oldIcon && oldIcon.tagName === 'DIV') ? oldIcon : document.createElement('div'),\n\t\toptions = this.options;\n\n\t\tif (options.html instanceof Element) {\n\t\t\tdiv.replaceChildren();\n\t\t\tdiv.appendChild(options.html);\n\t\t} else {\n\t\t\tdiv.innerHTML = options.html !== false ? options.html : '';\n\t\t}\n\n\t\tif (options.bgPos) {\n\t\t\tconst bgPos = new Point(options.bgPos);\n\t\t\tdiv.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;\n\t\t}\n\t\tthis._setIconStyles(div, 'icon');\n\n\t\treturn div;\n\t}\n\n\tcreateShadow() {\n\t\treturn null;\n\t}\n}\n"],"mappings":";;;AAuBA,IAAa,UAAb,MAAa,gBAAgB,KAAK;CAEjC;EACC,KAAK,kBAAkB;GAGtB,UAAU,CAAC,IAAI,EAAE;GAQjB,MAAM;GAIN,OAAO;GAEP,WAAW;EACZ,CAAC;CACF;CAEA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,OAAO;CAC3B;CAEA,WAAW,SAAS;EACnB,MAAM,MAAO,WAAW,QAAQ,YAAY,QAAS,UAAU,SAAS,cAAc,KAAK,GAC3F,UAAU,KAAK;EAEf,IAAI,QAAQ,gBAAgB,SAAS;GACpC,IAAI,gBAAgB;GACpB,IAAI,YAAY,QAAQ,IAAI;EAC7B,OACC,IAAI,YAAY,QAAQ,SAAS,QAAQ,QAAQ,OAAO;EAGzD,IAAI,QAAQ,OAAO;GAClB,MAAM,QAAQ,IAAI,MAAM,QAAQ,KAAK;GACrC,IAAI,MAAM,qBAAqB,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;EAC1D;EACA,KAAK,eAAe,KAAK,MAAM;EAE/B,OAAO;CACR;CAEA,eAAe;EACd,OAAO;CACR;AACD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { setOptions } from "../../core/Util.js";
|
|
2
|
+
import { Class } from "../../core/Class.js";
|
|
3
|
+
import { Point } from "../../geometry/Point.js";
|
|
4
|
+
import Browser_default from "../../core/Browser.js";
|
|
5
|
+
//#region src/layer/marker/Icon.js
|
|
6
|
+
var Icon = class Icon extends Class {
|
|
7
|
+
static {
|
|
8
|
+
this.setDefaultOptions({
|
|
9
|
+
popupAnchor: [0, 0],
|
|
10
|
+
tooltipAnchor: [0, 0],
|
|
11
|
+
crossOrigin: false
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super();
|
|
16
|
+
setOptions(this, options);
|
|
17
|
+
this.callInitHooks(Icon);
|
|
18
|
+
}
|
|
19
|
+
createIcon(oldIcon) {
|
|
20
|
+
return this._createIcon("icon", oldIcon);
|
|
21
|
+
}
|
|
22
|
+
createShadow(oldIcon) {
|
|
23
|
+
return this._createIcon("shadow", oldIcon);
|
|
24
|
+
}
|
|
25
|
+
_createIcon(name, oldIcon) {
|
|
26
|
+
const src = this._getIconUrl(name);
|
|
27
|
+
if (!src) {
|
|
28
|
+
if (name === "icon") throw new Error("iconUrl not set in Icon options (see the docs).");
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const img = this._createImg(src, oldIcon && oldIcon.tagName === "IMG" ? oldIcon : null);
|
|
32
|
+
this._setIconStyles(img, name);
|
|
33
|
+
if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
|
|
34
|
+
return img;
|
|
35
|
+
}
|
|
36
|
+
_setIconStyles(img, name) {
|
|
37
|
+
const options = this.options;
|
|
38
|
+
let sizeOption = options[`${name}Size`];
|
|
39
|
+
if (typeof sizeOption === "number") sizeOption = [sizeOption, sizeOption];
|
|
40
|
+
const size = Point.validate(sizeOption) && new Point(sizeOption);
|
|
41
|
+
const anchorPosition = name === "shadow" && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);
|
|
42
|
+
const anchor = Point.validate(anchorPosition) && new Point(anchorPosition);
|
|
43
|
+
img.className = `maplair-marker-${name} ${options.className || ""}`;
|
|
44
|
+
if (anchor) {
|
|
45
|
+
img.style.marginLeft = `${-anchor.x}px`;
|
|
46
|
+
img.style.marginTop = `${-anchor.y}px`;
|
|
47
|
+
}
|
|
48
|
+
if (size) {
|
|
49
|
+
img.style.width = `${size.x}px`;
|
|
50
|
+
img.style.height = `${size.y}px`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
_createImg(src, el) {
|
|
54
|
+
el ??= document.createElement("img");
|
|
55
|
+
el.src = src;
|
|
56
|
+
return el;
|
|
57
|
+
}
|
|
58
|
+
_getIconUrl(name) {
|
|
59
|
+
return Browser_default.retina && this.options[`${name}RetinaUrl`] || this.options[`${name}Url`];
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
export { Icon };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=Icon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.js","names":["Browser"],"sources":["../../../../src/layer/marker/Icon.js"],"sourcesContent":["import {Class} from '../../core/Class.js';\nimport {setOptions} from '../../core/Util.js';\nimport {Point} from '../../geometry/Point.js';\nimport Browser from '../../core/Browser.js';\n\n/*\n * @class Icon\n *\n * Represents an icon to provide when creating a marker.\n *\n * @example\n *\n * ```js\n * const myIcon = new Icon({\n * iconUrl: 'my-icon.png',\n * iconRetinaUrl: 'my-icon@2x.png',\n * iconSize: [38, 95],\n * iconAnchor: [22, 94],\n * popupAnchor: [-3, -76],\n * shadowUrl: 'my-icon-shadow.png',\n * shadowRetinaUrl: 'my-icon-shadow@2x.png',\n * shadowSize: [68, 95],\n * shadowAnchor: [22, 94]\n * });\n *\n * new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);\n * ```\n *\n * `DefaultIcon` extends `Icon` and is the blue icon Maplair uses for markers by default.\n *\n */\n\n// @constructor Icon(options: Icon options)\n// Creates an icon instance with the given options.\nexport class Icon extends Class {\n\n\tstatic {\n\t\t/* @section\n\t\t * @aka Icon options\n\t\t *\n\t\t * @option iconUrl: String = null\n\t\t * **(required)** The URL to the icon image (absolute or relative to your script path).\n\t\t *\n\t\t * @option iconRetinaUrl: String = null\n\t\t * The URL to a retina sized version of the icon image (absolute or relative to your\n\t\t * script path). Used for Retina screen devices.\n\t\t *\n\t\t * @option iconSize: Point = null\n\t\t * Size of the icon image in pixels.\n\t\t *\n\t\t * @option iconAnchor: Point = null\n\t\t * The coordinates of the \"tip\" of the icon (relative to its top left corner). The icon\n\t\t * will be aligned so that this point is at the marker's geographical location. Centered\n\t\t * by default if size is specified, also can be set in CSS with negative margins.\n\t\t *\n\t\t * @option popupAnchor: Point = [0, 0]\n\t\t * The coordinates of the point from which popups will \"open\", relative to the icon anchor.\n\t\t *\n\t\t * @option tooltipAnchor: Point = [0, 0]\n\t\t * The coordinates of the point from which tooltips will \"open\", relative to the icon anchor.\n\t\t *\n\t\t * @option shadowUrl: String = null\n\t\t * The URL to the icon shadow image. If not specified, no shadow image will be created.\n\t\t *\n\t\t * @option shadowRetinaUrl: String = null\n\t\t *\n\t\t * @option shadowSize: Point = null\n\t\t * Size of the shadow image in pixels.\n\t\t *\n\t\t * @option shadowAnchor: Point = null\n\t\t * The coordinates of the \"tip\" of the shadow (relative to its top left corner) (the same\n\t\t * as iconAnchor if not specified).\n\t\t *\n\t\t * @option className: String = ''\n\t\t * A custom class name to assign to both icon and shadow images. Empty by default.\n\t\t */\n\t\tthis.setDefaultOptions({\n\t\t\tpopupAnchor: [0, 0],\n\t\t\ttooltipAnchor: [0, 0],\n\n\t\t\t// @option crossOrigin: Boolean|String = false\n\t\t\t// Whether the crossOrigin attribute will be added to the tiles.\n\t\t\t// If a String is provided, all tiles will have their crossOrigin attribute set to the String provided. This is needed if you want to access tile pixel data.\n\t\t\t// Refer to [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) for valid String values.\n\t\t\tcrossOrigin: false\n\t\t});\n\t}\n\n\tconstructor(options) {\n\t\tsuper();\n\t\tsetOptions(this, options);\n\n\t\tthis.callInitHooks(Icon);\n\t}\n\n\t// @method createIcon(oldIcon?: HTMLElement): HTMLElement\n\t// Called internally when the icon has to be shown, returns a `<img>` HTML element\n\t// styled according to the options.\n\tcreateIcon(oldIcon) {\n\t\treturn this._createIcon('icon', oldIcon);\n\t}\n\n\t// @method createShadow(oldIcon?: HTMLElement): HTMLElement\n\t// As `createIcon`, but for the shadow beneath it.\n\tcreateShadow(oldIcon) {\n\t\treturn this._createIcon('shadow', oldIcon);\n\t}\n\n\t_createIcon(name, oldIcon) {\n\t\tconst src = this._getIconUrl(name);\n\n\t\tif (!src) {\n\t\t\tif (name === 'icon') {\n\t\t\t\tthrow new Error('iconUrl not set in Icon options (see the docs).');\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\n\t\tconst img = this._createImg(src, oldIcon && oldIcon.tagName === 'IMG' ? oldIcon : null);\n\t\tthis._setIconStyles(img, name);\n\n\t\tif (this.options.crossOrigin || this.options.crossOrigin === '') {\n\t\t\timg.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;\n\t\t}\n\n\t\treturn img;\n\t}\n\n\t_setIconStyles(img, name) {\n\t\tconst options = this.options;\n\t\tlet sizeOption = options[`${name}Size`];\n\n\t\tif (typeof sizeOption === 'number') {\n\t\t\tsizeOption = [sizeOption, sizeOption];\n\t\t}\n\n\t\tconst size = Point.validate(sizeOption) && new Point(sizeOption);\n\n\t\tconst anchorPosition = name === 'shadow' && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);\n\t\tconst anchor = Point.validate(anchorPosition) && new Point(anchorPosition);\n\n\t\timg.className = `maplair-marker-${name} ${options.className || ''}`;\n\n\t\tif (anchor) {\n\t\t\timg.style.marginLeft = `${-anchor.x}px`;\n\t\t\timg.style.marginTop = `${-anchor.y}px`;\n\t\t}\n\n\t\tif (size) {\n\t\t\timg.style.width = `${size.x}px`;\n\t\t\timg.style.height = `${size.y}px`;\n\t\t}\n\t}\n\n\t_createImg(src, el) {\n\t\tel ??= document.createElement('img');\n\t\tel.src = src;\n\t\treturn el;\n\t}\n\n\t_getIconUrl(name) {\n\t\treturn Browser.retina && this.options[`${name}RetinaUrl`] || this.options[`${name}Url`];\n\t}\n}\n"],"mappings":";;;;;AAkCA,IAAa,OAAb,MAAa,aAAa,MAAM;CAE/B;EAwCC,KAAK,kBAAkB;GACtB,aAAa,CAAC,GAAG,CAAC;GAClB,eAAe,CAAC,GAAG,CAAC;GAMpB,aAAa;EACd,CAAC;CACF;CAEA,YAAY,SAAS;EACpB,MAAM;EACN,WAAW,MAAM,OAAO;EAExB,KAAK,cAAc,IAAI;CACxB;CAKA,WAAW,SAAS;EACnB,OAAO,KAAK,YAAY,QAAQ,OAAO;CACxC;CAIA,aAAa,SAAS;EACrB,OAAO,KAAK,YAAY,UAAU,OAAO;CAC1C;CAEA,YAAY,MAAM,SAAS;EAC1B,MAAM,MAAM,KAAK,YAAY,IAAI;EAEjC,IAAI,CAAC,KAAK;GACT,IAAI,SAAS,QACZ,MAAM,IAAI,MAAM,iDAAiD;GAElE,OAAO;EACR;EAEA,MAAM,MAAM,KAAK,WAAW,KAAK,WAAW,QAAQ,YAAY,QAAQ,UAAU,IAAI;EACtF,KAAK,eAAe,KAAK,IAAI;EAE7B,IAAI,KAAK,QAAQ,eAAe,KAAK,QAAQ,gBAAgB,IAC5D,IAAI,cAAc,KAAK,QAAQ,gBAAgB,OAAO,KAAK,KAAK,QAAQ;EAGzE,OAAO;CACR;CAEA,eAAe,KAAK,MAAM;EACzB,MAAM,UAAU,KAAK;EACrB,IAAI,aAAa,QAAQ,GAAG,KAAK;EAEjC,IAAI,OAAO,eAAe,UACzB,aAAa,CAAC,YAAY,UAAU;EAGrC,MAAM,OAAO,MAAM,SAAS,UAAU,KAAK,IAAI,MAAM,UAAU;EAE/D,MAAM,iBAAiB,SAAS,YAAY,QAAQ,gBAAgB,QAAQ,cAAc,QAAQ,KAAK,SAAS,GAAG,IAAI;EACvH,MAAM,SAAS,MAAM,SAAS,cAAc,KAAK,IAAI,MAAM,cAAc;EAEzE,IAAI,YAAY,kBAAkB,KAAK,GAAG,QAAQ,aAAa;EAE/D,IAAI,QAAQ;GACX,IAAI,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE;GACpC,IAAI,MAAM,YAAa,GAAG,CAAC,OAAO,EAAE;EACrC;EAEA,IAAI,MAAM;GACT,IAAI,MAAM,QAAS,GAAG,KAAK,EAAE;GAC7B,IAAI,MAAM,SAAS,GAAG,KAAK,EAAE;EAC9B;CACD;CAEA,WAAW,KAAK,IAAI;EACnB,OAAO,SAAS,cAAc,KAAK;EACnC,GAAG,MAAM;EACT,OAAO;CACR;CAEA,YAAY,MAAM;EACjB,OAAOA,gBAAQ,UAAU,KAAK,QAAQ,GAAG,KAAK,eAAe,KAAK,QAAQ,GAAG,KAAK;CACnF;AACD"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Point } from "../../geometry/Point.js";
|
|
2
|
+
import { getPosition, setPosition } from "../../dom/DomUtil.js";
|
|
3
|
+
import { Handler } from "../../core/Handler.js";
|
|
4
|
+
import { Draggable } from "../../dom/Draggable.js";
|
|
5
|
+
import { Bounds } from "../../geometry/Bounds.js";
|
|
6
|
+
//#region src/layer/marker/Marker.Drag.js
|
|
7
|
+
var MarkerDrag = class MarkerDrag extends Handler {
|
|
8
|
+
constructor(marker) {
|
|
9
|
+
super(marker._map);
|
|
10
|
+
this._marker = marker;
|
|
11
|
+
this.callInitHooks(MarkerDrag);
|
|
12
|
+
}
|
|
13
|
+
addHooks() {
|
|
14
|
+
const icon = this._marker._icon;
|
|
15
|
+
if (!this._draggable) this._draggable = new Draggable(icon, icon, true);
|
|
16
|
+
this._draggable.on({
|
|
17
|
+
dragstart: this._onDragStart,
|
|
18
|
+
predrag: this._onPreDrag,
|
|
19
|
+
drag: this._onDrag,
|
|
20
|
+
dragend: this._onDragEnd
|
|
21
|
+
}, this).enable();
|
|
22
|
+
icon.classList.add("maplair-marker-draggable");
|
|
23
|
+
}
|
|
24
|
+
removeHooks() {
|
|
25
|
+
this._draggable.off({
|
|
26
|
+
dragstart: this._onDragStart,
|
|
27
|
+
predrag: this._onPreDrag,
|
|
28
|
+
drag: this._onDrag,
|
|
29
|
+
dragend: this._onDragEnd
|
|
30
|
+
}, this).disable();
|
|
31
|
+
this._marker._icon?.classList.remove("maplair-marker-draggable");
|
|
32
|
+
}
|
|
33
|
+
moved() {
|
|
34
|
+
return this._draggable?._moved;
|
|
35
|
+
}
|
|
36
|
+
_adjustPan(e) {
|
|
37
|
+
const marker = this._marker, map = marker._map, speed = this._marker.options.autoPanSpeed, padding = this._marker.options.autoPanPadding, iconPos = getPosition(marker._icon), bounds = map.getPixelBounds(), origin = map.getPixelOrigin();
|
|
38
|
+
const panBounds = new Bounds(bounds.min._subtract(origin).add(padding), bounds.max._subtract(origin).subtract(padding));
|
|
39
|
+
if (!panBounds.contains(iconPos)) {
|
|
40
|
+
const movement = new Point((Math.max(panBounds.max.x, iconPos.x) - panBounds.max.x) / (bounds.max.x - panBounds.max.x) - (Math.min(panBounds.min.x, iconPos.x) - panBounds.min.x) / (bounds.min.x - panBounds.min.x), (Math.max(panBounds.max.y, iconPos.y) - panBounds.max.y) / (bounds.max.y - panBounds.max.y) - (Math.min(panBounds.min.y, iconPos.y) - panBounds.min.y) / (bounds.min.y - panBounds.min.y)).multiplyBy(speed);
|
|
41
|
+
map.panBy(movement, { animate: false });
|
|
42
|
+
this._draggable._newPos._add(movement);
|
|
43
|
+
this._draggable._startPos._add(movement);
|
|
44
|
+
setPosition(marker._icon, this._draggable._newPos);
|
|
45
|
+
this._onDrag(e);
|
|
46
|
+
this._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
_onDragStart() {
|
|
50
|
+
this._oldLatLng = this._marker.getLatLng();
|
|
51
|
+
this._marker.closePopup?.();
|
|
52
|
+
this._marker.fire("movestart").fire("dragstart");
|
|
53
|
+
}
|
|
54
|
+
_onPreDrag(e) {
|
|
55
|
+
if (this._marker.options.autoPan) {
|
|
56
|
+
cancelAnimationFrame(this._panRequest);
|
|
57
|
+
this._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
_onDrag(e) {
|
|
61
|
+
const marker = this._marker, shadow = marker._shadow, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos);
|
|
62
|
+
if (shadow) setPosition(shadow, iconPos);
|
|
63
|
+
marker._latlng = latlng;
|
|
64
|
+
e.latlng = latlng;
|
|
65
|
+
e.oldLatLng = this._oldLatLng;
|
|
66
|
+
marker.fire("move", e).fire("drag", e);
|
|
67
|
+
}
|
|
68
|
+
_onDragEnd(e) {
|
|
69
|
+
cancelAnimationFrame(this._panRequest);
|
|
70
|
+
delete this._oldLatLng;
|
|
71
|
+
this._marker.fire("moveend").fire("dragend", e);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
export { MarkerDrag };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=Marker.Drag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Marker.Drag.js","names":["DomUtil.getPosition"],"sources":["../../../../src/layer/marker/Marker.Drag.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {Draggable} from '../../dom/Draggable.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/*\n * Handler.MarkerDrag is used internally by Marker to make the markers draggable.\n */\n\n\n/* @namespace Marker\n * @section Interaction handlers\n *\n * Interaction handlers are properties of a marker instance that allow you to control interaction behavior in runtime, enabling or disabling certain features such as dragging (see `Handler` methods). Example:\n *\n * ```js\n * marker.dragging.disable();\n * ```\n *\n * @property dragging: Handler\n * Marker dragging handler. Only valid when the marker is on the map (Otherwise set [`marker.options.draggable`](#marker-draggable)).\n */\n\nexport class MarkerDrag extends Handler {\n\tconstructor(marker) {\n\t\tsuper(marker._map);\n\t\tthis._marker = marker;\n\n\t\tthis.callInitHooks(MarkerDrag);\n\t}\n\n\taddHooks() {\n\t\tconst icon = this._marker._icon;\n\n\t\tif (!this._draggable) {\n\t\t\tthis._draggable = new Draggable(icon, icon, true);\n\t\t}\n\n\t\tthis._draggable.on({\n\t\t\tdragstart: this._onDragStart,\n\t\t\tpredrag: this._onPreDrag,\n\t\t\tdrag: this._onDrag,\n\t\t\tdragend: this._onDragEnd\n\t\t}, this).enable();\n\n\t\ticon.classList.add('maplair-marker-draggable');\n\t}\n\n\tremoveHooks() {\n\t\tthis._draggable.off({\n\t\t\tdragstart: this._onDragStart,\n\t\t\tpredrag: this._onPreDrag,\n\t\t\tdrag: this._onDrag,\n\t\t\tdragend: this._onDragEnd\n\t\t}, this).disable();\n\n\t\tthis._marker._icon?.classList.remove('maplair-marker-draggable');\n\t}\n\n\tmoved() {\n\t\treturn this._draggable?._moved;\n\t}\n\n\t_adjustPan(e) {\n\t\tconst marker = this._marker,\n\t\tmap = marker._map,\n\t\tspeed = this._marker.options.autoPanSpeed,\n\t\tpadding = this._marker.options.autoPanPadding,\n\t\ticonPos = DomUtil.getPosition(marker._icon),\n\t\tbounds = map.getPixelBounds(),\n\t\torigin = map.getPixelOrigin();\n\n\t\tconst panBounds = new Bounds(\n\t\t\tbounds.min._subtract(origin).add(padding),\n\t\t\tbounds.max._subtract(origin).subtract(padding)\n\t\t);\n\n\t\tif (!panBounds.contains(iconPos)) {\n\t\t\t// Compute incremental movement\n\t\t\tconst movement = new Point(\n\t\t\t\t(Math.max(panBounds.max.x, iconPos.x) - panBounds.max.x) / (bounds.max.x - panBounds.max.x) -\n\t\t\t\t(Math.min(panBounds.min.x, iconPos.x) - panBounds.min.x) / (bounds.min.x - panBounds.min.x),\n\n\t\t\t\t(Math.max(panBounds.max.y, iconPos.y) - panBounds.max.y) / (bounds.max.y - panBounds.max.y) -\n\t\t\t\t(Math.min(panBounds.min.y, iconPos.y) - panBounds.min.y) / (bounds.min.y - panBounds.min.y)\n\t\t\t).multiplyBy(speed);\n\n\t\t\tmap.panBy(movement, {animate: false});\n\n\t\t\tthis._draggable._newPos._add(movement);\n\t\t\tthis._draggable._startPos._add(movement);\n\n\t\t\tDomUtil.setPosition(marker._icon, this._draggable._newPos);\n\t\t\tthis._onDrag(e);\n\n\t\t\tthis._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));\n\t\t}\n\t}\n\n\t_onDragStart() {\n\t\t// @section Dragging events\n\t\t// @event dragstart: Event\n\t\t// Fired when the user starts dragging the marker.\n\n\t\t// @event movestart: Event\n\t\t// Fired when the marker starts moving (because of dragging).\n\n\t\tthis._oldLatLng = this._marker.getLatLng();\n\n\t\t// When using ES6 imports it could not be set when `Popup` was not imported as well\n\t\tthis._marker.closePopup?.();\n\n\t\tthis._marker\n\t\t\t.fire('movestart')\n\t\t\t.fire('dragstart');\n\t}\n\n\t_onPreDrag(e) {\n\t\tif (this._marker.options.autoPan) {\n\t\t\tcancelAnimationFrame(this._panRequest);\n\t\t\tthis._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));\n\t\t}\n\t}\n\n\t_onDrag(e) {\n\t\tconst marker = this._marker,\n\t\tshadow = marker._shadow,\n\t\ticonPos = DomUtil.getPosition(marker._icon),\n\t\tlatlng = marker._map.layerPointToLatLng(iconPos);\n\n\t\t// update shadow position\n\t\tif (shadow) {\n\t\t\tDomUtil.setPosition(shadow, iconPos);\n\t\t}\n\n\t\tmarker._latlng = latlng;\n\t\te.latlng = latlng;\n\t\te.oldLatLng = this._oldLatLng;\n\n\t\t// @event drag: Event\n\t\t// Fired repeatedly while the user drags the marker.\n\t\tmarker\n\t\t\t.fire('move', e)\n\t\t\t.fire('drag', e);\n\t}\n\n\t_onDragEnd(e) {\n\t\t// @event dragend: DragEndEvent\n\t\t// Fired when the user stops dragging the marker.\n\n\t\tcancelAnimationFrame(this._panRequest);\n\n\t\t// @event moveend: Event\n\t\t// Fired when the marker stops moving (because of dragging).\n\t\tdelete this._oldLatLng;\n\t\tthis._marker\n\t\t\t.fire('moveend')\n\t\t\t.fire('dragend', e);\n\t}\n}\n"],"mappings":";;;;;;AAwBA,IAAa,aAAb,MAAa,mBAAmB,QAAQ;CACvC,YAAY,QAAQ;EACnB,MAAM,OAAO,IAAI;EACjB,KAAK,UAAU;EAEf,KAAK,cAAc,UAAU;CAC9B;CAEA,WAAW;EACV,MAAM,OAAO,KAAK,QAAQ;EAE1B,IAAI,CAAC,KAAK,YACT,KAAK,aAAa,IAAI,UAAU,MAAM,MAAM,IAAI;EAGjD,KAAK,WAAW,GAAG;GAClB,WAAW,KAAK;GAChB,SAAS,KAAK;GACd,MAAM,KAAK;GACX,SAAS,KAAK;EACf,GAAG,IAAI,CAAC,CAAC,OAAO;EAEhB,KAAK,UAAU,IAAI,0BAA0B;CAC9C;CAEA,cAAc;EACb,KAAK,WAAW,IAAI;GACnB,WAAW,KAAK;GAChB,SAAS,KAAK;GACd,MAAM,KAAK;GACX,SAAS,KAAK;EACf,G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