Skip to content

Commit

Permalink
feat(VectorTile): add support for relative url in style
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Jan 15, 2025
1 parent 9b9d52a commit 09f7adb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Source/VectorTilesSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ class VectorTilesSource extends TMSSource {

this.accessToken = source.accessToken;

let styleUrl;
if (source.style) {
if (typeof source.style == 'string') {
const styleUrl = urlParser.normalizeStyleURL(source.style, this.accessToken);
styleUrl = urlParser.normalizeStyleURL(source.style, this.accessToken);
promise = Fetcher.json(styleUrl, this.networkOptions);
} else {
promise = Promise.resolve(source.style);
Expand All @@ -84,8 +85,9 @@ class VectorTilesSource extends TMSSource {

this.whenReady = promise.then((style) => {
this.jsonStyle = style;
const baseurl = source.sprite || style.sprite;
let baseurl = source.sprite || style.sprite;
if (baseurl) {
baseurl = new URL(baseurl, styleUrl).toString();
const spriteUrl = urlParser.normalizeSpriteURL(baseurl, '', '.json', this.accessToken);
return Fetcher.json(spriteUrl, this.networkOptions).then((sprites) => {
this.sprites = sprites;
Expand Down Expand Up @@ -123,9 +125,11 @@ class VectorTilesSource extends TMSSource {
if (this.url == '.') {
const TMSUrlList = Object.values(style.sources).map((sourceVT) => {
if (sourceVT.url) {
sourceVT.url = new URL(sourceVT.url, styleUrl).toString();
const urlSource = urlParser.normalizeSourceURL(sourceVT.url, this.accessToken);
return Fetcher.json(urlSource, this.networkOptions).then((tileJSON) => {
if (tileJSON.tiles[0]) {
tileJSON.tiles[0] = decodeURIComponent(new URL(tileJSON.tiles[0], urlSource).toString());
return toTMSUrl(tileJSON.tiles[0]);
}
});
Expand Down

0 comments on commit 09f7adb

Please sign in to comment.