astro-viewer 2.0.0 → 3.0.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.
Files changed (40) hide show
  1. package/dist/astroviewer.cjs +18851 -17175
  2. package/dist/astroviewer.js +1 -1
  3. package/dist/astroviewer.min.js +1 -1
  4. package/lib-esm/AstroSphere.d.ts +9 -0
  5. package/lib-esm/AstroSphere.js +63 -9
  6. package/lib-esm/AstroViewer.d.ts +18 -0
  7. package/lib-esm/AstroViewer.js +46 -0
  8. package/lib-esm/index.d.ts +5 -0
  9. package/lib-esm/index.js +4 -0
  10. package/lib-esm/model/AbstractSkyEntity.d.ts +10 -0
  11. package/lib-esm/model/earth/XYZAncestorMeshCache.d.ts +10 -0
  12. package/lib-esm/model/earth/XYZAncestorMeshCache.js +31 -0
  13. package/lib-esm/model/earth/XYZLayer.d.ts +31 -0
  14. package/lib-esm/model/earth/XYZLayer.js +231 -0
  15. package/lib-esm/model/earth/XYZMeshBuilder.d.ts +6 -0
  16. package/lib-esm/model/earth/XYZMeshBuilder.js +97 -0
  17. package/lib-esm/model/earth/XYZTile.d.ts +39 -0
  18. package/lib-esm/model/earth/XYZTile.js +187 -0
  19. package/lib-esm/model/earth/XYZTileBuffer.d.ts +39 -0
  20. package/lib-esm/model/earth/XYZTileBuffer.js +149 -0
  21. package/lib-esm/model/earth/XYZTileProvider.d.ts +29 -0
  22. package/lib-esm/model/earth/XYZTileProvider.js +187 -0
  23. package/lib-esm/model/earth/XYZTileRequestScheduler.d.ts +25 -0
  24. package/lib-esm/model/earth/XYZTileRequestScheduler.js +161 -0
  25. package/lib-esm/model/earth/XYZVisibleTilesManager.d.ts +30 -0
  26. package/lib-esm/model/earth/XYZVisibleTilesManager.js +208 -0
  27. package/lib-esm/model/earth/types.d.ts +87 -0
  28. package/lib-esm/model/earth/types.js +1 -0
  29. package/lib-esm/model/earth/wmts/WMTSAdapter.d.ts +11 -0
  30. package/lib-esm/model/earth/wmts/WMTSAdapter.js +85 -0
  31. package/lib-esm/model/earth/wmts/types.d.ts +1 -0
  32. package/lib-esm/model/earth/wmts/types.js +1 -0
  33. package/lib-esm/model/footprints/FootprintSetGL.js +1 -1
  34. package/lib-esm/model/terra/TerraFootprintSetGL.d.ts +4 -0
  35. package/lib-esm/model/terra/TerraFootprintSetGL.js +4 -0
  36. package/lib-esm/model/terra/TerraPointSetGL.d.ts +4 -0
  37. package/lib-esm/model/terra/TerraPointSetGL.js +4 -0
  38. package/lib-esm/shader/XYZShaderProgram.d.ts +20 -0
  39. package/lib-esm/shader/XYZShaderProgram.js +88 -0
  40. package/package.json +1 -2
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { WMTSLayerConfig, XYZLayerConfig, XYZTileCoord } from '../types.js';
2
+ export declare class WMTSAdapter {
3
+ private _config;
4
+ constructor(config: WMTSLayerConfig);
5
+ toXYZLayerConfig(): XYZLayerConfig;
6
+ private getInferredMaxZoom;
7
+ getTileUrl(tile: XYZTileCoord): string;
8
+ private buildRestUrl;
9
+ private buildKvpUrl;
10
+ private getCommonTokenValues;
11
+ }
@@ -0,0 +1,85 @@
1
+ function replaceTokens(template, values) {
2
+ return Object.entries(values).reduce((result, [key, value]) => result.replace(new RegExp(`\\{${key}\\}`, 'g'), value), template);
3
+ }
4
+ export class WMTSAdapter {
5
+ _config;
6
+ constructor(config) {
7
+ this._config = config;
8
+ }
9
+ toXYZLayerConfig() {
10
+ const inferredMaxZoom = this.getInferredMaxZoom();
11
+ return {
12
+ urlTemplate: this._config.urlTemplate ?? this._config.baseUrl,
13
+ minZoom: this._config.minZoom,
14
+ maxZoom: inferredMaxZoom,
15
+ segmentsPerSide: this._config.segmentsPerSide,
16
+ tileSize: this._config.tileSize,
17
+ maxCachedTiles: this._config.maxCachedTiles,
18
+ subdomains: this._config.subdomains,
19
+ attribution: this._config.attribution,
20
+ flipY: this._config.flipY,
21
+ urlResolver: (tile) => this.getTileUrl(tile),
22
+ };
23
+ }
24
+ getInferredMaxZoom() {
25
+ const matrixLabelCount = this._config.matrixLabels?.length ?? 0;
26
+ const maxFromLabels = matrixLabelCount > 0 ? matrixLabelCount - 1 : undefined;
27
+ if (maxFromLabels == null) {
28
+ return this._config.maxZoom;
29
+ }
30
+ if (this._config.maxZoom == null) {
31
+ return maxFromLabels;
32
+ }
33
+ return Math.min(this._config.maxZoom, maxFromLabels);
34
+ }
35
+ getTileUrl(tile) {
36
+ return this._config.requestEncoding === 'rest'
37
+ ? this.buildRestUrl(tile)
38
+ : this.buildKvpUrl(tile);
39
+ }
40
+ buildRestUrl(tile) {
41
+ const template = this._config.urlTemplate ?? this._config.baseUrl;
42
+ const values = this.getCommonTokenValues(tile);
43
+ const resolved = replaceTokens(template, values);
44
+ return resolved.replace(/(?<!:)\/{2,}/g, '/');
45
+ }
46
+ buildKvpUrl(tile) {
47
+ const baseUrl = new URL(this._config.baseUrl);
48
+ const values = this.getCommonTokenValues(tile);
49
+ const params = baseUrl.searchParams;
50
+ params.set('SERVICE', 'WMTS');
51
+ params.set('REQUEST', 'GetTile');
52
+ params.set('VERSION', this._config.version ?? '1.0.0');
53
+ params.set('LAYER', this._config.layer);
54
+ params.set('STYLE', this._config.style ?? 'default');
55
+ params.set('FORMAT', this._config.format ?? 'image/png');
56
+ params.set('TILEMATRIXSET', this._config.tileMatrixSet);
57
+ params.set('TILEMATRIX', values.TileMatrix);
58
+ params.set('TILEROW', values.TileRow);
59
+ params.set('TILECOL', values.TileCol);
60
+ for (const [key, value] of Object.entries(this._config.dimensions ?? {})) {
61
+ params.set(key, value);
62
+ }
63
+ return baseUrl.toString();
64
+ }
65
+ getCommonTokenValues(tile) {
66
+ const dim = 2 ** tile.z;
67
+ const effectiveY = this._config.flipY ? dim - 1 - tile.y : tile.y;
68
+ const matrixLabel = this._config.matrixLabels?.[tile.z] ?? String(tile.z);
69
+ const tileFormat = this._config.format ?? 'image/png';
70
+ const tileFormatExtension = tileFormat.replace(/^image\//, '');
71
+ return {
72
+ Layer: this._config.layer,
73
+ Style: this._config.style ?? 'default',
74
+ Time: this._config.time ?? '',
75
+ TileMatrixSet: this._config.tileMatrixSet,
76
+ TileMatrix: matrixLabel,
77
+ TileRow: String(effectiveY),
78
+ TileCol: String(tile.x),
79
+ Format: tileFormatExtension,
80
+ TileFormat: tileFormat,
81
+ TileFormatExtension: tileFormatExtension,
82
+ ...Object.fromEntries(Object.entries(this._config.dimensions ?? {}).map(([key, value]) => [key, value])),
83
+ };
84
+ }
85
+ }
@@ -0,0 +1 @@
1
+ export type {};
@@ -0,0 +1 @@
1
+ export {};
@@ -126,7 +126,7 @@ export class FootprintSetGL {
126
126
  throw new Error("geomColumn or its index is undefined in footprintsetProps");
127
127
  }
128
128
  for (let j = 0; j < in_data.length; j++) {
129
- if (in_data[j][0] !== null) {
129
+ if (in_data[j][geomDataIndex] !== null) {
130
130
  const footprint = new Footprint(in_data[j][geomDataIndex], in_data[j]);
131
131
  if (footprint._valid) {
132
132
  this.addFootprint(footprint);
@@ -0,0 +1,4 @@
1
+ import { FootprintSetGL } from '../footprints/FootprintSetGL.js';
2
+ export declare class TerraFootprintSetGL extends FootprintSetGL {
3
+ _kind: string;
4
+ }
@@ -0,0 +1,4 @@
1
+ import { FootprintSetGL } from '../footprints/FootprintSetGL.js';
2
+ export class TerraFootprintSetGL extends FootprintSetGL {
3
+ _kind = 'TerraFootprintSetGL';
4
+ }
@@ -0,0 +1,4 @@
1
+ import { CatalogueGL } from '../catalogues/CatalogueGL.js';
2
+ export declare class TerraPointSetGL extends CatalogueGL {
3
+ _kind: string;
4
+ }
@@ -0,0 +1,4 @@
1
+ import { CatalogueGL } from '../catalogues/CatalogueGL.js';
2
+ export class TerraPointSetGL extends CatalogueGL {
3
+ _kind = 'TerraPointSetGL';
4
+ }
@@ -0,0 +1,20 @@
1
+ type XYZLocations = {
2
+ pMatrix: WebGLUniformLocation | null;
3
+ mMatrix: WebGLUniformLocation | null;
4
+ vMatrix: WebGLUniformLocation | null;
5
+ sampler: WebGLUniformLocation | null;
6
+ vertexPositionAttribute: number;
7
+ textureCoordAttribute: number;
8
+ };
9
+ export declare class XYZShaderProgram {
10
+ readonly locations: XYZLocations;
11
+ private _webgl;
12
+ private _shaderProgram?;
13
+ constructor(webgl: WebGL2RenderingContext);
14
+ get shaderProgram(): WebGLProgram;
15
+ enableProgram(): void;
16
+ enableShaders(pMatrix: Float32Array, vMatrix: Float32Array, mMatrix: Float32Array): void;
17
+ private initShaders;
18
+ private compileShader;
19
+ }
20
+ export {};
@@ -0,0 +1,88 @@
1
+ export class XYZShaderProgram {
2
+ locations;
3
+ _webgl;
4
+ _shaderProgram;
5
+ constructor(webgl) {
6
+ this._webgl = webgl;
7
+ this.locations = {
8
+ pMatrix: null,
9
+ mMatrix: null,
10
+ vMatrix: null,
11
+ sampler: null,
12
+ vertexPositionAttribute: -1,
13
+ textureCoordAttribute: -1,
14
+ };
15
+ }
16
+ get shaderProgram() {
17
+ const gl = this._webgl;
18
+ if (!this._shaderProgram) {
19
+ const program = gl.createProgram();
20
+ if (!program) {
21
+ throw new Error('Could not create XYZ shader program');
22
+ }
23
+ this._shaderProgram = program;
24
+ this.initShaders();
25
+ }
26
+ gl.useProgram(this._shaderProgram);
27
+ return this._shaderProgram;
28
+ }
29
+ enableProgram() {
30
+ this._webgl.useProgram(this.shaderProgram);
31
+ }
32
+ enableShaders(pMatrix, vMatrix, mMatrix) {
33
+ const gl = this._webgl;
34
+ const program = this.shaderProgram;
35
+ gl.useProgram(program);
36
+ this.locations.pMatrix = gl.getUniformLocation(program, 'uPMatrix');
37
+ this.locations.mMatrix = gl.getUniformLocation(program, 'uMMatrix');
38
+ this.locations.vMatrix = gl.getUniformLocation(program, 'uVMatrix');
39
+ this.locations.sampler = gl.getUniformLocation(program, 'uSampler');
40
+ this.locations.vertexPositionAttribute = gl.getAttribLocation(program, 'aVertexPosition');
41
+ this.locations.textureCoordAttribute = gl.getAttribLocation(program, 'aTextureCoord');
42
+ gl.uniformMatrix4fv(this.locations.pMatrix, false, pMatrix);
43
+ gl.uniformMatrix4fv(this.locations.vMatrix, false, vMatrix);
44
+ gl.uniformMatrix4fv(this.locations.mMatrix, false, mMatrix);
45
+ gl.uniform1i(this.locations.sampler, 0);
46
+ }
47
+ initShaders() {
48
+ const gl = this._webgl;
49
+ const vertexShader = this.compileShader(gl.VERTEX_SHADER, `#version 300 es
50
+ in vec3 aVertexPosition;
51
+ in vec2 aTextureCoord;
52
+ uniform mat4 uPMatrix;
53
+ uniform mat4 uVMatrix;
54
+ uniform mat4 uMMatrix;
55
+ out vec2 vTextureCoord;
56
+ void main(void) {
57
+ vTextureCoord = aTextureCoord;
58
+ gl_Position = uPMatrix * uVMatrix * uMMatrix * vec4(aVertexPosition, 1.0);
59
+ }`);
60
+ const fragmentShader = this.compileShader(gl.FRAGMENT_SHADER, `#version 300 es
61
+ precision mediump float;
62
+ in vec2 vTextureCoord;
63
+ uniform sampler2D uSampler;
64
+ out vec4 outColor;
65
+ void main(void) {
66
+ outColor = texture(uSampler, vTextureCoord);
67
+ }`);
68
+ gl.attachShader(this._shaderProgram, vertexShader);
69
+ gl.attachShader(this._shaderProgram, fragmentShader);
70
+ gl.linkProgram(this._shaderProgram);
71
+ if (!gl.getProgramParameter(this._shaderProgram, gl.LINK_STATUS)) {
72
+ throw new Error(gl.getProgramInfoLog(this._shaderProgram) || 'Could not initialise XYZ shaders');
73
+ }
74
+ }
75
+ compileShader(type, source) {
76
+ const gl = this._webgl;
77
+ const shader = gl.createShader(type);
78
+ if (!shader) {
79
+ throw new Error('Could not create XYZ shader');
80
+ }
81
+ gl.shaderSource(shader, source);
82
+ gl.compileShader(shader);
83
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
84
+ throw new Error(gl.getShaderInfoLog(shader) || 'XYZ shader compile error');
85
+ }
86
+ return shader;
87
+ }
88
+ }
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "astro-viewer",
3
3
  "description": "Astrobrowser 3d engine.",
4
-
5
- "version": "2.0.0",
4
+ "version": "3.0.0",
6
5
  "keywords": [
7
6
  "HiPS",
8
7
  "HiPS cutout",