@spacexr/tiles 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +57 -2
- package/dist/addressing/index.d.ts +16 -0
- package/dist/addressing/index.js +4 -0
- package/dist/addressing/index.js.map +1 -0
- package/dist/bake/index.d.ts +91 -0
- package/dist/bake/index.js +3 -0
- package/dist/bake/index.js.map +1 -0
- package/dist/celestial-dataset-CUIsplKO.d.ts +99 -0
- package/dist/chunk-2HLQXRDD.js +246 -0
- package/dist/chunk-2HLQXRDD.js.map +1 -0
- package/dist/chunk-6YNCRDEE.js +170 -0
- package/dist/chunk-6YNCRDEE.js.map +1 -0
- package/dist/chunk-7AWV2IEK.js +79 -0
- package/dist/chunk-7AWV2IEK.js.map +1 -0
- package/dist/chunk-ESLGXWQR.js +219 -0
- package/dist/chunk-ESLGXWQR.js.map +1 -0
- package/dist/chunk-FB57CZDK.js +312 -0
- package/dist/chunk-FB57CZDK.js.map +1 -0
- package/dist/chunk-GRTG4WNA.js +44 -0
- package/dist/chunk-GRTG4WNA.js.map +1 -0
- package/dist/chunk-HVYN4AIT.js +45 -0
- package/dist/chunk-HVYN4AIT.js.map +1 -0
- package/dist/chunk-IGNRXAW3.js +77 -0
- package/dist/chunk-IGNRXAW3.js.map +1 -0
- package/dist/chunk-QGTREKHS.js +145 -0
- package/dist/chunk-QGTREKHS.js.map +1 -0
- package/dist/chunk-SPDRAY37.js +56 -0
- package/dist/chunk-SPDRAY37.js.map +1 -0
- package/dist/chunk-TA4BEVHL.js +81 -0
- package/dist/chunk-TA4BEVHL.js.map +1 -0
- package/dist/chunk-TGOB5HT5.js +149 -0
- package/dist/chunk-TGOB5HT5.js.map +1 -0
- package/dist/chunk-X6ZJ2PDY.js +104 -0
- package/dist/chunk-X6ZJ2PDY.js.map +1 -0
- package/dist/chunk-XTY4HCPY.js +22 -0
- package/dist/chunk-XTY4HCPY.js.map +1 -0
- package/dist/chunk-Y66PNDG2.js +107 -0
- package/dist/chunk-Y66PNDG2.js.map +1 -0
- package/dist/chunk-YEACOJOC.js +51 -0
- package/dist/chunk-YEACOJOC.js.map +1 -0
- package/dist/cube/index.d.ts +160 -0
- package/dist/cube/index.js +9 -0
- package/dist/cube/index.js.map +1 -0
- package/dist/datasets/index.d.ts +75 -0
- package/dist/datasets/index.js +11 -0
- package/dist/datasets/index.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/mercator/index.d.ts +24 -0
- package/dist/mercator/index.js +8 -0
- package/dist/mercator/index.js.map +1 -0
- package/dist/metrics-HGbzqj6L.d.ts +45 -0
- package/dist/pyramid/index.d.ts +156 -0
- package/dist/pyramid/index.js +4 -0
- package/dist/pyramid/index.js.map +1 -0
- package/dist/raster-registration-CgBxrhDB.d.ts +19 -0
- package/dist/reference-surface-CsTtrNsc.d.ts +49 -0
- package/dist/reprojection/index.d.ts +255 -0
- package/dist/reprojection/index.js +6 -0
- package/dist/reprojection/index.js.map +1 -0
- package/dist/sources/index.d.ts +55 -0
- package/dist/sources/index.js +7 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/surface/index.d.ts +15 -0
- package/dist/surface/index.js +4 -0
- package/dist/surface/index.js.map +1 -0
- package/dist/tile-D-jjIRRA.d.ts +53 -0
- package/dist/tile-address-BkfSftp6.d.ts +66 -0
- package/dist/tile-http-client-BHZOtGX7.d.ts +73 -0
- package/dist/tile-neighbors-LfvV7oiX.d.ts +48 -0
- package/dist/tile-surface-s9Zi6X9_.d.ts +40 -0
- package/dist/tile-topology-B6xHYqPb.d.ts +51 -0
- package/dist/web-mercator-dataset-Dmou8byO.d.ts +125 -0
- package/dist/web-tile-source-DrZDBIm6.d.ts +92 -0
- package/package.json +122 -5
- package/src/addressing/index.ts +8 -0
- package/src/addressing/metrics.ts +48 -0
- package/src/addressing/raster-registration.ts +22 -0
- package/src/addressing/tile-address.ts +130 -0
- package/src/addressing/tile-edge-rotation.ts +13 -0
- package/src/addressing/tile-neighbors.ts +73 -0
- package/src/addressing/tile-surface.ts +44 -0
- package/src/addressing/tile-topology.ts +86 -0
- package/src/addressing/tile.ts +73 -0
- package/src/bake/bake-pyramid.ts +106 -0
- package/src/bake/index.ts +2 -0
- package/src/bake/pyramid-levels.ts +63 -0
- package/src/cube/celestial-dataset.ts +182 -0
- package/src/cube/cube-face.ts +51 -0
- package/src/cube/cube-geometric-error.ts +30 -0
- package/src/cube/cube-mapping.ts +101 -0
- package/src/cube/cube-neighbors.ts +198 -0
- package/src/cube/cube-tile-surface.ts +30 -0
- package/src/cube/index.ts +6 -0
- package/src/datasets/index.ts +1 -0
- package/src/datasets/tile-dataset.ts +121 -0
- package/src/index.ts +9 -0
- package/src/mercator/index.ts +3 -0
- package/src/mercator/web-mercator-dataset.ts +215 -0
- package/src/mercator/web-mercator-tile-metrics.ts +119 -0
- package/src/mercator/web-mercator-tile-surface.ts +52 -0
- package/src/pyramid/index.ts +2 -0
- package/src/pyramid/resident-tiles.ts +81 -0
- package/src/pyramid/tile-pyramid.ts +285 -0
- package/src/reprojection/cube-resampling.ts +159 -0
- package/src/reprojection/index.ts +4 -0
- package/src/reprojection/source-projection.ts +196 -0
- package/src/reprojection/source-tile-matrix.ts +100 -0
- package/src/reprojection/wmts-capabilities.ts +112 -0
- package/src/sources/index.ts +4 -0
- package/src/sources/tile-http-client.ts +154 -0
- package/src/sources/tile-layer-changes.ts +88 -0
- package/src/sources/url-template.ts +96 -0
- package/src/sources/web-tile-source.ts +73 -0
- package/src/surface/directions.ts +27 -0
- package/src/surface/index.ts +2 -0
- package/src/surface/reference-surface.ts +88 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { WebTileSource } from './chunk-YEACOJOC.js';
|
|
2
|
+
import { validateTileUrlTemplate } from './chunk-6YNCRDEE.js';
|
|
3
|
+
import { assertRasterRegistration } from './chunk-X6ZJ2PDY.js';
|
|
4
|
+
import { GeodeticSystem, Ellipsoid } from '@spacexr/geodesy';
|
|
5
|
+
|
|
6
|
+
// src/mercator/web-mercator-tile-metrics.ts
|
|
7
|
+
var WEB_MERCATOR_MAX_LATITUDE = 85.0511287798066;
|
|
8
|
+
function clamp(value, minimum, maximum) {
|
|
9
|
+
return Math.min(Math.max(value, minimum), maximum);
|
|
10
|
+
}
|
|
11
|
+
var WebMercatorTileMetrics = class {
|
|
12
|
+
constructor(options, geodeticSystem) {
|
|
13
|
+
this.geodeticSystem = geodeticSystem;
|
|
14
|
+
if (!geodeticSystem) throw new TypeError("An explicit geodetic system is required.");
|
|
15
|
+
if (!Number.isInteger(options.minLOD) || !Number.isInteger(options.maxLOD) || options.minLOD < 0 || options.maxLOD < options.minLOD)
|
|
16
|
+
throw new RangeError("Tile metrics require integer LOD bounds with 0 <= minLOD <= maxLOD.");
|
|
17
|
+
const tileSize = options.tileSize ?? 256;
|
|
18
|
+
if (!Number.isFinite(tileSize) || tileSize <= 0) throw new RangeError("Tile size must be a positive finite number.");
|
|
19
|
+
this.minLOD = options.minLOD;
|
|
20
|
+
this.maxLOD = options.maxLOD;
|
|
21
|
+
this.tileSize = tileSize;
|
|
22
|
+
this.cellSize = options.cellSize ?? 1;
|
|
23
|
+
this.cellCoordinateReference = options.cellCoordinateReference ?? 0 /* Center */;
|
|
24
|
+
this.overlap = options.overlap ?? 0;
|
|
25
|
+
}
|
|
26
|
+
geodeticSystem;
|
|
27
|
+
minLatitude = -WEB_MERCATOR_MAX_LATITUDE;
|
|
28
|
+
maxLatitude = WEB_MERCATOR_MAX_LATITUDE;
|
|
29
|
+
minLongitude = -180;
|
|
30
|
+
maxLongitude = 180;
|
|
31
|
+
minLOD;
|
|
32
|
+
maxLOD;
|
|
33
|
+
tileSize;
|
|
34
|
+
cellSize;
|
|
35
|
+
cellCoordinateReference;
|
|
36
|
+
overlap;
|
|
37
|
+
mapSize(levelOfDetail) {
|
|
38
|
+
this.assertLOD(levelOfDetail);
|
|
39
|
+
return this.tileSize * 2 ** levelOfDetail;
|
|
40
|
+
}
|
|
41
|
+
mapScale(latitudeDegrees, levelOfDetail, pixelsPerUnit) {
|
|
42
|
+
if (pixelsPerUnit === 0) return Number.POSITIVE_INFINITY;
|
|
43
|
+
const resolution = this.groundResolution(latitudeDegrees, levelOfDetail);
|
|
44
|
+
return resolution === 0 ? Number.POSITIVE_INFINITY : 1 / (resolution * pixelsPerUnit);
|
|
45
|
+
}
|
|
46
|
+
groundResolution(latitudeDegrees, levelOfDetail) {
|
|
47
|
+
const latitude = clamp(latitudeDegrees, this.minLatitude, this.maxLatitude);
|
|
48
|
+
const circumference = 2 * Math.PI * this.geodeticSystem.ellipsoid.semiMajorAxis;
|
|
49
|
+
return Math.cos(latitude * Math.PI / 180) * circumference / this.mapSize(levelOfDetail);
|
|
50
|
+
}
|
|
51
|
+
getLatLonToTileXY(latitudeDegrees, longitudeDegrees, levelOfDetail) {
|
|
52
|
+
const point = this.getLatLonToPointXY(latitudeDegrees, longitudeDegrees, levelOfDetail);
|
|
53
|
+
const tile = this.getPointXYToTileXY(point.x, point.y);
|
|
54
|
+
const lastTile = 2 ** levelOfDetail - 1;
|
|
55
|
+
return { x: Math.min(tile.x, lastTile), y: Math.min(tile.y, lastTile) };
|
|
56
|
+
}
|
|
57
|
+
getTileXYToLatLon(x, y, levelOfDetail) {
|
|
58
|
+
const point = this.getTileXYToPointXY(x, y);
|
|
59
|
+
return this.getPointXYToLatLon(point.x, point.y, levelOfDetail);
|
|
60
|
+
}
|
|
61
|
+
getLatLonToPointXY(latitudeDegrees, longitudeDegrees, levelOfDetail) {
|
|
62
|
+
const latitude = clamp(latitudeDegrees, this.minLatitude, this.maxLatitude);
|
|
63
|
+
const longitude = clamp(longitudeDegrees, this.minLongitude, this.maxLongitude);
|
|
64
|
+
const normalizedX = (longitude + 180) / 360;
|
|
65
|
+
const sineLatitude = Math.sin(latitude * Math.PI / 180);
|
|
66
|
+
const normalizedY = 0.5 - Math.log((1 + sineLatitude) / (1 - sineLatitude)) / (4 * Math.PI);
|
|
67
|
+
const mapSize = this.mapSize(levelOfDetail);
|
|
68
|
+
return {
|
|
69
|
+
x: clamp(normalizedX * mapSize, 0, mapSize),
|
|
70
|
+
y: clamp(normalizedY * mapSize, 0, mapSize)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
getPointXYToLatLon(x, y, levelOfDetail) {
|
|
74
|
+
const mapSize = this.mapSize(levelOfDetail);
|
|
75
|
+
const normalizedX = clamp(x, 0, mapSize) / mapSize - 0.5;
|
|
76
|
+
const normalizedY = 0.5 - clamp(y, 0, mapSize) / mapSize;
|
|
77
|
+
return {
|
|
78
|
+
latitude: 90 - 360 * Math.atan(Math.exp(-normalizedY * 2 * Math.PI)) / Math.PI,
|
|
79
|
+
longitude: 360 * normalizedX
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
getTileXYToPointXY(x, y) {
|
|
83
|
+
return { x: x * this.tileSize, y: y * this.tileSize };
|
|
84
|
+
}
|
|
85
|
+
getPointXYToTileXY(x, y) {
|
|
86
|
+
return {
|
|
87
|
+
x: Math.floor(x / this.tileSize),
|
|
88
|
+
y: Math.floor(y / this.tileSize)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
assertLOD(levelOfDetail) {
|
|
92
|
+
if (!Number.isInteger(levelOfDetail) || levelOfDetail < this.minLOD || levelOfDetail > this.maxLOD)
|
|
93
|
+
throw new RangeError(`LOD ${levelOfDetail} is outside [${this.minLOD}, ${this.maxLOD}].`);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var WEB_MERCATOR_SCHEME = "spacexr-web-mercator/1";
|
|
97
|
+
function fail(message) {
|
|
98
|
+
throw new RangeError(`Invalid Web Mercator dataset: ${message}`);
|
|
99
|
+
}
|
|
100
|
+
function text(value, name) {
|
|
101
|
+
const member = value[name];
|
|
102
|
+
if (typeof member !== "string" || member.length === 0) fail(`${name} must be a non-empty string.`);
|
|
103
|
+
return member;
|
|
104
|
+
}
|
|
105
|
+
function level(value, name) {
|
|
106
|
+
const member = value[name];
|
|
107
|
+
if (!Number.isInteger(member) || member < 0 || member > 30) fail(`${name} must be a level from 0 to 30.`);
|
|
108
|
+
return member;
|
|
109
|
+
}
|
|
110
|
+
function bounds(value) {
|
|
111
|
+
if (value === void 0) return void 0;
|
|
112
|
+
if (typeof value !== "object" || value === null) fail("bounds must be an object.");
|
|
113
|
+
const box = value;
|
|
114
|
+
const [west, south, east, north] = ["west", "south", "east", "north"].map((name) => box[name]);
|
|
115
|
+
if (![west, south, east, north].every((v) => typeof v === "number" && Number.isFinite(v))) fail("bounds needs four finite numbers of degrees.");
|
|
116
|
+
const w = west, s = south, e = east, n = north;
|
|
117
|
+
if (w < -180 || e > 180 || w >= e || s < -90 || n > 90 || s >= n) fail("bounds must satisfy -180 <= west < east <= 180 and -90 <= south < north <= 90.");
|
|
118
|
+
return { west: w, south: s, east: e, north: n };
|
|
119
|
+
}
|
|
120
|
+
function parseWebMercatorDataset(value) {
|
|
121
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) fail("the descriptor must be an object.");
|
|
122
|
+
const source = value;
|
|
123
|
+
const scheme = text(source, "scheme");
|
|
124
|
+
if (scheme !== WEB_MERCATOR_SCHEME) fail(`scheme ${scheme} is not supported, expected ${WEB_MERCATOR_SCHEME}.`);
|
|
125
|
+
const radii = source.referenceRadii;
|
|
126
|
+
if (!Array.isArray(radii) || radii.length !== 3 || radii.some((radius) => typeof radius !== "number" || !Number.isFinite(radius) || radius <= 0)) {
|
|
127
|
+
fail("referenceRadii must be three positive numbers of metres.");
|
|
128
|
+
}
|
|
129
|
+
if (radii[0] !== radii[1]) fail("referenceRadii must describe an ellipsoid of revolution: a equals b.");
|
|
130
|
+
const content = source.content;
|
|
131
|
+
if (content !== "elevation" && content !== "imagery" && content !== "normals") fail("content must be elevation, imagery or normals.");
|
|
132
|
+
const tileSize = source.tileSize;
|
|
133
|
+
if (!Number.isInteger(tileSize) || tileSize < 1) fail("tileSize must be a positive integer.");
|
|
134
|
+
const minLOD = level(source, "minLOD");
|
|
135
|
+
const maxLOD = level(source, "maxLOD");
|
|
136
|
+
if (minLOD > maxLOD) fail("minLOD must not exceed maxLOD.");
|
|
137
|
+
const registration = source.registration ?? "area";
|
|
138
|
+
try {
|
|
139
|
+
assertRasterRegistration(registration);
|
|
140
|
+
} catch {
|
|
141
|
+
fail("registration must be area or point.");
|
|
142
|
+
}
|
|
143
|
+
const rawSubdomains = source.subdomains;
|
|
144
|
+
if (rawSubdomains !== void 0 && (!Array.isArray(rawSubdomains) || rawSubdomains.some((s) => typeof s !== "string" || s.length === 0))) {
|
|
145
|
+
fail("subdomains must be an array of non-empty strings.");
|
|
146
|
+
}
|
|
147
|
+
const subdomains = rawSubdomains;
|
|
148
|
+
const tiles = text(source, "tiles");
|
|
149
|
+
validateTileUrlTemplate(tiles, subdomains ? { subdomains } : {});
|
|
150
|
+
const box = bounds(source.bounds);
|
|
151
|
+
return {
|
|
152
|
+
scheme,
|
|
153
|
+
body: text(source, "body"),
|
|
154
|
+
referenceRadii: [radii[0], radii[1], radii[2]],
|
|
155
|
+
content,
|
|
156
|
+
encoding: text(source, "encoding"),
|
|
157
|
+
tileSize,
|
|
158
|
+
minLOD,
|
|
159
|
+
maxLOD,
|
|
160
|
+
...box ? { bounds: box } : {},
|
|
161
|
+
registration,
|
|
162
|
+
tiles,
|
|
163
|
+
...subdomains ? { subdomains: [...subdomains] } : {},
|
|
164
|
+
attribution: text(source, "attribution")
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function webMercatorDatasetDescriptor(dataset, extras) {
|
|
168
|
+
const checked = parseWebMercatorDataset({ ...dataset, scheme: WEB_MERCATOR_SCHEME });
|
|
169
|
+
return { ...checked, ...extras ? { extras } : {} };
|
|
170
|
+
}
|
|
171
|
+
function corner(lod, x, y) {
|
|
172
|
+
const n = 2 ** lod;
|
|
173
|
+
return { longitude: x / n * 360 - 180, latitude: Math.atan(Math.sinh(Math.PI * (1 - 2 * y / n))) * 180 / Math.PI };
|
|
174
|
+
}
|
|
175
|
+
var WebMercatorDatasetSource = class {
|
|
176
|
+
dataset;
|
|
177
|
+
metrics;
|
|
178
|
+
/** The HTTP source of the tiles, for consumers that take a {@link WebTileSource}. */
|
|
179
|
+
source;
|
|
180
|
+
/** @param dataset - The descriptor, or its JSON value, checked by {@link parseWebMercatorDataset}. */
|
|
181
|
+
constructor(dataset, options = {}) {
|
|
182
|
+
this.dataset = parseWebMercatorDataset(dataset);
|
|
183
|
+
const [a, , c] = this.dataset.referenceRadii;
|
|
184
|
+
const system = options.geodeticSystem ?? new GeodeticSystem(Ellipsoid.fromAxes(this.dataset.body, a, c));
|
|
185
|
+
this.metrics = new WebMercatorTileMetrics({ minLOD: 0, maxLOD: this.dataset.maxLOD, tileSize: this.dataset.tileSize }, system);
|
|
186
|
+
this.source = new WebTileSource({
|
|
187
|
+
id: `${this.dataset.body}-${this.dataset.content}`,
|
|
188
|
+
urlTemplate: this.dataset.tiles,
|
|
189
|
+
metrics: this.metrics,
|
|
190
|
+
registration: this.dataset.registration,
|
|
191
|
+
attribution: this.dataset.attribution,
|
|
192
|
+
...this.dataset.subdomains ? { subdomains: [...this.dataset.subdomains] } : {},
|
|
193
|
+
...options.client ? { client: options.client } : {}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
get attribution() {
|
|
197
|
+
return this.dataset.attribution;
|
|
198
|
+
}
|
|
199
|
+
/** Whether the dataset declares a tile: its level is in range and it meets the bounds. */
|
|
200
|
+
isAvailable(address) {
|
|
201
|
+
const { lod, x, y } = address;
|
|
202
|
+
if (!Number.isInteger(lod) || lod < this.dataset.minLOD || lod > this.dataset.maxLOD) return false;
|
|
203
|
+
const n = 2 ** lod;
|
|
204
|
+
if (!Number.isInteger(x) || !Number.isInteger(y) || x < 0 || y < 0 || x >= n || y >= n) return false;
|
|
205
|
+
const box = this.dataset.bounds;
|
|
206
|
+
if (!box) return true;
|
|
207
|
+
const northWest = corner(lod, x, y), southEast = corner(lod, x + 1, y + 1);
|
|
208
|
+
return northWest.longitude < box.east && southEast.longitude > box.west && southEast.latitude < box.north && northWest.latitude > box.south;
|
|
209
|
+
}
|
|
210
|
+
/** Fetches a tile; a tile the dataset does not declare resolves as absent, like a 404, without any request. */
|
|
211
|
+
async fetchTile(address, signal) {
|
|
212
|
+
if (!this.isAvailable(address)) return { status: "absent", url: "", httpStatus: 404 };
|
|
213
|
+
return this.source.fetchTile(address, signal);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export { WEB_MERCATOR_SCHEME, WebMercatorDatasetSource, WebMercatorTileMetrics, parseWebMercatorDataset, webMercatorDatasetDescriptor };
|
|
218
|
+
//# sourceMappingURL=chunk-ESLGXWQR.js.map
|
|
219
|
+
//# sourceMappingURL=chunk-ESLGXWQR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mercator/web-mercator-tile-metrics.ts","../src/mercator/web-mercator-dataset.ts"],"names":[],"mappings":";;;;;;AAIA,IAAM,yBAAA,GAA4B,gBAAA;AAWlC,SAAS,KAAA,CAAM,KAAA,EAAe,OAAA,EAAiB,OAAA,EAAyB;AACpE,EAAA,OAAO,KAAK,GAAA,CAAI,IAAA,CAAK,IAAI,KAAA,EAAO,OAAO,GAAG,OAAO,CAAA;AACrD;AAGO,IAAM,yBAAN,MAAqD;AAAA,EAYjD,WAAA,CACH,SACgB,cAAA,EAClB;AADkB,IAAA,IAAA,CAAA,cAAA,GAAA,cAAA;AAEhB,IAAA,IAAI,CAAC,cAAA,EAAgB,MAAM,IAAI,UAAU,0CAA0C,CAAA;AACnF,IAAA,IAAI,CAAC,MAAA,CAAO,SAAA,CAAU,OAAA,CAAQ,MAAM,KAAK,CAAC,MAAA,CAAO,SAAA,CAAU,OAAA,CAAQ,MAAM,CAAA,IAAK,OAAA,CAAQ,SAAS,CAAA,IAAK,OAAA,CAAQ,SAAS,OAAA,CAAQ,MAAA;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MAAA,CAAO,SAAA,CAAU,CAAC,CAAA,IAAK,CAAC,OAAO,SAAA,CAAU,CAAC,CAAA,IAAK,CAAA,GAAI,KAAK,CAAA,GAAI,CAAA,IAAK,KAAK,CAAA,IAAK,CAAA,IAAK,GAAG,OAAO,KAAA;AAC/F,IAAA,MAAM,GAAA,GAAM,KAAK,OAAA,CAAQ,MAAA;AACzB,IAAA,IAAI,CAAC,KAAK,OAAO,IAAA;AACjB,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,GAAA,EAAK,CAAA,EAAG,CAAC,CAAA,EAC9B,SAAA,GAAY,MAAA,CAAO,GAAA,EAAK,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,CAAC,CAAA;AACxC,IAAA,OAAO,SAAA,CAAU,SAAA,GAAY,GAAA,CAAI,IAAA,IAAQ,UAAU,SAAA,GAAY,GAAA,CAAI,IAAA,IAAQ,SAAA,CAAU,QAAA,GAAW,GAAA,CAAI,KAAA,IAAS,SAAA,CAAU,WAAW,GAAA,CAAI,KAAA;AAAA,EAC1I;AAAA;AAAA,EAGA,MAAa,SAAA,CAAU,OAAA,EAAuB,MAAA,EAAgD;AAC1F,IAAA,IAAI,CAAC,IAAA,CAAK,WAAA,CAAY,OAAO,CAAA,EAAG,OAAO,EAAE,MAAA,EAAQ,QAAA,EAAU,GAAA,EAAK,EAAA,EAAI,UAAA,EAAY,GAAA,EAAI;AACpF,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,SAAA,CAAU,OAAA,EAAS,MAAM,CAAA;AAAA,EAChD;AACJ","file":"chunk-ESLGXWQR.js","sourcesContent":["import { GeodeticSystem } from \"@spacexr/geodesy\";\n\nimport { CellCoordinateReference, type ICartesian2, type IGeographic2, type ITileMetrics } from \"../addressing/metrics\";\n\nconst WEB_MERCATOR_MAX_LATITUDE = 85.0511287798066;\n\nexport interface IWebMercatorTileMetricsOptions {\n minLOD: number;\n maxLOD: number;\n tileSize?: number;\n cellSize?: number;\n cellCoordinateReference?: CellCoordinateReference;\n overlap?: number;\n}\n\nfunction clamp(value: number, minimum: number, maximum: number): number {\n return Math.min(Math.max(value, minimum), maximum);\n}\n\n/** Immutable EPSG:3857 tile metrics backed by a geodetic ellipsoid. */\nexport class WebMercatorTileMetrics implements ITileMetrics {\n public readonly minLatitude = -WEB_MERCATOR_MAX_LATITUDE;\n public readonly maxLatitude = WEB_MERCATOR_MAX_LATITUDE;\n public readonly minLongitude = -180;\n public readonly maxLongitude = 180;\n public readonly minLOD: number;\n public readonly maxLOD: number;\n public readonly tileSize: number;\n public readonly cellSize: number;\n public readonly cellCoordinateReference: CellCoordinateReference;\n public readonly overlap: number;\n\n public constructor(\n options: IWebMercatorTileMetricsOptions,\n public readonly geodeticSystem: GeodeticSystem\n ) {\n if (!geodeticSystem) throw new TypeError(\"An explicit geodetic system is required.\");\n if (!Number.isInteger(options.minLOD) || !Number.isInteger(options.maxLOD) || options.minLOD < 0 || options.maxLOD < options.minLOD)\n throw new RangeError(\"Tile metrics require integer LOD bounds with 0 <= minLOD <= maxLOD.\");\n const tileSize = options.tileSize ?? 256;\n if (!Number.isFinite(tileSize) || tileSize <= 0) throw new RangeError(\"Tile size must be a positive finite number.\");\n\n this.minLOD = options.minLOD;\n this.maxLOD = options.maxLOD;\n this.tileSize = tileSize;\n this.cellSize = options.cellSize ?? 1;\n this.cellCoordinateReference = options.cellCoordinateReference ?? CellCoordinateReference.Center;\n this.overlap = options.overlap ?? 0;\n }\n\n public mapSize(levelOfDetail: number): number {\n this.assertLOD(levelOfDetail);\n return this.tileSize * 2 ** levelOfDetail;\n }\n\n public mapScale(latitudeDegrees: number, levelOfDetail: number, pixelsPerUnit: number): number {\n if (pixelsPerUnit === 0) return Number.POSITIVE_INFINITY;\n const resolution = this.groundResolution(latitudeDegrees, levelOfDetail);\n return resolution === 0 ? Number.POSITIVE_INFINITY : 1 / (resolution * pixelsPerUnit);\n }\n\n public groundResolution(latitudeDegrees: number, levelOfDetail: number): number {\n const latitude = clamp(latitudeDegrees, this.minLatitude, this.maxLatitude);\n const circumference = 2 * Math.PI * this.geodeticSystem.ellipsoid.semiMajorAxis;\n return (Math.cos((latitude * Math.PI) / 180) * circumference) / this.mapSize(levelOfDetail);\n }\n\n public getLatLonToTileXY(latitudeDegrees: number, longitudeDegrees: number, levelOfDetail: number): ICartesian2 {\n const point = this.getLatLonToPointXY(latitudeDegrees, longitudeDegrees, levelOfDetail);\n const tile = this.getPointXYToTileXY(point.x, point.y);\n // The east and south map edges belong to the last tile, not to a tile beyond the pyramid.\n const lastTile = 2 ** levelOfDetail - 1;\n return { x: Math.min(tile.x, lastTile), y: Math.min(tile.y, lastTile) };\n }\n\n public getTileXYToLatLon(x: number, y: number, levelOfDetail: number): IGeographic2 {\n const point = this.getTileXYToPointXY(x, y);\n return this.getPointXYToLatLon(point.x, point.y, levelOfDetail);\n }\n\n public getLatLonToPointXY(latitudeDegrees: number, longitudeDegrees: number, levelOfDetail: number): ICartesian2 {\n const latitude = clamp(latitudeDegrees, this.minLatitude, this.maxLatitude);\n const longitude = clamp(longitudeDegrees, this.minLongitude, this.maxLongitude);\n const normalizedX = (longitude + 180) / 360;\n const sineLatitude = Math.sin((latitude * Math.PI) / 180);\n const normalizedY = 0.5 - Math.log((1 + sineLatitude) / (1 - sineLatitude)) / (4 * Math.PI);\n const mapSize = this.mapSize(levelOfDetail);\n return {\n x: clamp(normalizedX * mapSize, 0, mapSize),\n y: clamp(normalizedY * mapSize, 0, mapSize),\n };\n }\n\n public getPointXYToLatLon(x: number, y: number, levelOfDetail: number): IGeographic2 {\n const mapSize = this.mapSize(levelOfDetail);\n const normalizedX = clamp(x, 0, mapSize) / mapSize - 0.5;\n const normalizedY = 0.5 - clamp(y, 0, mapSize) / mapSize;\n return {\n latitude: 90 - (360 * Math.atan(Math.exp(-normalizedY * 2 * Math.PI))) / Math.PI,\n longitude: 360 * normalizedX,\n };\n }\n\n public getTileXYToPointXY(x: number, y: number): ICartesian2 {\n return { x: x * this.tileSize, y: y * this.tileSize };\n }\n\n public getPointXYToTileXY(x: number, y: number): ICartesian2 {\n return {\n x: Math.floor(x / this.tileSize),\n y: Math.floor(y / this.tileSize),\n };\n }\n\n private assertLOD(levelOfDetail: number): void {\n if (!Number.isInteger(levelOfDetail) || levelOfDetail < this.minLOD || levelOfDetail > this.maxLOD)\n throw new RangeError(`LOD ${levelOfDetail} is outside [${this.minLOD}, ${this.maxLOD}].`);\n }\n}\n","import { Ellipsoid, GeodeticSystem } from \"@spacexr/geodesy\";\n\nimport { assertRasterRegistration, type ITileAddress, type RasterRegistration } from \"../addressing\";\nimport { TileHttpClient, type ITileHttpClientOptions, type TileFetchResult } from \"../sources/tile-http-client\";\nimport { validateTileUrlTemplate } from \"../sources/url-template\";\nimport { WebTileSource } from \"../sources/web-tile-source\";\nimport { WebMercatorTileMetrics } from \"./web-mercator-tile-metrics\";\n\n/** Scheme of the Web Mercator datasets of this version of the specification. */\nexport const WEB_MERCATOR_SCHEME = \"spacexr-web-mercator/1\";\n\n/** What the tiles of a dataset hold. */\nexport type TileDatasetContent = \"elevation\" | \"imagery\" | \"normals\";\n\n/** A rectangle in degrees of longitude and latitude on the reference surface of a dataset. */\nexport interface IDatasetBounds {\n readonly west: number;\n readonly south: number;\n readonly east: number;\n readonly north: number;\n}\n\n/**\n * Descriptor of a Web Mercator (EPSG:3857 tiling, XYZ addressing, `y` from the north) dataset of a tile service: a\n * provider such as an elevation or imagery pyramid is described by this data, never by code.\n */\nexport interface IWebMercatorDataset {\n /** This specification and its version: {@link WEB_MERCATOR_SCHEME}. */\n readonly scheme: string;\n /** Catalogue name of the body, such as `Earth`. */\n readonly body: string;\n /** Radii `a`, `b`, `c` of the ellipsoid of revolution the tiles are computed on, in metres: `a` equals `b`. */\n readonly referenceRadii: readonly [number, number, number];\n readonly content: TileDatasetContent;\n /** Tile format: `terrarium` heights, `mapzen-normal` normals, or an image format such as `png`, `jpeg`, `webp`. */\n readonly encoding: string;\n /** Pixels per tile side. */\n readonly tileSize: number;\n /** Levels available inside {@link bounds}, from `minLOD` to `maxLOD`. */\n readonly minLOD: number;\n readonly maxLOD: number;\n /** Where the dataset has tiles; the whole Web Mercator square when absent. A tile outside is never requested. */\n readonly bounds?: IDatasetBounds;\n /** Where the samples of the tiles lie: `area` for images, the usual case. */\n readonly registration: RasterRegistration;\n /** URL template; a relative one is resolved against the URL of its descriptor by {@link loadTileDataset}. */\n readonly tiles: string;\n /** Values of `{s}` in the template, rotated between requests. */\n readonly subdomains?: readonly string[];\n /** Text applications must display with the tiles. */\n readonly attribution: string;\n}\n\nfunction fail(message: string): never {\n throw new RangeError(`Invalid Web Mercator dataset: ${message}`);\n}\n\nfunction text(value: Record<string, unknown>, name: string): string {\n const member = value[name];\n if (typeof member !== \"string\" || member.length === 0) fail(`${name} must be a non-empty string.`);\n return member;\n}\n\nfunction level(value: Record<string, unknown>, name: string): number {\n const member = value[name];\n if (!Number.isInteger(member) || (member as number) < 0 || (member as number) > 30) fail(`${name} must be a level from 0 to 30.`);\n return member as number;\n}\n\nfunction bounds(value: unknown): IDatasetBounds | undefined {\n if (value === undefined) return undefined;\n if (typeof value !== \"object\" || value === null) fail(\"bounds must be an object.\");\n const box = value as Record<string, unknown>;\n const [west, south, east, north] = [\"west\", \"south\", \"east\", \"north\"].map((name) => box[name]);\n if (![west, south, east, north].every((v) => typeof v === \"number\" && Number.isFinite(v))) fail(\"bounds needs four finite numbers of degrees.\");\n const w = west as number,\n s = south as number,\n e = east as number,\n n = north as number;\n if (w < -180 || e > 180 || w >= e || s < -90 || n > 90 || s >= n) fail(\"bounds must satisfy -180 <= west < east <= 180 and -90 <= south < north <= 90.\");\n return { west: w, south: s, east: e, north: n };\n}\n\n/**\n * Checks the JSON value of a Web Mercator dataset descriptor.\n *\n * @throws RangeError When a member is missing or invalid, naming it. A scheme of another version is rejected.\n * @throws TileUrlTemplateError When the URL template uses an unknown variable.\n */\nexport function parseWebMercatorDataset(value: unknown): IWebMercatorDataset {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) fail(\"the descriptor must be an object.\");\n const source = value as Record<string, unknown>;\n const scheme = text(source, \"scheme\");\n if (scheme !== WEB_MERCATOR_SCHEME) fail(`scheme ${scheme} is not supported, expected ${WEB_MERCATOR_SCHEME}.`);\n const radii = source.referenceRadii;\n if (!Array.isArray(radii) || radii.length !== 3 || radii.some((radius) => typeof radius !== \"number\" || !Number.isFinite(radius) || radius <= 0)) {\n fail(\"referenceRadii must be three positive numbers of metres.\");\n }\n if (radii[0] !== radii[1]) fail(\"referenceRadii must describe an ellipsoid of revolution: a equals b.\");\n const content = source.content;\n if (content !== \"elevation\" && content !== \"imagery\" && content !== \"normals\") fail(\"content must be elevation, imagery or normals.\");\n const tileSize = source.tileSize;\n if (!Number.isInteger(tileSize) || (tileSize as number) < 1) fail(\"tileSize must be a positive integer.\");\n const minLOD = level(source, \"minLOD\");\n const maxLOD = level(source, \"maxLOD\");\n if (minLOD > maxLOD) fail(\"minLOD must not exceed maxLOD.\");\n const registration = (source.registration ?? \"area\") as RasterRegistration;\n try {\n assertRasterRegistration(registration);\n } catch {\n fail(\"registration must be area or point.\");\n }\n const rawSubdomains = source.subdomains;\n if (rawSubdomains !== undefined && (!Array.isArray(rawSubdomains) || rawSubdomains.some((s) => typeof s !== \"string\" || s.length === 0))) {\n fail(\"subdomains must be an array of non-empty strings.\");\n }\n const subdomains = rawSubdomains as string[] | undefined;\n const tiles = text(source, \"tiles\");\n validateTileUrlTemplate(tiles, subdomains ? { subdomains } : {});\n const box = bounds(source.bounds);\n return {\n scheme,\n body: text(source, \"body\"),\n referenceRadii: [radii[0] as number, radii[1] as number, radii[2] as number],\n content,\n encoding: text(source, \"encoding\"),\n tileSize: tileSize as number,\n minLOD,\n maxLOD,\n ...(box ? { bounds: box } : {}),\n registration,\n tiles,\n ...(subdomains ? { subdomains: [...subdomains] } : {}),\n attribution: text(source, \"attribution\"),\n };\n}\n\n/**\n * The JSON value of a Web Mercator dataset descriptor, as {@link parseWebMercatorDataset} reads it back: the members of\n * the dataset, checked, with `extras` written as given (the parser keeps no member it does not know).\n *\n * @throws RangeError When a member is invalid, as {@link parseWebMercatorDataset} would report it.\n */\nexport function webMercatorDatasetDescriptor(dataset: Omit<IWebMercatorDataset, \"scheme\">, extras?: Record<string, unknown>): Record<string, unknown> {\n const checked = parseWebMercatorDataset({ ...dataset, scheme: WEB_MERCATOR_SCHEME });\n return { ...checked, ...(extras ? { extras } : {}) };\n}\n\n/** Options of {@link WebMercatorDatasetSource}. */\nexport interface IWebMercatorDatasetSourceOptions {\n /** Shared client, or options used to create a dedicated one. */\n client?: TileHttpClient | ITileHttpClientOptions;\n /**\n * Geodetic system of the tiles; by default one built from the radii of the descriptor. Give the system of the\n * application when it is the same ellipsoid, so that its metrics compare equal.\n */\n geodeticSystem?: GeodeticSystem;\n}\n\n/** Longitude and latitude in degrees of the north-west corner of a Web Mercator tile. */\nfunction corner(lod: number, x: number, y: number): { longitude: number; latitude: number } {\n const n = 2 ** lod;\n return { longitude: (x / n) * 360 - 180, latitude: (Math.atan(Math.sinh(Math.PI * (1 - (2 * y) / n))) * 180) / Math.PI };\n}\n\n/**\n * Tiles of a Web Mercator dataset over HTTP. Like the cube source of a tile service, it never requests a tile the\n * descriptor does not declare: a level out of range, or a tile outside the bounds, resolves as absent.\n */\nexport class WebMercatorDatasetSource {\n public readonly dataset: IWebMercatorDataset;\n public readonly metrics: WebMercatorTileMetrics;\n /** The HTTP source of the tiles, for consumers that take a {@link WebTileSource}. */\n public readonly source: WebTileSource;\n\n /** @param dataset - The descriptor, or its JSON value, checked by {@link parseWebMercatorDataset}. */\n public constructor(dataset: IWebMercatorDataset | unknown, options: IWebMercatorDatasetSourceOptions = {}) {\n this.dataset = parseWebMercatorDataset(dataset);\n const [a, , c] = this.dataset.referenceRadii;\n const system = options.geodeticSystem ?? new GeodeticSystem(Ellipsoid.fromAxes(this.dataset.body, a, c));\n this.metrics = new WebMercatorTileMetrics({ minLOD: 0, maxLOD: this.dataset.maxLOD, tileSize: this.dataset.tileSize }, system);\n this.source = new WebTileSource({\n id: `${this.dataset.body}-${this.dataset.content}`,\n urlTemplate: this.dataset.tiles,\n metrics: this.metrics,\n registration: this.dataset.registration,\n attribution: this.dataset.attribution,\n ...(this.dataset.subdomains ? { subdomains: [...this.dataset.subdomains] } : {}),\n ...(options.client ? { client: options.client } : {}),\n });\n }\n\n public get attribution(): string {\n return this.dataset.attribution;\n }\n\n /** Whether the dataset declares a tile: its level is in range and it meets the bounds. */\n public isAvailable(address: ITileAddress): boolean {\n const { lod, x, y } = address;\n if (!Number.isInteger(lod) || lod < this.dataset.minLOD || lod > this.dataset.maxLOD) return false;\n const n = 2 ** lod;\n if (!Number.isInteger(x) || !Number.isInteger(y) || x < 0 || y < 0 || x >= n || y >= n) return false;\n const box = this.dataset.bounds;\n if (!box) return true;\n const northWest = corner(lod, x, y),\n southEast = corner(lod, x + 1, y + 1);\n return northWest.longitude < box.east && southEast.longitude > box.west && southEast.latitude < box.north && northWest.latitude > box.south;\n }\n\n /** Fetches a tile; a tile the dataset does not declare resolves as absent, like a 404, without any request. */\n public async fetchTile(address: ITileAddress, signal?: AbortSignal): Promise<TileFetchResult> {\n if (!this.isAvailable(address)) return { status: \"absent\", url: \"\", httpStatus: 404 };\n return this.source.fetchTile(address, signal);\n }\n}\n"]}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { cubeTileDirection } from './chunk-IGNRXAW3.js';
|
|
2
|
+
import { assertRasterRegistration } from './chunk-X6ZJ2PDY.js';
|
|
3
|
+
import { tileCount } from './chunk-Y66PNDG2.js';
|
|
4
|
+
|
|
5
|
+
// src/reprojection/source-tile-matrix.ts
|
|
6
|
+
function sourcePixelCoordinates(matrix, position, target = { x: 0, y: 0 }) {
|
|
7
|
+
assertRasterRegistration(matrix.registration);
|
|
8
|
+
const offset = matrix.registration === "area" ? 0.5 : 0;
|
|
9
|
+
target.x = (position.x - matrix.originX) / matrix.pixelSize - offset;
|
|
10
|
+
target.y = (matrix.originY - position.y) / matrix.pixelSize - offset;
|
|
11
|
+
return target;
|
|
12
|
+
}
|
|
13
|
+
function sourcePixelAt(matrix, pixelX, pixelY, periodPixels2) {
|
|
14
|
+
let x = pixelX;
|
|
15
|
+
if (periodPixels2 !== void 0) x = (x % periodPixels2 + periodPixels2) % periodPixels2;
|
|
16
|
+
if (x < 0 || pixelY < 0) return void 0;
|
|
17
|
+
const column = Math.floor(x / matrix.tileWidth);
|
|
18
|
+
const row = Math.floor(pixelY / matrix.tileHeight);
|
|
19
|
+
if (column >= matrix.matrixWidth || row >= matrix.matrixHeight) return void 0;
|
|
20
|
+
return { column, row, x: x - column * matrix.tileWidth, y: pixelY - row * matrix.tileHeight };
|
|
21
|
+
}
|
|
22
|
+
function webMercatorTileMatrix(level, tileSize = 256, semiMajorAxis) {
|
|
23
|
+
const half = Math.PI * semiMajorAxis;
|
|
24
|
+
const tiles = 2 ** level;
|
|
25
|
+
return {
|
|
26
|
+
identifier: String(level),
|
|
27
|
+
registration: "area",
|
|
28
|
+
originX: -half,
|
|
29
|
+
originY: half,
|
|
30
|
+
pixelSize: 2 * half / (tiles * tileSize),
|
|
31
|
+
tileWidth: tileSize,
|
|
32
|
+
tileHeight: tileSize,
|
|
33
|
+
matrixWidth: tiles,
|
|
34
|
+
matrixHeight: tiles
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function geographicTileMatrix(level, tileSize = 256) {
|
|
38
|
+
const tiles = 2 ** level;
|
|
39
|
+
return {
|
|
40
|
+
identifier: String(level),
|
|
41
|
+
registration: "area",
|
|
42
|
+
originX: -180,
|
|
43
|
+
originY: 90,
|
|
44
|
+
pixelSize: 180 / (tiles * tileSize),
|
|
45
|
+
tileWidth: tileSize,
|
|
46
|
+
tileHeight: tileSize,
|
|
47
|
+
matrixWidth: 2 * tiles,
|
|
48
|
+
matrixHeight: tiles
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/reprojection/cube-resampling.ts
|
|
53
|
+
function periodPixels({ projection, matrix }) {
|
|
54
|
+
return projection.periodX === void 0 ? void 0 : projection.periodX / matrix.pixelSize;
|
|
55
|
+
}
|
|
56
|
+
function cubeSourceMatrix(projection, matrices, bodyRadius, lod, tileSize = 256) {
|
|
57
|
+
if (matrices.length === 0) throw new RangeError("The source has no level.");
|
|
58
|
+
const spacing = Math.PI / 2 * (bodyRadius / (tileSize * tileCount(lod)));
|
|
59
|
+
return matrices.find((matrix) => matrix.pixelSize * projection.metresPerUnit <= spacing * (1 + 1e-9)) ?? matrices[matrices.length - 1];
|
|
60
|
+
}
|
|
61
|
+
function forEachSample(address, tileSize, visit) {
|
|
62
|
+
const side = tileSize + 1;
|
|
63
|
+
const direction = { x: 0, y: 0, z: 0 };
|
|
64
|
+
for (let row = 0; row < side; row++) {
|
|
65
|
+
for (let column = 0; column < side; column++) {
|
|
66
|
+
cubeTileDirection(address, column / tileSize, row / tileSize, direction);
|
|
67
|
+
visit(row * side + column, direction);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function cubeTileSourceTiles(address, source, tileSize = 256) {
|
|
72
|
+
const found = /* @__PURE__ */ new Map();
|
|
73
|
+
const period = periodPixels(source);
|
|
74
|
+
const position = { x: 0, y: 0 };
|
|
75
|
+
const pixel = { x: 0, y: 0 };
|
|
76
|
+
forEachSample(address, tileSize, (_index, direction) => {
|
|
77
|
+
sourcePixelCoordinates(source.matrix, source.projection.forward(direction, position), pixel);
|
|
78
|
+
const left = Math.floor(pixel.x);
|
|
79
|
+
const top = Math.floor(pixel.y);
|
|
80
|
+
for (const [dx, dy] of [
|
|
81
|
+
[0, 0],
|
|
82
|
+
[1, 0],
|
|
83
|
+
[0, 1],
|
|
84
|
+
[1, 1]
|
|
85
|
+
]) {
|
|
86
|
+
const at = sourcePixelAt(source.matrix, left + dx, top + dy, period);
|
|
87
|
+
if (at) found.set(`${at.column}/${at.row}`, { column: at.column, row: at.row });
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return [...found.values()];
|
|
91
|
+
}
|
|
92
|
+
function resampleCubeTile(address, source, read, options = {}) {
|
|
93
|
+
const tileSize = options.tileSize ?? 256;
|
|
94
|
+
const channels = options.channels ?? 1;
|
|
95
|
+
const length = (tileSize + 1) ** 2 * channels;
|
|
96
|
+
const data = options.target ?? new Float32Array(length);
|
|
97
|
+
if (data.length !== length) throw new RangeError(`A tile of ${tileSize} cells needs ${length} values, not ${data.length}.`);
|
|
98
|
+
const period = periodPixels(source);
|
|
99
|
+
const position = { x: 0, y: 0 };
|
|
100
|
+
const pixel = { x: 0, y: 0 };
|
|
101
|
+
forEachSample(address, tileSize, (index, direction) => {
|
|
102
|
+
sourcePixelCoordinates(source.matrix, source.projection.forward(direction, position), pixel);
|
|
103
|
+
const left = Math.floor(pixel.x);
|
|
104
|
+
const top = Math.floor(pixel.y);
|
|
105
|
+
const fx = pixel.x - left;
|
|
106
|
+
const fy = pixel.y - top;
|
|
107
|
+
for (let channel = 0; channel < channels; channel++) {
|
|
108
|
+
let sum = 0;
|
|
109
|
+
let weights = 0;
|
|
110
|
+
for (const [dx, dy, weight] of [
|
|
111
|
+
[0, 0, (1 - fx) * (1 - fy)],
|
|
112
|
+
[1, 0, fx * (1 - fy)],
|
|
113
|
+
[0, 1, (1 - fx) * fy],
|
|
114
|
+
[1, 1, fx * fy]
|
|
115
|
+
]) {
|
|
116
|
+
if (weight === 0) continue;
|
|
117
|
+
const at = sourcePixelAt(source.matrix, left + dx, top + dy, period);
|
|
118
|
+
const value = at ? read(at.column, at.row, at.x, at.y, channel) : Number.NaN;
|
|
119
|
+
if (Number.isNaN(value)) continue;
|
|
120
|
+
sum += value * weight;
|
|
121
|
+
weights += weight;
|
|
122
|
+
}
|
|
123
|
+
data[index * channels + channel] = weights > 0 ? sum / weights : Number.NaN;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return data;
|
|
127
|
+
}
|
|
128
|
+
function rebaseRadialHeight(height, sourceRadius, reference, direction) {
|
|
129
|
+
return height + sourceRadius - reference.radius(direction);
|
|
130
|
+
}
|
|
131
|
+
function capBlendWeight(direction, fromDegrees, toDegrees) {
|
|
132
|
+
if (!(toDegrees > fromDegrees)) throw new RangeError("A cap blend must end beyond its start.");
|
|
133
|
+
const latitude = Math.atan2(Math.abs(direction.z), Math.hypot(direction.x, direction.y)) * 180 / Math.PI;
|
|
134
|
+
const t = Math.min(Math.max((latitude - fromDegrees) / (toDegrees - fromDegrees), 0), 1);
|
|
135
|
+
return t * t * (3 - 2 * t);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/reprojection/source-projection.ts
|
|
139
|
+
var DEGREES = 180 / Math.PI;
|
|
140
|
+
var GeographicProjection = class {
|
|
141
|
+
metresPerUnit;
|
|
142
|
+
periodX = 360;
|
|
143
|
+
squaredRatio;
|
|
144
|
+
centralMeridian;
|
|
145
|
+
constructor(options) {
|
|
146
|
+
const { semiMajorAxis: a, semiMinorAxis: b = a } = options;
|
|
147
|
+
if (!(a > 0) || !(b > 0)) throw new RangeError("The radii of a projection must be positive.");
|
|
148
|
+
this.metresPerUnit = Math.PI / 180 * a;
|
|
149
|
+
this.squaredRatio = a * a / (b * b);
|
|
150
|
+
this.centralMeridian = options.centralMeridianDegrees ?? 0;
|
|
151
|
+
}
|
|
152
|
+
forward(direction, target = { x: 0, y: 0 }) {
|
|
153
|
+
target.y = Math.atan2(direction.z * this.squaredRatio, Math.hypot(direction.x, direction.y)) * DEGREES;
|
|
154
|
+
target.x = wrapDegrees(Math.atan2(direction.y, direction.x) * DEGREES - this.centralMeridian);
|
|
155
|
+
return target;
|
|
156
|
+
}
|
|
157
|
+
inverse(x, y, target = { x: 0, y: 0, z: 0 }) {
|
|
158
|
+
const longitude = (x + this.centralMeridian) / DEGREES;
|
|
159
|
+
const latitude = Math.atan2(Math.sin(y / DEGREES), Math.cos(y / DEGREES) * this.squaredRatio);
|
|
160
|
+
target.x = Math.cos(latitude) * Math.cos(longitude);
|
|
161
|
+
target.y = Math.cos(latitude) * Math.sin(longitude);
|
|
162
|
+
target.z = Math.sin(latitude);
|
|
163
|
+
return target;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
function wrapDegrees(degrees) {
|
|
167
|
+
if (degrees < -180) return degrees + 360;
|
|
168
|
+
if (degrees >= 180) return degrees - 360;
|
|
169
|
+
return degrees;
|
|
170
|
+
}
|
|
171
|
+
var PolarStereographicProjection = class {
|
|
172
|
+
metresPerUnit = 1;
|
|
173
|
+
periodX = void 0;
|
|
174
|
+
south;
|
|
175
|
+
diameter;
|
|
176
|
+
cosine;
|
|
177
|
+
sine;
|
|
178
|
+
falseEasting;
|
|
179
|
+
falseNorthing;
|
|
180
|
+
constructor(options) {
|
|
181
|
+
if (!(options.radius > 0)) throw new RangeError("The radius of a projection must be positive.");
|
|
182
|
+
this.south = options.pole === "south";
|
|
183
|
+
this.diameter = 2 * options.radius;
|
|
184
|
+
const meridian = (options.centralMeridianDegrees ?? 0) / DEGREES;
|
|
185
|
+
this.cosine = Math.cos(meridian);
|
|
186
|
+
this.sine = Math.sin(meridian);
|
|
187
|
+
this.falseEasting = options.falseEasting ?? 0;
|
|
188
|
+
this.falseNorthing = options.falseNorthing ?? 0;
|
|
189
|
+
}
|
|
190
|
+
forward(direction, target = { x: 0, y: 0 }) {
|
|
191
|
+
const { x, y, z } = direction;
|
|
192
|
+
const dx = x * this.cosine + y * this.sine;
|
|
193
|
+
const dy = y * this.cosine - x * this.sine;
|
|
194
|
+
const scale = this.diameter / (this.south ? 1 - z : 1 + z);
|
|
195
|
+
target.x = dy * scale + this.falseEasting;
|
|
196
|
+
target.y = (this.south ? dx : -dx) * scale + this.falseNorthing;
|
|
197
|
+
return target;
|
|
198
|
+
}
|
|
199
|
+
inverse(x, y, target = { x: 0, y: 0, z: 0 }) {
|
|
200
|
+
const mapX = (x - this.falseEasting) / this.diameter;
|
|
201
|
+
const mapY = ((this.south ? y : -y) - (this.south ? this.falseNorthing : -this.falseNorthing)) / this.diameter;
|
|
202
|
+
const squared = mapX * mapX + mapY * mapY;
|
|
203
|
+
const denominator = 1 + squared;
|
|
204
|
+
const along = 2 * mapY / denominator;
|
|
205
|
+
const across = 2 * mapX / denominator;
|
|
206
|
+
target.x = along * this.cosine - across * this.sine;
|
|
207
|
+
target.y = along * this.sine + across * this.cosine;
|
|
208
|
+
target.z = (this.south ? -1 : 1) * (1 - squared) / denominator;
|
|
209
|
+
return target;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
var WebMercatorProjection = class {
|
|
213
|
+
metresPerUnit = 1;
|
|
214
|
+
periodX;
|
|
215
|
+
radius;
|
|
216
|
+
squaredRatio;
|
|
217
|
+
constructor(options) {
|
|
218
|
+
this.radius = options.semiMajorAxis;
|
|
219
|
+
if (!(this.radius > 0) || !Number.isFinite(this.radius)) throw new RangeError("A projection requires a positive finite radius.");
|
|
220
|
+
const b = options.semiMinorAxis ?? options.semiMajorAxis;
|
|
221
|
+
this.squaredRatio = this.radius * this.radius / (b * b);
|
|
222
|
+
this.periodX = 2 * Math.PI * this.radius;
|
|
223
|
+
}
|
|
224
|
+
forward(direction, target = { x: 0, y: 0 }) {
|
|
225
|
+
const latitude = Math.atan2(direction.z * this.squaredRatio, Math.hypot(direction.x, direction.y));
|
|
226
|
+
target.x = this.radius * Math.atan2(direction.y, direction.x);
|
|
227
|
+
target.y = this.radius * Math.log(Math.tan(Math.PI / 4 + latitude / 2));
|
|
228
|
+
return target;
|
|
229
|
+
}
|
|
230
|
+
inverse(x, y, target = { x: 0, y: 0, z: 0 }) {
|
|
231
|
+
const longitude = x / this.radius;
|
|
232
|
+
const geodetic = 2 * Math.atan(Math.exp(y / this.radius)) - Math.PI / 2;
|
|
233
|
+
const latitude = Math.atan2(Math.sin(geodetic), Math.cos(geodetic) * this.squaredRatio);
|
|
234
|
+
target.x = Math.cos(latitude) * Math.cos(longitude);
|
|
235
|
+
target.y = Math.cos(latitude) * Math.sin(longitude);
|
|
236
|
+
target.z = Math.sin(latitude);
|
|
237
|
+
return target;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
function geodeticOfDirection(direction, semiMajorAxis, semiMinorAxis) {
|
|
241
|
+
const ratio = semiMajorAxis * semiMajorAxis / (semiMinorAxis * semiMinorAxis);
|
|
242
|
+
return {
|
|
243
|
+
latitude: Math.atan2(direction.z * ratio, Math.hypot(direction.x, direction.y)) * DEGREES,
|
|
244
|
+
longitude: Math.atan2(direction.y, direction.x) * DEGREES
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/reprojection/wmts-capabilities.ts
|
|
249
|
+
var METRES_PER_SCALE = 28e-5;
|
|
250
|
+
function block(source, tag) {
|
|
251
|
+
return [...source.matchAll(new RegExp(`<${tag}(?:\\s[^>]*)?>([\\s\\S]*?)</${tag}>`, "g"))].map((match) => match[1]);
|
|
252
|
+
}
|
|
253
|
+
function text(source, tag) {
|
|
254
|
+
return new RegExp(`<${tag}(?:\\s[^>]*)?>\\s*([^<]*?)\\s*</${tag}>`).exec(source)?.[1];
|
|
255
|
+
}
|
|
256
|
+
function numbers(value) {
|
|
257
|
+
return (value ?? "").trim().split(/\s+/).filter(Boolean).map(Number);
|
|
258
|
+
}
|
|
259
|
+
function required(value, name) {
|
|
260
|
+
if (value === void 0 || value === "") throw new RangeError(`The WMTS capabilities miss ${name}.`);
|
|
261
|
+
return value;
|
|
262
|
+
}
|
|
263
|
+
function parseWmtsCapabilities(xml, layerIdentifier) {
|
|
264
|
+
const source = xml.replace(/<!--[\s\S]*?-->/g, "");
|
|
265
|
+
const layers = block(source, "Layer");
|
|
266
|
+
const layer = layerIdentifier === void 0 ? layers[0] : layers.find((candidate) => text(candidate, "ows:Identifier") === layerIdentifier);
|
|
267
|
+
if (layer === void 0) throw new RangeError(`The WMTS capabilities have no layer ${layerIdentifier ?? ""}.`.trim());
|
|
268
|
+
const set = required(text(required(block(layer, "TileMatrixSetLink")[0], "TileMatrixSetLink"), "TileMatrixSet"), "TileMatrixSet");
|
|
269
|
+
const definition = block(source, "TileMatrixSet").find((candidate) => text(candidate, "ows:Identifier") === set);
|
|
270
|
+
if (definition === void 0) throw new RangeError(`The WMTS capabilities do not define the tile matrix set ${set}.`);
|
|
271
|
+
const matrices = block(definition, "TileMatrix").map((matrix) => {
|
|
272
|
+
const identifier = required(text(matrix, "ows:Identifier"), "a TileMatrix identifier");
|
|
273
|
+
let corner = numbers(text(matrix, "TopLeftCorner"));
|
|
274
|
+
if (corner.length === 2 && Math.abs(corner[1]) > 90 && Math.abs(corner[1]) <= 180 && Math.abs(corner[0]) <= 90) corner = [corner[1], corner[0]];
|
|
275
|
+
const [originX, originY] = corner;
|
|
276
|
+
const scale = Number(text(matrix, "ScaleDenominator"));
|
|
277
|
+
const tileWidth = Number(text(matrix, "TileWidth"));
|
|
278
|
+
const tileHeight = Number(text(matrix, "TileHeight"));
|
|
279
|
+
const matrixWidth = Number(text(matrix, "MatrixWidth"));
|
|
280
|
+
const matrixHeight = Number(text(matrix, "MatrixHeight"));
|
|
281
|
+
if (![originX, originY, tileWidth, tileHeight, matrixWidth, matrixHeight].every((value) => Number.isFinite(value)) || !(tileWidth > 0)) {
|
|
282
|
+
throw new RangeError(`The tile matrix ${identifier} is invalid.`);
|
|
283
|
+
}
|
|
284
|
+
const pixelSize = originY !== 0 ? 2 * Math.abs(originY) / (matrixHeight * tileHeight) : scale * METRES_PER_SCALE;
|
|
285
|
+
if (!(pixelSize > 0)) throw new RangeError(`The tile matrix ${identifier} has no pixel size.`);
|
|
286
|
+
return { identifier, registration: "area", originX, originY, pixelSize, tileWidth, tileHeight, matrixWidth, matrixHeight };
|
|
287
|
+
});
|
|
288
|
+
if (matrices.length === 0) throw new RangeError(`The tile matrix set ${set} has no tile matrix.`);
|
|
289
|
+
const box = block(layer, "ows:BoundingBox")[0];
|
|
290
|
+
const lower = numbers(box && text(box, "ows:LowerCorner"));
|
|
291
|
+
const upper = numbers(box && text(box, "ows:UpperCorner"));
|
|
292
|
+
const style = block(layer, "Style")[0];
|
|
293
|
+
return {
|
|
294
|
+
identifier: required(text(layer, "ows:Identifier"), "a layer identifier"),
|
|
295
|
+
crs: text(definition, "ows:SupportedCRS"),
|
|
296
|
+
format: text(layer, "Format"),
|
|
297
|
+
style: (style && text(style, "ows:Identifier")) ?? "default",
|
|
298
|
+
tileMatrixSet: set,
|
|
299
|
+
boundingBox: lower.length === 2 && upper.length === 2 ? [lower[0], lower[1], upper[0], upper[1]] : void 0,
|
|
300
|
+
resourceUrl: /<ResourceURL[^>]*\stemplate="([^"]+)"/.exec(layer)?.[1],
|
|
301
|
+
matrices
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function wmtsTileUrl(layer, matrix, row, column) {
|
|
305
|
+
if (layer.resourceUrl === void 0) throw new RangeError(`The layer ${layer.identifier} has no REST template.`);
|
|
306
|
+
const url = layer.resourceUrl.replaceAll("{Style}", layer.style).replaceAll("{style}", layer.style).replaceAll("{TileMatrixSet}", layer.tileMatrixSet).replaceAll("{TileMatrix}", matrix.identifier).replaceAll("{TileRow}", String(row)).replaceAll("{TileCol}", String(column));
|
|
307
|
+
return url.replace(/([^:/])\/{2,}/g, "$1/");
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export { GeographicProjection, PolarStereographicProjection, WebMercatorProjection, capBlendWeight, cubeSourceMatrix, cubeTileSourceTiles, geodeticOfDirection, geographicTileMatrix, parseWmtsCapabilities, rebaseRadialHeight, resampleCubeTile, sourcePixelAt, sourcePixelCoordinates, webMercatorTileMatrix, wmtsTileUrl };
|
|
311
|
+
//# sourceMappingURL=chunk-FB57CZDK.js.map
|
|
312
|
+
//# sourceMappingURL=chunk-FB57CZDK.js.map
|