Add option to disable static maps (close #129)
This commit is contained in:
parent
37386bfb29
commit
0673c8990a
2 changed files with 108 additions and 105 deletions
|
@ -27,7 +27,8 @@ Example::
|
||||||
},
|
},
|
||||||
"maxSize": 2048,
|
"maxSize": 2048,
|
||||||
"pbfAlias": "pbf",
|
"pbfAlias": "pbf",
|
||||||
"serveAllFonts": false
|
"serveAllFonts": false,
|
||||||
|
"serveStaticMaps": true
|
||||||
},
|
},
|
||||||
"styles": {
|
"styles": {
|
||||||
"basic": {
|
"basic": {
|
||||||
|
|
|
@ -474,121 +474,123 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||||
return z;
|
return z;
|
||||||
};
|
};
|
||||||
|
|
||||||
var staticPattern =
|
if (options.serveStaticMaps !== false) {
|
||||||
'/static/:raw(raw)?/%s/:width(\\d+)x:height(\\d+)' +
|
var staticPattern =
|
||||||
':scale(' + SCALE_PATTERN + ')?\.:format([\\w]+)';
|
'/static/:raw(raw)?/%s/:width(\\d+)x:height(\\d+)' +
|
||||||
|
':scale(' + SCALE_PATTERN + ')?\.:format([\\w]+)';
|
||||||
|
|
||||||
var centerPattern =
|
var centerPattern =
|
||||||
util.format(':x(%s),:y(%s),:z(%s)(@:bearing(%s)(,:pitch(%s))?)?',
|
util.format(':x(%s),:y(%s),:z(%s)(@:bearing(%s)(,:pitch(%s))?)?',
|
||||||
FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN,
|
FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN,
|
||||||
FLOAT_PATTERN, FLOAT_PATTERN);
|
FLOAT_PATTERN, FLOAT_PATTERN);
|
||||||
|
|
||||||
app.get(util.format(staticPattern, centerPattern), function(req, res, next) {
|
app.get(util.format(staticPattern, centerPattern), function(req, res, next) {
|
||||||
var raw = req.params.raw;
|
var raw = req.params.raw;
|
||||||
var z = +req.params.z,
|
var z = +req.params.z,
|
||||||
x = +req.params.x,
|
x = +req.params.x,
|
||||||
y = +req.params.y,
|
y = +req.params.y,
|
||||||
bearing = +(req.params.bearing || '0'),
|
bearing = +(req.params.bearing || '0'),
|
||||||
pitch = +(req.params.pitch || '0'),
|
pitch = +(req.params.pitch || '0'),
|
||||||
w = req.params.width | 0,
|
w = req.params.width | 0,
|
||||||
h = req.params.height | 0,
|
h = req.params.height | 0,
|
||||||
scale = getScale(req.params.scale),
|
scale = getScale(req.params.scale),
|
||||||
format = req.params.format;
|
format = req.params.format;
|
||||||
|
|
||||||
if (z < 0) {
|
if (z < 0) {
|
||||||
return res.status(404).send('Invalid zoom');
|
return res.status(404).send('Invalid zoom');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raw) {
|
if (raw) {
|
||||||
var ll = mercator.inverse([x, y]);
|
var ll = mercator.inverse([x, y]);
|
||||||
x = ll[0];
|
x = ll[0];
|
||||||
y = ll[1];
|
y = ll[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = extractPathFromQuery(req.query);
|
var path = extractPathFromQuery(req.query);
|
||||||
var overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale,
|
var overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale,
|
||||||
path, req.query);
|
path, req.query);
|
||||||
|
|
||||||
return respondImage(z, x, y, bearing, pitch, w, h, scale, format,
|
return respondImage(z, x, y, bearing, pitch, w, h, scale, format,
|
||||||
res, next, overlay);
|
res, next, overlay);
|
||||||
});
|
|
||||||
|
|
||||||
var boundsPattern =
|
|
||||||
util.format(':minx(%s),:miny(%s),:maxx(%s),:maxy(%s)',
|
|
||||||
FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN);
|
|
||||||
|
|
||||||
app.get(util.format(staticPattern, boundsPattern), function(req, res, next) {
|
|
||||||
var raw = req.params.raw;
|
|
||||||
var bbox = [+req.params.minx, +req.params.miny,
|
|
||||||
+req.params.maxx, +req.params.maxy];
|
|
||||||
|
|
||||||
if (raw) {
|
|
||||||
var minCorner = mercator.inverse(bbox.slice(0, 2));
|
|
||||||
var maxCorner = mercator.inverse(bbox.slice(2));
|
|
||||||
bbox[0] = minCorner[0];
|
|
||||||
bbox[1] = minCorner[1];
|
|
||||||
bbox[2] = maxCorner[0];
|
|
||||||
bbox[3] = maxCorner[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
var w = req.params.width | 0,
|
|
||||||
h = req.params.height | 0,
|
|
||||||
scale = getScale(req.params.scale),
|
|
||||||
format = req.params.format;
|
|
||||||
|
|
||||||
var z = calcZForBBox(bbox, w, h, req.query),
|
|
||||||
x = (bbox[0] + bbox[2]) / 2,
|
|
||||||
y = (bbox[1] + bbox[3]) / 2,
|
|
||||||
bearing = 0,
|
|
||||||
pitch = 0;
|
|
||||||
|
|
||||||
var path = extractPathFromQuery(req.query);
|
|
||||||
var overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale,
|
|
||||||
path, req.query);
|
|
||||||
return respondImage(z, x, y, bearing, pitch, w, h, scale, format,
|
|
||||||
res, next, overlay);
|
|
||||||
});
|
|
||||||
|
|
||||||
var autoPattern = 'auto';
|
|
||||||
|
|
||||||
app.get(util.format(staticPattern, autoPattern), function(req, res, next) {
|
|
||||||
var path = extractPathFromQuery(req.query);
|
|
||||||
if (path.length < 2) {
|
|
||||||
return res.status(400).send('Invalid path');
|
|
||||||
}
|
|
||||||
|
|
||||||
var raw = req.params.raw;
|
|
||||||
var w = req.params.width | 0,
|
|
||||||
h = req.params.height | 0,
|
|
||||||
bearing = 0,
|
|
||||||
pitch = 0,
|
|
||||||
scale = getScale(req.params.scale),
|
|
||||||
format = req.params.format;
|
|
||||||
|
|
||||||
var bbox = [Infinity, Infinity, -Infinity, -Infinity];
|
|
||||||
path.forEach(function(pair) {
|
|
||||||
bbox[0] = Math.min(bbox[0], pair[0]);
|
|
||||||
bbox[1] = Math.min(bbox[1], pair[1]);
|
|
||||||
bbox[2] = Math.max(bbox[2], pair[0]);
|
|
||||||
bbox[3] = Math.max(bbox[3], pair[1]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var z = calcZForBBox(bbox, w, h, req.query),
|
var boundsPattern =
|
||||||
x = (bbox[0] + bbox[2]) / 2,
|
util.format(':minx(%s),:miny(%s),:maxx(%s),:maxy(%s)',
|
||||||
y = (bbox[1] + bbox[3]) / 2;
|
FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN);
|
||||||
|
|
||||||
if (raw) {
|
app.get(util.format(staticPattern, boundsPattern), function(req, res, next) {
|
||||||
var ll = mercator.inverse([x, y]);
|
var raw = req.params.raw;
|
||||||
x = ll[0];
|
var bbox = [+req.params.minx, +req.params.miny,
|
||||||
y = ll[1];
|
+req.params.maxx, +req.params.maxy];
|
||||||
}
|
|
||||||
|
|
||||||
var overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale,
|
if (raw) {
|
||||||
path, req.query);
|
var minCorner = mercator.inverse(bbox.slice(0, 2));
|
||||||
|
var maxCorner = mercator.inverse(bbox.slice(2));
|
||||||
|
bbox[0] = minCorner[0];
|
||||||
|
bbox[1] = minCorner[1];
|
||||||
|
bbox[2] = maxCorner[0];
|
||||||
|
bbox[3] = maxCorner[1];
|
||||||
|
}
|
||||||
|
|
||||||
return respondImage(z, x, y, bearing, pitch, w, h, scale, format,
|
var w = req.params.width | 0,
|
||||||
res, next, overlay);
|
h = req.params.height | 0,
|
||||||
});
|
scale = getScale(req.params.scale),
|
||||||
|
format = req.params.format;
|
||||||
|
|
||||||
|
var z = calcZForBBox(bbox, w, h, req.query),
|
||||||
|
x = (bbox[0] + bbox[2]) / 2,
|
||||||
|
y = (bbox[1] + bbox[3]) / 2,
|
||||||
|
bearing = 0,
|
||||||
|
pitch = 0;
|
||||||
|
|
||||||
|
var path = extractPathFromQuery(req.query);
|
||||||
|
var overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale,
|
||||||
|
path, req.query);
|
||||||
|
return respondImage(z, x, y, bearing, pitch, w, h, scale, format,
|
||||||
|
res, next, overlay);
|
||||||
|
});
|
||||||
|
|
||||||
|
var autoPattern = 'auto';
|
||||||
|
|
||||||
|
app.get(util.format(staticPattern, autoPattern), function(req, res, next) {
|
||||||
|
var path = extractPathFromQuery(req.query);
|
||||||
|
if (path.length < 2) {
|
||||||
|
return res.status(400).send('Invalid path');
|
||||||
|
}
|
||||||
|
|
||||||
|
var raw = req.params.raw;
|
||||||
|
var w = req.params.width | 0,
|
||||||
|
h = req.params.height | 0,
|
||||||
|
bearing = 0,
|
||||||
|
pitch = 0,
|
||||||
|
scale = getScale(req.params.scale),
|
||||||
|
format = req.params.format;
|
||||||
|
|
||||||
|
var bbox = [Infinity, Infinity, -Infinity, -Infinity];
|
||||||
|
path.forEach(function(pair) {
|
||||||
|
bbox[0] = Math.min(bbox[0], pair[0]);
|
||||||
|
bbox[1] = Math.min(bbox[1], pair[1]);
|
||||||
|
bbox[2] = Math.max(bbox[2], pair[0]);
|
||||||
|
bbox[3] = Math.max(bbox[3], pair[1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
var z = calcZForBBox(bbox, w, h, req.query),
|
||||||
|
x = (bbox[0] + bbox[2]) / 2,
|
||||||
|
y = (bbox[1] + bbox[3]) / 2;
|
||||||
|
|
||||||
|
if (raw) {
|
||||||
|
var ll = mercator.inverse([x, y]);
|
||||||
|
x = ll[0];
|
||||||
|
y = ll[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
var overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale,
|
||||||
|
path, req.query);
|
||||||
|
|
||||||
|
return respondImage(z, x, y, bearing, pitch, w, h, scale, format,
|
||||||
|
res, next, overlay);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
app.get('/rendered.json', function(req, res, next) {
|
app.get('/rendered.json', function(req, res, next) {
|
||||||
var info = clone(tileJSON);
|
var info = clone(tileJSON);
|
||||||
|
|
Loading…
Reference in a new issue