Merge pull request #608 from WifiDB/second_renderer
Add static renderer pool to fix static images
This commit is contained in:
commit
2796b1514d
1 changed files with 22 additions and 21 deletions
|
@ -229,9 +229,7 @@ module.exports = {
|
||||||
|
|
||||||
const app = express().disable('x-powered-by');
|
const app = express().disable('x-powered-by');
|
||||||
|
|
||||||
const respondImage = (item, z, lon, lat, bearing, pitch,
|
const respondImage = (item, z, lon, lat, bearing, pitch, width, height, scale, format, res, next, opt_overlay, opt_mode='tile') => {
|
||||||
width, height, scale, format, res, next,
|
|
||||||
opt_overlay) => {
|
|
||||||
if (Math.abs(lon) > 180 || Math.abs(lat) > 85.06 ||
|
if (Math.abs(lon) > 180 || Math.abs(lat) > 85.06 ||
|
||||||
lon !== lon || lat !== lat) {
|
lon !== lon || lat !== lat) {
|
||||||
return res.status(400).send('Invalid center');
|
return res.status(400).send('Invalid center');
|
||||||
|
@ -248,7 +246,12 @@ module.exports = {
|
||||||
return res.status(400).send('Invalid format');
|
return res.status(400).send('Invalid format');
|
||||||
}
|
}
|
||||||
|
|
||||||
const pool = item.map.renderers[scale];
|
let pool;
|
||||||
|
if (opt_mode === 'tile') {
|
||||||
|
pool = item.map.renderers[scale];
|
||||||
|
} else {
|
||||||
|
pool = item.map.renderers_static[scale];
|
||||||
|
}
|
||||||
pool.acquire((err, renderer) => {
|
pool.acquire((err, renderer) => {
|
||||||
const mbglZ = Math.max(0, z - 1);
|
const mbglZ = Math.max(0, z - 1);
|
||||||
const params = {
|
const params = {
|
||||||
|
@ -383,8 +386,7 @@ module.exports = {
|
||||||
((x + 0.5) / (1 << z)) * (256 << z),
|
((x + 0.5) / (1 << z)) * (256 << z),
|
||||||
((y + 0.5) / (1 << z)) * (256 << z)
|
((y + 0.5) / (1 << z)) * (256 << z)
|
||||||
], z);
|
], z);
|
||||||
return respondImage(item, z, tileCenter[0], tileCenter[1], 0, 0,
|
return respondImage(item, z, tileCenter[0], tileCenter[1], 0, 0, tileSize, tileSize, scale, format, res, next);
|
||||||
tileSize, tileSize, scale, format, res, next);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (options.serveStaticMaps !== false) {
|
if (options.serveStaticMaps !== false) {
|
||||||
|
@ -426,11 +428,9 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = extractPathFromQuery(req.query, transformer);
|
const path = extractPathFromQuery(req.query, transformer);
|
||||||
const overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale,
|
const overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale, path, req.query);
|
||||||
path, req.query);
|
|
||||||
|
|
||||||
return respondImage(item, z, x, y, bearing, pitch, w, h, scale, format,
|
return respondImage(item, z, x, y, bearing, pitch, w, h, scale, format, res, next, overlay, 'static');
|
||||||
res, next, overlay);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const serveBounds = (req, res, next) => {
|
const serveBounds = (req, res, next) => {
|
||||||
|
@ -468,10 +468,8 @@ module.exports = {
|
||||||
pitch = 0;
|
pitch = 0;
|
||||||
|
|
||||||
const path = extractPathFromQuery(req.query, transformer);
|
const path = extractPathFromQuery(req.query, transformer);
|
||||||
const overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale,
|
const overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale, path, req.query);
|
||||||
path, req.query);
|
return respondImage(item, z, x, y, bearing, pitch, w, h, scale, format, res, next, overlay, 'static');
|
||||||
return respondImage(item, z, x, y, bearing, pitch, w, h, scale, format,
|
|
||||||
res, next, overlay);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const boundsPattern =
|
const boundsPattern =
|
||||||
|
@ -542,11 +540,9 @@ module.exports = {
|
||||||
x = center[0],
|
x = center[0],
|
||||||
y = center[1];
|
y = center[1];
|
||||||
|
|
||||||
const overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale,
|
const overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale, path, req.query);
|
||||||
path, req.query);
|
|
||||||
|
|
||||||
return respondImage(item, z, x, y, bearing, pitch, w, h, scale, format,
|
return respondImage(item, z, x, y, bearing, pitch, w, h, scale, format, res, next, overlay, 'static');
|
||||||
res, next, overlay);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,14 +562,15 @@ module.exports = {
|
||||||
add: (options, repo, params, id, publicUrl, dataResolver) => {
|
add: (options, repo, params, id, publicUrl, dataResolver) => {
|
||||||
const map = {
|
const map = {
|
||||||
renderers: [],
|
renderers: [],
|
||||||
|
renderers_static: [],
|
||||||
sources: {}
|
sources: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let styleJSON;
|
let styleJSON;
|
||||||
const createPool = (ratio, min, max) => {
|
const createPool = (ratio, mode, min, max) => {
|
||||||
const createRenderer = (ratio, createCallback) => {
|
const createRenderer = (ratio, createCallback) => {
|
||||||
const renderer = new mbgl.Map({
|
const renderer = new mbgl.Map({
|
||||||
mode: "tile",
|
mode: mode,
|
||||||
ratio: ratio,
|
ratio: ratio,
|
||||||
request: (req, callback) => {
|
request: (req, callback) => {
|
||||||
const protocol = req.url.split(':')[0];
|
const protocol = req.url.split(':')[0];
|
||||||
|
@ -814,7 +811,8 @@ module.exports = {
|
||||||
const j = Math.min(maxPoolSizes.length - 1, s - 1);
|
const j = Math.min(maxPoolSizes.length - 1, s - 1);
|
||||||
const minPoolSize = minPoolSizes[i];
|
const minPoolSize = minPoolSizes[i];
|
||||||
const maxPoolSize = Math.max(minPoolSize, maxPoolSizes[j]);
|
const maxPoolSize = Math.max(minPoolSize, maxPoolSizes[j]);
|
||||||
map.renderers[s] = createPool(s, minPoolSize, maxPoolSize);
|
map.renderers[s] = createPool(s, 'tile', minPoolSize, maxPoolSize);
|
||||||
|
map.renderers_static[s] = createPool(s, 'static', minPoolSize, maxPoolSize);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -826,6 +824,9 @@ module.exports = {
|
||||||
item.map.renderers.forEach(pool => {
|
item.map.renderers.forEach(pool => {
|
||||||
pool.close();
|
pool.close();
|
||||||
});
|
});
|
||||||
|
item.map.renderers_static.forEach(pool => {
|
||||||
|
pool.close();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
delete repo[id];
|
delete repo[id];
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue