maplair 4.0.0-alpha.2 → 4.0.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 (82) hide show
  1. package/CHANGELOG.md +22 -38
  2. package/LICENSE +1 -1
  3. package/README.md +10 -9
  4. package/dist/esm/control/SearchControl.js +1 -1
  5. package/dist/esm/control/SearchControl.js.map +1 -1
  6. package/dist/esm/geo/LatLng.js +20 -2
  7. package/dist/esm/geo/LatLng.js.map +1 -1
  8. package/dist/esm/geo/LatLngBounds.js +19 -7
  9. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  10. package/dist/esm/geo/crs/CRS.js +4 -3
  11. package/dist/esm/geo/crs/CRS.js.map +1 -1
  12. package/dist/esm/geo/projection/Projection.LonLat.js +2 -2
  13. package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
  14. package/dist/esm/geo/projection/Projection.Mercator.js +2 -2
  15. package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
  16. package/dist/esm/geo/projection/Projection.SphericalMercator.js +2 -2
  17. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
  18. package/dist/esm/geometry/Bounds.js +19 -7
  19. package/dist/esm/geometry/Bounds.js.map +1 -1
  20. package/dist/esm/geometry/Point.js +23 -5
  21. package/dist/esm/geometry/Point.js.map +1 -1
  22. package/dist/esm/geometry/PolyUtil.js +1 -1
  23. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  24. package/dist/esm/layer/DivOverlay.js +1 -1
  25. package/dist/esm/layer/DivOverlay.js.map +1 -1
  26. package/dist/esm/layer/GeoJSON.js +1 -1
  27. package/dist/esm/layer/GeoJSON.js.map +1 -1
  28. package/dist/esm/layer/Popup.js +1 -1
  29. package/dist/esm/layer/Popup.js.map +1 -1
  30. package/dist/esm/layer/marker/DivIcon.js +1 -1
  31. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  32. package/dist/esm/layer/marker/Icon.js +2 -2
  33. package/dist/esm/layer/marker/Icon.js.map +1 -1
  34. package/dist/esm/layer/marker/Marker.Move.js +1 -1
  35. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  36. package/dist/esm/layer/marker/Marker.js +2 -2
  37. package/dist/esm/layer/marker/Marker.js.map +1 -1
  38. package/dist/esm/layer/tile/GridLayer.js +1 -1
  39. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  40. package/dist/esm/layer/vector/Polyline.js +1 -1
  41. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  42. package/dist/esm/map/Map.Rotation.js +5 -5
  43. package/dist/esm/map/Map.Rotation.js.map +1 -1
  44. package/dist/esm/map/Map.js +19 -19
  45. package/dist/esm/map/Map.js.map +1 -1
  46. package/dist/esm/map/handler/DragHandler.js +1 -1
  47. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  48. package/dist/esm/map/handler/KeyboardHandler.js +2 -2
  49. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  50. package/dist/esm/package.js +1 -1
  51. package/dist/maplair-global-src.js +134 -73
  52. package/dist/maplair-global-src.js.map +1 -1
  53. package/dist/maplair-global.js +3 -3
  54. package/dist/maplair-global.js.map +1 -1
  55. package/dist/maplair-src.js +134 -73
  56. package/dist/maplair-src.js.map +1 -1
  57. package/dist/maplair.js +3 -3
  58. package/dist/maplair.js.map +1 -1
  59. package/package.json +4 -4
  60. package/src/control/SearchControl.js +2 -2
  61. package/src/geo/LatLng.js +21 -2
  62. package/src/geo/LatLngBounds.js +20 -7
  63. package/src/geo/crs/CRS.js +4 -3
  64. package/src/geo/projection/Projection.LonLat.js +2 -2
  65. package/src/geo/projection/Projection.Mercator.js +2 -2
  66. package/src/geo/projection/Projection.SphericalMercator.js +2 -2
  67. package/src/geometry/Bounds.js +20 -7
  68. package/src/geometry/Point.js +24 -5
  69. package/src/geometry/PolyUtil.js +1 -1
  70. package/src/layer/DivOverlay.js +1 -1
  71. package/src/layer/GeoJSON.js +1 -1
  72. package/src/layer/Popup.js +3 -3
  73. package/src/layer/marker/DivIcon.js +1 -1
  74. package/src/layer/marker/Icon.js +2 -2
  75. package/src/layer/marker/Marker.Move.js +1 -1
  76. package/src/layer/marker/Marker.js +2 -2
  77. package/src/layer/tile/GridLayer.js +1 -1
  78. package/src/layer/vector/Polyline.js +1 -1
  79. package/src/map/Map.Rotation.js +7 -7
  80. package/src/map/Map.js +21 -21
  81. package/src/map/handler/DragHandler.js +1 -1
  82. package/src/map/handler/KeyboardHandler.js +2 -2
@@ -12,11 +12,11 @@ import { LatLng } from "../LatLng.js";
12
12
  */
13
13
  const LonLat = {
14
14
  project(latlng) {
15
- latlng = new LatLng(latlng);
15
+ latlng = LatLng.from(latlng);
16
16
  return new Point(latlng.lng, latlng.lat);
17
17
  },
18
18
  unproject(point) {
19
- point = new Point(point);
19
+ point = Point.from(point);
20
20
  return new LatLng(point.y, point.x);
21
21
  },
22
22
  bounds: new Bounds([-180, -90], [180, 90])
@@ -1 +1 @@
1
- {"version":3,"file":"Projection.LonLat.js","names":[],"sources":["../../../../src/geo/projection/Projection.LonLat.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\n/**\n * Equirectangular, or Plate Carree projection — the most simple projection,\n * mostly used by GIS enthusiasts. Directly maps `x` as longitude, and `y` as\n * latitude. Also suitable for flat worlds, e.g. game maps. Used by the\n * `EPSG4326` and `SimpleCRS` CRS.\n * @type {Projection}\n */\nexport const LonLat = {\n\tproject(latlng) {\n\t\tlatlng = new LatLng(latlng);\n\t\treturn new Point(latlng.lng, latlng.lat);\n\t},\n\n\tunproject(point) {\n\t\tpoint = new Point(point);\n\t\treturn new LatLng(point.y, point.x);\n\t},\n\n\tbounds: new Bounds([-180, -90], [180, 90])\n};\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,SAAS;CACrB,QAAQ,QAAQ;EACf,SAAS,IAAI,OAAO,MAAM;EAC1B,OAAO,IAAI,MAAM,OAAO,KAAK,OAAO,GAAG;CACxC;CAEA,UAAU,OAAO;EAChB,QAAQ,IAAI,MAAM,KAAK;EACvB,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,CAAC;CACnC;CAEA,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;AAC1C"}
1
+ {"version":3,"file":"Projection.LonLat.js","names":[],"sources":["../../../../src/geo/projection/Projection.LonLat.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\n/**\n * Equirectangular, or Plate Carree projection — the most simple projection,\n * mostly used by GIS enthusiasts. Directly maps `x` as longitude, and `y` as\n * latitude. Also suitable for flat worlds, e.g. game maps. Used by the\n * `EPSG4326` and `SimpleCRS` CRS.\n * @type {Projection}\n */\nexport const LonLat = {\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\treturn new Point(latlng.lng, latlng.lat);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\treturn new LatLng(point.y, point.x);\n\t},\n\n\tbounds: new Bounds([-180, -90], [180, 90])\n};\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,SAAS;CACrB,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,OAAO,IAAI,MAAM,OAAO,KAAK,OAAO,GAAG;CACxC;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,CAAC;CACnC;CAEA,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;AAC1C"}
@@ -11,7 +11,7 @@ const Mercator = {
11
11
  R_MINOR: 6356752.314245179,
12
12
  bounds: new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),
13
13
  project(latlng) {
14
- latlng = new LatLng(latlng);
14
+ latlng = LatLng.from(latlng);
15
15
  const d = Math.PI / 180, r = this.R, tmp = this.R_MINOR / r, e = Math.sqrt(1 - tmp * tmp);
16
16
  let y = latlng.lat * d;
17
17
  const con = e * Math.sin(y);
@@ -20,7 +20,7 @@ const Mercator = {
20
20
  return new Point(latlng.lng * d * r, y);
21
21
  },
22
22
  unproject(point) {
23
- point = new Point(point);
23
+ point = Point.from(point);
24
24
  const d = 180 / Math.PI, r = this.R, tmp = this.R_MINOR / r, e = Math.sqrt(1 - tmp * tmp), ts = Math.exp(-point.y / r);
25
25
  let phi = Math.PI / 2 - 2 * Math.atan(ts);
26
26
  for (let i = 0, dphi = .1, con; i < 15 && Math.abs(dphi) > 1e-7; i++) {
@@ -1 +1 @@
1
- {"version":3,"file":"Projection.Mercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.Mercator.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Elliptical Mercator projection — more complex than Spherical Mercator. Assumes that\n * Earth is an ellipsoid. Used by the EPSG:3395 CRS.\n * @type {Projection & {R: number, R_MINOR: number}}\n */\nexport const Mercator = {\n\tR: earthRadius,\n\tR_MINOR: 6356752.314245179,\n\n\tbounds: new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),\n\n\tproject(latlng) {\n\t\tlatlng = new LatLng(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp);\n\t\tlet y = latlng.lat * d;\n\t\tconst con = e * Math.sin(y);\n\n\t\tconst ts = Math.tan(Math.PI / 4 - y / 2) / ((1 - con) / (1 + con)) ** (e / 2);\n\t\ty = -r * Math.log(Math.max(ts, 1E-10));\n\n\t\treturn new Point(latlng.lng * d * r, y);\n\t},\n\n\tunproject(point) {\n\t\tpoint = new Point(point);\n\t\tconst d = 180 / Math.PI,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp),\n\t\tts = Math.exp(-point.y / r);\n\t\tlet phi = Math.PI / 2 - 2 * Math.atan(ts);\n\n\t\tfor (let i = 0, dphi = 0.1, con; i < 15 && Math.abs(dphi) > 1e-7; i++) {\n\t\t\tcon = e * Math.sin(phi);\n\t\t\tcon = ((1 - con) / (1 + con)) ** (e / 2);\n\t\t\tdphi = Math.PI / 2 - 2 * Math.atan(ts * con) - phi;\n\t\t\tphi += dphi;\n\t\t}\n\n\t\treturn new LatLng(phi * d, point.x * d / r);\n\t}\n};\n"],"mappings":";;;;;;;;AAaA,MAAa,WAAW;CACvB,GAAG;CACH,SAAS;CAET,QAAQ,IAAI,OAAO,CAAC,iBAAiB,eAAe,GAAG,CAAC,gBAAgB,cAAc,CAAC;CAEvF,QAAQ,QAAQ;EACf,SAAS,IAAI,OAAO,MAAM;EAC1B,MAAM,IAAI,KAAK,KAAK,KACpB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG;EAC3B,IAAI,IAAI,OAAO,MAAM;EACrB,MAAM,MAAM,IAAI,KAAK,IAAI,CAAC;EAE1B,MAAM,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ,IAAI,UAAU,IAAI;EAC3E,IAAI,CAAC,IAAI,KAAK,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC;EAErC,OAAO,IAAI,MAAM,OAAO,MAAM,IAAI,GAAG,CAAC;CACvC;CAEA,UAAU,OAAO;EAChB,QAAQ,IAAI,MAAM,KAAK;EACvB,MAAM,IAAI,MAAM,KAAK,IACrB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG,GAC3B,KAAK,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC;EAC1B,IAAI,MAAM,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE;EAExC,KAAK,IAAI,IAAI,GAAG,OAAO,IAAK,KAAK,IAAI,MAAM,KAAK,IAAI,IAAI,IAAI,MAAM,KAAK;GACtE,MAAM,IAAI,KAAK,IAAI,GAAG;GACtB,QAAQ,IAAI,QAAQ,IAAI,UAAU,IAAI;GACtC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,GAAG,IAAI;GAC/C,OAAO;EACR;EAEA,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;CAC3C;AACD"}
1
+ {"version":3,"file":"Projection.Mercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.Mercator.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Elliptical Mercator projection — more complex than Spherical Mercator. Assumes that\n * Earth is an ellipsoid. Used by the EPSG:3395 CRS.\n * @type {Projection & {R: number, R_MINOR: number}}\n */\nexport const Mercator = {\n\tR: earthRadius,\n\tR_MINOR: 6356752.314245179,\n\n\tbounds: new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),\n\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp);\n\t\tlet y = latlng.lat * d;\n\t\tconst con = e * Math.sin(y);\n\n\t\tconst ts = Math.tan(Math.PI / 4 - y / 2) / ((1 - con) / (1 + con)) ** (e / 2);\n\t\ty = -r * Math.log(Math.max(ts, 1E-10));\n\n\t\treturn new Point(latlng.lng * d * r, y);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\tconst d = 180 / Math.PI,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp),\n\t\tts = Math.exp(-point.y / r);\n\t\tlet phi = Math.PI / 2 - 2 * Math.atan(ts);\n\n\t\tfor (let i = 0, dphi = 0.1, con; i < 15 && Math.abs(dphi) > 1e-7; i++) {\n\t\t\tcon = e * Math.sin(phi);\n\t\t\tcon = ((1 - con) / (1 + con)) ** (e / 2);\n\t\t\tdphi = Math.PI / 2 - 2 * Math.atan(ts * con) - phi;\n\t\t\tphi += dphi;\n\t\t}\n\n\t\treturn new LatLng(phi * d, point.x * d / r);\n\t}\n};\n"],"mappings":";;;;;;;;AAaA,MAAa,WAAW;CACvB,GAAG;CACH,SAAS;CAET,QAAQ,IAAI,OAAO,CAAC,iBAAiB,eAAe,GAAG,CAAC,gBAAgB,cAAc,CAAC;CAEvF,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,MAAM,IAAI,KAAK,KAAK,KACpB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG;EAC3B,IAAI,IAAI,OAAO,MAAM;EACrB,MAAM,MAAM,IAAI,KAAK,IAAI,CAAC;EAE1B,MAAM,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ,IAAI,UAAU,IAAI;EAC3E,IAAI,CAAC,IAAI,KAAK,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC;EAErC,OAAO,IAAI,MAAM,OAAO,MAAM,IAAI,GAAG,CAAC;CACvC;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,MAAM,IAAI,MAAM,KAAK,IACrB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG,GAC3B,KAAK,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC;EAC1B,IAAI,MAAM,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE;EAExC,KAAK,IAAI,IAAI,GAAG,OAAO,IAAK,KAAK,IAAI,MAAM,KAAK,IAAI,IAAI,IAAI,MAAM,KAAK;GACtE,MAAM,IAAI,KAAK,IAAI,GAAG;GACtB,QAAQ,IAAI,QAAQ,IAAI,UAAU,IAAI;GACtC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,GAAG,IAAI;GAC/C,OAAO;EACR;EAEA,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;CAC3C;AACD"}
@@ -14,12 +14,12 @@ const SphericalMercator = {
14
14
  R: earthRadius,
15
15
  MAX_LATITUDE: 85.0511287798,
16
16
  project(latlng) {
17
- latlng = new LatLng(latlng);
17
+ latlng = LatLng.from(latlng);
18
18
  const d = Math.PI / 180, max = this.MAX_LATITUDE, lat = Math.max(Math.min(max, latlng.lat), -max), sin = Math.sin(lat * d);
19
19
  return new Point(this.R * latlng.lng * d, this.R * Math.log((1 + sin) / (1 - sin)) / 2);
20
20
  },
21
21
  unproject(point) {
22
- point = new Point(point);
22
+ point = Point.from(point);
23
23
  const d = 180 / Math.PI;
24
24
  return new LatLng((2 * Math.atan(Math.exp(point.y / this.R)) - Math.PI / 2) * d, point.x * d / this.R);
25
25
  },
@@ -1 +1 @@
1
- {"version":3,"file":"Projection.SphericalMercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.SphericalMercator.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Spherical Mercator projection — the most common projection for online maps,\n * used by almost all free and commercial tile providers. Assumes that Earth is\n * a sphere. Used by the `EPSG:3857` CRS.\n * @type {Projection & {R: number, MAX_LATITUDE: number}}\n */\nexport const SphericalMercator = {\n\n\tR: earthRadius,\n\tMAX_LATITUDE: 85.0511287798,\n\n\tproject(latlng) {\n\t\tlatlng = new LatLng(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tmax = this.MAX_LATITUDE,\n\t\tlat = Math.max(Math.min(max, latlng.lat), -max),\n\t\tsin = Math.sin(lat * d);\n\n\t\treturn new Point(\n\t\t\tthis.R * latlng.lng * d,\n\t\t\tthis.R * Math.log((1 + sin) / (1 - sin)) / 2);\n\t},\n\n\tunproject(point) {\n\t\tpoint = new Point(point);\n\t\tconst d = 180 / Math.PI;\n\n\t\treturn new LatLng(\n\t\t\t(2 * Math.atan(Math.exp(point.y / this.R)) - (Math.PI / 2)) * d,\n\t\t\tpoint.x * d / this.R);\n\t},\n\n\tbounds: (() => {\n\t\tconst d = earthRadius * Math.PI;\n\t\treturn new Bounds([-d, -d], [d, d]);\n\t})()\n};\n"],"mappings":";;;;;AAMA,MAAM,cAAc;;;;;;;AAQpB,MAAa,oBAAoB;CAEhC,GAAG;CACH,cAAc;CAEd,QAAQ,QAAQ;EACf,SAAS,IAAI,OAAO,MAAM;EAC1B,MAAM,IAAI,KAAK,KAAK,KACpB,MAAM,KAAK,cACX,MAAM,KAAK,IAAI,KAAK,IAAI,KAAK,OAAO,GAAG,GAAG,CAAC,GAAG,GAC9C,MAAM,KAAK,IAAI,MAAM,CAAC;EAEtB,OAAO,IAAI,MACV,KAAK,IAAI,OAAO,MAAM,GACtB,KAAK,IAAI,KAAK,KAAK,IAAI,QAAQ,IAAI,IAAI,IAAI,CAAC;CAC9C;CAEA,UAAU,OAAO;EAChB,QAAQ,IAAI,MAAM,KAAK;EACvB,MAAM,IAAI,MAAM,KAAK;EAErB,OAAO,IAAI,QACT,IAAI,KAAK,KAAK,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,IAAK,KAAK,KAAK,KAAM,GAC9D,MAAM,IAAI,IAAI,KAAK,CAAC;CACtB;CAEA,eAAe;EACd,MAAM,IAAI,cAAc,KAAK;EAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACnC,EAAA,CAAG;AACJ"}
1
+ {"version":3,"file":"Projection.SphericalMercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.SphericalMercator.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Spherical Mercator projection — the most common projection for online maps,\n * used by almost all free and commercial tile providers. Assumes that Earth is\n * a sphere. Used by the `EPSG:3857` CRS.\n * @type {Projection & {R: number, MAX_LATITUDE: number}}\n */\nexport const SphericalMercator = {\n\n\tR: earthRadius,\n\tMAX_LATITUDE: 85.0511287798,\n\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tmax = this.MAX_LATITUDE,\n\t\tlat = Math.max(Math.min(max, latlng.lat), -max),\n\t\tsin = Math.sin(lat * d);\n\n\t\treturn new Point(\n\t\t\tthis.R * latlng.lng * d,\n\t\t\tthis.R * Math.log((1 + sin) / (1 - sin)) / 2);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\tconst d = 180 / Math.PI;\n\n\t\treturn new LatLng(\n\t\t\t(2 * Math.atan(Math.exp(point.y / this.R)) - (Math.PI / 2)) * d,\n\t\t\tpoint.x * d / this.R);\n\t},\n\n\tbounds: (() => {\n\t\tconst d = earthRadius * Math.PI;\n\t\treturn new Bounds([-d, -d], [d, d]);\n\t})()\n};\n"],"mappings":";;;;;AAMA,MAAM,cAAc;;;;;;;AAQpB,MAAa,oBAAoB;CAEhC,GAAG;CACH,cAAc;CAEd,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,MAAM,IAAI,KAAK,KAAK,KACpB,MAAM,KAAK,cACX,MAAM,KAAK,IAAI,KAAK,IAAI,KAAK,OAAO,GAAG,GAAG,CAAC,GAAG,GAC9C,MAAM,KAAK,IAAI,MAAM,CAAC;EAEtB,OAAO,IAAI,MACV,KAAK,IAAI,OAAO,MAAM,GACtB,KAAK,IAAI,KAAK,KAAK,IAAI,QAAQ,IAAI,IAAI,IAAI,CAAC;CAC9C;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,MAAM,IAAI,MAAM,KAAK;EAErB,OAAO,IAAI,QACT,IAAI,KAAK,KAAK,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,IAAK,KAAK,KAAK,KAAM,GAC9D,MAAM,IAAI,IAAI,KAAK,CAAC;CACtB;CAEA,eAAe;EACd,MAAM,IAAI,cAAc,KAAK;EAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACnC,EAAA,CAAG;AACJ"}
@@ -57,6 +57,18 @@ var Bounds = class Bounds {
57
57
  for (const point of points) this.extend(point);
58
58
  }
59
59
  /**
60
+ * Returns the given `Bounds` object as it is, or else a new `Bounds` object created
61
+ * from the given arguments (the same as of the constructor) — unlike the
62
+ * constructor, which always creates a new object.
63
+ * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the
64
+ * bounds.
65
+ * @param {PointExpression} [b] The opposite corner.
66
+ * @returns {Bounds}
67
+ */
68
+ static from(a, b) {
69
+ return a instanceof Bounds ? a : new Bounds(a, b);
70
+ }
71
+ /**
60
72
  * Extends the bounds to contain the given point or bounds.
61
73
  * @param {PointExpression|BoundsExpression} obj
62
74
  * @returns {this}
@@ -64,9 +76,9 @@ var Bounds = class Bounds {
64
76
  extend(obj) {
65
77
  let min2, max2;
66
78
  if (!obj) return this;
67
- if (obj instanceof Point || typeof obj[0] === "number" || "x" in obj) min2 = max2 = new Point(obj);
79
+ if (obj instanceof Point || typeof obj[0] === "number" || "x" in obj) min2 = max2 = Point.from(obj);
68
80
  else {
69
- obj = new Bounds(obj);
81
+ obj = Bounds.from(obj);
70
82
  min2 = obj.min;
71
83
  max2 = obj.max;
72
84
  if (!min2 || !max2) return this;
@@ -132,8 +144,8 @@ var Bounds = class Bounds {
132
144
  */
133
145
  contains(obj) {
134
146
  let min, max;
135
- if (typeof obj[0] === "number" || obj instanceof Point) obj = new Point(obj);
136
- else obj = new Bounds(obj);
147
+ if (typeof obj[0] === "number" || obj instanceof Point) obj = Point.from(obj);
148
+ else obj = Bounds.from(obj);
137
149
  if (obj instanceof Bounds) {
138
150
  min = obj.min;
139
151
  max = obj.max;
@@ -147,7 +159,7 @@ var Bounds = class Bounds {
147
159
  * @returns {boolean}
148
160
  */
149
161
  intersects(bounds) {
150
- bounds = new Bounds(bounds);
162
+ bounds = Bounds.from(bounds);
151
163
  const min = this.min, max = this.max, min2 = bounds.min, max2 = bounds.max, xIntersects = max2.x >= min.x && min2.x <= max.x, yIntersects = max2.y >= min.y && min2.y <= max.y;
152
164
  return xIntersects && yIntersects;
153
165
  }
@@ -158,7 +170,7 @@ var Bounds = class Bounds {
158
170
  * @returns {boolean}
159
171
  */
160
172
  overlaps(bounds) {
161
- bounds = new Bounds(bounds);
173
+ bounds = Bounds.from(bounds);
162
174
  const min = this.min, max = this.max, min2 = bounds.min, max2 = bounds.max, xOverlaps = max2.x > min.x && min2.x < max.x, yOverlaps = max2.y > min.y && min2.y < max.y;
163
175
  return xOverlaps && yOverlaps;
164
176
  }
@@ -187,7 +199,7 @@ var Bounds = class Bounds {
187
199
  */
188
200
  equals(bounds) {
189
201
  if (!bounds) return false;
190
- bounds = new Bounds(bounds);
202
+ bounds = Bounds.from(bounds);
191
203
  return this.min.equals(bounds.getTopLeft()) && this.max.equals(bounds.getBottomRight());
192
204
  }
193
205
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Bounds.js","names":[],"sources":["../../../src/geometry/Bounds.js"],"sourcesContent":["import {Point} from './Point.js';\n/** @import {PointExpression} from './Point.js' */\n\n/**\n * A rectangular area in pixel coordinates: a `Bounds`, or an array of points (usually\n * two diagonally opposite corners), e.g. `[[10, 10], [40, 60]]`. Accepted by all\n * Maplair methods which accept `Bounds` objects (unless noted otherwise).\n * @typedef {Bounds|PointExpression[]} BoundsExpression\n */\n\n/**\n * Represents a rectangular area in pixel coordinates.\n *\n * @example\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\n * 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 */\nexport class Bounds {\n\t/**\n\t * Creates a Bounds object from two corners coordinate pairs. Alternatively, creates a\n\t * Bounds object from the given array of points, or a copy of the given Bounds object.\n\t * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the\n\t * bounds to copy.\n\t * @param {PointExpression} [b] The opposite corner.\n\t */\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\t/**\n\t\t\t\t * The top left corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\n\t\t\t\tthis.min = new Point(a.min);\n\t\t\t\t/**\n\t\t\t\t * The bottom right corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\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/**\n\t * Extends the bounds to contain the given point or bounds.\n\t * @param {PointExpression|BoundsExpression} obj\n\t * @returns {this}\n\t */\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\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/**\n\t * Returns the center point of the bounds.\n\t * @param {boolean} [round]\n\t * @returns {Point}\n\t */\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/**\n\t * Returns the bottom-left point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetBottomLeft() {\n\t\treturn new Point(this.min.x, this.max.y);\n\t}\n\n\t/**\n\t * Returns the top-right point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetTopRight() { // -> Point\n\t\treturn new Point(this.max.x, this.min.y);\n\t}\n\n\t/**\n\t * Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-min)).\n\t * @returns {Point}\n\t */\n\tgetTopLeft() {\n\t\treturn this.min; // left, top\n\t}\n\n\t/**\n\t * Returns the bottom-right point of the bounds (i.e. [`this.max`](#bounds-max)).\n\t * @returns {Point}\n\t */\n\tgetBottomRight() {\n\t\treturn this.max; // right, bottom\n\t}\n\n\t/**\n\t * Returns the size of the given bounds.\n\t * @returns {Point}\n\t */\n\tgetSize() {\n\t\treturn this.max.subtract(this.min);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle contains the given bounds or point.\n\t * @param {BoundsExpression|PointExpression} obj\n\t * @returns {boolean}\n\t */\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/**\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\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\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/**\n\t * Returns `true` if the rectangle overlaps the given bounds. Two bounds\n\t * overlap if their intersection is an area.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\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/**\n\t * Returns `true` if the bounds are properly initialized.\n\t * @returns {boolean}\n\t */\n\tisValid() {\n\t\treturn !!(this.min && this.max);\n\t}\n\n\n\t/**\n\t * Returns bounds created by extending or retracting the current bounds by a given\n\t * ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in\n\t * each direction. Negative values will retract the bounds.\n\t * @param {number} bufferRatio\n\t * @returns {Bounds}\n\t */\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/**\n\t * Returns `true` if the rectangle is equivalent to the given bounds.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAa,SAAb,MAAa,OAAO;;;;;;;;CAQnB,YAAY,GAAG,GAAG;EACjB,IAAI,CAAC,GAAK;EAEV,IAAI,aAAa,QAAQ;GACxB,IAAI,EAAE,QAAQ,GAAG;;;;;IAKhB,KAAK,MAAM,IAAI,MAAM,EAAE,GAAG;;;;;IAK1B,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;;;;;;CAOA,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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ClB,IAAI,KAAK,KAAK,IAAI;CAC3B;;;;;;;CAQA,WAAW,QAAQ;EAClB,SAAS,IAAI,OAAO,MAAM;EAE1B,MAAM,MAAM,KAAK,KACjB,MAAM,KAAK,KACX,OAAO,OAAO,KACd,OAAO,OAAO,KACd,cAAe,KAAK,KAAK,IAAI,KAAO,KAAK,KAAK,IAAI,GAClD,cAAe,KAAK,KAAK,IAAI,KAAO,KAAK,KAAK,IAAI;EAElD,OAAO,eAAe;CACvB;;;;;;;CAQA,SAAS,QAAQ;EAChB,SAAS,IAAI,OAAO,MAAM;EAE1B,MAAM,MAAM,KAAK,KACjB,MAAM,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;;;;;CAMA,UAAU;EACT,OAAO,CAAC,EAAE,KAAK,OAAO,KAAK;CAC5B;;;;;;;;CAUA,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;;;;;;CAQA,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"}
1
+ {"version":3,"file":"Bounds.js","names":[],"sources":["../../../src/geometry/Bounds.js"],"sourcesContent":["import {Point} from './Point.js';\n/** @import {PointExpression} from './Point.js' */\n\n/**\n * A rectangular area in pixel coordinates: a `Bounds`, or an array of points (usually\n * two diagonally opposite corners), e.g. `[[10, 10], [40, 60]]`. Accepted by all\n * Maplair methods which accept `Bounds` objects (unless noted otherwise).\n * @typedef {Bounds|PointExpression[]} BoundsExpression\n */\n\n/**\n * Represents a rectangular area in pixel coordinates.\n *\n * @example\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\n * 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 */\nexport class Bounds {\n\t/**\n\t * Creates a Bounds object from two corners coordinate pairs. Alternatively, creates a\n\t * Bounds object from the given array of points, or a copy of the given Bounds object.\n\t * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the\n\t * bounds to copy.\n\t * @param {PointExpression} [b] The opposite corner.\n\t */\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\t/**\n\t\t\t\t * The top left corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\n\t\t\t\tthis.min = new Point(a.min);\n\t\t\t\t/**\n\t\t\t\t * The bottom right corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\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/**\n\t * Returns the given `Bounds` object as it is, or else a new `Bounds` object created\n\t * from the given arguments (the same as of the constructor) — unlike the\n\t * constructor, which always creates a new object.\n\t * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the\n\t * bounds.\n\t * @param {PointExpression} [b] The opposite corner.\n\t * @returns {Bounds}\n\t */\n\tstatic from(a, b) {\n\t\treturn a instanceof Bounds ? a : new Bounds(a, b);\n\t}\n\n\t/**\n\t * Extends the bounds to contain the given point or bounds.\n\t * @param {PointExpression|BoundsExpression} obj\n\t * @returns {this}\n\t */\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 = Point.from(obj);\n\t\t} else {\n\t\t\tobj = Bounds.from(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\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/**\n\t * Returns the center point of the bounds.\n\t * @param {boolean} [round]\n\t * @returns {Point}\n\t */\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/**\n\t * Returns the bottom-left point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetBottomLeft() {\n\t\treturn new Point(this.min.x, this.max.y);\n\t}\n\n\t/**\n\t * Returns the top-right point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetTopRight() { // -> Point\n\t\treturn new Point(this.max.x, this.min.y);\n\t}\n\n\t/**\n\t * Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-min)).\n\t * @returns {Point}\n\t */\n\tgetTopLeft() {\n\t\treturn this.min; // left, top\n\t}\n\n\t/**\n\t * Returns the bottom-right point of the bounds (i.e. [`this.max`](#bounds-max)).\n\t * @returns {Point}\n\t */\n\tgetBottomRight() {\n\t\treturn this.max; // right, bottom\n\t}\n\n\t/**\n\t * Returns the size of the given bounds.\n\t * @returns {Point}\n\t */\n\tgetSize() {\n\t\treturn this.max.subtract(this.min);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle contains the given bounds or point.\n\t * @param {BoundsExpression|PointExpression} obj\n\t * @returns {boolean}\n\t */\n\tcontains(obj) {\n\t\tlet min, max;\n\n\t\tif (typeof obj[0] === 'number' || obj instanceof Point) {\n\t\t\tobj = Point.from(obj);\n\t\t} else {\n\t\t\tobj = Bounds.from(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/**\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\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tintersects(bounds) { // (Bounds) -> Boolean\n\t\tbounds = Bounds.from(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/**\n\t * Returns `true` if the rectangle overlaps the given bounds. Two bounds\n\t * overlap if their intersection is an area.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\toverlaps(bounds) { // (Bounds) -> Boolean\n\t\tbounds = Bounds.from(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/**\n\t * Returns `true` if the bounds are properly initialized.\n\t * @returns {boolean}\n\t */\n\tisValid() {\n\t\treturn !!(this.min && this.max);\n\t}\n\n\n\t/**\n\t * Returns bounds created by extending or retracting the current bounds by a given\n\t * ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in\n\t * each direction. Negative values will retract the bounds.\n\t * @param {number} bufferRatio\n\t * @returns {Bounds}\n\t */\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/**\n\t * Returns `true` if the rectangle is equivalent to the given bounds.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tequals(bounds) {\n\t\tif (!bounds) { return false; }\n\n\t\tbounds = Bounds.from(bounds);\n\n\t\treturn this.min.equals(bounds.getTopLeft()) &&\n\t\t\tthis.max.equals(bounds.getBottomRight());\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAa,SAAb,MAAa,OAAO;;;;;;;;CAQnB,YAAY,GAAG,GAAG;EACjB,IAAI,CAAC,GAAK;EAEV,IAAI,aAAa,QAAQ;GACxB,IAAI,EAAE,QAAQ,GAAG;;;;;IAKhB,KAAK,MAAM,IAAI,MAAM,EAAE,GAAG;;;;;IAK1B,KAAK,MAAM,IAAI,MAAM,EAAE,GAAG;GAC3B;GACA;EACD;EAEA,MAAM,SAAS,IAAI,CAAC,GAAG,CAAC,IAAI;EAC5B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OACV,IAAI,MAAM,IAAI,IAAI,cAAc,IAAI,IAAI,WAAW,GACnD,IAAI,MAAM,IAAI,IAAI,cAAc,IAAI,IAAI,WAAW,CAAC;CACtD;;;;;;CAQA,OAAO,QAAQ;EACd,IAAI,CAAC,QAAU,OAAO;EAEtB,SAAS,OAAO,KAAK,MAAM;EAE3B,OAAO,KAAK,IAAI,OAAO,OAAO,WAAW,CAAC,KACzC,KAAK,IAAI,OAAO,OAAO,eAAe,CAAC;CACzC;AACD"}
@@ -64,6 +64,24 @@ var Point = class Point {
64
64
  this.y = round ? Math.round(_y) : _y;
65
65
  }
66
66
  /**
67
+ * Returns the given `Point` object as it is (unless `round` is set), or else a new
68
+ * `Point` object created from the given arguments (the same as of the constructor) —
69
+ * unlike the constructor, which always creates a new object.
70
+ *
71
+ * @example
72
+ * ```js
73
+ * Point.from(point) === point; // true
74
+ * Point.from([200, 300]); // Point(200, 300)
75
+ * ```
76
+ * @param {number|PointExpression} x The `x` coordinate, or the coordinates.
77
+ * @param {number} [y] The `y` coordinate.
78
+ * @param {boolean} [round]
79
+ * @returns {Point}
80
+ */
81
+ static from(x, y, round) {
82
+ return x instanceof Point && !round ? x : new Point(x, y, round);
83
+ }
84
+ /**
67
85
  * Returns `true` if the Point object can be properly initialized with the given
68
86
  * arguments (the same as of the constructor).
69
87
  * @param {any} x
@@ -82,7 +100,7 @@ var Point = class Point {
82
100
  * @returns {Point}
83
101
  */
84
102
  add(point) {
85
- return new Point(this)._add(new Point(point));
103
+ return new Point(this)._add(Point.from(point));
86
104
  }
87
105
  _add(point) {
88
106
  this.x += point.x;
@@ -95,7 +113,7 @@ var Point = class Point {
95
113
  * @returns {Point}
96
114
  */
97
115
  subtract(point) {
98
- return new Point(this)._subtract(new Point(point));
116
+ return new Point(this)._subtract(Point.from(point));
99
117
  }
100
118
  _subtract(point) {
101
119
  this.x -= point.x;
@@ -203,7 +221,7 @@ var Point = class Point {
203
221
  * @returns {number}
204
222
  */
205
223
  distanceTo(point) {
206
- point = new Point(point);
224
+ point = Point.from(point);
207
225
  const x = point.x - this.x, y = point.y - this.y;
208
226
  return Math.sqrt(x * x + y * y);
209
227
  }
@@ -213,7 +231,7 @@ var Point = class Point {
213
231
  * @returns {boolean}
214
232
  */
215
233
  equals(point) {
216
- point = new Point(point);
234
+ point = Point.from(point);
217
235
  return point.x === this.x && point.y === this.y;
218
236
  }
219
237
  /**
@@ -223,7 +241,7 @@ var Point = class Point {
223
241
  * @returns {boolean}
224
242
  */
225
243
  contains(point) {
226
- point = new Point(point);
244
+ point = Point.from(point);
227
245
  return Math.abs(point.x) <= Math.abs(this.x) && Math.abs(point.y) <= Math.abs(this.y);
228
246
  }
229
247
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Point.js","names":[],"sources":["../../../src/geometry/Point.js"],"sourcesContent":["import {formatNum} from '../core/Util.js';\n\n/**\n * A point in pixels: a `Point`, an array of the form `[x, y]`, or a plain object of\n * the form `{x, y}`. Accepted by all Maplair methods and options which accept `Point`\n * objects (unless noted otherwise).\n * @typedef {Point|[number, number]|number[]|{x: number, y: number}} PointExpression\n */\n\n/**\n * Represents a point with `x` and `y` coordinates in pixels.\n *\n * @example\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\n * 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 */\nexport class Point {\n\t/**\n\t * Creates a Point object with the given `x` and `y` coordinates. If optional `round`\n\t * is set to true, rounds the `x` and `y` values. Alternatively, expects a Point\n\t * object, an array of the form `[x, y]` or a plain object of the form `{x, y}`\n\t * instead.\n\t * @param {number|PointExpression} x The `x` coordinate, or the coordinates.\n\t * @param {number} [y] The `y` coordinate.\n\t * @param {boolean} [round]\n\t */\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/**\n\t\t * The `x` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.x = (round ? Math.round(_x) : _x);\n\t\t/**\n\t\t * The `y` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.y = (round ? Math.round(_y) : _y);\n\t}\n\n\t/**\n\t * Returns `true` if the Point object can be properly initialized with the given\n\t * arguments (the same as of the constructor).\n\t * @param {any} x\n\t * @param {any} [y]\n\t * @returns {boolean}\n\t */\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/**\n\t * Returns the result of addition of the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\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/**\n\t * Returns the result of subtraction of the given point from the current.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\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/**\n\t * Returns the result of division of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\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/**\n\t * Returns the result of multiplication of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\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/**\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\t * @param {Point} point The scale.\n\t * @returns {Point}\n\t */\n\tscaleBy(point) {\n\t\treturn new Point(this.x * point.x, this.y * point.y);\n\t}\n\n\t/**\n\t * Inverse of `scaleBy`. Divide each coordinate of the current point by\n\t * each coordinate of `scale`.\n\t * @param {Point} point The scale.\n\t * @returns {Point}\n\t */\n\tunscaleBy(point) {\n\t\treturn new Point(this.x / point.x, this.y / point.y);\n\t}\n\n\t/**\n\t * Returns a copy of the current point with rounded coordinates.\n\t * @returns {Point}\n\t */\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/**\n\t * Returns a copy of the current point with floored coordinates (rounded down).\n\t * @returns {Point}\n\t */\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/**\n\t * Returns a copy of the current point with ceiled coordinates (rounded up).\n\t * @returns {Point}\n\t */\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/**\n\t * Returns a copy of the current point with truncated coordinates (rounded towards\n\t * zero).\n\t * @returns {Point}\n\t */\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/**\n\t * Returns the cartesian distance between the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {number}\n\t */\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/**\n\t * Returns `true` if the given point has the same coordinates.\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\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/**\n\t * Returns `true` if both coordinates of the given point are less than the\n\t * corresponding current point coordinates (in absolute values).\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\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/**\n\t * Returns a string representation of the point for debugging purposes.\n\t * @returns {string}\n\t */\n\ttoString() {\n\t\treturn `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,QAAb,MAAa,MAAM;;;;;;;;;;CAUlB,YAAY,GAAG,GAAG,OAAO;EAGxB,IAAI,CADU,MAAM,SAAS,GAAG,CACvB,GACR,MAAM,IAAI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AC;CAC/B;;;;;;CAOA,OAAO,OAAO;EACb,QAAQ,IAAI,MAAM,KAAK;EAEvB,OAAO,MAAM,MAAM,KAAK,KACjB,MAAM,MAAM,KAAK;CACzB;;;;;;;CAQA,SAAS,OAAO;EACf,QAAQ,IAAI,MAAM,KAAK;EAEvB,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,KAAK,CAAC,KACpC,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,KAAK,CAAC;CAC5C;;;;;CAMA,WAAW;EACV,OAAO,SAAS,UAAU,KAAK,CAAC,EAAE,IAAI,UAAU,KAAK,CAAC,EAAE;CACzD;AACD"}
1
+ {"version":3,"file":"Point.js","names":[],"sources":["../../../src/geometry/Point.js"],"sourcesContent":["import {formatNum} from '../core/Util.js';\n\n/**\n * A point in pixels: a `Point`, an array of the form `[x, y]`, or a plain object of\n * the form `{x, y}`. Accepted by all Maplair methods and options which accept `Point`\n * objects (unless noted otherwise).\n * @typedef {Point|[number, number]|number[]|{x: number, y: number}} PointExpression\n */\n\n/**\n * Represents a point with `x` and `y` coordinates in pixels.\n *\n * @example\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\n * 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 */\nexport class Point {\n\t/**\n\t * Creates a Point object with the given `x` and `y` coordinates. If optional `round`\n\t * is set to true, rounds the `x` and `y` values. Alternatively, expects a Point\n\t * object, an array of the form `[x, y]` or a plain object of the form `{x, y}`\n\t * instead.\n\t * @param {number|PointExpression} x The `x` coordinate, or the coordinates.\n\t * @param {number} [y] The `y` coordinate.\n\t * @param {boolean} [round]\n\t */\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/**\n\t\t * The `x` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.x = (round ? Math.round(_x) : _x);\n\t\t/**\n\t\t * The `y` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.y = (round ? Math.round(_y) : _y);\n\t}\n\n\t/**\n\t * Returns the given `Point` object as it is (unless `round` is set), or else a new\n\t * `Point` object created from the given arguments (the same as of the constructor) —\n\t * unlike the constructor, which always creates a new object.\n\t *\n\t * @example\n\t * ```js\n\t * Point.from(point) === point; // true\n\t * Point.from([200, 300]); // Point(200, 300)\n\t * ```\n\t * @param {number|PointExpression} x The `x` coordinate, or the coordinates.\n\t * @param {number} [y] The `y` coordinate.\n\t * @param {boolean} [round]\n\t * @returns {Point}\n\t */\n\tstatic from(x, y, round) {\n\t\treturn x instanceof Point && !round ? x : new Point(x, y, round);\n\t}\n\n\t/**\n\t * Returns `true` if the Point object can be properly initialized with the given\n\t * arguments (the same as of the constructor).\n\t * @param {any} x\n\t * @param {any} [y]\n\t * @returns {boolean}\n\t */\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/**\n\t * Returns the result of addition of the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\n\tadd(point) {\n\t\t// non-destructive, returns a new point\n\t\treturn new Point(this)._add(Point.from(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/**\n\t * Returns the result of subtraction of the given point from the current.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\n\tsubtract(point) {\n\t\treturn new Point(this)._subtract(Point.from(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/**\n\t * Returns the result of division of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\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/**\n\t * Returns the result of multiplication of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\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/**\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\t * @param {Point} point The scale.\n\t * @returns {Point}\n\t */\n\tscaleBy(point) {\n\t\treturn new Point(this.x * point.x, this.y * point.y);\n\t}\n\n\t/**\n\t * Inverse of `scaleBy`. Divide each coordinate of the current point by\n\t * each coordinate of `scale`.\n\t * @param {Point} point The scale.\n\t * @returns {Point}\n\t */\n\tunscaleBy(point) {\n\t\treturn new Point(this.x / point.x, this.y / point.y);\n\t}\n\n\t/**\n\t * Returns a copy of the current point with rounded coordinates.\n\t * @returns {Point}\n\t */\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/**\n\t * Returns a copy of the current point with floored coordinates (rounded down).\n\t * @returns {Point}\n\t */\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/**\n\t * Returns a copy of the current point with ceiled coordinates (rounded up).\n\t * @returns {Point}\n\t */\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/**\n\t * Returns a copy of the current point with truncated coordinates (rounded towards\n\t * zero).\n\t * @returns {Point}\n\t */\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/**\n\t * Returns the cartesian distance between the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {number}\n\t */\n\tdistanceTo(point) {\n\t\tpoint = Point.from(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/**\n\t * Returns `true` if the given point has the same coordinates.\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\n\tequals(point) {\n\t\tpoint = Point.from(point);\n\n\t\treturn point.x === this.x &&\n\t\t point.y === this.y;\n\t}\n\n\t/**\n\t * Returns `true` if both coordinates of the given point are less than the\n\t * corresponding current point coordinates (in absolute values).\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\n\tcontains(point) {\n\t\tpoint = Point.from(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/**\n\t * Returns a string representation of the point for debugging purposes.\n\t * @returns {string}\n\t */\n\ttoString() {\n\t\treturn `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,QAAb,MAAa,MAAM;;;;;;;;;;CAUlB,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,OAAO;GACN,KAAK;GACL,KAAK;EACN;;;;;EAMA,KAAK,IAAK,QAAQ,KAAK,MAAM,EAAE,IAAI;;;;;EAKnC,KAAK,IAAK,QAAQ,KAAK,MAAM,EAAE,IAAI;CACpC;;;;;;;;;;;;;;;;CAiBA,OAAO,KAAK,GAAG,GAAG,OAAO;EACxB,OAAO,aAAa,SAAS,CAAC,QAAQ,IAAI,IAAI,MAAM,GAAG,GAAG,KAAK;CAChE;;;;;;;;CASA,OAAO,SAAS,GAAG,GAAG;EACrB,IAAI,aAAa,SAAS,MAAM,QAAQ,CAAC,GACxC,OAAO;OACD,IAAI,KAAK,OAAO,MAAM,YAAY,OAAO,KAAK,OAAO,GAC3D,OAAO;OACD,KAAK,KAAK,MAAM,OAAO,KAAK,MAAM,IACxC,OAAO;EAER,OAAO;CACR;;;;;;CAOA,IAAI,OAAO;EAEV,OAAO,IAAI,MAAM,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK,KAAK,C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B;CAEA,QAAQ;EACP,KAAK,IAAI,KAAK,KAAK,KAAK,CAAC;EACzB,KAAK,IAAI,KAAK,KAAK,KAAK,CAAC;EACzB,OAAO;CACR;;;;;;CAOA,QAAQ;EACP,OAAO,IAAI,MAAM,IAAI,CAAC,CAAC,OAAO;CAC/B;CAEA,SAAS;EACR,KAAK,IAAI,KAAK,MAAM,KAAK,CAAC;EAC1B,KAAK,IAAI,KAAK,MAAM,KAAK,CAAC;EAC1B,OAAO;CACR;;;;;;CAOA,WAAW,OAAO;EACjB,QAAQ,MAAM,KAAK,KAAK;EAExB,MAAM,IAAI,MAAM,IAAI,KAAK,GACzB,IAAI,MAAM,IAAI,KAAK;EAEnB,OAAO,KAAK,KAAK,IAAI,IAAI,IAAI,CAAC;CAC/B;;;;;;CAOA,OAAO,OAAO;EACb,QAAQ,MAAM,KAAK,KAAK;EAExB,OAAO,MAAM,MAAM,KAAK,KACjB,MAAM,MAAM,KAAK;CACzB;;;;;;;CAQA,SAAS,OAAO;EACf,QAAQ,MAAM,KAAK,KAAK;EAExB,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,KAAK,CAAC,KACpC,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,KAAK,CAAC;CAC5C;;;;;CAMA,WAAW;EACV,OAAO,SAAS,UAAU,KAAK,CAAC,EAAE,IAAI,UAAU,KAAK,CAAC,EAAE;CACzD;AACD"}
@@ -102,7 +102,7 @@ function centroid(coords) {
102
102
  let lngSum = 0;
103
103
  let len = 0;
104
104
  for (const coord of coords) {
105
- const latlng = new LatLng(coord);
105
+ const latlng = LatLng.from(coord);
106
106
  latSum += latlng.lat;
107
107
  lngSum += latlng.lng;
108
108
  len++;
@@ -1 +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/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// PolyUtil: various utility functions for polygon geometries.\n\n/**\n * Clips the polygon geometry defined by the given `points` by the given bounds (using\n * 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 * @param {Point[]} points\n * @param {Bounds} bounds\n * @param {boolean} [round]\n * @returns {Point[]}\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/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polygon.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\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/**\n * Returns the 'center of mass' of the passed LatLngs.\n * @param {LatLngExpression[]} coords\n * @returns {LatLng}\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\t}\n\treturn new LatLng([latSum / len, lngSum / len]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,YAAY,QAAQ,QAAQ,OAAO;CAClD,IAAI,eACJ,GAAG,GAAG,GACN,GAAG,GACH,KAAK,MAAM;CACX,MAAM,QAAQ;EAAC;EAAG;EAAG;EAAG;CAAC;CAEzB,KAAK,IAAI,GAAG,MAAM,OAAO,QAAQ,IAAI,KAAK,KACzC,OAAO,EAAE,CAAC,QAAQA,YAAqB,OAAO,IAAI,MAAM;CAIzD,KAAK,IAAI,GAAG,IAAI,GAAG,KAAK;EACvB,OAAO,MAAM;EACb,gBAAgB,CAAC;EAEjB,KAAK,IAAI,GAAG,MAAM,OAAO,QAAQ,IAAI,MAAM,GAAG,IAAI,KAAK,IAAI,KAAK;GAC/D,IAAI,OAAO;GACX,IAAI,OAAO;GAGX,IAAI,EAAE,EAAE,QAAQ,OAAO;IAEtB,IAAI,EAAE,QAAQ,MAAM;KACnB,IAAIC,qBAA8B,GAAG,GAAG,MAAM,QAAQ,KAAK;KAC3D,EAAE,QAAQD,YAAqB,GAAG,MAAM;KACxC,cAAc,KAAK,CAAC;IACrB;IACA,cAAc,KAAK,CAAC;GAGrB,OAAO,IAAI,EAAE,EAAE,QAAQ,OAAO;IAC7B,IAAIC,qBAA8B,GAAG,GAAG,MAAM,QAAQ,KAAK;IAC3D,EAAE,QAAQD,YAAqB,GAAG,MAAM;IAC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M,MAAM,CAAC;CACpD,OAAO,IAAI,OAAO,CAAC,aAAa,MAAM,eAAe,KAAK,aAAa,MAAM,eAAe,GAAG,CAAC;AACjG;;;;;;AAOA,SAAgB,SAAS,QAAQ;CAChC,IAAI,SAAS;CACb,IAAI,SAAS;CACb,IAAI,MAAM;CACV,KAAK,MAAM,SAAS,QAAQ;EAC3B,MAAM,SAAS,IAAI,OAAO,KAAK;EAC/B,UAAU,OAAO;EACjB,UAAU,OAAO;EACjB;CACD;CACA,OAAO,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,GAAG,CAAC;AAC/C"}
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/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// PolyUtil: various utility functions for polygon geometries.\n\n/**\n * Clips the polygon geometry defined by the given `points` by the given bounds (using\n * 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 * @param {Point[]} points\n * @param {Bounds} bounds\n * @param {boolean} [round]\n * @returns {Point[]}\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/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polygon.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\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/**\n * Returns the 'center of mass' of the passed LatLngs.\n * @param {LatLngExpression[]} coords\n * @returns {LatLng}\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 = LatLng.from(coord);\n\t\tlatSum += latlng.lat;\n\t\tlngSum += latlng.lng;\n\t\tlen++;\n\t}\n\treturn new LatLng([latSum / len, lngSum / len]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,YAAY,QAAQ,QAAQ,OAAO;CAClD,IAAI,eACJ,GAAG,GAAG,GACN,GAAG,GACH,KAAK,MAAM;CACX,MAAM,QAAQ;EAAC;EAAG;EAAG;EAAG;CAAC;CAEzB,KAAK,IAAI,GAAG,MAAM,OAAO,QAAQ,IAAI,KAAK,KACzC,OAAO,EAAE,CAAC,QAAQA,YAAqB,OAAO,IAAI,MAAM;CAIzD,KAAK,IAAI,GAAG,IAAI,GA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E;EACpC,OAAO,KAAK,IAAI,QAAQ,IAAI,OAAO,CAAC,OAAO,MAAM,eAAe,KAAK,OAAO,MAAM,eAAe,GAAG,CAAC,CAAC,CAAC;CACxG;CAEA,OAAO,IAAI,IAAI;CAGf,KAAK,IAAI,GAAG,IAAI,MAAM,GAAG,IAAI,KAAK,IAAI,KAAK;EAC1C,KAAK,OAAO;EACZ,KAAK,OAAO;EAEZ,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG;EAC5B,MAAM,GAAG,IAAI,GAAG,KAAK;EACrB,MAAM,GAAG,IAAI,GAAG,KAAK;EACrB,QAAQ,IAAI;CACb;CAEA,IAAI,SAAS,GAEZ,SAAS,OAAO;MAEhB,SAAS,CAAC,IAAI,MAAM,IAAI,IAAI;CAG7B,MAAM,eAAe,IAAI,UAAU,IAAI,MAAM,MAAM,CAAC;CACpD,OAAO,IAAI,OAAO,CAAC,aAAa,MAAM,eAAe,KAAK,aAAa,MAAM,eAAe,GAAG,CAAC;AACjG;;;;;;AAOA,SAAgB,SAAS,QAAQ;CAChC,IAAI,SAAS;CACb,IAAI,SAAS;CACb,IAAI,MAAM;CACV,KAAK,MAAM,SAAS,QAAQ;EAC3B,MAAM,SAAS,OAAO,KAAK,KAAK;EAChC,UAAU,OAAO;EACjB,UAAU,OAAO;EACjB;CACD;CACA,OAAO,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,GAAG,CAAC;AAC/C"}
@@ -347,7 +347,7 @@ var DivOverlay = class DivOverlay extends Layer {
347
347
  _updatePosition() {
348
348
  if (!this._map) return;
349
349
  const pos = this._map.latLngToLayerPoint(this._latlng), anchor = this._getAnchor();
350
- let offset = new Point(this.options.offset);
350
+ let offset = Point.from(this.options.offset);
351
351
  if (this._zoomAnimated || this.options.overflow) this._setContainerPosition(pos.add(anchor));
352
352
  else offset = offset.add(pos).add(anchor);
353
353
  const bottom = this._containerBottom = -offset.y, left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
@@ -1 +1 @@
1
- {"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement`, or a function receiving the source layer and returning one of them.\n * @typedef {string|HTMLElement|((layer: Layer) => string|HTMLElement)} DivOverlayContent\n */\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String` or `HTMLElement` to be used in the\n * overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tinteractive: false,\n\t\t\toffset: [0, 0],\n\t\t\tclassName: '',\n\t\t\tpane: undefined,\n\t\t\toverflow: false,\n\t\t\tcontent: ''\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tthis._prepareOpen();\n\n\t\t\t// open the overlay on the map\n\t\t\tthis.openOn(layer._map);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tthis._zoomAnimated = map._zoomAnimated;\n\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 0;\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().appendChild(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 1;\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 0;\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)\n\t * or pass an `HTMLElement` with safe `textContent` instead. If a function is\n\t * passed the source layer will be passed to the function. The function should\n\t * return a `String` or `HTMLElement` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition\n\t\t};\n\n\t\tif (this._zoomAnimated) {\n\t\t\tevents.zoomanim = this._animateZoom;\n\t\t}\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map && this._map.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tif (!latlng) {\n\t\t\tif (source.getCenter) {\n\t\t\t\tlatlng = source.getCenter();\n\t\t\t} else if (source.getLatLng) {\n\t\t\t\tlatlng = source.getLatLng();\n\t\t\t} else if (source.getBounds) {\n\t\t\t\tlatlng = source.getBounds().getCenter();\n\t\t\t} else {\n\t\t\t\tthrow new Error('Unable to get source layer LatLng.');\n\t\t\t}\n\t\t}\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (!this._content) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else {\n\t\t\twhile (node.hasChildNodes()) {\n\t\t\t\tnode.removeChild(node.firstChild);\n\t\t\t}\n\t\t\tnode.appendChild(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng),\n\t\tanchor = this._getAnchor();\n\t\tlet offset = new Point(this.options.offset);\n\n\t\tif (this._zoomAnimated || this.options.overflow) {\n\t\t\tthis._setContainerPosition(pos.add(anchor));\n\t\t} else {\n\t\t\toffset = offset.add(pos).add(anchor);\n\t\t}\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [0, 0];\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAM,uBAAuB,EAC5B,aAAa,cAAc,SAAS,QAAQ,SAAS;CACpD,IAAI,UAAU;CACd,IAAI,EAAE,mBAAmB,eACxB,UAAU,IAAI,aAAa,OAAO,CAAC,CAAC,WAAW,OAAO;CAEvD,IAAI,QACH,QAAQ,UAAU,MAAM;CAEzB,OAAO;AACR,EACD;;;;;;AAOA,MAAM,yBAAyB,EAC9B,aAAa,cAAc,KAAK,SAAS,SAAS;CACjD,IAAI,UAAU;CACd,IAAI,mBAAmB,cAAc;EACpC,WAAgB,SAAS,OAAO;EAChC,QAAQ,UAAU;CACnB,OAAO;EACN,UAAW,OAAO,CAAC,UAAW,MAAM,IAAI,aAAa,SAAS,IAAI;EAClE,QAAQ,WAAW,OAAO;CAC3B;CACA,OAAO;AACR,EACD;;;;;;;AAQA,IAAa,aAAb,MAAa,mBAAmB,MAAM;CAErC;EACC,KAAK,kBAAkB;GACtB,aAAa;GACb,QAAQ,CAAC,GAAG,CAAC;GACb,WAAW;GACX,MAAM,KAAA;GACN,UAAU;GACV,SAAS;EACV,CAA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,KAAK,KAAK,YAC/B,OAAO,aAAa,sBAAsB;GAC1C,MAAM,KAAK,KAAK,2BAA2B,GAAG,CAAC,CAC7C,KAAK,IAAI,MAAM,KAAK,OAAO,aAAa,YAAY,KAAK,MAAM,aAAa,SAAS,CAAC;EACzF;EACA,YAAoB,KAAK,YAAY,GAAG;CACzC;CAGA,wBAAwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
1
+ {"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement`, or a function receiving the source layer and returning one of them.\n * @typedef {string|HTMLElement|((layer: Layer) => string|HTMLElement)} DivOverlayContent\n */\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String` or `HTMLElement` to be used in the\n * overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tinteractive: false,\n\t\t\toffset: [0, 0],\n\t\t\tclassName: '',\n\t\t\tpane: undefined,\n\t\t\toverflow: false,\n\t\t\tcontent: ''\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tthis._prepareOpen();\n\n\t\t\t// open the overlay on the map\n\t\t\tthis.openOn(layer._map);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tthis._zoomAnimated = map._zoomAnimated;\n\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 0;\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().appendChild(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 1;\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 0;\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)\n\t * or pass an `HTMLElement` with safe `textContent` instead. If a function is\n\t * passed the source layer will be passed to the function. The function should\n\t * return a `String` or `HTMLElement` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition\n\t\t};\n\n\t\tif (this._zoomAnimated) {\n\t\t\tevents.zoomanim = this._animateZoom;\n\t\t}\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map && this._map.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tif (!latlng) {\n\t\t\tif (source.getCenter) {\n\t\t\t\tlatlng = source.getCenter();\n\t\t\t} else if (source.getLatLng) {\n\t\t\t\tlatlng = source.getLatLng();\n\t\t\t} else if (source.getBounds) {\n\t\t\t\tlatlng = source.getBounds().getCenter();\n\t\t\t} else {\n\t\t\t\tthrow new Error('Unable to get source layer LatLng.');\n\t\t\t}\n\t\t}\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (!this._content) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else {\n\t\t\twhile (node.hasChildNodes()) {\n\t\t\t\tnode.removeChild(node.firstChild);\n\t\t\t}\n\t\t\tnode.appendChild(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng),\n\t\tanchor = this._getAnchor();\n\t\tlet offset = Point.from(this.options.offset);\n\n\t\tif (this._zoomAnimated || this.options.overflow) {\n\t\t\tthis._setContainerPosition(pos.add(anchor));\n\t\t} else {\n\t\t\toffset = offset.add(pos).add(anchor);\n\t\t}\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [0, 0];\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAM,uBAAuB,EAC5B,aAAa,cAAc,SAAS,QAAQ,SAAS;CACpD,IAAI,UAAU;CACd,IAAI,EAAE,mBAAmB,eACxB,UAAU,IAAI,aAAa,OAAO,CAAC,CAAC,WAAW,OAAO;CAEvD,IAAI,QACH,QAAQ,UAAU,MAAM;CAEzB,OAAO;AACR,EACD;;;;;;AAOA,MAAM,yBAAyB,EA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AGpC,MAAM,SAAS,KAAK,mBAAmB,CAAC,OAAO,GAC/C,OAAO,KAAK,iBAAiB,CAAC,KAAK,MAAM,KAAK,kBAAkB,CAAC,IAAI,OAAO;EAG5E,IAAI,KAAK,QAAQ,UAAU;GAE1B,KAAK,WAAW,MAAM,MAAM;GAC5B,KAAK,WAAW,MAAM,SAAS,eAAe,OAAO;EACtD,OACC,KAAK,WAAW,MAAM,SAAS,GAAG,OAAO;EAE1C,KAAK,WAAW,MAAM,OAAO,GAAG,KAAK;CACtC;CAIA,sBAAsB,KAAK;EAC1B,KAAK,gBAAgB;EACrB,IAAI,KAAK,QAAQ,UAAU;GAC1B,MAAM,eAAe,KAAK,KAAK,YAC/B,OAAO,aAAa,sBAAsB;GAC1C,MAAM,KAAK,KAAK,2BAA2B,GAAG,CAAC,CAC7C,KAAK,IAAI,MAAM,KAAK,OAAO,aAAa,YAAY,KAAK,MAAM,aAAa,SAAS,CAAC;EACzF;EACA,YAAoB,KAAK,YAAY,GAAG;CACzC;CAGA,wBAAwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
@@ -228,7 +228,7 @@ var GeoJSON = class GeoJSON extends FeatureGroup {
228
228
  * @returns {number[]}
229
229
  */
230
230
  static latLngToCoords(latlng, precision) {
231
- latlng = new LatLng(latlng);
231
+ latlng = LatLng.from(latlng);
232
232
  return latlng.alt !== void 0 ? [
233
233
  formatNum(latlng.lng, precision),
234
234
  formatNum(latlng.lat, precision),
@@ -1 +1 @@
1
- {"version":3,"file":"GeoJSON.js","names":["Util.formatNum","LineUtil.isFlat"],"sources":["../../../src/layer/GeoJSON.js"],"sourcesContent":["import {LayerGroup} from './LayerGroup.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {Marker} from './marker/Marker.js';\nimport {Circle} from './vector/Circle.js';\nimport {CircleMarker} from './vector/CircleMarker.js';\nimport {Polyline} from './vector/Polyline.js';\nimport {Polygon} from './vector/Polygon.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport * as LineUtil from '../geometry/LineUtil.js';\n\n/** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */\n/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PathOptions} from './vector/Path.js' */\n\n/**\n * Options of `GeoJSON`.\n * @typedef {object} GeoJSONOptions\n * @property {(geoJsonPoint: Feature, latlng: LatLng) => Layer} [pointToLayer] A\n * `Function` defining how GeoJSON points spawn Maplair layers. It is internally\n * called when data is added, passing the GeoJSON point feature and its `LatLng`.\n * The default is to spawn a default `Marker`:\n * ```js\n * function(geoJsonPoint, latlng) {\n * \treturn new Marker(latlng);\n * }\n * ```\n * @property {PathOptions|((geoJsonFeature: Feature) => PathOptions)} [style] A\n * `Function` defining the `Path options` for styling GeoJSON lines and polygons,\n * called internally when data is added.\n * The default value is to not override any defaults:\n * ```js\n * function (geoJsonFeature) {\n * \treturn {}\n * }\n * ```\n * @property {(feature: Feature, layer: Layer) => void} [onEachFeature] A `Function`\n * that will be called once for each created `Feature`, after it has been created and\n * styled. Useful for attaching events and popups to features. It will receive the\n * `feature` as the first argument and its corresponding spawned `layer` from\n * [`asFeature`](#geojson-asFeature) as the second.\n * The default is to do nothing with the newly created layers:\n * ```js\n * function (feature, layer) {}\n * ```\n * @property {(geoJsonFeature: Feature) => boolean} [filter] A `Function` that will be\n * used to decide whether to include a feature or not.\n * The default is to include all features:\n * ```js\n * function (geoJsonFeature) {\n * \treturn true;\n * }\n * ```\n * Note: dynamically changing the `filter` option will have effect only on newly\n * added data. It will _not_ re-evaluate already included features.\n * @property {(coords: number[]) => LatLng} [coordsToLatLng] A `Function` that will be\n * used for converting GeoJSON coordinates to `LatLng`s.\n * The default is the `coordsToLatLng` static method.\n * @property {boolean} [markersInheritOptions=false] Whether default Markers for \"Point\"\n * type Features inherit from group options.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Properties of layers created from GeoJSON.\n * @typedef {object} GeoJSONLayerProperties\n * @lends Layer\n * @property {Feature} [feature] The GeoJSON feature the layer was created from (by\n * `GeoJSON`).\n */\n\n/**\n * Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse\n * GeoJSON data and display it on the map. Extends `FeatureGroup`.\n *\n * There are several static functions which can be called without instantiating\n * `GeoJSON`.\n *\n * @example\n * ```js\n * new GeoJSON(data, {\n * \tstyle: function (feature) {\n * \t\treturn {color: feature.properties.color};\n * \t}\n * }).bindPopup(function (layer) {\n * \treturn layer.feature.properties.description;\n * }).addTo(map);\n * ```\n */\nexport class GeoJSON extends FeatureGroup {\n\n\t/**\n\t * Creates a GeoJSON layer. Optionally accepts an object in\n\t * [GeoJSON format](https://tools.ietf.org/html/rfc7946) to display on the map\n\t * (you can alternatively add it later with `addData` method) and an `options` object.\n\t * @param {GeoJSONData|GeoJSONData[]|null} [geojson]\n\t * @param {GeoJSONOptions} [options]\n\t */\n\tconstructor(geojson, options) {\n\t\tsuper(undefined, options);\n\n\t\tif (geojson) {\n\t\t\tthis.addData(geojson);\n\t\t}\n\n\t\tthis.callInitHooks(GeoJSON);\n\t}\n\n\t/**\n\t * Adds a GeoJSON object to the layer.\n\t * @param {GeoJSONData|GeoJSONData[]} geojson\n\t * @returns {this}\n\t */\n\taddData(geojson) {\n\t\tconst features = Array.isArray(geojson) ? geojson : geojson.features;\n\n\t\tif (features) {\n\t\t\tfor (const feature of features) {\n\t\t\t\t// only add this if geometry or geometries are set and not null\n\t\t\t\tif (feature.geometries || feature.geometry || feature.features || feature.coordinates) {\n\t\t\t\t\tthis.addData(feature);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tconst options = this.options;\n\n\t\tif (options.filter && !options.filter(geojson)) { return this; }\n\n\t\tconst layer = GeoJSON.geometryToLayer(geojson, options);\n\t\tif (!layer) {\n\t\t\treturn this;\n\t\t}\n\t\tlayer.feature = GeoJSON.asFeature(geojson);\n\n\t\tlayer.defaultOptions = layer.options;\n\t\tthis.resetStyle(layer);\n\n\t\tif (options.onEachFeature) {\n\t\t\toptions.onEachFeature(geojson, layer);\n\t\t}\n\n\t\treturn this.addLayer(layer);\n\t}\n\n\t/**\n\t * Resets the given vector layer's style to the original GeoJSON style, useful for\n\t * resetting style after hover events. If `layer` is omitted, the style of all\n\t * features in the current layer is reset.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\tresetStyle(layer) {\n\t\tif (layer === undefined) {\n\t\t\treturn this.eachLayer(this.resetStyle, this);\n\t\t}\n\t\t// reset any custom styles\n\t\tlayer.options = Object.create(layer.defaultOptions);\n\t\tthis._setLayerStyle(layer, this.options.style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes styles of GeoJSON vector layers with the given style function.\n\t * @param {PathOptions|((geoJsonFeature: Feature) => PathOptions)} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\treturn this.eachLayer(layer => this._setLayerStyle(layer, style));\n\t}\n\n\t_setLayerStyle(layer, style) {\n\t\tif (layer.setStyle) {\n\t\t\tif (typeof style === 'function') {\n\t\t\t\tstyle = style(layer.feature);\n\t\t\t}\n\t\t\tlayer.setStyle(style);\n\t\t}\n\t}\n\n\t/**\n\t * Creates a `Layer` from a given GeoJSON feature. Can use a custom\n\t * [`pointToLayer`](#geojson-pointtolayer) and/or [`coordsToLatLng`](#geojson-coordstolatlng)\n\t * functions if provided as options.\n\t * @param {GeoJsonObject} geojson\n\t * @param {GeoJSONOptions} [options]\n\t * @returns {Layer|null}\n\t */\n\tstatic geometryToLayer(geojson, options) {\n\n\t\tconst geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,\n\t\tcoords = geometry?.coordinates,\n\t\tlayers = [],\n\t\tpointToLayer = options?.pointToLayer,\n\t\t_coordsToLatLng = options?.coordsToLatLng ?? GeoJSON.coordsToLatLng;\n\t\tlet latlng, latlngs;\n\n\t\tif (!coords && !geometry) {\n\t\t\treturn null;\n\t\t}\n\n\t\tswitch (geometry.type) {\n\t\tcase 'Point':\n\t\t\tlatlng = _coordsToLatLng(coords);\n\t\t\treturn GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options);\n\n\t\tcase 'MultiPoint':\n\t\t\tfor (const coord of coords) {\n\t\t\t\tlatlng = _coordsToLatLng(coord);\n\t\t\t\tlayers.push(GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options));\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'LineString':\n\t\tcase 'MultiLineString':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, _coordsToLatLng);\n\t\t\treturn new Polyline(latlngs, options);\n\n\t\tcase 'Polygon':\n\t\tcase 'MultiPolygon':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, _coordsToLatLng);\n\t\t\treturn new Polygon(latlngs, options);\n\n\t\tcase 'GeometryCollection':\n\t\t\tfor (const g of geometry.geometries) {\n\t\t\t\tconst geoLayer = GeoJSON.geometryToLayer({\n\t\t\t\t\tgeometry: g,\n\t\t\t\t\ttype: 'Feature',\n\t\t\t\t\tproperties: geojson.properties\n\t\t\t\t}, options);\n\n\t\t\t\tif (geoLayer) {\n\t\t\t\t\tlayers.push(geoLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'FeatureCollection':\n\t\t\tfor (const f of geometry.features) {\n\t\t\t\tconst featureLayer = GeoJSON.geometryToLayer(f, options);\n\n\t\t\t\tif (featureLayer) {\n\t\t\t\t\tlayers.push(featureLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tdefault:\n\t\t\tthrow new Error('Invalid GeoJSON object.');\n\t\t}\n\t}\n\n\tstatic _pointToLayer(pointToLayerFn, geojson, latlng, options) {\n\t\treturn pointToLayerFn ?\n\t\t\tpointToLayerFn(geojson, latlng) :\n\t\t\tnew Marker(latlng, options?.markersInheritOptions && options);\n\t}\n\n\t/**\n\t * Creates a `LatLng` object from an array of 2 numbers (longitude, latitude)\n\t * or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.\n\t * @param {number[]} coords\n\t * @returns {LatLng}\n\t */\n\tstatic coordsToLatLng(coords) {\n\t\treturn new LatLng(coords[1], coords[0], coords[2]);\n\t}\n\n\t/**\n\t * Creates a multidimensional array of `LatLng`s from a GeoJSON coordinates array.\n\t * `levelsDeep` specifies the nesting level (0 is for an array of points, 1 for an\n\t * array of arrays of points, etc., 0 by default).\n\t * Can use a custom [`coordsToLatLng`](#geojson-coordstolatlng) function.\n\t * @param {any[]} coords\n\t * @param {number} [levelsDeep]\n\t * @param {(coords: number[]) => LatLng} [_coordsToLatLng]\n\t * @returns {any[]}\n\t */\n\tstatic coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {\n\t\treturn coords.map(coord => (levelsDeep ?\n\t\t\tGeoJSON.coordsToLatLngs(coord, levelsDeep - 1, _coordsToLatLng) :\n\t\t\t(_coordsToLatLng || GeoJSON.coordsToLatLng)(coord)));\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLng`](#geojson-coordstolatlng).\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {LatLngExpression} latlng\n\t * @param {number|false} [precision]\n\t * @returns {number[]}\n\t */\n\tstatic latLngToCoords(latlng, precision) {\n\t\tlatlng = new LatLng(latlng);\n\t\treturn latlng.alt !== undefined ?\n\t\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :\n\t\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs).\n\t * `close` determines whether the first point should be appended to the end of the\n\t * array to close the feature, only used when `levelsDeep` is 0. False by default.\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {any[]} latlngs\n\t * @param {number} [levelsDeep]\n\t * @param {boolean} [close]\n\t * @param {number|false} [precision]\n\t * @returns {any[]}\n\t */\n\tstatic latLngsToCoords(latlngs, levelsDeep, close, precision) {\n\t\t// Check for flat arrays required to ensure unbalanced arrays are correctly converted in recursion\n\t\tconst coords = latlngs.map(latlng => (levelsDeep ?\n\t\t\tGeoJSON.latLngsToCoords(latlng, LineUtil.isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) :\n\t\t\tGeoJSON.latLngToCoords(latlng, precision)));\n\n\t\tif (!levelsDeep && close && coords.length > 0) {\n\t\t\tcoords.push(coords[0].slice());\n\t\t}\n\n\t\treturn coords;\n\t}\n\n\t/**\n\t * Returns GeoJSON geometries/features of layer with new GeoJSON geometry.\n\t * @param {Layer} layer\n\t * @param {Geometry} newGeometry\n\t * @returns {Feature}\n\t */\n\tstatic getFeature(layer, newGeometry) {\n\t\treturn layer.feature ?\n\t\t\t{...layer.feature, geometry: newGeometry} :\n\t\t\tGeoJSON.asFeature(newGeometry);\n\t}\n\n\t/**\n\t * Normalize GeoJSON geometries/features into GeoJSON features.\n\t * @param {GeoJsonObject} geojson\n\t * @returns {Feature|FeatureCollection}\n\t */\n\tstatic asFeature(geojson) {\n\t\tif (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') {\n\t\t\treturn geojson;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'Feature',\n\t\t\tproperties: {},\n\t\t\tgeometry: geojson\n\t\t};\n\t}\n\n}\n\n/**\n * Methods of `Marker` (and `CircleMarker`, `Circle`) for GeoJSON.\n * @lends Marker.prototype\n */\nconst PointToGeoJSON = {\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 marker (as a GeoJSON `Point` Feature).\n\t * @group Other methods\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: 'Point',\n\t\t\tcoordinates: GeoJSON.latLngToCoords(this.getLatLng(), precision)\n\t\t});\n\t}\n};\n/** @typedef {typeof PointToGeoJSON} PointToGeoJSONMethods */\n\n/**\n * Methods of `CircleMarker` (and `Circle`) for GeoJSON: `toGeoJSON(precision?)`\n * returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the\n * circle marker (as a GeoJSON `Point` Feature), with the coordinates values rounded\n * with [`formatNum`](#util-formatnum) function with given `precision`.\n * @typedef {object} CircleMarkerToGeoJSONMethods\n * @extends PointToGeoJSONMethods\n * @lends CircleMarker\n */\n\nMarker.include(PointToGeoJSON);\nCircle.include(PointToGeoJSON);\nCircleMarker.include(PointToGeoJSON);\n\n/**\n * Methods of `Polyline` for GeoJSON.\n * @lends Polyline.prototype\n */\nconst polylineToGeoJSON = {\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 = GeoJSON.latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}LineString`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n};\n/** @typedef {typeof polylineToGeoJSON} PolylineToGeoJSONMethods */\n\nPolyline.include(polylineToGeoJSON);\n\n/**\n * Methods of `Polygon` for GeoJSON.\n * @lends Polygon.prototype\n */\nconst polygonToGeoJSON = {\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 = GeoJSON.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 GeoJSON.getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}Polygon`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n};\n/** @typedef {typeof polygonToGeoJSON} PolygonToGeoJSONMethods */\n\nPolygon.include(polygonToGeoJSON);\n\n/**\n * Methods of `LayerGroup` for GeoJSON.\n * @lends LayerGroup.prototype\n */\nconst layerGroupToGeoJSON = {\n\t/**\n\t * Returns a GeoJSON `MultiPoint` Feature of the points of the group, used by\n\t * `toGeoJSON()`.\n\t * @internal\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoMultiPoint(precision) {\n\t\tconst coords = [];\n\n\t\tthis.eachLayer((layer) => {\n\t\t\tcoords.push(layer.toGeoJSON(precision).geometry.coordinates);\n\t\t});\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: 'MultiPoint',\n\t\t\tcoordinates: coords\n\t\t});\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 layer group (as a GeoJSON `FeatureCollection`,\n\t * `GeometryCollection`, or `MultiPoint`).\n\t * @param {number|false} [precision]\n\t * @returns {Feature|FeatureCollection}\n\t */\n\ttoGeoJSON(precision) {\n\n\t\tconst type = this.feature?.geometry?.type;\n\n\t\tif (type === 'MultiPoint') {\n\t\t\treturn this.toMultiPoint(precision);\n\t\t}\n\n\t\tconst isGeometryCollection = type === 'GeometryCollection',\n\t\tjsons = [];\n\n\t\tthis.eachLayer((layer) => {\n\t\t\tif (layer.toGeoJSON) {\n\t\t\t\tconst json = layer.toGeoJSON(precision);\n\t\t\t\tif (isGeometryCollection) {\n\t\t\t\t\tjsons.push(json.geometry);\n\t\t\t\t} else {\n\t\t\t\t\tconst feature = GeoJSON.asFeature(json);\n\t\t\t\t\t// Squash nested feature collections\n\t\t\t\t\tif (feature.type === 'FeatureCollection') {\n\t\t\t\t\t\tjsons.push(...feature.features);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tjsons.push(feature);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tif (isGeometryCollection) {\n\t\t\treturn GeoJSON.getFeature(this, {\n\t\t\t\tgeometries: jsons,\n\t\t\t\ttype: 'GeometryCollection'\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'FeatureCollection',\n\t\t\tfeatures: jsons\n\t\t};\n\t}\n};\n/** @typedef {typeof layerGroupToGeoJSON} LayerGroupToGeoJSONMethods */\n\nLayerGroup.include(layerGroupToGeoJSON);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,IAAa,UAAb,MAAa,gBAAgB,aAAa;;;;;;;;CASzC,YAAY,SAAS,SAAS;EAC7B,MAAM,KAAA,GAAW,OAAO;EAExB,IAAI,SACH,KAAK,QAAQ,OAAO;EAGrB,KAAK,cAAc,OAAO;CAC3B;;;;;;CAOA,QAAQ,SAAS;EAChB,MAAM,WAAW,MAAM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BACH,MAAM,KAAK,KAAK,QAAQ;SAClB;KACN,MAAM,UAAU,QAAQ,UAAU,IAAI;KAEtC,IAAI,QAAQ,SAAS,qBACpB,MAAM,KAAK,GAAG,QAAQ,QAAQ;UAE9B,MAAM,KAAK,OAAO;IAEpB;GACD;EACD,CAAC;EAED,IAAI,sBACH,OAAO,QAAQ,WAAW,MAAM;GAC/B,YAAY;GACZ,MAAM;EACP,CAAC;EAGF,OAAO;GACN,MAAM;GACN,UAAU;EACX;CACD;AAIoC,CAAC"}
1
+ {"version":3,"file":"GeoJSON.js","names":["Util.formatNum","LineUtil.isFlat"],"sources":["../../../src/layer/GeoJSON.js"],"sourcesContent":["import {LayerGroup} from './LayerGroup.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {Marker} from './marker/Marker.js';\nimport {Circle} from './vector/Circle.js';\nimport {CircleMarker} from './vector/CircleMarker.js';\nimport {Polyline} from './vector/Polyline.js';\nimport {Polygon} from './vector/Polygon.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport * as LineUtil from '../geometry/LineUtil.js';\n\n/** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */\n/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PathOptions} from './vector/Path.js' */\n\n/**\n * Options of `GeoJSON`.\n * @typedef {object} GeoJSONOptions\n * @property {(geoJsonPoint: Feature, latlng: LatLng) => Layer} [pointToLayer] A\n * `Function` defining how GeoJSON points spawn Maplair layers. It is internally\n * called when data is added, passing the GeoJSON point feature and its `LatLng`.\n * The default is to spawn a default `Marker`:\n * ```js\n * function(geoJsonPoint, latlng) {\n * \treturn new Marker(latlng);\n * }\n * ```\n * @property {PathOptions|((geoJsonFeature: Feature) => PathOptions)} [style] A\n * `Function` defining the `Path options` for styling GeoJSON lines and polygons,\n * called internally when data is added.\n * The default value is to not override any defaults:\n * ```js\n * function (geoJsonFeature) {\n * \treturn {}\n * }\n * ```\n * @property {(feature: Feature, layer: Layer) => void} [onEachFeature] A `Function`\n * that will be called once for each created `Feature`, after it has been created and\n * styled. Useful for attaching events and popups to features. It will receive the\n * `feature` as the first argument and its corresponding spawned `layer` from\n * [`asFeature`](#geojson-asFeature) as the second.\n * The default is to do nothing with the newly created layers:\n * ```js\n * function (feature, layer) {}\n * ```\n * @property {(geoJsonFeature: Feature) => boolean} [filter] A `Function` that will be\n * used to decide whether to include a feature or not.\n * The default is to include all features:\n * ```js\n * function (geoJsonFeature) {\n * \treturn true;\n * }\n * ```\n * Note: dynamically changing the `filter` option will have effect only on newly\n * added data. It will _not_ re-evaluate already included features.\n * @property {(coords: number[]) => LatLng} [coordsToLatLng] A `Function` that will be\n * used for converting GeoJSON coordinates to `LatLng`s.\n * The default is the `coordsToLatLng` static method.\n * @property {boolean} [markersInheritOptions=false] Whether default Markers for \"Point\"\n * type Features inherit from group options.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Properties of layers created from GeoJSON.\n * @typedef {object} GeoJSONLayerProperties\n * @lends Layer\n * @property {Feature} [feature] The GeoJSON feature the layer was created from (by\n * `GeoJSON`).\n */\n\n/**\n * Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse\n * GeoJSON data and display it on the map. Extends `FeatureGroup`.\n *\n * There are several static functions which can be called without instantiating\n * `GeoJSON`.\n *\n * @example\n * ```js\n * new GeoJSON(data, {\n * \tstyle: function (feature) {\n * \t\treturn {color: feature.properties.color};\n * \t}\n * }).bindPopup(function (layer) {\n * \treturn layer.feature.properties.description;\n * }).addTo(map);\n * ```\n */\nexport class GeoJSON extends FeatureGroup {\n\n\t/**\n\t * Creates a GeoJSON layer. Optionally accepts an object in\n\t * [GeoJSON format](https://tools.ietf.org/html/rfc7946) to display on the map\n\t * (you can alternatively add it later with `addData` method) and an `options` object.\n\t * @param {GeoJSONData|GeoJSONData[]|null} [geojson]\n\t * @param {GeoJSONOptions} [options]\n\t */\n\tconstructor(geojson, options) {\n\t\tsuper(undefined, options);\n\n\t\tif (geojson) {\n\t\t\tthis.addData(geojson);\n\t\t}\n\n\t\tthis.callInitHooks(GeoJSON);\n\t}\n\n\t/**\n\t * Adds a GeoJSON object to the layer.\n\t * @param {GeoJSONData|GeoJSONData[]} geojson\n\t * @returns {this}\n\t */\n\taddData(geojson) {\n\t\tconst features = Array.isArray(geojson) ? geojson : geojson.features;\n\n\t\tif (features) {\n\t\t\tfor (const feature of features) {\n\t\t\t\t// only add this if geometry or geometries are set and not null\n\t\t\t\tif (feature.geometries || feature.geometry || feature.features || feature.coordinates) {\n\t\t\t\t\tthis.addData(feature);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tconst options = this.options;\n\n\t\tif (options.filter && !options.filter(geojson)) { return this; }\n\n\t\tconst layer = GeoJSON.geometryToLayer(geojson, options);\n\t\tif (!layer) {\n\t\t\treturn this;\n\t\t}\n\t\tlayer.feature = GeoJSON.asFeature(geojson);\n\n\t\tlayer.defaultOptions = layer.options;\n\t\tthis.resetStyle(layer);\n\n\t\tif (options.onEachFeature) {\n\t\t\toptions.onEachFeature(geojson, layer);\n\t\t}\n\n\t\treturn this.addLayer(layer);\n\t}\n\n\t/**\n\t * Resets the given vector layer's style to the original GeoJSON style, useful for\n\t * resetting style after hover events. If `layer` is omitted, the style of all\n\t * features in the current layer is reset.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\tresetStyle(layer) {\n\t\tif (layer === undefined) {\n\t\t\treturn this.eachLayer(this.resetStyle, this);\n\t\t}\n\t\t// reset any custom styles\n\t\tlayer.options = Object.create(layer.defaultOptions);\n\t\tthis._setLayerStyle(layer, this.options.style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes styles of GeoJSON vector layers with the given style function.\n\t * @param {PathOptions|((geoJsonFeature: Feature) => PathOptions)} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\treturn this.eachLayer(layer => this._setLayerStyle(layer, style));\n\t}\n\n\t_setLayerStyle(layer, style) {\n\t\tif (layer.setStyle) {\n\t\t\tif (typeof style === 'function') {\n\t\t\t\tstyle = style(layer.feature);\n\t\t\t}\n\t\t\tlayer.setStyle(style);\n\t\t}\n\t}\n\n\t/**\n\t * Creates a `Layer` from a given GeoJSON feature. Can use a custom\n\t * [`pointToLayer`](#geojson-pointtolayer) and/or [`coordsToLatLng`](#geojson-coordstolatlng)\n\t * functions if provided as options.\n\t * @param {GeoJsonObject} geojson\n\t * @param {GeoJSONOptions} [options]\n\t * @returns {Layer|null}\n\t */\n\tstatic geometryToLayer(geojson, options) {\n\n\t\tconst geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,\n\t\tcoords = geometry?.coordinates,\n\t\tlayers = [],\n\t\tpointToLayer = options?.pointToLayer,\n\t\t_coordsToLatLng = options?.coordsToLatLng ?? GeoJSON.coordsToLatLng;\n\t\tlet latlng, latlngs;\n\n\t\tif (!coords && !geometry) {\n\t\t\treturn null;\n\t\t}\n\n\t\tswitch (geometry.type) {\n\t\tcase 'Point':\n\t\t\tlatlng = _coordsToLatLng(coords);\n\t\t\treturn GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options);\n\n\t\tcase 'MultiPoint':\n\t\t\tfor (const coord of coords) {\n\t\t\t\tlatlng = _coordsToLatLng(coord);\n\t\t\t\tlayers.push(GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options));\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'LineString':\n\t\tcase 'MultiLineString':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, _coordsToLatLng);\n\t\t\treturn new Polyline(latlngs, options);\n\n\t\tcase 'Polygon':\n\t\tcase 'MultiPolygon':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, _coordsToLatLng);\n\t\t\treturn new Polygon(latlngs, options);\n\n\t\tcase 'GeometryCollection':\n\t\t\tfor (const g of geometry.geometries) {\n\t\t\t\tconst geoLayer = GeoJSON.geometryToLayer({\n\t\t\t\t\tgeometry: g,\n\t\t\t\t\ttype: 'Feature',\n\t\t\t\t\tproperties: geojson.properties\n\t\t\t\t}, options);\n\n\t\t\t\tif (geoLayer) {\n\t\t\t\t\tlayers.push(geoLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'FeatureCollection':\n\t\t\tfor (const f of geometry.features) {\n\t\t\t\tconst featureLayer = GeoJSON.geometryToLayer(f, options);\n\n\t\t\t\tif (featureLayer) {\n\t\t\t\t\tlayers.push(featureLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tdefault:\n\t\t\tthrow new Error('Invalid GeoJSON object.');\n\t\t}\n\t}\n\n\tstatic _pointToLayer(pointToLayerFn, geojson, latlng, options) {\n\t\treturn pointToLayerFn ?\n\t\t\tpointToLayerFn(geojson, latlng) :\n\t\t\tnew Marker(latlng, options?.markersInheritOptions && options);\n\t}\n\n\t/**\n\t * Creates a `LatLng` object from an array of 2 numbers (longitude, latitude)\n\t * or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.\n\t * @param {number[]} coords\n\t * @returns {LatLng}\n\t */\n\tstatic coordsToLatLng(coords) {\n\t\treturn new LatLng(coords[1], coords[0], coords[2]);\n\t}\n\n\t/**\n\t * Creates a multidimensional array of `LatLng`s from a GeoJSON coordinates array.\n\t * `levelsDeep` specifies the nesting level (0 is for an array of points, 1 for an\n\t * array of arrays of points, etc., 0 by default).\n\t * Can use a custom [`coordsToLatLng`](#geojson-coordstolatlng) function.\n\t * @param {any[]} coords\n\t * @param {number} [levelsDeep]\n\t * @param {(coords: number[]) => LatLng} [_coordsToLatLng]\n\t * @returns {any[]}\n\t */\n\tstatic coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {\n\t\treturn coords.map(coord => (levelsDeep ?\n\t\t\tGeoJSON.coordsToLatLngs(coord, levelsDeep - 1, _coordsToLatLng) :\n\t\t\t(_coordsToLatLng || GeoJSON.coordsToLatLng)(coord)));\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLng`](#geojson-coordstolatlng).\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {LatLngExpression} latlng\n\t * @param {number|false} [precision]\n\t * @returns {number[]}\n\t */\n\tstatic latLngToCoords(latlng, precision) {\n\t\tlatlng = LatLng.from(latlng);\n\t\treturn latlng.alt !== undefined ?\n\t\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :\n\t\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs).\n\t * `close` determines whether the first point should be appended to the end of the\n\t * array to close the feature, only used when `levelsDeep` is 0. False by default.\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {any[]} latlngs\n\t * @param {number} [levelsDeep]\n\t * @param {boolean} [close]\n\t * @param {number|false} [precision]\n\t * @returns {any[]}\n\t */\n\tstatic latLngsToCoords(latlngs, levelsDeep, close, precision) {\n\t\t// Check for flat arrays required to ensure unbalanced arrays are correctly converted in recursion\n\t\tconst coords = latlngs.map(latlng => (levelsDeep ?\n\t\t\tGeoJSON.latLngsToCoords(latlng, LineUtil.isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) :\n\t\t\tGeoJSON.latLngToCoords(latlng, precision)));\n\n\t\tif (!levelsDeep && close && coords.length > 0) {\n\t\t\tcoords.push(coords[0].slice());\n\t\t}\n\n\t\treturn coords;\n\t}\n\n\t/**\n\t * Returns GeoJSON geometries/features of layer with new GeoJSON geometry.\n\t * @param {Layer} layer\n\t * @param {Geometry} newGeometry\n\t * @returns {Feature}\n\t */\n\tstatic getFeature(layer, newGeometry) {\n\t\treturn layer.feature ?\n\t\t\t{...layer.feature, geometry: newGeometry} :\n\t\t\tGeoJSON.asFeature(newGeometry);\n\t}\n\n\t/**\n\t * Normalize GeoJSON geometries/features into GeoJSON features.\n\t * @param {GeoJsonObject} geojson\n\t * @returns {Feature|FeatureCollection}\n\t */\n\tstatic asFeature(geojson) {\n\t\tif (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') {\n\t\t\treturn geojson;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'Feature',\n\t\t\tproperties: {},\n\t\t\tgeometry: geojson\n\t\t};\n\t}\n\n}\n\n/**\n * Methods of `Marker` (and `CircleMarker`, `Circle`) for GeoJSON.\n * @lends Marker.prototype\n */\nconst PointToGeoJSON = {\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 marker (as a GeoJSON `Point` Feature).\n\t * @group Other methods\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: 'Point',\n\t\t\tcoordinates: GeoJSON.latLngToCoords(this.getLatLng(), precision)\n\t\t});\n\t}\n};\n/** @typedef {typeof PointToGeoJSON} PointToGeoJSONMethods */\n\n/**\n * Methods of `CircleMarker` (and `Circle`) for GeoJSON: `toGeoJSON(precision?)`\n * returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the\n * circle marker (as a GeoJSON `Point` Feature), with the coordinates values rounded\n * with [`formatNum`](#util-formatnum) function with given `precision`.\n * @typedef {object} CircleMarkerToGeoJSONMethods\n * @extends PointToGeoJSONMethods\n * @lends CircleMarker\n */\n\nMarker.include(PointToGeoJSON);\nCircle.include(PointToGeoJSON);\nCircleMarker.include(PointToGeoJSON);\n\n/**\n * Methods of `Polyline` for GeoJSON.\n * @lends Polyline.prototype\n */\nconst polylineToGeoJSON = {\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 = GeoJSON.latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}LineString`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n};\n/** @typedef {typeof polylineToGeoJSON} PolylineToGeoJSONMethods */\n\nPolyline.include(polylineToGeoJSON);\n\n/**\n * Methods of `Polygon` for GeoJSON.\n * @lends Polygon.prototype\n */\nconst polygonToGeoJSON = {\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 = GeoJSON.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 GeoJSON.getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}Polygon`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n};\n/** @typedef {typeof polygonToGeoJSON} PolygonToGeoJSONMethods */\n\nPolygon.include(polygonToGeoJSON);\n\n/**\n * Methods of `LayerGroup` for GeoJSON.\n * @lends LayerGroup.prototype\n */\nconst layerGroupToGeoJSON = {\n\t/**\n\t * Returns a GeoJSON `MultiPoint` Feature of the points of the group, used by\n\t * `toGeoJSON()`.\n\t * @internal\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoMultiPoint(precision) {\n\t\tconst coords = [];\n\n\t\tthis.eachLayer((layer) => {\n\t\t\tcoords.push(layer.toGeoJSON(precision).geometry.coordinates);\n\t\t});\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: 'MultiPoint',\n\t\t\tcoordinates: coords\n\t\t});\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 layer group (as a GeoJSON `FeatureCollection`,\n\t * `GeometryCollection`, or `MultiPoint`).\n\t * @param {number|false} [precision]\n\t * @returns {Feature|FeatureCollection}\n\t */\n\ttoGeoJSON(precision) {\n\n\t\tconst type = this.feature?.geometry?.type;\n\n\t\tif (type === 'MultiPoint') {\n\t\t\treturn this.toMultiPoint(precision);\n\t\t}\n\n\t\tconst isGeometryCollection = type === 'GeometryCollection',\n\t\tjsons = [];\n\n\t\tthis.eachLayer((layer) => {\n\t\t\tif (layer.toGeoJSON) {\n\t\t\t\tconst json = layer.toGeoJSON(precision);\n\t\t\t\tif (isGeometryCollection) {\n\t\t\t\t\tjsons.push(json.geometry);\n\t\t\t\t} else {\n\t\t\t\t\tconst feature = GeoJSON.asFeature(json);\n\t\t\t\t\t// Squash nested feature collections\n\t\t\t\t\tif (feature.type === 'FeatureCollection') {\n\t\t\t\t\t\tjsons.push(...feature.features);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tjsons.push(feature);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tif (isGeometryCollection) {\n\t\t\treturn GeoJSON.getFeature(this, {\n\t\t\t\tgeometries: jsons,\n\t\t\t\ttype: 'GeometryCollection'\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\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