@xylabs/geo 4.4.35

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 (95) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +69 -0
  3. package/dist/neutral/GeoJson.d.ts +25 -0
  4. package/dist/neutral/GeoJson.d.ts.map +1 -0
  5. package/dist/neutral/LayerBase.d.ts +9 -0
  6. package/dist/neutral/LayerBase.d.ts.map +1 -0
  7. package/dist/neutral/index.d.ts +4 -0
  8. package/dist/neutral/index.d.ts.map +1 -0
  9. package/dist/neutral/index.mjs +322 -0
  10. package/dist/neutral/index.mjs.map +1 -0
  11. package/dist/neutral/mercator/boundingbox/index.d.ts +2 -0
  12. package/dist/neutral/mercator/boundingbox/index.d.ts.map +1 -0
  13. package/dist/neutral/mercator/boundingbox/to/boundary.d.ts +3 -0
  14. package/dist/neutral/mercator/boundingbox/to/boundary.d.ts.map +1 -0
  15. package/dist/neutral/mercator/boundingbox/to/center.d.ts +3 -0
  16. package/dist/neutral/mercator/boundingbox/to/center.d.ts.map +1 -0
  17. package/dist/neutral/mercator/boundingbox/to/index.d.ts +4 -0
  18. package/dist/neutral/mercator/boundingbox/to/index.d.ts.map +1 -0
  19. package/dist/neutral/mercator/boundingbox/to/polygon.d.ts +4 -0
  20. package/dist/neutral/mercator/boundingbox/to/polygon.d.ts.map +1 -0
  21. package/dist/neutral/mercator/constants.d.ts +4 -0
  22. package/dist/neutral/mercator/constants.d.ts.map +1 -0
  23. package/dist/neutral/mercator/index.d.ts +6 -0
  24. package/dist/neutral/mercator/index.d.ts.map +1 -0
  25. package/dist/neutral/mercator/tile/from/index.d.ts +3 -0
  26. package/dist/neutral/mercator/tile/from/index.d.ts.map +1 -0
  27. package/dist/neutral/mercator/tile/from/point.d.ts +4 -0
  28. package/dist/neutral/mercator/tile/from/point.d.ts.map +1 -0
  29. package/dist/neutral/mercator/tile/from/quadkey.d.ts +3 -0
  30. package/dist/neutral/mercator/tile/from/quadkey.d.ts.map +1 -0
  31. package/dist/neutral/mercator/tile/index.d.ts +3 -0
  32. package/dist/neutral/mercator/tile/index.d.ts.map +1 -0
  33. package/dist/neutral/mercator/tile/to/boundingbox.d.ts +5 -0
  34. package/dist/neutral/mercator/tile/to/boundingbox.d.ts.map +1 -0
  35. package/dist/neutral/mercator/tile/to/children.d.ts +4 -0
  36. package/dist/neutral/mercator/tile/to/children.d.ts.map +1 -0
  37. package/dist/neutral/mercator/tile/to/geoJson.d.ts +5 -0
  38. package/dist/neutral/mercator/tile/to/geoJson.d.ts.map +1 -0
  39. package/dist/neutral/mercator/tile/to/index.d.ts +8 -0
  40. package/dist/neutral/mercator/tile/to/index.d.ts.map +1 -0
  41. package/dist/neutral/mercator/tile/to/parent.d.ts +4 -0
  42. package/dist/neutral/mercator/tile/to/parent.d.ts.map +1 -0
  43. package/dist/neutral/mercator/tile/to/point.d.ts +4 -0
  44. package/dist/neutral/mercator/tile/to/point.d.ts.map +1 -0
  45. package/dist/neutral/mercator/tile/to/quadkey.d.ts +4 -0
  46. package/dist/neutral/mercator/tile/to/quadkey.d.ts.map +1 -0
  47. package/dist/neutral/mercator/tile/to/siblings.d.ts +4 -0
  48. package/dist/neutral/mercator/tile/to/siblings.d.ts.map +1 -0
  49. package/dist/neutral/mercator/tiles/equal.d.ts +4 -0
  50. package/dist/neutral/mercator/tiles/equal.d.ts.map +1 -0
  51. package/dist/neutral/mercator/tiles/from/boundingbox.d.ts +4 -0
  52. package/dist/neutral/mercator/tiles/from/boundingbox.d.ts.map +1 -0
  53. package/dist/neutral/mercator/tiles/from/index.d.ts +2 -0
  54. package/dist/neutral/mercator/tiles/from/index.d.ts.map +1 -0
  55. package/dist/neutral/mercator/tiles/hasSiblings.d.ts +4 -0
  56. package/dist/neutral/mercator/tiles/hasSiblings.d.ts.map +1 -0
  57. package/dist/neutral/mercator/tiles/hasTile.d.ts +4 -0
  58. package/dist/neutral/mercator/tiles/hasTile.d.ts.map +1 -0
  59. package/dist/neutral/mercator/tiles/index.d.ts +4 -0
  60. package/dist/neutral/mercator/tiles/index.d.ts.map +1 -0
  61. package/dist/neutral/mercator/types.d.ts +10 -0
  62. package/dist/neutral/mercator/types.d.ts.map +1 -0
  63. package/package.json +53 -0
  64. package/src/GeoJson.spec.ts +12 -0
  65. package/src/GeoJson.ts +104 -0
  66. package/src/LayerBase.ts +22 -0
  67. package/src/index.ts +3 -0
  68. package/src/mercator/boundingbox/index.ts +1 -0
  69. package/src/mercator/boundingbox/to/boundary.ts +5 -0
  70. package/src/mercator/boundingbox/to/center.ts +15 -0
  71. package/src/mercator/boundingbox/to/index.ts +3 -0
  72. package/src/mercator/boundingbox/to/polygon.ts +12 -0
  73. package/src/mercator/constants.ts +4 -0
  74. package/src/mercator/index.ts +5 -0
  75. package/src/mercator/tile/from/index.ts +2 -0
  76. package/src/mercator/tile/from/point.ts +29 -0
  77. package/src/mercator/tile/from/quadkey.ts +19 -0
  78. package/src/mercator/tile/index.ts +2 -0
  79. package/src/mercator/tile/to/boundingbox.ts +24 -0
  80. package/src/mercator/tile/to/children.ts +12 -0
  81. package/src/mercator/tile/to/geoJson.ts +23 -0
  82. package/src/mercator/tile/to/index.ts +7 -0
  83. package/src/mercator/tile/to/parent.ts +7 -0
  84. package/src/mercator/tile/to/point.ts +10 -0
  85. package/src/mercator/tile/to/quadkey.ts +15 -0
  86. package/src/mercator/tile/to/siblings.ts +9 -0
  87. package/src/mercator/tiles/equal.ts +7 -0
  88. package/src/mercator/tiles/from/boundingbox.ts +37 -0
  89. package/src/mercator/tiles/from/index.ts +1 -0
  90. package/src/mercator/tiles/hasSiblings.ts +13 -0
  91. package/src/mercator/tiles/hasTile.ts +11 -0
  92. package/src/mercator/tiles/index.ts +3 -0
  93. package/src/mercator/types.ts +9 -0
  94. package/typedoc.json +5 -0
  95. package/xy.config.ts +10 -0
@@ -0,0 +1,7 @@
1
+ import type { MercatorTile } from '../../types.ts'
2
+
3
+ const tileToParent = (tile: MercatorTile): MercatorTile => {
4
+ return [tile[0] >> 1, tile[1] >> 1, tile[2] - 1]
5
+ }
6
+
7
+ export { tileToParent }
@@ -0,0 +1,10 @@
1
+ import type { MercatorLngLat, MercatorTile } from '../../types.ts'
2
+ import { tileToBoundingBox } from './boundingbox.ts'
3
+
4
+ const tileToPoint = (tile: MercatorTile): MercatorLngLat => {
5
+ const boundingBox = tileToBoundingBox(tile)
6
+ boundingBox.getCenter()
7
+ return boundingBox.getCenter()
8
+ }
9
+
10
+ export { tileToPoint }
@@ -0,0 +1,15 @@
1
+ import type { MercatorTile } from '../../types.ts'
2
+
3
+ const tileToQuadkey = (tile: MercatorTile): string => {
4
+ let index = ''
5
+ for (let z = tile[2]; z > 0; z--) {
6
+ let b = 0
7
+ const mask = 1 << (z - 1)
8
+ if ((tile[0] & mask) !== 0) b++
9
+ if ((tile[1] & mask) !== 0) b += 2
10
+ index += b.toString()
11
+ }
12
+ return index
13
+ }
14
+
15
+ export { tileToQuadkey }
@@ -0,0 +1,9 @@
1
+ import type { MercatorTile } from '../../types.ts'
2
+ import { tileToChildren } from './children.ts'
3
+ import { tileToParent } from './parent.ts'
4
+
5
+ const tileToSiblings = (tile: MercatorTile): MercatorTile[] => {
6
+ return tileToChildren(tileToParent(tile))
7
+ }
8
+
9
+ export { tileToSiblings }
@@ -0,0 +1,7 @@
1
+ import type { MercatorTile } from '../types.ts'
2
+
3
+ const tilesEqual = (tile1: MercatorTile, tile2: MercatorTile) => {
4
+ return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2]
5
+ }
6
+
7
+ export { tilesEqual }
@@ -0,0 +1,37 @@
1
+ import { tileFromPoint } from '../../tile/index.ts'
2
+ import type { MercatorBoundingBox, MercatorTile } from '../../types.ts'
3
+
4
+ const tilesFromBoundingBox = (box: MercatorBoundingBox, zoom: number): MercatorTile[] => {
5
+ const nw = tileFromPoint(box.getNorthWest(), zoom)
6
+ const se = tileFromPoint(box.getSouthEast(), zoom)
7
+ const size = Math.pow(2, zoom)
8
+
9
+ let minX = nw[0]
10
+ let maxX = se[0]
11
+ let minY = nw[1]
12
+ let maxY = se[1]
13
+
14
+ // in case of horizontal wrapping
15
+ if (minX >= maxX) {
16
+ maxX = maxX + size
17
+ }
18
+
19
+ if (zoom < 4) {
20
+ minX = 0
21
+ maxX = size - 1
22
+ minY = 0
23
+ maxY = size - 1
24
+ }
25
+
26
+ const result: MercatorTile[] = []
27
+
28
+ for (let x = minX; x <= maxX; x++) {
29
+ for (let y = minY; y <= maxY; y++) {
30
+ result.push([x % size, y, zoom])
31
+ }
32
+ }
33
+
34
+ return result
35
+ }
36
+
37
+ export { tilesFromBoundingBox }
@@ -0,0 +1 @@
1
+ export { tilesFromBoundingBox } from './boundingbox.ts'
@@ -0,0 +1,13 @@
1
+ import { tileToSiblings } from '../tile/index.ts'
2
+ import type { MercatorTile } from '../types.ts'
3
+ import { tilesHasTile } from './hasTile.ts'
4
+
5
+ const hasSiblings = (tiles: MercatorTile[], tile: MercatorTile) => {
6
+ const siblings = tileToSiblings(tile)
7
+ for (const sibling of siblings) {
8
+ if (!tilesHasTile(tiles, sibling)) return false
9
+ }
10
+ return true
11
+ }
12
+
13
+ export { hasSiblings }
@@ -0,0 +1,11 @@
1
+ import type { MercatorTile } from '../types.ts'
2
+ import { tilesEqual } from './equal.ts'
3
+
4
+ const tilesHasTile = (tiles: MercatorTile[], tile: MercatorTile) => {
5
+ for (const tileToCheck of tiles) {
6
+ if (tilesEqual(tileToCheck, tile)) return true
7
+ }
8
+ return false
9
+ }
10
+
11
+ export { tilesHasTile }
@@ -0,0 +1,3 @@
1
+ export { tilesEqual } from './equal.ts'
2
+ export * from './from/index.ts'
3
+ export { tilesHasTile } from './hasTile.ts'
@@ -0,0 +1,9 @@
1
+ import MapBox from 'mapbox-gl'
2
+
3
+ type MercatorTile = number[]
4
+ type MercatorBoundary = MercatorLngLat[]
5
+ class MercatorBoundingBox extends MapBox.LngLatBounds {}
6
+ class MercatorLngLat extends MapBox.LngLat {}
7
+
8
+ export { MercatorBoundingBox, MercatorLngLat }
9
+ export type { MercatorBoundary, MercatorTile }
package/typedoc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://typedoc.org/schema.json",
3
+ "entryPoints": ["src/index.ts"],
4
+ "tsconfig": "./tsconfig.typedoc.json"
5
+ }
package/xy.config.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
+ const config: XyTsupConfig = {
3
+ compile: {
4
+ browser: {},
5
+ neutral: { src: true },
6
+ node: {},
7
+ },
8
+ }
9
+
10
+ export default config