@xylabs/geo 5.0.79 → 5.0.81
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 +16 -16
- package/package.json +4 -7
- package/src/GeoJson.ts +0 -104
- package/src/LayerBase.ts +0 -22
- package/src/index.ts +0 -3
- package/src/mercator/boundingbox/index.ts +0 -1
- package/src/mercator/boundingbox/to/boundary.ts +0 -5
- package/src/mercator/boundingbox/to/center.ts +0 -15
- package/src/mercator/boundingbox/to/index.ts +0 -3
- package/src/mercator/boundingbox/to/polygon.ts +0 -12
- package/src/mercator/constants.ts +0 -4
- package/src/mercator/index.ts +0 -5
- package/src/mercator/tile/from/index.ts +0 -2
- package/src/mercator/tile/from/point.ts +0 -23
- package/src/mercator/tile/from/quadkey.ts +0 -21
- package/src/mercator/tile/index.ts +0 -2
- package/src/mercator/tile/to/boundingbox.ts +0 -24
- package/src/mercator/tile/to/children.ts +0 -12
- package/src/mercator/tile/to/geoJson.ts +0 -23
- package/src/mercator/tile/to/index.ts +0 -7
- package/src/mercator/tile/to/parent.ts +0 -7
- package/src/mercator/tile/to/point.ts +0 -10
- package/src/mercator/tile/to/quadkey.ts +0 -15
- package/src/mercator/tile/to/siblings.ts +0 -9
- package/src/mercator/tiles/equal.ts +0 -5
- package/src/mercator/tiles/from/boundingbox.ts +0 -37
- package/src/mercator/tiles/from/index.ts +0 -1
- package/src/mercator/tiles/hasSiblings.ts +0 -11
- package/src/mercator/tiles/hasTile.ts +0 -9
- package/src/mercator/tiles/index.ts +0 -5
- package/src/mercator/types.ts +0 -9
package/README.md
CHANGED
|
@@ -312,7 +312,7 @@ source: string;
|
|
|
312
312
|
### update()
|
|
313
313
|
|
|
314
314
|
```ts
|
|
315
|
-
update(map, show): void;
|
|
315
|
+
update(map, show?): void;
|
|
316
316
|
```
|
|
317
317
|
|
|
318
318
|
### Parameters
|
|
@@ -321,7 +321,7 @@ update(map, show): void;
|
|
|
321
321
|
|
|
322
322
|
`Map$1`
|
|
323
323
|
|
|
324
|
-
#### show
|
|
324
|
+
#### show?
|
|
325
325
|
|
|
326
326
|
`boolean` = `true`
|
|
327
327
|
|
|
@@ -446,7 +446,7 @@ function boundingBoxToBoundary(box): MercatorBoundary;
|
|
|
446
446
|
***
|
|
447
447
|
|
|
448
448
|
```ts
|
|
449
|
-
function boundingBoxToCenter(boundingBox, decimal): number[];
|
|
449
|
+
function boundingBoxToCenter(boundingBox, decimal?): number[];
|
|
450
450
|
```
|
|
451
451
|
|
|
452
452
|
## Parameters
|
|
@@ -455,7 +455,7 @@ function boundingBoxToCenter(boundingBox, decimal): number[];
|
|
|
455
455
|
|
|
456
456
|
[`MercatorBoundingBox`](#../classes/MercatorBoundingBox)
|
|
457
457
|
|
|
458
|
-
### decimal
|
|
458
|
+
### decimal?
|
|
459
459
|
|
|
460
460
|
`number` = `6`
|
|
461
461
|
|
|
@@ -514,7 +514,7 @@ function hasSiblings(tiles, tile): boolean;
|
|
|
514
514
|
***
|
|
515
515
|
|
|
516
516
|
```ts
|
|
517
|
-
function tileFromPoint(point, z):
|
|
517
|
+
function tileFromPoint(point, z): MercatorTile;
|
|
518
518
|
```
|
|
519
519
|
|
|
520
520
|
## Parameters
|
|
@@ -529,7 +529,7 @@ function tileFromPoint(point, z): number[];
|
|
|
529
529
|
|
|
530
530
|
## Returns
|
|
531
531
|
|
|
532
|
-
`
|
|
532
|
+
[`MercatorTile`](#../type-aliases/MercatorTile)
|
|
533
533
|
|
|
534
534
|
### <a id="tileFromQuadkey"></a>tileFromQuadkey
|
|
535
535
|
|
|
@@ -538,7 +538,7 @@ function tileFromPoint(point, z): number[];
|
|
|
538
538
|
***
|
|
539
539
|
|
|
540
540
|
```ts
|
|
541
|
-
function tileFromQuadkey(quadkey):
|
|
541
|
+
function tileFromQuadkey(quadkey): MercatorTile;
|
|
542
542
|
```
|
|
543
543
|
|
|
544
544
|
## Parameters
|
|
@@ -549,7 +549,7 @@ function tileFromQuadkey(quadkey): number[];
|
|
|
549
549
|
|
|
550
550
|
## Returns
|
|
551
551
|
|
|
552
|
-
`
|
|
552
|
+
[`MercatorTile`](#../type-aliases/MercatorTile)
|
|
553
553
|
|
|
554
554
|
### <a id="tileToBoundingBox"></a>tileToBoundingBox
|
|
555
555
|
|
|
@@ -578,7 +578,7 @@ function tileToBoundingBox(tile): MercatorBoundingBox;
|
|
|
578
578
|
***
|
|
579
579
|
|
|
580
580
|
```ts
|
|
581
|
-
function tileToChildren(tile):
|
|
581
|
+
function tileToChildren(tile): MercatorTile[];
|
|
582
582
|
```
|
|
583
583
|
|
|
584
584
|
## Parameters
|
|
@@ -589,7 +589,7 @@ function tileToChildren(tile): number[][];
|
|
|
589
589
|
|
|
590
590
|
## Returns
|
|
591
591
|
|
|
592
|
-
`
|
|
592
|
+
[`MercatorTile`](#../type-aliases/MercatorTile)[]
|
|
593
593
|
|
|
594
594
|
### <a id="tileToGeoJson"></a>tileToGeoJson
|
|
595
595
|
|
|
@@ -658,12 +658,12 @@ function tileToPoint(tile): MercatorLngLat;
|
|
|
658
658
|
***
|
|
659
659
|
|
|
660
660
|
```ts
|
|
661
|
-
function tileToQuadkey(
|
|
661
|
+
function tileToQuadkey(__namedParameters): string;
|
|
662
662
|
```
|
|
663
663
|
|
|
664
664
|
## Parameters
|
|
665
665
|
|
|
666
|
-
###
|
|
666
|
+
### \_\_namedParameters
|
|
667
667
|
|
|
668
668
|
[`MercatorTile`](#../type-aliases/MercatorTile)
|
|
669
669
|
|
|
@@ -698,16 +698,16 @@ function tileToSiblings(tile): MercatorTile[];
|
|
|
698
698
|
***
|
|
699
699
|
|
|
700
700
|
```ts
|
|
701
|
-
function tilesEqual(
|
|
701
|
+
function tilesEqual(__namedParameters, __namedParameters): boolean;
|
|
702
702
|
```
|
|
703
703
|
|
|
704
704
|
## Parameters
|
|
705
705
|
|
|
706
|
-
###
|
|
706
|
+
### \_\_namedParameters
|
|
707
707
|
|
|
708
708
|
[`MercatorTile`](#../type-aliases/MercatorTile)
|
|
709
709
|
|
|
710
|
-
###
|
|
710
|
+
### \_\_namedParameters
|
|
711
711
|
|
|
712
712
|
[`MercatorTile`](#../type-aliases/MercatorTile)
|
|
713
713
|
|
|
@@ -782,7 +782,7 @@ type MercatorBoundary = MercatorLngLat[];
|
|
|
782
782
|
***
|
|
783
783
|
|
|
784
784
|
```ts
|
|
785
|
-
type MercatorTile = number
|
|
785
|
+
type MercatorTile = readonly [number, number, number];
|
|
786
786
|
```
|
|
787
787
|
|
|
788
788
|
### variables
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/geo",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.81",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -28,28 +28,25 @@
|
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
30
|
"types": "./dist/neutral/index.d.ts",
|
|
31
|
-
"source": "./src/index.ts",
|
|
32
31
|
"default": "./dist/neutral/index.mjs"
|
|
33
32
|
},
|
|
34
33
|
"./package.json": "./package.json"
|
|
35
34
|
},
|
|
36
35
|
"module": "./dist/neutral/index.mjs",
|
|
37
|
-
"source": "./src/index.ts",
|
|
38
36
|
"types": "./dist/neutral/index.d.ts",
|
|
39
37
|
"files": [
|
|
40
38
|
"dist",
|
|
41
|
-
"src",
|
|
42
39
|
"!**/*.bench.*",
|
|
43
40
|
"!**/*.spec.*",
|
|
44
41
|
"!**/*.test.*"
|
|
45
42
|
],
|
|
46
43
|
"dependencies": {
|
|
47
44
|
"@types/geojson": "~7946.0.16",
|
|
48
|
-
"mapbox-gl": "~3.
|
|
45
|
+
"mapbox-gl": "~3.19.1"
|
|
49
46
|
},
|
|
50
47
|
"devDependencies": {
|
|
51
|
-
"@xylabs/ts-scripts-yarn3": "~7.
|
|
52
|
-
"@xylabs/tsconfig": "~7.
|
|
48
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.11",
|
|
49
|
+
"@xylabs/tsconfig": "~7.4.11",
|
|
53
50
|
"typescript": "~5.9.3",
|
|
54
51
|
"vitest": "~4.0.18"
|
|
55
52
|
},
|
package/src/GeoJson.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
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 }
|
package/src/LayerBase.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './to/index.ts'
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
package/src/mercator/index.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { d2r } from '../../constants.ts'
|
|
2
|
-
import type { MercatorLngLat, MercatorTile } from '../../types.ts'
|
|
3
|
-
|
|
4
|
-
const pointToTileFraction = (point: MercatorLngLat, z: number): MercatorTile => {
|
|
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): 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]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { tileFromPoint }
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { MercatorTile } from '../../types.ts'
|
|
2
|
-
|
|
3
|
-
const tileFromQuadkey = (quadkey: string): MercatorTile => {
|
|
4
|
-
let x = 0
|
|
5
|
-
let y = 0
|
|
6
|
-
const z = quadkey.length
|
|
7
|
-
|
|
8
|
-
for (let i = z; i > 0; i--) {
|
|
9
|
-
const mask = 1 << (i - 1)
|
|
10
|
-
const q = +quadkey[z - i]
|
|
11
|
-
if (q === 1) x |= mask
|
|
12
|
-
if (q === 2) y |= mask
|
|
13
|
-
if (q === 3) {
|
|
14
|
-
x |= mask
|
|
15
|
-
y |= mask
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return [x, y, z]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { tileFromQuadkey }
|
|
@@ -1,24 +0,0 @@
|
|
|
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 }
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { MercatorTile } from '../../types.ts'
|
|
2
|
-
|
|
3
|
-
const tileToChildren = (tile: MercatorTile): 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 }
|
|
@@ -1,23 +0,0 @@
|
|
|
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 }
|
|
@@ -1,7 +0,0 @@
|
|
|
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'
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { MercatorLngLat, MercatorTile } from '../../types.ts'
|
|
2
|
-
import { tileToBoundingBox } from './boundingbox.ts'
|
|
3
|
-
|
|
4
|
-
const tileToPoint = (tile: MercatorTile): MercatorLngLat => {
|
|
5
|
-
const boundingBox = tileToBoundingBox(tile)
|
|
6
|
-
boundingBox.getCenter()
|
|
7
|
-
return boundingBox.getCenter()
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export { tileToPoint }
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { MercatorTile } from '../../types.ts'
|
|
2
|
-
|
|
3
|
-
const tileToQuadkey = ([tileX, tileY, tileZoom]: MercatorTile): string => {
|
|
4
|
-
let index = ''
|
|
5
|
-
for (let z = tileZoom; z > 0; z--) {
|
|
6
|
-
let b = 0
|
|
7
|
-
const mask = 1 << (z - 1)
|
|
8
|
-
if ((tileX & mask) !== 0) b++
|
|
9
|
-
if ((tileY & mask) !== 0) b += 2
|
|
10
|
-
index += b.toString()
|
|
11
|
-
}
|
|
12
|
-
return index
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { tileToQuadkey }
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { MercatorTile } from '../../types.ts'
|
|
2
|
-
import { tileToChildren } from './children.ts'
|
|
3
|
-
import { tileToParent } from './parent.ts'
|
|
4
|
-
|
|
5
|
-
const tileToSiblings = (tile: MercatorTile): MercatorTile[] => {
|
|
6
|
-
return tileToChildren(tileToParent(tile))
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export { tileToSiblings }
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { tileFromPoint } from '../../tile/index.ts'
|
|
2
|
-
import type { MercatorBoundingBox, MercatorTile } from '../../types.ts'
|
|
3
|
-
|
|
4
|
-
const tilesFromBoundingBox = (box: MercatorBoundingBox, zoom: number): MercatorTile[] => {
|
|
5
|
-
const nw = tileFromPoint(box.getNorthWest(), zoom)
|
|
6
|
-
const se = tileFromPoint(box.getSouthEast(), zoom)
|
|
7
|
-
const size = Math.pow(2, zoom)
|
|
8
|
-
|
|
9
|
-
let minX = nw[0]
|
|
10
|
-
let maxX = se[0]
|
|
11
|
-
let minY = nw[1]
|
|
12
|
-
let maxY = se[1]
|
|
13
|
-
|
|
14
|
-
// in case of horizontal wrapping
|
|
15
|
-
if (minX >= maxX) {
|
|
16
|
-
maxX = maxX + size
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (zoom < 4) {
|
|
20
|
-
minX = 0
|
|
21
|
-
maxX = size - 1
|
|
22
|
-
minY = 0
|
|
23
|
-
maxY = size - 1
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const result: MercatorTile[] = []
|
|
27
|
-
|
|
28
|
-
for (let x = minX; x <= maxX; x++) {
|
|
29
|
-
for (let y = minY; y <= maxY; y++) {
|
|
30
|
-
result.push([x % size, y, zoom])
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return result
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { tilesFromBoundingBox }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { tilesFromBoundingBox } from './boundingbox.ts'
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { tileToSiblings } from '../tile/index.ts'
|
|
2
|
-
import type { MercatorTile } from '../types.ts'
|
|
3
|
-
import { tilesHasTile } from './hasTile.ts'
|
|
4
|
-
|
|
5
|
-
export const hasSiblings = (tiles: MercatorTile[], tile: MercatorTile) => {
|
|
6
|
-
const siblings = tileToSiblings(tile)
|
|
7
|
-
for (const sibling of siblings) {
|
|
8
|
-
if (!tilesHasTile(tiles, sibling)) return false
|
|
9
|
-
}
|
|
10
|
-
return true
|
|
11
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { MercatorTile } from '../types.ts'
|
|
2
|
-
import { tilesEqual } from './equal.ts'
|
|
3
|
-
|
|
4
|
-
export const tilesHasTile = (tiles: MercatorTile[], tile: MercatorTile) => {
|
|
5
|
-
for (const tileToCheck of tiles) {
|
|
6
|
-
if (tilesEqual(tileToCheck, tile)) return true
|
|
7
|
-
}
|
|
8
|
-
return false
|
|
9
|
-
}
|
package/src/mercator/types.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import MapBox from 'mapbox-gl'
|
|
2
|
-
|
|
3
|
-
type MercatorTile = readonly [x: number, y: number, zoom: number]
|
|
4
|
-
type MercatorBoundary = MercatorLngLat[]
|
|
5
|
-
class MercatorBoundingBox extends MapBox.LngLatBounds {}
|
|
6
|
-
class MercatorLngLat extends MapBox.LngLat {}
|
|
7
|
-
|
|
8
|
-
export { MercatorBoundingBox, MercatorLngLat }
|
|
9
|
-
export type { MercatorBoundary, MercatorTile }
|