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