maplair 4.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/CHANGELOG.md +2804 -0
  2. package/LICENSE +27 -0
  3. package/README.md +40 -0
  4. package/dist/esm/Maplair.js +71 -0
  5. package/dist/esm/Maplair.js.map +1 -0
  6. package/dist/esm/_virtual/_rolldown/runtime.js +13 -0
  7. package/dist/esm/control/AttributionControl.js +79 -0
  8. package/dist/esm/control/AttributionControl.js.map +1 -0
  9. package/dist/esm/control/Control.js +81 -0
  10. package/dist/esm/control/Control.js.map +1 -0
  11. package/dist/esm/control/LayersControl.js +220 -0
  12. package/dist/esm/control/LayersControl.js.map +1 -0
  13. package/dist/esm/control/ScaleControl.js +72 -0
  14. package/dist/esm/control/ScaleControl.js.map +1 -0
  15. package/dist/esm/control/ZoomControl.js +86 -0
  16. package/dist/esm/control/ZoomControl.js.map +1 -0
  17. package/dist/esm/core/Browser.js +31 -0
  18. package/dist/esm/core/Browser.js.map +1 -0
  19. package/dist/esm/core/Class.js +52 -0
  20. package/dist/esm/core/Class.js.map +1 -0
  21. package/dist/esm/core/Events.js +149 -0
  22. package/dist/esm/core/Events.js.map +1 -0
  23. package/dist/esm/core/Handler.js +32 -0
  24. package/dist/esm/core/Handler.js.map +1 -0
  25. package/dist/esm/core/I18n.js +36 -0
  26. package/dist/esm/core/I18n.js.map +1 -0
  27. package/dist/esm/core/Util.js +71 -0
  28. package/dist/esm/core/Util.js.map +1 -0
  29. package/dist/esm/dom/DomEvent.DoubleTap.js +74 -0
  30. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -0
  31. package/dist/esm/dom/DomEvent.PointerEvents.js +46 -0
  32. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -0
  33. package/dist/esm/dom/DomEvent.js +135 -0
  34. package/dist/esm/dom/DomEvent.js.map +1 -0
  35. package/dist/esm/dom/DomUtil.js +107 -0
  36. package/dist/esm/dom/DomUtil.js.map +1 -0
  37. package/dist/esm/dom/Draggable.js +107 -0
  38. package/dist/esm/dom/Draggable.js.map +1 -0
  39. package/dist/esm/dom/PosAnimation.js +56 -0
  40. package/dist/esm/dom/PosAnimation.js.map +1 -0
  41. package/dist/esm/geo/LatLng.js +65 -0
  42. package/dist/esm/geo/LatLng.js.map +1 -0
  43. package/dist/esm/geo/LatLngBounds.js +114 -0
  44. package/dist/esm/geo/LatLngBounds.js.map +1 -0
  45. package/dist/esm/geo/crs/CRS.js +51 -0
  46. package/dist/esm/geo/crs/CRS.js.map +1 -0
  47. package/dist/esm/geo/crs/EPSG3395.js +16 -0
  48. package/dist/esm/geo/crs/EPSG3395.js.map +1 -0
  49. package/dist/esm/geo/crs/EPSG3857.js +19 -0
  50. package/dist/esm/geo/crs/EPSG3857.js.map +1 -0
  51. package/dist/esm/geo/crs/EPSG4326.js +13 -0
  52. package/dist/esm/geo/crs/EPSG4326.js.map +1 -0
  53. package/dist/esm/geo/crs/EarthCRS.js +14 -0
  54. package/dist/esm/geo/crs/EarthCRS.js.map +1 -0
  55. package/dist/esm/geo/crs/SimpleCRS.js +23 -0
  56. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -0
  57. package/dist/esm/geo/projection/Projection.LonLat.js +19 -0
  58. package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -0
  59. package/dist/esm/geo/projection/Projection.Mercator.js +33 -0
  60. package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -0
  61. package/dist/esm/geo/projection/Projection.SphericalMercator.js +27 -0
  62. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -0
  63. package/dist/esm/geo/projection/index.js +14 -0
  64. package/dist/esm/geo/projection/index.js.map +1 -0
  65. package/dist/esm/geometry/Bounds.js +91 -0
  66. package/dist/esm/geometry/Bounds.js.map +1 -0
  67. package/dist/esm/geometry/LineUtil.js +169 -0
  68. package/dist/esm/geometry/LineUtil.js.map +1 -0
  69. package/dist/esm/geometry/Point.js +119 -0
  70. package/dist/esm/geometry/Point.js.map +1 -0
  71. package/dist/esm/geometry/PolyUtil.js +89 -0
  72. package/dist/esm/geometry/PolyUtil.js.map +1 -0
  73. package/dist/esm/geometry/Transformation.js +34 -0
  74. package/dist/esm/geometry/Transformation.js.map +1 -0
  75. package/dist/esm/layer/BlanketOverlay.js +87 -0
  76. package/dist/esm/layer/BlanketOverlay.js.map +1 -0
  77. package/dist/esm/layer/DivOverlay.js +192 -0
  78. package/dist/esm/layer/DivOverlay.js.map +1 -0
  79. package/dist/esm/layer/FeatureGroup.js +40 -0
  80. package/dist/esm/layer/FeatureGroup.js.map +1 -0
  81. package/dist/esm/layer/GeoJSON.js +192 -0
  82. package/dist/esm/layer/GeoJSON.js.map +1 -0
  83. package/dist/esm/layer/ImageOverlay.js +140 -0
  84. package/dist/esm/layer/ImageOverlay.js.map +1 -0
  85. package/dist/esm/layer/Layer.js +119 -0
  86. package/dist/esm/layer/Layer.js.map +1 -0
  87. package/dist/esm/layer/LayerGroup.js +58 -0
  88. package/dist/esm/layer/LayerGroup.js.map +1 -0
  89. package/dist/esm/layer/Popup.js +224 -0
  90. package/dist/esm/layer/Popup.js.map +1 -0
  91. package/dist/esm/layer/SVGOverlay.js +21 -0
  92. package/dist/esm/layer/SVGOverlay.js.map +1 -0
  93. package/dist/esm/layer/Tooltip.js +228 -0
  94. package/dist/esm/layer/Tooltip.js.map +1 -0
  95. package/dist/esm/layer/VideoOverlay.js +54 -0
  96. package/dist/esm/layer/VideoOverlay.js.map +1 -0
  97. package/dist/esm/layer/marker/DefaultIcon.js +50 -0
  98. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -0
  99. package/dist/esm/layer/marker/DivIcon.js +37 -0
  100. package/dist/esm/layer/marker/DivIcon.js.map +1 -0
  101. package/dist/esm/layer/marker/Icon.js +65 -0
  102. package/dist/esm/layer/marker/Icon.js.map +1 -0
  103. package/dist/esm/layer/marker/Marker.Drag.js +77 -0
  104. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -0
  105. package/dist/esm/layer/marker/Marker.js +235 -0
  106. package/dist/esm/layer/marker/Marker.js.map +1 -0
  107. package/dist/esm/layer/tile/GridLayer.js +447 -0
  108. package/dist/esm/layer/tile/GridLayer.js.map +1 -0
  109. package/dist/esm/layer/tile/TileLayer.js +139 -0
  110. package/dist/esm/layer/tile/TileLayer.js.map +1 -0
  111. package/dist/esm/layer/tile/WMSTileLayer.js +68 -0
  112. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -0
  113. package/dist/esm/layer/vector/Canvas.js +292 -0
  114. package/dist/esm/layer/vector/Canvas.js.map +1 -0
  115. package/dist/esm/layer/vector/Circle.js +35 -0
  116. package/dist/esm/layer/vector/Circle.js.map +1 -0
  117. package/dist/esm/layer/vector/CircleMarker.js +69 -0
  118. package/dist/esm/layer/vector/CircleMarker.js.map +1 -0
  119. package/dist/esm/layer/vector/Path.js +68 -0
  120. package/dist/esm/layer/vector/Path.js.map +1 -0
  121. package/dist/esm/layer/vector/Polygon.js +70 -0
  122. package/dist/esm/layer/vector/Polygon.js.map +1 -0
  123. package/dist/esm/layer/vector/Polyline.js +152 -0
  124. package/dist/esm/layer/vector/Polyline.js.map +1 -0
  125. package/dist/esm/layer/vector/Rectangle.js +25 -0
  126. package/dist/esm/layer/vector/Rectangle.js.map +1 -0
  127. package/dist/esm/layer/vector/Renderer.getRenderer.js +31 -0
  128. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -0
  129. package/dist/esm/layer/vector/Renderer.js +39 -0
  130. package/dist/esm/layer/vector/Renderer.js.map +1 -0
  131. package/dist/esm/layer/vector/SVG.js +115 -0
  132. package/dist/esm/layer/vector/SVG.js.map +1 -0
  133. package/dist/esm/map/Map.js +844 -0
  134. package/dist/esm/map/Map.js.map +1 -0
  135. package/dist/esm/map/handler/BoxZoomHandler.js +105 -0
  136. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -0
  137. package/dist/esm/map/handler/DoubleClickZoomHandler.js +27 -0
  138. package/dist/esm/map/handler/DoubleClickZoomHandler.js.map +1 -0
  139. package/dist/esm/map/handler/DragHandler.js +133 -0
  140. package/dist/esm/map/handler/DragHandler.js.map +1 -0
  141. package/dist/esm/map/handler/KeyboardHandler.js +117 -0
  142. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -0
  143. package/dist/esm/map/handler/PinchZoomHandler.js +96 -0
  144. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -0
  145. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +50 -0
  146. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -0
  147. package/dist/esm/map/handler/TapHoldHandler.js +77 -0
  148. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -0
  149. package/dist/esm/package.js +6 -0
  150. package/dist/esm/package.js.map +1 -0
  151. package/dist/images/layers.svg +1 -0
  152. package/dist/images/logo.svg +1 -0
  153. package/dist/images/marker-icon.svg +1 -0
  154. package/dist/images/marker-shadow.svg +1 -0
  155. package/dist/maplair-global-src.js +6810 -0
  156. package/dist/maplair-global-src.js.map +1 -0
  157. package/dist/maplair-global.js +12 -0
  158. package/dist/maplair-global.js.map +1 -0
  159. package/dist/maplair-src.js +6704 -0
  160. package/dist/maplair-src.js.map +1 -0
  161. package/dist/maplair.css +730 -0
  162. package/dist/maplair.js +7 -0
  163. package/dist/maplair.js.map +1 -0
  164. package/i18n/cs.json +12 -0
  165. package/i18n/de.json +12 -0
  166. package/i18n/en.json +12 -0
  167. package/i18n/es.json +12 -0
  168. package/i18n/fr.json +12 -0
  169. package/i18n/hu.json +12 -0
  170. package/i18n/it.json +12 -0
  171. package/i18n/rm.json +12 -0
  172. package/i18n/sk.json +12 -0
  173. package/i18n/sl.json +12 -0
  174. package/package.json +87 -0
  175. package/src/Maplair.js +24 -0
  176. package/src/control/AttributionControl.js +147 -0
  177. package/src/control/Control.js +174 -0
  178. package/src/control/LayersControl.js +444 -0
  179. package/src/control/ScaleControl.js +141 -0
  180. package/src/control/ZoomControl.js +147 -0
  181. package/src/control/index.js +5 -0
  182. package/src/core/Browser.js +75 -0
  183. package/src/core/Class.js +97 -0
  184. package/src/core/Events.js +334 -0
  185. package/src/core/Handler.js +59 -0
  186. package/src/core/I18n.js +76 -0
  187. package/src/core/Util.js +122 -0
  188. package/src/core/index.js +8 -0
  189. package/src/dom/DomEvent.DoubleTap.js +120 -0
  190. package/src/dom/DomEvent.PointerEvents.js +75 -0
  191. package/src/dom/DomEvent.js +282 -0
  192. package/src/dom/DomUtil.js +175 -0
  193. package/src/dom/Draggable.js +204 -0
  194. package/src/dom/PosAnimation.js +115 -0
  195. package/src/dom/index.js +9 -0
  196. package/src/geo/LatLng.js +163 -0
  197. package/src/geo/LatLngBounds.js +260 -0
  198. package/src/geo/crs/CRS.js +143 -0
  199. package/src/geo/crs/EPSG3395.js +19 -0
  200. package/src/geo/crs/EPSG3857.js +26 -0
  201. package/src/geo/crs/EPSG4326.js +21 -0
  202. package/src/geo/crs/EarthCRS.js +32 -0
  203. package/src/geo/crs/SimpleCRS.js +35 -0
  204. package/src/geo/crs/index.js +6 -0
  205. package/src/geo/index.js +7 -0
  206. package/src/geo/projection/Projection.LonLat.js +30 -0
  207. package/src/geo/projection/Projection.Mercator.js +53 -0
  208. package/src/geo/projection/Projection.SphericalMercator.js +46 -0
  209. package/src/geo/projection/index.js +26 -0
  210. package/src/geometry/Bounds.js +222 -0
  211. package/src/geometry/LineUtil.js +299 -0
  212. package/src/geometry/Point.js +239 -0
  213. package/src/geometry/PolyUtil.js +129 -0
  214. package/src/geometry/Transformation.js +67 -0
  215. package/src/geometry/index.js +8 -0
  216. package/src/images/layers.svg +1 -0
  217. package/src/images/logo.svg +1 -0
  218. package/src/images/marker-icon.svg +1 -0
  219. package/src/images/marker-shadow.svg +1 -0
  220. package/src/layer/BlanketOverlay.js +171 -0
  221. package/src/layer/DivOverlay.js +353 -0
  222. package/src/layer/FeatureGroup.js +93 -0
  223. package/src/layer/GeoJSON.js +432 -0
  224. package/src/layer/ImageOverlay.js +279 -0
  225. package/src/layer/Layer.js +273 -0
  226. package/src/layer/LayerGroup.js +129 -0
  227. package/src/layer/Popup.js +528 -0
  228. package/src/layer/SVGOverlay.js +47 -0
  229. package/src/layer/Tooltip.js +469 -0
  230. package/src/layer/VideoOverlay.js +111 -0
  231. package/src/layer/index.js +18 -0
  232. package/src/layer/marker/DefaultIcon.js +79 -0
  233. package/src/layer/marker/DivIcon.js +76 -0
  234. package/src/layer/marker/Icon.js +164 -0
  235. package/src/layer/marker/Marker.Drag.js +161 -0
  236. package/src/layer/marker/Marker.js +465 -0
  237. package/src/layer/marker/index.js +5 -0
  238. package/src/layer/tile/GridLayer.js +901 -0
  239. package/src/layer/tile/TileLayer.js +299 -0
  240. package/src/layer/tile/WMSTileLayer.js +133 -0
  241. package/src/layer/tile/index.js +3 -0
  242. package/src/layer/vector/Canvas.js +479 -0
  243. package/src/layer/vector/Circle.js +87 -0
  244. package/src/layer/vector/CircleMarker.js +110 -0
  245. package/src/layer/vector/Path.js +145 -0
  246. package/src/layer/vector/Polygon.js +160 -0
  247. package/src/layer/vector/Polyline.js +296 -0
  248. package/src/layer/vector/Rectangle.js +52 -0
  249. package/src/layer/vector/Renderer.getRenderer.js +48 -0
  250. package/src/layer/vector/Renderer.js +75 -0
  251. package/src/layer/vector/SVG.js +216 -0
  252. package/src/layer/vector/index.js +10 -0
  253. package/src/map/Map.js +1830 -0
  254. package/src/map/handler/BoxZoomHandler.js +156 -0
  255. package/src/map/handler/DoubleClickZoomHandler.js +62 -0
  256. package/src/map/handler/DragHandler.js +240 -0
  257. package/src/map/handler/KeyboardHandler.js +188 -0
  258. package/src/map/handler/PinchZoomHandler.js +157 -0
  259. package/src/map/handler/ScrollWheelZoomHandler.js +98 -0
  260. package/src/map/handler/TapHoldHandler.js +111 -0
  261. package/src/map/index.js +8 -0
  262. package/src/maplair.css +730 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Bounds.js","names":[],"sources":["../../../src/geometry/Bounds.js"],"sourcesContent":["import {Point} from './Point.js';\n\n/*\n * @class Bounds\n *\n * Represents a rectangular area in pixel coordinates.\n *\n * @example\n *\n * ```js\n * const p1 = new Point(10, 10),\n * p2 = new Point(40, 60),\n * bounds = new Bounds(p1, p2);\n * ```\n *\n * All Maplair methods that accept `Bounds` objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:\n *\n * ```js\n * otherBounds.intersects([[10, 10], [40, 60]]);\n * ```\n *\n * Note that `Bounds` does not inherit from Maplair's `Class` object,\n * which means new classes can't inherit from it, and new methods\n * can't be added to it with the `include` function.\n */\n\n\n// @constructor Bounds(corner1: Point, corner2: Point)\n// Creates a Bounds object from two corners coordinate pairs.\n// @alternative\n// @constructor Bounds(points: Point[])\n// Creates a Bounds object from the given array of points.\n\n// @alternative\n// @constructor Bounds(bounds: Bounds)\n// Creates a copy of the given Bounds object.\nexport class Bounds {\n\tconstructor(a, b) {\n\t\tif (!a) { return; }\n\n\t\tif (a instanceof Bounds) {\n\t\t\tif (a.isValid()) {\n\t\t\t\tthis.min = new Point(a.min);\n\t\t\t\tthis.max = new Point(a.max);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst points = b ? [a, b] : a;\n\t\tfor (const point of points) {\n\t\t\tthis.extend(point);\n\t\t}\n\t}\n\n\t// @method extend(point: Point): this\n\t// Extends the bounds to contain the given point.\n\n\t// @alternative\n\t// @method extend(otherBounds: Bounds): this\n\t// Extend the bounds to contain the given bounds\n\textend(obj) {\n\t\tlet min2, max2;\n\t\tif (!obj) { return this; }\n\n\t\tif (obj instanceof Point || typeof obj[0] === 'number' || 'x' in obj) {\n\t\t\tmin2 = max2 = new Point(obj);\n\t\t} else {\n\t\t\tobj = new Bounds(obj);\n\t\t\tmin2 = obj.min;\n\t\t\tmax2 = obj.max;\n\n\t\t\tif (!min2 || !max2) { return this; }\n\t\t}\n\n\t\t// @property min: Point\n\t\t// The top left corner of the rectangle.\n\t\t// @property max: Point\n\t\t// The bottom right corner of the rectangle.\n\t\tif (!this.min && !this.max) {\n\t\t\tthis.min = new Point(min2);\n\t\t\tthis.max = new Point(max2);\n\t\t} else {\n\t\t\tthis.min.x = Math.min(min2.x, this.min.x);\n\t\t\tthis.max.x = Math.max(max2.x, this.max.x);\n\t\t\tthis.min.y = Math.min(min2.y, this.min.y);\n\t\t\tthis.max.y = Math.max(max2.y, this.max.y);\n\t\t}\n\t\treturn this;\n\t}\n\n\t// @method getCenter(round?: Boolean): Point\n\t// Returns the center point of the bounds.\n\tgetCenter(round) {\n\t\treturn new Point(\n\t\t\t(this.min.x + this.max.x) / 2,\n\t\t\t(this.min.y + this.max.y) / 2, round);\n\t}\n\n\t// @method getBottomLeft(): Point\n\t// Returns the bottom-left point of the bounds.\n\tgetBottomLeft() {\n\t\treturn new Point(this.min.x, this.max.y);\n\t}\n\n\t// @method getTopRight(): Point\n\t// Returns the top-right point of the bounds.\n\tgetTopRight() { // -> Point\n\t\treturn new Point(this.max.x, this.min.y);\n\t}\n\n\t// @method getTopLeft(): Point\n\t// Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-min)).\n\tgetTopLeft() {\n\t\treturn this.min; // left, top\n\t}\n\n\t// @method getBottomRight(): Point\n\t// Returns the bottom-right point of the bounds (i.e. [`this.max`](#bounds-max)).\n\tgetBottomRight() {\n\t\treturn this.max; // right, bottom\n\t}\n\n\t// @method getSize(): Point\n\t// Returns the size of the given bounds\n\tgetSize() {\n\t\treturn this.max.subtract(this.min);\n\t}\n\n\t// @method contains(otherBounds: Bounds): Boolean\n\t// Returns `true` if the rectangle contains the given one.\n\t// @alternative\n\t// @method contains(point: Point): Boolean\n\t// Returns `true` if the rectangle contains the given point.\n\tcontains(obj) {\n\t\tlet min, max;\n\n\t\tif (typeof obj[0] === 'number' || obj instanceof Point) {\n\t\t\tobj = new Point(obj);\n\t\t} else {\n\t\t\tobj = new Bounds(obj);\n\t\t}\n\n\t\tif (obj instanceof Bounds) {\n\t\t\tmin = obj.min;\n\t\t\tmax = obj.max;\n\t\t} else {\n\t\t\tmin = max = obj;\n\t\t}\n\n\t\treturn (min.x >= this.min.x) &&\n\t\t (max.x <= this.max.x) &&\n\t\t (min.y >= this.min.y) &&\n\t\t (max.y <= this.max.y);\n\t}\n\n\t// @method intersects(otherBounds: Bounds): Boolean\n\t// Returns `true` if the rectangle intersects the given bounds. Two bounds\n\t// intersect if they have at least one point in common.\n\tintersects(bounds) { // (Bounds) -> Boolean\n\t\tbounds = new Bounds(bounds);\n\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\tmin2 = bounds.min,\n\t\tmax2 = bounds.max,\n\t\txIntersects = (max2.x >= min.x) && (min2.x <= max.x),\n\t\tyIntersects = (max2.y >= min.y) && (min2.y <= max.y);\n\n\t\treturn xIntersects && yIntersects;\n\t}\n\n\t// @method overlaps(otherBounds: Bounds): Boolean\n\t// Returns `true` if the rectangle overlaps the given bounds. Two bounds\n\t// overlap if their intersection is an area.\n\toverlaps(bounds) { // (Bounds) -> Boolean\n\t\tbounds = new Bounds(bounds);\n\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\tmin2 = bounds.min,\n\t\tmax2 = bounds.max,\n\t\txOverlaps = (max2.x > min.x) && (min2.x < max.x),\n\t\tyOverlaps = (max2.y > min.y) && (min2.y < max.y);\n\n\t\treturn xOverlaps && yOverlaps;\n\t}\n\n\t// @method isValid(): Boolean\n\t// Returns `true` if the bounds are properly initialized.\n\tisValid() {\n\t\treturn !!(this.min && this.max);\n\t}\n\n\n\t// @method pad(bufferRatio: Number): Bounds\n\t// Returns bounds created by extending or retracting the current bounds by a given ratio in each direction.\n\t// For example, a ratio of 0.5 extends the bounds by 50% in each direction.\n\t// Negative values will retract the bounds.\n\tpad(bufferRatio) {\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\theightBuffer = Math.abs(min.x - max.x) * bufferRatio,\n\t\twidthBuffer = Math.abs(min.y - max.y) * bufferRatio;\n\n\n\t\treturn new Bounds(\n\t\t\tnew Point(min.x - heightBuffer, min.y - widthBuffer),\n\t\t\tnew Point(max.x + heightBuffer, max.y + widthBuffer));\n\t}\n\n\n\t// @method equals(otherBounds: Bounds): Boolean\n\t// Returns `true` if the rectangle is equivalent to the given bounds.\n\tequals(bounds) {\n\t\tif (!bounds) { return false; }\n\n\t\tbounds = new Bounds(bounds);\n\n\t\treturn this.min.equals(bounds.getTopLeft()) &&\n\t\t\tthis.max.equals(bounds.getBottomRight());\n\t}\n}\n"],"mappings":";;AAoCA,IAAa,SAAb,MAAa,OAAO;CACnB,YAAY,GAAG,GAAG;EACjB,IAAI,CAAC,GAAK;EAEV,IAAI,aAAa,QAAQ;GACxB,IAAI,EAAE,QAAQ,GAAG;IAChB,KAAK,MAAM,IAAI,MAAM,EAAE,GAAG;IAC1B,KAAK,MAAM,IAAI,MAAM,EAAE,GAAG;GAC3B;GACA;EACD;EAEA,MAAM,SAAS,IAAI,CAAC,GAAG,CAAC,IAAI;EAC5B,KAAK,MAAM,SAAS,QACnB,KAAK,OAAO,KAAK;CAEnB;CAQA,OAAO,KAAK;EACX,IAAI,MAAM;EACV,IAAI,CAAC,KAAO,OAAO;EAEnB,IAAI,eAAe,SAAS,OAAO,IAAI,OAAO,YAAY,OAAO,KAChE,OAAO,OAAO,IAAI,MAAM,GAAG;OACrB;GACN,MAAM,IAAI,OAAO,GAAG;GACpB,OAAO,IAAI;GACX,OAAO,IAAI;GAEX,IAAI,CAAC,QAAQ,CAAC,MAAQ,OAAO;EAC9B;EAMA,IAAI,CAAC,KAAK,OAAO,CAAC,KAAK,KAAK;GAC3B,KAAK,MAAM,IAAI,MAAM,IAAI;GACzB,KAAK,MAAM,IAAI,MAAM,IAAI;EAC1B,OAAO;GACN,KAAK,IAAI,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC;GACxC,KAAK,IAAI,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC;GACxC,KAAK,IAAI,IAAI,KAAK,IAAI,KAAK,GAAG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,KAAK,KACX,OAAO,OAAO,KACd,OAAO,OAAO,KACd,YAAa,KAAK,IAAI,IAAI,KAAO,KAAK,IAAI,IAAI,GAC9C,YAAa,KAAK,IAAI,IAAI,KAAO,KAAK,IAAI,IAAI;EAE9C,OAAO,aAAa;CACrB;CAIA,UAAU;EACT,OAAO,CAAC,EAAE,KAAK,OAAO,KAAK;CAC5B;CAOA,IAAI,aAAa;EAChB,MAAM,MAAM,KAAK,KACjB,MAAM,KAAK,KACX,eAAe,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,aACzC,cAAc,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI;EAGxC,OAAO,IAAI,OACV,IAAI,MAAM,IAAI,IAAI,cAAc,IAAI,IAAI,WAAW,GACnD,IAAI,MAAM,IAAI,IAAI,cAAc,IAAI,IAAI,WAAW,CAAC;CACtD;CAKA,OAAO,QAAQ;EACd,IAAI,CAAC,QAAU,OAAO;EAEtB,SAAS,IAAI,OAAO,MAAM;EAE1B,OAAO,KAAK,IAAI,OAAO,OAAO,WAAW,CAAC,KACzC,KAAK,IAAI,OAAO,OAAO,eAAe,CAAC;CACzC;AACD"}
@@ -0,0 +1,169 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ import { Point } from "./Point.js";
3
+ import { LatLngBounds } from "../geo/LatLngBounds.js";
4
+ import { LatLng } from "../geo/LatLng.js";
5
+ import { centroid } from "./PolyUtil.js";
6
+ //#region src/geometry/LineUtil.js
7
+ var LineUtil_exports = /* @__PURE__ */ __exportAll({
8
+ _getBitCode: () => _getBitCode,
9
+ _getEdgeIntersection: () => _getEdgeIntersection,
10
+ _sqClosestPointOnSegment: () => _sqClosestPointOnSegment,
11
+ clipSegment: () => clipSegment,
12
+ closestPointOnSegment: () => closestPointOnSegment,
13
+ isFlat: () => isFlat,
14
+ pointToSegmentDistance: () => pointToSegmentDistance,
15
+ polylineCenter: () => polylineCenter,
16
+ simplify: () => simplify
17
+ });
18
+ function simplify(points, tolerance) {
19
+ if (!tolerance || !points.length) return points.slice();
20
+ const sqTolerance = tolerance * tolerance;
21
+ points = _reducePoints(points, sqTolerance);
22
+ points = _simplifyDP(points, sqTolerance);
23
+ return points;
24
+ }
25
+ function pointToSegmentDistance(p, p1, p2) {
26
+ return Math.sqrt(_sqClosestPointOnSegment(p, p1, p2, true));
27
+ }
28
+ function closestPointOnSegment(p, p1, p2) {
29
+ return _sqClosestPointOnSegment(p, p1, p2);
30
+ }
31
+ function _simplifyDP(points, sqTolerance) {
32
+ const len = points.length, markers = new Uint8Array(len);
33
+ markers[0] = markers[len - 1] = 1;
34
+ _simplifyDPStep(points, markers, sqTolerance, 0, len - 1);
35
+ let i;
36
+ const newPoints = [];
37
+ for (i = 0; i < len; i++) if (markers[i]) newPoints.push(points[i]);
38
+ return newPoints;
39
+ }
40
+ function _simplifyDPStep(points, markers, sqTolerance, first, last) {
41
+ let maxSqDist = 0, index, i, sqDist;
42
+ for (i = first + 1; i <= last - 1; i++) {
43
+ sqDist = _sqClosestPointOnSegment(points[i], points[first], points[last], true);
44
+ if (sqDist > maxSqDist) {
45
+ index = i;
46
+ maxSqDist = sqDist;
47
+ }
48
+ }
49
+ if (maxSqDist > sqTolerance) {
50
+ markers[index] = 1;
51
+ _simplifyDPStep(points, markers, sqTolerance, first, index);
52
+ _simplifyDPStep(points, markers, sqTolerance, index, last);
53
+ }
54
+ }
55
+ function _reducePoints(points, sqTolerance) {
56
+ const reducedPoints = [points[0]];
57
+ let prev = 0;
58
+ for (let i = 1; i < points.length; i++) if (_sqDist(points[i], points[prev]) > sqTolerance) {
59
+ reducedPoints.push(points[i]);
60
+ prev = i;
61
+ }
62
+ if (prev < points.length - 1) reducedPoints.push(points[points.length - 1]);
63
+ return reducedPoints;
64
+ }
65
+ let _lastCode;
66
+ function clipSegment(a, b, bounds, useLastCode, round) {
67
+ let codeA = useLastCode ? _lastCode : _getBitCode(a, bounds), codeB = _getBitCode(b, bounds), codeOut, p, newCode;
68
+ _lastCode = codeB;
69
+ while (true) {
70
+ if (!(codeA | codeB)) return [a, b];
71
+ if (codeA & codeB) return false;
72
+ codeOut = codeA || codeB;
73
+ p = _getEdgeIntersection(a, b, codeOut, bounds, round);
74
+ newCode = _getBitCode(p, bounds);
75
+ if (codeOut === codeA) {
76
+ a = p;
77
+ codeA = newCode;
78
+ } else {
79
+ b = p;
80
+ codeB = newCode;
81
+ }
82
+ }
83
+ }
84
+ function _getEdgeIntersection(a, b, code, bounds, round) {
85
+ const dx = b.x - a.x, dy = b.y - a.y, min = bounds.min, max = bounds.max;
86
+ let x, y;
87
+ if (code & 8) {
88
+ x = a.x + dx * (max.y - a.y) / dy;
89
+ y = max.y;
90
+ } else if (code & 4) {
91
+ x = a.x + dx * (min.y - a.y) / dy;
92
+ y = min.y;
93
+ } else if (code & 2) {
94
+ x = max.x;
95
+ y = a.y + dy * (max.x - a.x) / dx;
96
+ } else if (code & 1) {
97
+ x = min.x;
98
+ y = a.y + dy * (min.x - a.x) / dx;
99
+ }
100
+ return new Point(x, y, round);
101
+ }
102
+ function _getBitCode(p, bounds) {
103
+ let code = 0;
104
+ if (p.x < bounds.min.x) code |= 1;
105
+ else if (p.x > bounds.max.x) code |= 2;
106
+ if (p.y < bounds.min.y) code |= 4;
107
+ else if (p.y > bounds.max.y) code |= 8;
108
+ return code;
109
+ }
110
+ function _sqDist(p1, p2) {
111
+ const dx = p2.x - p1.x, dy = p2.y - p1.y;
112
+ return dx * dx + dy * dy;
113
+ }
114
+ function _sqClosestPointOnSegment(p, p1, p2, sqDist) {
115
+ let x = p1.x, y = p1.y, dx = p2.x - x, dy = p2.y - y, t;
116
+ const dot = dx * dx + dy * dy;
117
+ if (dot > 0) {
118
+ t = ((p.x - x) * dx + (p.y - y) * dy) / dot;
119
+ if (t > 1) {
120
+ x = p2.x;
121
+ y = p2.y;
122
+ } else if (t > 0) {
123
+ x += dx * t;
124
+ y += dy * t;
125
+ }
126
+ }
127
+ dx = p.x - x;
128
+ dy = p.y - y;
129
+ return sqDist ? dx * dx + dy * dy : new Point(x, y);
130
+ }
131
+ function isFlat(latlngs) {
132
+ return !Array.isArray(latlngs[0]) || typeof latlngs[0][0] !== "object" && typeof latlngs[0][0] !== "undefined";
133
+ }
134
+ function polylineCenter(latlngs, crs) {
135
+ let i, halfDist, segDist, dist, p1, p2, ratio, center;
136
+ if (!latlngs || latlngs.length === 0) throw new Error("latlngs not passed");
137
+ if (!isFlat(latlngs)) {
138
+ console.warn("latlngs are not flat! Only the first ring will be used");
139
+ latlngs = latlngs[0];
140
+ }
141
+ let centroidLatLng = new LatLng([0, 0]);
142
+ const bounds = new LatLngBounds(latlngs);
143
+ if (bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest()) < 1700) centroidLatLng = centroid(latlngs);
144
+ const len = latlngs.length;
145
+ const points = [];
146
+ for (i = 0; i < len; i++) {
147
+ const latlng = new LatLng(latlngs[i]);
148
+ points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
149
+ }
150
+ for (i = 0, halfDist = 0; i < len - 1; i++) halfDist += points[i].distanceTo(points[i + 1]) / 2;
151
+ if (halfDist === 0) center = points[0];
152
+ else for (i = 0, dist = 0; i < len - 1; i++) {
153
+ p1 = points[i];
154
+ p2 = points[i + 1];
155
+ segDist = p1.distanceTo(p2);
156
+ dist += segDist;
157
+ if (dist > halfDist) {
158
+ ratio = (dist - halfDist) / segDist;
159
+ center = [p2.x - ratio * (p2.x - p1.x), p2.y - ratio * (p2.y - p1.y)];
160
+ break;
161
+ }
162
+ }
163
+ const latlngCenter = crs.unproject(new Point(center));
164
+ return new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);
165
+ }
166
+ //#endregion
167
+ export { LineUtil_exports, _getBitCode, _getEdgeIntersection, _sqClosestPointOnSegment, clipSegment, closestPointOnSegment, isFlat, pointToSegmentDistance, polylineCenter, simplify };
168
+
169
+ //# sourceMappingURL=LineUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LineUtil.js","names":[],"sources":["../../../src/geometry/LineUtil.js"],"sourcesContent":["import {Point} from './Point.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {centroid} from './PolyUtil.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\n\n\n/*\n * @namespace LineUtil\n *\n * Various utility functions for polyline points processing, used by Maplair internally to make polylines lightning-fast.\n */\n\n// Simplify polyline with vertex reduction and Douglas-Peucker simplification.\n// Improves rendering performance dramatically by lessening the number of points to draw.\n\n// @function simplify(points: Point[], tolerance: Number): Point[]\n// Dramatically reduces the number of points in a polyline while retaining\n// its shape and returns a new array of simplified points, using the\n// [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm).\n// Used for a huge performance boost when processing/displaying Maplair polylines for\n// each zoom level and also reducing visual noise. tolerance affects the amount of\n// simplification (lesser value means higher quality but slower and with more points).\n// Also released as a separated micro-library [Simplify.js](https://mourner.github.io/simplify-js/).\nexport function simplify(points, tolerance) {\n\tif (!tolerance || !points.length) {\n\t\treturn points.slice();\n\t}\n\n\tconst sqTolerance = tolerance * tolerance;\n\n\t// stage 1: vertex reduction\n\tpoints = _reducePoints(points, sqTolerance);\n\n\t// stage 2: Douglas-Peucker simplification\n\tpoints = _simplifyDP(points, sqTolerance);\n\n\treturn points;\n}\n\n// @function pointToSegmentDistance(p: Point, p1: Point, p2: Point): Number\n// Returns the distance between point `p` and segment `p1` to `p2`.\nexport function pointToSegmentDistance(p, p1, p2) {\n\treturn Math.sqrt(_sqClosestPointOnSegment(p, p1, p2, true));\n}\n\n// @function closestPointOnSegment(p: Point, p1: Point, p2: Point): Number\n// Returns the closest point from a point `p` on a segment `p1` to `p2`.\nexport function closestPointOnSegment(p, p1, p2) {\n\treturn _sqClosestPointOnSegment(p, p1, p2);\n}\n\n// Ramer-Douglas-Peucker simplification, see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm\nfunction _simplifyDP(points, sqTolerance) {\n\n\tconst len = points.length,\n\tmarkers = new Uint8Array(len);\n\tmarkers[0] = markers[len - 1] = 1;\n\n\t_simplifyDPStep(points, markers, sqTolerance, 0, len - 1);\n\n\tlet i;\n\tconst newPoints = [];\n\n\tfor (i = 0; i < len; i++) {\n\t\tif (markers[i]) {\n\t\t\tnewPoints.push(points[i]);\n\t\t}\n\t}\n\n\treturn newPoints;\n}\n\nfunction _simplifyDPStep(points, markers, sqTolerance, first, last) {\n\n\tlet maxSqDist = 0,\n\tindex, i, sqDist;\n\n\tfor (i = first + 1; i <= last - 1; i++) {\n\t\tsqDist = _sqClosestPointOnSegment(points[i], points[first], points[last], true);\n\n\t\tif (sqDist > maxSqDist) {\n\t\t\tindex = i;\n\t\t\tmaxSqDist = sqDist;\n\t\t}\n\t}\n\n\tif (maxSqDist > sqTolerance) {\n\t\tmarkers[index] = 1;\n\n\t\t_simplifyDPStep(points, markers, sqTolerance, first, index);\n\t\t_simplifyDPStep(points, markers, sqTolerance, index, last);\n\t}\n}\n\n// reduce points that are too close to each other to a single point\nfunction _reducePoints(points, sqTolerance) {\n\tconst reducedPoints = [points[0]];\n\tlet prev = 0;\n\n\tfor (let i = 1; i < points.length; i++) {\n\t\tif (_sqDist(points[i], points[prev]) > sqTolerance) {\n\t\t\treducedPoints.push(points[i]);\n\t\t\tprev = i;\n\t\t}\n\t}\n\tif (prev < points.length - 1) {\n\t\treducedPoints.push(points[points.length - 1]);\n\t}\n\treturn reducedPoints;\n}\n\nlet _lastCode;\n\n// @function clipSegment(a: Point, b: Point, bounds: Bounds, useLastCode?: Boolean, round?: Boolean): Point[]|Boolean\n// Clips the segment a to b by rectangular bounds with the\n// [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm)\n// (modifying the segment points directly!). Used by Maplair to only show polyline\n// points that are on the screen or near, increasing performance.\nexport function clipSegment(a, b, bounds, useLastCode, round) {\n\tlet codeA = useLastCode ? _lastCode : _getBitCode(a, bounds),\n\tcodeB = _getBitCode(b, bounds),\n\n\tcodeOut, p, newCode;\n\n\t// save 2nd code to avoid calculating it on the next segment\n\t_lastCode = codeB;\n\n\twhile (true) {\n\t\t// if a,b is inside the clip window (trivial accept)\n\t\tif (!(codeA | codeB)) {\n\t\t\treturn [a, b];\n\t\t}\n\n\t\t// if a,b is outside the clip window (trivial reject)\n\t\tif (codeA & codeB) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// other cases\n\t\tcodeOut = codeA || codeB;\n\t\tp = _getEdgeIntersection(a, b, codeOut, bounds, round);\n\t\tnewCode = _getBitCode(p, bounds);\n\n\t\tif (codeOut === codeA) {\n\t\t\ta = p;\n\t\t\tcodeA = newCode;\n\t\t} else {\n\t\t\tb = p;\n\t\t\tcodeB = newCode;\n\t\t}\n\t}\n}\n\nexport function _getEdgeIntersection(a, b, code, bounds, round) {\n\tconst dx = b.x - a.x,\n\tdy = b.y - a.y,\n\tmin = bounds.min,\n\tmax = bounds.max;\n\tlet x, y;\n\n\tif (code & 8) { // top\n\t\tx = a.x + dx * (max.y - a.y) / dy;\n\t\ty = max.y;\n\n\t} else if (code & 4) { // bottom\n\t\tx = a.x + dx * (min.y - a.y) / dy;\n\t\ty = min.y;\n\n\t} else if (code & 2) { // right\n\t\tx = max.x;\n\t\ty = a.y + dy * (max.x - a.x) / dx;\n\n\t} else if (code & 1) { // left\n\t\tx = min.x;\n\t\ty = a.y + dy * (min.x - a.x) / dx;\n\t}\n\n\treturn new Point(x, y, round);\n}\n\nexport function _getBitCode(p, bounds) {\n\tlet code = 0;\n\n\tif (p.x < bounds.min.x) { // left\n\t\tcode |= 1;\n\t} else if (p.x > bounds.max.x) { // right\n\t\tcode |= 2;\n\t}\n\n\tif (p.y < bounds.min.y) { // bottom\n\t\tcode |= 4;\n\t} else if (p.y > bounds.max.y) { // top\n\t\tcode |= 8;\n\t}\n\n\treturn code;\n}\n\n// square distance (to avoid unnecessary Math.sqrt calls)\nfunction _sqDist(p1, p2) {\n\tconst dx = p2.x - p1.x,\n\tdy = p2.y - p1.y;\n\treturn dx * dx + dy * dy;\n}\n\n// return closest point on segment or distance to that point\nexport function _sqClosestPointOnSegment(p, p1, p2, sqDist) {\n\tlet x = p1.x,\n\ty = p1.y,\n\tdx = p2.x - x,\n\tdy = p2.y - y,\n\tt;\n\tconst dot = dx * dx + dy * dy;\n\n\tif (dot > 0) {\n\t\tt = ((p.x - x) * dx + (p.y - y) * dy) / dot;\n\n\t\tif (t > 1) {\n\t\t\tx = p2.x;\n\t\t\ty = p2.y;\n\t\t} else if (t > 0) {\n\t\t\tx += dx * t;\n\t\t\ty += dy * t;\n\t\t}\n\t}\n\n\tdx = p.x - x;\n\tdy = p.y - y;\n\n\treturn sqDist ? dx * dx + dy * dy : new Point(x, y);\n}\n\n\n// @function isFlat(latlngs: LatLng[]): Boolean\n// Returns true if `latlngs` is a flat array, false is nested.\nexport function isFlat(latlngs) {\n\treturn !Array.isArray(latlngs[0]) || (typeof latlngs[0][0] !== 'object' && typeof latlngs[0][0] !== 'undefined');\n}\n\n/* @function polylineCenter(latlngs: LatLng[], crs: CRS): LatLng\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed LatLngs (first ring) from a polyline.\n */\nexport function polylineCenter(latlngs, crs) {\n\tlet i, halfDist, segDist, dist, p1, p2, ratio, center;\n\n\tif (!latlngs || latlngs.length === 0) {\n\t\tthrow new Error('latlngs not passed');\n\t}\n\n\tif (!isFlat(latlngs)) {\n\t\tconsole.warn('latlngs are not flat! Only the first ring will be used');\n\t\tlatlngs = latlngs[0];\n\t}\n\n\tlet centroidLatLng = new LatLng([0, 0]);\n\n\tconst bounds = new LatLngBounds(latlngs);\n\tconst areaBounds = bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest());\n\t// tests showed that below 1700 rounding errors are happening\n\tif (areaBounds < 1700) {\n\t\t// getting a inexact center, to move the latlngs near to [0, 0] to prevent rounding errors\n\t\tcentroidLatLng = centroid(latlngs);\n\t}\n\n\tconst len = latlngs.length;\n\tconst points = [];\n\tfor (i = 0; i < len; i++) {\n\t\tconst latlng = new LatLng(latlngs[i]);\n\t\tpoints.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));\n\t}\n\n\tfor (i = 0, halfDist = 0; i < len - 1; i++) {\n\t\thalfDist += points[i].distanceTo(points[i + 1]) / 2;\n\t}\n\n\t// The line is so small in the current view that all points are on the same pixel.\n\tif (halfDist === 0) {\n\t\tcenter = points[0];\n\t} else {\n\t\tfor (i = 0, dist = 0; i < len - 1; i++) {\n\t\t\tp1 = points[i];\n\t\t\tp2 = points[i + 1];\n\t\t\tsegDist = p1.distanceTo(p2);\n\t\t\tdist += segDist;\n\n\t\t\tif (dist > halfDist) {\n\t\t\t\tratio = (dist - halfDist) / segDist;\n\t\t\t\tcenter = [\n\t\t\t\t\tp2.x - ratio * (p2.x - p1.x),\n\t\t\t\t\tp2.y - ratio * (p2.y - p1.y)\n\t\t\t\t];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst latlngCenter = crs.unproject(new Point(center));\n\treturn new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,SAAgB,SAAS,QAAQ,WAAW;CAC3C,IAAI,CAAC,aAAa,CAAC,OAAO,QACzB,OAAO,OAAO,MAAM;CAGrB,MAAM,cAAc,YAAY;CAGhC,SAAS,cAAc,QAAQ,WAAW;CAG1C,SAAS,YAAY,QAAQ,WAAW;CAExC,OAAO;AACR;AAIA,SAAgB,uBAAuB,GAAG,IAAI,IAAI;CACjD,OAAO,KAAK,KAAK,yBAAyB,GAAG,IAAI,IAAI,IAAI,CAAC;AAC3D;AAIA,SAAgB,sBAAsB,GAAG,IAAI,IAAI;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OAAO,aAAa,CAAC,CAAC,WAAW,OAAO,aAAa,CAAC,IAElH,MAEhB,iBAAiB,SAAS,OAAO;CAGlC,MAAM,MAAM,QAAQ;CACpB,MAAM,SAAS,CAAC;CAChB,KAAK,IAAI,GAAG,IAAI,KAAK,KAAK;EACzB,MAAM,SAAS,IAAI,OAAO,QAAQ,EAAE;EACpC,OAAO,KAAK,IAAI,QAAQ,IAAI,OAAO,CAAC,OAAO,MAAM,eAAe,KAAK,OAAO,MAAM,eAAe,GAAG,CAAC,CAAC,CAAC;CACxG;CAEA,KAAK,IAAI,GAAG,WAAW,GAAG,IAAI,MAAM,GAAG,KACtC,YAAY,OAAO,EAAE,CAAC,WAAW,OAAO,IAAI,EAAE,IAAI;CAInD,IAAI,aAAa,GAChB,SAAS,OAAO;MAEhB,KAAK,IAAI,GAAG,OAAO,GAAG,IAAI,MAAM,GAAG,KAAK;EACvC,KAAK,OAAO;EACZ,KAAK,OAAO,IAAI;EAChB,UAAU,GAAG,WAAW,EAAE;EAC1B,QAAQ;EAER,IAAI,OAAO,UAAU;GACpB,SAAS,OAAO,YAAY;GAC5B,SAAS,CACR,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,IAC1B,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,EAC3B;GACA;EACD;CACD;CAGD,MAAM,eAAe,IAAI,UAAU,IAAI,MAAM,MAAM,CAAC;CACpD,OAAO,IAAI,OAAO,CAAC,aAAa,MAAM,eAAe,KAAK,aAAa,MAAM,eAAe,GAAG,CAAC;AACjG"}
@@ -0,0 +1,119 @@
1
+ import { formatNum } from "../core/Util.js";
2
+ //#region src/geometry/Point.js
3
+ var Point = class Point {
4
+ constructor(x, y, round) {
5
+ if (!Point.validate(x, y)) throw new Error(`Invalid Point object: (${x}, ${y})`);
6
+ let _x, _y;
7
+ if (x instanceof Point) {
8
+ _x = x.x;
9
+ _y = x.y;
10
+ } else if (Array.isArray(x)) {
11
+ _x = x[0];
12
+ _y = x[1];
13
+ } else if (typeof x === "object" && "x" in x && "y" in x) {
14
+ _x = x.x;
15
+ _y = x.y;
16
+ } else {
17
+ _x = x;
18
+ _y = y;
19
+ }
20
+ this.x = round ? Math.round(_x) : _x;
21
+ this.y = round ? Math.round(_y) : _y;
22
+ }
23
+ static validate(x, y) {
24
+ if (x instanceof Point || Array.isArray(x)) return true;
25
+ else if (x && typeof x === "object" && "x" in x && "y" in x) return true;
26
+ else if ((x || x === 0) && (y || y === 0)) return true;
27
+ return false;
28
+ }
29
+ add(point) {
30
+ return new Point(this)._add(new Point(point));
31
+ }
32
+ _add(point) {
33
+ this.x += point.x;
34
+ this.y += point.y;
35
+ return this;
36
+ }
37
+ subtract(point) {
38
+ return new Point(this)._subtract(new Point(point));
39
+ }
40
+ _subtract(point) {
41
+ this.x -= point.x;
42
+ this.y -= point.y;
43
+ return this;
44
+ }
45
+ divideBy(num) {
46
+ return new Point(this)._divideBy(num);
47
+ }
48
+ _divideBy(num) {
49
+ this.x /= num;
50
+ this.y /= num;
51
+ return this;
52
+ }
53
+ multiplyBy(num) {
54
+ return new Point(this)._multiplyBy(num);
55
+ }
56
+ _multiplyBy(num) {
57
+ this.x *= num;
58
+ this.y *= num;
59
+ return this;
60
+ }
61
+ scaleBy(point) {
62
+ return new Point(this.x * point.x, this.y * point.y);
63
+ }
64
+ unscaleBy(point) {
65
+ return new Point(this.x / point.x, this.y / point.y);
66
+ }
67
+ round() {
68
+ return new Point(this)._round();
69
+ }
70
+ _round() {
71
+ this.x = Math.round(this.x);
72
+ this.y = Math.round(this.y);
73
+ return this;
74
+ }
75
+ floor() {
76
+ return new Point(this)._floor();
77
+ }
78
+ _floor() {
79
+ this.x = Math.floor(this.x);
80
+ this.y = Math.floor(this.y);
81
+ return this;
82
+ }
83
+ ceil() {
84
+ return new Point(this)._ceil();
85
+ }
86
+ _ceil() {
87
+ this.x = Math.ceil(this.x);
88
+ this.y = Math.ceil(this.y);
89
+ return this;
90
+ }
91
+ trunc() {
92
+ return new Point(this)._trunc();
93
+ }
94
+ _trunc() {
95
+ this.x = Math.trunc(this.x);
96
+ this.y = Math.trunc(this.y);
97
+ return this;
98
+ }
99
+ distanceTo(point) {
100
+ point = new Point(point);
101
+ const x = point.x - this.x, y = point.y - this.y;
102
+ return Math.sqrt(x * x + y * y);
103
+ }
104
+ equals(point) {
105
+ point = new Point(point);
106
+ return point.x === this.x && point.y === this.y;
107
+ }
108
+ contains(point) {
109
+ point = new Point(point);
110
+ return Math.abs(point.x) <= Math.abs(this.x) && Math.abs(point.y) <= Math.abs(this.y);
111
+ }
112
+ toString() {
113
+ return `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;
114
+ }
115
+ };
116
+ //#endregion
117
+ export { Point };
118
+
119
+ //# sourceMappingURL=Point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Point.js","names":[],"sources":["../../../src/geometry/Point.js"],"sourcesContent":["import {formatNum} from '../core/Util.js';\n\n/*\n * @class Point\n *\n * Represents a point with `x` and `y` coordinates in pixels.\n *\n * @example\n *\n * ```js\n * const point = new Point(200, 300);\n * ```\n *\n * All Maplair methods and options that accept `Point` objects also accept them in a simple Array form (unless noted otherwise), so these lines are equivalent:\n *\n * ```js\n * map.panBy([200, 300]);\n * map.panBy(new Point(200, 300));\n * ```\n *\n * Note that `Point` does not inherit from Maplair's `Class` object,\n * which means new classes can't inherit from it, and new methods\n * can't be added to it with the `include` function.\n */\n\n// @constructor Point(x: Number, y: Number, round?: Boolean)\n// Creates a Point object with the given `x` and `y` coordinates. If optional `round` is set to true, rounds the `x` and `y` values.\n\n// @alternative\n// @constructor Point(coords: Point)\n// Expects a Point object instead.\n\n// @alternative\n// @constructor Point(coords: Number[])\n// Expects an array of the form `[x, y]` instead.\n\n// @alternative\n// @constructor Point(coords: Object)\n// Expects a plain object of the form `{x: Number, y: Number}` instead.\nexport class Point {\n\tconstructor(x, y, round) {\n\n\t\tconst valid = Point.validate(x, y);\n\t\tif (!valid) {\n\t\t\tthrow new Error(`Invalid Point object: (${x}, ${y})`);\n\t\t}\n\n\t\tlet _x, _y;\n\t\tif (x instanceof Point) {\n\t\t\t_x = x.x;\n\t\t\t_y = x.y;\n\t\t} else if (Array.isArray(x)) {\n\t\t\t_x = x[0];\n\t\t\t_y = x[1];\n\t\t} else if (typeof x === 'object' && 'x' in x && 'y' in x) {\n\t\t\t_x = x.x;\n\t\t\t_y = x.y;\n\t\t} else {\n\t\t\t_x = x;\n\t\t\t_y = y;\n\t\t}\n\n\t\t// @property x: Number; The `x` coordinate of the point\n\t\tthis.x = (round ? Math.round(_x) : _x);\n\t\t// @property y: Number; The `y` coordinate of the point\n\t\tthis.y = (round ? Math.round(_y) : _y);\n\t}\n\n\t// @section\n\t// There are several static functions which can be called without instantiating Point:\n\n\t// @function validate(x: Number, y: Number): Boolean\n\t// Returns `true` if the Point object can be properly initialized.\n\n\t// @alternative\n\t// @function validate(coords: Number[]): Boolean\n\t// Expects an array of the form `[x, y]`. Returns `true` if the Point object can be properly initialized.\n\n\t// @alternative\n\t// @function validate(coords: Object): Boolean\n\t// Returns `true` if the Point object can be properly initialized.\n\tstatic validate(x, y) {\n\t\tif (x instanceof Point || Array.isArray(x)) {\n\t\t\treturn true;\n\t\t} else if (x && typeof x === 'object' && 'x' in x && 'y' in x) {\n\t\t\treturn true;\n\t\t} else if ((x || x === 0) && (y || y === 0)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t// @method add(otherPoint: Point): Point\n\t// Returns the result of addition of the current and the given points.\n\tadd(point) {\n\t\t// non-destructive, returns a new point\n\t\treturn new Point(this)._add(new Point(point));\n\t}\n\n\t_add(point) {\n\t\t// destructive, used directly for performance in situations where it's safe to modify existing point\n\t\tthis.x += point.x;\n\t\tthis.y += point.y;\n\t\treturn this;\n\t}\n\n\t// @method subtract(otherPoint: Point): Point\n\t// Returns the result of subtraction of the given point from the current.\n\tsubtract(point) {\n\t\treturn new Point(this)._subtract(new Point(point));\n\t}\n\n\t_subtract(point) {\n\t\tthis.x -= point.x;\n\t\tthis.y -= point.y;\n\t\treturn this;\n\t}\n\n\t// @method divideBy(num: Number): Point\n\t// Returns the result of division of the current point by the given number.\n\tdivideBy(num) {\n\t\treturn new Point(this)._divideBy(num);\n\t}\n\n\t_divideBy(num) {\n\t\tthis.x /= num;\n\t\tthis.y /= num;\n\t\treturn this;\n\t}\n\n\t// @method multiplyBy(num: Number): Point\n\t// Returns the result of multiplication of the current point by the given number.\n\tmultiplyBy(num) {\n\t\treturn new Point(this)._multiplyBy(num);\n\t}\n\n\t_multiplyBy(num) {\n\t\tthis.x *= num;\n\t\tthis.y *= num;\n\t\treturn this;\n\t}\n\n\t// @method scaleBy(scale: Point): Point\n\t// Multiply each coordinate of the current point by each coordinate of\n\t// `scale`. In linear algebra terms, multiply the point by the\n\t// [scaling matrix](https://en.wikipedia.org/wiki/Scaling_%28geometry%29#Matrix_representation)\n\t// defined by `scale`.\n\tscaleBy(point) {\n\t\treturn new Point(this.x * point.x, this.y * point.y);\n\t}\n\n\t// @method unscaleBy(scale: Point): Point\n\t// Inverse of `scaleBy`. Divide each coordinate of the current point by\n\t// each coordinate of `scale`.\n\tunscaleBy(point) {\n\t\treturn new Point(this.x / point.x, this.y / point.y);\n\t}\n\n\t// Returns a copy of the current point with rounded coordinates.\n\tround() {\n\t\treturn new Point(this)._round();\n\t}\n\n\t_round() {\n\t\tthis.x = Math.round(this.x);\n\t\tthis.y = Math.round(this.y);\n\t\treturn this;\n\t}\n\n\t// @method floor(): Point\n\t// Returns a copy of the current point with floored coordinates (rounded down).\n\tfloor() {\n\t\treturn new Point(this)._floor();\n\t}\n\n\t_floor() {\n\t\tthis.x = Math.floor(this.x);\n\t\tthis.y = Math.floor(this.y);\n\t\treturn this;\n\t}\n\n\t// @method ceil(): Point\n\t// Returns a copy of the current point with ceiled coordinates (rounded up).\n\tceil() {\n\t\treturn new Point(this)._ceil();\n\t}\n\n\t_ceil() {\n\t\tthis.x = Math.ceil(this.x);\n\t\tthis.y = Math.ceil(this.y);\n\t\treturn this;\n\t}\n\n\t// Returns a copy of the current point with truncated coordinates (rounded towards zero).\n\ttrunc() {\n\t\treturn new Point(this)._trunc();\n\t}\n\n\t_trunc() {\n\t\tthis.x = Math.trunc(this.x);\n\t\tthis.y = Math.trunc(this.y);\n\t\treturn this;\n\t}\n\n\t// @method distanceTo(otherPoint: Point): Number\n\t// Returns the cartesian distance between the current and the given points.\n\tdistanceTo(point) {\n\t\tpoint = new Point(point);\n\n\t\tconst x = point.x - this.x,\n\t\ty = point.y - this.y;\n\n\t\treturn Math.sqrt(x * x + y * y);\n\t}\n\n\t// @method equals(otherPoint: Point): Boolean\n\t// Returns `true` if the given point has the same coordinates.\n\tequals(point) {\n\t\tpoint = new Point(point);\n\n\t\treturn point.x === this.x &&\n\t\t point.y === this.y;\n\t}\n\n\t// @method contains(otherPoint: Point): Boolean\n\t// Returns `true` if both coordinates of the given point are less than the corresponding current point coordinates (in absolute values).\n\tcontains(point) {\n\t\tpoint = new Point(point);\n\n\t\treturn Math.abs(point.x) <= Math.abs(this.x) &&\n\t\t Math.abs(point.y) <= Math.abs(this.y);\n\t}\n\n\t// @method toString(): String\n\t// Returns a string representation of the point for debugging purposes.\n\ttoString() {\n\t\treturn `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;\n\t}\n}\n"],"mappings":";;AAuCA,IAAa,QAAb,MAAa,MAAM;CAClB,YAAY,GAAG,GAAG,OAAO;EAGxB,IAAI,CADU,MAAM,SAAS,GAAG,CACvB,GACR,MAAM,IAAI,MAAM,0BAA0B,EAAE,IAAI,EAAE,EAAE;EAGrD,IAAI,IAAI;EACR,IAAI,aAAa,OAAO;GACvB,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO,IAAI,MAAM,QAAQ,CAAC,GAAG;GAC5B,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO,IAAI,OAAO,MAAM,YAAY,OAAO,KAAK,OAAO,GAAG;GACzD,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OA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EAAE;CACzD;AACD"}
@@ -0,0 +1,89 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ import { Point } from "./Point.js";
3
+ import { LatLngBounds } from "../geo/LatLngBounds.js";
4
+ import { LatLng } from "../geo/LatLng.js";
5
+ import { _getBitCode, _getEdgeIntersection, isFlat } from "./LineUtil.js";
6
+ //#region src/geometry/PolyUtil.js
7
+ var PolyUtil_exports = /* @__PURE__ */ __exportAll({
8
+ centroid: () => centroid,
9
+ clipPolygon: () => clipPolygon,
10
+ polygonCenter: () => polygonCenter
11
+ });
12
+ function clipPolygon(points, bounds, round) {
13
+ let clippedPoints, i, j, k, a, b, len, edge, p;
14
+ const edges = [
15
+ 1,
16
+ 4,
17
+ 2,
18
+ 8
19
+ ];
20
+ for (i = 0, len = points.length; i < len; i++) points[i]._code = _getBitCode(points[i], bounds);
21
+ for (k = 0; k < 4; k++) {
22
+ edge = edges[k];
23
+ clippedPoints = [];
24
+ for (i = 0, len = points.length, j = len - 1; i < len; j = i++) {
25
+ a = points[i];
26
+ b = points[j];
27
+ if (!(a._code & edge)) {
28
+ if (b._code & edge) {
29
+ p = _getEdgeIntersection(b, a, edge, bounds, round);
30
+ p._code = _getBitCode(p, bounds);
31
+ clippedPoints.push(p);
32
+ }
33
+ clippedPoints.push(a);
34
+ } else if (!(b._code & edge)) {
35
+ p = _getEdgeIntersection(b, a, edge, bounds, round);
36
+ p._code = _getBitCode(p, bounds);
37
+ clippedPoints.push(p);
38
+ }
39
+ }
40
+ points = clippedPoints;
41
+ }
42
+ return points;
43
+ }
44
+ function polygonCenter(latlngs, crs) {
45
+ let i, j, p1, p2, f, area, x, y, center;
46
+ if (!latlngs || latlngs.length === 0) throw new Error("latlngs not passed");
47
+ if (!isFlat(latlngs)) {
48
+ console.warn("latlngs are not flat! Only the first ring will be used");
49
+ latlngs = latlngs[0];
50
+ }
51
+ let centroidLatLng = new LatLng([0, 0]);
52
+ const bounds = new LatLngBounds(latlngs);
53
+ if (bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest()) < 1700) centroidLatLng = centroid(latlngs);
54
+ const len = latlngs.length;
55
+ const points = [];
56
+ for (i = 0; i < len; i++) {
57
+ const latlng = new LatLng(latlngs[i]);
58
+ points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
59
+ }
60
+ area = x = y = 0;
61
+ for (i = 0, j = len - 1; i < len; j = i++) {
62
+ p1 = points[i];
63
+ p2 = points[j];
64
+ f = p1.y * p2.x - p2.y * p1.x;
65
+ x += (p1.x + p2.x) * f;
66
+ y += (p1.y + p2.y) * f;
67
+ area += f * 3;
68
+ }
69
+ if (area === 0) center = points[0];
70
+ else center = [x / area, y / area];
71
+ const latlngCenter = crs.unproject(new Point(center));
72
+ return new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);
73
+ }
74
+ function centroid(coords) {
75
+ let latSum = 0;
76
+ let lngSum = 0;
77
+ let len = 0;
78
+ for (const coord of coords) {
79
+ const latlng = new LatLng(coord);
80
+ latSum += latlng.lat;
81
+ lngSum += latlng.lng;
82
+ len++;
83
+ }
84
+ return new LatLng([latSum / len, lngSum / len]);
85
+ }
86
+ //#endregion
87
+ export { PolyUtil_exports, centroid, clipPolygon, polygonCenter };
88
+
89
+ //# sourceMappingURL=PolyUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PolyUtil.js","names":["LineUtil._getBitCode","LineUtil._getEdgeIntersection","LineUtil.isFlat"],"sources":["../../../src/geometry/PolyUtil.js"],"sourcesContent":["import * as LineUtil from './LineUtil.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from './Point.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\n/*\n * @namespace PolyUtil\n * Various utility functions for polygon geometries.\n */\n\n/* @function clipPolygon(points: Point[], bounds: Bounds, round?: Boolean): Point[]\n * Clips the polygon geometry defined by the given `points` by the given bounds (using the [Sutherland-Hodgman algorithm](https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm)).\n * Used by Maplair to only show polygon points that are on the screen or near, increasing\n * performance. Note that polygon points needs different algorithm for clipping\n * than polyline, so there's a separate method for it.\n */\nexport function clipPolygon(points, bounds, round) {\n\tlet clippedPoints,\n\ti, j, k,\n\ta, b,\n\tlen, edge, p;\n\tconst edges = [1, 4, 2, 8];\n\n\tfor (i = 0, len = points.length; i < len; i++) {\n\t\tpoints[i]._code = LineUtil._getBitCode(points[i], bounds);\n\t}\n\n\t// for each edge (left, bottom, right, top)\n\tfor (k = 0; k < 4; k++) {\n\t\tedge = edges[k];\n\t\tclippedPoints = [];\n\n\t\tfor (i = 0, len = points.length, j = len - 1; i < len; j = i++) {\n\t\t\ta = points[i];\n\t\t\tb = points[j];\n\n\t\t\t// if a is inside the clip window\n\t\t\tif (!(a._code & edge)) {\n\t\t\t\t// if b is outside the clip window (a->b goes out of screen)\n\t\t\t\tif (b._code & edge) {\n\t\t\t\t\tp = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);\n\t\t\t\t\tp._code = LineUtil._getBitCode(p, bounds);\n\t\t\t\t\tclippedPoints.push(p);\n\t\t\t\t}\n\t\t\t\tclippedPoints.push(a);\n\n\t\t\t// else if b is inside the clip window (a->b enters the screen)\n\t\t\t} else if (!(b._code & edge)) {\n\t\t\t\tp = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);\n\t\t\t\tp._code = LineUtil._getBitCode(p, bounds);\n\t\t\t\tclippedPoints.push(p);\n\t\t\t}\n\t\t}\n\t\tpoints = clippedPoints;\n\t}\n\n\treturn points;\n}\n\n/* @function polygonCenter(latlngs: LatLng[], crs: CRS): LatLng\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed LatLngs (first ring) from a polygon.\n */\nexport function polygonCenter(latlngs, crs) {\n\tlet i, j, p1, p2, f, area, x, y, center;\n\n\tif (!latlngs || latlngs.length === 0) {\n\t\tthrow new Error('latlngs not passed');\n\t}\n\n\tif (!LineUtil.isFlat(latlngs)) {\n\t\tconsole.warn('latlngs are not flat! Only the first ring will be used');\n\t\tlatlngs = latlngs[0];\n\t}\n\n\tlet centroidLatLng = new LatLng([0, 0]);\n\n\tconst bounds = new LatLngBounds(latlngs);\n\tconst areaBounds = bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest());\n\t// tests showed that below 1700 rounding errors are happening\n\tif (areaBounds < 1700) {\n\t\t// getting a inexact center, to move the latlngs near to [0, 0] to prevent rounding errors\n\t\tcentroidLatLng = centroid(latlngs);\n\t}\n\n\tconst len = latlngs.length;\n\tconst points = [];\n\tfor (i = 0; i < len; i++) {\n\t\tconst latlng = new LatLng(latlngs[i]);\n\t\tpoints.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));\n\t}\n\n\tarea = x = y = 0;\n\n\t// polygon centroid algorithm;\n\tfor (i = 0, j = len - 1; i < len; j = i++) {\n\t\tp1 = points[i];\n\t\tp2 = points[j];\n\n\t\tf = p1.y * p2.x - p2.y * p1.x;\n\t\tx += (p1.x + p2.x) * f;\n\t\ty += (p1.y + p2.y) * f;\n\t\tarea += f * 3;\n\t}\n\n\tif (area === 0) {\n\t\t// Polygon is so small that all points are on same pixel.\n\t\tcenter = points[0];\n\t} else {\n\t\tcenter = [x / area, y / area];\n\t}\n\n\tconst latlngCenter = crs.unproject(new Point(center));\n\treturn new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);\n}\n\n/* @function centroid(latlngs: LatLng[]): LatLng\n * Returns the 'center of mass' of the passed LatLngs.\n */\nexport function centroid(coords) {\n\tlet latSum = 0;\n\tlet lngSum = 0;\n\tlet len = 0;\n\tfor (const coord of coords) {\n\t\tconst latlng = new LatLng(coord);\n\t\tlatSum += latlng.lat;\n\t\tlngSum += latlng.lng;\n\t\tlen++;\n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AC/C"}
@@ -0,0 +1,34 @@
1
+ import { Point } from "./Point.js";
2
+ //#region src/geometry/Transformation.js
3
+ var Transformation = class {
4
+ constructor(a, b, c, d) {
5
+ if (Array.isArray(a)) {
6
+ this._a = a[0];
7
+ this._b = a[1];
8
+ this._c = a[2];
9
+ this._d = a[3];
10
+ return;
11
+ }
12
+ this._a = a;
13
+ this._b = b;
14
+ this._c = c;
15
+ this._d = d;
16
+ }
17
+ transform(point, scale) {
18
+ return this._transform(new Point(point), scale);
19
+ }
20
+ _transform(point, scale) {
21
+ scale ||= 1;
22
+ point.x = scale * (this._a * point.x + this._b);
23
+ point.y = scale * (this._c * point.y + this._d);
24
+ return point;
25
+ }
26
+ untransform(point, scale) {
27
+ scale ||= 1;
28
+ return new Point((point.x / scale - this._b) / this._a, (point.y / scale - this._d) / this._c);
29
+ }
30
+ };
31
+ //#endregion
32
+ export { Transformation };
33
+
34
+ //# sourceMappingURL=Transformation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Transformation.js","names":[],"sources":["../../../src/geometry/Transformation.js"],"sourcesContent":["import {Point} from './Point.js';\n\n/*\n * @class Transformation\n *\n * Represents an affine transformation: a set of coefficients `a`, `b`, `c`, `d`\n * for transforming a point of a form `(x, y)` into `(a*x + b, c*y + d)` and doing\n * the reverse. Used by Maplair in its projections code.\n *\n * @example\n *\n * ```js\n * const transformation = new Transformation(2, 5, -1, 10),\n * \tp = new Point(1, 2),\n * \tp2 = transformation.transform(p), // new Point(7, 8)\n * \tp3 = transformation.untransform(p2); // new Point(1, 2)\n * ```\n */\n\n// @constructor Transformation(a: Number, b: Number, c: Number, d: Number)\n// Instantiates a Transformation object with the given coefficients.\n\n// @alternative\n// @constructor Transformation(coefficients: Array): Transformation\n// Expects an coefficients array of the form\n// `[a: Number, b: Number, c: Number, d: Number]`.\nexport class Transformation {\n\tconstructor(a, b, c, d) {\n\t\tif (Array.isArray(a)) {\n\t\t\t// use array properties\n\t\t\tthis._a = a[0];\n\t\t\tthis._b = a[1];\n\t\t\tthis._c = a[2];\n\t\t\tthis._d = a[3];\n\t\t\treturn;\n\t\t}\n\t\tthis._a = a;\n\t\tthis._b = b;\n\t\tthis._c = c;\n\t\tthis._d = d;\n\t}\n\n\t// @method transform(point: Point, scale?: Number): Point\n\t// Returns a transformed point, optionally multiplied by the given scale.\n\t// Only accepts actual `Point` instances, not arrays.\n\ttransform(point, scale) { // (Point, Number) -> Point\n\t\treturn this._transform(new Point(point), scale);\n\t}\n\n\t// destructive transform (faster)\n\t_transform(point, scale) {\n\t\tscale ||= 1;\n\t\tpoint.x = scale * (this._a * point.x + this._b);\n\t\tpoint.y = scale * (this._c * point.y + this._d);\n\t\treturn point;\n\t}\n\n\t// @method untransform(point: Point, scale?: Number): Point\n\t// Returns the reverse transformation of the given point, optionally divided\n\t// by the given scale. Only accepts actual `Point` instances, not arrays.\n\tuntransform(point, scale) {\n\t\tscale ||= 1;\n\t\treturn new Point(\n\t\t\t(point.x / scale - this._b) / this._a,\n\t\t\t(point.y / scale - this._d) / this._c);\n\t}\n}\n"],"mappings":";;AA0BA,IAAa,iBAAb,MAA4B;CAC3B,YAAY,GAAG,GAAG,GAAG,GAAG;EACvB,IAAI,MAAM,QAAQ,CAAC,GAAG;GAErB,KAAK,KAAK,EAAE;GACZ,KAAK,KAAK,EAAE;GACZ,KAAK,KAAK,EAAE;GACZ,KAAK,KAAK,EAAE;GACZ;EACD;EACA,KAAK,KAAK;EACV,KAAK,KAAK;EACV,KAAK,KAAK;EACV,KAAK,KAAK;CACX;CAKA,UAAU,OAAO,OAAO;EACvB,OAAO,KAAK,WAAW,IAAI,MAAM,KAAK,GAAG,KAAK;CAC/C;CAGA,WAAW,OAAO,OAAO;EACxB,UAAU;EACV,MAAM,IAAI,SAAS,KAAK,KAAK,MAAM,IAAI,KAAK;EAC5C,MAAM,IAAI,SAAS,KAAK,KAAK,MAAM,IAAI,KAAK;EAC5C,OAAO;CACR;CAKA,YAAY,OAAO,OAAO;EACzB,UAAU;EACV,OAAO,IAAI,OACT,MAAM,IAAI,QAAQ,KAAK,MAAM,KAAK,KAClC,MAAM,IAAI,QAAQ,KAAK,MAAM,KAAK,EAAE;CACvC;AACD"}
@@ -0,0 +1,87 @@
1
+ import { setOptions } from "../core/Util.js";
2
+ import { off } from "../dom/DomEvent.js";
3
+ import { create, setTransform } from "../dom/DomUtil.js";
4
+ import { Bounds } from "../geometry/Bounds.js";
5
+ import { Layer } from "./Layer.js";
6
+ //#region src/layer/BlanketOverlay.js
7
+ var BlanketOverlay = class BlanketOverlay extends Layer {
8
+ static {
9
+ this.setDefaultOptions({
10
+ padding: .1,
11
+ continuous: false
12
+ });
13
+ }
14
+ constructor(options) {
15
+ super();
16
+ setOptions(this, options);
17
+ this.callInitHooks(BlanketOverlay);
18
+ }
19
+ onAdd() {
20
+ if (!this._container) {
21
+ this._initContainer();
22
+ this._container.classList.add("maplair-zoom-animated");
23
+ }
24
+ this.getPane().appendChild(this._container);
25
+ this._resizeContainer();
26
+ this._onMoveEnd();
27
+ }
28
+ onRemove() {
29
+ this._destroyContainer();
30
+ }
31
+ getEvents() {
32
+ const events = {
33
+ viewreset: this._reset,
34
+ zoom: this._onZoom,
35
+ moveend: this._onMoveEnd,
36
+ resize: this._resizeContainer,
37
+ zoomend: this._onZoomEnd
38
+ };
39
+ if (this._zoomAnimated) events.zoomanim = this._onAnimZoom;
40
+ if (this.options.continuous) events.move = this._onMoveEnd;
41
+ return events;
42
+ }
43
+ _onAnimZoom(ev) {
44
+ this._updateTransform(ev.center, ev.zoom);
45
+ }
46
+ _onZoom() {
47
+ this._updateTransform(this._map.getCenter(), this._map.getZoom());
48
+ }
49
+ _updateTransform(center, zoom) {
50
+ const scale = this._map.getZoomScale(zoom, this._zoom), viewHalf = this._map.getSize().multiplyBy(.5 + this.options.padding), currentCenterPoint = this._map.project(this._center, zoom), topLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)._subtract(this._map._getNewPixelOrigin(center, zoom))._round();
51
+ setTransform(this._container, topLeftOffset, scale);
52
+ }
53
+ _onMoveEnd(ev) {
54
+ const p = this.options.padding, size = this._map.getSize(), min = this._map.containerPointToLayerPoint(size.multiplyBy(-p)).round();
55
+ this._bounds = new Bounds(min, min.add(size.multiplyBy(1 + p * 2)).round());
56
+ this._center = this._map.getCenter();
57
+ this._zoom = this._map.getZoom();
58
+ this._updateTransform(this._center, this._zoom);
59
+ this._onSettled(ev);
60
+ }
61
+ _reset() {
62
+ this._onSettled();
63
+ this._updateTransform(this._center, this._zoom);
64
+ this._onViewReset();
65
+ }
66
+ _initContainer() {
67
+ this._container = create("div");
68
+ }
69
+ _destroyContainer() {
70
+ off(this._container);
71
+ this._container.remove();
72
+ delete this._container;
73
+ }
74
+ _resizeContainer() {
75
+ const p = this.options.padding, size = this._map.getSize().multiplyBy(1 + p * 2).round();
76
+ this._container.style.width = `${size.x}px`;
77
+ this._container.style.height = `${size.y}px`;
78
+ return size;
79
+ }
80
+ _onZoomEnd() {}
81
+ _onViewReset() {}
82
+ _onSettled() {}
83
+ };
84
+ //#endregion
85
+ export { BlanketOverlay };
86
+
87
+ //# sourceMappingURL=BlanketOverlay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlanketOverlay.js","names":["DomUtil.create"],"sources":["../../../src/layer/BlanketOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Bounds} from '../geometry/Bounds.js';\n\n/*\n * @class BlanketOverlay\n * @inherits Layer\n *\n * Represents an HTML element that covers (\"blankets\") the entire surface\n * of the map.\n *\n * Do not use this class directly. It's meant for `Renderer`, and for plugins\n * that rely on one single HTML element\n */\n\nexport class BlanketOverlay extends Layer {\n\n\tstatic {\n\t\t// @section\n\t\t// @aka BlanketOverlay options\n\t\tthis.setDefaultOptions({\n\t\t\t// @option padding: Number = 0.1\n\t\t\t// How much to extend the clip area around the map view (relative to its size)\n\t\t\t// e.g. 0.1 would be 10% of map view in each direction\n\t\t\tpadding: 0.1,\n\n\t\t\t// @option continuous: Boolean = false\n\t\t\t// When `false`, the blanket will update its position only when the\n\t\t\t// map state settles (*after* a pan/zoom animation). When `true`,\n\t\t\t// it will update when the map state changes (*during* pan/zoom\n\t\t\t// animations)\n\t\t\tcontinuous: false,\n\t\t});\n\t}\n\n\tconstructor(options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(BlanketOverlay);\n\t}\n\n\tonAdd() {\n\t\tif (!this._container) {\n\t\t\tthis._initContainer(); // defined by renderer implementations\n\n\t\t\t// always keep transform-origin as 0 0, #8794\n\t\t\tthis._container.classList.add('maplair-zoom-animated');\n\t\t}\n\n\t\tthis.getPane().appendChild(this._container);\n\t\tthis._resizeContainer();\n\t\tthis._onMoveEnd();\n\t}\n\n\tonRemove() {\n\t\tthis._destroyContainer();\n\t}\n\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tviewreset: this._reset,\n\t\t\tzoom: this._onZoom,\n\t\t\tmoveend: this._onMoveEnd,\n\t\t\tresize: this._resizeContainer,\n\t\t\tzoomend: this._onZoomEnd\n\t\t};\n\t\tif (this._zoomAnimated) {\n\t\t\tevents.zoomanim = this._onAnimZoom;\n\t\t}\n\t\tif (this.options.continuous) {\n\t\t\tevents.move = this._onMoveEnd;\n\t\t}\n\t\treturn events;\n\t}\n\n\t_onAnimZoom(ev) {\n\t\tthis._updateTransform(ev.center, ev.zoom);\n\t}\n\n\t_onZoom() {\n\t\tthis._updateTransform(this._map.getCenter(), this._map.getZoom());\n\t}\n\n\t_updateTransform(center, zoom) {\n\t\tconst scale = this._map.getZoomScale(zoom, this._zoom),\n\t\tviewHalf = this._map.getSize().multiplyBy(0.5 + this.options.padding),\n\t\tcurrentCenterPoint = this._map.project(this._center, zoom),\n\t\ttopLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)\n\t\t\t._subtract(this._map._getNewPixelOrigin(center, zoom))\n\t\t\t._round();\n\n\t\tDomUtil.setTransform(this._container, topLeftOffset, scale);\n\t}\n\n\t_onMoveEnd(ev) {\n\t\t// Update pixel bounds of renderer container (for positioning/sizing/clipping later)\n\t\tconst p = this.options.padding,\n\t\tsize = this._map.getSize(),\n\t\tmin = this._map.containerPointToLayerPoint(size.multiplyBy(-p)).round();\n\n\t\tthis._bounds = new Bounds(min, min.add(size.multiplyBy(1 + p * 2)).round());\n\n\t\tthis._center = this._map.getCenter();\n\t\tthis._zoom = this._map.getZoom();\n\t\tthis._updateTransform(this._center, this._zoom);\n\n\t\tthis._onSettled(ev);\n\t}\n\n\t_reset() {\n\t\tthis._onSettled();\n\t\tthis._updateTransform(this._center, this._zoom);\n\t\tthis._onViewReset();\n\t}\n\n\t/*\n\t * @section Subclass interface\n\t * @uninheritable\n\t * Subclasses must define the following methods:\n\t *\n\t * @method _initContainer(): undefined\n\t * Must initialize the HTML element to use as blanket, and store it as\n\t * `this._container`. The base implementation creates a blank `<div>`\n\t *\n\t * @method _destroyContainer(): undefined\n\t * Must destroy the HTML element in `this._container` and free any other\n\t * resources. The base implementation destroys the element and removes\n\t * any event handlers attached to it.\n\t *\n\t * @method _resizeContainer(): Point\n\t * The base implementation resizes the container (based on the map's size\n\t * and taking into account the padding), returning the new size in CSS pixels.\n\t *\n\t * Subclass implementations shall reset container parameters and data\n\t * structures as needed.\n\t *\n\t * @method _onZoomEnd(ev?: PointerEvent): undefined\n\t * (Optional) Runs on the map's `zoomend` event.\n\t *\n\t * @method _onViewReset(ev?: PointerEvent): undefined\n\t * (Optional) Runs on the map's `viewreset` event.\n\t *\n\t * @method _onSettled(): undefined\n\t * Runs whenever the map state settles after changing (at the end of pan/zoom\n\t * animations, etc). This should trigger the bulk of any rendering logic.\n\t *\n\t * If the `continuous` option is set to `true`, then this also runs on\n\t * any map state change (including *during* pan/zoom animations).\n\t */\n\t_initContainer() {\n\t\tthis._container = DomUtil.create('div');\n\t}\n\t_destroyContainer() {\n\t\tDomEvent.off(this._container);\n\t\tthis._container.remove();\n\t\tdelete this._container;\n\t}\n\t_resizeContainer() {\n\t\tconst p = this.options.padding,\n\t\tsize = this._map.getSize().multiplyBy(1 + p * 2).round();\n\t\tthis._container.style.width = `${size.x}px`;\n\t\tthis._container.style.height = `${size.y}px`;\n\t\treturn size;\n\t}\n\t_onZoomEnd() {}\n\t_onViewReset() {}\n\t_onSettled() {}\n}\n"],"mappings":";;;;;;AAiBA,IAAa,iBAAb,MAAa,uBAAuB,MAAM;CAEzC;EAGC,KAAK,kBAAkB;GAItB,SAAS;GAOT,YAAY;EACb,CAAC;CACF;CAEA,YAAY,SAAS;EACpB,MAAM;EACN,WAAgB,MAAM,OAAO;EAE7B,KAAK,cAAc,cAAc;CAClC;CAEA,QAAQ;EACP,IAAI,CAAC,KAAK,YAAY;GACrB,KAAK,eAAe;GAGpB,KAAK,WAAW,UAAU,IAAI,uBAAuB;EACtD;EAEA,KAAK,QAAQ,CAAC,CAAC,YAAY,KAAK,UAAU;EAC1C,KAAK,iBAAiB;EACtB,KAAK,WAAW;CACjB;CAEA,WAAW;EACV,KAAK,kBAAkB;CACxB;CAEA,YAAY;EACX,MAAM,SAAS;GACd,WAAW,KAAK;GAChB,MAAM,KAAK;GACX,SAAS,KAAK;GACd,QAAQ,KAAK;GACb,SAAS,KAAK;EACf;EACA,IAAI,KAAK,eACR,OAAO,WAAW,KAAK;EAExB,IAAI,KAAK,QAAQ,YAChB,OAAO,OAAO,KAAK;EAEpB,OAAO;CACR;CAEA,YAAY,IAAI;EACf,KAAK,iBAAiB,GAAG,QAAQ,GAAG,IAAI;CACzC;CAEA,UAAU;EACT,KAAK,iBAAiB,KAAK,KAAK,UAAU,GAAG,KAAK,KAAK,QAAQ,CAAC;CACjE;CAEA,iBAAiB,QAAQ,MAAM;EAC9B,MAAM,QAAQ,KAAK,KAAK,aAAa,MAAM,KAAK,KAAK,GACrD,WAAW,KAAK,KAAK,QAAQ,CAAC,CAAC,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