@ac-kit/math-map-projection 0.2.0 → 0.3.0
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/CHANGELOG.md +53 -0
- package/README.md +47 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tile/_web-mercator.d.ts +11 -0
- package/dist/tile/_web-mercator.d.ts.map +1 -0
- package/dist/tile/_web-mercator.js +12 -0
- package/dist/tile/_web-mercator.js.map +1 -0
- package/dist/tile/index.d.ts +3 -0
- package/dist/tile/index.d.ts.map +1 -0
- package/dist/tile/index.js +3 -0
- package/dist/tile/index.js.map +1 -0
- package/dist/tile/tile-matrix-sets.d.ts +23 -0
- package/dist/tile/tile-matrix-sets.d.ts.map +1 -0
- package/dist/tile/tile-matrix-sets.js +73 -0
- package/dist/tile/tile-matrix-sets.js.map +1 -0
- package/dist/tile/web-mercator.d.ts +87 -0
- package/dist/tile/web-mercator.d.ts.map +1 -0
- package/dist/tile/web-mercator.js +166 -0
- package/dist/tile/web-mercator.js.map +1 -0
- package/package.json +11 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,58 @@
|
|
|
1
1
|
# @ac-kit/math-map-projection
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5c203e7: Web Mercator and the registered tile matrix sets of web maps, over
|
|
8
|
+
`@ac-kit/math-grid`'s tile model. Depends on `@ac-kit/math-grid` and
|
|
9
|
+
`@ac-kit/math-geodesy`.
|
|
10
|
+
|
|
11
|
+
- `WEB_MERCATOR_QUAD` (OGC WebMercatorQuad: EPSG:3857, levels 0 to 24, radius
|
|
12
|
+
from `ELLIPSOID_WGS84`) and `WORLD_CRS84_QUAD` (OGC WorldCRS84Quad: CRS84,
|
|
13
|
+
levels 0 to 23, two tiles at level 0), with computed cell sizes that halve
|
|
14
|
+
exactly from level to level.
|
|
15
|
+
- `webMercatorProject` and `webMercatorUnproject`, with their in-place
|
|
16
|
+
`…Array` forms: longitude and latitude in radians to EPSG:3857 metres and
|
|
17
|
+
back; `WEB_MERCATOR_MAX_LATITUDE` is the square's latitude limit, `atan(sinh
|
|
18
|
+
π)` radians.
|
|
19
|
+
- `webMercatorTileAt(out, coords, level)` gives the tile of a longitude and
|
|
20
|
+
latitude as tile servers count it (longitudes wrapped, latitudes beyond the
|
|
21
|
+
limit on the edge rows), and `webMercatorTileLongitudeLatitudeBounds(out,
|
|
22
|
+
tile)` its extent in radians; `RangeError` for a level outside 0 to 24.
|
|
23
|
+
- `webMercatorGroundResolution(latitude, zoom)` and
|
|
24
|
+
`webMercatorScaleDenominator(latitude, zoom, pixelSizeM?)` give the metres per
|
|
25
|
+
pixel and the scale at a latitude and a continuous zoom.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [5c203e7]
|
|
30
|
+
- Updated dependencies [5c203e7]
|
|
31
|
+
- Updated dependencies [5c203e7]
|
|
32
|
+
- Updated dependencies [5c203e7]
|
|
33
|
+
- Updated dependencies [5c203e7]
|
|
34
|
+
- Updated dependencies [5c203e7]
|
|
35
|
+
- Updated dependencies [5c203e7]
|
|
36
|
+
- Updated dependencies [5c203e7]
|
|
37
|
+
- Updated dependencies [5c203e7]
|
|
38
|
+
- Updated dependencies [5c203e7]
|
|
39
|
+
- Updated dependencies [5c203e7]
|
|
40
|
+
- Updated dependencies [5c203e7]
|
|
41
|
+
- Updated dependencies [5c203e7]
|
|
42
|
+
- Updated dependencies [5c203e7]
|
|
43
|
+
- Updated dependencies [5c203e7]
|
|
44
|
+
- Updated dependencies [5c203e7]
|
|
45
|
+
- Updated dependencies [5c203e7]
|
|
46
|
+
- Updated dependencies [5c203e7]
|
|
47
|
+
- Updated dependencies [5c203e7]
|
|
48
|
+
- Updated dependencies [5c203e7]
|
|
49
|
+
- @ac-kit/core@0.14.0
|
|
50
|
+
- @ac-kit/math-geodesy@0.2.0
|
|
51
|
+
- @ac-kit/math-geometry@0.5.0
|
|
52
|
+
- @ac-kit/math-grid@0.5.0
|
|
53
|
+
- @ac-kit/math-linear@0.5.0
|
|
54
|
+
- @ac-kit/math-scalar@0.5.0
|
|
55
|
+
|
|
3
56
|
## 0.2.0
|
|
4
57
|
|
|
5
58
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @ac-kit/math-map-projection
|
|
2
2
|
|
|
3
|
-
Point maps between the sphere and the plane — map and sky projections,
|
|
4
|
-
cutting, resampling and graticules a map needs
|
|
5
|
-
building are not here. Earth or sky: a
|
|
6
|
-
sphere, and `stereographicProjectArray`
|
|
7
|
-
0.16 ms.
|
|
3
|
+
Point maps between the sphere and the plane — map and sky projections, the
|
|
4
|
+
cutting, resampling and graticules a map needs, and the Web Mercator tile
|
|
5
|
+
matrix sets; styling and GeoJSON path building are not here. Earth or sky: a
|
|
6
|
+
star chart is a map of the celestial sphere, and `stereographicProjectArray`
|
|
7
|
+
projects 120 000 stars in about 0.16 ms.
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
10
|
import {
|
|
@@ -67,6 +67,9 @@ const lines = projectionGraticule(projection);
|
|
|
67
67
|
| `projectionPolylineProject`, `projectionPolygonProject` | Lines and polygons cut at the antimeridian or the clip circle, then sampled until straight |
|
|
68
68
|
| `graticuleCreate`, `projectionGraticule`, `projectionOutline` | The graticule and the outline of a map |
|
|
69
69
|
| `VertexRuns`, `vertexRunsFromArrays`, `PROJECTION_MAXIMUM_VERTICES` | The packed layout of lines and rings, and the most vertices a result holds |
|
|
70
|
+
| `WEB_MERCATOR_QUAD`, `WORLD_CRS84_QUAD` | The OGC tile matrix sets of web maps, for `@ac-kit/math-grid`'s `tile…` functions |
|
|
71
|
+
| `webMercatorProject`, `webMercatorUnproject` (and `…Array`), `WEB_MERCATOR_MAX_LATITUDE` | EPSG:3857 in metres |
|
|
72
|
+
| `webMercatorTileAt`, `webMercatorTileLongitudeLatitudeBounds`, `webMercatorGroundResolution`, `webMercatorScaleDenominator` | Tiles from longitudes and latitudes, their extents back, and the ground scale at a latitude and zoom |
|
|
70
73
|
|
|
71
74
|
Which projection for what: the **stereographic** keeps angles and turns circles
|
|
72
75
|
into circles (sky charts, polar maps); the **orthographic** is the globe seen
|
|
@@ -76,6 +79,45 @@ the **azimuthal equidistant** keeps distances from the centre; the
|
|
|
76
79
|
areas; **Mercator** and the **Lambert conformal conic** keep angles;
|
|
77
80
|
**equirectangular** and **Natural Earth** compromise.
|
|
78
81
|
|
|
82
|
+
## Web Mercator tiles
|
|
83
|
+
|
|
84
|
+
EPSG:3857 is the spherical Mercator on a sphere of WGS 84's equatorial radius
|
|
85
|
+
(`ELLIPSOID_WGS84` of `@ac-kit/math-geodesy`), in metres:
|
|
86
|
+
`webMercatorProject` takes radians like every function here. `WEB_MERCATOR_QUAD`
|
|
87
|
+
(levels 0 to 24) and `WORLD_CRS84_QUAD` (levels 0 to 23, 2 × 1 tiles at level
|
|
88
|
+
0) are the OGC registered tile matrix sets, with computed cell sizes, so every
|
|
89
|
+
level halves the last exactly; use them with `@ac-kit/math-grid`'s `tileAt`,
|
|
90
|
+
`tileBounds`, `tileNeighbours`, `tilesCoveringBox` and `tileQuadkey`.
|
|
91
|
+
|
|
92
|
+
`webMercatorTileAt` counts as tile servers do: a longitude outside `[−π, π]`
|
|
93
|
+
wraps, a latitude beyond `WEB_MERCATOR_MAX_LATITUDE` (85.051°) goes to the edge
|
|
94
|
+
row, the antimeridian at `+π` to the last column. The ground resolution and
|
|
95
|
+
scale denominator take a continuous zoom, for a map drawn between levels.
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import {
|
|
99
|
+
webMercatorGroundResolution,
|
|
100
|
+
webMercatorTileAt,
|
|
101
|
+
webMercatorTileLongitudeLatitudeBounds,
|
|
102
|
+
} from "@ac-kit/math-map-projection";
|
|
103
|
+
import { box2Create, longitudeLatitudeOf } from "@ac-kit/math-geometry";
|
|
104
|
+
import { tileQuadkey } from "@ac-kit/math-grid";
|
|
105
|
+
|
|
106
|
+
const degrees = Math.PI / 180;
|
|
107
|
+
const tile = webMercatorTileAt(
|
|
108
|
+
{ level: 0, col: 0, row: 0 },
|
|
109
|
+
longitudeLatitudeOf(2.35 * degrees, 48.85 * degrees),
|
|
110
|
+
12,
|
|
111
|
+
); // { level: 12, col: 2074, row: 1409 }
|
|
112
|
+
tileQuadkey(tile); // "120220011012"
|
|
113
|
+
webMercatorTileLongitudeLatitudeBounds(box2Create(), tile); // west, south, east, north (radians)
|
|
114
|
+
webMercatorGroundResolution(48.85 * degrees, 12.5); // ≈ 17.78 m per pixel
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Checked against `mercantile` (Python, BSD-3-Clause; a dev oracle through a
|
|
118
|
+
generated fixture, never a source): tiles and quadkeys equal, bounds within
|
|
119
|
+
`1e−9`° and metres within `1e−6` m.
|
|
120
|
+
|
|
79
121
|
## Cutting, resampling, graticules
|
|
80
122
|
|
|
81
123
|
`projectionPolygonProject` and `projectionPolylineProject` take the packed
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The sphere radius of EPSG:3857, WGS 84's equatorial radius, metres. */
|
|
2
|
+
export declare const WEB_MERCATOR_RADIUS_: number;
|
|
3
|
+
/**
|
|
4
|
+
* Half the side of the Web Mercator square, `π · a` metres: the plane x of the
|
|
5
|
+
* antimeridian and the plane y of the latitude limit. `2π · a` rounds to twice
|
|
6
|
+
* it exactly, so the side is exact too.
|
|
7
|
+
*/
|
|
8
|
+
export declare const WEB_MERCATOR_HALF_SIDE_: number;
|
|
9
|
+
/** The side of a WebMercatorQuad tile in cells. */
|
|
10
|
+
export declare const WEB_MERCATOR_TILE_SIZE_ = 256;
|
|
11
|
+
//# sourceMappingURL=_web-mercator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_web-mercator.d.ts","sourceRoot":"","sources":["../../src/tile/_web-mercator.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,eAAO,MAAM,oBAAoB,QAAiC,CAAC;AAEnE;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAAiC,CAAC;AAEtE,mDAAmD;AACnD,eAAO,MAAM,uBAAuB,MAAM,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ELLIPSOID_WGS84 } from "@ac-kit/math-geodesy";
|
|
2
|
+
/** The sphere radius of EPSG:3857, WGS 84's equatorial radius, metres. */
|
|
3
|
+
export const WEB_MERCATOR_RADIUS_ = ELLIPSOID_WGS84.semiMajorAxisM;
|
|
4
|
+
/**
|
|
5
|
+
* Half the side of the Web Mercator square, `π · a` metres: the plane x of the
|
|
6
|
+
* antimeridian and the plane y of the latitude limit. `2π · a` rounds to twice
|
|
7
|
+
* it exactly, so the side is exact too.
|
|
8
|
+
*/
|
|
9
|
+
export const WEB_MERCATOR_HALF_SIDE_ = Math.PI * WEB_MERCATOR_RADIUS_;
|
|
10
|
+
/** The side of a WebMercatorQuad tile in cells. */
|
|
11
|
+
export const WEB_MERCATOR_TILE_SIZE_ = 256;
|
|
12
|
+
//# sourceMappingURL=_web-mercator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_web-mercator.js","sourceRoot":"","sources":["../../src/tile/_web-mercator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAAe,CAAC,cAAc,CAAC;AAEnE;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC,EAAE,GAAG,oBAAoB,CAAC;AAEtE,mDAAmD;AACnD,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tile/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tile/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type TileMatrixSet } from "@ac-kit/math-grid";
|
|
2
|
+
/**
|
|
3
|
+
* OGC WebMercatorQuad (OGC 17-083r4 Annex D.1), the tiling of Google Maps, Bing
|
|
4
|
+
* Maps and OpenStreetMap: EPSG:3857, a sphere of WGS 84's equatorial radius
|
|
5
|
+
* (`ELLIPSOID_WGS84.semiMajorAxisM` of `@ac-kit/math-geodesy`), 256-cell tiles,
|
|
6
|
+
* levels 0 to 24 with `2^level × 2^level` tiles numbered from the top left
|
|
7
|
+
* ("XYZ"). The cell sizes are computed, not the registry's 15 rounded digits:
|
|
8
|
+
* each level halves the last exactly, and the far edges of every matrix are `±π
|
|
9
|
+
* · a` exactly. Use it with the `tile…` functions of `@ac-kit/math-grid`;
|
|
10
|
+
* points are in metres, x east, y north.
|
|
11
|
+
*/
|
|
12
|
+
export declare const WEB_MERCATOR_QUAD: TileMatrixSet;
|
|
13
|
+
/**
|
|
14
|
+
* OGC WorldCRS84Quad (OGC 17-083r4 Annex D.2): plate carrée in CRS84
|
|
15
|
+
* (longitude, then latitude, in degrees), 256-cell tiles, levels 0 to 23 with
|
|
16
|
+
* `2^(level + 1) × 2^level` tiles numbered from the top left, so level 0 is two
|
|
17
|
+
* tiles, one per half of the longitudes. Its scale denominators use WGS 84's
|
|
18
|
+
* equatorial metres per degree: those of WebMercatorQuad one level deeper. Use
|
|
19
|
+
* it with the `tile…` functions of `@ac-kit/math-grid`; points are `[longitude,
|
|
20
|
+
* latitude]` in degrees.
|
|
21
|
+
*/
|
|
22
|
+
export declare const WORLD_CRS84_QUAD: TileMatrixSet;
|
|
23
|
+
//# sourceMappingURL=tile-matrix-sets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tile-matrix-sets.d.ts","sourceRoot":"","sources":["../../src/tile/tile-matrix-sets.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,aAAa,EAGlB,MAAM,mBAAmB,CAAC;AAU3B;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,EAAE,aAuB9B,CAAC;AAQH;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,EAAE,aAqB7B,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { tileMatrixSetCreate, } from "@ac-kit/math-grid";
|
|
2
|
+
import { WEB_MERCATOR_HALF_SIDE_, WEB_MERCATOR_TILE_SIZE_, } from "./_web-mercator.js";
|
|
3
|
+
/** The standardised rendering cell of OGC 17-083r4 §6.1.1, metres. */
|
|
4
|
+
const RENDERING_CELL_M_ = 0.00028;
|
|
5
|
+
/**
|
|
6
|
+
* OGC WebMercatorQuad (OGC 17-083r4 Annex D.1), the tiling of Google Maps, Bing
|
|
7
|
+
* Maps and OpenStreetMap: EPSG:3857, a sphere of WGS 84's equatorial radius
|
|
8
|
+
* (`ELLIPSOID_WGS84.semiMajorAxisM` of `@ac-kit/math-geodesy`), 256-cell tiles,
|
|
9
|
+
* levels 0 to 24 with `2^level × 2^level` tiles numbered from the top left
|
|
10
|
+
* ("XYZ"). The cell sizes are computed, not the registry's 15 rounded digits:
|
|
11
|
+
* each level halves the last exactly, and the far edges of every matrix are `±π
|
|
12
|
+
* · a` exactly. Use it with the `tile…` functions of `@ac-kit/math-grid`;
|
|
13
|
+
* points are in metres, x east, y north.
|
|
14
|
+
*/
|
|
15
|
+
export const WEB_MERCATOR_QUAD = tileMatrixSetCreate({
|
|
16
|
+
id: "WebMercatorQuad",
|
|
17
|
+
title: "Google Maps Compatible for the World",
|
|
18
|
+
uri: "http://www.opengis.net/def/tilematrixset/OGC/1.0/WebMercatorQuad",
|
|
19
|
+
crs: "http://www.opengis.net/def/crs/EPSG/0/3857",
|
|
20
|
+
orderedAxes: ["X", "Y"],
|
|
21
|
+
axisOrder: "xy",
|
|
22
|
+
wellKnownScaleSet: "http://www.opengis.net/def/wkss/OGC/1.0/GoogleMapsCompatible",
|
|
23
|
+
tileMatrices: Array.from({ length: 25 }, (_, level) => {
|
|
24
|
+
const cellSize = (2 * WEB_MERCATOR_HALF_SIDE_) / (WEB_MERCATOR_TILE_SIZE_ * 2 ** level);
|
|
25
|
+
return {
|
|
26
|
+
id: String(level),
|
|
27
|
+
scaleDenominator: cellSize / RENDERING_CELL_M_,
|
|
28
|
+
cellSize,
|
|
29
|
+
pointOfOrigin: [-WEB_MERCATOR_HALF_SIDE_, WEB_MERCATOR_HALF_SIDE_],
|
|
30
|
+
tileWidth: WEB_MERCATOR_TILE_SIZE_,
|
|
31
|
+
tileHeight: WEB_MERCATOR_TILE_SIZE_,
|
|
32
|
+
matrixWidth: 2 ** level,
|
|
33
|
+
matrixHeight: 2 ** level,
|
|
34
|
+
};
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* The metres of a degree on WGS 84's equator, `2π · a / 360`: the
|
|
39
|
+
* `metersPerUnit` of OGC 17-083r4 Table 7 for a CRS in degrees.
|
|
40
|
+
*/
|
|
41
|
+
const METRES_PER_DEGREE_ = (2 * WEB_MERCATOR_HALF_SIDE_) / 360;
|
|
42
|
+
/**
|
|
43
|
+
* OGC WorldCRS84Quad (OGC 17-083r4 Annex D.2): plate carrée in CRS84
|
|
44
|
+
* (longitude, then latitude, in degrees), 256-cell tiles, levels 0 to 23 with
|
|
45
|
+
* `2^(level + 1) × 2^level` tiles numbered from the top left, so level 0 is two
|
|
46
|
+
* tiles, one per half of the longitudes. Its scale denominators use WGS 84's
|
|
47
|
+
* equatorial metres per degree: those of WebMercatorQuad one level deeper. Use
|
|
48
|
+
* it with the `tile…` functions of `@ac-kit/math-grid`; points are `[longitude,
|
|
49
|
+
* latitude]` in degrees.
|
|
50
|
+
*/
|
|
51
|
+
export const WORLD_CRS84_QUAD = tileMatrixSetCreate({
|
|
52
|
+
id: "WorldCRS84Quad",
|
|
53
|
+
title: "CRS84 for the World",
|
|
54
|
+
uri: "http://www.opengis.net/def/tilematrixset/OGC/1.0/WorldCRS84Quad",
|
|
55
|
+
crs: "http://www.opengis.net/def/crs/OGC/1.3/CRS84",
|
|
56
|
+
orderedAxes: ["Lon", "Lat"],
|
|
57
|
+
axisOrder: "xy",
|
|
58
|
+
wellKnownScaleSet: "http://www.opengis.net/def/wkss/OGC/1.0/GoogleCRS84Quad",
|
|
59
|
+
tileMatrices: Array.from({ length: 24 }, (_, level) => {
|
|
60
|
+
const cellSize = 180 / (WEB_MERCATOR_TILE_SIZE_ * 2 ** level);
|
|
61
|
+
return {
|
|
62
|
+
id: String(level),
|
|
63
|
+
scaleDenominator: (cellSize * METRES_PER_DEGREE_) / RENDERING_CELL_M_,
|
|
64
|
+
cellSize,
|
|
65
|
+
pointOfOrigin: [-180, 90],
|
|
66
|
+
tileWidth: WEB_MERCATOR_TILE_SIZE_,
|
|
67
|
+
tileHeight: WEB_MERCATOR_TILE_SIZE_,
|
|
68
|
+
matrixWidth: 2 ** (level + 1),
|
|
69
|
+
matrixHeight: 2 ** level,
|
|
70
|
+
};
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=tile-matrix-sets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tile-matrix-sets.js","sourceRoot":"","sources":["../../src/tile/tile-matrix-sets.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,mBAAmB,GAEnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACN,uBAAuB,EACvB,uBAAuB,GACvB,MAAM,oBAAoB,CAAC;AAE5B,sEAAsE;AACtE,MAAM,iBAAiB,GAAG,OAAQ,CAAC;AAEnC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAkB,mBAAmB,CAAC;IACnE,EAAE,EAAE,iBAAiB;IACrB,KA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rE,MAAM,QAAQ,GAAG,GAAG,GAAG,CAAC,uBAAuB,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC;QAC9D,OAAO;YACN,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC;YACjB,gBAAgB,EAAE,CAAC,QAAQ,GAAG,kBAAkB,CAAC,GAAG,iBAAiB;YACrE,QAAQ;YACR,aAAa,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;YACzB,SAAS,EAAE,uBAAuB;YAClC,UAAU,EAAE,uBAAuB;YACnC,WAAW,EAAE,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;YAC7B,YAAY,EAAE,CAAC,IAAI,KAAK;SACxB,CAAC;IACH,CAAC,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Box2, LongitudeLatitude, ReadonlyLongitudeLatitude } from "@ac-kit/math-geometry";
|
|
2
|
+
import { type TileIndex } from "@ac-kit/math-grid";
|
|
3
|
+
import { type ReadonlyVec2, type Vec2 } from "@ac-kit/math-linear";
|
|
4
|
+
/**
|
|
5
|
+
* The latitude limit of the Web Mercator square, `atan(sinh π)` radians (85.051
|
|
6
|
+
* 128 779 806 59°): the latitude whose plane y is `π · a`, the edge of
|
|
7
|
+
* WebMercatorQuad.
|
|
8
|
+
*/
|
|
9
|
+
export declare const WEB_MERCATOR_MAX_LATITUDE: number;
|
|
10
|
+
/**
|
|
11
|
+
* Writes the EPSG:3857 point of `coords` (longitude, latitude in radians) into
|
|
12
|
+
* `out`, in metres: `x = a · λ`, `y = a · asinh(tan φ)`. A pole gives `y = ±∞`;
|
|
13
|
+
* a latitude outside `[−π/2, π/2]` or a `NaN` gives `NaN`, and a longitude
|
|
14
|
+
* outside `(−π, π]` is kept as it is.
|
|
15
|
+
*
|
|
16
|
+
* @returns `out`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function webMercatorProject(out: Vec2, coords: ReadonlyLongitudeLatitude): Vec2;
|
|
19
|
+
/**
|
|
20
|
+
* Writes the longitude and latitude, in radians, of the EPSG:3857 point `point`
|
|
21
|
+
* (metres) into `out`: `λ = x / a`, `φ = atan(sinh(y / a))`. Any y is a
|
|
22
|
+
* latitude (a far one a pole); a point with `|x| > π · a` gives `NaN`.
|
|
23
|
+
*
|
|
24
|
+
* @returns `out`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function webMercatorUnproject(out: LongitudeLatitude, point: ReadonlyVec2): LongitudeLatitude;
|
|
27
|
+
/**
|
|
28
|
+
* Writes the EPSG:3857 point of every longitude–latitude pair of `input` into
|
|
29
|
+
* `out` (as many numbers), as {@link webMercatorProject} does for one. `out` may
|
|
30
|
+
* be `input`. O(n), no allocation.
|
|
31
|
+
*
|
|
32
|
+
* @returns `out`.
|
|
33
|
+
* @throws {RangeError} Unless `out` and `input` have the same even length.
|
|
34
|
+
*/
|
|
35
|
+
export declare function webMercatorProjectArray<T extends Float64Array>(out: T, input: Float64Array): T;
|
|
36
|
+
/**
|
|
37
|
+
* Writes the longitude–latitude pair of every EPSG:3857 point of `input` into
|
|
38
|
+
* `out` (as many numbers), as {@link webMercatorUnproject} does for one. `out`
|
|
39
|
+
* may be `input`. O(n), no allocation.
|
|
40
|
+
*
|
|
41
|
+
* @returns `out`.
|
|
42
|
+
* @throws {RangeError} Unless `out` and `input` have the same even length.
|
|
43
|
+
*/
|
|
44
|
+
export declare function webMercatorUnprojectArray<T extends Float64Array>(out: T, input: Float64Array): T;
|
|
45
|
+
/**
|
|
46
|
+
* The ground size of one WebMercatorQuad cell (a 256-pixel tile's pixel) at
|
|
47
|
+
* latitude `latitude` (radians) and zoom `zoom`, in metres on the sphere: `cos
|
|
48
|
+
* φ · 2π · a / (256 · 2^zoom)`, 156 543.03 m at the equator at zoom 0. The zoom
|
|
49
|
+
* is continuous, so a map drawn between levels gets its own value. `NaN` for a
|
|
50
|
+
* latitude outside `[−π/2, π/2]` or a `NaN`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function webMercatorGroundResolution(latitude: number, zoom: number): number;
|
|
53
|
+
/**
|
|
54
|
+
* The scale denominator of a WebMercatorQuad map at latitude `latitude`
|
|
55
|
+
* (radians) and zoom `zoom` shown with pixels `pixelSizeM` metres wide (the
|
|
56
|
+
* standard OGC 0.28 mm by default; `0.0254 / dpi` for a screen of known
|
|
57
|
+
* density): the ground resolution over the pixel size. At the equator it is the
|
|
58
|
+
* scale denominator of the level. `NaN` for a latitude outside `[−π/2, π/2]`, a
|
|
59
|
+
* non-positive pixel size or a `NaN`.
|
|
60
|
+
*/
|
|
61
|
+
export declare function webMercatorScaleDenominator(latitude: number, zoom: number, pixelSizeM?: number): number;
|
|
62
|
+
/**
|
|
63
|
+
* Writes the WebMercatorQuad tile of level `level` holding `coords` (longitude,
|
|
64
|
+
* latitude in radians) into `out`, as tile servers count it: a longitude
|
|
65
|
+
* outside `[−π, π]` is wrapped into it, a latitude beyond
|
|
66
|
+
* {@link WEB_MERCATOR_MAX_LATITUDE} (a pole included) goes to the first or last
|
|
67
|
+
* row, the antimeridian at `+π` to the last column; otherwise as `tileAt` of
|
|
68
|
+
* `@ac-kit/math-grid`. `col` and `row` are `NaN` for a latitude outside `[−π/2,
|
|
69
|
+
* π/2]`, an infinite longitude, a `NaN` or a `NaN` level. O(1), no allocation.
|
|
70
|
+
*
|
|
71
|
+
* @returns `out`.
|
|
72
|
+
* @throws {RangeError} When `level` is not an integer from 0 to 24.
|
|
73
|
+
*/
|
|
74
|
+
export declare function webMercatorTileAt(out: TileIndex, coords: ReadonlyLongitudeLatitude, level: number): TileIndex;
|
|
75
|
+
/**
|
|
76
|
+
* Writes the extent of the WebMercatorQuad tile `tile` as longitudes and
|
|
77
|
+
* latitudes in radians into `out`, `[west, south, east, north]`, from the
|
|
78
|
+
* indices directly (`λ = 2π · col / 2^level − π`, `φ = atan(sinh(π − 2π · row /
|
|
79
|
+
* 2^level))`), so the tiles of a level share their edges exactly and the outer
|
|
80
|
+
* ones end at `±π` and `±` {@link WEB_MERCATOR_MAX_LATITUDE}. `NaN` components
|
|
81
|
+
* for a `NaN` index. O(1), no allocation.
|
|
82
|
+
*
|
|
83
|
+
* @returns `out`.
|
|
84
|
+
* @throws {RangeError} When `tile` is not a tile of WebMercatorQuad.
|
|
85
|
+
*/
|
|
86
|
+
export declare function webMercatorTileLongitudeLatitudeBounds(out: Box2, tile: Readonly<TileIndex>): Box2;
|
|
87
|
+
//# sourceMappingURL=web-mercator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-mercator.d.ts","sourceRoot":"","sources":["../../src/tile/web-mercator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,IAAI,EACJ,iBAAiB,EACjB,yBAAyB,EACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,SAAS,EAAsB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,IAAI,EAAc,MAAM,qBAAqB,CAAC;AAkB/E;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAAgC,CAAC;AAEvE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,IAAI,EACT,MAAM,EAAE,yBAAyB,GAC/B,IAAI,CAIN;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CACnC,GAAG,EAAE,iBAAiB,EACtB,KAAK,EAAE,YAAY,GACjB,iBAAiB,CAOnB;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,YAAY,EAC7D,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,YAAY,GACjB,CAAC,CAQH;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,YAAY,EAC/D,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,YAAY,GACjB,CAAC,CAYH;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAC1C,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACV,MAAM,CAQR;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAC1C,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,UAAU,SAAW,GACnB,MAAM,CAKR;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,SAAS,EACd,MAAM,EAAE,yBAAyB,EACjC,KAAK,EAAE,MAAM,GACX,SAAS,CAmBX;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sCAAsC,CACrD,GAAG,EAAE,IAAI,EACT,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,GACvB,IAAI,CAaN"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { tileAt, tileBounds } from "@ac-kit/math-grid";
|
|
2
|
+
import { vec2Create } from "@ac-kit/math-linear";
|
|
3
|
+
import { elementCount_ } from "../_array-length.js";
|
|
4
|
+
import { isometricLatitude_ } from "../_isometric.js";
|
|
5
|
+
import { WEB_MERCATOR_HALF_SIDE_, WEB_MERCATOR_RADIUS_, WEB_MERCATOR_TILE_SIZE_, } from "./_web-mercator.js";
|
|
6
|
+
import { WEB_MERCATOR_QUAD } from "./tile-matrix-sets.js";
|
|
7
|
+
// Web Mercator, EPSG:3857 ("WGS 84 / Pseudo-Mercator"): the spherical Mercator
|
|
8
|
+
// of `mercatorProject` on a sphere of WGS 84's equatorial radius `a`, applied
|
|
9
|
+
// to WGS 84 longitudes and latitudes as if they were spherical (IOGP Guidance
|
|
10
|
+
// Note 7-2, method 1024). Neither conformal nor equal to the ellipsoidal
|
|
11
|
+
// Mercator (EPSG:3395) it resembles; the y of a latitude differs by up to
|
|
12
|
+
// about 43 km.
|
|
13
|
+
/**
|
|
14
|
+
* The latitude limit of the Web Mercator square, `atan(sinh π)` radians (85.051
|
|
15
|
+
* 128 779 806 59°): the latitude whose plane y is `π · a`, the edge of
|
|
16
|
+
* WebMercatorQuad.
|
|
17
|
+
*/
|
|
18
|
+
export const WEB_MERCATOR_MAX_LATITUDE = Math.atan(Math.sinh(Math.PI));
|
|
19
|
+
/**
|
|
20
|
+
* Writes the EPSG:3857 point of `coords` (longitude, latitude in radians) into
|
|
21
|
+
* `out`, in metres: `x = a · λ`, `y = a · asinh(tan φ)`. A pole gives `y = ±∞`;
|
|
22
|
+
* a latitude outside `[−π/2, π/2]` or a `NaN` gives `NaN`, and a longitude
|
|
23
|
+
* outside `(−π, π]` is kept as it is.
|
|
24
|
+
*
|
|
25
|
+
* @returns `out`.
|
|
26
|
+
*/
|
|
27
|
+
export function webMercatorProject(out, coords) {
|
|
28
|
+
out[0] = WEB_MERCATOR_RADIUS_ * coords[0];
|
|
29
|
+
out[1] = WEB_MERCATOR_RADIUS_ * isometricLatitude_(coords[1]);
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Writes the longitude and latitude, in radians, of the EPSG:3857 point `point`
|
|
34
|
+
* (metres) into `out`: `λ = x / a`, `φ = atan(sinh(y / a))`. Any y is a
|
|
35
|
+
* latitude (a far one a pole); a point with `|x| > π · a` gives `NaN`.
|
|
36
|
+
*
|
|
37
|
+
* @returns `out`.
|
|
38
|
+
*/
|
|
39
|
+
export function webMercatorUnproject(out, point) {
|
|
40
|
+
const x = point[0];
|
|
41
|
+
const y = point[1];
|
|
42
|
+
const valid = Math.abs(x) <= WEB_MERCATOR_HALF_SIDE_ && y === y;
|
|
43
|
+
out[0] = valid ? x / WEB_MERCATOR_RADIUS_ : Number.NaN;
|
|
44
|
+
out[1] = valid ? Math.atan(Math.sinh(y / WEB_MERCATOR_RADIUS_)) : Number.NaN;
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Writes the EPSG:3857 point of every longitude–latitude pair of `input` into
|
|
49
|
+
* `out` (as many numbers), as {@link webMercatorProject} does for one. `out` may
|
|
50
|
+
* be `input`. O(n), no allocation.
|
|
51
|
+
*
|
|
52
|
+
* @returns `out`.
|
|
53
|
+
* @throws {RangeError} Unless `out` and `input` have the same even length.
|
|
54
|
+
*/
|
|
55
|
+
export function webMercatorProjectArray(out, input) {
|
|
56
|
+
const count = elementCount_("webMercatorProjectArray", out, input, 2, 2);
|
|
57
|
+
for (let index = 0; index < count; index++) {
|
|
58
|
+
out[2 * index] = WEB_MERCATOR_RADIUS_ * input[2 * index];
|
|
59
|
+
out[2 * index + 1] =
|
|
60
|
+
WEB_MERCATOR_RADIUS_ * isometricLatitude_(input[2 * index + 1]);
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Writes the longitude–latitude pair of every EPSG:3857 point of `input` into
|
|
66
|
+
* `out` (as many numbers), as {@link webMercatorUnproject} does for one. `out`
|
|
67
|
+
* may be `input`. O(n), no allocation.
|
|
68
|
+
*
|
|
69
|
+
* @returns `out`.
|
|
70
|
+
* @throws {RangeError} Unless `out` and `input` have the same even length.
|
|
71
|
+
*/
|
|
72
|
+
export function webMercatorUnprojectArray(out, input) {
|
|
73
|
+
const count = elementCount_("webMercatorUnprojectArray", out, input, 2, 2);
|
|
74
|
+
for (let index = 0; index < count; index++) {
|
|
75
|
+
const x = input[2 * index];
|
|
76
|
+
const y = input[2 * index + 1];
|
|
77
|
+
const valid = Math.abs(x) <= WEB_MERCATOR_HALF_SIDE_ && y === y;
|
|
78
|
+
out[2 * index] = valid ? x / WEB_MERCATOR_RADIUS_ : Number.NaN;
|
|
79
|
+
out[2 * index + 1] = valid
|
|
80
|
+
? Math.atan(Math.sinh(y / WEB_MERCATOR_RADIUS_))
|
|
81
|
+
: Number.NaN;
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The ground size of one WebMercatorQuad cell (a 256-pixel tile's pixel) at
|
|
87
|
+
* latitude `latitude` (radians) and zoom `zoom`, in metres on the sphere: `cos
|
|
88
|
+
* φ · 2π · a / (256 · 2^zoom)`, 156 543.03 m at the equator at zoom 0. The zoom
|
|
89
|
+
* is continuous, so a map drawn between levels gets its own value. `NaN` for a
|
|
90
|
+
* latitude outside `[−π/2, π/2]` or a `NaN`.
|
|
91
|
+
*/
|
|
92
|
+
export function webMercatorGroundResolution(latitude, zoom) {
|
|
93
|
+
if (!(Math.abs(latitude) <= Math.PI / 2)) {
|
|
94
|
+
return Number.NaN;
|
|
95
|
+
}
|
|
96
|
+
return ((Math.cos(latitude) * (2 * WEB_MERCATOR_HALF_SIDE_)) /
|
|
97
|
+
(WEB_MERCATOR_TILE_SIZE_ * 2 ** zoom));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The scale denominator of a WebMercatorQuad map at latitude `latitude`
|
|
101
|
+
* (radians) and zoom `zoom` shown with pixels `pixelSizeM` metres wide (the
|
|
102
|
+
* standard OGC 0.28 mm by default; `0.0254 / dpi` for a screen of known
|
|
103
|
+
* density): the ground resolution over the pixel size. At the equator it is the
|
|
104
|
+
* scale denominator of the level. `NaN` for a latitude outside `[−π/2, π/2]`, a
|
|
105
|
+
* non-positive pixel size or a `NaN`.
|
|
106
|
+
*/
|
|
107
|
+
export function webMercatorScaleDenominator(latitude, zoom, pixelSizeM = 0.00028) {
|
|
108
|
+
if (!(pixelSizeM > 0)) {
|
|
109
|
+
return Number.NaN;
|
|
110
|
+
}
|
|
111
|
+
return webMercatorGroundResolution(latitude, zoom) / pixelSizeM;
|
|
112
|
+
}
|
|
113
|
+
const POINT_ = vec2Create();
|
|
114
|
+
/**
|
|
115
|
+
* Writes the WebMercatorQuad tile of level `level` holding `coords` (longitude,
|
|
116
|
+
* latitude in radians) into `out`, as tile servers count it: a longitude
|
|
117
|
+
* outside `[−π, π]` is wrapped into it, a latitude beyond
|
|
118
|
+
* {@link WEB_MERCATOR_MAX_LATITUDE} (a pole included) goes to the first or last
|
|
119
|
+
* row, the antimeridian at `+π` to the last column; otherwise as `tileAt` of
|
|
120
|
+
* `@ac-kit/math-grid`. `col` and `row` are `NaN` for a latitude outside `[−π/2,
|
|
121
|
+
* π/2]`, an infinite longitude, a `NaN` or a `NaN` level. O(1), no allocation.
|
|
122
|
+
*
|
|
123
|
+
* @returns `out`.
|
|
124
|
+
* @throws {RangeError} When `level` is not an integer from 0 to 24.
|
|
125
|
+
*/
|
|
126
|
+
export function webMercatorTileAt(out, coords, level) {
|
|
127
|
+
let longitude = coords[0];
|
|
128
|
+
const latitude = coords[1];
|
|
129
|
+
if (!(Math.abs(latitude) <= Math.PI / 2) || longitude - longitude !== 0) {
|
|
130
|
+
POINT_[0] = Number.NaN;
|
|
131
|
+
POINT_[1] = Number.NaN;
|
|
132
|
+
return tileAt(out, WEB_MERCATOR_QUAD, level, POINT_);
|
|
133
|
+
}
|
|
134
|
+
if (longitude < -Math.PI || longitude > Math.PI) {
|
|
135
|
+
longitude -=
|
|
136
|
+
2 * Math.PI * Math.floor((longitude + Math.PI) / (2 * Math.PI));
|
|
137
|
+
}
|
|
138
|
+
const half = WEB_MERCATOR_HALF_SIDE_;
|
|
139
|
+
POINT_[0] = Math.min(Math.max(WEB_MERCATOR_RADIUS_ * longitude, -half), half);
|
|
140
|
+
POINT_[1] = Math.min(Math.max(WEB_MERCATOR_RADIUS_ * isometricLatitude_(latitude), -half), half);
|
|
141
|
+
return tileAt(out, WEB_MERCATOR_QUAD, level, POINT_);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Writes the extent of the WebMercatorQuad tile `tile` as longitudes and
|
|
145
|
+
* latitudes in radians into `out`, `[west, south, east, north]`, from the
|
|
146
|
+
* indices directly (`λ = 2π · col / 2^level − π`, `φ = atan(sinh(π − 2π · row /
|
|
147
|
+
* 2^level))`), so the tiles of a level share their edges exactly and the outer
|
|
148
|
+
* ones end at `±π` and `±` {@link WEB_MERCATOR_MAX_LATITUDE}. `NaN` components
|
|
149
|
+
* for a `NaN` index. O(1), no allocation.
|
|
150
|
+
*
|
|
151
|
+
* @returns `out`.
|
|
152
|
+
* @throws {RangeError} When `tile` is not a tile of WebMercatorQuad.
|
|
153
|
+
*/
|
|
154
|
+
export function webMercatorTileLongitudeLatitudeBounds(out, tile) {
|
|
155
|
+
tileBounds(out, WEB_MERCATOR_QUAD, tile);
|
|
156
|
+
if (out[0] !== out[0]) {
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
const size = 2 ** tile.level;
|
|
160
|
+
out[0] = ((2 * Math.PI) / size) * tile.col - Math.PI;
|
|
161
|
+
out[2] = ((2 * Math.PI) / size) * (tile.col + 1) - Math.PI;
|
|
162
|
+
out[3] = Math.atan(Math.sinh(Math.PI - ((2 * Math.PI) / size) * tile.row));
|
|
163
|
+
out[1] = Math.atan(Math.sinh(Math.PI - ((2 * Math.PI) / size) * (tile.row + 1)));
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=web-mercator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-mercator.js","sourceRoot":"","sources":["../../src/tile/web-mercator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAgC,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE/E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACN,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,+EAA+E;AAC/E,8EAA8E;AAC9E,8EAA8E;AAC9E,yEAAyE;AACzE,0EAA0E;AAC1E,eAAe;AAEf;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAEvE;;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,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;IAC3D,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3E,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CACjB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAC5D,CAAC;IACF,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-kit/math-map-projection",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Point maps between the sphere and the plane: azimuthal, cylindrical, conic and pseudo-cylindrical map and sky projections,
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Point maps between the sphere and the plane: azimuthal, cylindrical, conic and pseudo-cylindrical map and sky projections, the cutting, resampling and graticules a map needs, and the Web Mercator tile matrix sets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"azimuthal",
|
|
7
7
|
"cartography",
|
|
@@ -45,17 +45,20 @@
|
|
|
45
45
|
"prepack": "yarn build"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@ac-kit/core": "^0.
|
|
49
|
-
"@ac-kit/math-
|
|
50
|
-
"@ac-kit/math-
|
|
51
|
-
"@ac-kit/math-
|
|
48
|
+
"@ac-kit/core": "^0.14.0",
|
|
49
|
+
"@ac-kit/math-geodesy": "^0.2.0",
|
|
50
|
+
"@ac-kit/math-geometry": "^0.5.0",
|
|
51
|
+
"@ac-kit/math-grid": "^0.5.0",
|
|
52
|
+
"@ac-kit/math-linear": "^0.5.0",
|
|
53
|
+
"@ac-kit/math-scalar": "^0.5.0",
|
|
52
54
|
"@types/web": "^0.0.367"
|
|
53
55
|
},
|
|
54
56
|
"devDependencies": {
|
|
55
|
-
"@ac-kit/math-random": "0.4.
|
|
57
|
+
"@ac-kit/math-random": "0.4.2",
|
|
58
|
+
"@ac-kit/test-util": "0.5.1",
|
|
56
59
|
"@ac-kit/tsconfig": "0.1.0",
|
|
57
60
|
"@ac-kit/typedoc-config": "0.1.0",
|
|
58
|
-
"@ac-kit/vitest-config": "0.
|
|
61
|
+
"@ac-kit/vitest-config": "0.3.0",
|
|
59
62
|
"@types/d3-geo": "3.1.1",
|
|
60
63
|
"@types/node": "26.6.11",
|
|
61
64
|
"@typescript/native": "typescript@7.0.2",
|