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.
Files changed (262) hide show
  1. package/CHANGELOG.md +2804 -0
  2. package/LICENSE +27 -0
  3. package/README.md +40 -0
  4. package/dist/esm/Maplair.js +71 -0
  5. package/dist/esm/Maplair.js.map +1 -0
  6. package/dist/esm/_virtual/_rolldown/runtime.js +13 -0
  7. package/dist/esm/control/AttributionControl.js +79 -0
  8. package/dist/esm/control/AttributionControl.js.map +1 -0
  9. package/dist/esm/control/Control.js +81 -0
  10. package/dist/esm/control/Control.js.map +1 -0
  11. package/dist/esm/control/LayersControl.js +220 -0
  12. package/dist/esm/control/LayersControl.js.map +1 -0
  13. package/dist/esm/control/ScaleControl.js +72 -0
  14. package/dist/esm/control/ScaleControl.js.map +1 -0
  15. package/dist/esm/control/ZoomControl.js +86 -0
  16. package/dist/esm/control/ZoomControl.js.map +1 -0
  17. package/dist/esm/core/Browser.js +31 -0
  18. package/dist/esm/core/Browser.js.map +1 -0
  19. package/dist/esm/core/Class.js +52 -0
  20. package/dist/esm/core/Class.js.map +1 -0
  21. package/dist/esm/core/Events.js +149 -0
  22. package/dist/esm/core/Events.js.map +1 -0
  23. package/dist/esm/core/Handler.js +32 -0
  24. package/dist/esm/core/Handler.js.map +1 -0
  25. package/dist/esm/core/I18n.js +36 -0
  26. package/dist/esm/core/I18n.js.map +1 -0
  27. package/dist/esm/core/Util.js +71 -0
  28. package/dist/esm/core/Util.js.map +1 -0
  29. package/dist/esm/dom/DomEvent.DoubleTap.js +74 -0
  30. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -0
  31. package/dist/esm/dom/DomEvent.PointerEvents.js +46 -0
  32. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -0
  33. package/dist/esm/dom/DomEvent.js +135 -0
  34. package/dist/esm/dom/DomEvent.js.map +1 -0
  35. package/dist/esm/dom/DomUtil.js +107 -0
  36. package/dist/esm/dom/DomUtil.js.map +1 -0
  37. package/dist/esm/dom/Draggable.js +107 -0
  38. package/dist/esm/dom/Draggable.js.map +1 -0
  39. package/dist/esm/dom/PosAnimation.js +56 -0
  40. package/dist/esm/dom/PosAnimation.js.map +1 -0
  41. package/dist/esm/geo/LatLng.js +65 -0
  42. package/dist/esm/geo/LatLng.js.map +1 -0
  43. package/dist/esm/geo/LatLngBounds.js +114 -0
  44. package/dist/esm/geo/LatLngBounds.js.map +1 -0
  45. package/dist/esm/geo/crs/CRS.js +51 -0
  46. package/dist/esm/geo/crs/CRS.js.map +1 -0
  47. package/dist/esm/geo/crs/EPSG3395.js +16 -0
  48. package/dist/esm/geo/crs/EPSG3395.js.map +1 -0
  49. package/dist/esm/geo/crs/EPSG3857.js +19 -0
  50. package/dist/esm/geo/crs/EPSG3857.js.map +1 -0
  51. package/dist/esm/geo/crs/EPSG4326.js +13 -0
  52. package/dist/esm/geo/crs/EPSG4326.js.map +1 -0
  53. package/dist/esm/geo/crs/EarthCRS.js +14 -0
  54. package/dist/esm/geo/crs/EarthCRS.js.map +1 -0
  55. package/dist/esm/geo/crs/SimpleCRS.js +23 -0
  56. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -0
  57. package/dist/esm/geo/projection/Projection.LonLat.js +19 -0
  58. package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -0
  59. package/dist/esm/geo/projection/Projection.Mercator.js +33 -0
  60. package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -0
  61. package/dist/esm/geo/projection/Projection.SphericalMercator.js +27 -0
  62. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -0
  63. package/dist/esm/geo/projection/index.js +14 -0
  64. package/dist/esm/geo/projection/index.js.map +1 -0
  65. package/dist/esm/geometry/Bounds.js +91 -0
  66. package/dist/esm/geometry/Bounds.js.map +1 -0
  67. package/dist/esm/geometry/LineUtil.js +169 -0
  68. package/dist/esm/geometry/LineUtil.js.map +1 -0
  69. package/dist/esm/geometry/Point.js +119 -0
  70. package/dist/esm/geometry/Point.js.map +1 -0
  71. package/dist/esm/geometry/PolyUtil.js +89 -0
  72. package/dist/esm/geometry/PolyUtil.js.map +1 -0
  73. package/dist/esm/geometry/Transformation.js +34 -0
  74. package/dist/esm/geometry/Transformation.js.map +1 -0
  75. package/dist/esm/layer/BlanketOverlay.js +87 -0
  76. package/dist/esm/layer/BlanketOverlay.js.map +1 -0
  77. package/dist/esm/layer/DivOverlay.js +192 -0
  78. package/dist/esm/layer/DivOverlay.js.map +1 -0
  79. package/dist/esm/layer/FeatureGroup.js +40 -0
  80. package/dist/esm/layer/FeatureGroup.js.map +1 -0
  81. package/dist/esm/layer/GeoJSON.js +192 -0
  82. package/dist/esm/layer/GeoJSON.js.map +1 -0
  83. package/dist/esm/layer/ImageOverlay.js +140 -0
  84. package/dist/esm/layer/ImageOverlay.js.map +1 -0
  85. package/dist/esm/layer/Layer.js +119 -0
  86. package/dist/esm/layer/Layer.js.map +1 -0
  87. package/dist/esm/layer/LayerGroup.js +58 -0
  88. package/dist/esm/layer/LayerGroup.js.map +1 -0
  89. package/dist/esm/layer/Popup.js +224 -0
  90. package/dist/esm/layer/Popup.js.map +1 -0
  91. package/dist/esm/layer/SVGOverlay.js +21 -0
  92. package/dist/esm/layer/SVGOverlay.js.map +1 -0
  93. package/dist/esm/layer/Tooltip.js +228 -0
  94. package/dist/esm/layer/Tooltip.js.map +1 -0
  95. package/dist/esm/layer/VideoOverlay.js +54 -0
  96. package/dist/esm/layer/VideoOverlay.js.map +1 -0
  97. package/dist/esm/layer/marker/DefaultIcon.js +50 -0
  98. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -0
  99. package/dist/esm/layer/marker/DivIcon.js +37 -0
  100. package/dist/esm/layer/marker/DivIcon.js.map +1 -0
  101. package/dist/esm/layer/marker/Icon.js +65 -0
  102. package/dist/esm/layer/marker/Icon.js.map +1 -0
  103. package/dist/esm/layer/marker/Marker.Drag.js +77 -0
  104. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -0
  105. package/dist/esm/layer/marker/Marker.js +235 -0
  106. package/dist/esm/layer/marker/Marker.js.map +1 -0
  107. package/dist/esm/layer/tile/GridLayer.js +447 -0
  108. package/dist/esm/layer/tile/GridLayer.js.map +1 -0
  109. package/dist/esm/layer/tile/TileLayer.js +139 -0
  110. package/dist/esm/layer/tile/TileLayer.js.map +1 -0
  111. package/dist/esm/layer/tile/WMSTileLayer.js +68 -0
  112. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -0
  113. package/dist/esm/layer/vector/Canvas.js +292 -0
  114. package/dist/esm/layer/vector/Canvas.js.map +1 -0
  115. package/dist/esm/layer/vector/Circle.js +35 -0
  116. package/dist/esm/layer/vector/Circle.js.map +1 -0
  117. package/dist/esm/layer/vector/CircleMarker.js +69 -0
  118. package/dist/esm/layer/vector/CircleMarker.js.map +1 -0
  119. package/dist/esm/layer/vector/Path.js +68 -0
  120. package/dist/esm/layer/vector/Path.js.map +1 -0
  121. package/dist/esm/layer/vector/Polygon.js +70 -0
  122. package/dist/esm/layer/vector/Polygon.js.map +1 -0
  123. package/dist/esm/layer/vector/Polyline.js +152 -0
  124. package/dist/esm/layer/vector/Polyline.js.map +1 -0
  125. package/dist/esm/layer/vector/Rectangle.js +25 -0
  126. package/dist/esm/layer/vector/Rectangle.js.map +1 -0
  127. package/dist/esm/layer/vector/Renderer.getRenderer.js +31 -0
  128. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -0
  129. package/dist/esm/layer/vector/Renderer.js +39 -0
  130. package/dist/esm/layer/vector/Renderer.js.map +1 -0
  131. package/dist/esm/layer/vector/SVG.js +115 -0
  132. package/dist/esm/layer/vector/SVG.js.map +1 -0
  133. package/dist/esm/map/Map.js +844 -0
  134. package/dist/esm/map/Map.js.map +1 -0
  135. package/dist/esm/map/handler/BoxZoomHandler.js +105 -0
  136. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -0
  137. package/dist/esm/map/handler/DoubleClickZoomHandler.js +27 -0
  138. package/dist/esm/map/handler/DoubleClickZoomHandler.js.map +1 -0
  139. package/dist/esm/map/handler/DragHandler.js +133 -0
  140. package/dist/esm/map/handler/DragHandler.js.map +1 -0
  141. package/dist/esm/map/handler/KeyboardHandler.js +117 -0
  142. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -0
  143. package/dist/esm/map/handler/PinchZoomHandler.js +96 -0
  144. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -0
  145. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +50 -0
  146. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -0
  147. package/dist/esm/map/handler/TapHoldHandler.js +77 -0
  148. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -0
  149. package/dist/esm/package.js +6 -0
  150. package/dist/esm/package.js.map +1 -0
  151. package/dist/images/layers.svg +1 -0
  152. package/dist/images/logo.svg +1 -0
  153. package/dist/images/marker-icon.svg +1 -0
  154. package/dist/images/marker-shadow.svg +1 -0
  155. package/dist/maplair-global-src.js +6810 -0
  156. package/dist/maplair-global-src.js.map +1 -0
  157. package/dist/maplair-global.js +12 -0
  158. package/dist/maplair-global.js.map +1 -0
  159. package/dist/maplair-src.js +6704 -0
  160. package/dist/maplair-src.js.map +1 -0
  161. package/dist/maplair.css +730 -0
  162. package/dist/maplair.js +7 -0
  163. package/dist/maplair.js.map +1 -0
  164. package/i18n/cs.json +12 -0
  165. package/i18n/de.json +12 -0
  166. package/i18n/en.json +12 -0
  167. package/i18n/es.json +12 -0
  168. package/i18n/fr.json +12 -0
  169. package/i18n/hu.json +12 -0
  170. package/i18n/it.json +12 -0
  171. package/i18n/rm.json +12 -0
  172. package/i18n/sk.json +12 -0
  173. package/i18n/sl.json +12 -0
  174. package/package.json +87 -0
  175. package/src/Maplair.js +24 -0
  176. package/src/control/AttributionControl.js +147 -0
  177. package/src/control/Control.js +174 -0
  178. package/src/control/LayersControl.js +444 -0
  179. package/src/control/ScaleControl.js +141 -0
  180. package/src/control/ZoomControl.js +147 -0
  181. package/src/control/index.js +5 -0
  182. package/src/core/Browser.js +75 -0
  183. package/src/core/Class.js +97 -0
  184. package/src/core/Events.js +334 -0
  185. package/src/core/Handler.js +59 -0
  186. package/src/core/I18n.js +76 -0
  187. package/src/core/Util.js +122 -0
  188. package/src/core/index.js +8 -0
  189. package/src/dom/DomEvent.DoubleTap.js +120 -0
  190. package/src/dom/DomEvent.PointerEvents.js +75 -0
  191. package/src/dom/DomEvent.js +282 -0
  192. package/src/dom/DomUtil.js +175 -0
  193. package/src/dom/Draggable.js +204 -0
  194. package/src/dom/PosAnimation.js +115 -0
  195. package/src/dom/index.js +9 -0
  196. package/src/geo/LatLng.js +163 -0
  197. package/src/geo/LatLngBounds.js +260 -0
  198. package/src/geo/crs/CRS.js +143 -0
  199. package/src/geo/crs/EPSG3395.js +19 -0
  200. package/src/geo/crs/EPSG3857.js +26 -0
  201. package/src/geo/crs/EPSG4326.js +21 -0
  202. package/src/geo/crs/EarthCRS.js +32 -0
  203. package/src/geo/crs/SimpleCRS.js +35 -0
  204. package/src/geo/crs/index.js +6 -0
  205. package/src/geo/index.js +7 -0
  206. package/src/geo/projection/Projection.LonLat.js +30 -0
  207. package/src/geo/projection/Projection.Mercator.js +53 -0
  208. package/src/geo/projection/Projection.SphericalMercator.js +46 -0
  209. package/src/geo/projection/index.js +26 -0
  210. package/src/geometry/Bounds.js +222 -0
  211. package/src/geometry/LineUtil.js +299 -0
  212. package/src/geometry/Point.js +239 -0
  213. package/src/geometry/PolyUtil.js +129 -0
  214. package/src/geometry/Transformation.js +67 -0
  215. package/src/geometry/index.js +8 -0
  216. package/src/images/layers.svg +1 -0
  217. package/src/images/logo.svg +1 -0
  218. package/src/images/marker-icon.svg +1 -0
  219. package/src/images/marker-shadow.svg +1 -0
  220. package/src/layer/BlanketOverlay.js +171 -0
  221. package/src/layer/DivOverlay.js +353 -0
  222. package/src/layer/FeatureGroup.js +93 -0
  223. package/src/layer/GeoJSON.js +432 -0
  224. package/src/layer/ImageOverlay.js +279 -0
  225. package/src/layer/Layer.js +273 -0
  226. package/src/layer/LayerGroup.js +129 -0
  227. package/src/layer/Popup.js +528 -0
  228. package/src/layer/SVGOverlay.js +47 -0
  229. package/src/layer/Tooltip.js +469 -0
  230. package/src/layer/VideoOverlay.js +111 -0
  231. package/src/layer/index.js +18 -0
  232. package/src/layer/marker/DefaultIcon.js +79 -0
  233. package/src/layer/marker/DivIcon.js +76 -0
  234. package/src/layer/marker/Icon.js +164 -0
  235. package/src/layer/marker/Marker.Drag.js +161 -0
  236. package/src/layer/marker/Marker.js +465 -0
  237. package/src/layer/marker/index.js +5 -0
  238. package/src/layer/tile/GridLayer.js +901 -0
  239. package/src/layer/tile/TileLayer.js +299 -0
  240. package/src/layer/tile/WMSTileLayer.js +133 -0
  241. package/src/layer/tile/index.js +3 -0
  242. package/src/layer/vector/Canvas.js +479 -0
  243. package/src/layer/vector/Circle.js +87 -0
  244. package/src/layer/vector/CircleMarker.js +110 -0
  245. package/src/layer/vector/Path.js +145 -0
  246. package/src/layer/vector/Polygon.js +160 -0
  247. package/src/layer/vector/Polyline.js +296 -0
  248. package/src/layer/vector/Rectangle.js +52 -0
  249. package/src/layer/vector/Renderer.getRenderer.js +48 -0
  250. package/src/layer/vector/Renderer.js +75 -0
  251. package/src/layer/vector/SVG.js +216 -0
  252. package/src/layer/vector/index.js +10 -0
  253. package/src/map/Map.js +1830 -0
  254. package/src/map/handler/BoxZoomHandler.js +156 -0
  255. package/src/map/handler/DoubleClickZoomHandler.js +62 -0
  256. package/src/map/handler/DragHandler.js +240 -0
  257. package/src/map/handler/KeyboardHandler.js +188 -0
  258. package/src/map/handler/PinchZoomHandler.js +157 -0
  259. package/src/map/handler/ScrollWheelZoomHandler.js +98 -0
  260. package/src/map/handler/TapHoldHandler.js +111 -0
  261. package/src/map/index.js +8 -0
  262. package/src/maplair.css +730 -0
@@ -0,0 +1,469 @@
1
+ import {DivOverlay} from './DivOverlay.js';
2
+ import {Point} from '../geometry/Point.js';
3
+ import {Layer} from './Layer.js';
4
+ import * as DomUtil from '../dom/DomUtil.js';
5
+ import * as DomEvent from '../dom/DomEvent.js';
6
+ import * as Util from '../core/Util.js';
7
+ import {FeatureGroup} from './FeatureGroup.js';
8
+
9
+ /*
10
+ * @class Tooltip
11
+ * @inherits DivOverlay
12
+ * Used to display small texts on top of map layers.
13
+ *
14
+ * @example
15
+ * If you want to just bind a tooltip to marker:
16
+ *
17
+ * ```js
18
+ * marker.bindTooltip("my tooltip text").openTooltip();
19
+ * ```
20
+ * Path overlays like polylines also have a `bindTooltip` method.
21
+ *
22
+ * A tooltip can be also standalone:
23
+ *
24
+ * ```js
25
+ * const tooltip = new Tooltip()
26
+ * .setLatLng(latlng)
27
+ * .setContent('Hello world!<br />This is a nice tooltip.')
28
+ * .addTo(map);
29
+ * ```
30
+ * or
31
+ * ```js
32
+ * const tooltip = new Tooltip(latlng, {content: 'Hello world!<br />This is a nice tooltip.'})
33
+ * .addTo(map);
34
+ * ```
35
+ *
36
+ * **Security note.** Tooltip string content is rendered as HTML. If your content
37
+ * may include untrusted input (e.g. data from users or external APIs), sanitize
38
+ * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or
39
+ * build a DOM element using `textContent` to render it as plain text:
40
+ *
41
+ * ```js
42
+ * const el = document.createElement('div');
43
+ * el.textContent = untrustedString;
44
+ * marker.bindTooltip(el);
45
+ * ```
46
+ *
47
+ * Note about tooltip offset. Maplair takes two options in consideration
48
+ * for computing tooltip offsetting:
49
+ * - the `offset` Tooltip option: it defaults to [0, 0], and it's specific to one tooltip.
50
+ * Add a positive x offset to move the tooltip to the right, and a positive y offset to
51
+ * move it to the bottom. Negatives will move to the left and top.
52
+ * - the `tooltipAnchor` Icon option: this will only be considered for Marker. You
53
+ * should adapt this value if you use a custom icon.
54
+ */
55
+
56
+ // @namespace Tooltip
57
+ // @constructor Tooltip(options?: Tooltip options, source?: Layer)
58
+ // 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.
59
+ // @alternative
60
+ // @constructor Tooltip(latlng: LatLng, options?: Tooltip options)
61
+ // Instantiates a `Tooltip` object given `latlng` where the tooltip will open and an optional `options` object that describes its appearance and location.
62
+ export class Tooltip extends DivOverlay {
63
+
64
+ static {
65
+ // @section
66
+ // @aka Tooltip options
67
+ this.setDefaultOptions({
68
+ // @option pane: String = 'tooltipPane'
69
+ // `Map pane` where the tooltip will be added.
70
+ pane: 'tooltipPane',
71
+
72
+ // @option offset: Point = Point(0, 0)
73
+ // Optional offset of the tooltip position.
74
+ offset: [0, 0],
75
+
76
+ // @option direction: String = 'auto'
77
+ // Direction where to open the tooltip. Possible values are: `right`, `left`,
78
+ // `top`, `bottom`, `center`, `auto`.
79
+ // `auto` will dynamically switch between `right` and `left` according to the tooltip
80
+ // position on the map.
81
+ direction: 'auto',
82
+
83
+ // @option permanent: Boolean = false
84
+ // Whether to open the tooltip permanently or only on pointerover.
85
+ permanent: false,
86
+
87
+ // @option sticky: Boolean = false
88
+ // If true, the tooltip will follow the pointer instead of being fixed at the feature center.
89
+ sticky: false,
90
+
91
+ // @option opacity: Number = 0.9
92
+ // Tooltip container opacity.
93
+ opacity: 0.9
94
+ });
95
+ }
96
+
97
+ constructor(...args) {
98
+ super(...args);
99
+ this.callInitHooks(Tooltip);
100
+ }
101
+
102
+ onAdd(map) {
103
+ super.onAdd(map);
104
+ this.setOpacity(this.options.opacity);
105
+
106
+ // @namespace MaplairMap
107
+ // @section Tooltip events
108
+ // @event tooltipopen: TooltipEvent
109
+ // Fired when a tooltip is opened in the map.
110
+ map.fire('tooltipopen', {tooltip: this});
111
+
112
+ if (this._source) {
113
+ this.addEventParent(this._source);
114
+
115
+ // @namespace Layer
116
+ // @section Tooltip events
117
+ // @event tooltipopen: TooltipEvent
118
+ // Fired when a tooltip bound to this layer is opened.
119
+ this._source.fire('tooltipopen', {tooltip: this}, true);
120
+ }
121
+ }
122
+
123
+ onRemove(map) {
124
+ super.onRemove(map);
125
+
126
+ // @namespace MaplairMap
127
+ // @section Tooltip events
128
+ // @event tooltipclose: TooltipEvent
129
+ // Fired when a tooltip in the map is closed.
130
+ map.fire('tooltipclose', {tooltip: this});
131
+
132
+ if (this._source) {
133
+ this.removeEventParent(this._source);
134
+
135
+ // @namespace Layer
136
+ // @section Tooltip events
137
+ // @event tooltipclose: TooltipEvent
138
+ // Fired when a tooltip bound to this layer is closed.
139
+ this._source.fire('tooltipclose', {tooltip: this}, true);
140
+ }
141
+ }
142
+
143
+ getEvents() {
144
+ const events = super.getEvents();
145
+
146
+ if (!this.options.permanent) {
147
+ events.preclick = this.close;
148
+ }
149
+
150
+ return events;
151
+ }
152
+
153
+ _initLayout() {
154
+ const prefix = 'maplair-tooltip',
155
+ className = `${prefix} ${this.options.className || ''} maplair-zoom-${this._zoomAnimated ? 'animated' : 'hide'}`;
156
+
157
+ this._contentNode = this._container = DomUtil.create('div', className);
158
+
159
+ this._container.setAttribute('role', 'tooltip');
160
+ this._container.setAttribute('id', `maplair-tooltip-${Util.stamp(this)}`);
161
+ }
162
+
163
+ _updateLayout() {}
164
+
165
+ _adjustPan() {}
166
+
167
+ _setPosition(pos) {
168
+ let subX, subY, direction = this.options.direction;
169
+ const map = this._map,
170
+ container = this._container,
171
+ centerPoint = map.latLngToContainerPoint(map.getCenter()),
172
+ tooltipPoint = map.layerPointToContainerPoint(pos),
173
+ tooltipWidth = container.offsetWidth,
174
+ tooltipHeight = container.offsetHeight,
175
+ offset = new Point(this.options.offset),
176
+ anchor = this._getAnchor();
177
+
178
+ if (direction === 'top') {
179
+ subX = tooltipWidth / 2;
180
+ subY = tooltipHeight;
181
+ } else if (direction === 'bottom') {
182
+ subX = tooltipWidth / 2;
183
+ subY = 0;
184
+ } else if (direction === 'center') {
185
+ subX = tooltipWidth / 2;
186
+ subY = tooltipHeight / 2;
187
+ } else if (direction === 'right') {
188
+ subX = 0;
189
+ subY = tooltipHeight / 2;
190
+ } else if (direction === 'left') {
191
+ subX = tooltipWidth;
192
+ subY = tooltipHeight / 2;
193
+ } else if (tooltipPoint.x < centerPoint.x) {
194
+ direction = 'right';
195
+ subX = 0;
196
+ subY = tooltipHeight / 2;
197
+ } else {
198
+ direction = 'left';
199
+ subX = tooltipWidth + (offset.x + anchor.x) * 2;
200
+ subY = tooltipHeight / 2;
201
+ }
202
+
203
+ pos = pos.subtract(new Point(subX, subY, true)).add(offset).add(anchor);
204
+
205
+ container.classList.remove(
206
+ 'maplair-tooltip-right',
207
+ 'maplair-tooltip-left',
208
+ 'maplair-tooltip-top',
209
+ 'maplair-tooltip-bottom'
210
+ );
211
+ container.classList.add(`maplair-tooltip-${direction}`);
212
+ DomUtil.setPosition(container, pos);
213
+ }
214
+
215
+ _updatePosition() {
216
+ const pos = this._map.latLngToLayerPoint(this._latlng);
217
+ this._setPosition(pos);
218
+ }
219
+
220
+ setOpacity(opacity) {
221
+ this.options.opacity = opacity;
222
+
223
+ if (this._container) {
224
+ this._container.style.opacity = opacity;
225
+ }
226
+ }
227
+
228
+ _animateZoom(e) {
229
+ const pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);
230
+ this._setPosition(pos);
231
+ }
232
+
233
+ _getAnchor() {
234
+ // Where should we anchor the tooltip on the source layer?
235
+ return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]);
236
+ }
237
+
238
+ // Registers this default feature on the map class, called by `MaplairMap` itself.
239
+ static register(MaplairMap) {
240
+ // @namespace MaplairMap
241
+ // @section Methods for Layers and Controls
242
+ MaplairMap.include({
243
+
244
+ // @method openTooltip(tooltip: Tooltip): this
245
+ // Opens the specified tooltip.
246
+ // @alternative
247
+ // @method openTooltip(content: String|HTMLElement, latlng: LatLng, options?: Tooltip options): this
248
+ // Creates a tooltip with the specified content and options and open it.
249
+ // String content is rendered as HTML; sanitize untrusted input or pass an `HTMLElement` with safe `textContent` instead.
250
+ openTooltip(tooltip, latlng, options) {
251
+ this._initOverlay(Tooltip, tooltip, latlng, options)
252
+ .openOn(this);
253
+
254
+ return this;
255
+ },
256
+
257
+ // @method closeTooltip(tooltip: Tooltip): this
258
+ // Closes the tooltip given as parameter.
259
+ closeTooltip(tooltip) {
260
+ tooltip.close();
261
+ return this;
262
+ }
263
+
264
+ });
265
+
266
+ /*
267
+ * @namespace Layer
268
+ * @section Tooltip methods example
269
+ *
270
+ * All layers share a set of methods convenient for binding tooltips to it.
271
+ *
272
+ * ```js
273
+ * const layer = new Polygon(latlngs).bindTooltip('Hi There!').addTo(map);
274
+ * layer.openTooltip();
275
+ * layer.closeTooltip();
276
+ * ```
277
+ */
278
+
279
+ // @section Tooltip methods
280
+ Layer.include({
281
+
282
+ // @method bindTooltip(content: String|HTMLElement|Function|Tooltip, options?: Tooltip options): this
283
+ // Binds a tooltip to the layer with the passed `content` and sets up the
284
+ // necessary event listeners. A `String` argument is rendered as HTML; if it
285
+ // may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
286
+ // `HTMLElement` with safe `textContent` instead. If a `Function` is passed
287
+ // it will receive the layer as the first argument and should return a
288
+ // `String` or `HTMLElement`.
289
+ bindTooltip(content, options) {
290
+
291
+ if (this._tooltip && this.isTooltipOpen()) {
292
+ this.unbindTooltip();
293
+ }
294
+
295
+ this._tooltip = this._initOverlay(Tooltip, this._tooltip, content, options);
296
+ this._initTooltipInteractions();
297
+
298
+ if (this._tooltip.options.permanent && this._map && this._map.hasLayer(this)) {
299
+ this.openTooltip();
300
+ }
301
+
302
+ return this;
303
+ },
304
+
305
+ // @method unbindTooltip(): this
306
+ // Removes the tooltip previously bound with `bindTooltip`.
307
+ unbindTooltip() {
308
+ if (this._tooltip) {
309
+ this._initTooltipInteractions(true);
310
+ this.closeTooltip();
311
+ this._tooltip = null;
312
+ }
313
+ return this;
314
+ },
315
+
316
+ _initTooltipInteractions(remove) {
317
+ if (!remove && this._tooltipHandlersAdded) { return; }
318
+ const onOff = remove ? 'off' : 'on',
319
+ events = {
320
+ remove: this.closeTooltip,
321
+ move: this._moveTooltip
322
+ };
323
+ if (!this._tooltip.options.permanent) {
324
+ events.pointerover = this._openTooltip;
325
+ events.pointerout = this.closeTooltip;
326
+ events.click = this._openTooltip;
327
+ if (this._map) {
328
+ this._addFocusListeners(remove);
329
+ } else {
330
+ events.add = () => this._addFocusListeners(remove);
331
+ }
332
+ } else {
333
+ events.add = this._openTooltip;
334
+ }
335
+ if (this._tooltip.options.sticky) {
336
+ events.pointermove = this._moveTooltip;
337
+ }
338
+ this[onOff](events);
339
+ this._tooltipHandlersAdded = !remove;
340
+ },
341
+
342
+ // @method openTooltip(latlng?: LatLng): this
343
+ // Opens the bound tooltip at the specified `latlng` or at the default tooltip anchor if no `latlng` is passed.
344
+ openTooltip(latlng) {
345
+ if (this._tooltip) {
346
+ if (!(this instanceof FeatureGroup)) {
347
+ this._tooltip._source = this;
348
+ }
349
+ if (this._tooltip._prepareOpen(latlng)) {
350
+ // open the tooltip on the map
351
+ this._tooltip.openOn(this._map);
352
+
353
+ if (this.getElement) {
354
+ this._setAriaDescribedByOnLayer(this);
355
+ } else if (this.eachLayer) {
356
+ this.eachLayer(this._setAriaDescribedByOnLayer, this);
357
+ }
358
+ }
359
+ }
360
+ return this;
361
+ },
362
+
363
+ // @method closeTooltip(): this
364
+ // Closes the tooltip bound to this layer if it is open.
365
+ closeTooltip() {
366
+ if (this._tooltip) {
367
+ return this._tooltip.close();
368
+ }
369
+ },
370
+
371
+ // @method toggleTooltip(): this
372
+ // Opens or closes the tooltip bound to this layer depending on its current state.
373
+ toggleTooltip() {
374
+ this._tooltip?.toggle(this);
375
+ return this;
376
+ },
377
+
378
+ // @method isTooltipOpen(): boolean
379
+ // Returns `true` if the tooltip bound to this layer is currently open.
380
+ isTooltipOpen() {
381
+ return this._tooltip.isOpen();
382
+ },
383
+
384
+ // @method setTooltipContent(content: String|HTMLElement|Tooltip): this
385
+ // Sets the content of the tooltip bound to this layer.
386
+ // String content is rendered as HTML; sanitize untrusted input or pass an `HTMLElement` with safe `textContent` instead.
387
+ setTooltipContent(content) {
388
+ this._tooltip?.setContent(content);
389
+ return this;
390
+ },
391
+
392
+ // @method getTooltip(): Tooltip
393
+ // Returns the tooltip bound to this layer.
394
+ getTooltip() {
395
+ return this._tooltip;
396
+ },
397
+
398
+ _addFocusListeners(remove) {
399
+ if (this.getElement) {
400
+ this._addFocusListenersOnLayer(this, remove);
401
+ } else if (this.eachLayer) {
402
+ this.eachLayer(layer => this._addFocusListenersOnLayer(layer, remove), this);
403
+ }
404
+ },
405
+
406
+ _addFocusListenersOnLayer(layer, remove) {
407
+ const el = typeof layer.getElement === 'function' && layer.getElement();
408
+ if (el) {
409
+ const toggle = remove ? DomEvent.off : DomEvent.on;
410
+ if (!remove) {
411
+ // Remove focus listener, if already existing
412
+ el._maplair_focus_handler && DomEvent.off(el, 'focus', el._maplair_focus_handler, this);
413
+
414
+ el._maplair_focus_handler = () => {
415
+ if (this._tooltip) {
416
+ this._tooltip._source = layer;
417
+ this.openTooltip();
418
+ }
419
+ };
420
+ }
421
+
422
+ el._maplair_focus_handler && toggle(el, 'focus', el._maplair_focus_handler, this);
423
+ toggle(el, 'blur', this.closeTooltip, this);
424
+
425
+ if (remove) {
426
+ delete el._maplair_focus_handler;
427
+ }
428
+ }
429
+ },
430
+
431
+ _setAriaDescribedByOnLayer(layer) {
432
+ const el = typeof layer.getElement === 'function' && layer.getElement();
433
+ el?.setAttribute?.('aria-describedby', this._tooltip._container.id);
434
+ },
435
+
436
+ _openTooltip(e) {
437
+ if (!this._tooltip || !this._map) {
438
+ return;
439
+ }
440
+
441
+ // If the map is moving, we will show the tooltip after it's done.
442
+ if (this._map.dragging?.moving()) {
443
+ if (e.type === 'add' && !this._moveEndOpensTooltip) {
444
+ this._moveEndOpensTooltip = true;
445
+ this._map.once('moveend', () => {
446
+ this._moveEndOpensTooltip = false;
447
+ this._openTooltip(e);
448
+ });
449
+ }
450
+ return;
451
+ }
452
+
453
+ this._tooltip._source = e.propagatedFrom ?? e.target;
454
+
455
+ this.openTooltip(this._tooltip.options.sticky ? e.latlng : undefined);
456
+ },
457
+
458
+ _moveTooltip(e) {
459
+ let latlng = e.latlng, containerPoint, layerPoint;
460
+ if (this._tooltip.options.sticky && e.originalEvent) {
461
+ containerPoint = this._map.pointerEventToContainerPoint(e.originalEvent);
462
+ layerPoint = this._map.containerPointToLayerPoint(containerPoint);
463
+ latlng = this._map.layerPointToLatLng(layerPoint);
464
+ }
465
+ this._tooltip.setLatLng(latlng);
466
+ }
467
+ });
468
+ }
469
+ }
@@ -0,0 +1,111 @@
1
+ import {ImageOverlay} from './ImageOverlay.js';
2
+ import * as DomUtil from '../dom/DomUtil.js';
3
+ import * as DomEvent from '../dom/DomEvent.js';
4
+ import * as Util from '../core/Util.js';
5
+
6
+ /*
7
+ * @class VideoOverlay
8
+ * @inherits ImageOverlay
9
+ *
10
+ * Used to load and display a video player over specific bounds of the map. Extends `ImageOverlay`.
11
+ *
12
+ * A video overlay uses the [`<video>`](https://developer.mozilla.org/docs/Web/HTML/Element/video)
13
+ * HTML element.
14
+ *
15
+ * @example
16
+ *
17
+ * ```js
18
+ * const videoUrl = 'https://www.mapbox.com/bites/00188/patricia_nasa.webm',
19
+ * videoBounds = [[ 32, -130], [ 13, -100]];
20
+ * new VideoOverlay(videoUrl, videoBounds ).addTo(map);
21
+ * ```
22
+ */
23
+
24
+ // @constructor VideoOverlay(video: String|Array|HTMLVideoElement, bounds: LatLngBounds, options?: VideoOverlay options)
25
+ // Instantiates an image overlay object given the URL of the video (or array of URLs, or even a video element) and the
26
+ // geographical bounds it is tied to.
27
+ export class VideoOverlay extends ImageOverlay {
28
+
29
+ static {
30
+ // @section
31
+ // @aka VideoOverlay options
32
+ this.setDefaultOptions({
33
+ // @option autoplay: Boolean = true
34
+ // Whether the video starts playing automatically when loaded.
35
+ // On some browsers autoplay will only work with `muted: true`
36
+ autoplay: true,
37
+
38
+ // @option controls: Boolean = false
39
+ // Whether the browser will offer controls to allow the user to control video playback, including volume, seeking, and pause/resume playback.
40
+ controls: false,
41
+
42
+ // @option loop: Boolean = true
43
+ // Whether the video will loop back to the beginning when played.
44
+ loop: true,
45
+
46
+ // @option keepAspectRatio: Boolean = true
47
+ // Whether the video will save aspect ratio after the projection.
48
+ keepAspectRatio: true,
49
+
50
+ // @option muted: Boolean = false
51
+ // Whether the video starts on mute when loaded.
52
+ muted: false,
53
+
54
+ // @option playsInline: Boolean = true
55
+ // Mobile browsers will play the video right where it is instead of open it up in fullscreen mode.
56
+ playsInline: true
57
+ });
58
+ }
59
+
60
+ constructor(...args) {
61
+ super(...args);
62
+ this.callInitHooks(VideoOverlay);
63
+ }
64
+
65
+ _initImage() {
66
+ const wasElementSupplied = this._url.tagName === 'VIDEO';
67
+ const vid = this._image = wasElementSupplied ? this._url : DomUtil.create('video');
68
+
69
+ vid.classList.add('maplair-image-layer');
70
+ if (this._zoomAnimated) { vid.classList.add('maplair-zoom-animated'); }
71
+ if (this.options.className) { vid.classList.add(...Util.splitWords(this.options.className)); }
72
+
73
+ DomEvent.on(vid, 'pointerdown', (e) => {
74
+ if (vid.controls) {
75
+ // Prevent the map from moving when the video or the seekbar is moved
76
+ DomEvent.stopPropagation(e);
77
+ }
78
+ });
79
+
80
+ // @event load: Event
81
+ // Fired when the video has finished loading the first frame
82
+ vid.onloadeddata = this.fire.bind(this, 'load');
83
+
84
+ if (wasElementSupplied) {
85
+ const sourceElements = vid.getElementsByTagName('source');
86
+ const sources = sourceElements.map(e => e.src);
87
+ this._url = (sourceElements.length > 0) ? sources : [vid.src];
88
+ return;
89
+ }
90
+
91
+ if (!Array.isArray(this._url)) { this._url = [this._url]; }
92
+
93
+ if (!this.options.keepAspectRatio && Object.hasOwn(vid.style, 'objectFit')) {
94
+ vid.style['objectFit'] = 'fill';
95
+ }
96
+ vid.autoplay = !!this.options.autoplay;
97
+ vid.controls = !!this.options.controls;
98
+ vid.loop = !!this.options.loop;
99
+ vid.muted = !!this.options.muted;
100
+ vid.playsInline = !!this.options.playsInline;
101
+ for (const url of this._url) {
102
+ const source = DomUtil.create('source');
103
+ source.src = url;
104
+ vid.appendChild(source);
105
+ }
106
+ }
107
+
108
+ // @method getElement(): HTMLVideoElement
109
+ // Returns the instance of [`HTMLVideoElement`](https://developer.mozilla.org/docs/Web/API/HTMLVideoElement)
110
+ // used by this overlay.
111
+ }
@@ -0,0 +1,18 @@
1
+ export {Layer} from './Layer.js';
2
+ export {LayerGroup} from './LayerGroup.js';
3
+ export {FeatureGroup} from './FeatureGroup.js';
4
+ export {GeoJSON} from './GeoJSON.js';
5
+
6
+ export {BlanketOverlay} from './BlanketOverlay.js';
7
+
8
+ export {ImageOverlay} from './ImageOverlay.js';
9
+ export {VideoOverlay} from './VideoOverlay.js';
10
+ export {SVGOverlay} from './SVGOverlay.js';
11
+
12
+ export {DivOverlay} from './DivOverlay.js';
13
+ export {Popup} from './Popup.js';
14
+ export {Tooltip} from './Tooltip.js';
15
+
16
+ export * from './marker/index.js';
17
+ export * from './tile/index.js';
18
+ export * from './vector/index.js';
@@ -0,0 +1,79 @@
1
+ import {Icon} from './Icon.js';
2
+ import * as DomUtil from '../../dom/DomUtil.js';
3
+
4
+ const URL_RE = /^url\((['"])?(.+)\1\)$/;
5
+ const MARKER_ICON_RE = /^(.*)marker-icon\.svg$/;
6
+
7
+ /*
8
+ * @miniclass DefaultIcon (Icon)
9
+ * @section
10
+ *
11
+ * A trivial subclass of `Icon`, represents the icon to use in `Marker`s when
12
+ * no icon is specified. Points to the blue marker image distributed with Maplair
13
+ * releases.
14
+ *
15
+ * In order to customize the default icon, just change the properties of `DefaultIcon.prototype.options`
16
+ * (which is a set of `Icon options`).
17
+ *
18
+ * If you want to _completely_ replace the default icon, override the
19
+ * `Marker.prototype.options.icon` with your own icon instead.
20
+ */
21
+
22
+ export class DefaultIcon extends Icon {
23
+
24
+ static {
25
+ this.setDefaultOptions({
26
+ iconUrl: 'marker-icon.svg',
27
+ iconRetinaUrl: 'marker-icon.svg',
28
+ shadowUrl: 'marker-shadow.svg',
29
+ iconSize: [25, 41],
30
+ iconAnchor: [12, 41],
31
+ popupAnchor: [1, -34],
32
+ tooltipAnchor: [16, -28],
33
+ shadowSize: [41, 41]
34
+ });
35
+ }
36
+
37
+ constructor(...args) {
38
+ super(...args);
39
+ this.callInitHooks(DefaultIcon);
40
+ }
41
+
42
+ _getIconUrl(name) {
43
+ // only detect once
44
+ if (!DefaultIcon.imagePath) {
45
+ DefaultIcon.imagePath = this._detectIconPath();
46
+ }
47
+
48
+ const url = super._getIconUrl(name);
49
+ if (!url) {
50
+ return null;
51
+ }
52
+
53
+ // @option imagePath: String
54
+ // `DefaultIcon` will try to auto-detect the location of the
55
+ // blue icon images. If you are placing these images in a non-standard
56
+ // way, set this option to point to the right path.
57
+ return (this.options.imagePath ?? DefaultIcon.imagePath) + url;
58
+ }
59
+
60
+ _stripUrl(path) { // separate function to use in tests
61
+ const strip = function (str, re, idx) {
62
+ const match = re.exec(str);
63
+ return match && match[idx];
64
+ };
65
+ path = strip(path, URL_RE, 2);
66
+ return path && strip(path, MARKER_ICON_RE, 1);
67
+ }
68
+
69
+ _detectIconPath() {
70
+ const el = DomUtil.create('div', 'maplair-default-icon-path', document.body);
71
+ const path = this._stripUrl(getComputedStyle(el).backgroundImage);
72
+
73
+ document.body.removeChild(el);
74
+ if (path) { return path; }
75
+ const link = document.querySelector('link[href$="maplair.css"]');
76
+ if (!link) { return ''; }
77
+ return link.href.substring(0, link.href.length - 'maplair.css'.length - 1);
78
+ }
79
+ }