fix: don't force multi-sprites in style

Signed-off-by: acalcutt <acalcutt@techidiots.net>
This commit is contained in:
acalcutt 2024-04-23 12:58:07 -04:00
parent 361464fd4a
commit e9bb16936e
2 changed files with 30 additions and 11 deletions

View file

@ -1046,6 +1046,9 @@ export const serve_rendered = {
} }
if (styleJSON.sprite) { if (styleJSON.sprite) {
if (!Array.isArray(styleJSON.sprite)) {
styleJSON.sprite = [{ id: 'default', url: styleJSON.sprite }];
}
styleJSON.sprite.forEach((spriteItem) => { styleJSON.sprite.forEach((spriteItem) => {
if (!httpTester.test(spriteItem.url)) { if (!httpTester.test(spriteItem.url)) {
spriteItem.url = spriteItem.url =

View file

@ -61,9 +61,13 @@ export const serve_style = {
} }
// mapbox-gl-js viewer cannot handle sprite urls with query // mapbox-gl-js viewer cannot handle sprite urls with query
if (styleJSON_.sprite) { if (styleJSON_.sprite) {
styleJSON_.sprite.forEach((spriteItem) => { if (Array.isArray(styleJSON_.sprite)) {
spriteItem.url = fixUrl(req, spriteItem.url, item.publicUrl); styleJSON_.sprite.forEach((spriteItem) => {
}); spriteItem.url = fixUrl(req, spriteItem.url, item.publicUrl);
});
} else {
styleJSON_.sprite = fixUrl(req, styleJSON_.sprite, item.publicUrl);
}
} }
if (styleJSON_.glyphs) { if (styleJSON_.glyphs) {
styleJSON_.glyphs = fixUrl(req, styleJSON_.glyphs, item.publicUrl); styleJSON_.glyphs = fixUrl(req, styleJSON_.glyphs, item.publicUrl);
@ -173,22 +177,34 @@ export const serve_style = {
let spritePaths = []; let spritePaths = [];
if (styleJSON.sprite) { if (styleJSON.sprite) {
if (!Array.isArray(styleJSON.sprite)) { if (!Array.isArray(styleJSON.sprite)) {
styleJSON.sprite = [{ id: 'default', url: styleJSON.sprite }]; if (!httpTester.test(styleJSON.sprite)) {
}
for (let spriteItem of styleJSON.sprite) {
if (!httpTester.test(spriteItem.url)) {
let spritePath = path.join( let spritePath = path.join(
options.paths.sprites, options.paths.sprites,
spriteItem.url styleJSON.sprite
.replace('{style}', path.basename(styleFile, '.json')) .replace('{style}', path.basename(styleFile, '.json'))
.replace( .replace(
'{styleJsonFolder}', '{styleJsonFolder}',
path.relative(options.paths.sprites, path.dirname(styleFile)), path.relative(options.paths.sprites, path.dirname(styleFile)),
), ),
); );
spriteItem.url = `local://styles/${id}/sprite/` + spriteItem.id; styleJSON.sprite = `local://styles/${id}/sprite`;
spritePaths.push({ id: spriteItem.id, path: spritePath }); spritePaths.push({ id: 'default', path: spritePath });
}
} else {
for (let spriteItem of styleJSON.sprite) {
if (!httpTester.test(spriteItem.url)) {
let spritePath = path.join(
options.paths.sprites,
spriteItem.url
.replace('{style}', path.basename(styleFile, '.json'))
.replace(
'{styleJsonFolder}',
path.relative(options.paths.sprites, path.dirname(styleFile)),
),
);
spriteItem.url = `local://styles/${id}/sprite/` + spriteItem.id;
spritePaths.push({ id: spriteItem.id, path: spritePath });
}
} }
} }
} }