Skip to content

Commit

Permalink
Revert "Apply suggestions from code review"
Browse files Browse the repository at this point in the history
This reverts commit 73853e5.
  • Loading branch information
jansule committed May 7, 2024
1 parent 73853e5 commit 51723af
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/ol/source/ogcTileUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,14 @@ export function getVectorTileUrlTemplate(
// commata in the identifiers of the `collections` query parameter
// need to be URLEncoded, while the commata separating the identifiers
// should not.
const url = new URL(tileUrlTemplate, window.location.href);
let url;
let isAbsolute = true;
try {
url = new URL(tileUrlTemplate);
} catch (e) {
isAbsolute = false;
url = new URL(tileUrlTemplate, 'https://example.com');
}

if (url.pathname.split('/').includes('collections')) {
logError(
Expand All @@ -206,7 +213,12 @@ export function getVectorTileUrlTemplate(
.join(',');

url.searchParams.append('collections', encodedCollections);
const baseUrl = url.origin + decodeURIComponent(url.pathname);
let baseUrl;
if (isAbsolute) {
baseUrl = decodeURI(url.toString()).split('?')[0];
} else {
baseUrl = decodeURIComponent(url.pathname);
}
const queryParams = decodeURIComponent(url.searchParams.toString());
tileUrlTemplate = `${baseUrl}?${queryParams}`;
}
Expand Down

0 comments on commit 51723af

Please sign in to comment.