maplair 4.1.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/dist/esm/Maplair.js +5 -4
  3. package/dist/esm/Maplair.js.map +1 -1
  4. package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
  5. package/dist/esm/control/AttributionControl.js +1 -2
  6. package/dist/esm/control/ButtonControl.js +1 -2
  7. package/dist/esm/control/ContextMenu.js +1 -2
  8. package/dist/esm/control/Control.js +1 -2
  9. package/dist/esm/control/FullscreenControl.js +1 -2
  10. package/dist/esm/control/LayersControl.js +27 -31
  11. package/dist/esm/control/LayersControl.js.map +1 -1
  12. package/dist/esm/control/LegendControl.js +1 -2
  13. package/dist/esm/control/MiniMapControl.js +1 -2
  14. package/dist/esm/control/RotateControl.js +1 -2
  15. package/dist/esm/control/ScaleControl.js +1 -2
  16. package/dist/esm/control/SearchControl.js +1 -2
  17. package/dist/esm/control/SideBySideControl.js +1 -2
  18. package/dist/esm/control/TextControl.js +1 -2
  19. package/dist/esm/control/TimeControl.js +1 -2
  20. package/dist/esm/control/ZoomControl.js +18 -29
  21. package/dist/esm/control/ZoomControl.js.map +1 -1
  22. package/dist/esm/core/Class.js +2 -9
  23. package/dist/esm/core/Class.js.map +1 -1
  24. package/dist/esm/core/Events.js +2 -2
  25. package/dist/esm/core/Events.js.map +1 -1
  26. package/dist/esm/core/Handler.js +10 -3
  27. package/dist/esm/core/Handler.js.map +1 -1
  28. package/dist/esm/core/I18n.js +1 -2
  29. package/dist/esm/core/Util.js +2 -3
  30. package/dist/esm/core/Util.js.map +1 -1
  31. package/dist/esm/dom/DomEvent.DoubleTap.js +1 -2
  32. package/dist/esm/dom/DomEvent.PointerEvents.js +1 -2
  33. package/dist/esm/dom/DomEvent.js +10 -18
  34. package/dist/esm/dom/DomEvent.js.map +1 -1
  35. package/dist/esm/dom/DomUtil.js +1 -2
  36. package/dist/esm/dom/Draggable.js +4 -3
  37. package/dist/esm/dom/Draggable.js.map +1 -1
  38. package/dist/esm/dom/PosAnimation.js +1 -2
  39. package/dist/esm/geo/LatLng.js +1 -2
  40. package/dist/esm/geo/LatLngBounds.js +9 -15
  41. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  42. package/dist/esm/geo/crs/CRS.js +1 -2
  43. package/dist/esm/geo/crs/EPSG3395.js +4 -5
  44. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  45. package/dist/esm/geo/crs/EPSG3857.js +4 -5
  46. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  47. package/dist/esm/geo/crs/EPSG4326.js +3 -4
  48. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  49. package/dist/esm/geo/crs/EarthCRS.js +1 -2
  50. package/dist/esm/geo/crs/SimpleCRS.js +3 -4
  51. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  52. package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +4 -5
  53. package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
  54. package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +3 -4
  55. package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
  56. package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +4 -5
  57. package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
  58. package/dist/esm/geometry/Bounds.js +10 -14
  59. package/dist/esm/geometry/Bounds.js.map +1 -1
  60. package/dist/esm/geometry/LineUtil.js +2 -3
  61. package/dist/esm/geometry/LineUtil.js.map +1 -1
  62. package/dist/esm/geometry/Point.js +1 -2
  63. package/dist/esm/geometry/PolyUtil.js +17 -25
  64. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  65. package/dist/esm/geometry/Transformation.js +1 -2
  66. package/dist/esm/layer/BlanketOverlay.js +1 -2
  67. package/dist/esm/layer/Classification.js +1 -2
  68. package/dist/esm/layer/DivOverlay.js +2 -3
  69. package/dist/esm/layer/DivOverlay.js.map +1 -1
  70. package/dist/esm/layer/FeatureGroup.js +5 -4
  71. package/dist/esm/layer/FeatureGroup.js.map +1 -1
  72. package/dist/esm/layer/GeoJSON.Load.js +1 -2
  73. package/dist/esm/layer/GeoJSON.js +8 -10
  74. package/dist/esm/layer/GeoJSON.js.map +1 -1
  75. package/dist/esm/layer/GeoJSONUtil.js +1 -2
  76. package/dist/esm/layer/HeatLayer.js +2 -3
  77. package/dist/esm/layer/HeatLayer.js.map +1 -1
  78. package/dist/esm/layer/ImageOverlay.js +2 -3
  79. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  80. package/dist/esm/layer/Layer.js +1 -2
  81. package/dist/esm/layer/LayerGroup.js +2 -3
  82. package/dist/esm/layer/LayerGroup.js.map +1 -1
  83. package/dist/esm/layer/Popup.js +9 -16
  84. package/dist/esm/layer/Popup.js.map +1 -1
  85. package/dist/esm/layer/SVGOverlay.js +1 -2
  86. package/dist/esm/layer/Tooltip.js +16 -17
  87. package/dist/esm/layer/Tooltip.js.map +1 -1
  88. package/dist/esm/layer/VideoOverlay.js +1 -2
  89. package/dist/esm/layer/marker/DefaultIcon.js +29 -7
  90. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  91. package/dist/esm/layer/marker/DivIcon.js +1 -2
  92. package/dist/esm/layer/marker/Icon.js +2 -2
  93. package/dist/esm/layer/marker/Icon.js.map +1 -1
  94. package/dist/esm/layer/marker/Marker.Drag.js +43 -4
  95. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  96. package/dist/esm/layer/marker/Marker.Move.js +4 -6
  97. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  98. package/dist/esm/layer/marker/Marker.js +54 -14
  99. package/dist/esm/layer/marker/Marker.js.map +1 -1
  100. package/dist/esm/layer/marker/MarkerClusterGroup.js +1 -2
  101. package/dist/esm/layer/marker/SvgIcon.js +1 -2
  102. package/dist/esm/layer/tile/GridLayer.js +4 -4
  103. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  104. package/dist/esm/layer/tile/TileLayer.js +8 -8
  105. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  106. package/dist/esm/layer/tile/WMSTileLayer.js +5 -4
  107. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  108. package/dist/esm/layer/vector/Canvas.js +7 -14
  109. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  110. package/dist/esm/layer/vector/Circle.js +5 -3
  111. package/dist/esm/layer/vector/Circle.js.map +1 -1
  112. package/dist/esm/layer/vector/CircleMarker.js +2 -3
  113. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  114. package/dist/esm/layer/vector/Path.DashAnimation.js +1 -2
  115. package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
  116. package/dist/esm/layer/vector/Path.js +1 -2
  117. package/dist/esm/layer/vector/Polygon.js +2 -3
  118. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  119. package/dist/esm/layer/vector/Polyline.Decorations.js +1 -2
  120. package/dist/esm/layer/vector/Polyline.js +2 -3
  121. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  122. package/dist/esm/layer/vector/Rectangle.js +1 -2
  123. package/dist/esm/layer/vector/Renderer.getRenderer.js +4 -5
  124. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  125. package/dist/esm/layer/vector/Renderer.js +1 -2
  126. package/dist/esm/layer/vector/SVG.js +7 -4
  127. package/dist/esm/layer/vector/SVG.js.map +1 -1
  128. package/dist/esm/map/Hash.js +1 -2
  129. package/dist/esm/map/Map.Rotation.js +31 -16
  130. package/dist/esm/map/Map.Rotation.js.map +1 -1
  131. package/dist/esm/map/Map.js +10 -17
  132. package/dist/esm/map/Map.js.map +1 -1
  133. package/dist/esm/map/MapSync.js +1 -2
  134. package/dist/esm/map/handler/BoxZoomHandler.js +20 -40
  135. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  136. package/dist/esm/map/handler/DisplaceHandler.js +1 -2
  137. package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
  138. package/dist/esm/map/handler/DragHandler.js +1 -2
  139. package/dist/esm/map/handler/KeyboardHandler.js +23 -43
  140. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  141. package/dist/esm/map/handler/PinchZoomHandler.js +1 -2
  142. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +1 -2
  143. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
  144. package/dist/esm/map/handler/TapHoldHandler.js +1 -2
  145. package/dist/esm/package.js +2 -3
  146. package/dist/maplair-global-src.js +489 -613
  147. package/dist/maplair-global-src.js.map +1 -1
  148. package/dist/maplair-global.js +2 -2
  149. package/dist/maplair-global.js.map +1 -1
  150. package/dist/maplair-src.js +485 -609
  151. package/dist/maplair-src.js.map +1 -1
  152. package/dist/maplair.css +1 -1263
  153. package/dist/maplair.js +2 -2
  154. package/dist/maplair.js.map +1 -1
  155. package/package.json +4 -8
  156. package/src/Maplair.all.js +0 -1
  157. package/src/control/LayersControl.js +39 -52
  158. package/src/control/ZoomControl.js +17 -31
  159. package/src/core/Class.js +5 -14
  160. package/src/core/Events.js +2 -0
  161. package/src/core/Handler.js +11 -1
  162. package/src/core/Util.js +1 -1
  163. package/src/dom/DomEvent.js +9 -19
  164. package/src/dom/Draggable.js +5 -1
  165. package/src/geo/LatLngBounds.js +8 -15
  166. package/src/geo/crs/EPSG3395.js +3 -3
  167. package/src/geo/crs/EPSG3857.js +3 -3
  168. package/src/geo/crs/EPSG4326.js +2 -2
  169. package/src/geo/crs/SimpleCRS.js +2 -2
  170. package/src/geo/index.js +1 -2
  171. package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +1 -1
  172. package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +1 -1
  173. package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +1 -1
  174. package/src/geo/projection/index.js +5 -5
  175. package/src/geometry/Bounds.js +12 -17
  176. package/src/geometry/LineUtil.js +1 -1
  177. package/src/geometry/PolyUtil.js +23 -31
  178. package/src/layer/DivOverlay.js +1 -1
  179. package/src/layer/FeatureGroup.js +8 -2
  180. package/src/layer/GeoJSON.js +10 -13
  181. package/src/layer/HeatLayer.js +1 -1
  182. package/src/layer/ImageOverlay.js +2 -2
  183. package/src/layer/LayerGroup.js +1 -1
  184. package/src/layer/Popup.js +9 -19
  185. package/src/layer/Tooltip.js +19 -17
  186. package/src/layer/marker/DefaultIcon.js +33 -5
  187. package/src/layer/marker/Icon.js +2 -0
  188. package/src/layer/marker/Marker.Drag.js +53 -5
  189. package/src/layer/marker/Marker.Move.js +3 -4
  190. package/src/layer/marker/Marker.js +64 -13
  191. package/src/layer/tile/GridLayer.js +5 -2
  192. package/src/layer/tile/TileLayer.js +9 -6
  193. package/src/layer/tile/WMSTileLayer.js +5 -2
  194. package/src/layer/vector/Canvas.js +10 -14
  195. package/src/layer/vector/Circle.js +7 -1
  196. package/src/layer/vector/CircleMarker.js +2 -1
  197. package/src/layer/vector/Polygon.js +1 -1
  198. package/src/layer/vector/Polyline.js +1 -1
  199. package/src/layer/vector/Renderer.getRenderer.js +4 -3
  200. package/src/layer/vector/SVG.js +12 -2
  201. package/src/map/Map.Rotation.js +28 -4
  202. package/src/map/Map.js +17 -21
  203. package/src/map/handler/BoxZoomHandler.js +21 -42
  204. package/src/map/handler/KeyboardHandler.js +34 -53
  205. package/src/maplair.css +5 -0
  206. package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
  207. package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
  208. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
  209. package/dist/esm/geo/projection/index.js +0 -14
  210. package/dist/esm/geo/projection/index.js.map +0 -1
  211. package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
  212. package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
  213. package/src/layer/marker/Marker.Rotation.js +0 -103
@@ -43,11 +43,6 @@ export class BoxZoomHandler extends Handler {
43
43
  */
44
44
  constructor(map) {
45
45
  super(map);
46
- this._container = map._container;
47
- this._pane = map._panes.overlayPane;
48
- this._resetStateTimeout = 0;
49
- map.on('unload', this._destroy, this);
50
-
51
46
  this.callInitHooks(BoxZoomHandler);
52
47
  }
53
48
 
@@ -55,14 +50,14 @@ export class BoxZoomHandler extends Handler {
55
50
  * Called when the handler is enabled, adds the event hooks.
56
51
  */
57
52
  addHooks() {
58
- DomEvent.on(this._container, 'pointerdown', this._onPointerDown, this);
53
+ DomEvent.on(this._map._container, 'pointerdown', this._onPointerDown, this);
59
54
  }
60
55
 
61
56
  /**
62
57
  * Called when the handler is disabled, removes the event hooks.
63
58
  */
64
59
  removeHooks() {
65
- DomEvent.off(this._container, 'pointerdown', this._onPointerDown, this);
60
+ DomEvent.off(this._map._container, 'pointerdown', this._onPointerDown, this);
66
61
  }
67
62
 
68
63
  /**
@@ -73,29 +68,24 @@ export class BoxZoomHandler extends Handler {
73
68
  return this._moved;
74
69
  }
75
70
 
76
- _destroy() {
77
- this._pane.remove();
78
- delete this._pane;
79
- }
80
-
81
71
  _resetState() {
82
- this._resetStateTimeout = 0;
72
+ clearTimeout(this._resetStateTimeout);
83
73
  this._moved = false;
84
74
  }
85
75
 
86
- _clearDeferredResetState() {
87
- if (this._resetStateTimeout !== 0) {
88
- clearTimeout(this._resetStateTimeout);
89
- this._resetStateTimeout = 0;
90
- }
76
+ _toggleListeners(onOff) {
77
+ onOff(this._map._container, {
78
+ contextmenu: DomEvent.stop,
79
+ pointermove: this._onPointerMove,
80
+ pointerup: this._onPointerUp
81
+ }, this);
82
+ onOff(document, 'keydown', this._onKeyDown, this);
91
83
  }
92
84
 
93
85
  _onPointerDown(e) {
94
86
  if (!e.shiftKey || (e.button !== 0)) { return false; }
95
87
 
96
- // Clear the deferred resetState if it hasn't executed yet, otherwise it
97
- // will interrupt the interaction and orphan a box element in the container.
98
- this._clearDeferredResetState();
88
+ // also cancels a deferred reset that hasn't run yet, which would interrupt the interaction and orphan a box
99
89
  this._resetState();
100
90
 
101
91
  // stops both text selection and native image drag in every engine without restyling the page; it also
@@ -104,26 +94,22 @@ export class BoxZoomHandler extends Handler {
104
94
 
105
95
  this._startPoint = this._map.pointerEventToContainerPoint(e);
106
96
 
107
- DomEvent.on(this._container, {
108
- contextmenu: DomEvent.stop,
109
- pointermove: this._onPointerMove,
110
- pointerup: this._onPointerUp,
111
- keydown: this._onKeyDown
112
- }, this);
113
- DomEvent.on(document, 'keydown', this._onKeyDown, this);
97
+ this._toggleListeners(DomEvent.on);
114
98
  }
115
99
 
116
100
  _onPointerMove(e) {
101
+ const map = this._map;
102
+
117
103
  if (!this._moved) {
118
104
  this._moved = true;
119
105
 
120
- this._box = DomUtil.create('div', 'maplair-zoom-box', this._container);
121
- this._container.classList.add('maplair-crosshair');
106
+ this._box = DomUtil.create('div', 'maplair-zoom-box', map._container);
107
+ map._container.classList.add('maplair-crosshair');
122
108
 
123
- this._map.fire('boxzoomstart');
109
+ map.fire('boxzoomstart');
124
110
  }
125
111
 
126
- this._point = this._map.pointerEventToContainerPoint(e);
112
+ this._point = map.pointerEventToContainerPoint(e);
127
113
 
128
114
  const bounds = new Bounds(this._point, this._startPoint),
129
115
  size = bounds.getSize();
@@ -137,15 +123,10 @@ export class BoxZoomHandler extends Handler {
137
123
  _finish() {
138
124
  if (this._moved) {
139
125
  this._box.remove();
140
- this._container.classList.remove('maplair-crosshair');
126
+ this._map._container.classList.remove('maplair-crosshair');
141
127
  }
142
128
 
143
- DomEvent.off(this._container, {
144
- contextmenu: DomEvent.stop,
145
- pointermove: this._onPointerMove,
146
- pointerup: this._onPointerUp,
147
- }, this);
148
- DomEvent.off(document, 'keydown', this._onKeyDown, this);
129
+ this._toggleListeners(DomEvent.off);
149
130
  }
150
131
 
151
132
  _onPointerUp(e) {
@@ -156,8 +137,7 @@ export class BoxZoomHandler extends Handler {
156
137
  if (!this._moved) { return; }
157
138
  // Postpone to next JS tick so internal click event handling
158
139
  // still see it as "moved".
159
- this._clearDeferredResetState();
160
- this._resetStateTimeout = setTimeout(this._resetState.bind(this), 0);
140
+ this._resetStateTimeout = setTimeout(() => this._resetState(), 0);
161
141
 
162
142
  const bounds = new LatLngBounds(
163
143
  this._map.containerPointToLatLng(this._startPoint),
@@ -175,7 +155,6 @@ export class BoxZoomHandler extends Handler {
175
155
  _onKeyDown(e) {
176
156
  if (e.code === 'Escape') {
177
157
  this._finish();
178
- this._clearDeferredResetState();
179
158
  this._resetState();
180
159
  }
181
160
  }
@@ -57,10 +57,6 @@ export class KeyboardHandler extends Handler {
57
57
  */
58
58
  constructor(map) {
59
59
  super(map);
60
-
61
- this._setPanDelta(map.options.keyboardPanDelta);
62
- this._setZoomDelta(map.options.zoomDelta);
63
-
64
60
  this.callInitHooks(KeyboardHandler);
65
61
  }
66
62
 
@@ -85,12 +81,8 @@ export class KeyboardHandler extends Handler {
85
81
  on(container, {
86
82
  focus: this._onFocus,
87
83
  blur: this._onBlur,
88
- pointerdown: this._onPointerDown
89
- }, this);
90
-
91
- this._map.on({
92
- focus: this._addHooks,
93
- blur: this._removeHooks
84
+ pointerdown: this._onPointerDown,
85
+ keydown: this._onContainerKeyDown
94
86
  }, this);
95
87
  }
96
88
 
@@ -98,7 +90,7 @@ export class KeyboardHandler extends Handler {
98
90
  * Called when the handler is disabled, removes the event hooks.
99
91
  */
100
92
  removeHooks() {
101
- this._removeHooks();
93
+ off(document, 'keydown', this._onKeyDown, this);
102
94
 
103
95
  if (this._map.options.ariaKeyShortcuts) {
104
96
  this._map._container.removeAttribute('aria-keyshortcuts');
@@ -107,12 +99,8 @@ export class KeyboardHandler extends Handler {
107
99
  off(this._map._container, {
108
100
  focus: this._onFocus,
109
101
  blur: this._onBlur,
110
- pointerdown: this._onPointerDown
111
- }, this);
112
-
113
- this._map.off({
114
- focus: this._addHooks,
115
- blur: this._removeHooks
102
+ pointerdown: this._onPointerDown,
103
+ keydown: this._onContainerKeyDown
116
104
  }, this);
117
105
 
118
106
  this._help?.remove();
@@ -166,38 +154,34 @@ export class KeyboardHandler extends Handler {
166
154
 
167
155
  _onFocus() {
168
156
  this._focused = true;
157
+ on(document, 'keydown', this._onKeyDown, this);
169
158
  this._map.fire('focus');
170
159
  }
171
160
 
172
161
  _onBlur() {
173
162
  this._focused = false;
163
+ off(document, 'keydown', this._onKeyDown, this);
174
164
  this._map.fire('blur');
175
165
  }
176
166
 
177
- _setPanDelta(panDelta) {
178
- const panKeys = this._panKeys = {},
179
- {left, right, down, up} = KeyboardHandler.keys;
167
+ // on the container rather than the document, so that Escape also works when focus is on a marker or
168
+ // inside the popup, which blurs the container and removes the document listener; controls are left
169
+ // out so that e.g. Escape in a geocoder input doesn't close an unrelated popup
170
+ _onContainerKeyDown(e) {
171
+ const map = this._map,
172
+ popup = map._popup;
180
173
 
181
- for (const key of left) { panKeys[key] = [-panDelta, 0]; }
182
- for (const key of right) { panKeys[key] = [panDelta, 0]; }
183
- for (const key of down) { panKeys[key] = [0, panDelta]; }
184
- for (const key of up) { panKeys[key] = [0, -panDelta]; }
185
- }
174
+ if (e.key !== 'Escape' || e.defaultPrevented || !popup?.options.closeOnEscapeKey ||
175
+ map._controlContainer?.contains(e.target)) { return; }
186
176
 
187
- _setZoomDelta(zoomDelta) {
188
- const zoomKeys = this._zoomKeys = {},
189
- {zoomIn, zoomOut} = KeyboardHandler.keys;
177
+ const inPopup = popup._container.contains(e.target),
178
+ icon = popup._source?._icon;
190
179
 
191
- for (const key of zoomIn) { zoomKeys[key] = zoomDelta; }
192
- for (const key of zoomOut) { zoomKeys[key] = -zoomDelta; }
193
- }
180
+ map.closePopup();
181
+ e.preventDefault();
194
182
 
195
- _addHooks() {
196
- on(document, 'keydown', this._onKeyDown, this);
197
- }
198
-
199
- _removeHooks() {
200
- off(document, 'keydown', this._onKeyDown, this);
183
+ // closing removes the focused element, which would send focus back to the start of the page
184
+ if (inPopup) { (icon?.tabIndex >= 0 ? icon : map._container).focus(); }
201
185
  }
202
186
 
203
187
  _onKeyDown(e) {
@@ -210,32 +194,29 @@ export class KeyboardHandler extends Handler {
210
194
  }
211
195
 
212
196
  const key = e.key,
213
- map = this._map;
214
- let offset;
215
-
216
- if (key in this._panKeys) {
217
- if (!map._panAnim || !map._panAnim._inProgress) {
218
- offset = this._panKeys[key];
219
- if (e.shiftKey) {
220
- offset = Point.from(offset).multiplyBy(3);
221
- }
222
-
197
+ map = this._map,
198
+ {left, right, down, up, zoomIn, zoomOut} = KeyboardHandler.keys,
199
+ x = +right.includes(key) - +left.includes(key),
200
+ y = +down.includes(key) - +up.includes(key),
201
+ dz = +zoomIn.includes(key) - +zoomOut.includes(key),
202
+ k = e.shiftKey ? 3 : 1;
203
+
204
+ if (x || y) {
205
+ if (!map._panAnim?._inProgress) {
206
+ let offset = new Point(x, y).multiplyBy(k * map.options.keyboardPanDelta);
223
207
  if (map.options.maxBounds) {
224
- offset = map._limitOffset(Point.from(offset), map.options.maxBounds);
208
+ offset = map._limitOffset(offset, map.options.maxBounds);
225
209
  }
226
210
 
227
211
  map._setUserEvent(e);
228
212
  map.panBy(offset);
229
213
  }
230
- } else if (key in this._zoomKeys) {
214
+ } else if (dz) {
231
215
  if (!map._zoomInputBlocked()) {
232
216
  map._setUserEvent(e);
233
- map.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]);
217
+ map.setZoom(map.getZoom() + k * dz * map.options.zoomDelta);
234
218
  }
235
219
 
236
- } else if (key === 'Escape' && map._popup && map._popup.options.closeOnEscapeKey) {
237
- map.closePopup();
238
-
239
220
  } else {
240
221
  return;
241
222
  }
package/src/maplair.css CHANGED
@@ -67,6 +67,10 @@
67
67
  position: absolute;
68
68
  left: 0;
69
69
  top: 0;
70
+ }
71
+
72
+ /* gives popups room to grow to their max-width; not set on icons and layers, which are sized by JS or content */
73
+ .maplair-pane {
70
74
  width: 100%;
71
75
  }
72
76
 
@@ -108,6 +112,7 @@
108
112
 
109
113
  .maplair-container {
110
114
  overflow: hidden;
115
+ isolation: isolate;
111
116
 
112
117
  .maplair-overlay-pane svg {
113
118
  max-width: none !important;
@@ -1 +0,0 @@
1
- {"version":3,"file":"Projection.LonLat.js","names":[],"sources":["../../../../src/geo/projection/Projection.LonLat.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\n/**\n * Equirectangular, or Plate Carree projection — the most simple projection,\n * mostly used by GIS enthusiasts. Directly maps `x` as longitude, and `y` as\n * latitude. Also suitable for flat worlds, e.g. game maps. Used by the\n * `EPSG4326` and `SimpleCRS` CRS.\n * @type {Projection}\n */\nexport const LonLat = {\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\treturn new Point(latlng.lng, latlng.lat);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\treturn new LatLng(point.y, point.x);\n\t},\n\n\tbounds: /* @__PURE__ */ new Bounds([-180, -90], [180, 90])\n};\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,SAAS;CACrB,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,OAAO,IAAI,MAAM,OAAO,KAAK,OAAO,GAAG;CACxC;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,CAAC;CACnC;CAEA,wBAAwB,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;AAC1D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Projection.Mercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.Mercator.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Elliptical Mercator projection — more complex than Spherical Mercator. Assumes that\n * Earth is an ellipsoid. Used by the EPSG:3395 CRS.\n * @type {Projection & {R: number, R_MINOR: number}}\n */\nexport const Mercator = {\n\tR: earthRadius,\n\tR_MINOR: 6356752.314245179,\n\n\tbounds: /* @__PURE__ */ new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),\n\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp);\n\t\tlet y = latlng.lat * d;\n\t\tconst con = e * Math.sin(y);\n\n\t\tconst ts = Math.tan(Math.PI / 4 - y / 2) / ((1 - con) / (1 + con)) ** (e / 2);\n\t\ty = -r * Math.log(Math.max(ts, 1E-10));\n\n\t\treturn new Point(latlng.lng * d * r, y);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\tconst d = 180 / Math.PI,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp),\n\t\tts = Math.exp(-point.y / r);\n\t\tlet phi = Math.PI / 2 - 2 * Math.atan(ts);\n\n\t\tfor (let i = 0, dphi = 0.1, con; i < 15 && Math.abs(dphi) > 1e-7; i++) {\n\t\t\tcon = e * Math.sin(phi);\n\t\t\tcon = ((1 - con) / (1 + con)) ** (e / 2);\n\t\t\tdphi = Math.PI / 2 - 2 * Math.atan(ts * con) - phi;\n\t\t\tphi += dphi;\n\t\t}\n\n\t\treturn new LatLng(phi * d, point.x * d / r);\n\t}\n};\n"],"mappings":";;;;;;;;AAaA,MAAa,WAAW;CACvB,GAAG;CACH,SAAS;CAET,wBAAwB,IAAI,OAAO,CAAC,iBAAiB,eAAe,GAAG,CAAC,gBAAgB,cAAc,CAAC;CAEvG,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,MAAM,IAAI,KAAK,KAAK,KACpB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG;EAC3B,IAAI,IAAI,OAAO,MAAM;EACrB,MAAM,MAAM,IAAI,KAAK,IAAI,CAAC;EAE1B,MAAM,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ,IAAI,UAAU,IAAI;EAC3E,IAAI,CAAC,IAAI,KAAK,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC;EAErC,OAAO,IAAI,MAAM,OAAO,MAAM,IAAI,GAAG,CAAC;CACvC;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,MAAM,IAAI,MAAM,KAAK,IACrB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG,GAC3B,KAAK,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC;EAC1B,IAAI,MAAM,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE;EAExC,KAAK,IAAI,IAAI,GAAG,OAAO,IAAK,KAAK,IAAI,MAAM,KAAK,IAAI,IAAI,IAAI,MAAM,KAAK;GACtE,MAAM,IAAI,KAAK,IAAI,GAAG;GACtB,QAAQ,IAAI,QAAQ,IAAI,UAAU,IAAI;GACtC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,GAAG,IAAI;GAC/C,OAAO;EACR;EAEA,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;CAC3C;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Projection.SphericalMercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.SphericalMercator.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Spherical Mercator projection — the most common projection for online maps,\n * used by almost all free and commercial tile providers. Assumes that Earth is\n * a sphere. Used by the `EPSG:3857` CRS.\n * @type {Projection & {R: number, MAX_LATITUDE: number}}\n */\nexport const SphericalMercator = {\n\n\tR: earthRadius,\n\tMAX_LATITUDE: 85.0511287798,\n\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tmax = this.MAX_LATITUDE,\n\t\tlat = Math.max(Math.min(max, latlng.lat), -max),\n\t\tsin = Math.sin(lat * d);\n\n\t\treturn new Point(\n\t\t\tthis.R * latlng.lng * d,\n\t\t\tthis.R * Math.log((1 + sin) / (1 - sin)) / 2);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\tconst d = 180 / Math.PI;\n\n\t\treturn new LatLng(\n\t\t\t(2 * Math.atan(Math.exp(point.y / this.R)) - (Math.PI / 2)) * d,\n\t\t\tpoint.x * d / this.R);\n\t},\n\n\tbounds: /* @__PURE__ */ (() => {\n\t\tconst d = earthRadius * Math.PI;\n\t\treturn new Bounds([-d, -d], [d, d]);\n\t})()\n};\n"],"mappings":";;;;;AAMA,MAAM,cAAc;;;;;;;AAQpB,MAAa,oBAAoB;CAEhC,GAAG;CACH,cAAc;CAEd,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,MAAM,IAAI,KAAK,KAAK,KACpB,MAAM,KAAK,cACX,MAAM,KAAK,IAAI,KAAK,IAAI,KAAK,OAAO,GAAG,GAAG,CAAC,GAAG,GAC9C,MAAM,KAAK,IAAI,MAAM,CAAC;EAEtB,OAAO,IAAI,MACV,KAAK,IAAI,OAAO,MAAM,GACtB,KAAK,IAAI,KAAK,KAAK,IAAI,QAAQ,IAAI,IAAI,IAAI,CAAC;CAC9C;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,MAAM,IAAI,MAAM,KAAK;EAErB,OAAO,IAAI,QACT,IAAI,KAAK,KAAK,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,IAAK,KAAK,KAAK,KAAM,GAC9D,MAAM,IAAI,IAAI,KAAK,CAAC;CACtB;CAEA,QAAwB,uBAAO;EAC9B,MAAM,IAAI,cAAc,KAAK;EAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACnC,EAAA,CAAG;AACJ"}
@@ -1,14 +0,0 @@
1
- import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
2
- import { SphericalMercator } from "./Projection.SphericalMercator.js";
3
- import { LonLat } from "./Projection.LonLat.js";
4
- import { Mercator } from "./Projection.Mercator.js";
5
- //#region src/geo/projection/index.js
6
- var projection_exports = /* @__PURE__ */ __exportAll({
7
- LonLat: () => LonLat,
8
- Mercator: () => Mercator,
9
- SphericalMercator: () => SphericalMercator
10
- });
11
- //#endregion
12
- export { LonLat, Mercator, SphericalMercator, projection_exports };
13
-
14
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/geo/projection/index.js"],"sourcesContent":["/** @import {Bounds} from '../../geometry/Bounds.js' */\n/** @import {Point} from '../../geometry/Point.js' */\n/** @import {LatLng} from '../LatLng.js' */\n\n/**\n * An object with methods for projecting geographical coordinates of the world onto\n * a flat surface (and back). See [Map projection](https://en.wikipedia.org/wiki/Map_projection).\n *\n * Maplair comes with a set of already defined projections out of the box: `LonLat`,\n * `Mercator` and `SphericalMercator` (in the `Projection` namespace).\n *\n * Note that the projection instances do not inherit from Maplair's `Class` object,\n * and can't be instantiated. Also, new classes can't inherit from them,\n * and methods can't be added to them with the `include` function.\n *\n * @typedef {object} Projection\n * @property {Bounds} bounds The bounds (specified in CRS units) where the projection is\n * valid.\n * @property {(latlng: LatLng) => Point} project Projects geographical coordinates into\n * a 2D point. Only accepts actual `LatLng` instances, not arrays.\n * @property {(point: Point) => LatLng} unproject The inverse of `project`. Projects a\n * 2D point into a geographical location. Only accepts actual `Point` instances, not\n * arrays.\n */\n\nexport {LonLat} from './Projection.LonLat.js';\nexport {Mercator} from './Projection.Mercator.js';\nexport {SphericalMercator} from './Projection.SphericalMercator.js';\n"],"mappings":""}
@@ -1,70 +0,0 @@
1
- import { MarkerDrag } from "./Marker.Drag.js";
2
- import { Marker } from "./Marker.js";
3
- //#region src/layer/marker/Marker.Rotation.js
4
- const { _setPos: setPos } = Marker.prototype, { _onDrag: onDrag } = MarkerDrag.prototype;
5
- /**
6
- * Options of `Marker` for the rotation of marker icons, see the
7
- * [marker rotation](#marker-setrotationangle).
8
- * @typedef {object} MarkerRotationOptions
9
- * @lends MarkerOptions
10
- * @property {number} [rotationAngle=0] Rotation of the icon in degrees, clockwise, e.g.
11
- * for the heading of a vehicle. On a rotated map, the angle is relative to the screen,
12
- * or to north with `rotateWithView`. The shadow is not rotated.
13
- * @property {string} [rotationOrigin] The CSS
14
- * [`transform-origin`](https://developer.mozilla.org/docs/Web/CSS/transform-origin) to
15
- * rotate the icon around, e.g. `'center'`. By default the anchor of the icon.
16
- * @property {boolean} [rotateWithView=false] On a rotated map (see
17
- * `MaplairMap.setBearing()`), whether the icon rotates with the map (e.g. for arrows
18
- * pointing in a geographic direction) instead of staying upright.
19
- */
20
- Marker.include({ options: {
21
- rotationAngle: 0,
22
- rotationOrigin: void 0,
23
- rotateWithView: false
24
- } });
25
- /** @typedef {typeof markerRotationMethods} MarkerRotationMethods */
26
- Marker.include({
27
- /**
28
- * Changes the [`rotationAngle`](#markeroptions-rotationangle) of the icon.
29
- * @group Marker rotation
30
- * @param {number} angle
31
- * @returns {this}
32
- */
33
- setRotationAngle(angle) {
34
- this.options.rotationAngle = angle;
35
- return this.update();
36
- },
37
- /**
38
- * Changes the [`rotationOrigin`](#markeroptions-rotationorigin) of the icon.
39
- * @group Marker rotation
40
- * @param {string} origin
41
- * @returns {this}
42
- */
43
- setRotationOrigin(origin) {
44
- this.options.rotationOrigin = origin;
45
- return this.update();
46
- },
47
- _setPos(pos) {
48
- setPos.call(this, pos);
49
- this._rotateIcon();
50
- },
51
- _rotateIcon() {
52
- const bearing = this.options.rotateWithView ? 0 : this._map?.getBearing?.() ?? 0;
53
- this._rotateElement(this._icon, bearing + (this.options.rotationAngle || 0), this.options.rotationOrigin);
54
- this._rotateElement(this._shadow, bearing);
55
- },
56
- _rotateElement(el, angle, origin) {
57
- if (!el) return;
58
- if (angle % 360) {
59
- el.style.transform += ` rotate(${angle}deg)`;
60
- el.style.transformOrigin = origin ?? `${-parseFloat(el.style.marginLeft) || 0}px ${-parseFloat(el.style.marginTop) || 0}px`;
61
- } else if (el.style.transformOrigin) el.style.transformOrigin = "";
62
- }
63
- });
64
- MarkerDrag.include({ _onDrag(e) {
65
- onDrag.call(this, e);
66
- this._marker._rotateIcon();
67
- } });
68
- //#endregion
69
-
70
- //# sourceMappingURL=Marker.Rotation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Marker.Rotation.js","names":[],"sources":["../../../../src/layer/marker/Marker.Rotation.js"],"sourcesContent":["import {Marker} from './Marker.js';\nimport {MarkerDrag} from './Marker.Drag.js';\n\n// The methods extended below\nconst {_setPos: setPos} = Marker.prototype,\n{_onDrag: onDrag} = MarkerDrag.prototype;\n\n/**\n * Options of `Marker` for the rotation of marker icons, see the\n * [marker rotation](#marker-setrotationangle).\n * @typedef {object} MarkerRotationOptions\n * @lends MarkerOptions\n * @property {number} [rotationAngle=0] Rotation of the icon in degrees, clockwise, e.g.\n * for the heading of a vehicle. On a rotated map, the angle is relative to the screen,\n * or to north with `rotateWithView`. The shadow is not rotated.\n * @property {string} [rotationOrigin] The CSS\n * [`transform-origin`](https://developer.mozilla.org/docs/Web/CSS/transform-origin) to\n * rotate the icon around, e.g. `'center'`. By default the anchor of the icon.\n * @property {boolean} [rotateWithView=false] On a rotated map (see\n * `MaplairMap.setBearing()`), whether the icon rotates with the map (e.g. for arrows\n * pointing in a geographic direction) instead of staying upright.\n */\nMarker.include({\n\toptions: {\n\t\trotationAngle: 0,\n\t\trotationOrigin: undefined,\n\t\trotateWithView: false\n\t}\n});\n\n/**\n * Methods of `Marker` for the rotation of marker icons, an optional feature: import\n * this module to add the `rotationAngle`, `rotationOrigin` and `rotateWithView` options\n * and `setRotationAngle()`/`setRotationOrigin()` to `Marker` (it is also part of the\n * map rotation, see `MaplairMap.setBearing()`).\n *\n * ```js\n * import 'maplair/marker-rotation';\n *\n * new Marker([47.27, 11.40], {rotationAngle: 45}).addTo(map);\n * ```\n *\n * Inspired by the [Leaflet.RotatedMarker](https://github.com/bbecquet/Leaflet.RotatedMarker) plugin.\n * @lends Marker.prototype\n */\nconst markerRotationMethods = {\n\t/**\n\t * Changes the [`rotationAngle`](#markeroptions-rotationangle) of the icon.\n\t * @group Marker rotation\n\t * @param {number} angle\n\t * @returns {this}\n\t */\n\tsetRotationAngle(angle) {\n\t\tthis.options.rotationAngle = angle;\n\t\treturn this.update();\n\t},\n\n\t/**\n\t * Changes the [`rotationOrigin`](#markeroptions-rotationorigin) of the icon.\n\t * @group Marker rotation\n\t * @param {string} origin\n\t * @returns {this}\n\t */\n\tsetRotationOrigin(origin) {\n\t\tthis.options.rotationOrigin = origin;\n\t\treturn this.update();\n\t},\n\n\t_setPos(pos) {\n\t\tsetPos.call(this, pos);\n\t\tthis._rotateIcon();\n\t},\n\n\t// Rotates the icon by the `rotationAngle`, and keeps the icon and the shadow\n\t// upright on a rotated map\n\t_rotateIcon() {\n\t\tconst bearing = this.options.rotateWithView ? 0 : (this._map?.getBearing?.() ?? 0);\n\t\tthis._rotateElement(this._icon, bearing + (this.options.rotationAngle || 0), this.options.rotationOrigin);\n\t\tthis._rotateElement(this._shadow, bearing);\n\t},\n\n\t// Rotates an element positioned with `DomUtil.setPosition()` around its anchor (or `origin`)\n\t_rotateElement(el, angle, origin) {\n\t\tif (!el) { return; }\n\t\tif (angle % 360) {\n\t\t\tel.style.transform += ` rotate(${angle}deg)`;\n\t\t\tel.style.transformOrigin = origin ?? `${-parseFloat(el.style.marginLeft) || 0}px ${-parseFloat(el.style.marginTop) || 0}px`;\n\t\t} else if (el.style.transformOrigin) {\n\t\t\tel.style.transformOrigin = '';\n\t\t}\n\t}\n};\n/** @typedef {typeof markerRotationMethods} MarkerRotationMethods */\n\nMarker.include(markerRotationMethods);\n\nMarkerDrag.include({\n\t_onDrag(e) {\n\t\tonDrag.call(this, e);\n\t\t// dragging positions the icon without the rotation\n\t\tthis._marker._rotateIcon();\n\t}\n});\n"],"mappings":";;;AAIA,MAAM,EAAC,SAAS,WAAU,OAAO,WACjC,EAAC,SAAS,WAAU,WAAW;;;;;;;;;;;;;;;;AAiB/B,OAAO,QAAQ,EACd,SAAS;CACR,eAAe;CACf,gBAAgB,KAAA;CAChB,gBAAgB;AACjB,EACD,CAAC;;AAkED,OAAO,QAAQ;;;;;;;CA1Cd,iBAAiB,OAAO;EACvB,KAAK,QAAQ,gBAAgB;EAC7B,OAAO,KAAK,OAAO;CACpB;;;;;;;CAQA,kBAAkB,QAAQ;EACzB,KAAK,QAAQ,iBAAiB;EAC9B,OAAO,KAAK,OAAO;CACpB;CAEA,QAAQ,KAAK;EACZ,OAAO,KAAK,MAAM,GAAG;EACrB,KAAK,YAAY;CAClB;CAIA,cAAc;EACb,MAAM,UAAU,KAAK,QAAQ,iBAAiB,IAAK,KAAK,MAAM,aAAa,KAAK;EAChF,KAAK,eAAe,KAAK,OAAO,WAAW,KAAK,QAAQ,iBAAiB,IAAI,KAAK,QAAQ,cAAc;EACxG,KAAK,eAAe,KAAK,SAAS,OAAO;CAC1C;CAGA,eAAe,IAAI,OAAO,QAAQ;EACjC,IAAI,CAAC,IAAM;EACX,IAAI,QAAQ,KAAK;GAChB,GAAG,MAAM,aAAa,WAAW,MAAM;GACvC,GAAG,MAAM,kBAAkB,UAAU,GAAG,CAAC,WAAW,GAAG,MAAM,UAAU,KAAK,EAAE,KAAK,CAAC,WAAW,GAAG,MAAM,SAAS,KAAK,EAAE;EACzH,OAAO,IAAI,GAAG,MAAM,iBACnB,GAAG,MAAM,kBAAkB;CAE7B;AAIkC,CAAC;AAEpC,WAAW,QAAQ,EAClB,QAAQ,GAAG;CACV,OAAO,KAAK,MAAM,CAAC;CAEnB,KAAK,QAAQ,YAAY;AAC1B,EACD,CAAC"}
@@ -1,103 +0,0 @@
1
- import {Marker} from './Marker.js';
2
- import {MarkerDrag} from './Marker.Drag.js';
3
-
4
- // The methods extended below
5
- const {_setPos: setPos} = Marker.prototype,
6
- {_onDrag: onDrag} = MarkerDrag.prototype;
7
-
8
- /**
9
- * Options of `Marker` for the rotation of marker icons, see the
10
- * [marker rotation](#marker-setrotationangle).
11
- * @typedef {object} MarkerRotationOptions
12
- * @lends MarkerOptions
13
- * @property {number} [rotationAngle=0] Rotation of the icon in degrees, clockwise, e.g.
14
- * for the heading of a vehicle. On a rotated map, the angle is relative to the screen,
15
- * or to north with `rotateWithView`. The shadow is not rotated.
16
- * @property {string} [rotationOrigin] The CSS
17
- * [`transform-origin`](https://developer.mozilla.org/docs/Web/CSS/transform-origin) to
18
- * rotate the icon around, e.g. `'center'`. By default the anchor of the icon.
19
- * @property {boolean} [rotateWithView=false] On a rotated map (see
20
- * `MaplairMap.setBearing()`), whether the icon rotates with the map (e.g. for arrows
21
- * pointing in a geographic direction) instead of staying upright.
22
- */
23
- Marker.include({
24
- options: {
25
- rotationAngle: 0,
26
- rotationOrigin: undefined,
27
- rotateWithView: false
28
- }
29
- });
30
-
31
- /**
32
- * Methods of `Marker` for the rotation of marker icons, an optional feature: import
33
- * this module to add the `rotationAngle`, `rotationOrigin` and `rotateWithView` options
34
- * and `setRotationAngle()`/`setRotationOrigin()` to `Marker` (it is also part of the
35
- * map rotation, see `MaplairMap.setBearing()`).
36
- *
37
- * ```js
38
- * import 'maplair/marker-rotation';
39
- *
40
- * new Marker([47.27, 11.40], {rotationAngle: 45}).addTo(map);
41
- * ```
42
- *
43
- * Inspired by the [Leaflet.RotatedMarker](https://github.com/bbecquet/Leaflet.RotatedMarker) plugin.
44
- * @lends Marker.prototype
45
- */
46
- const markerRotationMethods = {
47
- /**
48
- * Changes the [`rotationAngle`](#markeroptions-rotationangle) of the icon.
49
- * @group Marker rotation
50
- * @param {number} angle
51
- * @returns {this}
52
- */
53
- setRotationAngle(angle) {
54
- this.options.rotationAngle = angle;
55
- return this.update();
56
- },
57
-
58
- /**
59
- * Changes the [`rotationOrigin`](#markeroptions-rotationorigin) of the icon.
60
- * @group Marker rotation
61
- * @param {string} origin
62
- * @returns {this}
63
- */
64
- setRotationOrigin(origin) {
65
- this.options.rotationOrigin = origin;
66
- return this.update();
67
- },
68
-
69
- _setPos(pos) {
70
- setPos.call(this, pos);
71
- this._rotateIcon();
72
- },
73
-
74
- // Rotates the icon by the `rotationAngle`, and keeps the icon and the shadow
75
- // upright on a rotated map
76
- _rotateIcon() {
77
- const bearing = this.options.rotateWithView ? 0 : (this._map?.getBearing?.() ?? 0);
78
- this._rotateElement(this._icon, bearing + (this.options.rotationAngle || 0), this.options.rotationOrigin);
79
- this._rotateElement(this._shadow, bearing);
80
- },
81
-
82
- // Rotates an element positioned with `DomUtil.setPosition()` around its anchor (or `origin`)
83
- _rotateElement(el, angle, origin) {
84
- if (!el) { return; }
85
- if (angle % 360) {
86
- el.style.transform += ` rotate(${angle}deg)`;
87
- el.style.transformOrigin = origin ?? `${-parseFloat(el.style.marginLeft) || 0}px ${-parseFloat(el.style.marginTop) || 0}px`;
88
- } else if (el.style.transformOrigin) {
89
- el.style.transformOrigin = '';
90
- }
91
- }
92
- };
93
- /** @typedef {typeof markerRotationMethods} MarkerRotationMethods */
94
-
95
- Marker.include(markerRotationMethods);
96
-
97
- MarkerDrag.include({
98
- _onDrag(e) {
99
- onDrag.call(this, e);
100
- // dragging positions the icon without the rotation
101
- this._marker._rotateIcon();
102
- }
103
- });