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,528 @@
1
+ import {DivOverlay} from './DivOverlay.js';
2
+ import * as DomEvent from '../dom/DomEvent.js';
3
+ import * as DomUtil from '../dom/DomUtil.js';
4
+ import Browser from '../core/Browser.js';
5
+ import {Point} from '../geometry/Point.js';
6
+ import {Layer} from './Layer.js';
7
+ import {Path} from './vector/Path.js';
8
+ import {FeatureGroup} from './FeatureGroup.js';
9
+ import {I18n} from '../core/I18n.js';
10
+
11
+ /*
12
+ * @class Popup
13
+ * @inherits DivOverlay
14
+ * Used to open popups in certain places of the map. Use [Map.openPopup](#map-openpopup) to
15
+ * open popups while making sure that only one popup is open at one time
16
+ * (recommended for usability), or use [Map.addLayer](#map-addlayer) to open as many as you want.
17
+ *
18
+ * @example
19
+ *
20
+ * If you want to just bind a popup to marker click and then open it, it's really easy:
21
+ *
22
+ * ```js
23
+ * marker.bindPopup(popupContent).openPopup();
24
+ * ```
25
+ * Path overlays like polylines also have a `bindPopup` method.
26
+ *
27
+ * A popup can be also standalone:
28
+ *
29
+ * ```js
30
+ * const popup = new Popup()
31
+ * .setLatLng(latlng)
32
+ * .setContent('<p>Hello world!<br />This is a nice popup.</p>')
33
+ * .openOn(map);
34
+ * ```
35
+ * or
36
+ * ```js
37
+ * const popup = new Popup(latlng, {content: '<p>Hello world!<br />This is a nice popup.</p>'})
38
+ * .openOn(map);
39
+ * ```
40
+ *
41
+ * **Security note.** Popup string content is rendered as HTML. If your content
42
+ * may include untrusted input (e.g. data from users or external APIs), sanitize
43
+ * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or
44
+ * build a DOM element using `textContent` to render it as plain text:
45
+ *
46
+ * ```js
47
+ * const el = document.createElement('div');
48
+ * el.textContent = untrustedString;
49
+ * marker.bindPopup(el);
50
+ * ```
51
+ */
52
+
53
+ // @namespace Popup
54
+ // @constructor Popup(options?: Popup options, source?: Layer)
55
+ // Instantiates a `Popup` object given an optional `options` object that describes its appearance and location and an optional `source` object that is used to tag the popup with a reference to the Layer to which it refers.
56
+ // @alternative
57
+ // @constructor Popup(latlng: LatLng, options?: Popup options)
58
+ // Instantiates a `Popup` object given `latlng` where the popup will open and an optional `options` object that describes its appearance and location.
59
+ export class Popup extends DivOverlay {
60
+
61
+ static {
62
+ // @section
63
+ // @aka Popup options
64
+ this.setDefaultOptions({
65
+ // @option pane: String = 'popupPane'
66
+ // `Map pane` where the popup will be added.
67
+ pane: 'popupPane',
68
+
69
+ // @option offset: Point = Point(0, 7)
70
+ // The offset of the popup position.
71
+ offset: [0, 7],
72
+
73
+ // @option maxWidth: Number = 300
74
+ // Max width of the popup, in pixels.
75
+ maxWidth: 300,
76
+
77
+ // @option minWidth: Number = 50
78
+ // Min width of the popup, in pixels.
79
+ minWidth: 50,
80
+
81
+ // @option maxHeight: Number = null
82
+ // If set, creates a scrollable container of the given height
83
+ // inside a popup if its content exceeds it.
84
+ // The scrollable container can be styled using the
85
+ // `maplair-popup-scrolled` CSS class selector.
86
+ maxHeight: null,
87
+
88
+ // @option autoPan: Boolean = true
89
+ // Set it to `false` if you don't want the map to do panning animation
90
+ // to fit the opened popup.
91
+ autoPan: !Browser.reducedMotion,
92
+
93
+ // @option autoPanPaddingTopLeft: Point = null
94
+ // The margin between the popup and the top left corner of the map
95
+ // view after autopanning was performed.
96
+ autoPanPaddingTopLeft: null,
97
+
98
+ // @option autoPanPaddingBottomRight: Point = null
99
+ // The margin between the popup and the bottom right corner of the map
100
+ // view after autopanning was performed.
101
+ autoPanPaddingBottomRight: null,
102
+
103
+ // @option autoPanPadding: Point = Point(5, 5)
104
+ // Equivalent of setting both top left and bottom right autopan padding to the same value.
105
+ autoPanPadding: [5, 5],
106
+
107
+ // @option keepInView: Boolean = false
108
+ // Set it to `true` if you want to prevent users from panning the popup
109
+ // off of the screen while it is open.
110
+ keepInView: false,
111
+
112
+ // @option closeButton: Boolean = true
113
+ // Controls the presence of a close button in the popup.
114
+ closeButton: true,
115
+
116
+ // @option autoClose: Boolean = true
117
+ // Set it to `false` if you want to override the default behavior of
118
+ // the popup closing when another popup is opened.
119
+ autoClose: true,
120
+
121
+ // @option closeOnEscapeKey: Boolean = true
122
+ // Set it to `false` if you want to override the default behavior of
123
+ // the ESC key for closing of the popup.
124
+ closeOnEscapeKey: true,
125
+
126
+ // @option closeOnClick: Boolean = *
127
+ // Set it if you want to override the default behavior of the popup closing when user clicks
128
+ // on the map. Defaults to the map's [`closePopupOnClick`](#map-closepopuponclick) option.
129
+
130
+ // @option className: String = ''
131
+ // A custom CSS class name to assign to the popup.
132
+ className: '',
133
+
134
+ // @option trackResize: Boolean = true
135
+ // Whether the popup shall react to changes in the size of its contents
136
+ // (e.g. when an image inside the popup loads) and reposition itself.
137
+ trackResize: true,
138
+ });
139
+ }
140
+
141
+ constructor(...args) {
142
+ super(...args);
143
+ this.callInitHooks(Popup);
144
+ }
145
+
146
+ // @namespace Popup
147
+ // @method openOn(map: MaplairMap): this
148
+ // Alternative to `map.openPopup(popup)`.
149
+ // Adds the popup to the map and closes the previous one.
150
+ openOn(map) {
151
+ map = arguments.length ? map : this._source._map; // experimental, not the part of public api
152
+
153
+ if (!map.hasLayer(this) && map._popup && map._popup.options.autoClose) {
154
+ map.removeLayer(map._popup);
155
+ }
156
+ map._popup = this;
157
+
158
+ return super.openOn(map);
159
+ }
160
+
161
+ onAdd(map) {
162
+ super.onAdd(map);
163
+
164
+ // @namespace MaplairMap
165
+ // @section Popup events
166
+ // @event popupopen: PopupEvent
167
+ // Fired when a popup is opened in the map
168
+ map.fire('popupopen', {popup: this});
169
+
170
+ if (this._source) {
171
+ // @namespace Layer
172
+ // @section Popup events
173
+ // @event popupopen: PopupEvent
174
+ // Fired when a popup bound to this layer is opened
175
+ this._source.fire('popupopen', {popup: this}, true);
176
+ // For non-path layers, we toggle the popup when clicking
177
+ // again the layer, so prevent the map to reopen it.
178
+ if (!(this._source instanceof Path)) {
179
+ this._source.on('preclick', DomEvent.stopPropagation);
180
+ }
181
+ }
182
+ }
183
+
184
+ onRemove(map) {
185
+ super.onRemove(map);
186
+
187
+ // @namespace MaplairMap
188
+ // @section Popup events
189
+ // @event popupclose: PopupEvent
190
+ // Fired when a popup in the map is closed
191
+ map.fire('popupclose', {popup: this});
192
+
193
+ if (this._source) {
194
+ // @namespace Layer
195
+ // @section Popup events
196
+ // @event popupclose: PopupEvent
197
+ // Fired when a popup bound to this layer is closed
198
+ this._source.fire('popupclose', {popup: this}, true);
199
+ if (!(this._source instanceof Path)) {
200
+ this._source.off('preclick', DomEvent.stopPropagation);
201
+ }
202
+ }
203
+ }
204
+
205
+ getEvents() {
206
+ const events = super.getEvents();
207
+
208
+ if (this.options.closeOnClick ?? this._map.options.closePopupOnClick) {
209
+ events.preclick = this.close;
210
+ }
211
+
212
+ if (this.options.keepInView) {
213
+ events.moveend = this._adjustPan;
214
+ }
215
+
216
+ return events;
217
+ }
218
+
219
+ _initLayout() {
220
+ const prefix = 'maplair-popup',
221
+ container = this._container = DomUtil.create('div', `${prefix} ${this.options.className || ''} maplair-zoom-animated`);
222
+
223
+ const wrapper = this._wrapper = DomUtil.create('div', `${prefix}-content-wrapper`, container);
224
+ this._contentNode = DomUtil.create('div', `${prefix}-content`, wrapper);
225
+
226
+ DomEvent.disableClickPropagation(container);
227
+ DomEvent.disableScrollPropagation(this._contentNode);
228
+ DomEvent.on(container, 'contextmenu', DomEvent.stopPropagation);
229
+
230
+ this._tipContainer = DomUtil.create('div', `${prefix}-tip-container`, container);
231
+ this._tip = DomUtil.create('div', `${prefix}-tip`, this._tipContainer);
232
+
233
+ if (this.options.closeButton) {
234
+ const closeButton = this._closeButton = DomUtil.create('a', `${prefix}-close-button`, container);
235
+ closeButton.setAttribute('role', 'button'); // overrides the implicit role=link of <a> elements #7399
236
+ closeButton.setAttribute('aria-label', I18n.translate('Close popup'));
237
+
238
+ closeButton.href = '#close';
239
+ closeButton.innerHTML = '<span aria-hidden="true">&#215;</span>';
240
+
241
+ DomEvent.on(closeButton, 'click', (ev) => {
242
+ ev.preventDefault();
243
+ this.close();
244
+ });
245
+ }
246
+
247
+ if (this.options.trackResize) {
248
+ this._resizeObserver = new ResizeObserver(((entries) => {
249
+ if (!this._map) { return; }
250
+ this._containerWidth = entries[0]?.contentRect?.width;
251
+ this._containerHeight = entries[0]?.contentRect?.height;
252
+
253
+ this._updateLayout();
254
+ this._updatePosition();
255
+ this._adjustPan();
256
+ }));
257
+
258
+ this._resizeObserver.observe(this._contentNode);
259
+ }
260
+ }
261
+
262
+ _updateLayout() {
263
+ const container = this._contentNode,
264
+ style = container.style;
265
+
266
+ style.maxWidth = `${this.options.maxWidth}px`;
267
+ style.minWidth = `${this.options.minWidth}px`;
268
+
269
+ const maxHeight = this.options.maxHeight,
270
+ scrolledClass = 'maplair-popup-scrolled';
271
+
272
+ // only measure the height (forcing a layout) if needed
273
+ if (maxHeight && (this._containerHeight ?? container.offsetHeight) > maxHeight) {
274
+ style.height = `${maxHeight}px`;
275
+ container.classList.add(scrolledClass);
276
+ } else {
277
+ container.classList.remove(scrolledClass);
278
+ }
279
+
280
+ this._containerWidth = this._container.offsetWidth;
281
+ this._containerHeight = this._container.offsetHeight;
282
+ // read along with the size, so that _adjustPan doesn't force another style
283
+ // recalculation and layout after the popup has been positioned
284
+ this._containerMarginBottom = parseInt(getComputedStyle(this._container).marginBottom, 10) || 0;
285
+ }
286
+
287
+ _animateZoom(e) {
288
+ const pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center),
289
+ anchor = this._getAnchor();
290
+ DomUtil.setPosition(this._container, pos.add(anchor));
291
+ }
292
+
293
+ _adjustPan() {
294
+ if (!this.options.autoPan) { return; }
295
+ this._map._panAnim?.stop();
296
+
297
+ // We can endlessly recurse if keepInView is set and the view resets.
298
+ // Let's guard against that by exiting early if we're responding to our own autopan.
299
+ if (this._autopanning) {
300
+ this._autopanning = false;
301
+ return;
302
+ }
303
+
304
+ const map = this._map,
305
+ marginBottom = this._containerMarginBottom ?? (parseInt(getComputedStyle(this._container).marginBottom, 10) || 0),
306
+ containerHeight = this._containerHeight + marginBottom,
307
+ containerWidth = this._containerWidth,
308
+ layerPos = new Point(this._containerLeft, -containerHeight - this._containerBottom);
309
+
310
+ layerPos._add(DomUtil.getPosition(this._container));
311
+
312
+ const containerPos = map.layerPointToContainerPoint(layerPos),
313
+ padding = new Point(this.options.autoPanPadding),
314
+ paddingTL = new Point(this.options.autoPanPaddingTopLeft ?? padding),
315
+ paddingBR = new Point(this.options.autoPanPaddingBottomRight ?? padding),
316
+ size = map.getSize();
317
+ let dx = 0,
318
+ dy = 0;
319
+
320
+ if (containerPos.x + containerWidth + paddingBR.x > size.x) { // right
321
+ dx = containerPos.x + containerWidth - size.x + paddingBR.x;
322
+ }
323
+ if (containerPos.x - dx - paddingTL.x < 0) { // left
324
+ dx = containerPos.x - paddingTL.x;
325
+ }
326
+ if (containerPos.y + containerHeight + paddingBR.y > size.y) { // bottom
327
+ dy = containerPos.y + containerHeight - size.y + paddingBR.y;
328
+ }
329
+ if (containerPos.y - dy - paddingTL.y < 0) { // top
330
+ dy = containerPos.y - paddingTL.y;
331
+ }
332
+
333
+ // @namespace MaplairMap
334
+ // @section Popup events
335
+ // @event autopanstart: Event
336
+ // Fired when the map starts autopanning when opening a popup.
337
+ if (dx || dy) {
338
+ // Track that we're autopanning, as this function will be re-ran on moveend
339
+ if (this.options.keepInView) {
340
+ this._autopanning = true;
341
+ }
342
+
343
+ map
344
+ .fire('autopanstart')
345
+ .panBy([dx, dy]);
346
+ }
347
+ }
348
+
349
+ _getAnchor() {
350
+ // Where should we anchor the popup on the source layer?
351
+ return new Point(this._source?._getPopupAnchor ? this._source._getPopupAnchor() : [0, 0]);
352
+ }
353
+
354
+ // Registers this default feature on the map class, called by `MaplairMap` itself.
355
+ static register(MaplairMap) {
356
+ /* @namespace MaplairMap
357
+ * @section Interaction Options
358
+ * @option closePopupOnClick: Boolean = true
359
+ * Set it to `false` if you don't want popups to close when user clicks the map.
360
+ */
361
+ MaplairMap.mergeOptions({
362
+ closePopupOnClick: true
363
+ });
364
+
365
+ // @namespace MaplairMap
366
+ // @section Methods for Layers and Controls
367
+ MaplairMap.include({
368
+ // @method openPopup(popup: Popup): this
369
+ // Opens the specified popup while closing the previously opened (to make sure only one is opened at one time for usability).
370
+ // @alternative
371
+ // @method openPopup(content: String|HTMLElement, latlng: LatLng, options?: Popup options): this
372
+ // Creates a popup with the specified content and options and opens it in the given point on a map.
373
+ // String content is rendered as HTML; sanitize untrusted input or pass an `HTMLElement` with safe `textContent` instead.
374
+ openPopup(popup, latlng, options) {
375
+ this._initOverlay(Popup, popup, latlng, options)
376
+ .openOn(this);
377
+
378
+ return this;
379
+ },
380
+
381
+ // @method closePopup(popup?: Popup): this
382
+ // Closes the popup previously opened with [openPopup](#map-openpopup) (or the given one).
383
+ closePopup(popup) {
384
+ popup = arguments.length ? popup : this._popup;
385
+ popup?.close();
386
+ return this;
387
+ }
388
+ });
389
+
390
+ /*
391
+ * @namespace Layer
392
+ * @section Popup methods example
393
+ *
394
+ * All layers share a set of methods convenient for binding popups to it.
395
+ *
396
+ * ```js
397
+ * const layer = new Polygon(latlngs).bindPopup('Hi There!').addTo(map);
398
+ * layer.openPopup();
399
+ * layer.closePopup();
400
+ * ```
401
+ *
402
+ * Popups will also be automatically opened when the layer is clicked on and closed when the layer is removed from the map or another popup is opened.
403
+ */
404
+
405
+ // @section Popup methods
406
+ Layer.include({
407
+
408
+ // @method bindPopup(content: String|HTMLElement|Function|Popup, options?: Popup options): this
409
+ // Binds a popup to the layer with the passed `content` and sets up the
410
+ // necessary event listeners. A `String` argument is rendered as HTML; if it
411
+ // may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
412
+ // `HTMLElement` with safe `textContent` instead. If a `Function` is passed
413
+ // it will receive the layer as the first argument and should return a
414
+ // `String` or `HTMLElement`.
415
+ bindPopup(content, options) {
416
+ this._popup = this._initOverlay(Popup, this._popup, content, options);
417
+ if (!this._popupHandlersAdded) {
418
+ this.on({
419
+ click: this._openPopup,
420
+ keypress: this._onKeyPress,
421
+ remove: this.closePopup,
422
+ move: this._movePopup
423
+ });
424
+ this._popupHandlersAdded = true;
425
+ }
426
+
427
+ return this;
428
+ },
429
+
430
+ // @method unbindPopup(): this
431
+ // Removes the popup previously bound with `bindPopup`.
432
+ unbindPopup() {
433
+ if (this._popup) {
434
+ this.off({
435
+ click: this._openPopup,
436
+ keypress: this._onKeyPress,
437
+ remove: this.closePopup,
438
+ move: this._movePopup
439
+ });
440
+ this._popupHandlersAdded = false;
441
+ this._popup = null;
442
+ }
443
+ return this;
444
+ },
445
+
446
+ // @method openPopup(latlng?: LatLng): this
447
+ // Opens the bound popup at the specified `latlng` or at the default popup anchor if no `latlng` is passed.
448
+ openPopup(latlng) {
449
+ if (this._popup) {
450
+ if (!(this instanceof FeatureGroup)) {
451
+ this._popup._source = this;
452
+ }
453
+ if (this._popup._prepareOpen(latlng || this._latlng)) {
454
+ // open the popup on the map
455
+ this._popup.openOn(this._map);
456
+ }
457
+ }
458
+ return this;
459
+ },
460
+
461
+ // @method closePopup(): this
462
+ // Closes the popup bound to this layer if it is open.
463
+ closePopup() {
464
+ this._popup?.close();
465
+ return this;
466
+ },
467
+
468
+ // @method togglePopup(): this
469
+ // Opens or closes the popup bound to this layer depending on its current state.
470
+ togglePopup() {
471
+ this._popup?.toggle(this);
472
+ return this;
473
+ },
474
+
475
+ // @method isPopupOpen(): boolean
476
+ // Returns `true` if the popup bound to this layer is currently open.
477
+ isPopupOpen() {
478
+ return this._popup?.isOpen() ?? false;
479
+ },
480
+
481
+ // @method setPopupContent(content: String|HTMLElement|Popup): this
482
+ // Sets the content of the popup bound to this layer.
483
+ // String content is rendered as HTML; sanitize untrusted input or pass an `HTMLElement` with safe `textContent` instead.
484
+ setPopupContent(content) {
485
+ this._popup?.setContent(content);
486
+ return this;
487
+ },
488
+
489
+ // @method getPopup(): Popup
490
+ // Returns the popup bound to this layer.
491
+ getPopup() {
492
+ return this._popup;
493
+ },
494
+
495
+ _openPopup(e) {
496
+ if (!this._popup || !this._map) {
497
+ return;
498
+ }
499
+ // prevent map click
500
+ DomEvent.stop(e);
501
+
502
+ const target = e.propagatedFrom ?? e.target;
503
+ if (this._popup._source === target && !(target instanceof Path)) {
504
+ // treat it like a marker and figure out
505
+ // if we should toggle it open/closed
506
+ if (this._map.hasLayer(this._popup)) {
507
+ this.closePopup();
508
+ } else {
509
+ this.openPopup(e.latlng);
510
+ }
511
+ return;
512
+ }
513
+ this._popup._source = target;
514
+ this.openPopup(e.latlng);
515
+ },
516
+
517
+ _movePopup(e) {
518
+ this._popup.setLatLng(e.latlng);
519
+ },
520
+
521
+ _onKeyPress(e) {
522
+ if (e.originalEvent.code === 'Enter') {
523
+ this._openPopup(e);
524
+ }
525
+ }
526
+ });
527
+ }
528
+ }
@@ -0,0 +1,47 @@
1
+ import {ImageOverlay} from './ImageOverlay.js';
2
+ import * as Util from '../core/Util.js';
3
+
4
+ /*
5
+ * @class SVGOverlay
6
+ * @inherits ImageOverlay
7
+ *
8
+ * Used to load, display and provide DOM access to an SVG file over specific bounds of the map. Extends `ImageOverlay`.
9
+ *
10
+ * An SVG overlay uses the [`<svg>`](https://developer.mozilla.org/docs/Web/SVG/Element/svg) element.
11
+ *
12
+ * @example
13
+ *
14
+ * ```js
15
+ * const svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
16
+ * svgElement.setAttribute('xmlns', "http://www.w3.org/2000/svg");
17
+ * svgElement.setAttribute('viewBox', "0 0 200 200");
18
+ * svgElement.innerHTML = '<rect width="200" height="200"/><rect x="75" y="23" width="50" height="50" style="fill:red"/><rect x="75" y="123" width="50" height="50" style="fill:#0013ff"/>';
19
+ * const svgElementBounds = [ [ 32, -130 ], [ 13, -100 ] ];
20
+ * new SVGOverlay(svgElement, svgElementBounds).addTo(map);
21
+ * ```
22
+ */
23
+
24
+ // @constructor SVGOverlay(svg: String|SVGElement, bounds: LatLngBounds, options?: SVGOverlay options)
25
+ // Instantiates an image overlay object given an SVG element and the geographical bounds it is tied to.
26
+ // A viewBox attribute is required on the SVG element to zoom in and out properly.
27
+ export class SVGOverlay extends ImageOverlay {
28
+ constructor(...args) {
29
+ super(...args);
30
+ this.callInitHooks(SVGOverlay);
31
+ }
32
+
33
+ _initImage() {
34
+ const el = this._image = this._url;
35
+
36
+ el.classList.add('maplair-image-layer');
37
+ if (this._zoomAnimated) { el.classList.add('maplair-zoom-animated'); }
38
+ if (this.options.className) { el.classList.add(...Util.splitWords(this.options.className)); }
39
+
40
+ el.onselectstart = Util.falseFn;
41
+ el.onpointermove = Util.falseFn;
42
+ }
43
+
44
+ // @method getElement(): SVGElement
45
+ // Returns the instance of [`SVGElement`](https://developer.mozilla.org/docs/Web/API/SVGElement)
46
+ // used by this overlay.
47
+ }