Skip to content

Commit b79a89e

Browse files
authored
Small fixes to WMTSCapabilitiesLoader and WMTSImageSource (#1323)
* WMTS capabilities: handle missing style elements title/isDefault * WMTS capabilities: handle WGS84BoundingBox without crs * WMTSIMAGESource: set ContentBounds from layer * WMTS Capabilities: distinguish between false and missing isDefault * WMTS Capabilities: simplify check for WGS84BoundingBox * WMTS Capabilities: always return bool for Style isDefault * WMTSTiles example: fix crash if WMTS source has not default layer style * WMTS example: pick first tms that has a supported crs * WMTS example: auto select CRS compatible layer * WMTS: simplify code
1 parent 6cef376 commit b79a89e

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

example/wmtsTiles.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { TilesFadePlugin, UpdateOnChangePlugin, WMTSCapabilitiesLoader, WMTSTile
88
import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js';
99

1010
const url = window.location.hash.replace( /^#/, '' ) || 'https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/wmts.cgi?SERVICE=WMTS&request=GetCapabilities';
11+
const compatibleCRSList = [ 'EPSG:4326', 'EPSG:3857' ];
1112

1213
let controls, scene, renderer;
1314
let tiles, camera, gui;
@@ -50,9 +51,12 @@ async function updateCapabilities() {
5051

5152
// use a default overlay
5253
let defaultLayer = 'MODIS_Terra_CorrectedReflectance_TrueColor';
54+
5355
if ( ! capabilities.layers.find( l => l.identifier === defaultLayer ) ) {
5456

55-
defaultLayer = capabilities.layers[ 0 ].identifier;
57+
defaultLayer = capabilities.layers.find( l =>
58+
l.tileMatrixSets.some( tms => compatibleCRSList.includes( tms.supportedCRS ) )
59+
).identifier;
5660

5761
}
5862

@@ -84,8 +88,9 @@ function rebuildGUI() {
8488

8589
// initialize the layer settings
8690
const layer = capabilities.layers.find( l => l.identifier === params.layer );
87-
params.style = layer.styles.find( s => s.isDefault ).identifier;
88-
params.tileMatrixSet = layer.tileMatrixSets[ 0 ].identifier;
91+
params.style = layer.styles.find( s => s.isDefault )?.identifier || layer.styles[ 0 ].identifier;
92+
const compatibleTileMatrixSet = layer.tileMatrixSets.find( tms => compatibleCRSList.includes( tms.supportedCRS ) );
93+
params.tileMatrixSet = compatibleTileMatrixSet ? compatibleTileMatrixSet.identifier : layer.tileMatrixSets[ 0 ].identifier;
8994

9095
// update the ui
9196
const abstract = capabilities.serviceIdentification.abstract;

src/three/plugins/images/sources/WMTSImageSource.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,17 @@ export class WMTSImageSource extends TiledImageSource {
8181
// generate the tiling scheme
8282
tiling.flipY = true;
8383
tiling.setProjection( new ProjectionScheme( projection ) );
84-
tiling.setContentBounds( ...tiling.projection.getBounds() );
84+
85+
if ( layer.boundingBox !== null ) {
86+
87+
tiling.setContentBounds( ...layer.boundingBox.bounds );
88+
89+
} else {
90+
91+
tiling.setContentBounds( ...tiling.projection.getBounds() );
92+
93+
}
94+
8595
tileMatrixSet.tileMatrices.forEach( ( tm, i ) => {
8696

8797
// TODO: needs to set tileCountX from matrix width?

src/three/plugins/loaders/WMTSCapabilitiesLoader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function parseBoundingBox( el ) {
207207

208208
}
209209

210-
let crs = el.getAttribute( 'crs' );
210+
let crs = el.nodeName.endsWith( 'WGS84BoundingBox' ) ? 'urn:ogc:def:crs:CRS::84' : el.getAttribute( 'crs' );
211211
const lowerCorner = parseTuple( el.querySelector( 'LowerCorner' ).textContent );
212212
const upperCorner = parseTuple( el.querySelector( 'UpperCorner' ).textContent );
213213

@@ -244,7 +244,7 @@ function parseBoundingBox( el ) {
244244
// parse layer <Style> tag
245245
function parseStyle( el ) {
246246

247-
const title = el.querySelector( 'Title' ).textContent;
247+
const title = el.querySelector( 'Title' )?.textContent || null;
248248
const identifier = el.querySelector( 'Identifier' ).textContent;
249249
const isDefault = el.getAttribute( 'isDefault' ) === 'true';
250250

0 commit comments

Comments
 (0)