maplair 4.3.0 → 4.5.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 (191) hide show
  1. package/CHANGELOG.md +151 -8
  2. package/dist/esm/control/AttributionControl.js +30 -13
  3. package/dist/esm/control/AttributionControl.js.map +1 -1
  4. package/dist/esm/control/ButtonControl.js +0 -1
  5. package/dist/esm/control/ButtonControl.js.map +1 -1
  6. package/dist/esm/control/ContextMenu.js +1 -1
  7. package/dist/esm/control/ContextMenu.js.map +1 -1
  8. package/dist/esm/control/Control.js +16 -11
  9. package/dist/esm/control/Control.js.map +1 -1
  10. package/dist/esm/control/FullscreenControl.js +0 -1
  11. package/dist/esm/control/FullscreenControl.js.map +1 -1
  12. package/dist/esm/control/LayersControl.js +46 -27
  13. package/dist/esm/control/LayersControl.js.map +1 -1
  14. package/dist/esm/control/RotateControl.js +0 -1
  15. package/dist/esm/control/RotateControl.js.map +1 -1
  16. package/dist/esm/control/ScaleControl.js +7 -8
  17. package/dist/esm/control/ScaleControl.js.map +1 -1
  18. package/dist/esm/control/SideBySideControl.js +3 -2
  19. package/dist/esm/control/SideBySideControl.js.map +1 -1
  20. package/dist/esm/control/ZoomControl.js +14 -13
  21. package/dist/esm/control/ZoomControl.js.map +1 -1
  22. package/dist/esm/core/Events.js +3 -2
  23. package/dist/esm/core/Events.js.map +1 -1
  24. package/dist/esm/core/Util.js +17 -5
  25. package/dist/esm/core/Util.js.map +1 -1
  26. package/dist/esm/dom/DomEvent.PointerEvents.js +72 -2
  27. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  28. package/dist/esm/dom/DomEvent.js +4 -7
  29. package/dist/esm/dom/DomEvent.js.map +1 -1
  30. package/dist/esm/dom/DomUtil.js +5 -5
  31. package/dist/esm/dom/DomUtil.js.map +1 -1
  32. package/dist/esm/dom/Draggable.js +10 -8
  33. package/dist/esm/dom/Draggable.js.map +1 -1
  34. package/dist/esm/geo/LatLng.js +24 -35
  35. package/dist/esm/geo/LatLng.js.map +1 -1
  36. package/dist/esm/geo/LatLngBounds.js +6 -3
  37. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  38. package/dist/esm/geometry/Bounds.js +2 -2
  39. package/dist/esm/geometry/Bounds.js.map +1 -1
  40. package/dist/esm/geometry/Point.js +16 -19
  41. package/dist/esm/geometry/Point.js.map +1 -1
  42. package/dist/esm/geometry/PolyUtil.js +10 -3
  43. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  44. package/dist/esm/geometry/Transformation.js +1 -7
  45. package/dist/esm/geometry/Transformation.js.map +1 -1
  46. package/dist/esm/layer/BlanketOverlay.js +3 -2
  47. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  48. package/dist/esm/layer/DivOverlay.js +25 -25
  49. package/dist/esm/layer/DivOverlay.js.map +1 -1
  50. package/dist/esm/layer/ImageOverlay.js +8 -5
  51. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  52. package/dist/esm/layer/Layer.js +12 -7
  53. package/dist/esm/layer/Layer.js.map +1 -1
  54. package/dist/esm/layer/Popup.js +33 -15
  55. package/dist/esm/layer/Popup.js.map +1 -1
  56. package/dist/esm/layer/Tooltip.js +48 -56
  57. package/dist/esm/layer/Tooltip.js.map +1 -1
  58. package/dist/esm/layer/VideoOverlay.js +2 -2
  59. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  60. package/dist/esm/layer/marker/DivIcon.js +4 -8
  61. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  62. package/dist/esm/layer/marker/Icon.js +37 -17
  63. package/dist/esm/layer/marker/Icon.js.map +1 -1
  64. package/dist/esm/layer/marker/Marker.Drag.js +11 -12
  65. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  66. package/dist/esm/layer/marker/Marker.js +54 -53
  67. package/dist/esm/layer/marker/Marker.js.map +1 -1
  68. package/dist/esm/layer/marker/SvgIcon.js +1 -1
  69. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  70. package/dist/esm/layer/tile/GridLayer.js +29 -21
  71. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  72. package/dist/esm/layer/tile/TileLayer.js +19 -15
  73. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  74. package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
  75. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  76. package/dist/esm/layer/vector/Canvas.js +45 -94
  77. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  78. package/dist/esm/layer/vector/Circle.js +8 -9
  79. package/dist/esm/layer/vector/Circle.js.map +1 -1
  80. package/dist/esm/layer/vector/CircleMarker.js +15 -4
  81. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  82. package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
  83. package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
  84. package/dist/esm/layer/vector/Path.js +10 -5
  85. package/dist/esm/layer/vector/Path.js.map +1 -1
  86. package/dist/esm/layer/vector/Polygon.js +10 -11
  87. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  88. package/dist/esm/layer/vector/Polyline.js +19 -26
  89. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  90. package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
  91. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  92. package/dist/esm/layer/vector/Renderer.js +16 -0
  93. package/dist/esm/layer/vector/Renderer.js.map +1 -1
  94. package/dist/esm/layer/vector/SVG.js +3 -3
  95. package/dist/esm/layer/vector/SVG.js.map +1 -1
  96. package/dist/esm/map/Map.Rotation.js +9 -11
  97. package/dist/esm/map/Map.Rotation.js.map +1 -1
  98. package/dist/esm/map/Map.js +158 -71
  99. package/dist/esm/map/Map.js.map +1 -1
  100. package/dist/esm/map/MapSync.js +2 -5
  101. package/dist/esm/map/MapSync.js.map +1 -1
  102. package/dist/esm/map/handler/BoxZoomHandler.js +4 -0
  103. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  104. package/dist/esm/map/handler/DisplaceHandler.js +68 -30
  105. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  106. package/dist/esm/map/handler/DragHandler.js +7 -2
  107. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  108. package/dist/esm/map/handler/KeyboardHandler.js +3 -5
  109. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  110. package/dist/esm/map/handler/PinchZoomHandler.js +4 -7
  111. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  112. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -7
  113. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  114. package/dist/esm/map/handler/TapDragZoomHandler.js +2 -5
  115. package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
  116. package/dist/esm/map/handler/TapHoldHandler.js +8 -20
  117. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  118. package/dist/esm/package.js +1 -1
  119. package/dist/maplair-global-src.js +970 -810
  120. package/dist/maplair-global-src.js.map +1 -1
  121. package/dist/maplair-global.js +2 -2
  122. package/dist/maplair-global.js.map +1 -1
  123. package/dist/maplair-src.js +970 -810
  124. package/dist/maplair-src.js.map +1 -1
  125. package/dist/maplair.css +1 -1
  126. package/dist/maplair.js +2 -2
  127. package/dist/maplair.js.map +1 -1
  128. package/i18n/en.json +1 -0
  129. package/package.json +1 -1
  130. package/src/control/AttributionControl.js +37 -11
  131. package/src/control/ButtonControl.js +0 -1
  132. package/src/control/ContextMenu.js +1 -1
  133. package/src/control/Control.js +13 -16
  134. package/src/control/FullscreenControl.js +0 -1
  135. package/src/control/LayersControl.js +61 -37
  136. package/src/control/RotateControl.js +0 -1
  137. package/src/control/ScaleControl.js +10 -8
  138. package/src/control/SideBySideControl.js +4 -2
  139. package/src/control/ZoomControl.js +11 -13
  140. package/src/core/Events.js +6 -2
  141. package/src/core/Util.js +17 -4
  142. package/src/dom/DomEvent.PointerEvents.js +68 -2
  143. package/src/dom/DomEvent.js +5 -17
  144. package/src/dom/DomUtil.js +5 -5
  145. package/src/dom/Draggable.js +11 -8
  146. package/src/geo/LatLng.js +24 -37
  147. package/src/geo/LatLngBounds.js +10 -4
  148. package/src/geometry/Bounds.js +3 -3
  149. package/src/geometry/Point.js +22 -28
  150. package/src/geometry/PolyUtil.js +12 -3
  151. package/src/geometry/Transformation.js +1 -8
  152. package/src/layer/BlanketOverlay.js +6 -3
  153. package/src/layer/DivOverlay.js +30 -32
  154. package/src/layer/ImageOverlay.js +12 -9
  155. package/src/layer/Layer.js +19 -7
  156. package/src/layer/Popup.js +41 -21
  157. package/src/layer/Tooltip.js +50 -70
  158. package/src/layer/VideoOverlay.js +2 -2
  159. package/src/layer/marker/DivIcon.js +3 -6
  160. package/src/layer/marker/Icon.js +41 -20
  161. package/src/layer/marker/Marker.Drag.js +22 -24
  162. package/src/layer/marker/Marker.js +71 -64
  163. package/src/layer/marker/SvgIcon.js +1 -1
  164. package/src/layer/tile/GridLayer.js +41 -30
  165. package/src/layer/tile/TileLayer.js +31 -21
  166. package/src/layer/tile/WMSTileLayer.js +4 -2
  167. package/src/layer/vector/Canvas.js +53 -149
  168. package/src/layer/vector/Circle.js +13 -13
  169. package/src/layer/vector/CircleMarker.js +16 -3
  170. package/src/layer/vector/Path.ZoomStyles.js +5 -3
  171. package/src/layer/vector/Path.js +11 -5
  172. package/src/layer/vector/Polygon.js +11 -10
  173. package/src/layer/vector/Polyline.js +20 -21
  174. package/src/layer/vector/Renderer.getRenderer.js +2 -1
  175. package/src/layer/vector/Renderer.js +21 -3
  176. package/src/layer/vector/SVG.js +3 -3
  177. package/src/map/Map.Rotation.js +13 -9
  178. package/src/map/Map.js +195 -83
  179. package/src/map/MapSync.js +2 -2
  180. package/src/map/handler/BoxZoomHandler.js +5 -0
  181. package/src/map/handler/DisplaceHandler.js +53 -7
  182. package/src/map/handler/DragHandler.js +5 -5
  183. package/src/map/handler/KeyboardHandler.js +5 -10
  184. package/src/map/handler/PinchZoomHandler.js +4 -4
  185. package/src/map/handler/ScrollWheelZoomHandler.js +4 -4
  186. package/src/map/handler/TapDragZoomHandler.js +2 -2
  187. package/src/map/handler/TapHoldHandler.js +13 -25
  188. package/src/maplair.css +50 -10
  189. package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
  190. package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
  191. package/src/dom/DomEvent.DoubleTap.js +0 -143
@@ -1 +1 @@
1
- {"version":3,"file":"Circle.js","names":[],"sources":["../../../../src/layer/vector/Circle.js"],"sourcesContent":["import {CircleMarker} from './CircleMarker.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {EarthCRS} from '../../geo/crs/EarthCRS.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {CircleMarkerOptions} from './CircleMarker.js' */\n\n\n/**\n * Options of `Circle`.\n * @typedef {object} CircleOptions\n * @property {number} [radius] Radius of the circle, in meters.\n * @extends CircleMarkerOptions\n */\n\n/**\n * A class for drawing circle overlays on a map with radius specified in meters.\n * Extends `CircleMarker`, its `setRadius()` and `getRadius()` use meters.\n *\n * It's an approximation and starts to diverge from a real circle closer to poles\n * (due to projection distortion).\n *\n * @example\n * ```js\n * new Circle([50.5, 30.5], {radius: 200}).addTo(map);\n * ```\n */\nexport class Circle extends CircleMarker {\n\n\t/**\n\t * Instantiates a circle object given a geographical point, and an options object\n\t * which contains the circle radius.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tif (typeof options === 'number') {\n\t\t\tthrow new Error('Circle: the radius is an option in Maplair. Use new Circle(latlng, {radius}).');\n\t\t}\n\t\tsuper(latlng, options);\n\n\t\tif (isNaN(this.options.radius)) { throw new Error('Circle radius cannot be NaN'); }\n\n\t\tthis.callInitHooks(Circle);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path. When the circle isn't on a map, they're\n\t * approximated on a sphere.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\tif (!this._map) { return this._latlng.toBounds(this._radius * 2); }\n\n\t\tconst half = [this._pxRadius, this._pxRadiusY ?? this._pxRadius];\n\n\t\treturn new LatLngBounds(\n\t\t\tthis._map.layerPointToLatLng(this._point.subtract(half)),\n\t\t\tthis._map.layerPointToLatLng(this._point.add(half)));\n\t}\n\n\t_project() {\n\n\t\tconst lng = this._latlng.lng,\n\t\tlat = this._latlng.lat,\n\t\tmap = this._map,\n\t\tcrs = map.options.crs;\n\n\t\tif (crs.distance === EarthCRS.distance) {\n\t\t\tconst d = Math.PI / 180,\n\t\t\tlatR = (this._radius / EarthCRS.R) / d,\n\t\t\ttop = map.project([lat + latR, lng]),\n\t\t\tbottom = map.project([lat - latR, lng]),\n\t\t\tp = top.add(bottom).divideBy(2),\n\t\t\tlat2 = map.unproject(p).lat;\n\t\t\t// Longitude span from the haversine form of the spherical law of cosines. The plain acos() form\n\t\t\t// loses precision for radii of about a metre and less, where cos(latR) is too close to 1 (#6120).\n\t\t\tlet lngR = 2 * Math.asin(Math.sqrt(\n\t\t\t\t(Math.sin(latR * d / 2) ** 2 - Math.sin((lat2 - lat) * d / 2) ** 2) /\n\t\t\t\t(Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;\n\n\t\t\tif (isNaN(lngR) || lngR === 0) {\n\t\t\t\tlngR = latR / Math.cos(Math.PI / 180 * lat); // Fallback for edge case, #2425\n\t\t\t}\n\n\t\t\tthis._point = p.subtract(map.getPixelOrigin());\n\t\t\tthis._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x;\n\t\t\tthis._pxRadiusY = p.y - top.y;\n\n\t\t} else {\n\t\t\tconst latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));\n\n\t\t\tthis._point = map.latLngToLayerPoint(this._latlng);\n\t\t\tthis._pxRadius = Math.abs(this._point.x - map.latLngToLayerPoint(latlng2).x);\n\t\t}\n\n\t\tth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AE,CAAC,IAAI;GAE9C,IAAI,MAAM,IAAI,KAAK,SAAS,GAC3B,OAAO,OAAO,KAAK,IAAI,KAAK,KAAK,MAAM,GAAG;GAG3C,KAAK,SAAS,EAAE,SAAS,IAAI,eAAe,CAAC;GAC7C,KAAK,YAAY,MAAM,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,QAAQ,CAAC,MAAM,MAAM,IAAI,CAAC,CAAC,CAAC;GACzE,KAAK,aAAa,EAAE,IAAI,IAAI;EAE7B,OAAO;GACN,MAAM,UAAU,IAAI,UAAU,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC;GAEnF,KAAK,SAAS,IAAI,mBAAmB,KAAK,OAAO;GACjD,KAAK,YAAY,KAAK,IAAI,KAAK,OAAO,IAAI,IAAI,mBAAmB,OAAO,CAAC,CAAC,CAAC;EAC5E;EAEA,KAAK,cAAc;CACpB;AACD"}
1
+ {"version":3,"file":"Circle.js","names":[],"sources":["../../../../src/layer/vector/Circle.js"],"sourcesContent":["import {CircleMarker} from './CircleMarker.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {EarthCRS} from '../../geo/crs/EarthCRS.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {CircleMarkerOptions} from './CircleMarker.js' */\n\n\n/**\n * Options of `Circle`.\n * @typedef {object} CircleOptions\n * @property {number} [radius] Radius of the circle, in meters.\n * @extends CircleMarkerOptions\n */\n\n/**\n * A class for drawing circle overlays on a map with radius specified in meters.\n * Extends `CircleMarker`, its `setRadius()` and `getRadius()` use meters.\n *\n * It's an approximation and starts to diverge from a real circle closer to poles\n * (due to projection distortion).\n *\n * @example\n * ```js\n * new Circle([50.5, 30.5], {radius: 200}).addTo(map);\n * ```\n */\nexport class Circle extends CircleMarker {\n\n\t/**\n\t * Instantiates a circle object given a geographical point, and an options object\n\t * which contains the circle radius.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tif (typeof options === 'number') {\n\t\t\tthrow new Error('Circle: the radius is an option in Maplair. Use new Circle(latlng, {radius}).');\n\t\t}\n\t\tsuper(latlng, options);\n\t\tthis.callInitHooks(Circle);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path. When the circle isn't on a map, they're\n\t * approximated on a sphere.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\tif (!this._map) { return this._latlng.toBounds(this._radius * 2); }\n\n\t\tconst half = [this._pxRadius, this._pxRadiusY ?? this._pxRadius];\n\n\t\treturn new LatLngBounds(\n\t\t\tthis._map.layerPointToLatLng(this._point.subtract(half)),\n\t\t\tthis._map.layerPointToLatLng(this._point.add(half)));\n\t}\n\n\t_project() {\n\n\t\tconst lng = this._latlng.lng,\n\t\tlat = this._latlng.lat,\n\t\tmap = this._map,\n\t\tcrs = map.options.crs,\n\t\trenderer = this._renderer,\n\t\tzoom = renderer._pathZoom;\n\n\t\tif (crs.distance === EarthCRS.distance) {\n\t\t\tconst d = Math.PI / 180,\n\t\t\tlatR = (this._radius / EarthCRS.R) / d,\n\t\t\ttop = map.project([lat + latR, lng], zoom),\n\t\t\tbottom = map.project([lat - latR, lng], zoom),\n\t\t\tp = top.add(bottom).divideBy(2),\n\t\t\tlat2 = map.unproject(p, zoom).lat;\n\t\t\t// Longitude span from the haversine form of the spherical law of cosines. The plain acos() form\n\t\t\t// loses precision for radii of about a metre and less, where cos(latR) is too close to 1 (#6120).\n\t\t\tlet lngR = 2 * Math.asin(Math.sqrt(\n\t\t\t\t(Math.sin(latR * d / 2) ** 2 - Math.sin((lat2 - lat) * d / 2) ** 2) /\n\t\t\t\t(Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;\n\n\t\t\tif (isNaN(lngR) || lngR === 0) {\n\t\t\t\tlngR = latR / Math.cos(lat * d); // Fallback for edge case, #2425\n\t\t\t}\n\n\t\t\tthis._point = p.subtract(renderer._pathOrigin);\n\t\t\t// distances rather than x/y deltas, for projections that rotate the axes\n\t\t\tthis._pxRadius = isNaN(lngR) ? 0 : p.distanceTo(map.project([lat2, lng - lngR], zoom));\n\t\t\tthis._pxRadiusY = p.distanceTo(top);\n\n\t\t} else {\n\t\t\tconst latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));\n\n\t\t\tthis._point = renderer._latLngToLayerPoint(this._latlng);\n\t\t\tthis._pxRadius = Math.abs(this._point.x - renderer._latLngToLayerPoint(latlng2).x);\n\t\t}\n\n\t\tthis._updateBounds();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,SAAb,MAAa,eAAe,aAAa;;;;;;;CAQxC,YAAY,QAAQ,SAAS;EAC5B,IAAI,OAAO,YAAY,UACtB,MAAM,IAAI,MAAM,+EAA+E;EAEhG,MAAM,QAAQ,OAAO;EACrB,KAAK,cAAc,MAAM;CAC1B;;;;;;CAOA,YAAY;EACX,IAAI,CAAC,KAAK,MAAQ,OAAO,KAAK,QAAQ,SAAS,KAAK,UAAU,CAAC;EAE/D,MAAM,OAAO,CAAC,KAAK,WAAW,KAAK,cAAc,KAAK,SAAS;EAE/D,OAAO,IAAI,aACV,KAAK,KAAK,mBAAmB,KAAK,OAAO,SAAS,IAAI,CAAC,GACvD,KAAK,KAAK,mBAAmB,KAAK,OAAO,IAAI,IAAI,CAAC,CAAC;CACrD;CAEA,WAAW;EAEV,MAAM,MAAM,KAAK,QAAQ,KACzB,MAAM,KAAK,QAAQ,KACnB,MAAM,KAAK,MACX,MAAM,IAAI,QAAQ,KAClB,WAAW,KAAK,WAChB,OAAO,SAAS;EAEhB,IAAI,IAAI,aAAa,SAAS,UAAU;GACvC,MAAM,IAAI,KAAK,KAAK,KACpB,OAAQ,KAAK,UAAU,SAAS,IAAK,GACrC,MAAM,IAAI,QAAQ,CAAC,MAAM,MAAM,GAAG,GAAG,IAAI,GACzC,SAAS,IAAI,QAAQ,CAAC,MAAM,MAAM,GAAG,GAAG,IAAI,GAC5C,IAAI,IAAI,IAAI,MAAM,CAAC,CAAC,SAAS,CAAC,GAC9B,OAAO,IAAI,UAAU,GAAG,IAAI,CAAC,CAAC;GAG9B,IAAI,OAAO,IAAI,KAAK,KAAK,KAAK,MAC5B,KAAK,IAAI,OAAO,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,OAAO,OAAO,IAAI,CAAC,KAAK,MAChE,KAAK,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC,EAAE,CAAC,IAAI;GAE9C,IAAI,MAAM,IAAI,KAAK,SAAS,GAC3B,OAAO,OAAO,KAAK,IAAI,MAAM,CAAC;GAG/B,KAAK,SAAS,EAAE,SAAS,SAAS,WAAW;GAE7C,KAAK,YAAY,MAAM,IAAI,IAAI,IAAI,EAAE,WAAW,IAAI,QAAQ,CAAC,MAAM,MAAM,IAAI,GAAG,IAAI,CAAC;GACrF,KAAK,aAAa,EAAE,WAAW,GAAG;EAEnC,OAAO;GACN,MAAM,UAAU,IAAI,UAAU,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC;GAEnF,KAAK,SAAS,SAAS,oBAAoB,KAAK,OAAO;GACvD,KAAK,YAAY,KAAK,IAAI,KAAK,OAAO,IAAI,SAAS,oBAAoB,OAAO,CAAC,CAAC,CAAC;EAClF;EAEA,KAAK,cAAc;CACpB;AACD"}
@@ -1,9 +1,10 @@
1
- import { setOptions } from "../../core/Util.js";
1
+ import { setOptions, toNumber } from "../../core/Util.js";
2
2
  import { Bounds } from "../../geometry/Bounds.js";
3
3
  import { Path } from "./Path.js";
4
4
  import { LatLng } from "../../geo/LatLng.js";
5
5
  import { pointToGeoJSON } from "../GeoJSONUtil.js";
6
6
  // src/layer/vector/CircleMarker.js
7
+ /** @import {MaplairMap} from '../../map/Map.js' */
7
8
  /** @import {Feature} from 'geojson' */
8
9
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
9
10
  /** @import {MaplairEvent} from '../../core/Events.js' */
@@ -44,10 +45,17 @@ var CircleMarker = class CircleMarker extends Path {
44
45
  super();
45
46
  setOptions(this, options);
46
47
  this._latlng = new LatLng(latlng);
47
- this._radius = this.options.radius;
48
+ this.setRadius(this.options.radius);
48
49
  this.callInitHooks(CircleMarker);
49
50
  }
50
51
  /**
52
+ * @param {MaplairMap} map
53
+ */
54
+ beforeAdd(map) {
55
+ super.beforeAdd(map);
56
+ map._displaceHandler?._beforeMarkerAdd(this);
57
+ }
58
+ /**
51
59
  * Sets the position of a circle marker to a new location.
52
60
  * @param {LatLngExpression} latlng
53
61
  * @returns {this}
@@ -74,7 +82,10 @@ var CircleMarker = class CircleMarker extends Path {
74
82
  * @returns {this}
75
83
  */
76
84
  setRadius(radius) {
77
- this.options.radius = this._radius = radius;
85
+ const r = toNumber(radius);
86
+ if (isNaN(r)) throw new Error(`Invalid radius: ${radius}`);
87
+ /** @type {number} */
88
+ this._radius = this.options.radius = r;
78
89
  return this.redraw();
79
90
  }
80
91
  /**
@@ -95,7 +106,7 @@ var CircleMarker = class CircleMarker extends Path {
95
106
  return this;
96
107
  }
97
108
  _project() {
98
- this._point = this._map.latLngToLayerPoint(this._latlng)._round();
109
+ this._point = this._renderer._latLngToLayerPoint(this._latlng)._round();
99
110
  this._pxRadius = this._radius;
100
111
  this._updateBounds();
101
112
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CircleMarker.js","names":[],"sources":["../../../../src/layer/vector/CircleMarker.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {pointToGeoJSON} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n/** @import {PathOptions} from './Path.js' */\n\n\n/**\n * Options of `CircleMarker`.\n * @typedef {object} CircleMarkerOptions\n * @property {boolean} [fill=true] Whether to fill the circle with color.\n * @property {number} [radius=10] Radius of the circle marker, in CSS pixels.\n * @extends PathOptions\n */\n\n/**\n * The event object of `move` of circle markers.\n * @typedef {object} CircleMarkerMoveEvent\n * @property {LatLng} oldLatLng The previous position of the circle marker.\n * @property {LatLng} latlng The new position of the circle marker.\n * @extends MaplairEvent\n */\n\n/**\n * A circle of a fixed size with radius specified in CSS pixels. Extends `Path`.\n *\n * @fires move {CircleMarkerMoveEvent} Fired when the marker is moved via\n * [`setLatLng`](#circlemarker-setlatlng). Old and new coordinates are included in\n * event arguments as `oldLatLng`, `latlng`.\n */\nexport class CircleMarker extends Path {\n\n\tstatic defaultOptions = {\n\t\tfill: true,\n\t\tradius: 10\n\t};\n\n\t/**\n\t * Instantiates a circle marker object given a geographical point, and an optional\n\t * options object.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleMarkerOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis._radius = this.options.radius;\n\n\t\tthis.callInitHooks(CircleMarker);\n\t}\n\n\t/**\n\t * Sets the position of a circle marker to a new location.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tconst oldLatLng = this._latlng;\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis.redraw();\n\n\t\treturn this.fire('move', {oldLatLng, latlng: this._latlng});\n\t}\n\n\t/**\n\t * Returns the current geographical position of the circle marker.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the radius of a circle marker. Units are in CSS pixels.\n\t * @param {number} radius\n\t * @returns {this}\n\t */\n\tsetRadius(radius) {\n\t\tthis.options.radius = this._radius = radius;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the current radius of the circle. Units are in CSS pixels.\n\t * @returns {number}\n\t */\n\tgetRadius() {\n\t\treturn this._radius;\n\t}\n\n\t/**\n\t * Changes the appearance of the circle marker, also its `radius`.\n\t * @param {CircleMarkerOptions} options\n\t * @returns {this}\n\t */\n\tsetStyle(options) {\n\t\tsuper.setStyle(options);\n\t\tif (options?.radius !== undefined) {\n\t\t\tthis.setRadius(options.radius);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_project() {\n\t\t// snapped to whole pixels: subpixel precision is invisible on markers but slows down rendering many of them\n\t\tthis._point = this._map.latLngToLayerPoint(this._latlng)._round();\n\t\tthis._pxRadius = this._radius;\n\t\tthis._updateBounds();\n\t}\n\n\t_updateBounds() {\n\t\tconst r = this._pxRadius,\n\t\tr2 = this._pxRadiusY ?? r,\n\t\tw = this._clickTolerance(),\n\t\tp = [r + w, r2 + w];\n\t\tthis._pxBounds = new Bounds(this._point.subtract(p), this._point.add(p));\n\t}\n\n\t_update() {\n\t\tif (this._map) {\n\t\t\tthis._updatePath();\n\t\t}\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updateCircle(this);\n\t}\n\n\t_empty() {\n\t\treturn this._pxRadius && !this._renderer._bounds.intersects(this._pxBounds);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p) {\n\t\treturn p.distanceTo(this._point) <= this._pxRadius + this._clickTolerance();\n\t}\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the circle marker (as a GeoJSON `Point` Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\treturn pointToGeoJSON(this, precision);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,eAAb,MAAa,qBAAqB,KAAK;CAEtC,OAAO,iBAAiB;EACvB,MAAM;EACN,QAAQ;CACT;;;;;;;CAQ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AK,KAAK,YAAY,KAAK,gBAAgB;CAC3E;;;;;;;;CASA,UAAU,WAAW;EACpB,OAAO,eAAe,MAAM,SAAS;CACtC;AACD"}
1
+ {"version":3,"file":"CircleMarker.js","names":["Util.toNumber"],"sources":["../../../../src/layer/vector/CircleMarker.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {pointToGeoJSON} from '../GeoJSONUtil.js';\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n/** @import {PathOptions} from './Path.js' */\n\n\n/**\n * Options of `CircleMarker`.\n * @typedef {object} CircleMarkerOptions\n * @property {boolean} [fill=true] Whether to fill the circle with color.\n * @property {number} [radius=10] Radius of the circle marker, in CSS pixels.\n * @extends PathOptions\n */\n\n/**\n * The event object of `move` of circle markers.\n * @typedef {object} CircleMarkerMoveEvent\n * @property {LatLng} oldLatLng The previous position of the circle marker.\n * @property {LatLng} latlng The new position of the circle marker.\n * @extends MaplairEvent\n */\n\n/**\n * A circle of a fixed size with radius specified in CSS pixels. Extends `Path`.\n *\n * @fires move {CircleMarkerMoveEvent} Fired when the marker is moved via\n * [`setLatLng`](#circlemarker-setlatlng). Old and new coordinates are included in\n * event arguments as `oldLatLng`, `latlng`.\n */\nexport class CircleMarker extends Path {\n\n\tstatic defaultOptions = {\n\t\tfill: true,\n\t\tradius: 10\n\t};\n\n\t/**\n\t * Instantiates a circle marker object given a geographical point, and an optional\n\t * options object.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleMarkerOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis.setRadius(this.options.radius);\n\n\t\tthis.callInitHooks(CircleMarker);\n\t}\n\n\t/**\n\t * @param {MaplairMap} map\n\t */\n\tbeforeAdd(map) {\n\t\tsuper.beforeAdd(map);\n\t\t// before the marker is drawn, see `DisplaceHandler`\n\t\tmap._displaceHandler?._beforeMarkerAdd(this);\n\t}\n\n\t/**\n\t * Sets the position of a circle marker to a new location.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tconst oldLatLng = this._latlng;\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis.redraw();\n\n\t\treturn this.fire('move', {oldLatLng, latlng: this._latlng});\n\t}\n\n\t/**\n\t * Returns the current geographical position of the circle marker.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the radius of a circle marker. Units are in CSS pixels.\n\t * @param {number} radius\n\t * @returns {this}\n\t */\n\tsetRadius(radius) {\n\t\tconst r = Util.toNumber(radius);\n\t\tif (isNaN(r)) { throw new Error(`Invalid radius: ${radius}`); }\n\t\t/** @type {number} */\n\t\tthis._radius = this.options.radius = r;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the current radius of the circle. Units are in CSS pixels.\n\t * @returns {number}\n\t */\n\tgetRadius() {\n\t\treturn this._radius;\n\t}\n\n\t/**\n\t * Changes the appearance of the circle marker, also its `radius`.\n\t * @param {CircleMarkerOptions} options\n\t * @returns {this}\n\t */\n\tsetStyle(options) {\n\t\tsuper.setStyle(options);\n\t\tif (options?.radius !== undefined) {\n\t\t\tthis.setRadius(options.radius);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_project() {\n\t\t// snapped to whole pixels: subpixel precision is invisible on markers but slows down rendering many of them\n\t\tthis._point = this._renderer._latLngToLayerPoint(this._latlng)._round();\n\t\tthis._pxRadius = this._radius;\n\t\tthis._updateBounds();\n\t}\n\n\t_updateBounds() {\n\t\tconst r = this._pxRadius,\n\t\tr2 = this._pxRadiusY ?? r,\n\t\tw = this._clickTolerance(),\n\t\tp = [r + w, r2 + w];\n\t\tthis._pxBounds = new Bounds(this._point.subtract(p), this._point.add(p));\n\t}\n\n\t_update() {\n\t\tif (this._map) {\n\t\t\tthis._updatePath();\n\t\t}\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updateCircle(this);\n\t}\n\n\t_empty() {\n\t\treturn this._pxRadius && !this._renderer._bounds.intersects(this._pxBounds);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p) {\n\t\treturn p.distanceTo(this._point) <= this._pxRadius + this._clickTolerance();\n\t}\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the circle marker (as a GeoJSON `Point` Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\treturn pointToGeoJSON(this, precision);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAa,eAAb,MAAa,qBAAqB,KAAK;CAEtC,OAAO,iBAAiB;EACvB,MAAM;EACN,QAAQ;CACT;;;;;;;CAQA,YAAY,QAAQ,SAAS;EAC5B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B,KAAK,UAAU,IAAI,OAAO,MAAM;EAChC,KAAK,UAAU,KAAK,QAAQ,MAAM;EAElC,KAAK,cAAc,YAAY;CAChC;;;;CAKA,UAAU,KAAK;EACd,MAAM,UAAU,GAAG;EAEnB,IAAI,kBAAkB,iBAAiB,IAAI;CAC5C;;;;;;CAOA,UAAU,QAAQ;EACjB,MAAM,YAAY,KAAK;EACvB,KAAK,UAAU,IAAI,OAAO,MAAM;EAChC,KAAK,OAAO;EAEZ,OAAO,KAAK,KAAK,QAAQ;GAAC;GAAW,QAAQ,KAAK;EAAO,CAAC;CAC3D;;;;;CAMA,YAAY;EACX,OAAO,KAAK;CACb;;;;;;CAOA,UAAU,QAAQ;EACjB,MAAM,IAAIA,SAAc,MAAM;EAC9B,IAAI,MAAM,CAAC,GAAK,MAAM,IAAI,MAAM,mBAAmB,QAAQ;;EAE3D,KAAK,UAAU,KAAK,QAAQ,SAAS;EACrC,OAAO,KAAK,OAAO;CACpB;;;;;CAMA,YAAY;EACX,OAAO,KAAK;CACb;;;;;;CAOA,SAAS,SAAS;EACjB,MAAM,SAAS,OAAO;EACtB,IAAI,SAAS,WAAW,KAAA,GACvB,KAAK,UAAU,QAAQ,MAAM;EAE9B,OAAO;CACR;CAEA,WAAW;EAEV,KAAK,SAAS,KAAK,UAAU,oBAAoB,KAAK,OAAO,CAAC,CAAC,OAAO;EACtE,KAAK,YAAY,KAAK;EACtB,KAAK,cAAc;CACpB;CAEA,gBAAgB;EACf,MAAM,IAAI,KAAK,WACf,KAAK,KAAK,cAAc,GACxB,IAAI,KAAK,gBAAgB,GACzB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;EAClB,KAAK,YAAY,IAAI,OAAO,KAAK,OAAO,SAAS,CAAC,GAAG,KAAK,OAAO,IAAI,CAAC,CAAC;CACxE;CAEA,UAAU;EACT,IAAI,KAAK,MACR,KAAK,YAAY;CAEnB;CAEA,cAAc;EACb,KAAK,UAAU,cAAc,IAAI;CAClC;CAEA,SAAS;EACR,OAAO,KAAK,aAAa,CAAC,KAAK,UAAU,QAAQ,WAAW,KAAK,SAAS;CAC3E;CAGA,eAAe,GAAG;EACjB,OAAO,EAAE,WAAW,KAAK,MAAM,KAAK,KAAK,YAAY,KAAK,gBAAgB;CAC3E;;;;;;;;CASA,UAAU,WAAW;EACpB,OAAO,eAAe,MAAM,SAAS;CACtC;AACD"}
@@ -67,7 +67,10 @@ Path.include({
67
67
  });
68
68
  CircleMarker.include({ setRadius(radius) {
69
69
  this._takeZoomStyles({ radius });
70
- return this._zoomStyles?.radius && this._map ? setRadius.call(this, evaluate(radius, this._map.getZoom())) : setRadius.call(this, radius);
70
+ if (!this._zoomStyles?.radius) return setRadius.call(this, radius);
71
+ if (this._map) return setRadius.call(this, evaluate(radius, this._map.getZoom()));
72
+ this.options.radius = this._radius = radius;
73
+ return this;
71
74
  } });
72
75
  Path.addInitHook(function() {
73
76
  this._takeZoomStyles(this.options);
@@ -1 +1 @@
1
- {"version":3,"file":"Path.ZoomStyles.js","names":[],"sources":["../../../../src/layer/vector/Path.ZoomStyles.js"],"sourcesContent":["import {Path} from './Path.js';\nimport {CircleMarker} from './CircleMarker.js';\n\n/**\n * A zoom-dependent style value, of the `weight` option of paths and the `radius` of\n * circle markers: either a function of the zoom or an object of zoom stops\n * `{zoom: value}`, using the value of the highest stop not above the zoom (or of the\n * lowest stop). The styles are updated on `zoomend`.\n *\n * Zoom-dependent styles are an optional feature, like the zoom expressions of\n * MapLibre: import this module to let the `weight` and `radius` options depend on the\n * zoom.\n *\n * ```js\n * import 'maplair/zoom-styles';\n *\n * new CircleMarker(latlng, {radius: {5: 3, 10: 6, 15: 10}}).addTo(map);\n * new Polyline(latlngs, {weight: zoom => zoom / 2}).addTo(map);\n * ```\n * @typedef {number|Record<number, number>|((zoom: number) => number)} ZoomStyle\n */\n\nconst zoomStyleNames = ['weight', 'radius'];\n\n// The value of `stops` (a function or an object of zoom stops) at `zoom`\nfunction evaluate(stops, zoom) {\n\tif (typeof stops === 'function') { return stops(zoom); }\n\tconst zooms = Object.keys(stops).map(Number).sort((a, b) => a - b);\n\treturn stops[zooms.findLast(z => z <= zoom) ?? zooms[0]];\n}\n\nconst {beforeAdd, setStyle} = Path.prototype,\n{setRadius} = CircleMarker.prototype;\n\nPath.include({\n\tgetEvents() {\n\t\t// also for zoom-dependent styles set later with `setStyle()`\n\t\treturn {zoomend: this._updateZoomStyles};\n\t},\n\n\tbeforeAdd(map) {\n\t\tbeforeAdd.call(this, map);\n\t\t// before the path is drawn\n\t\tthis._applyZoomStyles(map.getZoom());\n\t},\n\n\tsetStyle(style) {\n\t\tthis._takeZoomStyles(style);\n\t\tconst zoom = this._map?.getZoom();\n\t\tif (style && this._zoomStyles && zoom !== undefined) {\n\t\t\tstyle = {...style};\n\t\t\tfor (const [name, stops] of Object.entries(this._zoomStyles)) {\n\t\t\t\tif (Object.hasOwn(style, name)) {\n\t\t\t\t\tstyle[name] = evaluate(stops, zoom);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn setStyle.call(this, style);\n\t},\n\n\t// Keeps the zoom-dependent values of `style` (functions and objects) in\n\t// `_zoomStyles`, numbers replace them\n\t_takeZoomStyles(style) {\n\t\tfor (const name of zoomStyleNames) {\n\t\t\tif (!style || !Object.hasOwn(style, name)) { continue; }\n\t\t\tconst value = style[name];\n\t\t\tif (value && (typeof value === 'function' || typeof value === 'object')) {\n\t\t\t\tthis._zoomStyles = {...this._zoomStyles, [name]: value};\n\t\t\t} else if (this._zoomStyles) {\n\t\t\t\tdelete this._zoomStyles[name];\n\t\t\t}\n\t\t}\n\t},\n\n\t_applyZoomStyles(zoom) {\n\t\tif (!this._zoomStyles) { return; }\n\t\tconst values = {};\n\t\tfor (const [name, stops] of Object.entries(this._zoomStyles)) {\n\t\t\tvalues[name] = evaluate(stops, zoom);\n\t\t}\n\t\tsetStyle.call(this, values);\n\t\tif (values.radius !== undefined && this.setRadius) {\n\t\t\tsetRadius.call(this, values.radius);\n\t\t}\n\t},\n\n\t_updateZoomStyles() {\n\t\tthis._applyZoomStyles(this._map.getZoom());\n\t}\n});\n\nCircleMarker.include({\n\tsetRadius(radius) {\n\t\tthis._takeZoomStyles({radius});\n\t\treturn this._zoomStyles?.radius && this._map ?\n\t\t\tsetRadius.call(this, evaluate(radius, this._map.getZoom())) :\n\t\t\tsetRadius.call(this, radius);\n\t}\n});\n\nPath.addInitHook(function () {\n\tthis._takeZoomStyles(this.options);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,iBAAiB,CAAC,UAAU,QAAQ;AAG1C,SAAS,SAAS,OAAO,MAAM;CAC9B,IAAI,OAAO,UAAU,YAAc,OAAO,MAAM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SAAS,KAAK,MAAM,MAAM;EAC1B,IAAI,OAAO,WAAW,KAAA,KAAa,KAAK,WACvC,UAAU,KAAK,MAAM,OAAO,MAAM;CAEpC;CAEA,oBAAoB;EACnB,KAAK,iBAAiB,KAAK,KAAK,QAAQ,CAAC;CAC1C;AACD,CAAC;AAED,aAAa,QAAQ,EACpB,UAAU,QAAQ;CACjB,KAAK,gBAAgB,EAAC,OAAM,CAAC;CAC7B,OAAO,KAAK,aAAa,UAAU,KAAK,OACvC,UAAU,KAAK,MAAM,SAAS,QAAQ,KAAK,KAAK,QAAQ,CAAC,CAAC,IAC1D,UAAU,KAAK,MAAM,MAAM;AAC7B,EACD,CAAC;AAED,KAAK,YAAY,WAAY;CAC5B,KAAK,gBAAgB,KAAK,OAAO;AAClC,CAAC"}
1
+ {"version":3,"file":"Path.ZoomStyles.js","names":[],"sources":["../../../../src/layer/vector/Path.ZoomStyles.js"],"sourcesContent":["import {Path} from './Path.js';\nimport {CircleMarker} from './CircleMarker.js';\n\n/**\n * A zoom-dependent style value, of the `weight` option of paths and the `radius` of\n * circle markers: either a function of the zoom or an object of zoom stops\n * `{zoom: value}`, using the value of the highest stop not above the zoom (or of the\n * lowest stop). The styles are updated on `zoomend`.\n *\n * Zoom-dependent styles are an optional feature, like the zoom expressions of\n * MapLibre: import this module to let the `weight` and `radius` options depend on the\n * zoom.\n *\n * ```js\n * import 'maplair/zoom-styles';\n *\n * new CircleMarker(latlng, {radius: {5: 3, 10: 6, 15: 10}}).addTo(map);\n * new Polyline(latlngs, {weight: zoom => zoom / 2}).addTo(map);\n * ```\n * @typedef {number|Record<number, number>|((zoom: number) => number)} ZoomStyle\n */\n\nconst zoomStyleNames = ['weight', 'radius'];\n\n// The value of `stops` (a function or an object of zoom stops) at `zoom`\nfunction evaluate(stops, zoom) {\n\tif (typeof stops === 'function') { return stops(zoom); }\n\tconst zooms = Object.keys(stops).map(Number).sort((a, b) => a - b);\n\treturn stops[zooms.findLast(z => z <= zoom) ?? zooms[0]];\n}\n\nconst {beforeAdd, setStyle} = Path.prototype,\n{setRadius} = CircleMarker.prototype;\n\nPath.include({\n\tgetEvents() {\n\t\t// also for zoom-dependent styles set later with `setStyle()`\n\t\treturn {zoomend: this._updateZoomStyles};\n\t},\n\n\tbeforeAdd(map) {\n\t\tbeforeAdd.call(this, map);\n\t\t// before the path is drawn\n\t\tthis._applyZoomStyles(map.getZoom());\n\t},\n\n\tsetStyle(style) {\n\t\tthis._takeZoomStyles(style);\n\t\tconst zoom = this._map?.getZoom();\n\t\tif (style && this._zoomStyles && zoom !== undefined) {\n\t\t\tstyle = {...style};\n\t\t\tfor (const [name, stops] of Object.entries(this._zoomStyles)) {\n\t\t\t\tif (Object.hasOwn(style, name)) {\n\t\t\t\t\tstyle[name] = evaluate(stops, zoom);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn setStyle.call(this, style);\n\t},\n\n\t// Keeps the zoom-dependent values of `style` (functions and objects) in\n\t// `_zoomStyles`, numbers replace them\n\t_takeZoomStyles(style) {\n\t\tfor (const name of zoomStyleNames) {\n\t\t\tif (!style || !Object.hasOwn(style, name)) { continue; }\n\t\t\tconst value = style[name];\n\t\t\tif (value && (typeof value === 'function' || typeof value === 'object')) {\n\t\t\t\tthis._zoomStyles = {...this._zoomStyles, [name]: value};\n\t\t\t} else if (this._zoomStyles) {\n\t\t\t\tdelete this._zoomStyles[name];\n\t\t\t}\n\t\t}\n\t},\n\n\t_applyZoomStyles(zoom) {\n\t\tif (!this._zoomStyles) { return; }\n\t\tconst values = {};\n\t\tfor (const [name, stops] of Object.entries(this._zoomStyles)) {\n\t\t\tvalues[name] = evaluate(stops, zoom);\n\t\t}\n\t\tsetStyle.call(this, values);\n\t\tif (values.radius !== undefined && this.setRadius) {\n\t\t\tsetRadius.call(this, values.radius);\n\t\t}\n\t},\n\n\t_updateZoomStyles() {\n\t\tthis._applyZoomStyles(this._map.getZoom());\n\t}\n});\n\nCircleMarker.include({\n\tsetRadius(radius) {\n\t\tthis._takeZoomStyles({radius});\n\t\tif (!this._zoomStyles?.radius) { return setRadius.call(this, radius); }\n\t\tif (this._map) { return setRadius.call(this, evaluate(radius, this._map.getZoom())); }\n\t\t// evaluated when the circle marker is added to a map\n\t\tthis.options.radius = this._radius = radius;\n\t\treturn this;\n\t}\n});\n\nPath.addInitHook(function () {\n\tthis._takeZoomStyles(this.options);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,iBAAiB,CAAC,UAAU,QAAQ;AAG1C,SAAS,SAAS,OAAO,MAAM;CAC9B,IAAI,OAAO,UAAU,YAAc,OAAO,MAAM,IAAI;CACpD,MAAM,QAAQ,OAAO,KAAK,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC;CACjE,OAAO,MAAM,MAAM,UAAS,MAAK,KAAK,IAAI,KAAK,MAAM;AACtD;AAEA,MAAM,EAAC,WAAW,aAAY,KAAK,WACnC,EAAC,cAAa,aAAa;AAE3B,KAAK,QAAQ;CACZ,YAAY;EAEX,OAAO,EAAC,SAAS,KAAK,kBAAiB;CACxC;CAEA,UAAU,KAAK;EACd,UAAU,KAAK,MAAM,GAAG;EAExB,KAAK,iBAAiB,IAAI,QAAQ,CAAC;CACpC;CAEA,SAAS,OAAO;EACf,KAAK,gBAAgB,KAAK;EAC1B,MAAM,OAAO,KAAK,MAAM,QAAQ;EAChC,IAAI,SAAS,KAAK,eAAe,SAAS,KAAA,GAAW;GACpD,QAAQ,EAAC,GAAG,MAAK;GACjB,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,WAAW,GAC1D,IAAI,OAAO,OAAO,OAAO,IAAI,GAC5B,MAAM,QAAQ,SAAS,OAAO,IAAI;EAGrC;EACA,OAAO,SAAS,KAAK,MAAM,KAAK;CACjC;CAIA,gBAAgB,OAAO;EACtB,KAAK,MAAM,QAAQ,gBAAgB;GAClC,IAAI,CAAC,SAAS,CAAC,OAAO,OAAO,OAAO,IAAI,GAAK;GAC7C,MAAM,QAAQ,MAAM;GACpB,IAAI,UAAU,OAAO,UAAU,cAAc,OAAO,UAAU,WAC7D,KAAK,cAAc;IAAC,GAAG,KAAK;KAAc,OAAO;GAAK;QAChD,IAAI,KAAK,aACf,OAAO,KAAK,YAAY;EAE1B;CACD;CAEA,iBAAiB,MAAM;EACtB,IAAI,CAAC,KAAK,aAAe;EACzB,MAAM,SAAS,CAAC;EAChB,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,WAAW,GAC1D,OAAO,QAAQ,SAAS,OAAO,IAAI;EAEpC,SAAS,KAAK,MAAM,MAAM;EAC1B,IAAI,OAAO,WAAW,KAAA,KAAa,KAAK,WACvC,UAAU,KAAK,MAAM,OAAO,MAAM;CAEpC;CAEA,oBAAoB;EACnB,KAAK,iBAAiB,KAAK,KAAK,QAAQ,CAAC;CAC1C;AACD,CAAC;AAED,aAAa,QAAQ,EACpB,UAAU,QAAQ;CACjB,KAAK,gBAAgB,EAAC,OAAM,CAAC;CAC7B,IAAI,CAAC,KAAK,aAAa,QAAU,OAAO,UAAU,KAAK,MAAM,MAAM;CACnE,IAAI,KAAK,MAAQ,OAAO,UAAU,KAAK,MAAM,SAAS,QAAQ,KAAK,KAAK,QAAQ,CAAC,CAAC;CAElF,KAAK,QAAQ,SAAS,KAAK,UAAU;CACrC,OAAO;AACR,EACD,CAAC;AAED,KAAK,YAAY,WAAY;CAC5B,KAAK,gBAAgB,KAAK,OAAO;AAClC,CAAC"}
@@ -36,13 +36,15 @@ import { SVG } from "./SVG.js";
36
36
  * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it
37
37
  * afterwards.
38
38
  * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this
39
- * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer),
40
- * which is `SVG` by default. If set, it overrides the `pane` option.
39
+ * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)
40
+ * (`SVG` by default), or in a custom pane, a renderer of the same kind created for
41
+ * that pane. If set, it overrides the `pane` option.
41
42
  * @extends InteractiveLayerOptions
42
43
  */
43
44
  /**
44
- * An abstract class that contains options and constants shared between vector
45
- * overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.
45
+ * An abstract class that contains options and methods shared between vector overlays
46
+ * (`Polyline`, `Polygon`, `Rectangle`, `Circle`, `CircleMarker`). Do not use it
47
+ * directly. Extends `Layer`.
46
48
  */
47
49
  var Path = class extends Layer {
48
50
  static defaultOptions = {
@@ -139,8 +141,11 @@ var Path = class extends Layer {
139
141
  this._project();
140
142
  this._update();
141
143
  }
144
+ _togglesPopupOnClick() {
145
+ return false;
146
+ }
142
147
  _clickTolerance() {
143
- return (this.options.stroke ? this.options.weight / 2 : 0) + (this._renderer.options.tolerance || 0);
148
+ return (this.options.stroke ? this.options.weight / 2 || 0 : 0) + (this._renderer.options.tolerance || 0);
144
149
  }
145
150
  };
146
151
  export { Path };
@@ -1 +1 @@
1
- {"version":3,"file":"Path.js","names":[],"sources":["../../../../src/layer/vector/Path.js"],"sourcesContent":["import {Layer} from '../Layer.js';\nimport {SVG} from './SVG.js';\nimport * as Util from '../../core/Util.js';\n/** @import {InteractiveLayerOptions} from '../Layer.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Renderer} from './Renderer.js' */\n\n/**\n * Options of `Path`, shared by all vector layers.\n * @typedef {object} PathOptions\n * @property {boolean} [stroke=true] Whether to draw stroke along the path. Set it to\n * `false` to disable borders on polygons or circles.\n * @property {string} [color='#3388ff'] Stroke color.\n * @property {number} [weight=3] Stroke width in pixels.\n * @property {number} [opacity=1] Stroke opacity.\n * @property {string} [lineCap='round'] A string that defines\n * [shape to be used at the end](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linecap)\n * of the stroke.\n * @property {string} [lineJoin='round'] A string that defines\n * [shape to be used at the corners](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linejoin)\n * of the stroke.\n * @property {string|null} [dashArray=null] A string that defines the stroke\n * [dash pattern](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dasharray).\n * @property {string|null} [dashOffset=null] A string that defines the\n * [distance into the dash pattern to start the dash](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dashoffset).\n * @property {boolean} [fill=false] Whether to fill the path with color. Set it to\n * `false` to disable filling on polygons or circles. The default depends on the\n * class: `true` for polygons and circles.\n * @property {string|null} [fillColor=null] Fill color. Defaults to the value of the\n * [`color`](#pathoptions-color) option.\n * @property {number} [fillOpacity=0.2] Fill opacity.\n * @property {string} [fillRule='evenodd'] A string that defines\n * [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule)\n * is determined.\n * @property {string} [className] Custom class name set on an element. Only for SVG renderer.\n * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it\n * afterwards.\n * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this\n * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer),\n * which is `SVG` by default. If set, it overrides the `pane` option.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * An abstract class that contains options and constants shared between vector\n * overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.\n */\nexport class Path extends Layer {\n\n\tstatic defaultOptions = {\n\t\tstroke: true,\n\t\tcolor: '#3388ff',\n\t\tweight: 3,\n\t\topacity: 1,\n\t\tlineCap: 'round',\n\t\tlineJoin: 'round',\n\t\tdashArray: null,\n\t\tdashOffset: null,\n\t\tfill: false,\n\t\tfillColor: null,\n\t\tfillOpacity: 0.2,\n\t\tfillRule: 'evenodd',\n\t\t// className: '',\n\t\tinteractive: true,\n\t\tbubblingPointerEvents: true\n\t};\n\n\t/**\n\t * Gets the renderer of the path from the map, before it is added.\n\t * @param {MaplairMap} map\n\t */\n\tbeforeAdd(map) {\n\t\t// Renderer is set here because we need to call renderer.getEvents\n\t\t// before this.getEvents.\n\t\tthis._renderer = map.getRenderer(this);\n\t}\n\n\t/**\n\t * Adds the path to its renderer.\n\t */\n\tonAdd() {\n\t\tthis._renderer._initPath(this);\n\t\tthis._reset();\n\t\tthis._renderer._addPath(this);\n\t}\n\n\t/**\n\t * Removes the path from its renderer.\n\t */\n\tonRemove() {\n\t\tthis._renderer._removePath(this);\n\t}\n\n\t/**\n\t * Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map) {\n\t\t\tthis._renderer._updatePath(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_updateInteractive() {\n\t\tthis._renderer._updateInteractive(this);\n\t}\n\n\t/**\n\t * Changes the appearance of a Path based on the options in the `PathOptions` object.\n\t * Note that [`className`](#pathoptions-classname) is an exception: it is applied only\n\t * when the path element is created, so passing it here updates the option but leaves\n\t * the element's class unchanged.\n\t * @param {PathOptions} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\tUtil.setOptions(this, style);\n\t\tif (this._renderer) {\n\t\t\tthis._renderer._updateStyle(this);\n\t\t\tif (this.options.stroke && style && Object.hasOwn(style, 'weight')) {\n\t\t\t\tthis._updateBounds();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all path layers.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tthis._renderer?._bringToFront(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all path layers.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tthis._renderer?._bringToBack(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the SVG `path` element of the layer, if it is rendered by the `SVG` renderer.\n\t * @returns {SVGPathElement|undefined}\n\t */\n\tgetElement() {\n\t\treturn this._path;\n\t}\n\n\t// the renderer of the path if neither the path nor the map has one\n\t_createRenderer(options) {\n\t\treturn new SVG(options);\n\t}\n\n\t_reset() {\n\t\t// defined in child classes\n\t\tthis._project();\n\t\tthis._update();\n\t}\n\n\t_clickTolerance() {\n\t\t// used when doing hit detection for Canvas layers\n\t\treturn (this.options.stroke ? this.options.weight / 2 : 0) +\n\t\t (this._renderer.options.tolerance || 0);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,OAAb,cAA0B,MAAM;CAE/B,OAAO,iBAAiB;EACvB,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,SAAS;EACT,SAAS;EACT,UAAU;EACV,WAAW;EACX,YAAY;EACZ,MAAM;EACN,WAAW;EACX,aAAa;EACb,UAAU;EAEV,aAAa;EACb,uBAAuB;CACxB;;;;;CAMA,UAAU,KAAK;EAGd,KAAK,YAAY,IAAI,YAAY,IAAI;CACtC;;;;CAKA,QAAQ;EACP,KAAK,UAAU,UAAU,IAAI;EAC7B,KAAK,OAAO;EACZ,KAAK,UAAU,SAAS,IAAI;CAC7B;;;;CAKA,WAAW;EACV,KAAK,UAAU,YAAY,IAAI;CAChC;;;;;CAMA,SAAS;EACR,IAAI,KAAK,MACR,KAAK,UAAU,YAAY,IAAI;EAEhC,OAAO;CACR;CAEA,qBAAqB;EACpB,KAAK,UAAU,mBAAmB,IAAI;CACvC;;;;;;;;;CAUA,SAAS,OAAO;EACf,WAAgB,MAAM,KAAK;EAC3B,IAAI,KAAK,WAAW;GACnB,KAAK,UAAU,aAAa,IAAI;GAChC,IAAI,KAAK,QAAQ,UAAU,SAAS,OAAO,OAAO,OAAO,QAAQ,GAChE,KAAK,cAAc;EAErB;EACA,OAAO;CACR;;;;;CAMA,eAAe;EACd,KAAK,WAAW,cAAc,IAAI;EAClC,OAAO;CACR;;;;;CAMA,cAAc;EACb,KAAK,WAAW,aAAa,IAAI;EACjC,OAAO;CACR;;;;;CAMA,aAAa;EACZ,OAAO,KAAK;CACb;CAGA,gBAAgB,SAAS;EACxB,OAAO,IAAI,IAAI,OAAO;CACvB;CAEA,SAAS;EAER,KAAK,SAAS;EACd,KAAK,QAAQ;CACd;CAEA,kBAAkB;EAEjB,QAAQ,KAAK,QAAQ,SAAS,KAAK,QAAQ,SAAS,IAAI,MACrD,KAAK,UAAU,QAAQ,aAAa;CACxC;AACD"}
1
+ {"version":3,"file":"Path.js","names":[],"sources":["../../../../src/layer/vector/Path.js"],"sourcesContent":["import {Layer} from '../Layer.js';\nimport {SVG} from './SVG.js';\nimport * as Util from '../../core/Util.js';\n/** @import {InteractiveLayerOptions} from '../Layer.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Renderer} from './Renderer.js' */\n\n/**\n * Options of `Path`, shared by all vector layers.\n * @typedef {object} PathOptions\n * @property {boolean} [stroke=true] Whether to draw stroke along the path. Set it to\n * `false` to disable borders on polygons or circles.\n * @property {string} [color='#3388ff'] Stroke color.\n * @property {number} [weight=3] Stroke width in pixels.\n * @property {number} [opacity=1] Stroke opacity.\n * @property {string} [lineCap='round'] A string that defines\n * [shape to be used at the end](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linecap)\n * of the stroke.\n * @property {string} [lineJoin='round'] A string that defines\n * [shape to be used at the corners](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linejoin)\n * of the stroke.\n * @property {string|null} [dashArray=null] A string that defines the stroke\n * [dash pattern](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dasharray).\n * @property {string|null} [dashOffset=null] A string that defines the\n * [distance into the dash pattern to start the dash](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dashoffset).\n * @property {boolean} [fill=false] Whether to fill the path with color. Set it to\n * `false` to disable filling on polygons or circles. The default depends on the\n * class: `true` for polygons and circles.\n * @property {string|null} [fillColor=null] Fill color. Defaults to the value of the\n * [`color`](#pathoptions-color) option.\n * @property {number} [fillOpacity=0.2] Fill opacity.\n * @property {string} [fillRule='evenodd'] A string that defines\n * [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule)\n * is determined.\n * @property {string} [className] Custom class name set on an element. Only for SVG renderer.\n * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it\n * afterwards.\n * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this\n * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)\n * (`SVG` by default), or in a custom pane, a renderer of the same kind created for\n * that pane. If set, it overrides the `pane` option.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * An abstract class that contains options and methods shared between vector overlays\n * (`Polyline`, `Polygon`, `Rectangle`, `Circle`, `CircleMarker`). Do not use it\n * directly. Extends `Layer`.\n */\nexport class Path extends Layer {\n\n\tstatic defaultOptions = {\n\t\tstroke: true,\n\t\tcolor: '#3388ff',\n\t\tweight: 3,\n\t\topacity: 1,\n\t\tlineCap: 'round',\n\t\tlineJoin: 'round',\n\t\tdashArray: null,\n\t\tdashOffset: null,\n\t\tfill: false,\n\t\tfillColor: null,\n\t\tfillOpacity: 0.2,\n\t\tfillRule: 'evenodd',\n\t\t// className: '',\n\t\tinteractive: true,\n\t\tbubblingPointerEvents: true\n\t};\n\n\t/**\n\t * Gets the renderer of the path from the map, before it is added.\n\t * @param {MaplairMap} map\n\t */\n\tbeforeAdd(map) {\n\t\t// Renderer is set here because we need to call renderer.getEvents\n\t\t// before this.getEvents.\n\t\tthis._renderer = map.getRenderer(this);\n\t}\n\n\t/**\n\t * Adds the path to its renderer.\n\t */\n\tonAdd() {\n\t\tthis._renderer._initPath(this);\n\t\tthis._reset();\n\t\tthis._renderer._addPath(this);\n\t}\n\n\t/**\n\t * Removes the path from its renderer.\n\t */\n\tonRemove() {\n\t\tthis._renderer._removePath(this);\n\t}\n\n\t/**\n\t * Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map) {\n\t\t\tthis._renderer._updatePath(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_updateInteractive() {\n\t\tthis._renderer._updateInteractive(this);\n\t}\n\n\t/**\n\t * Changes the appearance of a Path based on the options in the `PathOptions` object.\n\t * Note that [`className`](#pathoptions-classname) is an exception: it is applied only\n\t * when the path element is created, so passing it here updates the option but leaves\n\t * the element's class unchanged.\n\t * @param {PathOptions} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\tUtil.setOptions(this, style);\n\t\tif (this._renderer) {\n\t\t\tthis._renderer._updateStyle(this);\n\t\t\tif (this.options.stroke && style && Object.hasOwn(style, 'weight')) {\n\t\t\t\tthis._updateBounds();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all path layers.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tthis._renderer?._bringToFront(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all path layers.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tthis._renderer?._bringToBack(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the SVG `path` element of the layer, if it is rendered by the `SVG` renderer.\n\t * @returns {SVGPathElement|undefined}\n\t */\n\tgetElement() {\n\t\treturn this._path;\n\t}\n\n\t// the renderer of the path if neither the path nor the map has one\n\t_createRenderer(options) {\n\t\treturn new SVG(options);\n\t}\n\n\t_reset() {\n\t\t// defined in child classes\n\t\tthis._project();\n\t\tthis._update();\n\t}\n\n\t_togglesPopupOnClick() {\n\t\treturn false;\n\t}\n\n\t_clickTolerance() {\n\t\t// used when doing hit detection for Canvas layers\n\t\treturn (this.options.stroke ? this.options.weight / 2 || 0 : 0) +\n\t\t (this._renderer.options.tolerance || 0);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAa,OAAb,cAA0B,MAAM;CAE/B,OAAO,iBAAiB;EACvB,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,SAAS;EACT,SAAS;EACT,UAAU;EACV,WAAW;EACX,YAAY;EACZ,MAAM;EACN,WAAW;EACX,aAAa;EACb,UAAU;EAEV,aAAa;EACb,uBAAuB;CACxB;;;;;CAMA,UAAU,KAAK;EAGd,KAAK,YAAY,IAAI,YAAY,IAAI;CACtC;;;;CAKA,QAAQ;EACP,KAAK,UAAU,UAAU,IAAI;EAC7B,KAAK,OAAO;EACZ,KAAK,UAAU,SAAS,IAAI;CAC7B;;;;CAKA,WAAW;EACV,KAAK,UAAU,YAAY,IAAI;CAChC;;;;;CAMA,SAAS;EACR,IAAI,KAAK,MACR,KAAK,UAAU,YAAY,IAAI;EAEhC,OAAO;CACR;CAEA,qBAAqB;EACpB,KAAK,UAAU,mBAAmB,IAAI;CACvC;;;;;;;;;CAUA,SAAS,OAAO;EACf,WAAgB,MAAM,KAAK;EAC3B,IAAI,KAAK,WAAW;GACnB,KAAK,UAAU,aAAa,IAAI;GAChC,IAAI,KAAK,QAAQ,UAAU,SAAS,OAAO,OAAO,OAAO,QAAQ,GAChE,KAAK,cAAc;EAErB;EACA,OAAO;CACR;;;;;CAMA,eAAe;EACd,KAAK,WAAW,cAAc,IAAI;EAClC,OAAO;CACR;;;;;CAMA,cAAc;EACb,KAAK,WAAW,aAAa,IAAI;EACjC,OAAO;CACR;;;;;CAMA,aAAa;EACZ,OAAO,KAAK;CACb;CAGA,gBAAgB,SAAS;EACxB,OAAO,IAAI,IAAI,OAAO;CACvB;CAEA,SAAS;EAER,KAAK,SAAS;EACd,KAAK,QAAQ;CACd;CAEA,uBAAuB;EACtB,OAAO;CACR;CAEA,kBAAkB;EAEjB,QAAQ,KAAK,QAAQ,SAAS,KAAK,QAAQ,SAAS,KAAK,IAAI,MAC1D,KAAK,UAAU,QAAQ,aAAa;CACxC;AACD"}
@@ -101,10 +101,10 @@ var Polygon = class Polygon extends Polyline {
101
101
  }
102
102
  _clipPoints() {
103
103
  let bounds = this._renderer._bounds;
104
- const w = this.options.weight, p = new Point(w, w);
104
+ const w = +this.options.weight || 0, p = new Point(w, w);
105
105
  bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));
106
106
  this._parts = [];
107
- if (!this._pxBounds || !this._pxBounds.intersects(bounds)) return;
107
+ if (!this._pxBounds?.intersects(bounds)) return;
108
108
  if (this.options.noClip) {
109
109
  this._parts = this._rings;
110
110
  return;
@@ -117,16 +117,15 @@ var Polygon = class Polygon extends Polyline {
117
117
  _updatePath() {
118
118
  this._renderer._updatePoly(this, true);
119
119
  }
120
+ _isClosed() {
121
+ return true;
122
+ }
120
123
  _containsPoint(p) {
121
- let inside = false, part, p1, p2, i, j, k, len, len2;
122
- if (!this._pxBounds || !this._pxBounds.contains(p)) return false;
123
- for (i = 0, len = this._parts.length; i < len; i++) {
124
- part = this._parts[i];
125
- for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
126
- p1 = part[j];
127
- p2 = part[k];
128
- if (p1.y > p.y !== p2.y > p.y && p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x) inside = !inside;
129
- }
124
+ let inside = false;
125
+ if (!this._pxBounds?.contains(p)) return false;
126
+ for (const part of this._parts) for (let j = 0, len = part.length, k = len - 1; j < len; k = j++) {
127
+ const p1 = part[j], p2 = part[k];
128
+ if (p1.y > p.y !== p2.y > p.y && p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x) inside = !inside;
130
129
  }
131
130
  return inside || super._containsPoint(p, true);
132
131
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Polygon.js","names":["PolyUtil.polygonCenter","LineUtil.isFlat","PolyUtil.clipPolygon"],"sources":["../../../../src/layer/vector/Polygon.js"],"sourcesContent":["import {Polyline} from './Polyline.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport * as PolyUtil from '../../geometry/PolyUtil.js';\nimport {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PolylineOptions} from './Polyline.js' */\n\n/**\n * Options of `Polygon`.\n * @typedef {object} PolygonOptions\n * @property {boolean} [fill=true] Whether to fill the polygon with color.\n * @extends PolylineOptions\n */\n\n/**\n * A class for drawing polygon overlays on a map. Extends `Polyline`.\n *\n * Note that points you pass when creating a polygon shouldn't have an additional last\n * point equal to the first one — it's better to filter out such points.\n *\n * @example\n * ```js\n * // create a red polygon from an array of LatLng points\n * const latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]];\n *\n * const polygon = new Polygon(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polygon\n * map.fitBounds(polygon.getBounds());\n * ```\n *\n * You can also pass an array of arrays of latlngs, with the first array representing\n * the outer shape and the other arrays representing holes in the outer shape:\n *\n * ```js\n * const latlngs = [\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ];\n * ```\n *\n * Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.\n *\n * ```js\n * const latlngs = [\n * [ // first polygon\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ],\n * [ // second polygon\n * [[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]\n * ]\n * ];\n * ```\n */\nexport class Polygon extends Polyline {\n\n\tstatic defaultOptions = {\n\t\tfill: true\n\t};\n\n\t/**\n\t * Instantiates a polygon object given an array of geographical points (or arrays\n\t * of them for holes and multi-polygons) and optionally an options object.\n\t * @overload\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @param {PolygonOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Polygon);\n\t}\n\n\t/**\n\t * Returns `true` if the Polygon has no LatLngs.\n\t * @returns {boolean}\n\t */\n\tisEmpty() {\n\t\treturn !this._latlngs.length || !this._latlngs[0].length;\n\t}\n\n\t/**\n\t * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the Polygon.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\t// throws error when not yet added to map as this center calculation requires projected coordinates\n\t\tif (!this._map) {\n\t\t\tthrow new Error('Must add layer to map before using getCenter()');\n\t\t}\n\t\treturn PolyUtil.polygonCenter(this._defaultShape(), this._map.options.crs);\n\t}\n\n\t_convertLatLngs(latlngs) {\n\t\tconst result = super._convertLatLngs(latlngs),\n\t\tlen = result.length;\n\n\t\t// remove last point if it equals first one\n\t\tif (len >= 2 && result[0] instanceof LatLng && result[0].equals(result[len - 1])) {\n\t\t\tresult.pop();\n\t\t}\n\t\treturn result;\n\t}\n\n\t_setLatLngs(latlngs) {\n\t\tsuper._setLatLngs(latlngs);\n\t\tif (LineUtil.isFlat(this._latlngs)) {\n\t\t\tthis._latlngs = [this._latlngs];\n\t\t}\n\t}\n\n\t_defaultShape() {\n\t\treturn LineUtil.isFlat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0];\n\t}\n\n\t_clipPoints() {\n\t\t// polygons need a different clipping algorithm so we redefine that\n\n\t\tlet bounds = this._renderer._bounds;\n\t\tconst w = this.options.weight,\n\t\tp = new Point(w, w);\n\n\t\t// increase clip padding by stroke width to avoid stroke on clip edges\n\t\tbounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));\n\n\t\tthis._parts = [];\n\t\tif (!this._pxBounds || !this._pxBounds.intersects(bounds)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.options.noClip) {\n\t\t\tthis._parts = this._rings;\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const ring of this._rings) {\n\t\t\tconst clipped = PolyUtil.clipPolygon(ring, bounds);\n\t\t\tif (clipped.length) {\n\t\t\t\tthis._parts.push(clipped);\n\t\t\t}\n\t\t}\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updatePoly(this, true);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p) {\n\t\tlet inside = false,\n\t\tpart, p1, p2, i, j, k, len, len2;\n\n\t\tif (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }\n\n\t\t// ray casting algorithm for detecting if point is in polygon\n\t\tfor (i = 0, len = this._parts.length; i < len; i++) {\n\t\t\tpart = this._parts[i];\n\n\t\t\tfor (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {\n\t\t\t\tp1 = part[j];\n\t\t\t\tp2 = part[k];\n\n\t\t\t\tif (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {\n\t\t\t\t\tinside = !inside;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// also check if it's on polygon stroke\n\t\treturn inside || super._containsPoint(p, true);\n\t}\n\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\tconst holes = !LineUtil.isFlat(this._latlngs),\n\t\tmulti = holes && !LineUtil.isFlat(this._latlngs[0]);\n\n\t\tlet coords = latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);\n\n\t\tif (!holes) {\n\t\t\tcoords = [coords];\n\t\t}\n\n\t\treturn getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}Polygon`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,IAAa,UAAb,MAAa,gBAAgB,SAAS;CAErC,OAAO,iBAAiB,E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KAAK,OAAO;EAE1B;CACD;CAEA,cAAc;EACb,KAAK,UAAU,YAAY,MAAM,IAAI;CACtC;CAGA,eAAe,GAAG;EACjB,IAAI,SAAS,OACb,MAAM,IAAI,IAAI,GAAG,GAAG,GAAG,KAAK;EAE5B,IAAI,CAAC,KAAK,aAAa,CAAC,KAAK,UAAU,SAAS,CAAC,GAAK,OAAO;EAG7D,KAAK,IAAI,GAAG,MAAM,KAAK,OAAO,QAAQ,IAAI,KAAK,KAAK;GACnD,OAAO,KAAK,OAAO;GAEnB,KAAK,IAAI,GAAG,OAAO,KAAK,QAAQ,IAAI,OAAO,GAAG,IAAI,MAAM,IAAI,KAAK;IAChE,KAAK,KAAK;IACV,KAAK,KAAK;IAEV,IAAM,GAAG,IAAI,EAAE,MAAQ,GAAG,IAAI,EAAE,KAAQ,EAAE,KAAK,GAAG,IAAI,GAAG,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,GAAG,GAC/F,SAAS,CAAC;GAEZ;EACD;EAGA,OAAO,UAAU,MAAM,eAAe,GAAG,IAAI;CAC9C;;;;;;;;CAUA,UAAU,WAAW;EACpB,MAAM,QAAQ,CAACD,OAAgB,KAAK,QAAQ,GAC5C,QAAQ,SAAS,CAACA,OAAgB,KAAK,SAAS,EAAE;EAElD,IAAI,SAAS,gBAAgB,KAAK,UAAU,QAAQ,IAAI,QAAQ,IAAI,GAAG,MAAM,SAAS;EAEtF,IAAI,CAAC,OACJ,SAAS,CAAC,MAAM;EAGjB,OAAO,WAAW,MAAM;GACvB,MAAM,GAAG,QAAQ,UAAU,GAAG;GAC9B,aAAa;EACd,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"Polygon.js","names":["PolyUtil.polygonCenter","LineUtil.isFlat","PolyUtil.clipPolygon"],"sources":["../../../../src/layer/vector/Polygon.js"],"sourcesContent":["import {Polyline} from './Polyline.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport * as PolyUtil from '../../geometry/PolyUtil.js';\nimport {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PolylineOptions} from './Polyline.js' */\n\n/**\n * Options of `Polygon`.\n * @typedef {object} PolygonOptions\n * @property {boolean} [fill=true] Whether to fill the polygon with color.\n * @extends PolylineOptions\n */\n\n/**\n * A class for drawing polygon overlays on a map. Extends `Polyline`.\n *\n * Note that points you pass when creating a polygon shouldn't have an additional last\n * point equal to the first one — it's better to filter out such points.\n *\n * @example\n * ```js\n * // create a red polygon from an array of LatLng points\n * const latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]];\n *\n * const polygon = new Polygon(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polygon\n * map.fitBounds(polygon.getBounds());\n * ```\n *\n * You can also pass an array of arrays of latlngs, with the first array representing\n * the outer shape and the other arrays representing holes in the outer shape:\n *\n * ```js\n * const latlngs = [\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ];\n * ```\n *\n * Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.\n *\n * ```js\n * const latlngs = [\n * [ // first polygon\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ],\n * [ // second polygon\n * [[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]\n * ]\n * ];\n * ```\n */\nexport class Polygon extends Polyline {\n\n\tstatic defaultOptions = {\n\t\tfill: true\n\t};\n\n\t/**\n\t * Instantiates a polygon object given an array of geographical points (or arrays\n\t * of them for holes and multi-polygons) and optionally an options object.\n\t * @overload\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @param {PolygonOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Polygon);\n\t}\n\n\t/**\n\t * Returns `true` if the Polygon has no LatLngs.\n\t * @returns {boolean}\n\t */\n\tisEmpty() {\n\t\treturn !this._latlngs.length || !this._latlngs[0].length;\n\t}\n\n\t/**\n\t * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the Polygon.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\t// throws error when not yet added to map as this center calculation requires projected coordinates\n\t\tif (!this._map) {\n\t\t\tthrow new Error('Must add layer to map before using getCenter()');\n\t\t}\n\t\treturn PolyUtil.polygonCenter(this._defaultShape(), this._map.options.crs);\n\t}\n\n\t_convertLatLngs(latlngs) {\n\t\tconst result = super._convertLatLngs(latlngs),\n\t\tlen = result.length;\n\n\t\t// remove last point if it equals first one\n\t\tif (len >= 2 && result[0] instanceof LatLng && result[0].equals(result[len - 1])) {\n\t\t\tresult.pop();\n\t\t}\n\t\treturn result;\n\t}\n\n\t_setLatLngs(latlngs) {\n\t\tsuper._setLatLngs(latlngs);\n\t\tif (LineUtil.isFlat(this._latlngs)) {\n\t\t\tthis._latlngs = [this._latlngs];\n\t\t}\n\t}\n\n\t_defaultShape() {\n\t\treturn LineUtil.isFlat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0];\n\t}\n\n\t_clipPoints() {\n\t\t// polygons need a different clipping algorithm so we redefine that\n\n\t\tlet bounds = this._renderer._bounds;\n\t\tconst w = +this.options.weight || 0,\n\t\tp = new Point(w, w);\n\n\t\t// increase clip padding by stroke width to avoid stroke on clip edges\n\t\tbounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));\n\n\t\tthis._parts = [];\n\t\tif (!this._pxBounds?.intersects(bounds)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.options.noClip) {\n\t\t\tthis._parts = this._rings;\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const ring of this._rings) {\n\t\t\tconst clipped = PolyUtil.clipPolygon(ring, bounds);\n\t\t\tif (clipped.length) {\n\t\t\t\tthis._parts.push(clipped);\n\t\t\t}\n\t\t}\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updatePoly(this, true);\n\t}\n\n\t_isClosed() {\n\t\treturn true;\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p) {\n\t\tlet inside = false;\n\n\t\tif (!this._pxBounds?.contains(p)) { return false; }\n\n\t\t// ray casting algorithm for detecting if point is in polygon\n\t\tfor (const part of this._parts) {\n\t\t\tfor (let j = 0, len = part.length, k = len - 1; j < len; k = j++) {\n\t\t\t\tconst p1 = part[j],\n\t\t\t\tp2 = part[k];\n\n\t\t\t\tif (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {\n\t\t\t\t\tinside = !inside;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// also check if it's on polygon stroke\n\t\treturn inside || super._containsPoint(p, true);\n\t}\n\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\tconst holes = !LineUtil.isFlat(this._latlngs),\n\t\tmulti = holes && !LineUtil.isFlat(this._latlngs[0]);\n\n\t\tlet coords = latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);\n\n\t\tif (!holes) {\n\t\t\tcoords = [coords];\n\t\t}\n\n\t\treturn getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}Polygon`,\n\t\t\tcoordinates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,QAAQ;GACxB,KAAK,SAAS,KAAK;GACnB;EACD;EAEA,KAAK,MAAM,QAAQ,KAAK,QAAQ;GAC/B,MAAM,UAAUC,YAAqB,MAAM,MAAM;GACjD,IAAI,QAAQ,QACX,KAAK,OAAO,KAAK,OAAO;EAE1B;CACD;CAEA,cAAc;EACb,KAAK,UAAU,YAAY,MAAM,IAAI;CACtC;CAEA,YAAY;EACX,OAAO;CACR;CAGA,eAAe,GAAG;EACjB,IAAI,SAAS;EAEb,IAAI,CAAC,KAAK,WAAW,SAAS,CAAC,GAAK,OAAO;EAG3C,KAAK,MAAM,QAAQ,KAAK,QACvB,KAAK,IAAI,IAAI,GAAG,MAAM,KAAK,QAAQ,IAAI,MAAM,GAAG,IAAI,KAAK,IAAI,KAAK;GACjE,MAAM,KAAK,KAAK,IAChB,KAAK,KAAK;GAEV,IAAM,GAAG,IAAI,EAAE,MAAQ,GAAG,IAAI,EAAE,KAAQ,EAAE,KAAK,GAAG,IAAI,GAAG,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,GAAG,GAC/F,SAAS,CAAC;EAEZ;EAID,OAAO,UAAU,MAAM,eAAe,GAAG,IAAI;CAC9C;;;;;;;;CAUA,UAAU,WAAW;EACpB,MAAM,QAAQ,CAACD,OAAgB,KAAK,QAAQ,GAC5C,QAAQ,SAAS,CAACA,OAAgB,KAAK,SAAS,EAAE;EAElD,IAAI,SAAS,gBAAgB,KAAK,UAAU,QAAQ,IAAI,QAAQ,IAAI,GAAG,MAAM,SAAS;EAEtF,IAAI,CAAC,OACJ,SAAS,CAAC,MAAM;EAGjB,OAAO,WAAW,MAAM;GACvB,MAAM,GAAG,QAAQ,UAAU,GAAG;GAC9B,aAAa;EACd,CAAC;CACF;AACD"}
@@ -104,9 +104,9 @@ var Polyline = class Polyline extends Path {
104
104
  closestLayerPoint(p) {
105
105
  p = Point.from(p);
106
106
  let minDistance = Infinity, minPoint = null, p1, p2;
107
- const closest = _sqClosestPointOnSegment;
108
- for (const points of this._parts) for (let i = 1, len = points.length; i < len; i++) {
109
- p1 = points[i - 1];
107
+ const closest = _sqClosestPointOnSegment, closed = this._isClosed();
108
+ for (const points of this._parts) for (let i = closed ? 0 : 1, len = points.length; i < len; i++) {
109
+ p1 = points[(i || len) - 1];
110
110
  p2 = points[i];
111
111
  const sqDist = closest(p, p1, p2, true);
112
112
  if (sqDist < minDistance) {
@@ -179,7 +179,7 @@ var Polyline = class Polyline extends Path {
179
179
  }
180
180
  _projectLatlngs(latlngs, result, projectedBounds) {
181
181
  if (latlngs[0] instanceof LatLng) {
182
- const ring = latlngs.map((latlng) => this._map.latLngToLayerPoint(latlng));
182
+ const ring = latlngs.map((latlng) => this._renderer._latLngToLayerPoint(latlng));
183
183
  ring.forEach((r) => projectedBounds.extend(r));
184
184
  result.push(ring);
185
185
  } else latlngs.forEach((latlng) => this._projectLatlngs(latlng, result, projectedBounds));
@@ -187,24 +187,21 @@ var Polyline = class Polyline extends Path {
187
187
  _clipPoints() {
188
188
  const bounds = this._renderer._bounds;
189
189
  this._parts = [];
190
- if (!this._pxBounds || !this._pxBounds.intersects(bounds)) return;
190
+ if (!this._pxBounds?.intersects(bounds)) return;
191
191
  if (this.options.noClip) {
192
192
  this._parts = this._rings;
193
193
  return;
194
194
  }
195
195
  const parts = this._parts;
196
- let i, j, k, len, len2, segment, points;
197
- for (i = 0, k = 0, len = this._rings.length; i < len; i++) {
198
- points = this._rings[i];
199
- for (j = 0, len2 = points.length; j < len2 - 1; j++) {
200
- segment = clipSegment(points[j], points[j + 1], bounds, j);
201
- if (!segment) continue;
202
- parts[k] ??= [];
203
- parts[k].push(segment[0]);
204
- if (segment[1] !== points[j + 1] || j === len2 - 2) {
205
- parts[k].push(segment[1]);
206
- k++;
207
- }
196
+ let k = 0;
197
+ for (const points of this._rings) for (let j = 0, len = points.length; j < len - 1; j++) {
198
+ const segment = clipSegment(points[j], points[j + 1], bounds, j);
199
+ if (!segment) continue;
200
+ parts[k] ??= [];
201
+ parts[k].push(segment[0]);
202
+ if (segment[1] !== points[j + 1] || j === len - 2) {
203
+ parts[k].push(segment[1]);
204
+ k++;
208
205
  }
209
206
  }
210
207
  }
@@ -221,17 +218,13 @@ var Polyline = class Polyline extends Path {
221
218
  _updatePath() {
222
219
  this._renderer._updatePoly(this);
223
220
  }
221
+ _isClosed() {
222
+ return false;
223
+ }
224
224
  _containsPoint(p, closed) {
225
- let i, j, k, len, len2, part;
226
225
  const w = this._clickTolerance();
227
- if (!this._pxBounds || !this._pxBounds.contains(p)) return false;
228
- for (i = 0, len = this._parts.length; i < len; i++) {
229
- part = this._parts[i];
230
- for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
231
- if (!closed && j === 0) continue;
232
- if (pointToSegmentDistance(p, part[k], part[j]) <= w) return true;
233
- }
234
- }
226
+ if (!this._pxBounds?.contains(p)) return false;
227
+ for (const part of this._parts) for (let j = closed ? 0 : 1, len = part.length; j < len; j++) if (pointToSegmentDistance(p, part[(j || len) - 1], part[j]) <= w) return true;
235
228
  return false;
236
229
  }
237
230
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Polyline.js","names":["LineUtil._sqClosestPointOnSegment","LineUtil.polylineCenter","LineUtil.isFlat","LineUtil.clipSegment","LineUtil.simplify","LineUtil.pointToSegmentDistance"],"sources":["../../../../src/layer/vector/Polyline.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\nimport {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n/** @import {PathOptions} from './Path.js' */\n\n/**\n * Options of `Polyline`.\n * @typedef {object} PolylineOptions\n * @property {number} [smoothFactor=0.5] How much to simplify the polyline on each zoom\n * level (Douglas–Peucker epsilon, in pixels). Higher values mean faster rendering but\n * less accuracy; lower values mean more accuracy but slower rendering.\n * @property {boolean} [noClip=false] Disable polyline clipping.\n * @extends PathOptions\n */\n\n/**\n * A class for drawing polyline overlays on a map. Extends `Path`.\n *\n * @example\n * ```js\n * // create a red polyline from an array of LatLng points\n * const latlngs = [\n * \t[45.51, -122.68],\n * \t[37.77, -122.43],\n * \t[34.04, -118.2]\n * ];\n *\n * const polyline = new Polyline(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polyline\n * map.fitBounds(polyline.getBounds());\n * ```\n *\n * You can also pass a multi-dimensional array to represent a `MultiPolyline` shape:\n *\n * ```js\n * // create a red polyline from an array of arrays of LatLng points\n * const latlngs = [\n * \t[[45.51, -122.68],\n * \t [37.77, -122.43],\n * \t [34.04, -118.2]],\n * \t[[40.78, -73.91],\n * \t [41.83, -87.62],\n * \t [32.76, -96.72]]\n * ];\n * ```\n */\nexport class Polyline extends Path {\n\n\tstatic defaultOptions = {\n\t\tsmoothFactor: 0.5,\n\t\tnoClip: false\n\t};\n\n\t/**\n\t * Instantiates a polyline object given an array of geographical points and\n\t * optionally an options object. You can create a `Polyline` object with\n\t * multiple separate lines (`MultiPolyline`) by passing an array of arrays\n\t * of geographic points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @param {PolylineOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._setLatLngs(latlngs);\n\n\t\tthis.callInitHooks(Polyline);\n\t}\n\n\t/**\n\t * Returns an array of the points in the path, or nested arrays of points in case of\n\t * multi-polyline.\n\t * @returns {LatLng[]|LatLng[][]|LatLng[][][]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Replaces all the points in the polyline with the given array of geographical points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._setLatLngs(latlngs);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns `true` if the Polyline has no LatLngs.\n\t * @returns {boolean}\n\t */\n\tisEmpty() {\n\t\treturn !this._latlngs.length;\n\t}\n\n\t/**\n\t * Returns the point closest to `p` on the Polyline, with its `distance` to `p` in\n\t * pixels, or `null` if the polyline is not visible.\n\t * @param {PointExpression} p\n\t * @returns {(Point & {distance: number})|null}\n\t */\n\tclosestLayerPoint(p) {\n\t\tp = Point.from(p);\n\t\tlet minDistance = Infinity,\n\t\tminPoint = null,\n\t\tp1, p2;\n\t\tconst closest = LineUtil._sqClosestPointOnSegment;\n\n\t\tfor (const points of this._parts) {\n\t\t\tfor (let i = 1, len = points.length; i < len; i++) {\n\t\t\t\tp1 = points[i - 1];\n\t\t\t\tp2 = points[i];\n\n\t\t\t\tconst sqDist = closest(p, p1, p2, true);\n\n\t\t\t\tif (sqDist < minDistance) {\n\t\t\t\t\tminDistance = sqDist;\n\t\t\t\t\tminPoint = closest(p, p1, p2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (minPoint) {\n\t\t\tminPoint.distance = Math.sqrt(minDistance);\n\t\t}\n\t\treturn minPoint;\n\t}\n\n\t/**\n\t * Returns the center ([centroid](https://en.wikipedia.org/wiki/Centroid)) of the polyline.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\t// throws error when not yet added to map as this center calculation requires projected coordinates\n\t\tif (!this._map) {\n\t\t\tthrow new Error('Must add layer to map before using getCenter()');\n\t\t}\n\t\treturn LineUtil.polylineCenter(this._defaultShape(), this._map.options.crs);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Adds a given point to the polyline. By default, adds to the first ring of\n\t * the polyline in case of a multi-polyline, but can be overridden by passing\n\t * a specific ring as a LatLng array (that you can earlier access with\n\t * [`getLatLngs`](#polyline-getlatlngs)).\n\t * @param {LatLngExpression} latlng\n\t * @param {LatLng[]} [latlngs]\n\t * @returns {this}\n\t */\n\taddLatLng(latlng, latlngs) {\n\t\tlatlngs ??= this._defaultShape();\n\t\tlatlng = new LatLng(latlng);\n\t\tlatlngs.push(latlng);\n\t\tthis._bounds.extend(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t_setLatLngs(latlngs) {\n\t\tthis._bounds = new LatLngBounds();\n\t\tthis._latlngs = this._convertLatLngs(latlngs);\n\t}\n\n\t_defaultShape() {\n\t\treturn LineUtil.isFlat(this._latlngs) ? this._latlngs : this._latlngs[0];\n\t}\n\n\t// recursively convert latlngs input into actual LatLng instances; calculate bounds along the way\n\t_convertLatLngs(latlngs) {\n\t\tconst result = [],\n\t\tflat = LineUtil.isFlat(latlngs);\n\n\t\tfor (let i = 0, len = latlngs.length; i < len; i++) {\n\t\t\tif (flat) {\n\t\t\t\tresult[i] = new LatLng(latlngs[i]);\n\t\t\t\tthis._bounds.extend(result[i]);\n\t\t\t} else {\n\t\t\t\tresult[i] = this._convertLatLngs(latlngs[i]);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t_project() {\n\t\tconst pxBounds = new Bounds();\n\t\tthis._rings = [];\n\t\tthis._projectLatlngs(this._latlngs, this._rings, pxBounds);\n\n\t\tif (this._bounds.isValid() && pxBounds.isValid()) {\n\t\t\tthis._rawPxBounds = pxBounds;\n\t\t\tthis._updateBounds();\n\t\t}\n\t}\n\n\t_updateBounds() {\n\t\tconst w = this._clickTolerance(),\n\t\tp = new Point(w, w);\n\n\t\tif (!this._rawPxBounds) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._pxBounds = new Bounds([\n\t\t\tthis._rawPxBounds.min.subtract(p),\n\t\t\tthis._rawPxBounds.max.add(p)\n\t\t]);\n\t}\n\n\t// recursively turns latlngs into a set of rings with projected coordinates\n\t_projectLatlngs(latlngs, result, projectedBounds) {\n\t\tconst flat = latlngs[0] instanceof LatLng;\n\n\t\tif (flat) {\n\t\t\tconst ring = latlngs.map(latlng => this._map.latLngToLayerPoint(latlng));\n\t\t\tring.forEach(r => projectedBounds.extend(r));\n\t\t\tresult.push(ring);\n\t\t} else {\n\t\t\tlatlngs.forEach(latlng => this._projectLatlngs(latlng, result, projectedBounds));\n\t\t}\n\t}\n\n\t// clip polyline by renderer bounds so that we have less to render for performance\n\t_clipPoints() {\n\t\tconst bounds = this._renderer._bounds;\n\n\t\tthis._parts = [];\n\t\tif (!this._pxBounds || !this._pxBounds.intersects(bounds)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.options.noClip) {\n\t\t\tthis._parts = this._rings;\n\t\t\treturn;\n\t\t}\n\n\t\tconst parts = this._parts;\n\t\tlet i, j, k, len, len2, segment, points;\n\n\t\tfor (i = 0, k = 0, len = this._rings.length; i < len; i++) {\n\t\t\tpoints = this._rings[i];\n\n\t\t\tfor (j = 0, len2 = points.length; j < len2 - 1; j++) {\n\t\t\t\tsegment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j);\n\n\t\t\t\tif (!segment) { continue; }\n\n\t\t\t\tparts[k] ??= [];\n\t\t\t\tparts[k].push(segment[0]);\n\n\t\t\t\t// if segment goes out of screen, or it's the last one, it's the end of the line part\n\t\t\t\tif ((segment[1] !== points[j + 1]) || (j === len2 - 2)) {\n\t\t\t\t\tparts[k].push(segment[1]);\n\t\t\t\t\tk++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// simplify each clipped part of the polyline for performance\n\t_simplifyPoints() {\n\t\tconst parts = this._parts,\n\t\ttolerance = this.options.smoothFactor;\n\n\t\tfor (let i = 0, len = parts.length; i < len; i++) {\n\t\t\tparts[i] = LineUtil.simplify(parts[i], tolerance);\n\t\t}\n\t}\n\n\t_update() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._clipPoints();\n\t\tthis._simplifyPoints();\n\t\tthis._updatePath();\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updatePoly(this);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p, closed) {\n\t\tlet i, j, k, len, len2, part;\n\t\tconst w = this._clickTolerance();\n\n\t\tif (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }\n\n\t\t// hit detection for polylines\n\t\tfor (i = 0, len = this._parts.length; i < len; i++) {\n\t\t\tpart = this._parts[i];\n\n\t\t\tfor (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {\n\t\t\t\tif (!closed && (j === 0)) { continue; }\n\n\t\t\t\tif (LineUtil.pointToSegmentDistance(p, part[k], part[j]) <= w) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`\n\t * Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\tconst multi = !LineUtil.isFlat(this._latlngs);\n\n\t\tconst coords = latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);\n\n\t\treturn getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}LineString`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,WAAb,MAAa,iBAAiB,KAAK;CAElC,OAAO,iBAAiB;EACvB,cAAc;EACd,QAAQ;CACT;;;;;;;;;CAUA,YAAY,SAAS,SAAS;EAC7B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B,KAAK,YAAY,OAAO;EAExB,KAAK,c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;IAE5B,IAAIC,uBAAgC,GAAG,KAAK,IAAI,KAAK,EAAE,KAAK,GAC3D,OAAO;GAET;EACD;EACA,OAAO;CACR;;;;;;;;;CAUA,UAAU,WAAW;EACpB,MAAM,QAAQ,CAACH,OAAgB,KAAK,QAAQ;EAE5C,MAAM,SAAS,gBAAgB,KAAK,UAAU,QAAQ,IAAI,GAAG,OAAO,SAAS;EAE7E,OAAO,WAAW,MAAM;GACvB,MAAM,GAAG,QAAQ,UAAU,GAAG;GAC9B,aAAa;EACd,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"Polyline.js","names":["LineUtil._sqClosestPointOnSegment","LineUtil.polylineCenter","LineUtil.isFlat","LineUtil.clipSegment","LineUtil.simplify","LineUtil.pointToSegmentDistance"],"sources":["../../../../src/layer/vector/Polyline.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\nimport {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n/** @import {PathOptions} from './Path.js' */\n\n/**\n * Options of `Polyline`.\n * @typedef {object} PolylineOptions\n * @property {number} [smoothFactor=0.5] How much to simplify the polyline on each zoom\n * level (Douglas–Peucker epsilon, in pixels). Higher values mean faster rendering but\n * less accuracy; lower values mean more accuracy but slower rendering.\n * @property {boolean} [noClip=false] Disable polyline clipping.\n * @extends PathOptions\n */\n\n/**\n * A class for drawing polyline overlays on a map. Extends `Path`.\n *\n * @example\n * ```js\n * // create a red polyline from an array of LatLng points\n * const latlngs = [\n * \t[45.51, -122.68],\n * \t[37.77, -122.43],\n * \t[34.04, -118.2]\n * ];\n *\n * const polyline = new Polyline(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polyline\n * map.fitBounds(polyline.getBounds());\n * ```\n *\n * You can also pass a multi-dimensional array to represent a `MultiPolyline` shape:\n *\n * ```js\n * // create a red polyline from an array of arrays of LatLng points\n * const latlngs = [\n * \t[[45.51, -122.68],\n * \t [37.77, -122.43],\n * \t [34.04, -118.2]],\n * \t[[40.78, -73.91],\n * \t [41.83, -87.62],\n * \t [32.76, -96.72]]\n * ];\n * ```\n */\nexport class Polyline extends Path {\n\n\tstatic defaultOptions = {\n\t\tsmoothFactor: 0.5,\n\t\tnoClip: false\n\t};\n\n\t/**\n\t * Instantiates a polyline object given an array of geographical points and\n\t * optionally an options object. You can create a `Polyline` object with\n\t * multiple separate lines (`MultiPolyline`) by passing an array of arrays\n\t * of geographic points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @param {PolylineOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._setLatLngs(latlngs);\n\n\t\tthis.callInitHooks(Polyline);\n\t}\n\n\t/**\n\t * Returns an array of the points in the path, or nested arrays of points in case of\n\t * multi-polyline.\n\t * @returns {LatLng[]|LatLng[][]|LatLng[][][]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Replaces all the points in the polyline with the given array of geographical points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._setLatLngs(latlngs);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns `true` if the Polyline has no LatLngs.\n\t * @returns {boolean}\n\t */\n\tisEmpty() {\n\t\treturn !this._latlngs.length;\n\t}\n\n\t/**\n\t * Returns the point closest to `p` on the Polyline, with its `distance` to `p` in\n\t * pixels, or `null` if the polyline is not visible.\n\t * @param {PointExpression} p\n\t * @returns {(Point & {distance: number})|null}\n\t */\n\tclosestLayerPoint(p) {\n\t\tp = Point.from(p);\n\t\tlet minDistance = Infinity,\n\t\tminPoint = null,\n\t\tp1, p2;\n\t\tconst closest = LineUtil._sqClosestPointOnSegment,\n\t\tclosed = this._isClosed();\n\n\t\tfor (const points of this._parts) {\n\t\t\tfor (let i = closed ? 0 : 1, len = points.length; i < len; i++) {\n\t\t\t\tp1 = points[(i || len) - 1];\n\t\t\t\tp2 = points[i];\n\n\t\t\t\tconst sqDist = closest(p, p1, p2, true);\n\n\t\t\t\tif (sqDist < minDistance) {\n\t\t\t\t\tminDistance = sqDist;\n\t\t\t\t\tminPoint = closest(p, p1, p2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (minPoint) {\n\t\t\tminPoint.distance = Math.sqrt(minDistance);\n\t\t}\n\t\treturn minPoint;\n\t}\n\n\t/**\n\t * Returns the center ([centroid](https://en.wikipedia.org/wiki/Centroid)) of the polyline.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\t// throws error when not yet added to map as this center calculation requires projected coordinates\n\t\tif (!this._map) {\n\t\t\tthrow new Error('Must add layer to map before using getCenter()');\n\t\t}\n\t\treturn LineUtil.polylineCenter(this._defaultShape(), this._map.options.crs);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Adds a given point to the polyline. By default, adds to the first ring of\n\t * the polyline in case of a multi-polyline, but can be overridden by passing\n\t * a specific ring as a LatLng array (that you can earlier access with\n\t * [`getLatLngs`](#polyline-getlatlngs)).\n\t * @param {LatLngExpression} latlng\n\t * @param {LatLng[]} [latlngs]\n\t * @returns {this}\n\t */\n\taddLatLng(latlng, latlngs) {\n\t\tlatlngs ??= this._defaultShape();\n\t\tlatlng = new LatLng(latlng);\n\t\tlatlngs.push(latlng);\n\t\tthis._bounds.extend(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t_setLatLngs(latlngs) {\n\t\tthis._bounds = new LatLngBounds();\n\t\tthis._latlngs = this._convertLatLngs(latlngs);\n\t}\n\n\t_defaultShape() {\n\t\treturn LineUtil.isFlat(this._latlngs) ? this._latlngs : this._latlngs[0];\n\t}\n\n\t// recursively convert latlngs input into actual LatLng instances; calculate bounds along the way\n\t_convertLatLngs(latlngs) {\n\t\tconst result = [],\n\t\tflat = LineUtil.isFlat(latlngs);\n\n\t\tfor (let i = 0, len = latlngs.length; i < len; i++) {\n\t\t\tif (flat) {\n\t\t\t\tresult[i] = new LatLng(latlngs[i]);\n\t\t\t\tthis._bounds.extend(result[i]);\n\t\t\t} else {\n\t\t\t\tresult[i] = this._convertLatLngs(latlngs[i]);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t_project() {\n\t\tconst pxBounds = new Bounds();\n\t\tthis._rings = [];\n\t\tthis._projectLatlngs(this._latlngs, this._rings, pxBounds);\n\n\t\tif (this._bounds.isValid() && pxBounds.isValid()) {\n\t\t\tthis._rawPxBounds = pxBounds;\n\t\t\tthis._updateBounds();\n\t\t}\n\t}\n\n\t_updateBounds() {\n\t\tconst w = this._clickTolerance(),\n\t\tp = new Point(w, w);\n\n\t\tif (!this._rawPxBounds) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._pxBounds = new Bounds([\n\t\t\tthis._rawPxBounds.min.subtract(p),\n\t\t\tthis._rawPxBounds.max.add(p)\n\t\t]);\n\t}\n\n\t// recursively turns latlngs into a set of rings with projected coordinates\n\t_projectLatlngs(latlngs, result, projectedBounds) {\n\t\tconst flat = latlngs[0] instanceof LatLng;\n\n\t\tif (flat) {\n\t\t\tconst ring = latlngs.map(latlng => this._renderer._latLngToLayerPoint(latlng));\n\t\t\tring.forEach(r => projectedBounds.extend(r));\n\t\t\tresult.push(ring);\n\t\t} else {\n\t\t\tlatlngs.forEach(latlng => this._projectLatlngs(latlng, result, projectedBounds));\n\t\t}\n\t}\n\n\t// clip polyline by renderer bounds so that we have less to render for performance\n\t_clipPoints() {\n\t\tconst bounds = this._renderer._bounds;\n\n\t\tthis._parts = [];\n\t\tif (!this._pxBounds?.intersects(bounds)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.options.noClip) {\n\t\t\tthis._parts = this._rings;\n\t\t\treturn;\n\t\t}\n\n\t\tconst parts = this._parts;\n\t\tlet k = 0;\n\n\t\tfor (const points of this._rings) {\n\t\t\tfor (let j = 0, len = points.length; j < len - 1; j++) {\n\t\t\t\tconst segment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j);\n\n\t\t\t\tif (!segment) { continue; }\n\n\t\t\t\tparts[k] ??= [];\n\t\t\t\tparts[k].push(segment[0]);\n\n\t\t\t\t// if segment goes out of screen, or it's the last one, it's the end of the line part\n\t\t\t\tif ((segment[1] !== points[j + 1]) || (j === len - 2)) {\n\t\t\t\t\tparts[k].push(segment[1]);\n\t\t\t\t\tk++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// simplify each clipped part of the polyline for performance\n\t_simplifyPoints() {\n\t\tconst parts = this._parts,\n\t\ttolerance = this.options.smoothFactor;\n\n\t\tfor (let i = 0, len = parts.length; i < len; i++) {\n\t\t\tparts[i] = LineUtil.simplify(parts[i], tolerance);\n\t\t}\n\t}\n\n\t_update() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._clipPoints();\n\t\tthis._simplifyPoints();\n\t\tthis._updatePath();\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updatePoly(this);\n\t}\n\n\t// polygon rings also have a segment from the last point back to the first\n\t_isClosed() {\n\t\treturn false;\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p, closed) {\n\t\tconst w = this._clickTolerance();\n\n\t\tif (!this._pxBounds?.contains(p)) { return false; }\n\n\t\t// hit detection for polylines\n\t\tfor (const part of this._parts) {\n\t\t\tfor (let j = closed ? 0 : 1, len = part.length; j < len; j++) {\n\t\t\t\tif (LineUtil.pointToSegmentDistance(p, part[(j || len) - 1], part[j]) <= w) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`\n\t * Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\tconst multi = !LineUtil.isFlat(this._latlngs);\n\n\t\tconst coords = latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);\n\n\t\treturn getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}LineString`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,WAAb,MAAa,iBAAiB,KAAK;CAElC,OAAO,iBAAiB;EACvB,cAAc;EACd,QAAQ;CACT;;;;;;;;;CAUA,YAAY,SAAS,SAAS;EAC7B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B,KAAK,YAAY,OAAO;EAExB,KAAK,cAAc,QAAQ;CAC5B;;;;;;CAOA,aAAa;EACZ,OAAO,KAAK;CACb;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,YAAY,OAAO;EACxB,OAAO,KAAK,OAAO;CACpB;;;;;CAMA,UAAU;EACT,OAAO,CAAC,KAAK,SAAS;CACvB;;;;;;;CAQA,kBAAkB,GAAG;EACpB,IAAI,MAAM,KAAK,CAAC;EAChB,IAAI,cAAc,UAClB,WAAW,MACX,IAAI;EACJ,MAAM,UAAUA,0BAChB,SAAS,KAAK,UAAU;EAExB,KAAK,MAAM,UAAU,KAAK,QACzB,KAAK,IAAI,IAAI,SAAS,IAAI,GAAG,MAAM,OAAO,QAAQ,IA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GACD;EACD;CAEF;CAGA,kBAAkB;EACjB,MAAM,QAAQ,KAAK,QACnB,YAAY,KAAK,QAAQ;EAEzB,KAAK,IAAI,IAAI,GAAG,MAAM,MAAM,QAAQ,IAAI,KAAK,KAC5C,MAAM,KAAKC,SAAkB,MAAM,IAAI,SAAS;CAElD;CAEA,UAAU;EACT,IAAI,CAAC,KAAK,MAAQ;EAElB,KAAK,YAAY;EACjB,KAAK,gBAAgB;EACrB,KAAK,YAAY;CAClB;CAEA,cAAc;EACb,KAAK,UAAU,YAAY,IAAI;CAChC;CAGA,YAAY;EACX,OAAO;CACR;CAGA,eAAe,GAAG,QAAQ;EACzB,MAAM,IAAI,KAAK,gBAAgB;EAE/B,IAAI,CAAC,KAAK,WAAW,SAAS,CAAC,GAAK,OAAO;EAG3C,KAAK,MAAM,QAAQ,KAAK,QACvB,KAAK,IAAI,IAAI,SAAS,IAAI,GAAG,MAAM,KAAK,QAAQ,IAAI,KAAK,KACxD,IAAIC,uBAAgC,GAAG,MAAM,KAAK,OAAO,IAAI,KAAK,EAAE,KAAK,GACxE,OAAO;EAIV,OAAO;CACR;;;;;;;;;CAUA,UAAU,WAAW;EACpB,MAAM,QAAQ,CAACH,OAAgB,KAAK,QAAQ;EAE5C,MAAM,SAAS,gBAAgB,KAAK,UAAU,QAAQ,IAAI,GAAG,OAAO,SAAS;EAE7E,OAAO,WAAW,MAAM;GACvB,MAAM,GAAG,QAAQ,UAAU,GAAG;GAC9B,aAAa;EACd,CAAC;CACF;AACD"}
@@ -44,7 +44,8 @@ const mapRendererMethods = {
44
44
  * @lends MaplairMapOptions
45
45
  * @property {Renderer} [renderer] The default method for drawing vector layers on the
46
46
  * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
47
- * instead.
47
+ * instead. Paths in custom panes get their own renderer for that pane, of the same
48
+ * class and with the same options as this one.
48
49
  */
49
50
  /**
50
51
  * Registers `getRenderer()` and related methods on the given map class, called by
@@ -1 +1 @@
1
- {"version":3,"file":"Renderer.getRenderer.js","names":[],"sources":["../../../../src/layer/vector/Renderer.getRenderer.js"],"sourcesContent":["/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Path} from './Path.js' */\n/** @import {Renderer} from './Renderer.js' */\n\n/**\n * Methods of `MaplairMap` for the renderers of vector layers.\n * @lends MaplairMap.prototype\n */\nconst mapRendererMethods = {\n\t/**\n\t * Returns the instance of `Renderer` that should be used to render the given\n\t * `Path`. It will ensure that the `renderer` options of the map and paths\n\t * are respected, and that the renderers do exist on the map.\n\t * @internal\n\t * @param {Path} layer\n\t * @returns {Renderer|undefined}\n\t */\n\tgetRenderer(layer) {\n\t\tconst renderer = layer.options.renderer ?? this._getPaneRenderer(layer) ?? this.options.renderer ??\n\t\t\t(this._renderer ??= layer._createRenderer?.());\n\n\t\t// a non-Path layer (e.g. a marker cluster group of a plugin) has no renderer of its own\n\t\tif (renderer && !this.hasLayer(renderer)) {\n\t\t\tthis.addLayer(renderer);\n\t\t}\n\t\treturn renderer;\n\t},\n\n\t_getPaneRenderer(layer) {\n\t\tconst name = layer.options.pane;\n\t\tif (name === 'overlayPane' || name === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet renderer = this._paneRenderers[name];\n\t\tif (!renderer) {\n\t\t\t// custom panes get a renderer of the same kind as the map's default one, so Canvas maps stay Canvas\n\t\t\tconst Renderer = this.options.renderer?.constructor;\n\t\t\trenderer = Renderer ?\n\t\t\t\tnew Renderer({...this.options.renderer.options, pane: name}) :\n\t\t\t\tlayer._createRenderer({pane: name});\n\t\t\tthis._paneRenderers[name] = renderer;\n\t\t}\n\t\treturn renderer;\n\t}\n};\n/** @typedef {typeof mapRendererMethods} MapRendererMethods */\n\n/**\n * Map options of the vector renderers.\n * @typedef {object} RendererMapOptions\n * @lends MaplairMapOptions\n * @property {Renderer} [renderer] The default method for drawing vector layers on the\n * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas\n * instead.\n */\n\n/**\n * Registers `getRenderer()` and related methods on the given map class, called by\n * `MaplairMap` itself.\n * @internal\n * @param {typeof MaplairMap} MaplairMap\n */\nexport function register(MaplairMap) {\n\tMaplairMap.include(mapRendererMethods);\n\tMaplairMap.addInitHook(function () {\n\t\tif (this.options.preferCanvas !== undefined) {\n\t\t\tconsole.error('MaplairMap: preferCanvas option has been removed. Use renderer: new Canvas() instead.');\n\t\t}\n\t});\n}\n"],"mappings":";;;;;;;;;;AAQA,MAAM,qBAAqB;;;;;;;;;CAS1B,YAAY,OAAO;EAClB,MAAM,WAAW,MAAM,QAAQ,YAAY,KAAK,iBAAiB,KAAK,KAAK,KAAK,QAAQ,aACtF,KAAK,cAAc,MAAM,kBAAkB;EAG7C,IAAI,YAAY,CAAC,KAAK,SAAS,QAAQ,GACtC,KAAK,SAAS,QAAQ;EAEvB,OAAO;CACR;CAEA,iBAAiB,OAAO;EACvB,MAAM,OAAO,MAAM,QAAQ;EAC3B,IAAI,SAAS,iBAAiB,SAAS,KAAA,GACtC;EAGD,IAAI,WAAW,KAAK,eAAe;EACnC,IAAI,CAAC,UAAU;GAEd,MAAM,WAAW,KAAK,QAAQ,UAAU;GACxC,WAAW,WACV,IAAI,SAAS;IAAC,GAAG,KAAK,QAAQ,SAAS;IAAS,MAAM;GAAI,CAAC,IAC3D,MAAM,gBAAgB,EAAC,MAAM,KAAI,CAAC;GACnC,KAAK,eAAe,QAAQ;EAC7B;EACA,OAAO;CACR;AACD;;;;;;;;;;;;;;;;AAkBA,SAAgB,SAAS,YAAY;CACpC,WAAW,QAAQ,kBAAkB;CACrC,WAAW,YAAY,WAAY;EAClC,IAAI,KAAK,QAAQ,iBAAiB,KAAA,GACjC,QAAQ,MAAM,uFAAuF;CAEvG,CAAC;AACF"}
1
+ {"version":3,"file":"Renderer.getRenderer.js","names":[],"sources":["../../../../src/layer/vector/Renderer.getRenderer.js"],"sourcesContent":["/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Path} from './Path.js' */\n/** @import {Renderer} from './Renderer.js' */\n\n/**\n * Methods of `MaplairMap` for the renderers of vector layers.\n * @lends MaplairMap.prototype\n */\nconst mapRendererMethods = {\n\t/**\n\t * Returns the instance of `Renderer` that should be used to render the given\n\t * `Path`. It will ensure that the `renderer` options of the map and paths\n\t * are respected, and that the renderers do exist on the map.\n\t * @internal\n\t * @param {Path} layer\n\t * @returns {Renderer|undefined}\n\t */\n\tgetRenderer(layer) {\n\t\tconst renderer = layer.options.renderer ?? this._getPaneRenderer(layer) ?? this.options.renderer ??\n\t\t\t(this._renderer ??= layer._createRenderer?.());\n\n\t\t// a non-Path layer (e.g. a marker cluster group of a plugin) has no renderer of its own\n\t\tif (renderer && !this.hasLayer(renderer)) {\n\t\t\tthis.addLayer(renderer);\n\t\t}\n\t\treturn renderer;\n\t},\n\n\t_getPaneRenderer(layer) {\n\t\tconst name = layer.options.pane;\n\t\tif (name === 'overlayPane' || name === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet renderer = this._paneRenderers[name];\n\t\tif (!renderer) {\n\t\t\t// custom panes get a renderer of the same kind as the map's default one, so Canvas maps stay Canvas\n\t\t\tconst Renderer = this.options.renderer?.constructor;\n\t\t\trenderer = Renderer ?\n\t\t\t\tnew Renderer({...this.options.renderer.options, pane: name}) :\n\t\t\t\tlayer._createRenderer({pane: name});\n\t\t\tthis._paneRenderers[name] = renderer;\n\t\t}\n\t\treturn renderer;\n\t}\n};\n/** @typedef {typeof mapRendererMethods} MapRendererMethods */\n\n/**\n * Map options of the vector renderers.\n * @typedef {object} RendererMapOptions\n * @lends MaplairMapOptions\n * @property {Renderer} [renderer] The default method for drawing vector layers on the\n * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas\n * instead. Paths in custom panes get their own renderer for that pane, of the same\n * class and with the same options as this one.\n */\n\n/**\n * Registers `getRenderer()` and related methods on the given map class, called by\n * `MaplairMap` itself.\n * @internal\n * @param {typeof MaplairMap} MaplairMap\n */\nexport function register(MaplairMap) {\n\tMaplairMap.include(mapRendererMethods);\n\tMaplairMap.addInitHook(function () {\n\t\tif (this.options.preferCanvas !== undefined) {\n\t\t\tconsole.error('MaplairMap: preferCanvas option has been removed. Use renderer: new Canvas() instead.');\n\t\t}\n\t});\n}\n"],"mappings":";;;;;;;;;;AAQA,MAAM,qBAAqB;;;;;;;;;CAS1B,YAAY,OAAO;EAClB,MAAM,WAAW,MAAM,QAAQ,YAAY,KAAK,iBAAiB,KAAK,KAAK,KAAK,QAAQ,aACtF,KAAK,cAAc,MAAM,kBAAkB;EAG7C,IAAI,YAAY,CAAC,KAAK,SAAS,QAAQ,GACtC,KAAK,SAAS,QAAQ;EAEvB,OAAO;CACR;CAEA,iBAAiB,OAAO;EACvB,MAAM,OAAO,MAAM,QAAQ;EAC3B,IAAI,SAAS,iBAAiB,SAAS,KAAA,GACtC;EAGD,IAAI,WAAW,KAAK,eAAe;EACnC,IAAI,CAAC,UAAU;GAEd,MAAM,WAAW,KAAK,QAAQ,UAAU;GACxC,WAAW,WACV,IAAI,SAAS;IAAC,GAAG,KAAK,QAAQ,SAAS;IAAS,MAAM;GAAI,CAAC,IAC3D,MAAM,gBAAgB,EAAC,MAAM,KAAI,CAAC;GACnC,KAAK,eAAe,QAAQ;EAC7B;EACA,OAAO;CACR;AACD;;;;;;;;;;;;;;;;;AAmBA,SAAgB,SAAS,YAAY;CACpC,WAAW,QAAQ,kBAAkB;CACrC,WAAW,YAAY,WAAY;EAClC,IAAI,KAAK,QAAQ,iBAAiB,KAAA,GACjC,QAAQ,MAAM,uFAAuF;CAEvG,CAAC;AACF"}
@@ -4,6 +4,8 @@ import { BlanketOverlay } from "../BlanketOverlay.js";
4
4
  /** @import {BlanketOverlayOptions} from '../BlanketOverlay.js' */
5
5
  /** @import {MaplairEvent} from '../../core/Events.js' */
6
6
  /** @import {MaplairMap} from '../../map/Map.js' */
7
+ /** @import {LatLngExpression} from '../../geo/LatLng.js' */
8
+ /** @import {Point} from '../../geometry/Point.js' */
7
9
  /**
8
10
  * Options of `Renderer`, `SVG` and `Canvas`. The `continuous` option inherited from
9
11
  * `BlanketOverlay` cannot be set to `true`.
@@ -45,6 +47,7 @@ var Renderer = class Renderer extends BlanketOverlay {
45
47
  * @param {MaplairMap} map
46
48
  */
47
49
  onAdd(map) {
50
+ this._setPathView();
48
51
  super.onAdd(map);
49
52
  this.on("update", this._updatePaths, this);
50
53
  }
@@ -56,12 +59,25 @@ var Renderer = class Renderer extends BlanketOverlay {
56
59
  this.off("update", this._updatePaths, this);
57
60
  }
58
61
  _onZoomEnd() {
62
+ this._setPathView();
59
63
  for (const layer of Object.values(this._layers)) layer._project();
60
64
  }
65
+ _setPathView() {
66
+ this._pathZoom = this._map.getZoom();
67
+ this._pathOrigin = this._map.getPixelOrigin();
68
+ }
69
+ /**
70
+ * @param {LatLngExpression} latlng
71
+ * @returns {Point}
72
+ */
73
+ _latLngToLayerPoint(latlng) {
74
+ return this._map.project(latlng, this._pathZoom)._subtract(this._pathOrigin);
75
+ }
61
76
  _updatePaths() {
62
77
  for (const layer of Object.values(this._layers)) layer._update();
63
78
  }
64
79
  _onViewReset() {
80
+ this._setPathView();
65
81
  for (const layer of Object.values(this._layers)) layer._reset();
66
82
  }
67
83
  _onSettled() {
@@ -1 +1 @@
1
- {"version":3,"file":"Renderer.js","names":[],"sources":["../../../../src/layer/vector/Renderer.js"],"sourcesContent":["import {BlanketOverlay} from '../BlanketOverlay.js';\nimport * as Util from '../../core/Util.js';\n/** @import {BlanketOverlayOptions} from '../BlanketOverlay.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n\n/**\n * Options of `Renderer`, `SVG` and `Canvas`. The `continuous` option inherited from\n * `BlanketOverlay` cannot be set to `true`.\n * @typedef {object} RendererOptions\n * @extends BlanketOverlayOptions\n */\n\n/**\n * Base class for vector renderer implementations (`SVG`, `Canvas`). Handles the\n * DOM container of the renderer, its bounds, and its zoom animation.\n *\n * A `Renderer` works as an implicit layer group for all `Path`s - the renderer\n * itself can be added or removed to the map. All paths use a renderer, which can\n * be implicit (the map will decide the type of renderer and use it automatically)\n * or explicit (using the [`renderer`](#pathoptions-renderer) option of the path).\n *\n * Do not use this class directly, use `SVG` and `Canvas` instead.\n *\n * The `continuous` option inherited from `BlanketOverlay` cannot be set to `true`\n * (otherwise, renderers get out of place during a pinch-zoom operation).\n *\n * @fires update {MaplairEvent} Fired when the renderer updates its bounds, center and\n * zoom, for example when its map has moved.\n */\nexport class Renderer extends BlanketOverlay {\n\n\t/**\n\t * @param {RendererOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper({...options, continuous: false});\n\t\tUtil.stamp(this);\n\t\tthis._layers ??= {};\n\n\t\tthis.callInitHooks(Renderer);\n\t}\n\n\t/**\n\t * Adds the container of the renderer to the map and starts updating the paths.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tsuper.onAdd(map);\n\t\tthis.on('update', this._updatePaths, this);\n\t}\n\n\t/**\n\t * Removes the container of the renderer from the map.\n\t */\n\tonRemove() {\n\t\tsuper.onRemove();\n\t\tthis.off('update', this._updatePaths, this);\n\t}\n\n\t_onZoomEnd() {\n\t\t// When a zoom ends, the \"origin pixel\" changes. Internal coordinates\n\t\t// of paths are relative to the origin pixel and therefore need to\n\t\t// be recalculated.\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tlayer._project();\n\t\t}\n\t}\n\n\t_updatePaths() {\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tlayer._update();\n\t\t}\n\t}\n\n\t_onViewReset() {\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tlayer._reset();\n\t\t}\n\t}\n\n\t_onSettled() {\n\t\tthis._update();\n\t}\n\n\t// Subclasses are responsible of implementing `_update()`. It should fire\n\t// the 'update' event whenever appropriate (before/after rendering).\n\t_update() {}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAa,WAAb,MAAa,iBAAiB,eAAe;;;;CAK5C,YAAY,SAAS;EACpB,MAAM;GAAC,GAAG;GAAS,YAAY;EAAK,CAAC;EACrC,MAAW,IAAI;EACf,KAAK,YAAY,CAAC;EAElB,KAAK,cAAc,QAAQ;CAC5B;;;;;CAMA,MAAM,KAAK;EACV,MAAM,MAAM,GAAG;EACf,KAAK,GAAG,UAAU,KAAK,cAAc,IAAI;CAC1C;;;;CAKA,WAAW;EACV,MAAM,SAAS;EACf,KAAK,IAAI,UAAU,KAAK,cAAc,IAAI;CAC3C;CAEA,aAAa;EAIZ,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,GAC7C,MAAM,SAAS;CAEjB;CAEA,eAAe;EACd,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,GAC7C,MAAM,QAAQ;CAEhB;CAEA,eAAe;EACd,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,GAC7C,MAAM,OAAO;CAEf;CAEA,aAAa;EACZ,KAAK,QAAQ;CACd;CAIA,UAAU,CAAC;AAEZ"}
1
+ {"version":3,"file":"Renderer.js","names":[],"sources":["../../../../src/layer/vector/Renderer.js"],"sourcesContent":["import {BlanketOverlay} from '../BlanketOverlay.js';\nimport * as Util from '../../core/Util.js';\n/** @import {BlanketOverlayOptions} from '../BlanketOverlay.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {Point} from '../../geometry/Point.js' */\n\n/**\n * Options of `Renderer`, `SVG` and `Canvas`. The `continuous` option inherited from\n * `BlanketOverlay` cannot be set to `true`.\n * @typedef {object} RendererOptions\n * @extends BlanketOverlayOptions\n */\n\n/**\n * Base class for vector renderer implementations (`SVG`, `Canvas`). Handles the\n * DOM container of the renderer, its bounds, and its zoom animation.\n *\n * A `Renderer` works as an implicit layer group for all `Path`s - the renderer\n * itself can be added or removed to the map. All paths use a renderer, which can\n * be implicit (the map will decide the type of renderer and use it automatically)\n * or explicit (using the [`renderer`](#pathoptions-renderer) option of the path).\n *\n * Do not use this class directly, use `SVG` and `Canvas` instead.\n *\n * The `continuous` option inherited from `BlanketOverlay` cannot be set to `true`\n * (otherwise, renderers get out of place during a pinch-zoom operation).\n *\n * @fires update {MaplairEvent} Fired when the renderer updates its bounds, center and\n * zoom, for example when its map has moved.\n */\nexport class Renderer extends BlanketOverlay {\n\n\t/**\n\t * @param {RendererOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper({...options, continuous: false});\n\t\tUtil.stamp(this);\n\t\tthis._layers ??= {};\n\n\t\tthis.callInitHooks(Renderer);\n\t}\n\n\t/**\n\t * Adds the container of the renderer to the map and starts updating the paths.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tthis._setPathView();\n\t\tsuper.onAdd(map);\n\t\tthis.on('update', this._updatePaths, this);\n\t}\n\n\t/**\n\t * Removes the container of the renderer from the map.\n\t */\n\tonRemove() {\n\t\tsuper.onRemove();\n\t\tthis.off('update', this._updatePaths, this);\n\t}\n\n\t_onZoomEnd() {\n\t\tthis._setPathView();\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tlayer._project();\n\t\t}\n\t}\n\n\t// Paths are projected with the zoom and pixel origin the renderer was last drawn\n\t// at, which lag behind the map's during zoom animation and pinch, so that paths\n\t// changed or added meanwhile line up with the rest.\n\t_setPathView() {\n\t\tthis._pathZoom = this._map.getZoom();\n\t\tthis._pathOrigin = this._map.getPixelOrigin();\n\t}\n\n\t/**\n\t * @param {LatLngExpression} latlng\n\t * @returns {Point}\n\t */\n\t_latLngToLayerPoint(latlng) {\n\t\treturn this._map.project(latlng, this._pathZoom)._subtract(this._pathOrigin);\n\t}\n\n\t_updatePaths() {\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tlayer._update();\n\t\t}\n\t}\n\n\t_onViewReset() {\n\t\tthis._setPathView();\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tlayer._reset();\n\t\t}\n\t}\n\n\t_onSettled() {\n\t\tthis._update();\n\t}\n\n\t// Subclasses are responsible of implementing `_update()`. It should fire\n\t// the 'update' event whenever appropriate (before/after rendering).\n\t_update() {}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,WAAb,MAAa,iBAAiB,eAAe;;;;CAK5C,YAAY,SAAS;EACpB,MAAM;GAAC,GAAG;GAAS,YAAY;EAAK,CAAC;EACrC,MAAW,IAAI;EACf,KAAK,YAAY,CAAC;EAElB,KAAK,cAAc,QAAQ;CAC5B;;;;;CAMA,MAAM,KAAK;EACV,KAAK,aAAa;EAClB,MAAM,MAAM,GAAG;EACf,KAAK,GAAG,UAAU,KAAK,cAAc,IAAI;CAC1C;;;;CAKA,WAAW;EACV,MAAM,SAAS;EACf,KAAK,IAAI,UAAU,KAAK,cAAc,IAAI;CAC3C;CAEA,aAAa;EACZ,KAAK,aAAa;EAClB,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,GAC7C,MAAM,SAAS;CAEjB;CAKA,eAAe;EACd,KAAK,YAAY,KAAK,KAAK,QAAQ;EACnC,KAAK,cAAc,KAAK,KAAK,eAAe;CAC7C;;;;;CAMA,oBAAoB,QAAQ;EAC3B,OAAO,KAAK,KAAK,QAAQ,QAAQ,KAAK,SAAS,CAAC,CAAC,UAAU,KAAK,WAAW;CAC5E;CAEA,eAAe;EACd,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,GAC7C,MAAM,QAAQ;CAEhB;CAEA,eAAe;EACd,KAAK,aAAa;EAClB,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,GAC7C,MAAM,OAAO;CAEf;CAEA,aAAa;EACZ,KAAK,QAAQ;CACd;CAIA,UAAU,CAAC;AAEZ"}
@@ -43,7 +43,7 @@ var SVG = class SVG extends Renderer {
43
43
  this._container = SVG.create("svg");
44
44
  this._container.setAttribute("pointer-events", "none");
45
45
  this._rootGroup = SVG.create("g");
46
- this._container.appendChild(this._rootGroup);
46
+ this._container.append(this._rootGroup);
47
47
  }
48
48
  _destroyContainer() {
49
49
  super._destroyContainer();
@@ -52,7 +52,7 @@ var SVG = class SVG extends Renderer {
52
52
  }
53
53
  _resizeContainer() {
54
54
  const size = super._resizeContainer();
55
- if (!this._svgSize || !this._svgSize.equals(size)) {
55
+ if (!this._svgSize?.equals(size)) {
56
56
  this._svgSize = size;
57
57
  this._container.setAttribute("width", `${size.x}`);
58
58
  this._container.setAttribute("height", `${size.y}`);
@@ -88,7 +88,7 @@ var SVG = class SVG extends Renderer {
88
88
  }
89
89
  _addPath(layer) {
90
90
  if (!this._rootGroup) this._initContainer();
91
- this._rootGroup.appendChild(layer._path);
91
+ this._rootGroup.append(layer._path);
92
92
  layer.addInteractiveTarget(layer._path);
93
93
  }
94
94
  _removePath(layer) {