maplair 4.1.0 → 4.2.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 (211) hide show
  1. package/CHANGELOG.md +60 -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 +1 -2
  25. package/dist/esm/core/Handler.js +10 -3
  26. package/dist/esm/core/Handler.js.map +1 -1
  27. package/dist/esm/core/I18n.js +1 -2
  28. package/dist/esm/core/Util.js +2 -3
  29. package/dist/esm/core/Util.js.map +1 -1
  30. package/dist/esm/dom/DomEvent.DoubleTap.js +1 -2
  31. package/dist/esm/dom/DomEvent.PointerEvents.js +1 -2
  32. package/dist/esm/dom/DomEvent.js +10 -18
  33. package/dist/esm/dom/DomEvent.js.map +1 -1
  34. package/dist/esm/dom/DomUtil.js +1 -2
  35. package/dist/esm/dom/Draggable.js +4 -3
  36. package/dist/esm/dom/Draggable.js.map +1 -1
  37. package/dist/esm/dom/PosAnimation.js +1 -2
  38. package/dist/esm/geo/LatLng.js +1 -2
  39. package/dist/esm/geo/LatLngBounds.js +9 -15
  40. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  41. package/dist/esm/geo/crs/CRS.js +1 -2
  42. package/dist/esm/geo/crs/EPSG3395.js +4 -5
  43. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  44. package/dist/esm/geo/crs/EPSG3857.js +4 -5
  45. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  46. package/dist/esm/geo/crs/EPSG4326.js +3 -4
  47. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  48. package/dist/esm/geo/crs/EarthCRS.js +1 -2
  49. package/dist/esm/geo/crs/SimpleCRS.js +3 -4
  50. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  51. package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +4 -5
  52. package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
  53. package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +3 -4
  54. package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
  55. package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +4 -5
  56. package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
  57. package/dist/esm/geometry/Bounds.js +10 -14
  58. package/dist/esm/geometry/Bounds.js.map +1 -1
  59. package/dist/esm/geometry/LineUtil.js +2 -3
  60. package/dist/esm/geometry/LineUtil.js.map +1 -1
  61. package/dist/esm/geometry/Point.js +1 -2
  62. package/dist/esm/geometry/PolyUtil.js +17 -25
  63. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  64. package/dist/esm/geometry/Transformation.js +1 -2
  65. package/dist/esm/layer/BlanketOverlay.js +1 -2
  66. package/dist/esm/layer/Classification.js +1 -2
  67. package/dist/esm/layer/DivOverlay.js +2 -3
  68. package/dist/esm/layer/DivOverlay.js.map +1 -1
  69. package/dist/esm/layer/FeatureGroup.js +5 -4
  70. package/dist/esm/layer/FeatureGroup.js.map +1 -1
  71. package/dist/esm/layer/GeoJSON.Load.js +1 -2
  72. package/dist/esm/layer/GeoJSON.js +8 -10
  73. package/dist/esm/layer/GeoJSON.js.map +1 -1
  74. package/dist/esm/layer/GeoJSONUtil.js +1 -2
  75. package/dist/esm/layer/HeatLayer.js +2 -3
  76. package/dist/esm/layer/HeatLayer.js.map +1 -1
  77. package/dist/esm/layer/ImageOverlay.js +2 -3
  78. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  79. package/dist/esm/layer/Layer.js +1 -2
  80. package/dist/esm/layer/LayerGroup.js +2 -3
  81. package/dist/esm/layer/LayerGroup.js.map +1 -1
  82. package/dist/esm/layer/Popup.js +9 -16
  83. package/dist/esm/layer/Popup.js.map +1 -1
  84. package/dist/esm/layer/SVGOverlay.js +1 -2
  85. package/dist/esm/layer/Tooltip.js +16 -17
  86. package/dist/esm/layer/Tooltip.js.map +1 -1
  87. package/dist/esm/layer/VideoOverlay.js +1 -2
  88. package/dist/esm/layer/marker/DefaultIcon.js +29 -7
  89. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  90. package/dist/esm/layer/marker/DivIcon.js +1 -2
  91. package/dist/esm/layer/marker/Icon.js +2 -2
  92. package/dist/esm/layer/marker/Icon.js.map +1 -1
  93. package/dist/esm/layer/marker/Marker.Drag.js +43 -4
  94. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  95. package/dist/esm/layer/marker/Marker.Move.js +4 -6
  96. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  97. package/dist/esm/layer/marker/Marker.js +54 -14
  98. package/dist/esm/layer/marker/Marker.js.map +1 -1
  99. package/dist/esm/layer/marker/MarkerClusterGroup.js +1 -2
  100. package/dist/esm/layer/marker/SvgIcon.js +1 -2
  101. package/dist/esm/layer/tile/GridLayer.js +4 -4
  102. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  103. package/dist/esm/layer/tile/TileLayer.js +8 -8
  104. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  105. package/dist/esm/layer/tile/WMSTileLayer.js +5 -4
  106. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  107. package/dist/esm/layer/vector/Canvas.js +7 -14
  108. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  109. package/dist/esm/layer/vector/Circle.js +4 -3
  110. package/dist/esm/layer/vector/Circle.js.map +1 -1
  111. package/dist/esm/layer/vector/CircleMarker.js +2 -3
  112. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  113. package/dist/esm/layer/vector/Path.DashAnimation.js +1 -2
  114. package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
  115. package/dist/esm/layer/vector/Path.js +1 -2
  116. package/dist/esm/layer/vector/Polygon.js +2 -3
  117. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  118. package/dist/esm/layer/vector/Polyline.Decorations.js +1 -2
  119. package/dist/esm/layer/vector/Polyline.js +2 -3
  120. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  121. package/dist/esm/layer/vector/Rectangle.js +1 -2
  122. package/dist/esm/layer/vector/Renderer.getRenderer.js +4 -5
  123. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  124. package/dist/esm/layer/vector/Renderer.js +1 -2
  125. package/dist/esm/layer/vector/SVG.js +7 -4
  126. package/dist/esm/layer/vector/SVG.js.map +1 -1
  127. package/dist/esm/map/Hash.js +1 -2
  128. package/dist/esm/map/Map.Rotation.js +31 -16
  129. package/dist/esm/map/Map.Rotation.js.map +1 -1
  130. package/dist/esm/map/Map.js +10 -17
  131. package/dist/esm/map/Map.js.map +1 -1
  132. package/dist/esm/map/MapSync.js +1 -2
  133. package/dist/esm/map/handler/BoxZoomHandler.js +20 -40
  134. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  135. package/dist/esm/map/handler/DisplaceHandler.js +1 -2
  136. package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
  137. package/dist/esm/map/handler/DragHandler.js +1 -2
  138. package/dist/esm/map/handler/KeyboardHandler.js +23 -43
  139. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  140. package/dist/esm/map/handler/PinchZoomHandler.js +1 -2
  141. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +1 -2
  142. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
  143. package/dist/esm/map/handler/TapHoldHandler.js +1 -2
  144. package/dist/esm/package.js +2 -3
  145. package/dist/maplair-global-src.js +487 -613
  146. package/dist/maplair-global-src.js.map +1 -1
  147. package/dist/maplair-global.js +2 -2
  148. package/dist/maplair-global.js.map +1 -1
  149. package/dist/maplair-src.js +483 -609
  150. package/dist/maplair-src.js.map +1 -1
  151. package/dist/maplair.css +1 -1263
  152. package/dist/maplair.js +2 -2
  153. package/dist/maplair.js.map +1 -1
  154. package/package.json +3 -8
  155. package/src/Maplair.all.js +0 -1
  156. package/src/control/LayersControl.js +39 -52
  157. package/src/control/ZoomControl.js +17 -31
  158. package/src/core/Class.js +5 -14
  159. package/src/core/Handler.js +11 -1
  160. package/src/core/Util.js +1 -1
  161. package/src/dom/DomEvent.js +9 -19
  162. package/src/dom/Draggable.js +5 -1
  163. package/src/geo/LatLngBounds.js +8 -15
  164. package/src/geo/crs/EPSG3395.js +3 -3
  165. package/src/geo/crs/EPSG3857.js +3 -3
  166. package/src/geo/crs/EPSG4326.js +2 -2
  167. package/src/geo/crs/SimpleCRS.js +2 -2
  168. package/src/geo/index.js +1 -2
  169. package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +1 -1
  170. package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +1 -1
  171. package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +1 -1
  172. package/src/geo/projection/index.js +5 -5
  173. package/src/geometry/Bounds.js +12 -17
  174. package/src/geometry/LineUtil.js +1 -1
  175. package/src/geometry/PolyUtil.js +23 -31
  176. package/src/layer/DivOverlay.js +1 -1
  177. package/src/layer/FeatureGroup.js +8 -2
  178. package/src/layer/GeoJSON.js +10 -13
  179. package/src/layer/HeatLayer.js +1 -1
  180. package/src/layer/ImageOverlay.js +2 -2
  181. package/src/layer/LayerGroup.js +1 -1
  182. package/src/layer/Popup.js +9 -19
  183. package/src/layer/Tooltip.js +19 -17
  184. package/src/layer/marker/DefaultIcon.js +33 -5
  185. package/src/layer/marker/Icon.js +2 -0
  186. package/src/layer/marker/Marker.Drag.js +53 -5
  187. package/src/layer/marker/Marker.Move.js +3 -4
  188. package/src/layer/marker/Marker.js +64 -13
  189. package/src/layer/tile/GridLayer.js +5 -2
  190. package/src/layer/tile/TileLayer.js +9 -6
  191. package/src/layer/tile/WMSTileLayer.js +5 -2
  192. package/src/layer/vector/Canvas.js +10 -14
  193. package/src/layer/vector/Circle.js +4 -1
  194. package/src/layer/vector/CircleMarker.js +2 -1
  195. package/src/layer/vector/Polygon.js +1 -1
  196. package/src/layer/vector/Polyline.js +1 -1
  197. package/src/layer/vector/Renderer.getRenderer.js +4 -3
  198. package/src/layer/vector/SVG.js +12 -2
  199. package/src/map/Map.Rotation.js +28 -4
  200. package/src/map/Map.js +17 -21
  201. package/src/map/handler/BoxZoomHandler.js +21 -42
  202. package/src/map/handler/KeyboardHandler.js +34 -53
  203. package/src/maplair.css +5 -0
  204. package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
  205. package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
  206. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
  207. package/dist/esm/geo/projection/index.js +0 -14
  208. package/dist/esm/geo/projection/index.js.map +0 -1
  209. package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
  210. package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
  211. package/src/layer/marker/Marker.Rotation.js +0 -103
@@ -6,8 +6,8 @@
6
6
  * An object with methods for projecting geographical coordinates of the world onto
7
7
  * a flat surface (and back). See [Map projection](https://en.wikipedia.org/wiki/Map_projection).
8
8
  *
9
- * Maplair comes with a set of already defined projections out of the box: `LonLat`,
10
- * `Mercator` and `SphericalMercator` (in the `Projection` namespace).
9
+ * Maplair comes with a set of already defined projections out of the box:
10
+ * `LonLatProjection`, `MercatorProjection` and `SphericalMercatorProjection`.
11
11
  *
12
12
  * Note that the projection instances do not inherit from Maplair's `Class` object,
13
13
  * and can't be instantiated. Also, new classes can't inherit from them,
@@ -23,6 +23,6 @@
23
23
  * arrays.
24
24
  */
25
25
 
26
- export {LonLat} from './Projection.LonLat.js';
27
- export {Mercator} from './Projection.Mercator.js';
28
- export {SphericalMercator} from './Projection.SphericalMercator.js';
26
+ export {LonLatProjection} from './LonLatProjection.js';
27
+ export {MercatorProjection} from './MercatorProjection.js';
28
+ export {SphericalMercatorProjection} from './SphericalMercatorProjection.js';
@@ -84,17 +84,14 @@ export class Bounds {
84
84
  let min2, max2;
85
85
  if (!obj) { return this; }
86
86
 
87
- if (obj instanceof Point || typeof obj[0] === 'number' || 'x' in obj) {
87
+ if (isPointExpression(obj)) {
88
88
  min2 = max2 = Point.from(obj);
89
89
  } else {
90
- obj = Bounds.from(obj);
91
- min2 = obj.min;
92
- max2 = obj.max;
93
-
94
- if (!min2 || !max2) { return this; }
90
+ ({min: min2, max: max2} = Bounds.from(obj));
91
+ if (!min2) { return this; }
95
92
  }
96
93
 
97
- if (!this.min && !this.max) {
94
+ if (!this.min) {
98
95
  this.min = new Point(min2);
99
96
  this.max = new Point(max2);
100
97
  } else {
@@ -165,17 +162,10 @@ export class Bounds {
165
162
  contains(obj) {
166
163
  let min, max;
167
164
 
168
- if (typeof obj[0] === 'number' || obj instanceof Point) {
169
- obj = Point.from(obj);
170
- } else {
171
- obj = Bounds.from(obj);
172
- }
173
-
174
- if (obj instanceof Bounds) {
175
- min = obj.min;
176
- max = obj.max;
165
+ if (isPointExpression(obj)) {
166
+ min = max = Point.from(obj);
177
167
  } else {
178
- min = max = obj;
168
+ ({min, max} = Bounds.from(obj));
179
169
  }
180
170
 
181
171
  return (min.x >= this.min.x) &&
@@ -265,3 +255,8 @@ export class Bounds {
265
255
  this.max.equals(bounds.getBottomRight());
266
256
  }
267
257
  }
258
+
259
+ // Whether `obj` is a point (or an array or object literal of one) rather than bounds
260
+ function isPointExpression(obj) {
261
+ return obj instanceof Point || (Array.isArray(obj) ? typeof obj[0] === 'number' : 'x' in obj);
262
+ }
@@ -320,7 +320,7 @@ export function _projectRing(latlngs, crs) {
320
320
 
321
321
  if (!isFlat(latlngs)) {
322
322
  console.warn('latlngs are not flat! Only the first ring will be used');
323
- latlngs = latlngs[0];
323
+ return _projectRing(latlngs[0], crs);
324
324
  }
325
325
 
326
326
  return latlngs.map(latlng => crs.project(LatLng.from(latlng)));
@@ -19,41 +19,26 @@ import {Point} from './Point.js';
19
19
  * @returns {Point[]}
20
20
  */
21
21
  export function clipPolygon(points, bounds, round) {
22
- let clippedPoints,
23
- i, j, k,
24
- a, b,
25
- len, edge, p;
26
- const edges = [1, 4, 2, 8];
22
+ // left, bottom, right, top
23
+ for (const edge of [1, 4, 2, 8]) {
24
+ if (!points.length) { break; }
27
25
 
28
- for (i = 0, len = points.length; i < len; i++) {
29
- points[i]._code = LineUtil._getBitCode(points[i], bounds);
30
- }
31
-
32
- // for each edge (left, bottom, right, top)
33
- for (k = 0; k < 4; k++) {
34
- edge = edges[k];
35
- clippedPoints = [];
26
+ /** @type {Point[]} */
27
+ const clippedPoints = [];
28
+ let b = points[points.length - 1],
29
+ bOut = isOutside(b, edge, bounds);
36
30
 
37
- for (i = 0, len = points.length, j = len - 1; i < len; j = i++) {
38
- a = points[i];
39
- b = points[j];
40
-
41
- // if a is inside the clip window
42
- if (!(a._code & edge)) {
43
- // if b is outside the clip window (a->b goes out of screen)
44
- if (b._code & edge) {
45
- p = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);
46
- p._code = LineUtil._getBitCode(p, bounds);
47
- clippedPoints.push(p);
48
- }
31
+ for (const a of points) {
32
+ const aOut = isOutside(a, edge, bounds);
33
+ // a->b crosses the edge
34
+ if (aOut !== bOut) {
35
+ clippedPoints.push(LineUtil._getEdgeIntersection(b, a, edge, bounds, round));
36
+ }
37
+ if (!aOut) {
49
38
  clippedPoints.push(a);
50
-
51
- // else if b is inside the clip window (a->b enters the screen)
52
- } else if (!(b._code & edge)) {
53
- p = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);
54
- p._code = LineUtil._getBitCode(p, bounds);
55
- clippedPoints.push(p);
56
39
  }
40
+ b = a;
41
+ bOut = aOut;
57
42
  }
58
43
  points = clippedPoints;
59
44
  }
@@ -61,6 +46,13 @@ export function clipPolygon(points, bounds, round) {
61
46
  return points;
62
47
  }
63
48
 
49
+ // Whether the point is outside the given edge of the bounds; the edge is a `LineUtil` clipping bit code
50
+ function isOutside(p, edge, bounds) {
51
+ return edge === 1 ? p.x < bounds.min.x :
52
+ edge === 2 ? p.x > bounds.max.x :
53
+ edge === 4 ? p.y < bounds.min.y : p.y > bounds.max.y;
54
+ }
55
+
64
56
  /**
65
57
  * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed
66
58
  * LatLngs (first ring) from a polygon.
@@ -443,7 +443,7 @@ export class DivOverlay extends Layer {
443
443
  _updatePosition() {
444
444
  if (!this._map) { return; }
445
445
 
446
- const pos = this._map.latLngToLayerPoint(this._latlng),
446
+ const pos = this._map.latLngToLayerPoint(this._latlng)._round(),
447
447
  offset = Point.from(this.options.offset);
448
448
 
449
449
  this._setContainerPosition(pos.add(this._getAnchor()));
@@ -115,14 +115,20 @@ export class FeatureGroup extends LayerGroup {
115
115
 
116
116
  /**
117
117
  * Returns the `LatLngBounds` of the feature group (created from bounds and
118
- * coordinates of its children).
118
+ * coordinates of its children, including the layers of nested layer groups).
119
119
  * @returns {LatLngBounds}
120
120
  */
121
121
  getBounds() {
122
122
  const bounds = new LatLngBounds();
123
123
 
124
124
  for (const layer of Object.values(this._layers)) {
125
- bounds.extend(layer.getBounds ? layer.getBounds() : layer.getLatLng());
125
+ if (layer.getBounds) {
126
+ bounds.extend(layer.getBounds());
127
+ } else if (layer.getLatLng) {
128
+ bounds.extend(layer.getLatLng());
129
+ } else if (layer instanceof LayerGroup) {
130
+ bounds.extend(FeatureGroup.prototype.getBounds.call(layer));
131
+ }
126
132
  }
127
133
  return bounds;
128
134
  }
@@ -109,33 +109,30 @@ export class GeoJSON extends FeatureGroup {
109
109
  * @returns {this}
110
110
  */
111
111
  addData(geojson) {
112
- const features = Array.isArray(geojson) ? geojson : geojson.features;
113
-
114
- if (features) {
115
- for (const feature of features) {
116
- // only add this if geometry or geometries are set and not null
117
- if (feature.geometries || feature.geometry || feature.features || feature.coordinates) {
118
- this.addData(feature);
119
- }
112
+ if (Array.isArray(geojson) || 'features' in geojson) {
113
+ for (const data of Array.isArray(geojson) ? geojson : geojson.features) {
114
+ this.addData(data);
120
115
  }
121
116
  return this;
122
117
  }
123
118
 
124
- const options = this.options;
119
+ const options = this.options,
120
+ feature = GeoJSON.asFeature(geojson);
125
121
 
126
- if (options.filter && !options.filter(geojson)) { return this; }
122
+ // skips features without a geometry
123
+ if (!feature.geometry || (options.filter && !options.filter(feature))) { return this; }
127
124
 
128
- const layer = GeoJSON.geometryToLayer(geojson, options);
125
+ const layer = GeoJSON.geometryToLayer(feature, options);
129
126
  if (!layer) {
130
127
  return this;
131
128
  }
132
- layer.feature = GeoJSON.asFeature(geojson);
129
+ layer.feature = feature;
133
130
 
134
131
  layer.defaultOptions = layer.options;
135
132
  this.resetStyle(layer);
136
133
 
137
134
  if (options.onEachFeature) {
138
- options.onEachFeature(geojson, layer);
135
+ options.onEachFeature(feature, layer);
139
136
  }
140
137
 
141
138
  return this.addLayer(layer);
@@ -187,7 +187,7 @@ export class HeatLayer extends BlanketOverlay {
187
187
 
188
188
  // merge the points per grid cell, weighted by their intensity
189
189
  for (const latlng of this._latlngs) {
190
- const point = map.latLngToLayerPoint(latlng).subtract(offset);
190
+ const point = map.latLngToLayerPoint(latlng)._round()._subtract(offset);
191
191
  if (point.x < -r || point.y < -r || point.x > width + r || point.y > height + r) { continue; }
192
192
  const intensity = (latlng.alt ?? latlng[2] ?? 1) * zoomFactor,
193
193
  key = `${Math.floor(point.x / cellSize)}:${Math.floor(point.y / cellSize)}`,
@@ -288,8 +288,8 @@ export class ImageOverlay extends Layer {
288
288
  _reset() {
289
289
  const image = this._image,
290
290
  bounds = new Bounds(
291
- this._map.latLngToLayerPoint(this._bounds.getNorthWest()),
292
- this._map.latLngToLayerPoint(this._bounds.getSouthEast())),
291
+ this._map.latLngToLayerPoint(this._bounds.getNorthWest())._round(),
292
+ this._map.latLngToLayerPoint(this._bounds.getSouthEast())._round()),
293
293
  size = bounds.getSize();
294
294
 
295
295
  DomUtil.setPosition(image, bounds.min);
@@ -60,7 +60,7 @@ export class LayerGroup extends Layer {
60
60
  * @returns {this}
61
61
  */
62
62
  removeLayer(layer) {
63
- const id = layer in this._layers ? layer : this.getLayerId(layer);
63
+ const id = typeof layer === 'number' ? layer : this.getLayerId(layer);
64
64
 
65
65
  if (this._map && this._layers[id]) {
66
66
  this._map.removeLayer(this._layers[id]);
@@ -238,7 +238,7 @@ const layerPopupMethods = {
238
238
  return;
239
239
  }
240
240
  // prevent map click
241
- DomEvent.stop(e);
241
+ DomEvent.stopPropagation(e);
242
242
 
243
243
  const target = e.propagatedFrom ?? e.target;
244
244
  if (this._popup._source === target && !(target instanceof Path)) {
@@ -438,12 +438,6 @@ export class Popup extends DivOverlay {
438
438
  this._contentNode = DomUtil.create('div', `${prefix}-content`, wrapper);
439
439
 
440
440
  DomEvent.disableClickPropagation(container);
441
- // The keyboard handler of the map does not get keys while the focus is in the popup
442
- DomEvent.on(container, 'keydown', (e) => {
443
- if (e.key === 'Escape' && this.options.closeOnEscapeKey) {
444
- this.close();
445
- }
446
- });
447
441
  DomEvent.disableScrollPropagation(this._contentNode);
448
442
  DomEvent.on(container, 'contextmenu', DomEvent.stopPropagation);
449
443
 
@@ -464,15 +458,12 @@ export class Popup extends DivOverlay {
464
458
  }
465
459
 
466
460
  if (this.options.trackResize) {
467
- this._resizeObserver = new ResizeObserver(((entries) => {
461
+ this._resizeObserver = new ResizeObserver(() => {
468
462
  if (!this._map) { return; }
469
- this._containerWidth = entries[0]?.contentRect?.width;
470
- this._containerHeight = entries[0]?.contentRect?.height;
471
-
472
463
  this._updateLayout();
473
464
  this._updatePosition();
474
465
  this._adjustPan();
475
- }));
466
+ });
476
467
 
477
468
  this._resizeObserver.observe(this._contentNode);
478
469
  }
@@ -485,16 +476,15 @@ export class Popup extends DivOverlay {
485
476
  style.maxWidth = `${this.options.maxWidth}px`;
486
477
  style.minWidth = `${this.options.minWidth}px`;
487
478
 
488
- const maxHeight = this.options.maxHeight,
489
- scrolledClass = 'maplair-popup-scrolled';
479
+ style.height = '';
490
480
 
491
- // only measure the height (forcing a layout) if needed
492
- if (maxHeight && (this._containerHeight ?? container.offsetHeight) > maxHeight) {
481
+ // only measure the height of the content (forcing a layout) if needed
482
+ const maxHeight = this.options.maxHeight,
483
+ scrolled = !!maxHeight && container.offsetHeight > maxHeight;
484
+ if (scrolled) {
493
485
  style.height = `${maxHeight}px`;
494
- container.classList.add(scrolledClass);
495
- } else {
496
- container.classList.remove(scrolledClass);
497
486
  }
487
+ container.classList.toggle('maplair-popup-scrolled', scrolled);
498
488
 
499
489
  this._containerWidth = this._container.offsetWidth;
500
490
  this._containerHeight = this._container.offsetHeight;
@@ -121,13 +121,16 @@ const layerTooltipMethods = {
121
121
  * @returns {this}
122
122
  */
123
123
  bindTooltip(content, options) {
124
+ // an open tooltip is replaced, a closed one reused
125
+ const old = this.isTooltipOpen() ? null : this._tooltip;
124
126
 
125
- if (this._tooltip && this.isTooltipOpen()) {
127
+ // the handlers depend on the old options, so they go before the new ones are applied
128
+ if (this._tooltip) {
126
129
  this.unbindTooltip();
127
130
  }
128
131
 
129
132
  // eslint-disable-next-line no-use-before-define -- defined below, used when called
130
- this._tooltip = this._initOverlay(Tooltip, this._tooltip, content, options);
133
+ this._tooltip = this._initOverlay(Tooltip, old, content, options);
131
134
  this._initTooltipInteractions();
132
135
 
133
136
  if (this._tooltip.options.permanent && this._map && this._map.hasLayer(this)) {
@@ -152,29 +155,27 @@ const layerTooltipMethods = {
152
155
  },
153
156
 
154
157
  _initTooltipInteractions(remove) {
155
- if (!remove && this._tooltipHandlersAdded) { return; }
156
- const onOff = remove ? 'off' : 'on',
158
+ const {permanent, sticky} = this._tooltip.options,
157
159
  events = {
158
160
  remove: this.closeTooltip,
159
161
  move: this._moveTooltip
160
162
  };
161
- if (!this._tooltip.options.permanent) {
163
+ if (permanent) {
164
+ events.add = this._openTooltip;
165
+ } else {
162
166
  events.pointerover = this._openTooltip;
163
167
  events.pointerout = this.closeTooltip;
164
168
  events.click = this._openTooltip;
169
+ // layer elements can be recreated on every add
170
+ events.add = this._toggleFocusListeners;
165
171
  if (this._map) {
166
- this._addFocusListeners(remove);
167
- } else {
168
- events.add = () => this._addFocusListeners(remove);
172
+ this._toggleFocusListeners(!remove);
169
173
  }
170
- } else {
171
- events.add = this._openTooltip;
172
174
  }
173
- if (this._tooltip.options.sticky) {
175
+ if (sticky) {
174
176
  events.pointermove = this._moveTooltip;
175
177
  }
176
- this[onOff](events);
177
- this._tooltipHandlersAdded = !remove;
178
+ this[remove ? 'off' : 'on'](events);
178
179
  },
179
180
 
180
181
  /**
@@ -254,11 +255,12 @@ const layerTooltipMethods = {
254
255
  return this._tooltip;
255
256
  },
256
257
 
257
- _addFocusListeners(remove) {
258
+ // also the `add` listener, so any truthy argument adds
259
+ _toggleFocusListeners(add) {
258
260
  if (this.getElement) {
259
- this._addFocusListenersOnLayer(this, remove);
261
+ this._addFocusListenersOnLayer(this, !add);
260
262
  } else if (this.eachLayer) {
261
- this.eachLayer(layer => this._addFocusListenersOnLayer(layer, remove), this);
263
+ this.eachLayer(layer => this._addFocusListenersOnLayer(layer, !add), this);
262
264
  }
263
265
  },
264
266
 
@@ -580,7 +582,7 @@ export class Tooltip extends DivOverlay {
580
582
  }
581
583
 
582
584
  _updatePosition() {
583
- const pos = this._map.latLngToLayerPoint(this._latlng);
585
+ const pos = this._map.latLngToLayerPoint(this._latlng)._round();
584
586
  this._setPosition(pos);
585
587
  }
586
588
 
@@ -2,10 +2,26 @@ import {Icon} from './Icon.js';
2
2
  /** @import {IconOptions} from './Icon.js' */
3
3
  /** @import {PointExpression} from '../../geometry/Point.js' */
4
4
 
5
+ // The maple leaf marker. The pin is drawn white under its fill, which fades to it at the top with a `fillTopOpacity`
6
+ // below 1, so that a single color gets a highlight like the default one; the outline keeps light colors visible,
7
+ // but would double the antialiased edges of the default pin.
8
+ /**
9
+ * @param {string} fill
10
+ * @param {string} fillTop
11
+ * @param {number} fillTopOpacity
12
+ * @param {string} stroke
13
+ * @param {string} strokeTop
14
+ * @param {string} [outline]
15
+ * @returns {string}
16
+ */
17
+ const marker = (fill, fillTop, fillTopOpacity, stroke, strokeTop, outline = '') => `data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round" viewBox="0 0 500 820"><defs><linearGradient id="a" x1="0" x2="1" y1="0" y2="0" gradientTransform="rotate(-90 478.727 62.272)scale(37.566)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="${fill}"/><stop offset="1" stop-color="${fillTop}" stop-opacity="${fillTopOpacity}"/></linearGradient><linearGradient id="b" x1="0" x2="1" y1="0" y2="0" gradientTransform="rotate(-90 468.484 54.002)scale(19.053)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="${stroke}"/><stop offset="1" stop-color="${strokeTop}"/></linearGradient></defs><g fill="%23FFF"><path id="p" d="M416.500 542.096L420.919 533.569L422.024 531.437L424.460 529.996L424.233 527.174L426.670 525.732L426.382 522.881L428.720 521.213L428.075 518.393L429.979 516.125L428.342 513.639L429.080 510.777L426.581 509.207L426.168 506.292L423.266 505.773L421.781 503.221L418.898 503.859L416.511 502.112L414.131 503.870L411.248 503.241L409.766 505.793L406.865 506.302L406.439 509.216L403.933 510.775L404.661 513.641L403.023 516.136L404.935 518.393L404.271 521.204L406.590 522.896L406.299 525.752L408.738 527.189L408.516 530.011L410.956 531.448L412.065 533.578Z" transform="translate(-7889.1 -9807.44)scale(19.5417)"/></g><use href="%23p" fill="url(%23a)" stroke="url(%23b)" stroke-width="1.1" stroke-linejoin="miter" stroke-miterlimit="10"/>${outline}<path fill="%23FFF" d="m-90 2030 45-863a95 95 0 0 0-111-98l-859 151 116-320a65 65 0 0 0-20-73l-941-762 212-99a65 65 0 0 0 34-79l-186-572 542 115a65 65 0 0 0 73-38l105-247 423 454a65 65 0 0 0 111-57l-204-1052 327 189a65 65 0 0 0 91-27l332-652 332 652a65 65 0 0 0 91 27l327-189-204 1052a65 65 0 0 0 111 57l423-454 105 247a65 65 0 0 0 73 38l542-115-186 572a65 65 0 0 0 34 79l212 99-941 762a65 65 0 0 0-20 73l116 320-859-151a95 95 0 0 0-111 98l45 863z" transform="translate(250 258)scale(.068)"/></svg>`;
18
+
5
19
  /**
6
20
  * Options of `DefaultIcon`.
7
21
  * @typedef {object} DefaultIconOptions
8
22
  * @property {string} [iconUrl] The maple leaf marker, inlined as an SVG data URI.
23
+ * @property {string|null} [color=null] Paints the pin in the given CSS color instead of
24
+ * the default red, overriding `iconUrl`, e.g. `new DefaultIcon({color: 'teal'})`.
9
25
  * @property {string} [shadowUrl] Its shadow, inlined as an SVG data URI.
10
26
  * @property {PointExpression|number} [iconSize=[25, 41]]
11
27
  * @property {PointExpression} [iconAnchor=[12, 41]]
@@ -16,9 +32,9 @@ import {Icon} from './Icon.js';
16
32
  */
17
33
 
18
34
  /**
19
- * A trivial subclass of `Icon`, represents the icon to use in `Marker`s when
20
- * no icon is specified. The maple leaf marker and its shadow are inlined as SVG data
21
- * URIs, so they work with any bundler and need no image files.
35
+ * A subclass of `Icon`, represents the icon to use in `Marker`s when no icon is
36
+ * specified, optionally in another `color`. The maple leaf marker and its shadow are
37
+ * inlined as SVG data URIs, so they work with any bundler and need no image files.
22
38
  *
23
39
  * In order to customize the default icon, just change the properties of
24
40
  * `DefaultIcon.defaultOptions` (which is a set of `Icon options`).
@@ -29,13 +45,14 @@ import {Icon} from './Icon.js';
29
45
  export class DefaultIcon extends Icon {
30
46
 
31
47
  static defaultOptions = {
32
- iconUrl: 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round" viewBox="0 0 500 820"><defs><linearGradient id="a" x1="0" x2="1" y1="0" y2="0" gradientTransform="rotate(-90 478.727 62.272)scale(37.566)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="%23C2331B"/><stop offset="1" stop-color="%23E2603F"/></linearGradient><linearGradient id="b" x1="0" x2="1" y1="0" y2="0" gradientTransform="rotate(-90 468.484 54.002)scale(19.053)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="%238F2D20"/><stop offset="1" stop-color="%23B23A27"/></linearGradient></defs><path fill="url(%23a)" stroke="url(%23b)" stroke-width="1.1" stroke-linejoin="miter" stroke-miterlimit="10" d="M416.500 542.096L420.919 533.569L422.024 531.437L424.460 529.996L424.233 527.174L426.670 525.732L426.382 522.881L428.720 521.213L428.075 518.393L429.979 516.125L428.342 513.639L429.080 510.777L426.581 509.207L426.168 506.292L423.266 505.773L421.781 503.221L418.898 503.859L416.511 502.112L414.131 503.870L411.248 503.241L409.766 505.793L406.865 506.302L406.439 509.216L403.933 510.775L404.661 513.641L403.023 516.136L404.935 518.393L404.271 521.204L406.590 522.896L406.299 525.752L408.738 527.189L408.516 530.011L410.956 531.448L412.065 533.578Z" transform="translate(-7889.1 -9807.44)scale(19.5417)"/><path fill="%23FFF" d="m-90 2030 45-863a95 95 0 0 0-111-98l-859 151 116-320a65 65 0 0 0-20-73l-941-762 212-99a65 65 0 0 0 34-79l-186-572 542 115a65 65 0 0 0 73-38l105-247 423 454a65 65 0 0 0 111-57l-204-1052 327 189a65 65 0 0 0 91-27l332-652 332 652a65 65 0 0 0 91 27l327-189-204 1052a65 65 0 0 0 111 57l423-454 105 247a65 65 0 0 0 73 38l542-115-186 572a65 65 0 0 0 34 79l212 99-941 762a65 65 0 0 0-20 73l116 320-859-151a95 95 0 0 0-111 98l45 863z" transform="translate(250 258)scale(.068)"/></svg>',
48
+ iconUrl: /* @__PURE__ */ marker('%23C2331B', '%23E2603F', 1, '%238F2D20', '%23B23A27'),
33
49
  shadowUrl: 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="0 0 817.2 820"><radialGradient id="a" cx="526.6" cy="486.836" r="478.154" fx="275.876" fy="893.983" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:%235c5c5c;stop-opacity:.9477"/><stop offset=".112" style="stop-color:%23474747;stop-opacity:.7805"/><stop offset=".34" style="stop-color:%23202020;stop-opacity:.4413"/><stop offset=".523" style="stop-color:%23090909;stop-opacity:.1692"/><stop offset=".637" style="stop-color:%23000;stop-opacity:0"/></radialGradient><path d="M254.7 820.0L430.1 664.9L473.9 626.1L541.3 599.9L561.5 548.6L629.0 522.4L648.1 470.5L715.4 440.2L726.3 388.9L789.2 347.6L774.9 302.4L817.1 250.3L775.4 221.8L792.3 168.8L732.1 159.3L721.8 112.9L651.7 124.5L614.0 92.7L545.0 124.7L486.2 113.3L430.2 159.7L360.8 169.0L325.1 222.0L255.1 250.3L245.6 302.4L186.6 347.8L209.1 388.9L169.0 440.0L205.6 470.8L173.5 522.7L215.1 548.9L184.8 600.2L226.4 626.3L232.1 665.1Z" style="fill-rule:evenodd;clip-rule:evenodd;fill:url(%23a);fill-opacity:.7;filter:blur(15px)"/></svg>',
34
50
  iconSize: [25, 41],
35
51
  iconAnchor: [12, 41],
36
52
  popupAnchor: [1, -34],
37
53
  tooltipAnchor: [16, -28],
38
- shadowSize: [41, 41]
54
+ shadowSize: [41, 41],
55
+ color: null
39
56
  };
40
57
 
41
58
  /**
@@ -46,4 +63,15 @@ export class DefaultIcon extends Icon {
46
63
  super(...args);
47
64
  this.callInitHooks(DefaultIcon);
48
65
  }
66
+
67
+ /**
68
+ * @param {'icon'|'shadow'} name
69
+ * @returns {string|undefined}
70
+ */
71
+ _getIconUrl(name) {
72
+ const {color} = this.options;
73
+ if (!color || name !== 'icon') { return super._getIconUrl(name); }
74
+ const c = encodeURIComponent(color);
75
+ return marker(c, c, 0.75, c, c, '<use href="%23p" fill="none" stroke="%23666" stroke-opacity=".4"/>');
76
+ }
49
77
  }
@@ -137,6 +137,8 @@ export class Icon extends Class {
137
137
  img.style.marginLeft = `${-anchor.x}px`;
138
138
  img.style.marginTop = `${-anchor.y}px`;
139
139
  }
140
+ // the origin of the marker rotation: the anchor, which is the top left corner without one
141
+ img.style.transformOrigin = anchor ? `${anchor.x}px ${anchor.y}px` : '0 0';
140
142
 
141
143
  if (size) {
142
144
  img.style.width = `${size.x}px`;
@@ -1,4 +1,5 @@
1
1
  import {Handler} from '../../core/Handler.js';
2
+ import * as DomEvent from '../../dom/DomEvent.js';
2
3
  import * as DomUtil from '../../dom/DomUtil.js';
3
4
  import {Draggable} from '../../dom/Draggable.js';
4
5
  import {Bounds} from '../../geometry/Bounds.js';
@@ -7,6 +8,9 @@ import {Point} from '../../geometry/Point.js';
7
8
  /** @import {Marker, MarkerMoveEvent} from './Marker.js' */
8
9
  /** @import {MaplairEvent, DragEndEvent} from '../../core/Events.js' */
9
10
 
11
+ /** @type {Record<string, [number, number]>} */
12
+ const arrows = {ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1]};
13
+
10
14
  /**
11
15
  * The handler of `Marker` which makes the markers draggable, see the
12
16
  * [`dragging`](#marker-dragging) property of markers and its `draggable` option.
@@ -48,6 +52,8 @@ export class MarkerDrag extends Handler {
48
52
  dragend: this._onDragEnd
49
53
  }, this).enable();
50
54
 
55
+ DomEvent.on(icon, 'keydown keyup blur', this._onKey, this);
56
+
51
57
  icon.classList.add('maplair-marker-draggable');
52
58
  }
53
59
 
@@ -55,6 +61,8 @@ export class MarkerDrag extends Handler {
55
61
  * Makes the icon of the marker undraggable, called by `disable()`.
56
62
  */
57
63
  removeHooks() {
64
+ this._keyOffset = null; // disabling the Draggable below ends a keyboard drag in progress, as it does a pointer drag
65
+
58
66
  this._draggable.off({
59
67
  dragstart: this._onDragStart,
60
68
  predrag: this._onPreDrag,
@@ -62,6 +70,8 @@ export class MarkerDrag extends Handler {
62
70
  dragend: this._onDragEnd
63
71
  }, this).disable();
64
72
 
73
+ DomEvent.off(this._draggable._element, 'keydown keyup blur', this._onKey, this);
74
+
65
75
  this._marker._icon?.classList.remove('maplair-marker-draggable');
66
76
  }
67
77
 
@@ -129,14 +139,11 @@ export class MarkerDrag extends Handler {
129
139
 
130
140
  _onDrag(e) {
131
141
  const marker = this._marker,
132
- shadow = marker._shadow,
133
142
  iconPos = DomUtil.getPosition(marker._icon),
134
143
  latlng = marker._map.layerPointToLatLng(iconPos);
135
144
 
136
- // update shadow position
137
- if (shadow) {
138
- DomUtil.setPosition(shadow, iconPos);
139
- }
145
+ // Draggable only moved the icon and dropped its rotation
146
+ marker._positionElements(iconPos);
140
147
 
141
148
  marker._latlng = latlng;
142
149
  e.latlng = latlng;
@@ -155,4 +162,45 @@ export class MarkerDrag extends Handler {
155
162
  .fire('moveend')
156
163
  .fire('dragend', e);
157
164
  }
165
+
166
+ // Arrow keys move a focused marker. Holding a key down is one drag, driven through the Draggable like a pointer
167
+ // drag (so the two can't overlap), and ends on keyup or blur.
168
+ /** @param {KeyboardEvent|FocusEvent} e */
169
+ _onKey(e) {
170
+ const k = /** @type {KeyboardEvent} */ (e), // all but blur
171
+ dir = arrows[k.key],
172
+ draggable = this._draggable,
173
+ {options, _map: map} = this._marker;
174
+
175
+ if (e.type !== 'keydown') {
176
+ if (this._keyOffset) {
177
+ this._keyOffset = null;
178
+ draggable.finishDrag();
179
+ }
180
+
181
+ } else if (dir && k.target === draggable._element && !(k.altKey || k.ctrlKey || k.metaKey)) {
182
+ e.preventDefault(); // don't scroll the page
183
+
184
+ if (!this._keyOffset) {
185
+ if (Draggable._dragging) { return; }
186
+ Draggable._dragging = draggable;
187
+ draggable._startPos = DomUtil.getPosition(draggable._element);
188
+ draggable._moved = draggable._moving = true;
189
+ this._keyOffset = new Point(0, 0);
190
+ draggable.fire('dragstart');
191
+ }
192
+
193
+ // in container pixels, which the map rotation (if any) turns to the frame of the rotated pane
194
+ const offset = new Point(...dir).multiplyBy(k.shiftKey ? 30 : 10);
195
+ this._keyOffset = this._keyOffset.add(map._rotateToPane?.(offset) ?? offset);
196
+ // not through _updatePosition, whose predrag would start the pointer autoPan loop
197
+ draggable._newPos = draggable._startPos.add(this._keyOffset);
198
+ DomUtil.setPosition(draggable._element, draggable._newPos);
199
+ draggable.fire('drag', {originalEvent: k});
200
+
201
+ if (options.autoPan) {
202
+ map.panInside(this._marker._latlng, {padding: options.autoPanPadding, animate: false});
203
+ }
204
+ }
205
+ }
158
206
  }
@@ -11,9 +11,8 @@ import {Point} from '../../geometry/Point.js';
11
11
  * @property {number} [duration=1000] The duration of the movement in milliseconds.
12
12
  * @property {number} [speed] The speed in meters (or units of the CRS) per second
13
13
  * instead of the `duration`.
14
- * @property {boolean} [rotate=false] Whether to set the `rotationAngle` of the icon to
15
- * the heading of the movement (for icons pointing up; needs the marker rotation, see
16
- * `rotationAngle`).
14
+ * @property {boolean} [rotate=false] Whether to set the `rotation` of the marker to
15
+ * the heading of the movement (for icons pointing up).
17
16
  */
18
17
 
19
18
  // The methods extended below
@@ -81,7 +80,7 @@ const markerMoveMethods = {
81
80
  }
82
81
  const from = points[i], to = points[i + 1];
83
82
  if (options.rotate && !from.equals(to)) {
84
- this.options.rotationAngle = this._heading(from, to);
83
+ this.options.rotation = this._heading(from, to);
85
84
  }
86
85
  this.setLatLng(this._interpolate(from, to, lengths[i] ? Math.min(1, distance / lengths[i]) : 1));
87
86