isard 0.6.1 → 0.8.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 +100 -0
- package/dist/basemap.worker.d.ts +7 -1
- package/dist/basemap.worker.js +2 -2
- package/dist/basemap.worker.js.map +8 -7
- package/dist/decoder.worker.js +4 -4
- package/dist/decoder.worker.js.map +6 -5
- package/dist/engine-loader.d.ts +1 -1
- package/dist/engine-loader.js.map +1 -1
- package/dist/geoplateforme.d.ts +4 -3
- package/dist/geoplateforme.js +43 -19
- package/dist/geoplateforme.js.map +1 -1
- package/dist/glyphs.js +2 -1
- package/dist/glyphs.js.map +1 -1
- package/dist/icons.js +5 -1
- package/dist/icons.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/interaction.d.ts +2 -0
- package/dist/interaction.js +29 -2
- package/dist/interaction.js.map +1 -1
- package/dist/isard_bg.wasm +0 -0
- package/dist/isard_core_bg.wasm +0 -0
- package/dist/layers.d.ts +2 -0
- package/dist/layers.js +22 -4
- package/dist/layers.js.map +1 -1
- package/dist/loader.d.ts +2 -0
- package/dist/loader.js +10 -0
- package/dist/loader.js.map +1 -1
- package/dist/map.d.ts +52 -3
- package/dist/map.js +171 -6
- package/dist/map.js.map +1 -1
- package/dist/overlay.d.ts +55 -0
- package/dist/overlay.js +185 -7
- package/dist/overlay.js.map +1 -1
- package/dist/panoramas.d.ts +94 -0
- package/dist/panoramas.js +245 -0
- package/dist/panoramas.js.map +1 -0
- package/dist/pmtiles.js +3 -2
- package/dist/pmtiles.js.map +1 -1
- package/dist/pointclouds.js +1 -1
- package/dist/pointclouds.js.map +1 -1
- package/dist/protocol.d.ts +7 -1
- package/dist/protocol.js.map +1 -1
- package/dist/requests.d.ts +14 -0
- package/dist/requests.js +48 -0
- package/dist/requests.js.map +1 -0
- package/dist/resample.js +2 -1
- package/dist/resample.js.map +1 -1
- package/dist/style.js +3 -0
- package/dist/style.js.map +1 -1
- package/dist/terrain.d.ts +0 -5
- package/dist/terrain.js +2 -1
- package/dist/terrain.js.map +1 -1
- package/dist/types.d.ts +36 -4
- package/dist/types.js.map +1 -1
- package/dist/vectortiles.d.ts +6 -2
- package/dist/vectortiles.js +92 -33
- package/dist/vectortiles.js.map +1 -1
- package/dist/wasm/isard.d.ts +105 -11
- package/dist/wasm/isard.js +211 -13
- package/dist/wasm/isard_core.d.ts +64 -6
- package/dist/wasm/isard_core.js +149 -6
- package/dist/wmts.js +2 -1
- package/dist/wmts.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Street-level panoramas: the oriented images of a vehicle's cameras around each of its positions (Stereopolis, the
|
|
3
|
+
* iTowns immersive examples), projected onto the scene around the panorama shown. Their positions and attitudes come
|
|
4
|
+
* as GeoJSON points (Lambert-93 by default, altitudes NGF-IGN69 raised by the RAF20 geoid onto the IGN relief), the
|
|
5
|
+
* calibration of the cameras as JSON (rotation and position in the panorama frame, intrinsics, MicMac's radial
|
|
6
|
+
* distortion), the images from a URL template with `{cameraId}` and `{panoId}`.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const panoramas = await map.addPanoramas({ url, orientationsUrl, calibrationUrl });
|
|
10
|
+
* await panoramas.show(panoramas.nearest([2.3345, 48.8505]).index);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
import { getCrs } from "./crs.js";
|
|
14
|
+
import { withHeaders } from "./requests.js";
|
|
15
|
+
const RAD = Math.PI / 180;
|
|
16
|
+
/** 3 × 3 product, row-major */
|
|
17
|
+
function times(a, b) {
|
|
18
|
+
const out = [];
|
|
19
|
+
for (let r = 0; r < 3; r++) {
|
|
20
|
+
for (let c = 0; c < 3; c++) {
|
|
21
|
+
let sum = 0;
|
|
22
|
+
for (let k = 0; k < 3; k++)
|
|
23
|
+
sum += (a[r * 3 + k] ?? 0) * (b[k * 3 + c] ?? 0);
|
|
24
|
+
out.push(sum);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
const rotX = (t) => [1, 0, 0, 0, Math.cos(t), -Math.sin(t), 0, Math.sin(t), Math.cos(t)];
|
|
30
|
+
const rotY = (t) => [Math.cos(t), 0, Math.sin(t), 0, 1, 0, -Math.sin(t), 0, Math.cos(t)];
|
|
31
|
+
const rotZ = (t) => [Math.cos(t), -Math.sin(t), 0, Math.sin(t), Math.cos(t), 0, 0, 0, 1];
|
|
32
|
+
/**
|
|
33
|
+
* The panorama frame to east, north, up (row-major): the vehicle's attitude in the CRS's grid (iTowns'
|
|
34
|
+
* `quaternionFromRollPitchHeading`: Ry(-roll) · Rx(-pitch) · Rz(-heading)), turned by the meridian convergence of the
|
|
35
|
+
* projection (Lambert-93: sin(46.5°) · (3° - longitude))
|
|
36
|
+
*/
|
|
37
|
+
export function panoramaRotation(attitude, lon, lambert93) {
|
|
38
|
+
const vehicle = times(times(rotY(-attitude.roll * RAD), rotX(-attitude.pitch * RAD)), rotZ(-attitude.heading * RAD));
|
|
39
|
+
const convergence = lambert93 ? Math.sin(46.5 * RAD) * (3 - lon) * RAD : 0;
|
|
40
|
+
return times(rotZ(convergence), vehicle);
|
|
41
|
+
}
|
|
42
|
+
/** The 25 numbers of a camera for `setPanorama` */
|
|
43
|
+
function cameraNumbers(c) {
|
|
44
|
+
const p = c.projection;
|
|
45
|
+
const d = c.distortion;
|
|
46
|
+
return [
|
|
47
|
+
...c.rotation.slice(0, 9),
|
|
48
|
+
...c.position.slice(0, 3),
|
|
49
|
+
p[0] ?? 1,
|
|
50
|
+
p[4] ?? 1,
|
|
51
|
+
p[2] ?? 0,
|
|
52
|
+
p[5] ?? 0,
|
|
53
|
+
p[1] ?? 0,
|
|
54
|
+
c.size[0] ?? 1,
|
|
55
|
+
c.size[1] ?? 1,
|
|
56
|
+
d?.pps[0] ?? 0,
|
|
57
|
+
d?.pps[1] ?? 0,
|
|
58
|
+
d?.poly357[0] ?? 0,
|
|
59
|
+
d?.poly357[1] ?? 0,
|
|
60
|
+
d?.poly357[2] ?? 0,
|
|
61
|
+
d?.limit ?? 0,
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
/** The panoramas of a set, one shown at a time */
|
|
65
|
+
export class Panoramas {
|
|
66
|
+
host;
|
|
67
|
+
options;
|
|
68
|
+
list;
|
|
69
|
+
attitudes;
|
|
70
|
+
cameras;
|
|
71
|
+
lambert93;
|
|
72
|
+
/** The panorama shown, if any */
|
|
73
|
+
current;
|
|
74
|
+
shown = 0;
|
|
75
|
+
/** @internal */
|
|
76
|
+
constructor(host, options, list, attitudes, cameras, lambert93) {
|
|
77
|
+
this.host = host;
|
|
78
|
+
this.options = options;
|
|
79
|
+
this.list = list;
|
|
80
|
+
this.attitudes = attitudes;
|
|
81
|
+
this.cameras = cameras;
|
|
82
|
+
this.lambert93 = lambert93;
|
|
83
|
+
}
|
|
84
|
+
/** The panorama nearest to a position */
|
|
85
|
+
nearest(lonLat) {
|
|
86
|
+
const cos = Math.cos(lonLat[1] * RAD);
|
|
87
|
+
let best;
|
|
88
|
+
let distance = Number.POSITIVE_INFINITY;
|
|
89
|
+
for (const p of this.list) {
|
|
90
|
+
const d = ((p.lonLat[0] - lonLat[0]) * cos) ** 2 + (p.lonLat[1] - lonLat[1]) ** 2;
|
|
91
|
+
if (d < distance)
|
|
92
|
+
[best, distance] = [p, d];
|
|
93
|
+
}
|
|
94
|
+
return best;
|
|
95
|
+
}
|
|
96
|
+
/** Shows a panorama (its index in `list`): projected as soon as its first image arrives, the others after */
|
|
97
|
+
async show(index) {
|
|
98
|
+
const pano = this.list[index];
|
|
99
|
+
const attitude = this.attitudes[index];
|
|
100
|
+
if (!pano || !attitude)
|
|
101
|
+
return;
|
|
102
|
+
const shown = ++this.shown;
|
|
103
|
+
this.current = pano;
|
|
104
|
+
const rotation = panoramaRotation(attitude, pano.lonLat[0], this.lambert93);
|
|
105
|
+
const { url, backgroundDistance, opacity } = this.options;
|
|
106
|
+
this.host.setPanorama(pano.lonLat[0], pano.lonLat[1], pano.height, Float64Array.from(rotation), Float64Array.from(this.cameras.flatMap(cameraNumbers)), backgroundDistance, opacity);
|
|
107
|
+
await Promise.all(this.cameras.map(async (camera, k) => {
|
|
108
|
+
const src = url.replaceAll('{cameraId}', String(camera.id)).replaceAll('{panoId}', String(pano.id));
|
|
109
|
+
const response = await fetch(src, withHeaders(src));
|
|
110
|
+
if (!response.ok)
|
|
111
|
+
throw new Error(`isard: panorama image ${src}: ${response.status}`);
|
|
112
|
+
const image = await createImageBitmap(await response.blob(), { premultiplyAlpha: 'none' });
|
|
113
|
+
// Another panorama shown since: this image is not its
|
|
114
|
+
if (shown === this.shown)
|
|
115
|
+
this.host.setPanoramaImage(k, image);
|
|
116
|
+
image.close();
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
/** Hides the panorama shown */
|
|
120
|
+
hide() {
|
|
121
|
+
this.shown++;
|
|
122
|
+
this.current = undefined;
|
|
123
|
+
this.host.clearPanorama();
|
|
124
|
+
}
|
|
125
|
+
/** Stops the walk (`enter`) */
|
|
126
|
+
stopWalking;
|
|
127
|
+
/**
|
|
128
|
+
* Street-level walk from panorama to panorama (the iTowns immersive view): the eye on a panorama, the drag
|
|
129
|
+
* turning it; a click goes to the panorama nearest to the clicked point, the wheel to the nearest one ahead (or
|
|
130
|
+
* behind), Z and S (or Page Up and Page Down) to the next and the previous ones. Starts on the panorama `index`,
|
|
131
|
+
* else the one nearest to `near`
|
|
132
|
+
*/
|
|
133
|
+
async enter(start = {}) {
|
|
134
|
+
const first = start.index ?? (start.near && this.nearest(start.near)?.index) ?? 0;
|
|
135
|
+
this.stopWalking?.();
|
|
136
|
+
this.stopWalking = this.host.listen((lonLat) => {
|
|
137
|
+
const target = lonLat && this.nearest(lonLat);
|
|
138
|
+
if (target && target !== this.current)
|
|
139
|
+
void this.go(target.index);
|
|
140
|
+
}, (e) => {
|
|
141
|
+
const step = { z: 1, Z: 1, PageUp: 1, s: -1, S: -1, PageDown: -1 }[e.key];
|
|
142
|
+
if (!step || !this.current)
|
|
143
|
+
return;
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
void this.go((this.current.index + step + this.list.length) % this.list.length);
|
|
146
|
+
}, (e) => {
|
|
147
|
+
// One step per notch, the next ones once it is shown
|
|
148
|
+
if (this.moving || e.deltaY === 0)
|
|
149
|
+
return;
|
|
150
|
+
const target = this.ahead(e.deltaY < 0);
|
|
151
|
+
if (target) {
|
|
152
|
+
this.moving = true;
|
|
153
|
+
void this.go(target.index).finally(() => {
|
|
154
|
+
this.moving = false;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
await this.go(first, this.list[first]?.heading);
|
|
159
|
+
}
|
|
160
|
+
/** A step of the wheel under way */
|
|
161
|
+
moving = false;
|
|
162
|
+
/** The nearest panorama ahead of the eye (within 60° of where it looks), or behind it */
|
|
163
|
+
ahead(forward = true) {
|
|
164
|
+
const eye = this.host.firstPerson();
|
|
165
|
+
const here = this.current;
|
|
166
|
+
if (!eye || !here)
|
|
167
|
+
return undefined;
|
|
168
|
+
const cos = Math.cos(here.lonLat[1] * RAD);
|
|
169
|
+
const look = (eye.bearing + (forward ? 0 : 180)) * RAD;
|
|
170
|
+
let best;
|
|
171
|
+
let distance = Number.POSITIVE_INFINITY;
|
|
172
|
+
for (const p of this.list) {
|
|
173
|
+
if (p === here)
|
|
174
|
+
continue;
|
|
175
|
+
const [east, north] = [(p.lonLat[0] - here.lonLat[0]) * cos, p.lonLat[1] - here.lonLat[1]];
|
|
176
|
+
const d = Math.hypot(east, north);
|
|
177
|
+
const off = Math.acos(Math.max(-1, Math.min(1, (east * Math.sin(look) + north * Math.cos(look)) / (d || 1))));
|
|
178
|
+
if (off < 60 * RAD && d < distance)
|
|
179
|
+
[best, distance] = [p, d];
|
|
180
|
+
}
|
|
181
|
+
return best;
|
|
182
|
+
}
|
|
183
|
+
/** Goes to a panorama during the walk, the eye looking the same way (or `bearing`) */
|
|
184
|
+
async go(index, bearing) {
|
|
185
|
+
const pano = this.list[index];
|
|
186
|
+
if (!pano)
|
|
187
|
+
return;
|
|
188
|
+
const eye = this.host.firstPerson();
|
|
189
|
+
// The eye at the panorama's cameras, above the ground there
|
|
190
|
+
const ground = this.host.elevationAt(pano.lonLat);
|
|
191
|
+
this.host.setFirstPerson({
|
|
192
|
+
lonLat: pano.lonLat,
|
|
193
|
+
height: ground === undefined ? 2.5 : Math.max(0.5, pano.height - ground),
|
|
194
|
+
bearing: bearing ?? eye?.bearing ?? pano.heading,
|
|
195
|
+
...(eye ? { pitch: eye.pitch, fov: eye.fov } : {}),
|
|
196
|
+
});
|
|
197
|
+
await this.show(index);
|
|
198
|
+
}
|
|
199
|
+
/** Ends the walk: the panorama hidden, the camera turning around a point again, above where the eye stood */
|
|
200
|
+
exit() {
|
|
201
|
+
this.stopWalking?.();
|
|
202
|
+
this.stopWalking = undefined;
|
|
203
|
+
this.hide();
|
|
204
|
+
this.host.setFirstPerson(undefined);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** Loads a set of panoramas: their positions and attitudes, the calibration of their cameras */
|
|
208
|
+
export async function loadPanoramas(host, options) {
|
|
209
|
+
const json = async (src) => {
|
|
210
|
+
const response = await fetch(src, withHeaders(src));
|
|
211
|
+
if (!response.ok)
|
|
212
|
+
throw new Error(`isard: ${src}: ${response.status}`);
|
|
213
|
+
return (await response.json());
|
|
214
|
+
};
|
|
215
|
+
const [orientations, cameras] = await Promise.all([
|
|
216
|
+
json(options.orientationsUrl),
|
|
217
|
+
json(options.calibrationUrl),
|
|
218
|
+
]);
|
|
219
|
+
const crsName = options.crs ?? orientations.crs?.properties?.name ?? 'EPSG:2154';
|
|
220
|
+
const lambert93 = /2154/.test(crsName);
|
|
221
|
+
const crs = getCrs(crsName);
|
|
222
|
+
const geoid = options.geoid ?? lambert93;
|
|
223
|
+
const list = [];
|
|
224
|
+
const attitudes = [];
|
|
225
|
+
for (const feature of orientations.features) {
|
|
226
|
+
const [x = 0, y = 0, z = 0] = feature.geometry.coordinates;
|
|
227
|
+
const [lon = 0, lat = 0] = crs.inverse([x, y]);
|
|
228
|
+
const p = feature.properties;
|
|
229
|
+
const number = (key) => (typeof p[key] === 'number' ? p[key] : 0);
|
|
230
|
+
attitudes.push({ heading: number('heading'), pitch: number('pitch'), roll: number('roll') });
|
|
231
|
+
list.push({
|
|
232
|
+
index: list.length,
|
|
233
|
+
id: p.id ?? list.length,
|
|
234
|
+
lonLat: [lon, lat],
|
|
235
|
+
height: z + (geoid ? host.geoidHeight(lon, lat) : 0),
|
|
236
|
+
heading: number('heading'),
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return new Panoramas(host, {
|
|
240
|
+
url: options.url,
|
|
241
|
+
backgroundDistance: options.backgroundDistance ?? 1000,
|
|
242
|
+
opacity: options.opacity ?? 1,
|
|
243
|
+
}, list, attitudes, cameras, lambert93);
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=panoramas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panoramas.js","sourceRoot":"","sources":["../src/panoramas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA0E5C,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC;AAE1B,+BAA+B;AAC/B,SAAS,KAAK,CAAC,CAAW,EAAE,CAAW;IACrC,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE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CAClB,IAAI,EACJ;QACE,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,IAAI;QACtD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC;KAC9B,EACD,IAAI,EACJ,SAAS,EACT,OAAO,EACP,SAAS,CACV,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Street-level panoramas: the oriented images of a vehicle's cameras around each of its positions (Stereopolis, the\n * iTowns immersive examples), projected onto the scene around the panorama shown. Their positions and attitudes come\n * as GeoJSON points (Lambert-93 by default, altitudes NGF-IGN69 raised by the RAF20 geoid onto the IGN relief), the\n * calibration of the cameras as JSON (rotation and position in the panorama frame, intrinsics, MicMac's radial\n * distortion), the images from a URL template with `{cameraId}` and `{panoId}`.\n *\n * ```ts\n * const panoramas = await map.addPanoramas({ url, orientationsUrl, calibrationUrl });\n * await panoramas.show(panoramas.nearest([2.3345, 48.8505]).index);\n * ```\n */\nimport { getCrs } from './crs.ts';\nimport { withHeaders } from './requests.ts';\nimport type { FirstPersonView, LonLat } from './types.ts';\n\nexport interface PanoramaOptions {\n /** URL of an image: `{cameraId}` and `{panoId}` replaced by a camera's id and a panorama's */\n url: string;\n /** GeoJSON points: each panorama's position, and its `id`, `heading`, `pitch`, `roll` (degrees) in properties */\n orientationsUrl: string;\n /** JSON array of the cameras: `id`, `rotation` (row-major), `position`, `projection`, `size`, `distortion` */\n calibrationUrl: string;\n /** CRS of the positions (default the GeoJSON's `crs` member, else `EPSG:2154`) */\n crs?: string;\n /** Altitudes above the geoid (NGF-IGN69), raised by the RAF20 geoid onto the IGN relief (default true in\n * Lambert-93) */\n geoid?: boolean;\n /** Radius of the sphere around the panorama its images are a backdrop on, metres (default 1000) */\n backgroundDistance?: number;\n /** 0-1 (default 1) */\n opacity?: number;\n}\n\n/** A panorama: where it is and which way the vehicle faced */\nexport interface Panorama {\n index: number;\n id: number | string;\n lonLat: LonLat;\n /** Metres above the ellipsoid */\n height: number;\n /** Degrees clockwise from north */\n heading: number;\n}\n\n/** What the map gives the panoramas */\nexport interface PanoramaHost {\n setPanorama(\n lon: number,\n lat: number,\n height: number,\n rotation: Float64Array,\n cameras: Float64Array,\n radius: number,\n opacity: number,\n ): void;\n setPanoramaImage(index: number, image: ImageBitmap): void;\n clearPanorama(): void;\n geoidHeight(lon: number, lat: number): number;\n /** The street-level eye, and setting it (undefined: back to the camera turning around a point) */\n firstPerson(): Readonly<Required<FirstPersonView>> | undefined;\n setFirstPerson(view: FirstPersonView | undefined): void;\n elevationAt(lonLat: LonLat): number | undefined;\n /** Follows the clicks on the map (with the ground clicked), the keys typed on it and its wheel (taken from the\n * map's own); returns what stops */\n listen(\n click: (lonLat: LonLat | undefined) => void,\n key: (e: KeyboardEvent) => void,\n wheel: (e: WheelEvent) => void,\n ): () => void;\n}\n\ninterface Calibration {\n id: number | string;\n rotation: number[];\n position: number[];\n projection: number[];\n size: number[];\n distortion?: { pps: number[]; poly357: number[]; limit?: number };\n}\n\ninterface Attitude {\n heading: number;\n pitch: number;\n roll: number;\n}\n\nconst RAD = Math.PI / 180;\n\n/** 3 × 3 product, row-major */\nfunction times(a: number[], b: number[]): number[] {\n const out: number[] = [];\n for (let r = 0; r < 3; r++) {\n for (let c = 0; c < 3; c++) {\n let sum = 0;\n for (let k = 0; k < 3; k++) sum += (a[r * 3 + k] ?? 0) * (b[k * 3 + c] ?? 0);\n out.push(sum);\n }\n }\n return out;\n}\n\nconst rotX = (t: number) => [1, 0, 0, 0, Math.cos(t), -Math.sin(t), 0, Math.sin(t), Math.cos(t)];\nconst rotY = (t: number) => [Math.cos(t), 0, Math.sin(t), 0, 1, 0, -Math.sin(t), 0, Math.cos(t)];\nconst rotZ = (t: number) => [Math.cos(t), -Math.sin(t), 0, Math.sin(t), Math.cos(t), 0, 0, 0, 1];\n\n/**\n * The panorama frame to east, north, up (row-major): the vehicle's attitude in the CRS's grid (iTowns'\n * `quaternionFromRollPitchHeading`: Ry(-roll) · Rx(-pitch) · Rz(-heading)), turned by the meridian convergence of the\n * projection (Lambert-93: sin(46.5°) · (3° - longitude))\n */\nexport function panoramaRotation(attitude: Attitude, lon: number, lambert93: boolean): number[] {\n const vehicle = times(times(rotY(-attitude.roll * RAD), rotX(-attitude.pitch * RAD)), rotZ(-attitude.heading * RAD));\n const convergence = lambert93 ? Math.sin(46.5 * RAD) * (3 - lon) * RAD : 0;\n return times(rotZ(convergence), vehicle);\n}\n\n/** The 25 numbers of a camera for `setPanorama` */\nfunction cameraNumbers(c: Calibration): number[] {\n const p = c.projection;\n const d = c.distortion;\n return [\n ...c.rotation.slice(0, 9),\n ...c.position.slice(0, 3),\n p[0] ?? 1,\n p[4] ?? 1,\n p[2] ?? 0,\n p[5] ?? 0,\n p[1] ?? 0,\n c.size[0] ?? 1,\n c.size[1] ?? 1,\n d?.pps[0] ?? 0,\n d?.pps[1] ?? 0,\n d?.poly357[0] ?? 0,\n d?.poly357[1] ?? 0,\n d?.poly357[2] ?? 0,\n d?.limit ?? 0,\n ];\n}\n\n/** The panoramas of a set, one shown at a time */\nexport class Panoramas {\n /** The panorama shown, if any */\n current: Panorama | undefined;\n private shown = 0;\n\n /** @internal */\n constructor(\n private readonly host: PanoramaHost,\n private readonly options: Required<Pick<PanoramaOptions, 'url' | 'backgroundDistance' | 'opacity'>>,\n readonly list: readonly Panorama[],\n private readonly attitudes: readonly Attitude[],\n private readonly cameras: readonly Calibration[],\n private readonly lambert93: boolean,\n ) {}\n\n /** The panorama nearest to a position */\n nearest(lonLat: LonLat): Panorama | undefined {\n const cos = Math.cos(lonLat[1] * RAD);\n let best: Panorama | undefined;\n let distance = Number.POSITIVE_INFINITY;\n for (const p of this.list) {\n const d = ((p.lonLat[0] - lonLat[0]) * cos) ** 2 + (p.lonLat[1] - lonLat[1]) ** 2;\n if (d < distance) [best, distance] = [p, d];\n }\n return best;\n }\n\n /** Shows a panorama (its index in `list`): projected as soon as its first image arrives, the others after */\n async show(index: number): Promise<void> {\n const pano = this.list[index];\n const attitude = this.attitudes[index];\n if (!pano || !attitude) return;\n const shown = ++this.shown;\n this.current = pano;\n const rotation = panoramaRotation(attitude, pano.lonLat[0], this.lambert93);\n const { url, backgroundDistance, opacity } = this.options;\n this.host.setPanorama(\n pano.lonLat[0],\n pano.lonLat[1],\n pano.height,\n Float64Array.from(rotation),\n Float64Array.from(this.cameras.flatMap(cameraNumbers)),\n backgroundDistance,\n opacity,\n );\n await Promise.all(\n this.cameras.map(async (camera, k) => {\n const src = url.replaceAll('{cameraId}', String(camera.id)).replaceAll('{panoId}', String(pano.id));\n const response = await fetch(src, withHeaders(src));\n if (!response.ok) throw new Error(`isard: panorama image ${src}: ${response.status}`);\n const image = await createImageBitmap(await response.blob(), { premultiplyAlpha: 'none' });\n // Another panorama shown since: this image is not its\n if (shown === this.shown) this.host.setPanoramaImage(k, image);\n image.close();\n }),\n );\n }\n\n /** Hides the panorama shown */\n hide(): void {\n this.shown++;\n this.current = undefined;\n this.host.clearPanorama();\n }\n\n /** Stops the walk (`enter`) */\n private stopWalking: (() => void) | undefined;\n\n /**\n * Street-level walk from panorama to panorama (the iTowns immersive view): the eye on a panorama, the drag\n * turning it; a click goes to the panorama nearest to the clicked point, the wheel to the nearest one ahead (or\n * behind), Z and S (or Page Up and Page Down) to the next and the previous ones. Starts on the panorama `index`,\n * else the one nearest to `near`\n */\n async enter(start: { index?: number; near?: LonLat } = {}): Promise<void> {\n const first = start.index ?? (start.near && this.nearest(start.near)?.index) ?? 0;\n this.stopWalking?.();\n this.stopWalking = this.host.listen(\n (lonLat) => {\n const target = lonLat && this.nearest(lonLat);\n if (target && target !== this.current) void this.go(target.index);\n },\n (e) => {\n const step = { z: 1, Z: 1, PageUp: 1, s: -1, S: -1, PageDown: -1 }[e.key];\n if (!step || !this.current) return;\n e.preventDefault();\n void this.go((this.current.index + step + this.list.length) % this.list.length);\n },\n (e) => {\n // One step per notch, the next ones once it is shown\n if (this.moving || e.deltaY === 0) return;\n const target = this.ahead(e.deltaY < 0);\n if (target) {\n this.moving = true;\n void this.go(target.index).finally(() => {\n this.moving = false;\n });\n }\n },\n );\n await this.go(first, this.list[first]?.heading);\n }\n\n /** A step of the wheel under way */\n private moving = false;\n\n /** The nearest panorama ahead of the eye (within 60° of where it looks), or behind it */\n ahead(forward = true): Panorama | undefined {\n const eye = this.host.firstPerson();\n const here = this.current;\n if (!eye || !here) return undefined;\n const cos = Math.cos(here.lonLat[1] * RAD);\n const look = (eye.bearing + (forward ? 0 : 180)) * RAD;\n let best: Panorama | undefined;\n let distance = Number.POSITIVE_INFINITY;\n for (const p of this.list) {\n if (p === here) continue;\n const [east, north] = [(p.lonLat[0] - here.lonLat[0]) * cos, p.lonLat[1] - here.lonLat[1]];\n const d = Math.hypot(east, north);\n const off = Math.acos(Math.max(-1, Math.min(1, (east * Math.sin(look) + north * Math.cos(look)) / (d || 1))));\n if (off < 60 * RAD && d < distance) [best, distance] = [p, d];\n }\n return best;\n }\n\n /** Goes to a panorama during the walk, the eye looking the same way (or `bearing`) */\n async go(index: number, bearing?: number): Promise<void> {\n const pano = this.list[index];\n if (!pano) return;\n const eye = this.host.firstPerson();\n // The eye at the panorama's cameras, above the ground there\n const ground = this.host.elevationAt(pano.lonLat);\n this.host.setFirstPerson({\n lonLat: pano.lonLat,\n height: ground === undefined ? 2.5 : Math.max(0.5, pano.height - ground),\n bearing: bearing ?? eye?.bearing ?? pano.heading,\n ...(eye ? { pitch: eye.pitch, fov: eye.fov } : {}),\n });\n await this.show(index);\n }\n\n /** Ends the walk: the panorama hidden, the camera turning around a point again, above where the eye stood */\n exit(): void {\n this.stopWalking?.();\n this.stopWalking = undefined;\n this.hide();\n this.host.setFirstPerson(undefined);\n }\n}\n\n/** Loads a set of panoramas: their positions and attitudes, the calibration of their cameras */\nexport async function loadPanoramas(host: PanoramaHost, options: PanoramaOptions): Promise<Panoramas> {\n const json = async <T>(src: string) => {\n const response = await fetch(src, withHeaders(src));\n if (!response.ok) throw new Error(`isard: ${src}: ${response.status}`);\n return (await response.json()) as T;\n };\n const [orientations, cameras] = await Promise.all([\n json<{\n crs?: { properties?: { name?: string } };\n features: { geometry: { coordinates: number[] }; properties: Record<string, unknown> }[];\n }>(options.orientationsUrl),\n json<Calibration[]>(options.calibrationUrl),\n ]);\n const crsName = options.crs ?? orientations.crs?.properties?.name ?? 'EPSG:2154';\n const lambert93 = /2154/.test(crsName);\n const crs = getCrs(crsName);\n const geoid = options.geoid ?? lambert93;\n const list: Panorama[] = [];\n const attitudes: Attitude[] = [];\n for (const feature of orientations.features) {\n const [x = 0, y = 0, z = 0] = feature.geometry.coordinates;\n const [lon = 0, lat = 0] = crs.inverse([x, y]);\n const p = feature.properties;\n const number = (key: string) => (typeof p[key] === 'number' ? (p[key] as number) : 0);\n attitudes.push({ heading: number('heading'), pitch: number('pitch'), roll: number('roll') });\n list.push({\n index: list.length,\n id: (p.id as number | string | undefined) ?? list.length,\n lonLat: [lon, lat],\n height: z + (geoid ? host.geoidHeight(lon, lat) : 0),\n heading: number('heading'),\n });\n }\n return new Panoramas(\n host,\n {\n url: options.url,\n backgroundDistance: options.backgroundDistance ?? 1000,\n opacity: options.opacity ?? 1,\n },\n list,\n attitudes,\n cameras,\n lambert93,\n );\n}\n"]}
|
package/dist/pmtiles.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* workers (vector tiles of a style source `pmtiles://…`, as MapLibre's protocol names them).
|
|
6
6
|
*/
|
|
7
7
|
import { Lru } from "./lru.js";
|
|
8
|
+
import { withHeaders } from "./requests.js";
|
|
8
9
|
const HEADER = 127;
|
|
9
10
|
/** The header and the root directory lie within the first 16 KB of the file */
|
|
10
11
|
const FIRST = 16384;
|
|
@@ -180,10 +181,10 @@ export class PMTiles {
|
|
|
180
181
|
}
|
|
181
182
|
if (this.whole)
|
|
182
183
|
return (await this.whole).subarray(offset, offset + length);
|
|
183
|
-
const response = await fetch(this.source, {
|
|
184
|
+
const response = await fetch(this.source, withHeaders(this.source, {
|
|
184
185
|
headers: { Range: `bytes=${offset}-${offset + Math.max(length, 1) - 1}` },
|
|
185
186
|
...(signal ? { signal } : {}),
|
|
186
|
-
});
|
|
187
|
+
}));
|
|
187
188
|
if (!response.ok)
|
|
188
189
|
throw new Error(`${this.source}: HTTP ${response.status}`);
|
|
189
190
|
if (response.status === 206)
|
package/dist/pmtiles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pmtiles.js","sourceRoot":"","sources":["../src/pmtiles.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAkC/B,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,+EAA+E;AAC/E,MAAM,KAAK,GAAG,KAAK,CAAC;AACpB,MAAM,KAAK,GAAsB,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEnF,0CAA0C;AAC1C,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAEnD,6GAA6G;AAC7G,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;IACzD,IAAI,CAAC,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAC;IACjE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC/G,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtB,IAAI,CAAC,GAAG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C;IACzB,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;IACxC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACxE,CAAC","sourcesContent":["/**\n * PMTiles v3 archives: one file of tiles read by HTTP range requests (or from a `Blob`), as Protomaps publishes them.\n * The header and root directory in one request, the leaf directories as needed (kept in a small cache), each tile in\n * its own range; gzip through `DecompressionStream`. The same reader in the page (raster tiles) and in the basemap\n * workers (vector tiles of a style source `pmtiles://…`, as MapLibre's protocol names them).\n */\nimport { Lru } from './lru.ts';\n\n/** What a PMTiles archive's tiles are */\nexport type PmtilesTileType = 'unknown' | 'mvt' | 'png' | 'jpeg' | 'webp' | 'avif';\n\n/** The header of a PMTiles archive (v3) */\nexport interface PmtilesHeader {\n rootDirectoryOffset: number;\n rootDirectoryLength: number;\n metadataOffset: number;\n metadataLength: number;\n leafDirectoryOffset: number;\n leafDirectoryLength: number;\n tileDataOffset: number;\n tileDataLength: number;\n /** 1 none, 2 gzip, 3 brotli, 4 zstd (only none and gzip are read) */\n internalCompression: number;\n tileCompression: number;\n tileType: PmtilesTileType;\n minZoom: number;\n maxZoom: number;\n /** `[west, south, east, north]`, degrees */\n bounds: [number, number, number, number];\n center: [lon: number, lat: number, zoom: number];\n}\n\n/** An entry of a directory: a run of tiles (`runLength` > 0) or a leaf directory (0) */\nexport interface PmtilesEntry {\n tileId: number;\n offset: number;\n length: number;\n runLength: number;\n}\n\nconst HEADER = 127;\n/** The header and the root directory lie within the first 16 KB of the file */\nconst FIRST = 16384;\nconst TYPES: PmtilesTileType[] = ['unknown', 'mvt', 'png', 'jpeg', 'webp', 'avif'];\n\n/** Tiles before level z: (4^z - 1) / 3 */\nconst levelStart = (z: number) => (4 ** z - 1) / 3;\n\n/** The tile id of z/x/y: the tiles of the lower levels, then the position along the level's Hilbert curve */\nexport function zxyToTileId(z: number, x: number, y: number): number {\n if (z > 26) throw new Error(`isard: PMTiles level ${z} past 26`);\n const n = 2 ** z;\n if (x < 0 || y < 0 || x >= n || y >= n) throw new Error(`isard: PMTiles tile ${z}/${x}/${y} out of its level`);\n let [px, py] = [x, y];\n let d = 0;\n for (let s = n / 2; s >= 1; s /= 2) {\n const rx = (px & s) > 0 ? 1 : 0;\n const ry = (py & s) > 0 ? 1 : 0;\n d += s * s * ((3 * rx) ^ ry);\n if (ry === 0) {\n if (rx === 1) [px, py] = [s - 1 - px, s - 1 - py];\n [px, py] = [py, px];\n }\n }\n return levelStart(z) + d;\n}\n\n/** The z/x/y of a tile id (the inverse of `zxyToTileId`) */\nexport function tileIdToZxy(id: number): [z: number, x: number, y: number] {\n let z = 0;\n while (levelStart(z + 1) <= id) z += 1;\n const n = 2 ** z;\n let t = id - levelStart(z);\n let [x, y] = [0, 0];\n for (let s = 1; s < n; s *= 2) {\n // Arithmetic, not bitwise: positions pass 32 bits past level 16\n const rx = Math.floor(t / 2) % 2;\n const ry = (t % 2) ^ rx;\n if (ry === 0) {\n if (rx === 1) [x, y] = [s - 1 - x, s - 1 - y];\n [x, y] = [y, x];\n }\n x += s * rx;\n y += s * ry;\n t = Math.floor(t / 4);\n }\n return [z, x, y];\n}\n\n/** A reader of unsigned varints past 32 bits (tile ids reach 2^52) */\nclass Varints {\n pos = 0;\n constructor(private readonly bytes: Uint8Array) {}\n next(): number {\n let value = 0;\n let scale = 1;\n for (;;) {\n const b = this.bytes[this.pos++];\n if (b === undefined) throw new Error('isard: PMTiles directory truncated');\n value += (b & 0x7f) * scale;\n if (b < 0x80) return value;\n scale *= 128;\n if (scale > 2 ** 63) throw new Error('isard: PMTiles varint too long');\n }\n }\n}\n\n/** The entries of a directory (decompressed) */\nexport function parseDirectory(bytes: Uint8Array): PmtilesEntry[] {\n const v = new Varints(bytes);\n const count = v.next();\n if (count > bytes.length) throw new Error('isard: PMTiles directory larger than its bytes');\n const entries: PmtilesEntry[] = [];\n let id = 0;\n for (let i = 0; i < count; i += 1) {\n id += v.next();\n entries.push({ tileId: id, offset: 0, length: 0, runLength: 1 });\n }\n for (const e of entries) e.runLength = v.next();\n for (const e of entries) e.length = v.next();\n entries.forEach((e, i) => {\n const value = v.next();\n const previous = entries[i - 1];\n // 0 after the first: right after the previous entry's bytes\n e.offset = value === 0 && previous ? previous.offset + previous.length : value - 1;\n });\n return entries;\n}\n\n/** The entry holding a tile id: its run of tiles, or the leaf directory it falls in; undefined if none */\nexport function findEntry(entries: readonly PmtilesEntry[], id: number): PmtilesEntry | undefined {\n let [lo, hi] = [0, entries.length - 1];\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n const e = entries[mid] as PmtilesEntry;\n if (e.tileId === id) return e;\n if (e.tileId < id) lo = mid + 1;\n else hi = mid - 1;\n }\n const e = entries[hi];\n if (!e) return undefined;\n if (e.runLength === 0 || id - e.tileId < e.runLength) return e;\n return undefined;\n}\n\n/** The header of an archive from its first bytes */\nexport function parseHeader(bytes: Uint8Array): PmtilesHeader {\n if (bytes.length < HEADER || String.fromCharCode(...bytes.subarray(0, 7)) !== 'PMTiles') {\n throw new Error('isard: not a PMTiles archive');\n }\n if (bytes[7] !== 3) throw new Error(`isard: PMTiles version ${bytes[7]} (only 3 is read)`);\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n const u64 = (at: number) => Number(view.getBigUint64(at, true));\n const deg = (at: number) => view.getInt32(at, true) / 1e7;\n return {\n rootDirectoryOffset: u64(8),\n rootDirectoryLength: u64(16),\n metadataOffset: u64(24),\n metadataLength: u64(32),\n leafDirectoryOffset: u64(40),\n leafDirectoryLength: u64(48),\n tileDataOffset: u64(56),\n tileDataLength: u64(64),\n internalCompression: view.getUint8(97),\n tileCompression: view.getUint8(98),\n tileType: TYPES[view.getUint8(99)] ?? 'unknown',\n minZoom: view.getUint8(100),\n maxZoom: view.getUint8(101),\n bounds: [deg(102), deg(106), deg(110), deg(114)],\n center: [deg(119), deg(123), view.getUint8(118)],\n };\n}\n\n/** Bytes as they are stored, decompressed (1: none, 2: gzip; 0, unknown, is read as none) */\nexport async function decompress(bytes: Uint8Array, compression: number): Promise<Uint8Array> {\n if (compression === 0 || compression === 1) return bytes;\n if (compression !== 2) {\n throw new Error(`isard: PMTiles compression ${compression === 3 ? 'brotli' : 'zstd'} is not read (gzip only)`);\n }\n const stream = new Blob([bytes as Uint8Array<ArrayBuffer>]).stream().pipeThrough(new DecompressionStream('gzip'));\n return new Uint8Array(await new Response(stream).arrayBuffer());\n}\n\n/** Past this, a whole file sent for a range request (a server ignoring ranges) is an error rather than kept */\nconst WHOLE_FILE_MAX = 64 * 1024 * 1024;\n\n/** A PMTiles archive at a URL (range requests) or in a `Blob` (a dropped file) */\nexport class PMTiles {\n private head: Promise<{ header: PmtilesHeader; root: PmtilesEntry[] }> | undefined;\n /** The leaf directories read, by offset */\n private readonly leaves = new Lru<number, Promise<PmtilesEntry[]>>(64);\n /** The whole file, when the server answered a range request with it (small files, `blob:` URLs) */\n private whole: Promise<Uint8Array> | undefined;\n\n constructor(readonly source: string | Blob) {}\n\n /** `length` bytes from `offset` */\n private async range(offset: number, length: number, signal?: AbortSignal): Promise<Uint8Array> {\n if (typeof this.source !== 'string') {\n return new Uint8Array(await this.source.slice(offset, offset + length).arrayBuffer());\n }\n if (this.whole) return (await this.whole).subarray(offset, offset + length);\n const response = await fetch(this.source, {\n headers: { Range: `bytes=${offset}-${offset + Math.max(length, 1) - 1}` },\n ...(signal ? { signal } : {}),\n });\n if (!response.ok) throw new Error(`${this.source}: HTTP ${response.status}`);\n if (response.status === 206) return new Uint8Array(await response.arrayBuffer());\n // The whole file: kept, when small enough, for the next ranges\n const size = Number(response.headers.get('Content-Length'));\n if (size > WHOLE_FILE_MAX) {\n await response.body?.cancel();\n throw new Error(`${this.source}: the server ignores range requests (HTTP 206 expected)`);\n }\n const whole = response.arrayBuffer().then((b) => new Uint8Array(b));\n this.whole = whole;\n whole.catch(() => {\n this.whole = undefined;\n });\n return (await whole).subarray(offset, offset + length);\n }\n\n private load() {\n this.head ??= (async () => {\n const first = await this.range(0, FIRST);\n const header = parseHeader(first);\n const { rootDirectoryOffset: o, rootDirectoryLength: n } = header;\n const raw = o + n <= first.length ? first.subarray(o, o + n) : await this.range(o, n);\n const root = parseDirectory(await decompress(raw, header.internalCompression));\n return { header, root };\n })();\n // A failure is not kept: asked again next time\n this.head.catch(() => {\n this.head = undefined;\n });\n return this.head;\n }\n\n /** The archive's header */\n async header(): Promise<PmtilesHeader> {\n return (await this.load()).header;\n }\n\n /** The archive's JSON metadata (`vector_layers`, `attribution`, `name`…); `{}` if it has none */\n async metadata(): Promise<Record<string, unknown>> {\n const { header } = await this.load();\n if (header.metadataLength === 0) return {};\n const raw = await this.range(header.metadataOffset, header.metadataLength);\n const text = new TextDecoder().decode(await decompress(raw, header.internalCompression));\n const value: unknown = JSON.parse(text);\n return value && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>) : {};\n }\n\n private leaf(header: PmtilesHeader, entry: PmtilesEntry): Promise<PmtilesEntry[]> {\n const offset = header.leafDirectoryOffset + entry.offset;\n let leaf = this.leaves.get(offset);\n if (!leaf) {\n leaf = this.range(offset, entry.length).then(async (raw) =>\n parseDirectory(await decompress(raw, header.internalCompression)),\n );\n leaf.catch(() => this.leaves.delete(offset));\n this.leaves.set(offset, leaf);\n }\n return leaf;\n }\n\n /** The bytes of tile z/x/y, decompressed (a vector tile ungzipped); undefined where the archive has none */\n async tile(z: number, x: number, y: number, signal?: AbortSignal): Promise<Uint8Array | undefined> {\n const { header, root } = await this.load();\n if (z < header.minZoom || z > header.maxZoom) return undefined;\n const id = zxyToTileId(z, x, y);\n let entries = root;\n // The root, then at most three levels of leaves\n for (let depth = 0; depth < 4; depth += 1) {\n const entry = findEntry(entries, id);\n if (!entry) return undefined;\n if (entry.runLength > 0) {\n const raw = await this.range(header.tileDataOffset + entry.offset, entry.length, signal);\n return decompress(raw, header.tileCompression);\n }\n entries = await this.leaf(header, entry);\n }\n throw new Error('isard: PMTiles directories nested too deep');\n }\n}\n\n/** The archives opened, by URL: one reader (and its directory cache) per archive in a page or worker */\nconst archives = new Lru<string, PMTiles>(16);\n\n/** The reader of an archive URL (without `pmtiles://`), shared */\nexport function pmtiles(url: string): PMTiles {\n let archive = archives.get(url);\n if (!archive) {\n archive = new PMTiles(url);\n archives.set(url, archive);\n }\n return archive;\n}\n\n/** The archive URL of a `pmtiles://` URL, absolute (relative to the page), or undefined for another URL */\nexport function pmtilesUrl(url: string, base?: string): string | undefined {\n if (!url.startsWith('pmtiles://')) return undefined;\n const inner = url.slice('pmtiles://'.length);\n const from = base ?? (globalThis as { location?: { href: string } }).location?.href;\n try {\n return from ? new URL(inner, from).href : inner;\n } catch {\n return inner;\n }\n}\n\n/** A tile URL `pmtiles://<archive>/{z}/{x}/{y}` (with its numbers in) read from its archive: its bytes, undefined\n * where there is none; undefined too (`false`) for a URL that is not one */\nexport function pmtilesTile(url: string, signal?: AbortSignal): Promise<Uint8Array | undefined> | false {\n const match = /^pmtiles:\\/\\/(.+)\\/(\\d+)\\/(\\d+)\\/(\\d+)$/.exec(url);\n if (!match) return false;\n const [, archive = '', z, x, y] = match;\n return pmtiles(archive).tile(Number(z), Number(x), Number(y), signal);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pmtiles.js","sourceRoot":"","sources":["../src/pmtiles.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAkC5C,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,+EAA+E;AAC/E,MAAM,KAAK,GAAG,KAAK,CAAC;AACpB,MAAM,KAAK,GAAsB,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,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C7B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,IAAa;IACnD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,YAAY,CAAC;QAAE,OAAO,SAAS,CAAC;IACpD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,IAAI,GAAG,IAAI,IAAK,UAA8C,CAAC,QAAQ,EAAE,IAAI,CAAC;IACpF,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;4EAC4E;AAC5E,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,MAAoB;IAC3D,MAAM,KAAK,GAAG,yCAAyC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClE,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;IACxC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACxE,CAAC","sourcesContent":["/**\n * PMTiles v3 archives: one file of tiles read by HTTP range requests (or from a `Blob`), as Protomaps publishes them.\n * The header and root directory in one request, the leaf directories as needed (kept in a small cache), each tile in\n * its own range; gzip through `DecompressionStream`. The same reader in the page (raster tiles) and in the basemap\n * workers (vector tiles of a style source `pmtiles://…`, as MapLibre's protocol names them).\n */\nimport { Lru } from './lru.ts';\nimport { withHeaders } from './requests.ts';\n\n/** What a PMTiles archive's tiles are */\nexport type PmtilesTileType = 'unknown' | 'mvt' | 'png' | 'jpeg' | 'webp' | 'avif';\n\n/** The header of a PMTiles archive (v3) */\nexport interface PmtilesHeader {\n rootDirectoryOffset: number;\n rootDirectoryLength: number;\n metadataOffset: number;\n metadataLength: number;\n leafDirectoryOffset: number;\n leafDirectoryLength: number;\n tileDataOffset: number;\n tileDataLength: number;\n /** 1 none, 2 gzip, 3 brotli, 4 zstd (only none and gzip are read) */\n internalCompression: number;\n tileCompression: number;\n tileType: PmtilesTileType;\n minZoom: number;\n maxZoom: number;\n /** `[west, south, east, north]`, degrees */\n bounds: [number, number, number, number];\n center: [lon: number, lat: number, zoom: number];\n}\n\n/** An entry of a directory: a run of tiles (`runLength` > 0) or a leaf directory (0) */\nexport interface PmtilesEntry {\n tileId: number;\n offset: number;\n length: number;\n runLength: number;\n}\n\nconst HEADER = 127;\n/** The header and the root directory lie within the first 16 KB of the file */\nconst FIRST = 16384;\nconst TYPES: PmtilesTileType[] = ['unknown', 'mvt', 'png', 'jpeg', 'webp', 'avif'];\n\n/** Tiles before level z: (4^z - 1) / 3 */\nconst levelStart = (z: number) => (4 ** z - 1) / 3;\n\n/** The tile id of z/x/y: the tiles of the lower levels, then the position along the level's Hilbert curve */\nexport function zxyToTileId(z: number, x: number, y: number): number {\n if (z > 26) throw new Error(`isard: PMTiles level ${z} past 26`);\n const n = 2 ** z;\n if (x < 0 || y < 0 || x >= n || y >= n) throw new Error(`isard: PMTiles tile ${z}/${x}/${y} out of its level`);\n let [px, py] = [x, y];\n let d = 0;\n for (let s = n / 2; s >= 1; s /= 2) {\n const rx = (px & s) > 0 ? 1 : 0;\n const ry = (py & s) > 0 ? 1 : 0;\n d += s * s * ((3 * rx) ^ ry);\n if (ry === 0) {\n if (rx === 1) [px, py] = [s - 1 - px, s - 1 - py];\n [px, py] = [py, px];\n }\n }\n return levelStart(z) + d;\n}\n\n/** The z/x/y of a tile id (the inverse of `zxyToTileId`) */\nexport function tileIdToZxy(id: number): [z: number, x: number, y: number] {\n let z = 0;\n while (levelStart(z + 1) <= id) z += 1;\n const n = 2 ** z;\n let t = id - levelStart(z);\n let [x, y] = [0, 0];\n for (let s = 1; s < n; s *= 2) {\n // Arithmetic, not bitwise: positions pass 32 bits past level 16\n const rx = Math.floor(t / 2) % 2;\n const ry = (t % 2) ^ rx;\n if (ry === 0) {\n if (rx === 1) [x, y] = [s - 1 - x, s - 1 - y];\n [x, y] = [y, x];\n }\n x += s * rx;\n y += s * ry;\n t = Math.floor(t / 4);\n }\n return [z, x, y];\n}\n\n/** A reader of unsigned varints past 32 bits (tile ids reach 2^52) */\nclass Varints {\n pos = 0;\n constructor(private readonly bytes: Uint8Array) {}\n next(): number {\n let value = 0;\n let scale = 1;\n for (;;) {\n const b = this.bytes[this.pos++];\n if (b === undefined) throw new Error('isard: PMTiles directory truncated');\n value += (b & 0x7f) * scale;\n if (b < 0x80) return value;\n scale *= 128;\n if (scale > 2 ** 63) throw new Error('isard: PMTiles varint too long');\n }\n }\n}\n\n/** The entries of a directory (decompressed) */\nexport function parseDirectory(bytes: Uint8Array): PmtilesEntry[] {\n const v = new Varints(bytes);\n const count = v.next();\n if (count > bytes.length) throw new Error('isard: PMTiles directory larger than its bytes');\n const entries: PmtilesEntry[] = [];\n let id = 0;\n for (let i = 0; i < count; i += 1) {\n id += v.next();\n entries.push({ tileId: id, offset: 0, length: 0, runLength: 1 });\n }\n for (const e of entries) e.runLength = v.next();\n for (const e of entries) e.length = v.next();\n entries.forEach((e, i) => {\n const value = v.next();\n const previous = entries[i - 1];\n // 0 after the first: right after the previous entry's bytes\n e.offset = value === 0 && previous ? previous.offset + previous.length : value - 1;\n });\n return entries;\n}\n\n/** The entry holding a tile id: its run of tiles, or the leaf directory it falls in; undefined if none */\nexport function findEntry(entries: readonly PmtilesEntry[], id: number): PmtilesEntry | undefined {\n let [lo, hi] = [0, entries.length - 1];\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n const e = entries[mid] as PmtilesEntry;\n if (e.tileId === id) return e;\n if (e.tileId < id) lo = mid + 1;\n else hi = mid - 1;\n }\n const e = entries[hi];\n if (!e) return undefined;\n if (e.runLength === 0 || id - e.tileId < e.runLength) return e;\n return undefined;\n}\n\n/** The header of an archive from its first bytes */\nexport function parseHeader(bytes: Uint8Array): PmtilesHeader {\n if (bytes.length < HEADER || String.fromCharCode(...bytes.subarray(0, 7)) !== 'PMTiles') {\n throw new Error('isard: not a PMTiles archive');\n }\n if (bytes[7] !== 3) throw new Error(`isard: PMTiles version ${bytes[7]} (only 3 is read)`);\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n const u64 = (at: number) => Number(view.getBigUint64(at, true));\n const deg = (at: number) => view.getInt32(at, true) / 1e7;\n return {\n rootDirectoryOffset: u64(8),\n rootDirectoryLength: u64(16),\n metadataOffset: u64(24),\n metadataLength: u64(32),\n leafDirectoryOffset: u64(40),\n leafDirectoryLength: u64(48),\n tileDataOffset: u64(56),\n tileDataLength: u64(64),\n internalCompression: view.getUint8(97),\n tileCompression: view.getUint8(98),\n tileType: TYPES[view.getUint8(99)] ?? 'unknown',\n minZoom: view.getUint8(100),\n maxZoom: view.getUint8(101),\n bounds: [deg(102), deg(106), deg(110), deg(114)],\n center: [deg(119), deg(123), view.getUint8(118)],\n };\n}\n\n/** Bytes as they are stored, decompressed (1: none, 2: gzip; 0, unknown, is read as none) */\nexport async function decompress(bytes: Uint8Array, compression: number): Promise<Uint8Array> {\n if (compression === 0 || compression === 1) return bytes;\n if (compression !== 2) {\n throw new Error(`isard: PMTiles compression ${compression === 3 ? 'brotli' : 'zstd'} is not read (gzip only)`);\n }\n const stream = new Blob([bytes as Uint8Array<ArrayBuffer>]).stream().pipeThrough(new DecompressionStream('gzip'));\n return new Uint8Array(await new Response(stream).arrayBuffer());\n}\n\n/** Past this, a whole file sent for a range request (a server ignoring ranges) is an error rather than kept */\nconst WHOLE_FILE_MAX = 64 * 1024 * 1024;\n\n/** A PMTiles archive at a URL (range requests) or in a `Blob` (a dropped file) */\nexport class PMTiles {\n private head: Promise<{ header: PmtilesHeader; root: PmtilesEntry[] }> | undefined;\n /** The leaf directories read, by offset */\n private readonly leaves = new Lru<number, Promise<PmtilesEntry[]>>(64);\n /** The whole file, when the server answered a range request with it (small files, `blob:` URLs) */\n private whole: Promise<Uint8Array> | undefined;\n\n constructor(readonly source: string | Blob) {}\n\n /** `length` bytes from `offset` */\n private async range(offset: number, length: number, signal?: AbortSignal): Promise<Uint8Array> {\n if (typeof this.source !== 'string') {\n return new Uint8Array(await this.source.slice(offset, offset + length).arrayBuffer());\n }\n if (this.whole) return (await this.whole).subarray(offset, offset + length);\n const response = await fetch(\n this.source,\n withHeaders(this.source, {\n headers: { Range: `bytes=${offset}-${offset + Math.max(length, 1) - 1}` },\n ...(signal ? { signal } : {}),\n }),\n );\n if (!response.ok) throw new Error(`${this.source}: HTTP ${response.status}`);\n if (response.status === 206) return new Uint8Array(await response.arrayBuffer());\n // The whole file: kept, when small enough, for the next ranges\n const size = Number(response.headers.get('Content-Length'));\n if (size > WHOLE_FILE_MAX) {\n await response.body?.cancel();\n throw new Error(`${this.source}: the server ignores range requests (HTTP 206 expected)`);\n }\n const whole = response.arrayBuffer().then((b) => new Uint8Array(b));\n this.whole = whole;\n whole.catch(() => {\n this.whole = undefined;\n });\n return (await whole).subarray(offset, offset + length);\n }\n\n private load() {\n this.head ??= (async () => {\n const first = await this.range(0, FIRST);\n const header = parseHeader(first);\n const { rootDirectoryOffset: o, rootDirectoryLength: n } = header;\n const raw = o + n <= first.length ? first.subarray(o, o + n) : await this.range(o, n);\n const root = parseDirectory(await decompress(raw, header.internalCompression));\n return { header, root };\n })();\n // A failure is not kept: asked again next time\n this.head.catch(() => {\n this.head = undefined;\n });\n return this.head;\n }\n\n /** The archive's header */\n async header(): Promise<PmtilesHeader> {\n return (await this.load()).header;\n }\n\n /** The archive's JSON metadata (`vector_layers`, `attribution`, `name`…); `{}` if it has none */\n async metadata(): Promise<Record<string, unknown>> {\n const { header } = await this.load();\n if (header.metadataLength === 0) return {};\n const raw = await this.range(header.metadataOffset, header.metadataLength);\n const text = new TextDecoder().decode(await decompress(raw, header.internalCompression));\n const value: unknown = JSON.parse(text);\n return value && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>) : {};\n }\n\n private leaf(header: PmtilesHeader, entry: PmtilesEntry): Promise<PmtilesEntry[]> {\n const offset = header.leafDirectoryOffset + entry.offset;\n let leaf = this.leaves.get(offset);\n if (!leaf) {\n leaf = this.range(offset, entry.length).then(async (raw) =>\n parseDirectory(await decompress(raw, header.internalCompression)),\n );\n leaf.catch(() => this.leaves.delete(offset));\n this.leaves.set(offset, leaf);\n }\n return leaf;\n }\n\n /** The bytes of tile z/x/y, decompressed (a vector tile ungzipped); undefined where the archive has none */\n async tile(z: number, x: number, y: number, signal?: AbortSignal): Promise<Uint8Array | undefined> {\n const { header, root } = await this.load();\n if (z < header.minZoom || z > header.maxZoom) return undefined;\n const id = zxyToTileId(z, x, y);\n let entries = root;\n // The root, then at most three levels of leaves\n for (let depth = 0; depth < 4; depth += 1) {\n const entry = findEntry(entries, id);\n if (!entry) return undefined;\n if (entry.runLength > 0) {\n const raw = await this.range(header.tileDataOffset + entry.offset, entry.length, signal);\n return decompress(raw, header.tileCompression);\n }\n entries = await this.leaf(header, entry);\n }\n throw new Error('isard: PMTiles directories nested too deep');\n }\n}\n\n/** The archives opened, by URL: one reader (and its directory cache) per archive in a page or worker */\nconst archives = new Lru<string, PMTiles>(16);\n\n/** The reader of an archive URL (without `pmtiles://`), shared */\nexport function pmtiles(url: string): PMTiles {\n let archive = archives.get(url);\n if (!archive) {\n archive = new PMTiles(url);\n archives.set(url, archive);\n }\n return archive;\n}\n\n/** The archive URL of a `pmtiles://` URL, absolute (relative to the page), or undefined for another URL */\nexport function pmtilesUrl(url: string, base?: string): string | undefined {\n if (!url.startsWith('pmtiles://')) return undefined;\n const inner = url.slice('pmtiles://'.length);\n const from = base ?? (globalThis as { location?: { href: string } }).location?.href;\n try {\n return from ? new URL(inner, from).href : inner;\n } catch {\n return inner;\n }\n}\n\n/** A tile URL `pmtiles://<archive>/{z}/{x}/{y}` (with its numbers in) read from its archive: its bytes, undefined\n * where there is none; undefined too (`false`) for a URL that is not one */\nexport function pmtilesTile(url: string, signal?: AbortSignal): Promise<Uint8Array | undefined> | false {\n const match = /^pmtiles:\\/\\/(.+)\\/(\\d+)\\/(\\d+)\\/(\\d+)$/.exec(url);\n if (!match) return false;\n const [, archive = '', z, x, y] = match;\n return pmtiles(archive).tile(Number(z), Number(x), Number(y), signal);\n}\n"]}
|
package/dist/pointclouds.js
CHANGED
|
@@ -214,7 +214,7 @@ export class PointCloudLayer extends Layer {
|
|
|
214
214
|
apply(engine, id) {
|
|
215
215
|
const s = this.style;
|
|
216
216
|
if (this.format === '3dtiles') {
|
|
217
|
-
engine.setTiles3dStyle(id, s.maxScreenSpaceError, 1, s.pointSize);
|
|
217
|
+
engine.setTiles3dStyle(id, s.maxScreenSpaceError, 1, s.pointSize, new Float32Array());
|
|
218
218
|
return;
|
|
219
219
|
}
|
|
220
220
|
const rate = this.options.requestsPerSecond ?? (/^https?:\/\/data\.geopf\.fr\//.test(this.url) ? 8 : 0);
|
package/dist/pointclouds.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pointclouds.js","sourceRoot":"","sources":["../src/pointclouds.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAA0B,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAgB,UAAU,EAAa,UAAU,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAsEpC;iCACiC;AACjC,MAAM,CAAC,MAAM,eAAe,GAA6D;IACvF,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,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AC;IACZ,CAAC;CACF","sourcesContent":["/**\n * Point clouds: a COPC file (Cloud Optimized Point Cloud: LAZ 1.4 with an octree, read by HTTP range requests, as the\n * IGN distributes LiDAR HD) or a 3D Tiles point cloud (`.pnts`, glTF points), drawn by the engine with 3D Tiles. The\n * COPC file's CRS comes from its WKT (built-in CRSs, or registered ones: `registerCrs`) or the `crs` option; altitudes\n * in NGF-IGN69 (Lambert-93, the CC zones) are raised by the RAF20 geoid height onto the ellipsoid of the relief and\n * the 3D Tiles.\n */\nimport { type Crs, type CrsLike, epsgCode, getCrs } from './crs.ts';\nimport { type Feature, parseColor, type Ramp, rampTexels } from './features.ts';\nimport { Layer } from './layers.ts';\nimport type { LayerHost } from './types.ts';\nimport type {\n Engine,\n PointCloudCrs,\n PointCloudInfo,\n PointCloudPoint,\n PointCloudStats,\n Tiles3dStats,\n} from './wasm/isard.js';\n\n/** What the points are colored by */\nexport type PointColor = 'rgb' | 'classification' | 'elevation' | 'intensity';\n\n/** The look of a class of points */\nexport interface ClassStyle {\n /** CSS color */\n color?: string;\n /** false hides the class */\n visible?: boolean;\n}\n\nexport interface PointCloudStyle {\n /** By RGB (files with colors), class (the ASPRS palette, `classifications`), altitude (`elevationRamp` over\n * `elevationRange`) or intensity (grey over `intensityRange`). Default: RGB when the file has colors, else class */\n colorBy?: PointColor;\n /** CSS pixels: the size of the points, or the smallest with `sizeMode: 'adaptive'` (default 2) */\n pointSize: number;\n /** CSS pixels: the largest adaptive size (default 4) */\n maxPointSize: number;\n /** `'adaptive'` (default): the spacing of the points of the finest level drawn there, at their distance (the\n * nearer, the larger, no gap); `'fixed'`: `pointSize` everywhere */\n sizeMode: 'adaptive' | 'fixed';\n /** `'circle'` (default) or `'square'` */\n shape: 'circle' | 'square';\n /** Eye-Dome Lighting: points shaded by the depth of their neighbours on screen, their relief read without normals\n * nor colors (default false; `strength` 1, `radius` 1.4 CSS pixels) */\n edl: boolean | { strength?: number; radius?: number };\n /** Colors and visibility by class code, over the defaults (ASPRS, and IGN's LiDAR HD classes 64 to 67; the noise\n * 7 and 18 and the artefacts 65 hidden): `{ 2: { color: '#a0522d' }, 66: { visible: false } }` */\n classifications: Record<number, ClassStyle>;\n /** Altitudes (metres, the file's vertical datum) mapped onto the ramp; default the file's lowest and highest */\n elevationRange?: [min: number, max: number];\n /** Colors from the lowest altitude (0) to the highest (1) */\n elevationRamp: Ramp;\n /** Intensities mapped from black to white; default the bulk of the first node's (2nd to 98th percentile) */\n intensityRange?: [min: number, max: number];\n /** CSS pixels: a node is refined while the spacing of its points covers more on screen (default 1.5; lower is finer\n * and heavier). For 3D Tiles, their screen-space error (default 16) */\n maxScreenSpaceError: number;\n /** Points drawn at most, the nearest and the coarsest first (default 3 000 000) */\n pointBudget: number;\n}\n\nexport interface PointCloudOptions extends Partial<PointCloudStyle> {\n /** A COPC file (`.copc.laz`) or a 3D Tiles `tileset.json` of points */\n url: string;\n /** Default: `'3dtiles'` for a `.json` URL, else `'copc'` */\n format?: 'copc' | '3dtiles';\n /** The CRS of a COPC file without a WKT, or whose CRS is not built in (`proj4('EPSG:2992')`) */\n crs?: CrsLike;\n /** Its altitudes are above the geoid (NGF-IGN69), raised by the RAF20 geoid height; default for Lambert-93 and the\n * CC zones */\n geoid?: boolean;\n /** Metres of a unit of z; default the vertical unit of the WKT (a US survey foot…), else that of x and y */\n verticalScale?: number;\n /** Requests a second at most: 8 by default for the Géoplateforme (data.geopf.fr allows 10), no limit elsewhere */\n requestsPerSecond?: number;\n}\n\n/** The default classes: ASPRS LAS 1.4, then IGN's LiDAR HD (64 permanent structures, 65 artefacts, 66 virtual points,\n * 67 miscellaneous buildings) */\nexport const CLASSIFICATIONS: Readonly<Record<number, Readonly<Required<ClassStyle>>>> = {\n 0: { color: '#a6a6a6', visible: true },\n 1: { color: '#c8c8c8', visible: true },\n 2: { color: '#b08458', visible: true },\n 3: { color: '#9ccc65', visible: true },\n 4: { color: '#5aa83f', visible: true },\n 5: { color: '#2e7d32', visible: true },\n 6: { color: '#e57352', visible: true },\n 7: { color: '#ff00ff', visible: false },\n 8: { color: '#ff0000', visible: true },\n 9: { color: '#3d8fd6', visible: true },\n 10: { color: '#8e6bb0', visible: true },\n 11: { color: '#7a7a7a', visible: true },\n 12: { color: '#ffe680', visible: true },\n 13: { color: '#ffff00', visible: true },\n 14: { color: '#ffc800', visible: true },\n 15: { color: '#c89600', visible: true },\n 16: { color: '#ff9632', visible: true },\n 17: { color: '#b48cc8', visible: true },\n 18: { color: '#ff00ff', visible: false },\n 64: { color: '#8c6e5a', visible: true },\n 65: { color: '#ff00ff', visible: false },\n 66: { color: '#5a6ec8', visible: true },\n 67: { color: '#e6966e', visible: true },\n};\n\n/** The default ramp of the altitudes, low to high */\nexport const ELEVATION_RAMP: Ramp = [\n [0, '#2b83ba'],\n [0.25, '#abdda4'],\n [0.5, '#ffffbf'],\n [0.75, '#fdae61'],\n [1, '#d7191c'],\n];\n\n/** The colors of the 256 classes (RGBA, alpha 0 hides one) */\nexport function classPalette(overrides: Record<number, ClassStyle> = {}): Uint8Array {\n const out = new Uint8Array(256 * 4);\n for (let code = 0; code < 256; code += 1) {\n const base = CLASSIFICATIONS[code] ?? { color: '#c8c8c8', visible: true };\n const own = overrides[code] ?? {};\n const [r = 0, g = 0, b = 0] = parseColor(own.color ?? base.color);\n out.set([r * 255, g * 255, b * 255, (own.visible ?? base.visible) ? 255 : 0], code * 4);\n }\n return out;\n}\n\n/** The section of a WKT opening with one of `keywords` (`PROJCS[…]`), from its keyword to its closing bracket */\nfunction section(wkt: string, keywords: string[]): string | undefined {\n for (const keyword of keywords) {\n const start = wkt.indexOf(`${keyword}[`);\n if (start < 0) continue;\n let depth = 0;\n for (let i = start + keyword.length; i < wkt.length; i += 1) {\n if (wkt[i] === '[') depth += 1;\n else if (wkt[i] === ']' && --depth === 0) return wkt.slice(start, i + 1);\n }\n }\n return undefined;\n}\n\n/** The EPSG code a WKT section ends with (its own `AUTHORITY`, or `ID` in WKT2), the last of its nested ones */\nfunction lastCode(part: string): number | undefined {\n const codes = [...part.matchAll(/(?:AUTHORITY|ID)\\[\\s*\"EPSG\"\\s*,\\s*\"?(\\d+)\"?\\s*\\]/g)];\n const last = codes.at(-1)?.[1];\n return last === undefined ? undefined : Number(last);\n}\n\n/** The factor of the last `UNIT` (`LENGTHUNIT` in WKT2) of a WKT section */\nfunction lastUnit(part: string | undefined): number | undefined {\n const units = [...(part ?? '').matchAll(/(?:LENGTH)?UNIT\\[\\s*\"[^\"]*\"\\s*,\\s*([\\d.eE+-]+)/g)];\n const factor = Number(units.at(-1)?.[1]);\n return Number.isFinite(factor) && factor > 0 ? factor : undefined;\n}\n\n/** What a WKT says of a CRS: its EPSG code (projected first), the metres of a unit of z */\nexport function wktCrs(wkt: string): { code: number | undefined; verticalScale: number | undefined } {\n const projected = section(wkt, ['PROJCS', 'PROJCRS']);\n const geographic = section(wkt, ['GEOGCS', 'GEOGCRS']);\n let code = lastCode(projected ?? geographic ?? '');\n if (code === undefined && /Lambert[- ]93/i.test(wkt)) code = 2154;\n const vertical = section(wkt, ['VERT_CS', 'VERTCRS']);\n const verticalScale = lastUnit(vertical ?? projected);\n return { code, verticalScale };\n}\n\n/** Whether the altitudes of a CRS are NGF-IGN69 by default: Lambert-93 and the CC zones */\nconst FRENCH = (code: number | undefined) => code === 2154 || (code !== undefined && code >= 3942 && code <= 3950);\n\n/** The CRS of a COPC file for the engine, from its WKT and the options */\nexport function pointCloudCrs(\n wkt: string | undefined,\n options: Pick<PointCloudOptions, 'crs' | 'geoid' | 'verticalScale'>,\n): PointCloudCrs {\n const parsed = wkt ? wktCrs(wkt) : { code: undefined, verticalScale: undefined };\n let crs: Crs;\n let code = parsed.code;\n if (options.crs !== undefined) {\n crs = getCrs(options.crs);\n if (typeof options.crs === 'string') code = epsgCode(options.crs) ?? code;\n } else if (code !== undefined) {\n try {\n crs = getCrs(`EPSG:${code}`);\n } catch {\n throw new Error(`the CRS of the file, EPSG:${code}, is not built in: give it as \\`crs\\` (proj4('EPSG:${code}'))`);\n }\n } else {\n throw new Error('the file names no CRS: give it as `crs`');\n }\n const inverse = (xy: Float64Array) => {\n const out = new Float64Array(xy.length);\n for (let i = 0; i + 1 < xy.length; i += 2) {\n const [lon = Number.NaN, lat = Number.NaN] = crs.inverse([xy[i] as number, xy[i + 1] as number]);\n out[i] = lon;\n out[i + 1] = lat;\n }\n return out;\n };\n return {\n inverse,\n geoid: options.geoid ?? (FRENCH(code) || /IGN69|NGF/.test(wkt ?? '')),\n verticalScale: options.verticalScale ?? parsed.verticalScale ?? 1,\n };\n}\n\n/** The style numbers of the engine (`setPointCloudStyle`) */\nfunction styleNumbers(s: PointCloudStyle, rate: number): Float64Array {\n const colors: PointColor[] = ['rgb', 'classification', 'elevation', 'intensity'];\n let edl: { strength?: number; radius?: number } | undefined;\n if (s.edl) edl = s.edl === true ? {} : s.edl;\n const [emin = Number.NaN, emax = Number.NaN] = s.elevationRange ?? [];\n const [imin = Number.NaN, imax = Number.NaN] = s.intensityRange ?? [];\n return Float64Array.of(\n s.colorBy ? colors.indexOf(s.colorBy) : -1,\n s.pointSize,\n s.maxPointSize,\n s.sizeMode === 'fixed' ? 0 : 1,\n s.shape === 'square' ? 0 : 1,\n edl ? (edl.strength ?? 1) : 0,\n edl?.radius ?? 1.4,\n emin,\n emax,\n imin,\n imax,\n s.maxScreenSpaceError,\n s.pointBudget,\n rate,\n );\n}\n\n/** A point cloud (`GeoMap.addPointCloud`): COPC or 3D Tiles points; `pickFeature` gives a COPC point's attributes */\nexport class PointCloudLayer extends Layer {\n readonly url: string;\n readonly format: 'copc' | '3dtiles';\n private style: PointCloudStyle;\n private readonly options: PointCloudOptions;\n\n /** @internal */\n constructor(map: LayerHost, options: PointCloudOptions) {\n super(map);\n // Against the page: the decoding workers fetch it, and a relative URL would be theirs\n const base = typeof document === 'undefined' ? undefined : document.baseURI;\n this.url = base ? new URL(options.url, base).href : options.url;\n this.format = options.format ?? (/\\.json(?:[?#]|$)/i.test(options.url) ? '3dtiles' : 'copc');\n this.options = options;\n const tiles = this.format === '3dtiles';\n this.style = {\n ...(options.colorBy ? { colorBy: options.colorBy } : {}),\n pointSize: options.pointSize ?? 2,\n maxPointSize: options.maxPointSize ?? 4,\n sizeMode: options.sizeMode ?? 'adaptive',\n shape: options.shape ?? 'circle',\n edl: options.edl ?? false,\n classifications: options.classifications ?? {},\n ...(options.elevationRange ? { elevationRange: options.elevationRange } : {}),\n elevationRamp: options.elevationRamp ?? ELEVATION_RAMP,\n ...(options.intensityRange ? { intensityRange: options.intensityRange } : {}),\n maxScreenSpaceError: options.maxScreenSpaceError ?? (tiles ? 16 : 1.5),\n pointBudget: options.pointBudget ?? 3_000_000,\n };\n }\n\n /** @internal Drawn by the engine with 3D Tiles (the point cloud module loads with the first one) */\n override get needsFullEngine(): boolean {\n return true;\n }\n\n /** Changes the style, the rest kept */\n setStyle(style: Partial<PointCloudStyle>): void {\n this.style = { ...this.style, ...style };\n // Kept for its creation while the engine with 3D Tiles loads\n if (this.id < 0) return;\n this.apply(this.map.engine, this.id);\n this.map.requestRender();\n }\n\n getStyle(): Readonly<PointCloudStyle> {\n return this.style;\n }\n\n /** Loading counters; undefined once removed and while the engine with 3D Tiles loads */\n stats(): PointCloudStats | Tiles3dStats | undefined {\n if (this.id < 0) return undefined;\n return this.format === '3dtiles' ? this.map.engine.tiles3dStats(this.id) : this.map.engine.pointCloudStats(this.id);\n }\n\n /** What a COPC file says of itself (points, format, CRS, center, altitudes), once its head is read */\n info(): PointCloudInfo | undefined {\n return this.id < 0 || this.format === '3dtiles' ? undefined : this.map.engine.pointCloudInfo(this.id);\n }\n\n /** @internal The point picked (`pickFeature`, 'hoverfeature'): a Point at its longitude, latitude and height, its\n * attributes as properties */\n featureAt(index: number): Feature<PointCloudPoint> | undefined {\n if (this.id < 0 || this.format === '3dtiles') return undefined;\n const point = this.map.engine.pointCloudPoint(this.id, index);\n if (!point) return undefined;\n return {\n type: 'Feature',\n geometry: { type: 'Point', coordinates: [...point.lonLat, point.height] },\n properties: point,\n };\n }\n\n private apply(engine: Engine, id: number): void {\n const s = this.style;\n if (this.format === '3dtiles') {\n engine.setTiles3dStyle(id, s.maxScreenSpaceError, 1, s.pointSize);\n return;\n }\n const rate = this.options.requestsPerSecond ?? (/^https?:\\/\\/data\\.geopf\\.fr\\//.test(this.url) ? 8 : 0);\n engine.setPointCloudStyle(\n id,\n styleNumbers(s, rate),\n classPalette(s.classifications),\n rampTexels(s.elevationRamp).rgba,\n );\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id =\n this.format === '3dtiles'\n ? engine.addTiles3d(this.url, this.style.maxScreenSpaceError)\n : engine.addPointCloud(this.url, (wkt) => pointCloudCrs(wkt, this.options));\n this.apply(engine, id);\n return id;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pointclouds.js","sourceRoot":"","sources":["../src/pointclouds.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAA0B,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAgB,UAAU,EAAa,UAAU,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAsEpC;iCACiC;AACjC,MAAM,CAAC,MAAM,eAAe,GAA6D;IACvF,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;IACtC,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;IACtC,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;IACtC,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;IACtC,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;IACtC,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;IACtC,CAAC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,IAAI,YAAY,EAAE,CAAC,CAAC;YACtF,OAAO;QACT,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,IAAI,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxG,MAAM,CAAC,kBAAkB,CACvB,EAAE,EACF,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,EACrB,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,EAC/B,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,IAAI,CACjC,CAAC;IACJ,CAAC;IAED,gBAAgB;IACN,MAAM,CAAC,MAAc;QAC7B,MAAM,EAAE,GACN,IAAI,CAAC,MAAM,KAAK,SAAS;YACvB,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC;YAC7D,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAChF,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;CACF","sourcesContent":["/**\n * Point clouds: a COPC file (Cloud Optimized Point Cloud: LAZ 1.4 with an octree, read by HTTP range requests, as the\n * IGN distributes LiDAR HD) or a 3D Tiles point cloud (`.pnts`, glTF points), drawn by the engine with 3D Tiles. The\n * COPC file's CRS comes from its WKT (built-in CRSs, or registered ones: `registerCrs`) or the `crs` option; altitudes\n * in NGF-IGN69 (Lambert-93, the CC zones) are raised by the RAF20 geoid height onto the ellipsoid of the relief and\n * the 3D Tiles.\n */\nimport { type Crs, type CrsLike, epsgCode, getCrs } from './crs.ts';\nimport { type Feature, parseColor, type Ramp, rampTexels } from './features.ts';\nimport { Layer } from './layers.ts';\nimport type { LayerHost } from './types.ts';\nimport type {\n Engine,\n PointCloudCrs,\n PointCloudInfo,\n PointCloudPoint,\n PointCloudStats,\n Tiles3dStats,\n} from './wasm/isard.js';\n\n/** What the points are colored by */\nexport type PointColor = 'rgb' | 'classification' | 'elevation' | 'intensity';\n\n/** The look of a class of points */\nexport interface ClassStyle {\n /** CSS color */\n color?: string;\n /** false hides the class */\n visible?: boolean;\n}\n\nexport interface PointCloudStyle {\n /** By RGB (files with colors), class (the ASPRS palette, `classifications`), altitude (`elevationRamp` over\n * `elevationRange`) or intensity (grey over `intensityRange`). Default: RGB when the file has colors, else class */\n colorBy?: PointColor;\n /** CSS pixels: the size of the points, or the smallest with `sizeMode: 'adaptive'` (default 2) */\n pointSize: number;\n /** CSS pixels: the largest adaptive size (default 4) */\n maxPointSize: number;\n /** `'adaptive'` (default): the spacing of the points of the finest level drawn there, at their distance (the\n * nearer, the larger, no gap); `'fixed'`: `pointSize` everywhere */\n sizeMode: 'adaptive' | 'fixed';\n /** `'circle'` (default) or `'square'` */\n shape: 'circle' | 'square';\n /** Eye-Dome Lighting: points shaded by the depth of their neighbours on screen, their relief read without normals\n * nor colors (default false; `strength` 1, `radius` 1.4 CSS pixels) */\n edl: boolean | { strength?: number; radius?: number };\n /** Colors and visibility by class code, over the defaults (ASPRS, and IGN's LiDAR HD classes 64 to 67; the noise\n * 7 and 18 and the artefacts 65 hidden): `{ 2: { color: '#a0522d' }, 66: { visible: false } }` */\n classifications: Record<number, ClassStyle>;\n /** Altitudes (metres, the file's vertical datum) mapped onto the ramp; default the file's lowest and highest */\n elevationRange?: [min: number, max: number];\n /** Colors from the lowest altitude (0) to the highest (1) */\n elevationRamp: Ramp;\n /** Intensities mapped from black to white; default the bulk of the first node's (2nd to 98th percentile) */\n intensityRange?: [min: number, max: number];\n /** CSS pixels: a node is refined while the spacing of its points covers more on screen (default 1.5; lower is finer\n * and heavier). For 3D Tiles, their screen-space error (default 16) */\n maxScreenSpaceError: number;\n /** Points drawn at most, the nearest and the coarsest first (default 3 000 000) */\n pointBudget: number;\n}\n\nexport interface PointCloudOptions extends Partial<PointCloudStyle> {\n /** A COPC file (`.copc.laz`) or a 3D Tiles `tileset.json` of points */\n url: string;\n /** Default: `'3dtiles'` for a `.json` URL, else `'copc'` */\n format?: 'copc' | '3dtiles';\n /** The CRS of a COPC file without a WKT, or whose CRS is not built in (`proj4('EPSG:2992')`) */\n crs?: CrsLike;\n /** Its altitudes are above the geoid (NGF-IGN69), raised by the RAF20 geoid height; default for Lambert-93 and the\n * CC zones */\n geoid?: boolean;\n /** Metres of a unit of z; default the vertical unit of the WKT (a US survey foot…), else that of x and y */\n verticalScale?: number;\n /** Requests a second at most: 8 by default for the Géoplateforme (data.geopf.fr allows 10), no limit elsewhere */\n requestsPerSecond?: number;\n}\n\n/** The default classes: ASPRS LAS 1.4, then IGN's LiDAR HD (64 permanent structures, 65 artefacts, 66 virtual points,\n * 67 miscellaneous buildings) */\nexport const CLASSIFICATIONS: Readonly<Record<number, Readonly<Required<ClassStyle>>>> = {\n 0: { color: '#a6a6a6', visible: true },\n 1: { color: '#c8c8c8', visible: true },\n 2: { color: '#b08458', visible: true },\n 3: { color: '#9ccc65', visible: true },\n 4: { color: '#5aa83f', visible: true },\n 5: { color: '#2e7d32', visible: true },\n 6: { color: '#e57352', visible: true },\n 7: { color: '#ff00ff', visible: false },\n 8: { color: '#ff0000', visible: true },\n 9: { color: '#3d8fd6', visible: true },\n 10: { color: '#8e6bb0', visible: true },\n 11: { color: '#7a7a7a', visible: true },\n 12: { color: '#ffe680', visible: true },\n 13: { color: '#ffff00', visible: true },\n 14: { color: '#ffc800', visible: true },\n 15: { color: '#c89600', visible: true },\n 16: { color: '#ff9632', visible: true },\n 17: { color: '#b48cc8', visible: true },\n 18: { color: '#ff00ff', visible: false },\n 64: { color: '#8c6e5a', visible: true },\n 65: { color: '#ff00ff', visible: false },\n 66: { color: '#5a6ec8', visible: true },\n 67: { color: '#e6966e', visible: true },\n};\n\n/** The default ramp of the altitudes, low to high */\nexport const ELEVATION_RAMP: Ramp = [\n [0, '#2b83ba'],\n [0.25, '#abdda4'],\n [0.5, '#ffffbf'],\n [0.75, '#fdae61'],\n [1, '#d7191c'],\n];\n\n/** The colors of the 256 classes (RGBA, alpha 0 hides one) */\nexport function classPalette(overrides: Record<number, ClassStyle> = {}): Uint8Array {\n const out = new Uint8Array(256 * 4);\n for (let code = 0; code < 256; code += 1) {\n const base = CLASSIFICATIONS[code] ?? { color: '#c8c8c8', visible: true };\n const own = overrides[code] ?? {};\n const [r = 0, g = 0, b = 0] = parseColor(own.color ?? base.color);\n out.set([r * 255, g * 255, b * 255, (own.visible ?? base.visible) ? 255 : 0], code * 4);\n }\n return out;\n}\n\n/** The section of a WKT opening with one of `keywords` (`PROJCS[…]`), from its keyword to its closing bracket */\nfunction section(wkt: string, keywords: string[]): string | undefined {\n for (const keyword of keywords) {\n const start = wkt.indexOf(`${keyword}[`);\n if (start < 0) continue;\n let depth = 0;\n for (let i = start + keyword.length; i < wkt.length; i += 1) {\n if (wkt[i] === '[') depth += 1;\n else if (wkt[i] === ']' && --depth === 0) return wkt.slice(start, i + 1);\n }\n }\n return undefined;\n}\n\n/** The EPSG code a WKT section ends with (its own `AUTHORITY`, or `ID` in WKT2), the last of its nested ones */\nfunction lastCode(part: string): number | undefined {\n const codes = [...part.matchAll(/(?:AUTHORITY|ID)\\[\\s*\"EPSG\"\\s*,\\s*\"?(\\d+)\"?\\s*\\]/g)];\n const last = codes.at(-1)?.[1];\n return last === undefined ? undefined : Number(last);\n}\n\n/** The factor of the last `UNIT` (`LENGTHUNIT` in WKT2) of a WKT section */\nfunction lastUnit(part: string | undefined): number | undefined {\n const units = [...(part ?? '').matchAll(/(?:LENGTH)?UNIT\\[\\s*\"[^\"]*\"\\s*,\\s*([\\d.eE+-]+)/g)];\n const factor = Number(units.at(-1)?.[1]);\n return Number.isFinite(factor) && factor > 0 ? factor : undefined;\n}\n\n/** What a WKT says of a CRS: its EPSG code (projected first), the metres of a unit of z */\nexport function wktCrs(wkt: string): { code: number | undefined; verticalScale: number | undefined } {\n const projected = section(wkt, ['PROJCS', 'PROJCRS']);\n const geographic = section(wkt, ['GEOGCS', 'GEOGCRS']);\n let code = lastCode(projected ?? geographic ?? '');\n if (code === undefined && /Lambert[- ]93/i.test(wkt)) code = 2154;\n const vertical = section(wkt, ['VERT_CS', 'VERTCRS']);\n const verticalScale = lastUnit(vertical ?? projected);\n return { code, verticalScale };\n}\n\n/** Whether the altitudes of a CRS are NGF-IGN69 by default: Lambert-93 and the CC zones */\nconst FRENCH = (code: number | undefined) => code === 2154 || (code !== undefined && code >= 3942 && code <= 3950);\n\n/** The CRS of a COPC file for the engine, from its WKT and the options */\nexport function pointCloudCrs(\n wkt: string | undefined,\n options: Pick<PointCloudOptions, 'crs' | 'geoid' | 'verticalScale'>,\n): PointCloudCrs {\n const parsed = wkt ? wktCrs(wkt) : { code: undefined, verticalScale: undefined };\n let crs: Crs;\n let code = parsed.code;\n if (options.crs !== undefined) {\n crs = getCrs(options.crs);\n if (typeof options.crs === 'string') code = epsgCode(options.crs) ?? code;\n } else if (code !== undefined) {\n try {\n crs = getCrs(`EPSG:${code}`);\n } catch {\n throw new Error(`the CRS of the file, EPSG:${code}, is not built in: give it as \\`crs\\` (proj4('EPSG:${code}'))`);\n }\n } else {\n throw new Error('the file names no CRS: give it as `crs`');\n }\n const inverse = (xy: Float64Array) => {\n const out = new Float64Array(xy.length);\n for (let i = 0; i + 1 < xy.length; i += 2) {\n const [lon = Number.NaN, lat = Number.NaN] = crs.inverse([xy[i] as number, xy[i + 1] as number]);\n out[i] = lon;\n out[i + 1] = lat;\n }\n return out;\n };\n return {\n inverse,\n geoid: options.geoid ?? (FRENCH(code) || /IGN69|NGF/.test(wkt ?? '')),\n verticalScale: options.verticalScale ?? parsed.verticalScale ?? 1,\n };\n}\n\n/** The style numbers of the engine (`setPointCloudStyle`) */\nfunction styleNumbers(s: PointCloudStyle, rate: number): Float64Array {\n const colors: PointColor[] = ['rgb', 'classification', 'elevation', 'intensity'];\n let edl: { strength?: number; radius?: number } | undefined;\n if (s.edl) edl = s.edl === true ? {} : s.edl;\n const [emin = Number.NaN, emax = Number.NaN] = s.elevationRange ?? [];\n const [imin = Number.NaN, imax = Number.NaN] = s.intensityRange ?? [];\n return Float64Array.of(\n s.colorBy ? colors.indexOf(s.colorBy) : -1,\n s.pointSize,\n s.maxPointSize,\n s.sizeMode === 'fixed' ? 0 : 1,\n s.shape === 'square' ? 0 : 1,\n edl ? (edl.strength ?? 1) : 0,\n edl?.radius ?? 1.4,\n emin,\n emax,\n imin,\n imax,\n s.maxScreenSpaceError,\n s.pointBudget,\n rate,\n );\n}\n\n/** A point cloud (`GeoMap.addPointCloud`): COPC or 3D Tiles points; `pickFeature` gives a COPC point's attributes */\nexport class PointCloudLayer extends Layer {\n readonly url: string;\n readonly format: 'copc' | '3dtiles';\n private style: PointCloudStyle;\n private readonly options: PointCloudOptions;\n\n /** @internal */\n constructor(map: LayerHost, options: PointCloudOptions) {\n super(map);\n // Against the page: the decoding workers fetch it, and a relative URL would be theirs\n const base = typeof document === 'undefined' ? undefined : document.baseURI;\n this.url = base ? new URL(options.url, base).href : options.url;\n this.format = options.format ?? (/\\.json(?:[?#]|$)/i.test(options.url) ? '3dtiles' : 'copc');\n this.options = options;\n const tiles = this.format === '3dtiles';\n this.style = {\n ...(options.colorBy ? { colorBy: options.colorBy } : {}),\n pointSize: options.pointSize ?? 2,\n maxPointSize: options.maxPointSize ?? 4,\n sizeMode: options.sizeMode ?? 'adaptive',\n shape: options.shape ?? 'circle',\n edl: options.edl ?? false,\n classifications: options.classifications ?? {},\n ...(options.elevationRange ? { elevationRange: options.elevationRange } : {}),\n elevationRamp: options.elevationRamp ?? ELEVATION_RAMP,\n ...(options.intensityRange ? { intensityRange: options.intensityRange } : {}),\n maxScreenSpaceError: options.maxScreenSpaceError ?? (tiles ? 16 : 1.5),\n pointBudget: options.pointBudget ?? 3_000_000,\n };\n }\n\n /** @internal Drawn by the engine with 3D Tiles (the point cloud module loads with the first one) */\n override get needsFullEngine(): boolean {\n return true;\n }\n\n /** Changes the style, the rest kept */\n setStyle(style: Partial<PointCloudStyle>): void {\n this.style = { ...this.style, ...style };\n // Kept for its creation while the engine with 3D Tiles loads\n if (this.id < 0) return;\n this.apply(this.map.engine, this.id);\n this.map.requestRender();\n }\n\n getStyle(): Readonly<PointCloudStyle> {\n return this.style;\n }\n\n /** Loading counters; undefined once removed and while the engine with 3D Tiles loads */\n stats(): PointCloudStats | Tiles3dStats | undefined {\n if (this.id < 0) return undefined;\n return this.format === '3dtiles' ? this.map.engine.tiles3dStats(this.id) : this.map.engine.pointCloudStats(this.id);\n }\n\n /** What a COPC file says of itself (points, format, CRS, center, altitudes), once its head is read */\n info(): PointCloudInfo | undefined {\n return this.id < 0 || this.format === '3dtiles' ? undefined : this.map.engine.pointCloudInfo(this.id);\n }\n\n /** @internal The point picked (`pickFeature`, 'hoverfeature'): a Point at its longitude, latitude and height, its\n * attributes as properties */\n featureAt(index: number): Feature<PointCloudPoint> | undefined {\n if (this.id < 0 || this.format === '3dtiles') return undefined;\n const point = this.map.engine.pointCloudPoint(this.id, index);\n if (!point) return undefined;\n return {\n type: 'Feature',\n geometry: { type: 'Point', coordinates: [...point.lonLat, point.height] },\n properties: point,\n };\n }\n\n private apply(engine: Engine, id: number): void {\n const s = this.style;\n if (this.format === '3dtiles') {\n engine.setTiles3dStyle(id, s.maxScreenSpaceError, 1, s.pointSize, new Float32Array());\n return;\n }\n const rate = this.options.requestsPerSecond ?? (/^https?:\\/\\/data\\.geopf\\.fr\\//.test(this.url) ? 8 : 0);\n engine.setPointCloudStyle(\n id,\n styleNumbers(s, rate),\n classPalette(s.classifications),\n rampTexels(s.elevationRamp).rgba,\n );\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id =\n this.format === '3dtiles'\n ? engine.addTiles3d(this.url, this.style.maxScreenSpaceError)\n : engine.addPointCloud(this.url, (wkt) => pointCloudCrs(wkt, this.options));\n this.apply(engine, id);\n return id;\n }\n}\n"]}
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/** Messages between the main thread and the decoding workers */
|
|
2
2
|
import type { DecoderUrls } from './decoders.ts';
|
|
3
|
+
import type { HeaderRules } from './requests.ts';
|
|
3
4
|
import type { DecodedTile, TextureFormats } from './wasm/isard.js';
|
|
4
|
-
export type WorkerRequest =
|
|
5
|
+
export type WorkerRequest =
|
|
6
|
+
/** The page's request headers (`setRequestHeaders`) */
|
|
7
|
+
{
|
|
8
|
+
type: 'headers';
|
|
9
|
+
rules: HeaderRules;
|
|
10
|
+
} | {
|
|
5
11
|
type: 'init';
|
|
6
12
|
module: WebAssembly.Module;
|
|
7
13
|
decoders: DecoderUrls;
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"","sourcesContent":["/** Messages between the main thread and the decoding workers */\nimport type { DecoderUrls } from './decoders.ts';\nimport type { DecodedTile, TextureFormats } from './wasm/isard.js';\n\nexport type WorkerRequest =\n | {\n type: 'init';\n module: WebAssembly.Module;\n decoders: DecoderUrls;\n formats: TextureFormats;\n /** URL of the point cloud module (`isard_points_bg.wasm`), loaded with the first COPC chunk */\n points: string;\n }\n | {\n type: 'load';\n id: number;\n url: string;\n transform: Float64Array;\n yUp: boolean;\n reload: boolean;\n priority?: 'high' | 'low';\n }\n | {\n type: 'points';\n id: number;\n url: string;\n offset: number;\n size: number;\n laz: Uint8Array;\n layout: Float64Array;\n grid: Float64Array;\n count: number;\n priority?: 'high' | 'low';\n }\n | { type: 'abort'; id: number };\n\nexport type WorkerReply =\n | { type: 'tile'; id: number; tile: DecodedTile }\n | { type: 'points'; id: number; vertices: Uint8Array<ArrayBuffer> }\n | { type: 'error'; id: number; error: string; aborted: boolean };\n"]}
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"","sourcesContent":["/** Messages between the main thread and the decoding workers */\nimport type { DecoderUrls } from './decoders.ts';\nimport type { HeaderRules } from './requests.ts';\nimport type { DecodedTile, TextureFormats } from './wasm/isard.js';\n\nexport type WorkerRequest =\n /** The page's request headers (`setRequestHeaders`) */\n | { type: 'headers'; rules: HeaderRules }\n | {\n type: 'init';\n module: WebAssembly.Module;\n decoders: DecoderUrls;\n formats: TextureFormats;\n /** URL of the point cloud module (`isard_points_bg.wasm`), loaded with the first COPC chunk */\n points: string;\n }\n | {\n type: 'load';\n id: number;\n url: string;\n transform: Float64Array;\n yUp: boolean;\n reload: boolean;\n priority?: 'high' | 'low';\n }\n | {\n type: 'points';\n id: number;\n url: string;\n offset: number;\n size: number;\n laz: Uint8Array;\n layout: Float64Array;\n grid: Float64Array;\n count: number;\n priority?: 'high' | 'low';\n }\n | { type: 'abort'; id: number };\n\nexport type WorkerReply =\n | { type: 'tile'; id: number; tile: DecodedTile }\n | { type: 'points'; id: number; vertices: Uint8Array<ArrayBuffer> }\n | { type: 'error'; id: number; error: string; aborted: boolean };\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headers added to the requests of the page by URL prefix: an access token for private sources (a Géoplateforme
|
|
3
|
+
* private stream, a server behind single sign-on), on every request isard makes, from the page, its workers (vector
|
|
4
|
+
* tiles, 3D Tiles and point clouds) and its engine (raster tiles, tilesets): `setRequestHeaders(prefix, headers)`,
|
|
5
|
+
* again with a new token when it is renewed. The rules of a URL are merged, the longest prefix last (it wins).
|
|
6
|
+
*/
|
|
7
|
+
/** Rules: a URL prefix and its headers, the shortest prefix first */
|
|
8
|
+
export type HeaderRules = [prefix: string, headers: Record<string, string>][];
|
|
9
|
+
/**
|
|
10
|
+
* Adds `headers` to every request isard makes to a URL starting with `prefix` (in the page and its workers), or with
|
|
11
|
+
* no headers, stops: `setRequestHeaders('https://data.geopf.fr/private/', { Authorization: 'Bearer …' })`. The
|
|
12
|
+
* server must allow these headers (CORS). For the whole page: every map, the ones to come too
|
|
13
|
+
*/
|
|
14
|
+
export declare function setRequestHeaders(prefix: string, headers?: Record<string, string>): void;
|