diff --git a/modules/i3s/src/i3s-loader.ts b/modules/i3s/src/i3s-loader.ts index 8fec27a377..659c64e19b 100644 --- a/modules/i3s/src/i3s-loader.ts +++ b/modules/i3s/src/i3s-loader.ts @@ -5,6 +5,7 @@ import {I3SContentLoader} from './i3s-content-loader'; import {normalizeTileData, normalizeTilesetData} from './lib/parsers/parse-i3s'; import {COORDINATE_SYSTEM} from './lib/parsers/constants'; import {I3SParseOptions} from './types'; +import {getUrlWithoutParams} from './lib/utils/url-utils'; // __VERSION__ is injected by babel-plugin-version-inline // @ts-ignore TS2304: Cannot find name '__VERSION__'. @@ -58,17 +59,19 @@ async function parseI3S(data, options: I3SLoaderOptions = {}, context): Promise< throw new Error('Files with .slpk extention currently are not supported by I3SLoader'); } + const urlWithoutParams = getUrlWithoutParams(url); + // auto detect file type based on url let isTileset; if (options.i3s.isTileset === 'auto') { - isTileset = TILESET_REGEX.test(url); + isTileset = TILESET_REGEX.test(urlWithoutParams); } else { isTileset = options.i3s.isTileset; } let isTileHeader; if (options.isTileHeader === 'auto') { - isTileHeader = TILE_HEADER_REGEX.test(url); + isTileHeader = TILE_HEADER_REGEX.test(urlWithoutParams); } else { isTileHeader = options.i3s.isTileHeader; } diff --git a/modules/i3s/src/lib/parsers/parse-i3s.ts b/modules/i3s/src/lib/parsers/parse-i3s.ts index ccd0075e6f..da12855284 100644 --- a/modules/i3s/src/lib/parsers/parse-i3s.ts +++ b/modules/i3s/src/lib/parsers/parse-i3s.ts @@ -3,7 +3,7 @@ import {Ellipsoid} from '@math.gl/geospatial'; import {load} from '@loaders.gl/core'; import {TILE_TYPE, TILE_REFINEMENT, TILESET_TYPE} from '@loaders.gl/tiles'; import I3SNodePagesTiles from '../helpers/i3s-nodepages-tiles'; -import {generateTileAttributeUrls, getUrlWithToken} from '../utils/url-utils'; +import {generateTileAttributeUrls, getUrlWithToken, getUrlWithoutParams} from '../utils/url-utils'; import { I3STilesetHeader, I3STileHeader, @@ -84,7 +84,7 @@ export function normalizeTileNonUrlData(tile : I3SMinimalNodeData): I3STileHeade } export async function normalizeTilesetData(tileset : SceneLayer3D, options : LoaderOptions, context: LoaderContext): Promise { - const url = context.url; + const url = getUrlWithoutParams(context.url || ''); let nodePagesTile: I3SNodePagesTiles | undefined; let root: I3STileHeader | I3STilesetHeader; if (tileset.nodePages) { diff --git a/modules/i3s/src/lib/utils/url-utils.ts b/modules/i3s/src/lib/utils/url-utils.ts index 44986fbf45..95d93f9305 100644 --- a/modules/i3s/src/lib/utils/url-utils.ts +++ b/modules/i3s/src/lib/utils/url-utils.ts @@ -1,5 +1,22 @@ import {Node3DIndexDocument, SceneLayer3D} from '../../types'; +/** + * Return URL seperated from search params + * @param url - URL that might have search params + * @returns url without search params + */ +export function getUrlWithoutParams(url: string): string { + let urlWithoutParams; + + try { + const urlObj = new URL(url); + urlWithoutParams = `${urlObj.origin}${urlObj.pathname}`; + } catch (e) { + // do nothing + } + return urlWithoutParams || url; +} + /** * Generates url with token if it is exists. * @param url diff --git a/modules/i3s/test/lib/parsers/url-utils.spec.ts b/modules/i3s/test/lib/parsers/url-utils.spec.ts index 1f34933c8b..dbcd0927b0 100644 --- a/modules/i3s/test/lib/parsers/url-utils.spec.ts +++ b/modules/i3s/test/lib/parsers/url-utils.spec.ts @@ -5,6 +5,16 @@ import { generateTilesetAttributeUrls // @ts-expect-error } from '@loaders.gl/i3s/lib/utils/url-utils'; +import {getUrlWithoutParams} from '../../../src/lib/utils/url-utils'; + +test('i3s-utils#getUrlWithoutParams', async (t) => { + const url = getUrlWithoutParams('http://a.b.c/x/y/z?token=efk'); + t.equal(url, 'http://a.b.c/x/y/z'); + + const url2 = getUrlWithoutParams('@loaders.gl/core/test/data/url'); + t.equal(url2, '@loaders.gl/core/test/data/url'); + t.end(); +}); test('i3s-utils#getUrlWithToken Should return URL without token if token null', async (t) => { const url = getUrlWithToken('test', null);