@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,4 @@
1
+ export { boundingBoxToBoundary } from './boundary.ts';
2
+ export { boundingBoxToCenter } from './center.ts';
3
+ export { boundingBoxToPolygon } from './polygon.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/boundingbox/to/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { Polygon } from 'geojson';
2
+ import type { MercatorBoundingBox } from '../../types.ts';
3
+ export declare const boundingBoxToPolygon: (box: MercatorBoundingBox) => Polygon;
4
+ //# sourceMappingURL=polygon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/boundingbox/to/polygon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,KAAK,EAAE,mBAAmB,EAAkB,MAAM,gBAAgB,CAAA;AAGzE,eAAO,MAAM,oBAAoB,QAAS,mBAAmB,KAAG,OAM/D,CAAA"}
@@ -0,0 +1,4 @@
1
+ declare const d2r: number;
2
+ declare const r2d: number;
3
+ export { d2r, r2d };
4
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/mercator/constants.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,GAAG,QAAgB,CAAA;AACzB,QAAA,MAAM,GAAG,QAAgB,CAAA;AAEzB,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from './boundingbox/index.ts';
2
+ export * from './constants.ts';
3
+ export * from './tile/index.ts';
4
+ export * from './tiles/index.ts';
5
+ export * from './types.ts';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mercator/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { tileFromPoint } from './point.ts';
2
+ export { tileFromQuadkey } from './quadkey.ts';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/from/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { MercatorLngLat } from '../../types.ts';
2
+ declare const tileFromPoint: (point: MercatorLngLat, z: number) => number[];
3
+ export { tileFromPoint };
4
+ //# sourceMappingURL=point.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/from/point.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAcpD,QAAA,MAAM,aAAa,UAAW,cAAc,KAAK,MAAM,aAWtD,CAAA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
@@ -0,0 +1,3 @@
1
+ declare const tileFromQuadkey: (quadkey: string) => number[];
2
+ export { tileFromQuadkey };
3
+ //# sourceMappingURL=quadkey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quadkey.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/from/quadkey.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,eAAe,YAAa,MAAM,aAgBvC,CAAA;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './from/index.ts';
2
+ export * from './to/index.ts';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/mercator/tile/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { MercatorTile } from '../../types.ts';
2
+ import { MercatorBoundingBox } from '../../types.ts';
3
+ declare const tileToBoundingBox: (tile: MercatorTile) => MercatorBoundingBox;
4
+ export { tileToBoundingBox };
5
+ //# sourceMappingURL=boundingbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boundingbox.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/to/boundingbox.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAWpD,QAAA,MAAM,iBAAiB,SAAU,YAAY,KAAG,mBAM/C,CAAA;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { MercatorTile } from '../../types.ts';
2
+ declare const tileToChildren: (tile: MercatorTile) => number[][];
3
+ export { tileToChildren };
4
+ //# sourceMappingURL=children.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"children.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/to/children.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,QAAA,MAAM,cAAc,SAAU,YAAY,eAOzC,CAAA;AAED,OAAO,EAAE,cAAc,EAAE,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { Polygon } from 'geojson';
2
+ import type { MercatorTile } from '../../types.ts';
3
+ declare const tileToGeoJson: (tile: MercatorTile) => Polygon;
4
+ export { tileToGeoJson };
5
+ //# sourceMappingURL=geoJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geoJson.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/to/geoJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAY,MAAM,SAAS,CAAA;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAGlD,QAAA,MAAM,aAAa,SAAU,YAAY,KAAG,OAe3C,CAAA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
@@ -0,0 +1,8 @@
1
+ export { tileToBoundingBox } from './boundingbox.ts';
2
+ export { tileToChildren } from './children.ts';
3
+ export { tileToGeoJson } from './geoJson.ts';
4
+ export { tileToParent } from './parent.ts';
5
+ export { tileToPoint } from './point.ts';
6
+ export { tileToQuadkey } from './quadkey.ts';
7
+ export { tileToSiblings } from './siblings.ts';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/to/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { MercatorTile } from '../../types.ts';
2
+ declare const tileToParent: (tile: MercatorTile) => MercatorTile;
3
+ export { tileToParent };
4
+ //# sourceMappingURL=parent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parent.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/to/parent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,QAAA,MAAM,YAAY,SAAU,YAAY,KAAG,YAE1C,CAAA;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { MercatorLngLat, MercatorTile } from '../../types.ts';
2
+ declare const tileToPoint: (tile: MercatorTile) => MercatorLngLat;
3
+ export { tileToPoint };
4
+ //# sourceMappingURL=point.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/to/point.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAGlE,QAAA,MAAM,WAAW,SAAU,YAAY,KAAG,cAIzC,CAAA;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { MercatorTile } from '../../types.ts';
2
+ declare const tileToQuadkey: (tile: MercatorTile) => string;
3
+ export { tileToQuadkey };
4
+ //# sourceMappingURL=quadkey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quadkey.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/to/quadkey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,QAAA,MAAM,aAAa,SAAU,YAAY,KAAG,MAU3C,CAAA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { MercatorTile } from '../../types.ts';
2
+ declare const tileToSiblings: (tile: MercatorTile) => MercatorTile[];
3
+ export { tileToSiblings };
4
+ //# sourceMappingURL=siblings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"siblings.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/to/siblings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAIlD,QAAA,MAAM,cAAc,SAAU,YAAY,KAAG,YAAY,EAExD,CAAA;AAED,OAAO,EAAE,cAAc,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { MercatorTile } from '../types.ts';
2
+ declare const tilesEqual: (tile1: MercatorTile, tile2: MercatorTile) => boolean;
3
+ export { tilesEqual };
4
+ //# sourceMappingURL=equal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"equal.d.ts","sourceRoot":"","sources":["../../../../src/mercator/tiles/equal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,QAAA,MAAM,UAAU,UAAW,YAAY,SAAS,YAAY,YAE3D,CAAA;AAED,OAAO,EAAE,UAAU,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { MercatorBoundingBox, MercatorTile } from '../../types.ts';
2
+ declare const tilesFromBoundingBox: (box: MercatorBoundingBox, zoom: number) => MercatorTile[];
3
+ export { tilesFromBoundingBox };
4
+ //# sourceMappingURL=boundingbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boundingbox.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tiles/from/boundingbox.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAEvE,QAAA,MAAM,oBAAoB,QAAS,mBAAmB,QAAQ,MAAM,KAAG,YAAY,EA+BlF,CAAA;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { tilesFromBoundingBox } from './boundingbox.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tiles/from/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { MercatorTile } from '../types.ts';
2
+ declare const hasSiblings: (tiles: MercatorTile[], tile: MercatorTile) => boolean;
3
+ export { hasSiblings };
4
+ //# sourceMappingURL=hasSiblings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasSiblings.d.ts","sourceRoot":"","sources":["../../../../src/mercator/tiles/hasSiblings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG/C,QAAA,MAAM,WAAW,UAAW,YAAY,EAAE,QAAQ,YAAY,YAM7D,CAAA;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { MercatorTile } from '../types.ts';
2
+ declare const tilesHasTile: (tiles: MercatorTile[], tile: MercatorTile) => boolean;
3
+ export { tilesHasTile };
4
+ //# sourceMappingURL=hasTile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasTile.d.ts","sourceRoot":"","sources":["../../../../src/mercator/tiles/hasTile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG/C,QAAA,MAAM,YAAY,UAAW,YAAY,EAAE,QAAQ,YAAY,YAK9D,CAAA;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { tilesEqual } from './equal.ts';
2
+ export * from './from/index.ts';
3
+ export { tilesHasTile } from './hasTile.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/mercator/tiles/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,10 @@
1
+ import MapBox from 'mapbox-gl';
2
+ type MercatorTile = number[];
3
+ type MercatorBoundary = MercatorLngLat[];
4
+ declare class MercatorBoundingBox extends MapBox.LngLatBounds {
5
+ }
6
+ declare class MercatorLngLat extends MapBox.LngLat {
7
+ }
8
+ export { MercatorBoundingBox, MercatorLngLat };
9
+ export type { MercatorBoundary, MercatorTile };
10
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/mercator/types.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,WAAW,CAAA;AAE9B,KAAK,YAAY,GAAG,MAAM,EAAE,CAAA;AAC5B,KAAK,gBAAgB,GAAG,cAAc,EAAE,CAAA;AACxC,cAAM,mBAAoB,SAAQ,MAAM,CAAC,YAAY;CAAG;AACxD,cAAM,cAAe,SAAQ,MAAM,CAAC,MAAM;CAAG;AAE7C,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,CAAA;AAC9C,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,CAAA"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@xylabs/geo",
3
+ "version": "4.4.35",
4
+ "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
+ "keywords": [
6
+ "xylabs",
7
+ "utility",
8
+ "typescript",
9
+ "esm"
10
+ ],
11
+ "homepage": "https://xylabs.com",
12
+ "bugs": {
13
+ "url": "git+https://github.com/xylabs/sdk-js/issues",
14
+ "email": "support@xylabs.com"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/xylabs/sdk-js.git"
19
+ },
20
+ "license": "LGPL-3.0-only",
21
+ "author": {
22
+ "name": "XY Labs Development Team",
23
+ "email": "support@xylabs.com",
24
+ "url": "https://xylabs.com"
25
+ },
26
+ "sideEffects": false,
27
+ "type": "module",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/neutral/index.d.ts",
31
+ "import": "./dist/neutral/index.mjs"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "module": "dist/neutral/index.mjs",
36
+ "types": "dist/neutral/index.d.ts",
37
+ "dependencies": {
38
+ "geojson": "^0.5.0",
39
+ "mapbox-gl": "^3.9.1"
40
+ },
41
+ "devDependencies": {
42
+ "@types/geojson": "^7946.0.15",
43
+ "@xylabs/ts-scripts-yarn3": "^4.2.6",
44
+ "@xylabs/tsconfig": "^4.2.6",
45
+ "typescript": "^5.7.2",
46
+ "vitest": "^2.1.8"
47
+ },
48
+ "packageManager": "yarn@3.2.0",
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "docs": "dist/docs.json"
53
+ }
@@ -0,0 +1,12 @@
1
+ import {
2
+ describe, expect, it,
3
+ } from 'vitest'
4
+
5
+ import { GeoJson } from './GeoJson.ts'
6
+
7
+ describe('GeoJson', () => {
8
+ it('constructor', () => {
9
+ const instance = new GeoJson('0')
10
+ expect(instance).toBeDefined()
11
+ })
12
+ })
package/src/GeoJson.ts ADDED
@@ -0,0 +1,104 @@
1
+ import type {
2
+ Feature, FeatureCollection, Geometry, Point, Polygon,
3
+ } from 'geojson'
4
+ import MapBox from 'mapbox-gl'
5
+
6
+ import {
7
+ boundingBoxToCenter, boundingBoxToPolygon, tileFromQuadkey, tileToBoundingBox,
8
+ } from './mercator/index.ts'
9
+
10
+ class GeoJson {
11
+ private _lngLat?: MapBox.LngLat
12
+ private _point?: Point
13
+ private _polygon?: Polygon
14
+ private _zoom?: number
15
+
16
+ private quadkey: string
17
+
18
+ constructor(quadkey: string) {
19
+ this.quadkey = quadkey
20
+ }
21
+
22
+ static featureCollection(features: Feature[]): FeatureCollection {
23
+ return {
24
+ features,
25
+ type: 'FeatureCollection',
26
+ }
27
+ }
28
+
29
+ static featuresSource(data: FeatureCollection): MapBox.GeoJSONSourceSpecification {
30
+ return {
31
+ data,
32
+ type: 'geojson',
33
+ }
34
+ }
35
+
36
+ static geometryFeature(geometry: Geometry): Feature {
37
+ return {
38
+ geometry,
39
+ properties: {},
40
+ type: 'Feature',
41
+ }
42
+ }
43
+
44
+ center(): MapBox.LngLat {
45
+ if (!this._lngLat) {
46
+ const tile = tileFromQuadkey(this.quadkey)
47
+ const bb = tileToBoundingBox(tile)
48
+ const point = boundingBoxToCenter(bb)
49
+ this._lngLat = new MapBox.LngLat(point[0], point[1])
50
+ }
51
+ return this._lngLat
52
+ }
53
+
54
+ point(): Point {
55
+ if (!this._point) {
56
+ this._point = {
57
+ coordinates: this.center().toArray(),
58
+ type: 'Point',
59
+ }
60
+ }
61
+ return this._point
62
+ }
63
+
64
+ pointFeature(): Feature {
65
+ return GeoJson.geometryFeature(this.point())
66
+ }
67
+
68
+ pointFeatureCollection(): FeatureCollection {
69
+ return GeoJson.featureCollection([this.pointFeature()])
70
+ }
71
+
72
+ pointSource(): MapBox.GeoJSONSourceSpecification {
73
+ return {
74
+ data: this.pointFeatureCollection(),
75
+ type: 'geojson',
76
+ }
77
+ }
78
+
79
+ polygon(): Polygon {
80
+ if (!this._polygon) {
81
+ this._polygon = boundingBoxToPolygon(tileToBoundingBox(tileFromQuadkey(this.quadkey))) as Polygon
82
+ }
83
+ return this._polygon
84
+ }
85
+
86
+ polygonFeature(): Feature {
87
+ return GeoJson.geometryFeature(this.polygon())
88
+ }
89
+
90
+ polygonFeatureCollection(): FeatureCollection {
91
+ return GeoJson.featureCollection([this.polygonFeature()])
92
+ }
93
+
94
+ polygonSource(): MapBox.GeoJSONSourceSpecification {
95
+ return GeoJson.featuresSource(this.polygonFeatureCollection())
96
+ }
97
+
98
+ zoom(): number {
99
+ this._zoom = this._zoom ?? tileFromQuadkey(this.quadkey)[2]
100
+ return this._zoom
101
+ }
102
+ }
103
+
104
+ export { GeoJson }
@@ -0,0 +1,22 @@
1
+ import type MapBox from 'mapbox-gl'
2
+
3
+ export abstract class LayerBase<T extends MapBox.Layer> {
4
+ id: string
5
+ source: string
6
+
7
+ constructor(id: string, source: string) {
8
+ this.id = id
9
+ this.source = source
10
+ }
11
+
12
+ update(map: MapBox.Map, show = true) {
13
+ if (map.getLayer(this.id)) {
14
+ map.removeLayer(this.id)
15
+ }
16
+ if (show) {
17
+ map.addLayer(this.buildLayer())
18
+ }
19
+ }
20
+
21
+ abstract buildLayer(): T
22
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './GeoJson.ts'
2
+ export * from './LayerBase.ts'
3
+ export * from './mercator/index.ts'
@@ -0,0 +1 @@
1
+ export * from './to/index.ts'
@@ -0,0 +1,5 @@
1
+ import type { MercatorBoundary, MercatorBoundingBox } from '../../types.ts'
2
+
3
+ export const boundingBoxToBoundary = (box: MercatorBoundingBox): MercatorBoundary => {
4
+ return [box.getNorthWest(), box.getNorthEast(), box.getSouthEast(), box.getSouthWest(), box.getNorthWest()]
5
+ }
@@ -0,0 +1,15 @@
1
+ import type { MercatorBoundingBox } from '../../types.ts'
2
+
3
+ export const boundingBoxToCenter = (boundingBox: MercatorBoundingBox, decimal = 6) => {
4
+ const west = boundingBox.getWest()
5
+ const south = boundingBox.getSouth()
6
+ const east = boundingBox.getEast()
7
+ const north = boundingBox.getNorth()
8
+ let lng = (west - east) / 2 + east
9
+ let lat = (south - north) / 2 + north
10
+ if (decimal !== undefined && decimal !== null) {
11
+ lng = Number(lng.toFixed(decimal))
12
+ lat = Number(lat.toFixed(decimal))
13
+ }
14
+ return [lng, lat]
15
+ }
@@ -0,0 +1,3 @@
1
+ export { boundingBoxToBoundary } from './boundary.ts'
2
+ export { boundingBoxToCenter } from './center.ts'
3
+ export { boundingBoxToPolygon } from './polygon.ts'
@@ -0,0 +1,12 @@
1
+ import type { Polygon } from 'geojson'
2
+
3
+ import type { MercatorBoundingBox, MercatorLngLat } from '../../types.ts'
4
+ import { boundingBoxToBoundary } from './boundary.ts'
5
+
6
+ export const boundingBoxToPolygon = (box: MercatorBoundingBox): Polygon => {
7
+ const boundry = boundingBoxToBoundary(box)
8
+ return {
9
+ coordinates: [boundry.map((lnglng: MercatorLngLat) => lnglng.toArray())],
10
+ type: 'Polygon',
11
+ }
12
+ }
@@ -0,0 +1,4 @@
1
+ const d2r = Math.PI / 180
2
+ const r2d = 180 / Math.PI
3
+
4
+ export { d2r, r2d }
@@ -0,0 +1,5 @@
1
+ export * from './boundingbox/index.ts'
2
+ export * from './constants.ts'
3
+ export * from './tile/index.ts'
4
+ export * from './tiles/index.ts'
5
+ export * from './types.ts'
@@ -0,0 +1,2 @@
1
+ export { tileFromPoint } from './point.ts'
2
+ export { tileFromQuadkey } from './quadkey.ts'
@@ -0,0 +1,29 @@
1
+ import { d2r } from '../../constants.ts'
2
+ import type { MercatorLngLat } from '../../types.ts'
3
+
4
+ const pointToTileFraction = (point: MercatorLngLat, z: number) => {
5
+ const sin = Math.sin(point.lat * d2r)
6
+ const z2 = Math.pow(2, z)
7
+ let x = z2 * (point.lng / 360 + 0.5)
8
+ const y = z2 * (0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI)
9
+
10
+ // Wrap Tile X
11
+ x = x % z2
12
+ if (x < 0) x = x + z2
13
+ return [x, y, z]
14
+ }
15
+
16
+ const tileFromPoint = (point: MercatorLngLat, z: number) => {
17
+ const tile = pointToTileFraction(point, z)
18
+ tile[0] = Math.floor(tile[0])
19
+ tile[1] = Math.floor(tile[1])
20
+ if (tile[0] < 0) {
21
+ tile[0] = 0
22
+ }
23
+ if (tile[1] < 0) {
24
+ tile[1] = 0
25
+ }
26
+ return tile
27
+ }
28
+
29
+ export { tileFromPoint }
@@ -0,0 +1,19 @@
1
+ const tileFromQuadkey = (quadkey: string) => {
2
+ let x = 0
3
+ let y = 0
4
+ const z = quadkey.length
5
+
6
+ for (let i = z; i > 0; i--) {
7
+ const mask = 1 << (i - 1)
8
+ const q = +quadkey[z - i]
9
+ if (q === 1) x |= mask
10
+ if (q === 2) y |= mask
11
+ if (q === 3) {
12
+ x |= mask
13
+ y |= mask
14
+ }
15
+ }
16
+ return [x, y, z]
17
+ }
18
+
19
+ export { tileFromQuadkey }
@@ -0,0 +1,2 @@
1
+ export * from './from/index.ts'
2
+ export * from './to/index.ts'
@@ -0,0 +1,24 @@
1
+ import MapBox from 'mapbox-gl'
2
+
3
+ import { r2d } from '../../constants.ts'
4
+ import type { MercatorTile } from '../../types.ts'
5
+ import { MercatorBoundingBox } from '../../types.ts'
6
+
7
+ const toLongitude = (x: number, z: number): number => {
8
+ return (x / Math.pow(2, z)) * 360 - 180
9
+ }
10
+
11
+ const toLatitude = (y: number, z: number): number => {
12
+ const n = Math.PI - (2 * Math.PI * y) / Math.pow(2, z)
13
+ return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)))
14
+ }
15
+
16
+ const tileToBoundingBox = (tile: MercatorTile): MercatorBoundingBox => {
17
+ const e = toLongitude(tile[0] + 1, tile[2])
18
+ const w = toLongitude(tile[0], tile[2])
19
+ const s = toLatitude(tile[1] + 1, tile[2])
20
+ const n = toLatitude(tile[1], tile[2])
21
+ return new MercatorBoundingBox(new MapBox.LngLat(w, s), new MapBox.LngLat(e, n))
22
+ }
23
+
24
+ export { tileToBoundingBox }
@@ -0,0 +1,12 @@
1
+ import type { MercatorTile } from '../../types.ts'
2
+
3
+ const tileToChildren = (tile: MercatorTile) => {
4
+ return [
5
+ [tile[0] * 2, tile[1] * 2, tile[2] + 1],
6
+ [tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],
7
+ [tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],
8
+ [tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1],
9
+ ]
10
+ }
11
+
12
+ export { tileToChildren }
@@ -0,0 +1,23 @@
1
+ import type { Polygon, Position } from 'geojson'
2
+
3
+ import type { MercatorTile } from '../../types.ts'
4
+ import { tileToBoundingBox } from './boundingbox.ts'
5
+
6
+ const tileToGeoJson = (tile: MercatorTile): Polygon => {
7
+ const box = tileToBoundingBox(tile)
8
+ const poly: Polygon = {
9
+ coordinates: [
10
+ [
11
+ box.getNorthWest().toArray() as Position,
12
+ box.getNorthEast().toArray() as Position,
13
+ box.getSouthEast().toArray() as Position,
14
+ box.getSouthWest().toArray() as Position,
15
+ box.getNorthWest().toArray() as Position,
16
+ ],
17
+ ],
18
+ type: 'Polygon',
19
+ }
20
+ return poly
21
+ }
22
+
23
+ export { tileToGeoJson }
@@ -0,0 +1,7 @@
1
+ export { tileToBoundingBox } from './boundingbox.ts'
2
+ export { tileToChildren } from './children.ts'
3
+ export { tileToGeoJson } from './geoJson.ts'
4
+ export { tileToParent } from './parent.ts'
5
+ export { tileToPoint } from './point.ts'
6
+ export { tileToQuadkey } from './quadkey.ts'
7
+ export { tileToSiblings } from './siblings.ts'