@xylabs/geo 4.13.21 → 4.13.23

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.
package/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  Base functionality used throughout XY Labs TypeScript/JavaScript libraries
17
17
 
18
- ## API Documentation
18
+ ## Reference
19
19
 
20
20
  **@xylabs/geo**
21
21
 
@@ -45,16 +45,10 @@ var pointToTileFraction = (point, z) => {
45
45
  return [x, y, z];
46
46
  };
47
47
  var tileFromPoint = (point, z) => {
48
- const tile = pointToTileFraction(point, z);
49
- tile[0] = Math.floor(tile[0]);
50
- tile[1] = Math.floor(tile[1]);
51
- if (tile[0] < 0) {
52
- tile[0] = 0;
53
- }
54
- if (tile[1] < 0) {
55
- tile[1] = 0;
56
- }
57
- return tile;
48
+ const [tileX, tileY, tileZoom] = pointToTileFraction(point, z);
49
+ const x = Math.max(Math.floor(tileX), 0);
50
+ const y = Math.max(Math.floor(tileY), 0);
51
+ return [x, y, tileZoom];
58
52
  };
59
53
 
60
54
  // src/mercator/tile/from/quadkey.ts
@@ -142,13 +136,13 @@ var tileToPoint = (tile) => {
142
136
  };
143
137
 
144
138
  // src/mercator/tile/to/quadkey.ts
145
- var tileToQuadkey = (tile) => {
139
+ var tileToQuadkey = ([tileX, tileY, tileZoom]) => {
146
140
  let index = "";
147
- for (let z = tile[2]; z > 0; z--) {
141
+ for (let z = tileZoom; z > 0; z--) {
148
142
  let b = 0;
149
143
  const mask = 1 << z - 1;
150
- if ((tile[0] & mask) !== 0) b++;
151
- if ((tile[1] & mask) !== 0) b += 2;
144
+ if ((tileX & mask) !== 0) b++;
145
+ if ((tileY & mask) !== 0) b += 2;
152
146
  index += b.toString();
153
147
  }
154
148
  return index;
@@ -160,8 +154,8 @@ var tileToSiblings = (tile) => {
160
154
  };
161
155
 
162
156
  // src/mercator/tiles/equal.ts
163
- var tilesEqual = (tile1, tile2) => {
164
- return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2];
157
+ var tilesEqual = ([x1, y1, zoom1], [x2, y2, zoom2]) => {
158
+ return x1 === x2 && y1 === y2 && zoom1 === zoom2;
165
159
  };
166
160
 
167
161
  // src/mercator/tiles/from/boundingbox.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/GeoJson.ts","../../src/mercator/boundingbox/to/boundary.ts","../../src/mercator/boundingbox/to/center.ts","../../src/mercator/boundingbox/to/polygon.ts","../../src/mercator/constants.ts","../../src/mercator/tile/from/point.ts","../../src/mercator/tile/from/quadkey.ts","../../src/mercator/tile/to/boundingbox.ts","../../src/mercator/types.ts","../../src/mercator/tile/to/children.ts","../../src/mercator/tile/to/geoJson.ts","../../src/mercator/tile/to/parent.ts","../../src/mercator/tile/to/point.ts","../../src/mercator/tile/to/quadkey.ts","../../src/mercator/tile/to/siblings.ts","../../src/mercator/tiles/equal.ts","../../src/mercator/tiles/from/boundingbox.ts","../../src/mercator/tiles/hasTile.ts","../../src/mercator/tiles/hasSiblings.ts","../../src/LayerBase.ts"],"sourcesContent":["import type {\n Feature, FeatureCollection, Geometry, Point, Polygon,\n} from 'geojson'\nimport MapBox from 'mapbox-gl'\n\nimport {\n boundingBoxToCenter, boundingBoxToPolygon, tileFromQuadkey, tileToBoundingBox,\n} from './mercator/index.ts'\n\nclass GeoJson {\n private _lngLat?: MapBox.LngLat\n private _point?: Point\n private _polygon?: Polygon\n private _zoom?: number\n\n private quadkey: string\n\n constructor(quadkey: string) {\n this.quadkey = quadkey\n }\n\n static featureCollection(features: Feature[]): FeatureCollection {\n return {\n features,\n type: 'FeatureCollection',\n }\n }\n\n static featuresSource(data: FeatureCollection): MapBox.GeoJSONSourceSpecification {\n return {\n data,\n type: 'geojson',\n }\n }\n\n static geometryFeature(geometry: Geometry): Feature {\n return {\n geometry,\n properties: {},\n type: 'Feature',\n }\n }\n\n center(): MapBox.LngLat {\n if (!this._lngLat) {\n const tile = tileFromQuadkey(this.quadkey)\n const bb = tileToBoundingBox(tile)\n const point = boundingBoxToCenter(bb)\n this._lngLat = new MapBox.LngLat(point[0], point[1])\n }\n return this._lngLat\n }\n\n point(): Point {\n if (!this._point) {\n this._point = {\n coordinates: this.center().toArray(),\n type: 'Point',\n }\n }\n return this._point\n }\n\n pointFeature(): Feature {\n return GeoJson.geometryFeature(this.point())\n }\n\n pointFeatureCollection(): FeatureCollection {\n return GeoJson.featureCollection([this.pointFeature()])\n }\n\n pointSource(): MapBox.GeoJSONSourceSpecification {\n return {\n data: this.pointFeatureCollection(),\n type: 'geojson',\n }\n }\n\n polygon(): Polygon {\n if (!this._polygon) {\n this._polygon = boundingBoxToPolygon(tileToBoundingBox(tileFromQuadkey(this.quadkey))) as Polygon\n }\n return this._polygon\n }\n\n polygonFeature(): Feature {\n return GeoJson.geometryFeature(this.polygon())\n }\n\n polygonFeatureCollection(): FeatureCollection {\n return GeoJson.featureCollection([this.polygonFeature()])\n }\n\n polygonSource(): MapBox.GeoJSONSourceSpecification {\n return GeoJson.featuresSource(this.polygonFeatureCollection())\n }\n\n zoom(): number {\n this._zoom = this._zoom ?? tileFromQuadkey(this.quadkey)[2]\n return this._zoom\n }\n}\n\nexport { GeoJson }\n","import type { MercatorBoundary, MercatorBoundingBox } from '../../types.ts'\n\nexport const boundingBoxToBoundary = (box: MercatorBoundingBox): MercatorBoundary => {\n return [box.getNorthWest(), box.getNorthEast(), box.getSouthEast(), box.getSouthWest(), box.getNorthWest()]\n}\n","import type { MercatorBoundingBox } from '../../types.ts'\n\nexport const boundingBoxToCenter = (boundingBox: MercatorBoundingBox, decimal = 6) => {\n const west = boundingBox.getWest()\n const south = boundingBox.getSouth()\n const east = boundingBox.getEast()\n const north = boundingBox.getNorth()\n let lng = (west - east) / 2 + east\n let lat = (south - north) / 2 + north\n if (decimal !== undefined && decimal !== null) {\n lng = Number(lng.toFixed(decimal))\n lat = Number(lat.toFixed(decimal))\n }\n return [lng, lat]\n}\n","import type { Polygon } from 'geojson'\n\nimport type { MercatorBoundingBox, MercatorLngLat } from '../../types.ts'\nimport { boundingBoxToBoundary } from './boundary.ts'\n\nexport const boundingBoxToPolygon = (box: MercatorBoundingBox): Polygon => {\n const boundry = boundingBoxToBoundary(box)\n return {\n coordinates: [boundry.map((lnglng: MercatorLngLat) => lnglng.toArray())],\n type: 'Polygon',\n }\n}\n","const d2r = Math.PI / 180\nconst r2d = 180 / Math.PI\n\nexport { d2r, r2d }\n","import { d2r } from '../../constants.ts'\nimport type { MercatorLngLat } from '../../types.ts'\n\nconst pointToTileFraction = (point: MercatorLngLat, z: number) => {\n const sin = Math.sin(point.lat * d2r)\n const z2 = Math.pow(2, z)\n let x = z2 * (point.lng / 360 + 0.5)\n const y = z2 * (0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI)\n\n // Wrap Tile X\n x = x % z2\n if (x < 0) x = x + z2\n return [x, y, z]\n}\n\nconst tileFromPoint = (point: MercatorLngLat, z: number) => {\n const tile = pointToTileFraction(point, z)\n tile[0] = Math.floor(tile[0])\n tile[1] = Math.floor(tile[1])\n if (tile[0] < 0) {\n tile[0] = 0\n }\n if (tile[1] < 0) {\n tile[1] = 0\n }\n return tile\n}\n\nexport { tileFromPoint }\n","const tileFromQuadkey = (quadkey: string) => {\n let x = 0\n let y = 0\n const z = quadkey.length\n\n for (let i = z; i > 0; i--) {\n const mask = 1 << (i - 1)\n const q = +quadkey[z - i]\n if (q === 1) x |= mask\n if (q === 2) y |= mask\n if (q === 3) {\n x |= mask\n y |= mask\n }\n }\n return [x, y, z]\n}\n\nexport { tileFromQuadkey }\n","import MapBox from 'mapbox-gl'\n\nimport { r2d } from '../../constants.ts'\nimport type { MercatorTile } from '../../types.ts'\nimport { MercatorBoundingBox } from '../../types.ts'\n\nconst toLongitude = (x: number, z: number): number => {\n return (x / Math.pow(2, z)) * 360 - 180\n}\n\nconst toLatitude = (y: number, z: number): number => {\n const n = Math.PI - (2 * Math.PI * y) / Math.pow(2, z)\n return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)))\n}\n\nconst tileToBoundingBox = (tile: MercatorTile): MercatorBoundingBox => {\n const e = toLongitude(tile[0] + 1, tile[2])\n const w = toLongitude(tile[0], tile[2])\n const s = toLatitude(tile[1] + 1, tile[2])\n const n = toLatitude(tile[1], tile[2])\n return new MercatorBoundingBox(new MapBox.LngLat(w, s), new MapBox.LngLat(e, n))\n}\n\nexport { tileToBoundingBox }\n","import MapBox from 'mapbox-gl'\n\ntype MercatorTile = number[]\ntype MercatorBoundary = MercatorLngLat[]\nclass MercatorBoundingBox extends MapBox.LngLatBounds {}\nclass MercatorLngLat extends MapBox.LngLat {}\n\nexport { MercatorBoundingBox, MercatorLngLat }\nexport type { MercatorBoundary, MercatorTile }\n","import type { MercatorTile } from '../../types.ts'\n\nconst tileToChildren = (tile: MercatorTile) => {\n return [\n [tile[0] * 2, tile[1] * 2, tile[2] + 1],\n [tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],\n [tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],\n [tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1],\n ]\n}\n\nexport { tileToChildren }\n","import type { Polygon, Position } from 'geojson'\n\nimport type { MercatorTile } from '../../types.ts'\nimport { tileToBoundingBox } from './boundingbox.ts'\n\nconst tileToGeoJson = (tile: MercatorTile): Polygon => {\n const box = tileToBoundingBox(tile)\n const poly: Polygon = {\n coordinates: [\n [\n box.getNorthWest().toArray() as Position,\n box.getNorthEast().toArray() as Position,\n box.getSouthEast().toArray() as Position,\n box.getSouthWest().toArray() as Position,\n box.getNorthWest().toArray() as Position,\n ],\n ],\n type: 'Polygon',\n }\n return poly\n}\n\nexport { tileToGeoJson }\n","import type { MercatorTile } from '../../types.ts'\n\nconst tileToParent = (tile: MercatorTile): MercatorTile => {\n return [tile[0] >> 1, tile[1] >> 1, tile[2] - 1]\n}\n\nexport { tileToParent }\n","import type { MercatorLngLat, MercatorTile } from '../../types.ts'\nimport { tileToBoundingBox } from './boundingbox.ts'\n\nconst tileToPoint = (tile: MercatorTile): MercatorLngLat => {\n const boundingBox = tileToBoundingBox(tile)\n boundingBox.getCenter()\n return boundingBox.getCenter()\n}\n\nexport { tileToPoint }\n","import type { MercatorTile } from '../../types.ts'\n\nconst tileToQuadkey = (tile: MercatorTile): string => {\n let index = ''\n for (let z = tile[2]; z > 0; z--) {\n let b = 0\n const mask = 1 << (z - 1)\n if ((tile[0] & mask) !== 0) b++\n if ((tile[1] & mask) !== 0) b += 2\n index += b.toString()\n }\n return index\n}\n\nexport { tileToQuadkey }\n","import type { MercatorTile } from '../../types.ts'\nimport { tileToChildren } from './children.ts'\nimport { tileToParent } from './parent.ts'\n\nconst tileToSiblings = (tile: MercatorTile): MercatorTile[] => {\n return tileToChildren(tileToParent(tile))\n}\n\nexport { tileToSiblings }\n","import type { MercatorTile } from '../types.ts'\n\nexport const tilesEqual = (tile1: MercatorTile, tile2: MercatorTile) => {\n return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2]\n}\n","import { tileFromPoint } from '../../tile/index.ts'\nimport type { MercatorBoundingBox, MercatorTile } from '../../types.ts'\n\nconst tilesFromBoundingBox = (box: MercatorBoundingBox, zoom: number): MercatorTile[] => {\n const nw = tileFromPoint(box.getNorthWest(), zoom)\n const se = tileFromPoint(box.getSouthEast(), zoom)\n const size = Math.pow(2, zoom)\n\n let minX = nw[0]\n let maxX = se[0]\n let minY = nw[1]\n let maxY = se[1]\n\n // in case of horizontal wrapping\n if (minX >= maxX) {\n maxX = maxX + size\n }\n\n if (zoom < 4) {\n minX = 0\n maxX = size - 1\n minY = 0\n maxY = size - 1\n }\n\n const result: MercatorTile[] = []\n\n for (let x = minX; x <= maxX; x++) {\n for (let y = minY; y <= maxY; y++) {\n result.push([x % size, y, zoom])\n }\n }\n\n return result\n}\n\nexport { tilesFromBoundingBox }\n","import type { MercatorTile } from '../types.ts'\nimport { tilesEqual } from './equal.ts'\n\nexport const tilesHasTile = (tiles: MercatorTile[], tile: MercatorTile) => {\n for (const tileToCheck of tiles) {\n if (tilesEqual(tileToCheck, tile)) return true\n }\n return false\n}\n","import { tileToSiblings } from '../tile/index.ts'\nimport type { MercatorTile } from '../types.ts'\nimport { tilesHasTile } from './hasTile.ts'\n\nexport const hasSiblings = (tiles: MercatorTile[], tile: MercatorTile) => {\n const siblings = tileToSiblings(tile)\n for (const sibling of siblings) {\n if (!tilesHasTile(tiles, sibling)) return false\n }\n return true\n}\n","import type MapBox from 'mapbox-gl'\n\nexport abstract class LayerBase<T extends MapBox.Layer> {\n id: string\n source: string\n\n constructor(id: string, source: string) {\n this.id = id\n this.source = source\n }\n\n update(map: MapBox.Map, show = true) {\n if (map.getLayer(this.id)) {\n map.removeLayer(this.id)\n }\n if (show) {\n map.addLayer(this.buildLayer())\n }\n }\n\n abstract buildLayer(): T\n}\n"],"mappings":";AAGA,OAAOA,aAAY;;;ACDZ,IAAM,wBAAwB,CAAC,QAA+C;AACnF,SAAO,CAAC,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,CAAC;AAC5G;;;ACFO,IAAM,sBAAsB,CAAC,aAAkC,UAAU,MAAM;AACpF,QAAM,OAAO,YAAY,QAAQ;AACjC,QAAM,QAAQ,YAAY,SAAS;AACnC,QAAM,OAAO,YAAY,QAAQ;AACjC,QAAM,QAAQ,YAAY,SAAS;AACnC,MAAI,OAAO,OAAO,QAAQ,IAAI;AAC9B,MAAI,OAAO,QAAQ,SAAS,IAAI;AAChC,MAAI,YAAY,UAAa,YAAY,MAAM;AAC7C,UAAM,OAAO,IAAI,QAAQ,OAAO,CAAC;AACjC,UAAM,OAAO,IAAI,QAAQ,OAAO,CAAC;AAAA,EACnC;AACA,SAAO,CAAC,KAAK,GAAG;AAClB;;;ACTO,IAAM,uBAAuB,CAAC,QAAsC;AACzE,QAAM,UAAU,sBAAsB,GAAG;AACzC,SAAO;AAAA,IACL,aAAa,CAA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D;AAAA,EAEA,gBAAmD;AACjD,WAAO,SAAQ,eAAe,KAAK,yBAAyB,CAAC;AAAA,EAC/D;AAAA,EAEA,OAAe;AACb,SAAK,QAAQ,KAAK,SAAS,gBAAgB,KAAK,OAAO,EAAE,CAAC;AAC1D,WAAO,KAAK;AAAA,EACd;AACF;;;AmBnGO,IAAe,YAAf,MAAiD;AAAA,EACtD;AAAA,EACA;AAAA,EAEA,YAAY,IAAY,QAAgB;AACtC,SAAK,KAAK;AACV,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,OAAO,KAAiB,OAAO,MAAM;AACnC,QAAI,IAAI,SAAS,KAAK,EAAE,GAAG;AACzB,UAAI,YAAY,KAAK,EAAE;AAAA,IACzB;AACA,QAAI,MAAM;AACR,UAAI,SAAS,KAAK,WAAW,CAAC;AAAA,IAChC;AAAA,EACF;AAGF;","names":["MapBox","MapBox","MapBox","MapBox"]}
1
+ {"version":3,"sources":["../../src/GeoJson.ts","../../src/mercator/boundingbox/to/boundary.ts","../../src/mercator/boundingbox/to/center.ts","../../src/mercator/boundingbox/to/polygon.ts","../../src/mercator/constants.ts","../../src/mercator/tile/from/point.ts","../../src/mercator/tile/from/quadkey.ts","../../src/mercator/tile/to/boundingbox.ts","../../src/mercator/types.ts","../../src/mercator/tile/to/children.ts","../../src/mercator/tile/to/geoJson.ts","../../src/mercator/tile/to/parent.ts","../../src/mercator/tile/to/point.ts","../../src/mercator/tile/to/quadkey.ts","../../src/mercator/tile/to/siblings.ts","../../src/mercator/tiles/equal.ts","../../src/mercator/tiles/from/boundingbox.ts","../../src/mercator/tiles/hasTile.ts","../../src/mercator/tiles/hasSiblings.ts","../../src/LayerBase.ts"],"sourcesContent":["import type {\n Feature, FeatureCollection, Geometry, Point, Polygon,\n} from 'geojson'\nimport MapBox from 'mapbox-gl'\n\nimport {\n boundingBoxToCenter, boundingBoxToPolygon, tileFromQuadkey, tileToBoundingBox,\n} from './mercator/index.ts'\n\nclass GeoJson {\n private _lngLat?: MapBox.LngLat\n private _point?: Point\n private _polygon?: Polygon\n private _zoom?: number\n\n private quadkey: string\n\n constructor(quadkey: string) {\n this.quadkey = quadkey\n }\n\n static featureCollection(features: Feature[]): FeatureCollection {\n return {\n features,\n type: 'FeatureCollection',\n }\n }\n\n static featuresSource(data: FeatureCollection): MapBox.GeoJSONSourceSpecification {\n return {\n data,\n type: 'geojson',\n }\n }\n\n static geometryFeature(geometry: Geometry): Feature {\n return {\n geometry,\n properties: {},\n type: 'Feature',\n }\n }\n\n center(): MapBox.LngLat {\n if (!this._lngLat) {\n const tile = tileFromQuadkey(this.quadkey)\n const bb = tileToBoundingBox(tile)\n const point = boundingBoxToCenter(bb)\n this._lngLat = new MapBox.LngLat(point[0], point[1])\n }\n return this._lngLat\n }\n\n point(): Point {\n if (!this._point) {\n this._point = {\n coordinates: this.center().toArray(),\n type: 'Point',\n }\n }\n return this._point\n }\n\n pointFeature(): Feature {\n return GeoJson.geometryFeature(this.point())\n }\n\n pointFeatureCollection(): FeatureCollection {\n return GeoJson.featureCollection([this.pointFeature()])\n }\n\n pointSource(): MapBox.GeoJSONSourceSpecification {\n return {\n data: this.pointFeatureCollection(),\n type: 'geojson',\n }\n }\n\n polygon(): Polygon {\n if (!this._polygon) {\n this._polygon = boundingBoxToPolygon(tileToBoundingBox(tileFromQuadkey(this.quadkey))) as Polygon\n }\n return this._polygon\n }\n\n polygonFeature(): Feature {\n return GeoJson.geometryFeature(this.polygon())\n }\n\n polygonFeatureCollection(): FeatureCollection {\n return GeoJson.featureCollection([this.polygonFeature()])\n }\n\n polygonSource(): MapBox.GeoJSONSourceSpecification {\n return GeoJson.featuresSource(this.polygonFeatureCollection())\n }\n\n zoom(): number {\n this._zoom = this._zoom ?? tileFromQuadkey(this.quadkey)[2]\n return this._zoom\n }\n}\n\nexport { GeoJson }\n","import type { MercatorBoundary, MercatorBoundingBox } from '../../types.ts'\n\nexport const boundingBoxToBoundary = (box: MercatorBoundingBox): MercatorBoundary => {\n return [box.getNorthWest(), box.getNorthEast(), box.getSouthEast(), box.getSouthWest(), box.getNorthWest()]\n}\n","import type { MercatorBoundingBox } from '../../types.ts'\n\nexport const boundingBoxToCenter = (boundingBox: MercatorBoundingBox, decimal = 6) => {\n const west = boundingBox.getWest()\n const south = boundingBox.getSouth()\n const east = boundingBox.getEast()\n const north = boundingBox.getNorth()\n let lng = (west - east) / 2 + east\n let lat = (south - north) / 2 + north\n if (decimal !== undefined && decimal !== null) {\n lng = Number(lng.toFixed(decimal))\n lat = Number(lat.toFixed(decimal))\n }\n return [lng, lat]\n}\n","import type { Polygon } from 'geojson'\n\nimport type { MercatorBoundingBox, MercatorLngLat } from '../../types.ts'\nimport { boundingBoxToBoundary } from './boundary.ts'\n\nexport const boundingBoxToPolygon = (box: MercatorBoundingBox): Polygon => {\n const boundry = boundingBoxToBoundary(box)\n return {\n coordinates: [boundry.map((lnglng: MercatorLngLat) => lnglng.toArray())],\n type: 'Polygon',\n }\n}\n","const d2r = Math.PI / 180\nconst r2d = 180 / Math.PI\n\nexport { d2r, r2d }\n","import { d2r } from '../../constants.ts'\nimport type { MercatorLngLat, MercatorTile } from '../../types.ts'\n\nconst pointToTileFraction = (point: MercatorLngLat, z: number): MercatorTile => {\n const sin = Math.sin(point.lat * d2r)\n const z2 = Math.pow(2, z)\n let x = z2 * (point.lng / 360 + 0.5)\n const y = z2 * (0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI)\n\n // Wrap Tile X\n x = x % z2\n if (x < 0) x = x + z2\n return [x, y, z]\n}\n\nconst tileFromPoint = (point: MercatorLngLat, z: number): MercatorTile => {\n const [tileX, tileY, tileZoom] = pointToTileFraction(point, z)\n const x = Math.max(Math.floor(tileX), 0)\n const y = Math.max(Math.floor(tileY), 0)\n return [x, y, tileZoom]\n}\n\nexport { tileFromPoint }\n","import type { MercatorTile } from '../../types.ts'\n\nconst tileFromQuadkey = (quadkey: string): MercatorTile => {\n let x = 0\n let y = 0\n const z = quadkey.length\n\n for (let i = z; i > 0; i--) {\n const mask = 1 << (i - 1)\n const q = +quadkey[z - i]\n if (q === 1) x |= mask\n if (q === 2) y |= mask\n if (q === 3) {\n x |= mask\n y |= mask\n }\n }\n return [x, y, z]\n}\n\nexport { tileFromQuadkey }\n","import MapBox from 'mapbox-gl'\n\nimport { r2d } from '../../constants.ts'\nimport type { MercatorTile } from '../../types.ts'\nimport { MercatorBoundingBox } from '../../types.ts'\n\nconst toLongitude = (x: number, z: number): number => {\n return (x / Math.pow(2, z)) * 360 - 180\n}\n\nconst toLatitude = (y: number, z: number): number => {\n const n = Math.PI - (2 * Math.PI * y) / Math.pow(2, z)\n return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)))\n}\n\nconst tileToBoundingBox = (tile: MercatorTile): MercatorBoundingBox => {\n const e = toLongitude(tile[0] + 1, tile[2])\n const w = toLongitude(tile[0], tile[2])\n const s = toLatitude(tile[1] + 1, tile[2])\n const n = toLatitude(tile[1], tile[2])\n return new MercatorBoundingBox(new MapBox.LngLat(w, s), new MapBox.LngLat(e, n))\n}\n\nexport { tileToBoundingBox }\n","import MapBox from 'mapbox-gl'\n\ntype MercatorTile = readonly [x: number, y: number, zoom: number]\ntype MercatorBoundary = MercatorLngLat[]\nclass MercatorBoundingBox extends MapBox.LngLatBounds {}\nclass MercatorLngLat extends MapBox.LngLat {}\n\nexport { MercatorBoundingBox, MercatorLngLat }\nexport type { MercatorBoundary, MercatorTile }\n","import type { MercatorTile } from '../../types.ts'\n\nconst tileToChildren = (tile: MercatorTile): MercatorTile[] => {\n return [\n [tile[0] * 2, tile[1] * 2, tile[2] + 1],\n [tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],\n [tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],\n [tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1],\n ]\n}\n\nexport { tileToChildren }\n","import type { Polygon, Position } from 'geojson'\n\nimport type { MercatorTile } from '../../types.ts'\nimport { tileToBoundingBox } from './boundingbox.ts'\n\nconst tileToGeoJson = (tile: MercatorTile): Polygon => {\n const box = tileToBoundingBox(tile)\n const poly: Polygon = {\n coordinates: [\n [\n box.getNorthWest().toArray() as Position,\n box.getNorthEast().toArray() as Position,\n box.getSouthEast().toArray() as Position,\n box.getSouthWest().toArray() as Position,\n box.getNorthWest().toArray() as Position,\n ],\n ],\n type: 'Polygon',\n }\n return poly\n}\n\nexport { tileToGeoJson }\n","import type { MercatorTile } from '../../types.ts'\n\nconst tileToParent = (tile: MercatorTile): MercatorTile => {\n return [tile[0] >> 1, tile[1] >> 1, tile[2] - 1]\n}\n\nexport { tileToParent }\n","import type { MercatorLngLat, MercatorTile } from '../../types.ts'\nimport { tileToBoundingBox } from './boundingbox.ts'\n\nconst tileToPoint = (tile: MercatorTile): MercatorLngLat => {\n const boundingBox = tileToBoundingBox(tile)\n boundingBox.getCenter()\n return boundingBox.getCenter()\n}\n\nexport { tileToPoint }\n","import type { MercatorTile } from '../../types.ts'\n\nconst tileToQuadkey = ([tileX, tileY, tileZoom]: MercatorTile): string => {\n let index = ''\n for (let z = tileZoom; z > 0; z--) {\n let b = 0\n const mask = 1 << (z - 1)\n if ((tileX & mask) !== 0) b++\n if ((tileY & mask) !== 0) b += 2\n index += b.toString()\n }\n return index\n}\n\nexport { tileToQuadkey }\n","import type { MercatorTile } from '../../types.ts'\nimport { tileToChildren } from './children.ts'\nimport { tileToParent } from './parent.ts'\n\nconst tileToSiblings = (tile: MercatorTile): MercatorTile[] => {\n return tileToChildren(tileToParent(tile))\n}\n\nexport { tileToSiblings }\n","import type { MercatorTile } from '../types.ts'\n\nexport const tilesEqual = /* @__PURE__ */ ([x1, y1, zoom1]: MercatorTile, [x2, y2, zoom2]: MercatorTile): boolean => {\n return x1 === x2 && y1 === y2 && zoom1 === zoom2\n}\n","import { tileFromPoint } from '../../tile/index.ts'\nimport type { MercatorBoundingBox, MercatorTile } from '../../types.ts'\n\nconst tilesFromBoundingBox = (box: MercatorBoundingBox, zoom: number): MercatorTile[] => {\n const nw = tileFromPoint(box.getNorthWest(), zoom)\n const se = tileFromPoint(box.getSouthEast(), zoom)\n const size = Math.pow(2, zoom)\n\n let minX = nw[0]\n let maxX = se[0]\n let minY = nw[1]\n let maxY = se[1]\n\n // in case of horizontal wrapping\n if (minX >= maxX) {\n maxX = maxX + size\n }\n\n if (zoom < 4) {\n minX = 0\n maxX = size - 1\n minY = 0\n maxY = size - 1\n }\n\n const result: MercatorTile[] = []\n\n for (let x = minX; x <= maxX; x++) {\n for (let y = minY; y <= maxY; y++) {\n result.push([x % size, y, zoom])\n }\n }\n\n return result\n}\n\nexport { tilesFromBoundingBox }\n","import type { MercatorTile } from '../types.ts'\nimport { tilesEqual } from './equal.ts'\n\nexport const tilesHasTile = (tiles: MercatorTile[], tile: MercatorTile) => {\n for (const tileToCheck of tiles) {\n if (tilesEqual(tileToCheck, tile)) return true\n }\n return false\n}\n","import { tileToSiblings } from '../tile/index.ts'\nimport type { MercatorTile } from '../types.ts'\nimport { tilesHasTile } from './hasTile.ts'\n\nexport const hasSiblings = (tiles: MercatorTile[], tile: MercatorTile) => {\n const siblings = tileToSiblings(tile)\n for (const sibling of siblings) {\n if (!tilesHasTile(tiles, sibling)) return false\n }\n return true\n}\n","import type MapBox from 'mapbox-gl'\n\nexport abstract class LayerBase<T extends MapBox.Layer> {\n id: string\n source: string\n\n constructor(id: string, source: string) {\n this.id = id\n this.source = source\n }\n\n update(map: MapBox.Map, show = true) {\n if (map.getLayer(this.id)) {\n map.removeLayer(this.id)\n }\n if (show) {\n map.addLayer(this.buildLayer())\n }\n }\n\n abstract buildLayer(): T\n}\n"],"mappings":";AAGA,OAAOA,aAAY;;;ACDZ,IAAM,wBAAwB,CAAC,QAA+C;AACnF,SAAO,CAAC,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,CAAC;AAC5G;;;ACFO,IAAM,sBAAsB,CAAC,aAAkC,UAAU,MAAM;AACp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,MAClC,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,UAAmB;AACjB,QAAI,CAAC,KAAK,UAAU;AAClB,WAAK,WAAW,qBAAqB,kBAAkB,gBAAgB,KAAK,OAAO,CAAC,CAAC;AAAA,IACvF;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,iBAA0B;AACxB,WAAO,SAAQ,gBAAgB,KAAK,QAAQ,CAAC;AAAA,EAC/C;AAAA,EAEA,2BAA8C;AAC5C,WAAO,SAAQ,kBAAkB,CAAC,KAAK,eAAe,CAAC,CAAC;AAAA,EAC1D;AAAA,EAEA,gBAAmD;AACjD,WAAO,SAAQ,eAAe,KAAK,yBAAyB,CAAC;AAAA,EAC/D;AAAA,EAEA,OAAe;AACb,SAAK,QAAQ,KAAK,SAAS,gBAAgB,KAAK,OAAO,EAAE,CAAC;AAC1D,WAAO,KAAK;AAAA,EACd;AACF;;;AmBnGO,IAAe,YAAf,MAAiD;AAAA,EACtD;AAAA,EACA;AAAA,EAEA,YAAY,IAAY,QAAgB;AACtC,SAAK,KAAK;AACV,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,OAAO,KAAiB,OAAO,MAAM;AACnC,QAAI,IAAI,SAAS,KAAK,EAAE,GAAG;AACzB,UAAI,YAAY,KAAK,EAAE;AAAA,IACzB;AACA,QAAI,MAAM;AACR,UAAI,SAAS,KAAK,WAAW,CAAC;AAAA,IAChC;AAAA,EACF;AAGF;","names":["MapBox","MapBox","MapBox","MapBox"]}
@@ -1,4 +1,4 @@
1
- import type { MercatorLngLat } from '../../types.ts';
2
- declare const tileFromPoint: (point: MercatorLngLat, z: number) => number[];
1
+ import type { MercatorLngLat, MercatorTile } from '../../types.ts';
2
+ declare const tileFromPoint: (point: MercatorLngLat, z: number) => MercatorTile;
3
3
  export { tileFromPoint };
4
4
  //# sourceMappingURL=point.d.ts.map
@@ -1 +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,GAAI,OAAO,cAAc,EAAE,GAAG,MAAM,aAWtD,CAAA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
1
+ {"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/from/point.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAclE,QAAA,MAAM,aAAa,GAAI,OAAO,cAAc,EAAE,GAAG,MAAM,KAAG,YAKzD,CAAA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
@@ -1,3 +1,4 @@
1
- declare const tileFromQuadkey: (quadkey: string) => number[];
1
+ import type { MercatorTile } from '../../types.ts';
2
+ declare const tileFromQuadkey: (quadkey: string) => MercatorTile;
2
3
  export { tileFromQuadkey };
3
4
  //# sourceMappingURL=quadkey.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"quadkey.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/from/quadkey.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,eAAe,GAAI,SAAS,MAAM,aAgBvC,CAAA;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
1
+ {"version":3,"file":"quadkey.d.ts","sourceRoot":"","sources":["../../../../../src/mercator/tile/from/quadkey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,QAAA,MAAM,eAAe,GAAI,SAAS,MAAM,KAAG,YAgB1C,CAAA;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
@@ -1,4 +1,4 @@
1
1
  import type { MercatorTile } from '../../types.ts';
2
- declare const tileToChildren: (tile: MercatorTile) => number[][];
2
+ declare const tileToChildren: (tile: MercatorTile) => MercatorTile[];
3
3
  export { tileToChildren };
4
4
  //# sourceMappingURL=children.d.ts.map
@@ -1 +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,GAAI,MAAM,YAAY,eAOzC,CAAA;AAED,OAAO,EAAE,cAAc,EAAE,CAAA"}
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,GAAI,MAAM,YAAY,KAAG,YAAY,EAOxD,CAAA;AAED,OAAO,EAAE,cAAc,EAAE,CAAA"}
@@ -1,4 +1,4 @@
1
1
  import type { MercatorTile } from '../../types.ts';
2
- declare const tileToQuadkey: (tile: MercatorTile) => string;
2
+ declare const tileToQuadkey: ([tileX, tileY, tileZoom]: MercatorTile) => string;
3
3
  export { tileToQuadkey };
4
4
  //# sourceMappingURL=quadkey.d.ts.map
@@ -1 +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,GAAI,MAAM,YAAY,KAAG,MAU3C,CAAA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
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,GAAI,0BAA0B,YAAY,KAAG,MAU/D,CAAA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
@@ -1,3 +1,3 @@
1
1
  import type { MercatorTile } from '../types.ts';
2
- export declare const tilesEqual: (tile1: MercatorTile, tile2: MercatorTile) => boolean;
2
+ export declare const tilesEqual: ([x1, y1, zoom1]: MercatorTile, [x2, y2, zoom2]: MercatorTile) => boolean;
3
3
  //# sourceMappingURL=equal.d.ts.map
@@ -1 +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,eAAO,MAAM,UAAU,GAAI,OAAO,YAAY,EAAE,OAAO,YAAY,YAElE,CAAA"}
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,eAAO,MAAM,UAAU,GAAoB,iBAAiB,YAAY,EAAE,iBAAiB,YAAY,KAAG,OAEzG,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import MapBox from 'mapbox-gl';
2
- type MercatorTile = number[];
2
+ type MercatorTile = readonly [x: number, y: number, zoom: number];
3
3
  type MercatorBoundary = MercatorLngLat[];
4
4
  declare class MercatorBoundingBox extends MapBox.LngLatBounds {
5
5
  }
@@ -1 +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"}
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,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;AACjE,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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/geo",
3
- "version": "4.13.21",
3
+ "version": "4.13.23",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "xylabs",
@@ -1,7 +1,7 @@
1
1
  import { d2r } from '../../constants.ts'
2
- import type { MercatorLngLat } from '../../types.ts'
2
+ import type { MercatorLngLat, MercatorTile } from '../../types.ts'
3
3
 
4
- const pointToTileFraction = (point: MercatorLngLat, z: number) => {
4
+ const pointToTileFraction = (point: MercatorLngLat, z: number): MercatorTile => {
5
5
  const sin = Math.sin(point.lat * d2r)
6
6
  const z2 = Math.pow(2, z)
7
7
  let x = z2 * (point.lng / 360 + 0.5)
@@ -13,17 +13,11 @@ const pointToTileFraction = (point: MercatorLngLat, z: number) => {
13
13
  return [x, y, z]
14
14
  }
15
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
16
+ const tileFromPoint = (point: MercatorLngLat, z: number): MercatorTile => {
17
+ const [tileX, tileY, tileZoom] = pointToTileFraction(point, z)
18
+ const x = Math.max(Math.floor(tileX), 0)
19
+ const y = Math.max(Math.floor(tileY), 0)
20
+ return [x, y, tileZoom]
27
21
  }
28
22
 
29
23
  export { tileFromPoint }
@@ -1,4 +1,6 @@
1
- const tileFromQuadkey = (quadkey: string) => {
1
+ import type { MercatorTile } from '../../types.ts'
2
+
3
+ const tileFromQuadkey = (quadkey: string): MercatorTile => {
2
4
  let x = 0
3
5
  let y = 0
4
6
  const z = quadkey.length
@@ -1,6 +1,6 @@
1
1
  import type { MercatorTile } from '../../types.ts'
2
2
 
3
- const tileToChildren = (tile: MercatorTile) => {
3
+ const tileToChildren = (tile: MercatorTile): MercatorTile[] => {
4
4
  return [
5
5
  [tile[0] * 2, tile[1] * 2, tile[2] + 1],
6
6
  [tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],
@@ -1,12 +1,12 @@
1
1
  import type { MercatorTile } from '../../types.ts'
2
2
 
3
- const tileToQuadkey = (tile: MercatorTile): string => {
3
+ const tileToQuadkey = ([tileX, tileY, tileZoom]: MercatorTile): string => {
4
4
  let index = ''
5
- for (let z = tile[2]; z > 0; z--) {
5
+ for (let z = tileZoom; z > 0; z--) {
6
6
  let b = 0
7
7
  const mask = 1 << (z - 1)
8
- if ((tile[0] & mask) !== 0) b++
9
- if ((tile[1] & mask) !== 0) b += 2
8
+ if ((tileX & mask) !== 0) b++
9
+ if ((tileY & mask) !== 0) b += 2
10
10
  index += b.toString()
11
11
  }
12
12
  return index
@@ -1,5 +1,5 @@
1
1
  import type { MercatorTile } from '../types.ts'
2
2
 
3
- export const tilesEqual = (tile1: MercatorTile, tile2: MercatorTile) => {
4
- return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2]
3
+ export const tilesEqual = /* @__PURE__ */ ([x1, y1, zoom1]: MercatorTile, [x2, y2, zoom2]: MercatorTile): boolean => {
4
+ return x1 === x2 && y1 === y2 && zoom1 === zoom2
5
5
  }
@@ -1,6 +1,6 @@
1
1
  import MapBox from 'mapbox-gl'
2
2
 
3
- type MercatorTile = number[]
3
+ type MercatorTile = readonly [x: number, y: number, zoom: number]
4
4
  type MercatorBoundary = MercatorLngLat[]
5
5
  class MercatorBoundingBox extends MapBox.LngLatBounds {}
6
6
  class MercatorLngLat extends MapBox.LngLat {}