ol-stac 1.2.0 → 1.4.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/README.md CHANGED
@@ -15,7 +15,21 @@ Explore the examples to get started with some more code:
15
15
  Dig into the API documentation for all details:
16
16
  <https://ol-stac.moregeo.it/en/latest/apidoc/>
17
17
 
18
- **ol-stac requires OpenLayers version >=7.5.2**
18
+ ### OpenLayers versions
19
+
20
+ ol-stac works best with OpenLayers >= 10.9.0.
21
+
22
+ It should work with older versions >= 9.0.0, but certain features will be unavailable
23
+ or work less reliably, for example:
24
+
25
+ - Better per-band visualization of GeoTiff files (requires >= 10.9.0)
26
+ - Automatic loading of missing projections for GeoTiff files (EPSG code retrieval requires >= 10.0.0, other projection codes require >= 10.8.0)
27
+ - GeoZARR support (requires >= 10.8.0)
28
+
29
+ Generally, we highly recommend to use OpenLayers >= 10.9.0.
30
+ If you use an older version, please ensure it works well for your usecases.
31
+
32
+ Older versions of ol-stac (< 1.3.0) support OpenLayers >= 7.5.2.
19
33
 
20
34
  ## Sponsors
21
35
 
package/layer/STAC.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  export default STACLayer;
2
2
  export type Extent = import("ol/extent.js").Extent;
3
3
  export type Layer = import("ol/layer/Layer.js").default;
4
+ export type APICollection = any;
4
5
  export type Link = any;
6
+ export type STAC = any;
7
+ export type STACObject = any;
5
8
  export type Map = import("ol/Map.js").default;
6
9
  export type Style = import('ol/style/Style.js').default;
7
10
  export type SourceOptions = import('../source/type.js').SourceOptions;
@@ -35,9 +38,9 @@ export type Options = {
35
38
  */
36
39
  assets?: any[] | null | undefined;
37
40
  /**
38
- * The (one-based) bands to show.
41
+ * The bands to show. One-based index of the band, or the name of the band.
39
42
  */
40
- bands?: number[] | undefined;
43
+ bands?: (string | number)[] | undefined;
41
44
  /**
42
45
  * Optional function that can be used to configure the underlying sources. The function can do any additional work
43
46
  * and return the completed options or a promise for the same. The function will be called with the current source options
@@ -64,7 +67,7 @@ export type Options = {
64
67
  */
65
68
  displayPreview?: boolean | undefined;
66
69
  /**
67
- * Allow to display COGs and, if `displayGeoTiffByDefault` is enabled, GeoTiffs,
70
+ * Allow to display COGs/WOZs and, if `displayGeoTiffByDefault` is enabled, GeoTiffs,
68
71
  * usually an asset with role `overview` or `visual`.
69
72
  */
70
73
  displayOverview?: boolean | undefined;
@@ -77,6 +80,10 @@ export type Options = {
77
80
  * To disable the functionality set this to `false`.
78
81
  */
79
82
  displayWebMapLink?: string | boolean | any[] | undefined;
83
+ /**
84
+ * The style for GeoTIFF and GeoZarr layers (WebGLTileLayer style).
85
+ */
86
+ style?: import("ol/layer/WebGLTile.js").Style | null | undefined;
80
87
  /**
81
88
  * The style for the overall bounds / footprint.
82
89
  */
@@ -164,9 +171,18 @@ export type Options = {
164
171
  /**
165
172
  * @typedef {import("ol/layer/Layer.js").default} Layer
166
173
  */
174
+ /**
175
+ * @typedef {import('stac-js').APICollection} APICollection
176
+ */
167
177
  /**
168
178
  * @typedef {import("stac-js").Link} Link
169
179
  */
180
+ /**
181
+ * @typedef {import('stac-js').STAC} STAC
182
+ */
183
+ /**
184
+ * @typedef {import('stac-js').STACObject} STACObject
185
+ */
170
186
  /**
171
187
  * @typedef {import("ol/Map.js").default} Map
172
188
  */
@@ -191,7 +207,7 @@ export type Options = {
191
207
  * only for STAC Items and Collections.
192
208
  * This can be an array of strings corresponding to asset keys or Asset objects.
193
209
  * null shows the default asset, an empty array shows no asset.
194
- * @property {Array<number>} [bands] The (one-based) bands to show.
210
+ * @property {Array<number|string>} [bands] The bands to show. One-based index of the band, or the name of the band.
195
211
  * @property {function(SourceType, SourceOptions, (Asset|Link)):(SourceOptions|Promise<SourceOptions>)} [getSourceOptions]
196
212
  * Optional function that can be used to configure the underlying sources. The function can do any additional work
197
213
  * and return the completed options or a promise for the same. The function will be called with the current source options
@@ -206,7 +222,7 @@ export type Options = {
206
222
  * i.e. assets with any of the roles `thumbnail`, `overview`, or a link with relation type `preview`.
207
223
  * The previews are usually not covering the full extents and as such may be placed incorrectly on the map.
208
224
  * For performance reasons, it is recommended to enable this option if you pass in STAC API Items instead of `displayOverview`.
209
- * @property {boolean} [displayOverview=true] Allow to display COGs and, if `displayGeoTiffByDefault` is enabled, GeoTiffs,
225
+ * @property {boolean} [displayOverview=true] Allow to display COGs/WOZs and, if `displayGeoTiffByDefault` is enabled, GeoTiffs,
210
226
  * usually an asset with role `overview` or `visual`.
211
227
  * @property {string|boolean|Array<Link|string>} [displayWebMapLink=false] Allow to display a layer
212
228
  * based on the information provided through the web map links extension.
@@ -214,6 +230,7 @@ export type Options = {
214
230
  * If set to true or to a specific type of web map link (`pmtiles`, `tilejson`, `wms`, `wmts`, `xyz`),
215
231
  * it lets this library choose a web map link to show, but only if no other data is shown.
216
232
  * To disable the functionality set this to `false`.
233
+ * @property {import("ol/layer/WebGLTile.js").Style|null} [style=null] The style for GeoTIFF and GeoZarr layers (WebGLTileLayer style).
217
234
  * @property {Style} [boundsStyle] The style for the overall bounds / footprint.
218
235
  * @property {Style} [collectionStyle] The style for individual children in a list of STAC Items or Collections.
219
236
  * @property {null|string} [crossOrigin] For thumbnails: The `crossOrigin` attribute for loaded images / tiles.
@@ -283,7 +300,7 @@ declare class STACLayer extends LayerGroup {
283
300
  */
284
301
  private assets_;
285
302
  /**
286
- * @type {Array<number>}
303
+ * @type {Array<number|string>}
287
304
  * @private
288
305
  */
289
306
  private bands_;
@@ -326,6 +343,11 @@ declare class STACLayer extends LayerGroup {
326
343
  * @private
327
344
  */
328
345
  private useTileLayerAsFallback_;
346
+ /**
347
+ * @type {import("ol/layer/WebGLTile.js").Style|null}
348
+ * @private
349
+ */
350
+ private style_;
329
351
  /**
330
352
  * @type {Style}
331
353
  * @private
@@ -389,7 +411,7 @@ declare class STACLayer extends LayerGroup {
389
411
  * @param {string} url The url to the data.
390
412
  * @param {APICollection|Object|Array<STAC>|string|null} children The child STAC entities to show.
391
413
  * @param {Array<Asset|string>|null} assets The assets to show.
392
- * @param {Array<number>} bands The (one-based) bands to show.
414
+ * @param {Array<number|string>} bands The bands to show.
393
415
  * @private
394
416
  */
395
417
  private configure_;
@@ -452,7 +474,7 @@ declare class STACLayer extends LayerGroup {
452
474
  private addTileLayerForImagery_;
453
475
  /**
454
476
  * @param {Layer|LayerGroup} [layer] A Layer to add to the LayerGroup
455
- * @param {import("stac-js").STACObject} [data] The STAC object, can be any class exposed by stac-js
477
+ * @param {STACObject} [data] The STAC object, can be any class exposed by stac-js
456
478
  * @param {number} [zIndex] The z-index for the layer
457
479
  * @private
458
480
  */
@@ -485,6 +507,7 @@ declare class STACLayer extends LayerGroup {
485
507
  * @private
486
508
  */
487
509
  private addLabelExtension_;
510
+ addGeoZarr_(asset: any): Promise<WebGLTileLayer | TileLayer<import("ol/source/Tile.js").default<import("ol/Tile.js").default>> | undefined>;
488
511
  /**
489
512
  * Update the layers shown manually based on the current configuration.
490
513
  * Usually this doesn't need to be called manually.
@@ -505,6 +528,12 @@ declare class STACLayer extends LayerGroup {
505
528
  * @api
506
529
  */
507
530
  getWebMapLinks(): Array<Link>;
531
+ /**
532
+ * Set the style for GeoTIFF and GeoZarr layers (WebGLTileLayer style).
533
+ * @param {import("ol/layer/WebGLTile.js").Style|null} style The style to apply.
534
+ * @api
535
+ */
536
+ setStyle(style: import("ol/layer/WebGLTile.js").Style | null): void;
508
537
  /**
509
538
  * Update the assets to be rendered.
510
539
  * @param {Array<string|Asset>|null} assets The assets to show.
@@ -571,4 +600,6 @@ declare class STACLayer extends LayerGroup {
571
600
  import SourceType from '../source/type.js';
572
601
  import LayerGroup from 'ol/layer/Group.js';
573
602
  import VectorLayer from 'ol/layer/Vector.js';
603
+ import WebGLTileLayer from 'ol/layer/WebGLTile.js';
604
+ import TileLayer from 'ol/layer/Tile.js';
574
605
  //# sourceMappingURL=STAC.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"STAC.d.ts","sourceRoot":"","sources":["../../../src/ol/layer/STAC.js"],"names":[],"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;;;;OAIG;IACH,oBASC;IAED;;;;;;;;OAQG;IACH,4BAgBC;IAED;;;;;OAKG;IACH,2BAkDC;IAED,4IAyCC;IAED;;;;;;OAMG;IACH,uDAyGC;IAED;;;;OAIG;IACH,iBAHY,OAAO,CASlB;IAED;;;;OAIG;IACH,kBAHY,MAAM,IAAI,CAAC,CAwCtB;IAED;;;;OAIG;IACH,gBAHW,OAAO,uBAAuB,EAAE,KAAK,GAAC,IAAI,QAUpD;IAED;;;;;;OAMG;IACH,kBALW,MAAM,MAAM,QAAM,CAAC,GAAC,IAAI,oDA2BlC;IAED;;;;;;;;;;OAUG;IACH,oBANW,aAAa,SAAQ,MAAM,IAAI,MAAO,CAAC,GAAC,IAAI,0FAiCtD;IAED;;;;;OAKG;IACH,WAHY,IAAI,QAAM,CAKrB;IAED;;;;;OAKG;IACH,eAHY,MAAM,IAAI,CAAC,CAKtB;IAED;;;;;OAKG;IACH,aAHY,YAAY,CAKvB;IA6CD,mDAOC;IAED;;;;;OAKG;IACH,mBAHY,MAAM,MAAM,CAAC,CAaxB;IAED;;;OAGG;IACH,aAFY,UAAU,GAAC,IAAI,CAI1B;IAED;;;;;;OAMG;IACH,6BAYC;CACF;uBAz1CsB,mBAAmB;uBA3BnB,mBAAmB;wBAGlB,oBAAoB;2BAEjB,uBAAuB;sBAH5B,kBAAkB"}
package/layer/STAC.js CHANGED
@@ -11,7 +11,7 @@ import VectorLayer from 'ol/layer/Vector.js';
11
11
  import VectorTileLayer from 'ol/layer/VectorTile.js';
12
12
  import WebGLTileLayer from 'ol/layer/WebGLTile.js';
13
13
  import { transformExtent } from 'ol/proj.js';
14
- // import GeoTIFF from 'ol/source/GeoTIFF.js';
14
+ import GeoTIFF from 'ol/source/GeoTIFF.js';
15
15
  import StaticImage from 'ol/source/ImageStatic.js';
16
16
  import TileJSON from 'ol/source/TileJSON.js';
17
17
  import WMS from 'ol/source/TileWMS.js';
@@ -21,24 +21,32 @@ import WMTS, { optionsFromCapabilities } from 'ol/source/WMTS.js';
21
21
  import XYZ from 'ol/source/XYZ.js';
22
22
  import { PMTilesRasterSource, PMTilesVectorSource } from 'ol-pmtiles';
23
23
  import * as pmtiles from 'pmtiles';
24
- import create, { APICollection, Asset, CollectionCollection, Item, ItemCollection, STAC, } from 'stac-js';
24
+ import create, { Asset } from 'stac-js';
25
25
  import { fixGeoJson, toGeoJSON, unionBoundingBox } from 'stac-js/src/geo.js';
26
- import { geojsonMediaType } from 'stac-js/src/mediatypes.js';
26
+ import { geojsonMediaType, geotiffMediaTypes, wozMediaTypes, } from 'stac-js/src/mediatypes.js';
27
27
  import { isObject } from 'stac-js/src/utils.js';
28
28
  import ErrorEvent from '../events/ErrorEvent.js';
29
- // todo: temporary fix for https://github.com/openlayers/openlayers/issues/17153
30
- import GeoTIFF from '../source/GeoTIFF.js';
29
+ import { getProjection } from '../proj.js';
31
30
  import SourceType from '../source/type.js';
32
- import { LABEL_EXTENSION, defaultBoundsStyle, defaultCollectionStyle, getBoundsStyle, getClassificationStyle, getGeoTiffSourceInfoFromAsset, getProjection, getSpecificWebMapUrl, isScalar, } from '../util.js';
31
+ import { LABEL_EXTENSION, defaultBoundsStyle, defaultCollectionStyle, getBoundsStyle, getClassificationStyle, getGeoTiffSourceInfoFromAsset, getGeoZarrSourceOptionsFromAsset, getSpecificWebMapUrl, isScalar, } from '../util.js';
33
32
  /**
34
33
  * @typedef {import("ol/extent.js").Extent} Extent
35
34
  */
36
35
  /**
37
36
  * @typedef {import("ol/layer/Layer.js").default} Layer
38
37
  */
38
+ /**
39
+ * @typedef {import('stac-js').APICollection} APICollection
40
+ */
39
41
  /**
40
42
  * @typedef {import("stac-js").Link} Link
41
43
  */
44
+ /**
45
+ * @typedef {import('stac-js').STAC} STAC
46
+ */
47
+ /**
48
+ * @typedef {import('stac-js').STACObject} STACObject
49
+ */
42
50
  /**
43
51
  * @typedef {import("ol/Map.js").default} Map
44
52
  */
@@ -63,7 +71,7 @@ import { LABEL_EXTENSION, defaultBoundsStyle, defaultCollectionStyle, getBoundsS
63
71
  * only for STAC Items and Collections.
64
72
  * This can be an array of strings corresponding to asset keys or Asset objects.
65
73
  * null shows the default asset, an empty array shows no asset.
66
- * @property {Array<number>} [bands] The (one-based) bands to show.
74
+ * @property {Array<number|string>} [bands] The bands to show. One-based index of the band, or the name of the band.
67
75
  * @property {function(SourceType, SourceOptions, (Asset|Link)):(SourceOptions|Promise<SourceOptions>)} [getSourceOptions]
68
76
  * Optional function that can be used to configure the underlying sources. The function can do any additional work
69
77
  * and return the completed options or a promise for the same. The function will be called with the current source options
@@ -78,7 +86,7 @@ import { LABEL_EXTENSION, defaultBoundsStyle, defaultCollectionStyle, getBoundsS
78
86
  * i.e. assets with any of the roles `thumbnail`, `overview`, or a link with relation type `preview`.
79
87
  * The previews are usually not covering the full extents and as such may be placed incorrectly on the map.
80
88
  * For performance reasons, it is recommended to enable this option if you pass in STAC API Items instead of `displayOverview`.
81
- * @property {boolean} [displayOverview=true] Allow to display COGs and, if `displayGeoTiffByDefault` is enabled, GeoTiffs,
89
+ * @property {boolean} [displayOverview=true] Allow to display COGs/WOZs and, if `displayGeoTiffByDefault` is enabled, GeoTiffs,
82
90
  * usually an asset with role `overview` or `visual`.
83
91
  * @property {string|boolean|Array<Link|string>} [displayWebMapLink=false] Allow to display a layer
84
92
  * based on the information provided through the web map links extension.
@@ -86,6 +94,7 @@ import { LABEL_EXTENSION, defaultBoundsStyle, defaultCollectionStyle, getBoundsS
86
94
  * If set to true or to a specific type of web map link (`pmtiles`, `tilejson`, `wms`, `wmts`, `xyz`),
87
95
  * it lets this library choose a web map link to show, but only if no other data is shown.
88
96
  * To disable the functionality set this to `false`.
97
+ * @property {import("ol/layer/WebGLTile.js").Style|null} [style=null] The style for GeoTIFF and GeoZarr layers (WebGLTileLayer style).
89
98
  * @property {Style} [boundsStyle] The style for the overall bounds / footprint.
90
99
  * @property {Style} [collectionStyle] The style for individual children in a list of STAC Items or Collections.
91
100
  * @property {null|string} [crossOrigin] For thumbnails: The `crossOrigin` attribute for loaded images / tiles.
@@ -167,7 +176,7 @@ class STACLayer extends LayerGroup {
167
176
  */
168
177
  this.assets_ = null;
169
178
  /**
170
- * @type {Array<number>}
179
+ * @type {Array<number|string>}
171
180
  * @private
172
181
  */
173
182
  this.bands_ = [];
@@ -210,6 +219,11 @@ class STACLayer extends LayerGroup {
210
219
  * @private
211
220
  */
212
221
  this.useTileLayerAsFallback_ = options.useTileLayerAsFallback || false;
222
+ /**
223
+ * @type {import("ol/layer/WebGLTile.js").Style|null}
224
+ * @private
225
+ */
226
+ this.style_ = options.style || null;
213
227
  /**
214
228
  * @type {Style}
215
229
  * @private
@@ -296,12 +310,11 @@ class STACLayer extends LayerGroup {
296
310
  * @api
297
311
  */
298
312
  isEmpty() {
299
- var _a;
300
313
  const count = this.getLayers().getLength();
301
314
  if (count > 1) {
302
315
  return false;
303
316
  }
304
- const bbox = (_a = this.getData()) === null || _a === void 0 ? void 0 : _a.getBoundingBox();
317
+ const bbox = this.getData().getBoundingBox();
305
318
  if (!bbox || isEmpty(bbox)) {
306
319
  return true;
307
320
  }
@@ -312,6 +325,11 @@ class STACLayer extends LayerGroup {
312
325
  * @private
313
326
  */
314
327
  handleError_(error) {
328
+ const listeners = this.getListeners('error');
329
+ if (!Array.isArray(listeners) || listeners.length === 0) {
330
+ // To avoid swallowing errors when no listener is registered, log them to the console.
331
+ console.error(error); // eslint-disable-line no-console
332
+ }
315
333
  /**
316
334
  * Error event.
317
335
  *
@@ -326,12 +344,12 @@ class STACLayer extends LayerGroup {
326
344
  * @param {string} url The url to the data.
327
345
  * @param {APICollection|Object|Array<STAC>|string|null} children The child STAC entities to show.
328
346
  * @param {Array<Asset|string>|null} assets The assets to show.
329
- * @param {Array<number>} bands The (one-based) bands to show.
347
+ * @param {Array<number|string>} bands The bands to show.
330
348
  * @private
331
349
  */
332
350
  configure_(data, url = null, children = null, assets = null, bands = []) {
333
351
  let stac;
334
- if (data instanceof Asset || data instanceof STAC) {
352
+ if (data.isAsset || data.isSTAC) {
335
353
  stac = data;
336
354
  }
337
355
  else {
@@ -633,8 +651,7 @@ class STACLayer extends LayerGroup {
633
651
  }
634
652
  const sourceInfo = getGeoTiffSourceInfoFromAsset(asset, this.bands_);
635
653
  /**
636
- * todo: temporary fix for https://github.com/openlayers/openlayers/issues/17153
637
- * @type {import("../source/GeoTIFF.js").Options}
654
+ * @type {import("ol/source/GeoTIFF.js").Options}
638
655
  */
639
656
  let options = {
640
657
  sources: [sourceInfo],
@@ -645,7 +662,7 @@ class STACLayer extends LayerGroup {
645
662
  if (projection) {
646
663
  options.projection = projection;
647
664
  }
648
- const classificationStyle = getClassificationStyle(asset, this.bands_);
665
+ const classificationStyle = getClassificationStyle(asset, sourceInfo.bands);
649
666
  if (classificationStyle) {
650
667
  options.normalize = false;
651
668
  }
@@ -669,7 +686,10 @@ class STACLayer extends LayerGroup {
669
686
  try {
670
687
  await status;
671
688
  const layerOptions = { source };
672
- if (classificationStyle) {
689
+ if (this.style_) {
690
+ layerOptions.style = this.style_;
691
+ }
692
+ else if (classificationStyle) {
673
693
  layerOptions.style = classificationStyle;
674
694
  }
675
695
  const layer = new WebGLTileLayer(layerOptions);
@@ -711,7 +731,7 @@ class STACLayer extends LayerGroup {
711
731
  }
712
732
  /**
713
733
  * @param {Layer|LayerGroup} [layer] A Layer to add to the LayerGroup
714
- * @param {import("stac-js").STACObject} [data] The STAC object, can be any class exposed by stac-js
734
+ * @param {STACObject} [data] The STAC object, can be any class exposed by stac-js
715
735
  * @param {number} [zIndex] The z-index for the layer
716
736
  * @private
717
737
  */
@@ -729,7 +749,7 @@ class STACLayer extends LayerGroup {
729
749
  addFootprint_() {
730
750
  let geojson = null;
731
751
  const data = this.getData();
732
- if (data.isItemCollection || data.isCollectionCollection) {
752
+ if (data.isApiCollection) {
733
753
  geojson = toGeoJSON(data.getBoundingBox());
734
754
  }
735
755
  else {
@@ -794,7 +814,7 @@ class STACLayer extends LayerGroup {
794
814
  */
795
815
  async addLabelExtension_() {
796
816
  const data = this.getData();
797
- if (!(data instanceof Item)) {
817
+ if (!data || !data.isItem) {
798
818
  return;
799
819
  }
800
820
  // determine the asset with the geojson labels
@@ -828,7 +848,7 @@ class STACLayer extends LayerGroup {
828
848
  return null;
829
849
  }
830
850
  });
831
- const items = (await Promise.all(promises)).filter((item) => item instanceof STAC);
851
+ const items = (await Promise.all(promises)).filter((item) => item && item.isSTAC);
832
852
  await this.addChildren_(items, { displayFootprint: false });
833
853
  }
834
854
  // Add the GeoJSON labels
@@ -839,6 +859,43 @@ class STACLayer extends LayerGroup {
839
859
  this.handleError_(error);
840
860
  }
841
861
  }
862
+ async addGeoZarr_(asset) {
863
+ if (this.buildTileUrlTemplate_ && !this.useTileLayerAsFallback_) {
864
+ return await this.addTileLayerForImagery_(asset);
865
+ }
866
+ let options = getGeoZarrSourceOptionsFromAsset(asset, this.bands_);
867
+ if (this.getSourceOptions_) {
868
+ // @ts-ignore
869
+ options = await this.getSourceOptions_(SourceType.GeoZarr, options, asset);
870
+ }
871
+ try {
872
+ const GeoZarr = (await import('ol/source/GeoZarr.js')).default;
873
+ const source = new GeoZarr(options);
874
+ await new Promise((resolve, reject) => {
875
+ source.on('change', () => {
876
+ if (source.getState() === 'error') {
877
+ reject(source.error_);
878
+ }
879
+ else {
880
+ resolve();
881
+ }
882
+ });
883
+ });
884
+ const layerOptions = { source };
885
+ if (this.style_) {
886
+ layerOptions.style = this.style_;
887
+ }
888
+ const layer = new WebGLTileLayer(layerOptions);
889
+ this.addLayer_(layer, asset);
890
+ return layer;
891
+ }
892
+ catch (error) {
893
+ if (this.useTileLayerAsFallback_) {
894
+ return await this.addTileLayerForImagery_(asset);
895
+ }
896
+ this.handleError_(error);
897
+ }
898
+ }
842
899
  /**
843
900
  * Update the layers shown manually based on the current configuration.
844
901
  * Usually this doesn't need to be called manually.
@@ -873,12 +930,15 @@ class STACLayer extends LayerGroup {
873
930
  if (!ref) {
874
931
  return;
875
932
  }
876
- if (ref.type === geojsonMediaType) {
933
+ if (ref.isType(geojsonMediaType)) {
877
934
  return await this.addGeoJson_(ref);
878
935
  }
879
- if (ref.isGeoTIFF) {
936
+ if (ref.isType(geotiffMediaTypes)) {
880
937
  return await this.addGeoTiff_(ref);
881
938
  }
939
+ if (ref.isType(wozMediaTypes)) {
940
+ return await this.addGeoZarr_(ref);
941
+ }
882
942
  if (ref.canBrowserDisplayImage()) {
883
943
  return await this.addPreviewImage_(ref);
884
944
  }
@@ -889,10 +949,10 @@ class STACLayer extends LayerGroup {
889
949
  // choose a sensible default visualization
890
950
  if (this.hasOnlyBounds()) {
891
951
  // Show the ItemCollection/CollectionCollection entries
892
- if (data instanceof APICollection) {
952
+ if (data.isApiCollection) {
893
953
  await this.addChildren_(data.getAll(), this.childrenOptions_);
894
954
  }
895
- else if (data instanceof STAC) {
955
+ else if (data.isSTAC) {
896
956
  // Show label extension
897
957
  if (data.isItem &&
898
958
  data.supportsExtension(LABEL_EXTENSION) &&
@@ -903,27 +963,32 @@ class STACLayer extends LayerGroup {
903
963
  }
904
964
  return;
905
965
  }
906
- // Show web map links
907
- const links = this.getWebMapLinks();
908
- if (links.length > 0) {
909
- await this.addLayerForLink(links[0]);
910
- }
911
- else {
912
- // Find an asset that we can visualize
913
- const geotiff = data.getDefaultGeoTIFF(true, !this.displayGeoTiffByDefault_);
914
- let layer;
915
- // Try to visualize the default GeoTIFF first
916
- if (geotiff && this.displayOverview_) {
966
+ let layer;
967
+ if (this.displayOverview_ && !layer) {
968
+ // Find a GeoTiff asset that we can visualize
969
+ const geotiff = data.getDefaultGeoFile('geotiff', true, !this.displayGeoTiffByDefault_);
970
+ if (geotiff) {
917
971
  layer = await this.addGeoTiff_(geotiff);
918
972
  }
919
- // If no GeoTIFF is available or it can't be shown (e.g. error),
920
- // try to visualize the default thumbnail
921
- if (this.displayPreview_ && (!geotiff || !layer)) {
922
- // This may return Links or Assets
923
- const thumbnails = data.getThumbnails(true, 'overview');
924
- if (thumbnails.length > 0) {
925
- await this.addPreviewImage_(thumbnails[0]);
926
- }
973
+ }
974
+ if (this.displayOverview_ && !layer) {
975
+ // Find a Web-Optimized GeoZarr asset that we can visualize
976
+ const geozarr = data.getDefaultGeoFile('geozarr', true, true);
977
+ if (geozarr) {
978
+ layer = await this.addGeoZarr_(geozarr);
979
+ }
980
+ }
981
+ // Show web map links if available
982
+ const links = this.getWebMapLinks();
983
+ if (!layer && links.length > 0) {
984
+ layer = await this.addLayerForLink(links[0]);
985
+ }
986
+ // If no other layer is available, try to visualize the default thumbnail
987
+ if (this.displayPreview_ && !layer) {
988
+ // This may return Links or Assets
989
+ const thumbnails = data.getThumbnails(true, 'overview');
990
+ if (thumbnails.length > 0) {
991
+ await this.addPreviewImage_(thumbnails[0]);
927
992
  }
928
993
  }
929
994
  }
@@ -948,8 +1013,11 @@ class STACLayer extends LayerGroup {
948
1013
  * @api
949
1014
  */
950
1015
  getWebMapLinks() {
1016
+ if (this.displayWebMapLink_ === false) {
1017
+ return [];
1018
+ }
951
1019
  const data = this.getData();
952
- if (data instanceof Asset) {
1020
+ if (!data || data.isAsset) {
953
1021
  return [];
954
1022
  }
955
1023
  let types = ['xyz', 'tilejson', 'pmtiles', 'wmts', 'wms']; // This also defines the priority
@@ -980,6 +1048,19 @@ class STACLayer extends LayerGroup {
980
1048
  }
981
1049
  return mapLinks;
982
1050
  }
1051
+ /**
1052
+ * Set the style for GeoTIFF and GeoZarr layers (WebGLTileLayer style).
1053
+ * @param {import("ol/layer/WebGLTile.js").Style|null} style The style to apply.
1054
+ * @api
1055
+ */
1056
+ setStyle(style) {
1057
+ this.style_ = style || null;
1058
+ for (const layer of this.getLayersArray()) {
1059
+ if (layer instanceof WebGLTileLayer) {
1060
+ layer.setStyle(this.style_);
1061
+ }
1062
+ }
1063
+ }
983
1064
  /**
984
1065
  * Update the assets to be rendered.
985
1066
  * @param {Array<string|Asset>|null} assets The assets to show.
@@ -994,10 +1075,11 @@ class STACLayer extends LayerGroup {
994
1075
  if (Array.isArray(assets)) {
995
1076
  const data = this.getData();
996
1077
  this.assets_ = assets.map((asset) => {
997
- if (data instanceof STAC && typeof asset === 'string') {
1078
+ const isStr = typeof asset === 'string';
1079
+ if (data.isSTAC && isStr) {
998
1080
  return data.getAsset(asset);
999
1081
  }
1000
- if (!(asset instanceof Asset)) {
1082
+ if (!isStr && !asset.isAsset) {
1001
1083
  return new Asset(asset);
1002
1084
  }
1003
1085
  return asset;
@@ -1022,18 +1104,19 @@ class STACLayer extends LayerGroup {
1022
1104
  * @api
1023
1105
  */
1024
1106
  async setChildren(childs, options = null, updateLayers = true) {
1025
- if (childs instanceof ItemCollection) {
1107
+ const childsIsObj = isObject(childs);
1108
+ if (childsIsObj && childs.isItemCollection) {
1026
1109
  this.children_ = childs.getAll();
1027
1110
  }
1028
- else if (childs instanceof CollectionCollection) {
1111
+ else if (childsIsObj && childs.isCollectionCollection) {
1029
1112
  this.children_ = childs.getAll();
1030
1113
  }
1031
- else if (isObject(childs) && childs.type === 'FeatureCollection') {
1114
+ else if (childsIsObj && childs.type === 'FeatureCollection') {
1032
1115
  this.children_ = create(childs, !this.disableMigration_).getAll();
1033
1116
  }
1034
1117
  else if (Array.isArray(childs)) {
1035
1118
  this.children_ = childs.map((child) => {
1036
- if (child instanceof STAC) {
1119
+ if (child.isSTAC) {
1037
1120
  return child;
1038
1121
  }
1039
1122
  return create(child, !this.disableMigration_);