@xylabs/geo 5.1.2 → 5.1.4
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/dist/neutral/index.mjs
CHANGED
|
@@ -1 +1,7 @@
|
|
|
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\n/** Provides GeoJSON geometry and MapBox source generation from a quadkey. */\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 /**\n * Creates a GeoJSON FeatureCollection from an array of features.\n * @param features - The features to include\n * @returns A GeoJSON FeatureCollection\n */\n static featureCollection(features: Feature[]): FeatureCollection {\n return {\n features,\n type: 'FeatureCollection',\n }\n }\n\n /**\n * Creates a MapBox GeoJSON source specification from a FeatureCollection.\n * @param data - The FeatureCollection to use as the source data\n * @returns A MapBox GeoJSON source specification\n */\n static featuresSource(data: FeatureCollection): MapBox.GeoJSONSourceSpecification {\n return {\n data,\n type: 'geojson',\n }\n }\n\n /**\n * Wraps a geometry object in a GeoJSON Feature.\n * @param geometry - The geometry to wrap\n * @returns A GeoJSON Feature containing the geometry\n */\n static geometryFeature(geometry: Geometry): Feature {\n return {\n geometry,\n properties: {},\n type: 'Feature',\n }\n }\n\n /** Computes and caches the center point of the quadkey's bounding box as a MapBox LngLat. */\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 /** Returns a GeoJSON Point geometry at the center of the quadkey's bounding box. */\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 /** Returns a GeoJSON Feature containing the center point geometry. */\n pointFeature(): Feature {\n return GeoJson.geometryFeature(this.point())\n }\n\n /** Returns a GeoJSON FeatureCollection containing the center point feature. */\n pointFeatureCollection(): FeatureCollection {\n return GeoJson.featureCollection([this.pointFeature()])\n }\n\n /** Returns a MapBox GeoJSON source specification for the center point. */\n pointSource(): MapBox.GeoJSONSourceSpecification {\n return {\n data: this.pointFeatureCollection(),\n type: 'geojson',\n }\n }\n\n /** Returns a GeoJSON Polygon geometry representing the quadkey's bounding box. */\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 /** Returns a GeoJSON Feature containing the polygon geometry. */\n polygonFeature(): Feature {\n return GeoJson.geometryFeature(this.polygon())\n }\n\n /** Returns a GeoJSON FeatureCollection containing the polygon feature. */\n polygonFeatureCollection(): FeatureCollection {\n return GeoJson.featureCollection([this.polygonFeature()])\n }\n\n /** Returns a MapBox GeoJSON source specification for the polygon. */\n polygonSource(): MapBox.GeoJSONSourceSpecification {\n return GeoJson.featuresSource(this.polygonFeatureCollection())\n }\n\n /** Returns the zoom level derived from the quadkey length. */\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\n/**\n * Converts a bounding box to an ordered boundary polygon (closed ring of corner points).\n * @param box - The bounding box to convert\n * @returns An array of corner points forming a closed boundary\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\n/**\n * Computes the center point of a bounding box as [lng, lat], rounded to the specified decimal places.\n * @param boundingBox - The bounding box to find the center of\n * @param decimal - Number of decimal places for rounding (default 6)\n * @returns A [longitude, latitude] tuple representing the center\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\n/**\n * Converts a bounding box to a GeoJSON Polygon geometry.\n * @param box - The bounding box to convert\n * @returns A GeoJSON Polygon representing the bounding box\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","/** Conversion factor from degrees to radians. */\nconst d2r = Math.PI / 180\n/** Conversion factor from radians to degrees. */\nconst r2d = 180 / Math.PI\n\nexport { d2r, r2d }\n","import { d2r } from '../../constants.ts'\nimport type { MercatorLngLat, MercatorTile } from '../../types.ts'\n\n/**\n * Converts a geographic point to fractional tile coordinates at the given zoom level.\n * @param point - The geographic coordinate\n * @param z - The zoom level\n * @returns A tile with fractional x and y values\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\n/**\n * Converts a geographic point to the integer Mercator tile containing it at the given zoom level.\n * @param point - The geographic coordinate\n * @param z - The zoom level\n * @returns The tile as [x, y, zoom]\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\n/**\n * Converts a quadkey string to a Mercator tile [x, y, zoom].\n * @param quadkey - The quadkey string to decode\n * @returns The tile as [x, y, zoom]\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\n/**\n * Converts a Mercator tile to its geographic bounding box.\n * @param tile - The tile as [x, y, zoom]\n * @returns The bounding box covering the tile's geographic extent\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\n/** A Mercator tile represented as [x, y, zoom]. */\ntype MercatorTile = readonly [x: number, y: number, zoom: number]\n/** An ordered array of MercatorLngLat points forming a boundary. */\ntype MercatorBoundary = MercatorLngLat[]\n/** A Mercator bounding box extending MapBox LngLatBounds. */\nclass MercatorBoundingBox extends MapBox.LngLatBounds {}\n/** A Mercator coordinate extending MapBox LngLat. */\nclass MercatorLngLat extends MapBox.LngLat {}\n\nexport { MercatorBoundingBox, MercatorLngLat }\nexport type { MercatorBoundary, MercatorTile }\n","import type { MercatorTile } from '../../types.ts'\n\n/**\n * Returns the four child tiles at one zoom level higher.\n * @param tile - The parent tile as [x, y, zoom]\n * @returns An array of four child tiles at zoom + 1\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\n/**\n * Converts a Mercator tile to a GeoJSON Polygon geometry.\n * @param tile - The tile as [x, y, zoom]\n * @returns A GeoJSON Polygon representing the tile's geographic extent\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\n/**\n * Returns the parent tile at one zoom level lower.\n * @param tile - The tile as [x, y, zoom]\n * @returns The parent tile at zoom - 1\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\n/**\n * Returns the center point of a Mercator tile.\n * @param tile - The tile as [x, y, zoom]\n * @returns The center coordinate as a MercatorLngLat\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\n/**\n * Converts a Mercator tile to its quadkey string representation.\n * @param param0 - The tile as [tileX, tileY, tileZoom]\n * @returns The quadkey string encoding the tile's position and zoom\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\n/**\n * Returns the four sibling tiles (children of the parent tile) for the given tile.\n * @param tile - The tile as [x, y, zoom]\n * @returns An array of four sibling tiles at the same zoom level\n */\nconst tileToSiblings = (tile: MercatorTile): MercatorTile[] => {\n return tileToChildren(tileToParent(tile))\n}\n\nexport { tileToSiblings }\n","import type { MercatorTile } from '../types.ts'\n\n/**\n * Checks whether two Mercator tiles are equal by comparing their x, y, and zoom values.\n * @param param0 - The first tile as [x, y, zoom]\n * @param param1 - The second tile as [x, y, zoom]\n * @returns True if both tiles have identical coordinates and zoom\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\n/**\n * Returns all Mercator tiles that intersect the given bounding box at the specified zoom level.\n * @param box - The geographic bounding box\n * @param zoom - The zoom level\n * @returns An array of tiles covering the bounding box\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\n/**\n * Checks whether a specific tile exists in the given tile array.\n * @param tiles - The array of tiles to search\n * @param tile - The tile to look for\n * @returns True if the tile is found in the array\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\n/**\n * Checks whether all four siblings of the given tile exist in the tile array.\n * @param tiles - The array of tiles to search\n * @param tile - The tile whose siblings to check for\n * @returns True if all siblings are present in the array\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\n/** Abstract base class for managing MapBox map layers with add/remove lifecycle. */\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 /**\n * Removes and re-adds the layer on the map, optionally hiding it.\n * @param map - The MapBox map instance\n * @param show - Whether to show the layer after updating (default true)\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 /** Builds the MapBox layer configuration object. */\n abstract buildLayer(): T\n}\n"],"mappings":";AAGA,OAAOA,aAAY;;;ACIZ,IAAM,wBAAwB,CAAC,QAA+C;AACnF,SAAO,CAAC,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,CAAC;AAC5G;;;ACDO,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,YA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AAK,WAAW,qBAAqB,kBAAkB,gBAAgB,KAAK,OAAO,CAAC,CAAC;AAAA,IACvF;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,iBAA0B;AACxB,WAAO,SAAQ,gBAAgB,KAAK,QAAQ,CAAC;AAAA,EAC/C;AAAA;AAAA,EAGA,2BAA8C;AAC5C,WAAO,SAAQ,kBAAkB,CAAC,KAAK,eAAe,CAAC,CAAC;AAAA,EAC1D;AAAA;AAAA,EAGA,gBAAmD;AACjD,WAAO,SAAQ,eAAe,KAAK,yBAAyB,CAAC;AAAA,EAC/D;AAAA;AAAA,EAGA,OAAe;AACb,SAAK,QAAQ,KAAK,SAAS,gBAAgB,KAAK,OAAO,EAAE,CAAC;AAC1D,WAAO,KAAK;AAAA,EACd;AACF;;;AmB5HO,IAAe,YAAf,MAAiD;AAAA,EACtD;AAAA,EACA;AAAA,EAEA,YAAY,IAAY,QAAgB;AACtC,SAAK,KAAK;AACV,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,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;AAIF;","names":["MapBox","MapBox","MapBox","MapBox"]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
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"],
|
|
4
|
+
"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\n/** Provides GeoJSON geometry and MapBox source generation from a quadkey. */\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 /**\n * Creates a GeoJSON FeatureCollection from an array of features.\n * @param features - The features to include\n * @returns A GeoJSON FeatureCollection\n */\n static featureCollection(features: Feature[]): FeatureCollection {\n return {\n features,\n type: 'FeatureCollection',\n }\n }\n\n /**\n * Creates a MapBox GeoJSON source specification from a FeatureCollection.\n * @param data - The FeatureCollection to use as the source data\n * @returns A MapBox GeoJSON source specification\n */\n static featuresSource(data: FeatureCollection): MapBox.GeoJSONSourceSpecification {\n return {\n data,\n type: 'geojson',\n }\n }\n\n /**\n * Wraps a geometry object in a GeoJSON Feature.\n * @param geometry - The geometry to wrap\n * @returns A GeoJSON Feature containing the geometry\n */\n static geometryFeature(geometry: Geometry): Feature {\n return {\n geometry,\n properties: {},\n type: 'Feature',\n }\n }\n\n /** Computes and caches the center point of the quadkey's bounding box as a MapBox LngLat. */\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 /** Returns a GeoJSON Point geometry at the center of the quadkey's bounding box. */\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 /** Returns a GeoJSON Feature containing the center point geometry. */\n pointFeature(): Feature {\n return GeoJson.geometryFeature(this.point())\n }\n\n /** Returns a GeoJSON FeatureCollection containing the center point feature. */\n pointFeatureCollection(): FeatureCollection {\n return GeoJson.featureCollection([this.pointFeature()])\n }\n\n /** Returns a MapBox GeoJSON source specification for the center point. */\n pointSource(): MapBox.GeoJSONSourceSpecification {\n return {\n data: this.pointFeatureCollection(),\n type: 'geojson',\n }\n }\n\n /** Returns a GeoJSON Polygon geometry representing the quadkey's bounding box. */\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 /** Returns a GeoJSON Feature containing the polygon geometry. */\n polygonFeature(): Feature {\n return GeoJson.geometryFeature(this.polygon())\n }\n\n /** Returns a GeoJSON FeatureCollection containing the polygon feature. */\n polygonFeatureCollection(): FeatureCollection {\n return GeoJson.featureCollection([this.polygonFeature()])\n }\n\n /** Returns a MapBox GeoJSON source specification for the polygon. */\n polygonSource(): MapBox.GeoJSONSourceSpecification {\n return GeoJson.featuresSource(this.polygonFeatureCollection())\n }\n\n /** Returns the zoom level derived from the quadkey length. */\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\n/**\n * Converts a bounding box to an ordered boundary polygon (closed ring of corner points).\n * @param box - The bounding box to convert\n * @returns An array of corner points forming a closed boundary\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\n/**\n * Computes the center point of a bounding box as [lng, lat], rounded to the specified decimal places.\n * @param boundingBox - The bounding box to find the center of\n * @param decimal - Number of decimal places for rounding (default 6)\n * @returns A [longitude, latitude] tuple representing the center\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\n/**\n * Converts a bounding box to a GeoJSON Polygon geometry.\n * @param box - The bounding box to convert\n * @returns A GeoJSON Polygon representing the bounding box\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", "/** Conversion factor from degrees to radians. */\nconst d2r = Math.PI / 180\n/** Conversion factor from radians to degrees. */\nconst r2d = 180 / Math.PI\n\nexport { d2r, r2d }\n", "import { d2r } from '../../constants.ts'\nimport type { MercatorLngLat, MercatorTile } from '../../types.ts'\n\n/**\n * Converts a geographic point to fractional tile coordinates at the given zoom level.\n * @param point - The geographic coordinate\n * @param z - The zoom level\n * @returns A tile with fractional x and y values\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\n/**\n * Converts a geographic point to the integer Mercator tile containing it at the given zoom level.\n * @param point - The geographic coordinate\n * @param z - The zoom level\n * @returns The tile as [x, y, zoom]\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\n/**\n * Converts a quadkey string to a Mercator tile [x, y, zoom].\n * @param quadkey - The quadkey string to decode\n * @returns The tile as [x, y, zoom]\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\n/**\n * Converts a Mercator tile to its geographic bounding box.\n * @param tile - The tile as [x, y, zoom]\n * @returns The bounding box covering the tile's geographic extent\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\n/** A Mercator tile represented as [x, y, zoom]. */\ntype MercatorTile = readonly [x: number, y: number, zoom: number]\n/** An ordered array of MercatorLngLat points forming a boundary. */\ntype MercatorBoundary = MercatorLngLat[]\n/** A Mercator bounding box extending MapBox LngLatBounds. */\nclass MercatorBoundingBox extends MapBox.LngLatBounds {}\n/** A Mercator coordinate extending MapBox LngLat. */\nclass MercatorLngLat extends MapBox.LngLat {}\n\nexport { MercatorBoundingBox, MercatorLngLat }\nexport type { MercatorBoundary, MercatorTile }\n", "import type { MercatorTile } from '../../types.ts'\n\n/**\n * Returns the four child tiles at one zoom level higher.\n * @param tile - The parent tile as [x, y, zoom]\n * @returns An array of four child tiles at zoom + 1\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\n/**\n * Converts a Mercator tile to a GeoJSON Polygon geometry.\n * @param tile - The tile as [x, y, zoom]\n * @returns A GeoJSON Polygon representing the tile's geographic extent\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\n/**\n * Returns the parent tile at one zoom level lower.\n * @param tile - The tile as [x, y, zoom]\n * @returns The parent tile at zoom - 1\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\n/**\n * Returns the center point of a Mercator tile.\n * @param tile - The tile as [x, y, zoom]\n * @returns The center coordinate as a MercatorLngLat\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\n/**\n * Converts a Mercator tile to its quadkey string representation.\n * @param param0 - The tile as [tileX, tileY, tileZoom]\n * @returns The quadkey string encoding the tile's position and zoom\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\n/**\n * Returns the four sibling tiles (children of the parent tile) for the given tile.\n * @param tile - The tile as [x, y, zoom]\n * @returns An array of four sibling tiles at the same zoom level\n */\nconst tileToSiblings = (tile: MercatorTile): MercatorTile[] => {\n return tileToChildren(tileToParent(tile))\n}\n\nexport { tileToSiblings }\n", "import type { MercatorTile } from '../types.ts'\n\n/**\n * Checks whether two Mercator tiles are equal by comparing their x, y, and zoom values.\n * @param param0 - The first tile as [x, y, zoom]\n * @param param1 - The second tile as [x, y, zoom]\n * @returns True if both tiles have identical coordinates and zoom\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\n/**\n * Returns all Mercator tiles that intersect the given bounding box at the specified zoom level.\n * @param box - The geographic bounding box\n * @param zoom - The zoom level\n * @returns An array of tiles covering the bounding box\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\n/**\n * Checks whether a specific tile exists in the given tile array.\n * @param tiles - The array of tiles to search\n * @param tile - The tile to look for\n * @returns True if the tile is found in the array\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\n/**\n * Checks whether all four siblings of the given tile exist in the tile array.\n * @param tiles - The array of tiles to search\n * @param tile - The tile whose siblings to check for\n * @returns True if all siblings are present in the array\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\n/** Abstract base class for managing MapBox map layers with add/remove lifecycle. */\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 /**\n * Removes and re-adds the layer on the map, optionally hiding it.\n * @param map - The MapBox map instance\n * @param show - Whether to show the layer after updating (default true)\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 /** Builds the MapBox layer configuration object. */\n abstract buildLayer(): T\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAOA,aAAY;;;ACIZ,IAAM,wBAAwB,CAAC,QAA+C;AACnF,SAAO,CAAC,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,GAAG,IAAI,aAAa,CAAC;AAC5G;;;ACDO,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;;;ACVO,IAAM,uBAAuB,CAAC,QAAsC;AACzE,QAAM,UAAU,sBAAsB,GAAG;AACzC,SAAO;AAAA,IACL,aAAa,CAAC,QAAQ,IAAI,CAAC,WAA2B,OAAO,QAAQ,CAAC,CAAC;AAAA,IACvE,MAAM;AAAA,EACR;AACF;;;ACfA,IAAM,MAAM,KAAK,KAAK;AAEtB,IAAM,MAAM,MAAM,KAAK;;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,SAAK,QAAQ,KAAK,SAAS,gBAAgB,KAAK,OAAO,EAAE,CAAC;AAC1D,WAAO,KAAK;AAAA,EACd;AACF;;;AmB5HO,IAAe,YAAf,MAAiD;AAAA,EACtD;AAAA,EACA;AAAA,EAEA,YAAY,IAAY,QAAgB;AACtC,SAAK,KAAK;AACV,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,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;AAIF;",
|
|
6
|
+
"names": ["MapBox", "MapBox", "MapBox", "MapBox"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/geo",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.4",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -43,16 +43,16 @@
|
|
|
43
43
|
"@types/geojson": "~7946.0.16"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@xylabs/toolchain": "~
|
|
47
|
-
"@xylabs/tsconfig": "~
|
|
48
|
-
"eslint": "^10.
|
|
49
|
-
"mapbox-gl": "
|
|
50
|
-
"typescript": "^
|
|
51
|
-
"vite": "^8.0.
|
|
52
|
-
"vitest": "^4.1.
|
|
46
|
+
"@xylabs/toolchain": "~8.0.8",
|
|
47
|
+
"@xylabs/tsconfig": "~8.0.8",
|
|
48
|
+
"eslint": "^10.4.0",
|
|
49
|
+
"mapbox-gl": "^3.24.0",
|
|
50
|
+
"typescript": "^6.0.3",
|
|
51
|
+
"vite": "^8.0.13",
|
|
52
|
+
"vitest": "^4.1.6"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"mapbox-gl": "
|
|
55
|
+
"mapbox-gl": "^3.23"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=18"
|