fix: match docs source behavior

Signed-off-by: Andrew Calcutt <acalcutt@techidiots.net>
This commit is contained in:
Andrew Calcutt 2023-10-14 21:25:47 -04:00
parent c866de4691
commit 065b3742f0
2 changed files with 139 additions and 148 deletions

View file

@ -6,8 +6,8 @@ import path from 'path';
import url from 'url';
import util from 'util';
import zlib from 'zlib';
import { createCanvas, Image } from 'canvas';
import sharp from 'sharp'; // sharp has to be required before node-canvas on linux but after it on windows. see https://github.com/lovell/sharp/issues/371
import { createCanvas, Image } from 'canvas';
import clone from 'clone';
import Color from 'color';
import express from 'express';
@ -1470,11 +1470,10 @@ export const serve_rendered = {
let source_type;
let source = styleJSON.sources[name];
let url = source.url;
if (url) {
if (url.startsWith('{') && url.endsWith('}')) {
url = url.slice(1, -1);
}
if (url.startsWith('pmtiles://') || url.startsWith('mbtiles://')) {
if (
url &&
(url.startsWith('pmtiles://') || url.startsWith('mbtiles://'))
) {
// found pmtiles or mbtiles source, replace with info from local file
delete source.url;
@ -1548,9 +1547,7 @@ export const serve_rendered = {
if (!inputFileStats.isFile() || inputFileStats.size === 0) {
throw Error(`Not valid MBTiles file: "${inputFile}"`);
}
map.sources[name] = new MBTiles(
inputFile + '?mode=ro',
(err) => {
map.sources[name] = new MBTiles(inputFile + '?mode=ro', (err) => {
map.sources[name].getInfo((err, info) => {
if (err) {
console.error(err);
@ -1589,9 +1586,7 @@ export const serve_rendered = {
source.attribution &&
source.attribution.length > 0
) {
if (
!tileJSON.attribution.includes(source.attribution)
) {
if (!tileJSON.attribution.includes(source.attribution)) {
if (tileJSON.attribution.length > 0) {
tileJSON.attribution += ' | ';
}
@ -1600,14 +1595,12 @@ export const serve_rendered = {
}
resolve();
});
},
);
});
}),
);
}
}
}
}
const renderersReadyPromise = Promise.all(queue).then(() => {
// standard and @2x tiles are much more usual -> default to larger pools

View file

@ -111,11 +111,10 @@ export const serve_style = {
for (const name of Object.keys(styleJSON.sources)) {
const source = styleJSON.sources[name];
let url = source.url;
if (url) {
if (url.startsWith('{') && url.endsWith('}')) {
url = url.slice(1, -1);
}
if (url.startsWith('pmtiles://') || url.startsWith('mbtiles://')) {
if (
url &&
(url.startsWith('pmtiles://') || url.startsWith('mbtiles://'))
) {
const protocol = url.split(':')[0];
let dataId = url.replace('pmtiles://', '').replace('mbtiles://', '');
@ -135,7 +134,6 @@ export const serve_style = {
source.url = `local://data/${identifier}.json`;
}
}
}
for (const obj of styleJSON.layers) {
if (obj['type'] === 'symbol') {