Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
654bdda629 | ||
|
|
537313840e | ||
|
|
d30f8464b2 | ||
|
|
698c527e94 | ||
|
|
8007f1386c | ||
|
|
4f2fdf602b | ||
|
|
6d7397647a | ||
|
|
8fd7a9b42b | ||
|
|
95470143b6 | ||
|
|
de83021c3d | ||
|
|
7de3d8b9c7 | ||
|
|
bdc3d20524 | ||
|
|
5d93b1d4f9 | ||
|
|
d30027e992 | ||
|
|
c233d23523 | ||
|
|
1109c77ec2 | ||
|
|
88cf9b37a9 | ||
|
|
2d207f792b | ||
|
|
d67a57861d | ||
|
|
27e9dbfb4e | ||
|
|
a199008fa3 | ||
|
|
e88b786073 | ||
|
|
c03b0a12f8 | ||
|
|
a234041cd1 | ||
|
|
49a779970e | ||
|
|
9545c2594e | ||
|
|
6c23d95feb | ||
|
|
366380395e | ||
|
|
8ea665297f | ||
|
|
f6580c0342 | ||
|
|
34a139040c | ||
|
|
66bea8a42b | ||
|
|
28790fda30 | ||
|
|
0b16af0084 |
@@ -1,6 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "4"
|
||||
- "6"
|
||||
env:
|
||||
- CXX=g++-4.8
|
||||
addons:
|
||||
@@ -12,7 +12,7 @@ addons:
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++
|
||||
- sudo apt-get install -qq xvfb
|
||||
- sudo apt-get install -qq xvfb libgles2-mesa-dev libgbm-dev libxxf86vm-dev
|
||||
install:
|
||||
- npm install
|
||||
- wget -O test_data.zip https://github.com/klokantech/tileserver-gl/releases/download/v1.3.0/test_data.zip
|
||||
|
||||
10
Dockerfile
10
Dockerfile
@@ -9,10 +9,14 @@ RUN apt-get -qq update \
|
||||
build-essential \
|
||||
python \
|
||||
libcairo2-dev \
|
||||
libgles2-mesa-dev \
|
||||
libgbm-dev \
|
||||
libllvm3.9 \
|
||||
libprotobuf-dev \
|
||||
libxxf86vm-dev \
|
||||
xvfb \
|
||||
&& echo "deb https://deb.nodesource.com/node_4.x jessie main" >> /etc/apt/sources.list.d/nodejs.list \
|
||||
&& echo "deb-src https://deb.nodesource.com/node_4.x jessie main" >> /etc/apt/sources.list.d/nodejs.list \
|
||||
&& echo "deb https://deb.nodesource.com/node_6.x jessie main" >> /etc/apt/sources.list.d/nodejs.list \
|
||||
&& echo "deb-src https://deb.nodesource.com/node_6.x jessie main" >> /etc/apt/sources.list.d/nodejs.list \
|
||||
&& apt-get -qq update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get -y --allow-unauthenticated install \
|
||||
nodejs \
|
||||
@@ -26,5 +30,7 @@ RUN cd /usr/src/app && npm install --production
|
||||
VOLUME /data
|
||||
WORKDIR /data
|
||||
|
||||
ENV NODE_ENV="production"
|
||||
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["/usr/src/app/run.sh"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM node:4
|
||||
FROM node:6
|
||||
MAINTAINER Petr Sloup <petr.sloup@klokantech.com>
|
||||
|
||||
RUN mkdir -p /usr/src/app
|
||||
@@ -8,5 +8,7 @@ RUN cd /usr/src/app && npm install --production
|
||||
VOLUME /data
|
||||
WORKDIR /data
|
||||
|
||||
ENV NODE_ENV="production"
|
||||
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["node", "/usr/src/app/", "-p", "80"]
|
||||
|
||||
@@ -17,4 +17,4 @@ Nginx can be used to add protection via https, password, referrer, IP address re
|
||||
Running behind a proxy or a load-balancer
|
||||
=========================================
|
||||
|
||||
If you need to run TileServer GL behind a proxy, make sure the proxy sends ``X-Forwarded-*`` headers to the server (most importantly ``X-Forwarded-Host`` and ``X-Forwaded-Proto``) to ensures the URLs generated inside TileJSON etc. are using the desired domain and protocol.
|
||||
If you need to run TileServer GL behind a proxy, make sure the proxy sends ``X-Forwarded-*`` headers to the server (most importantly ``X-Forwarded-Host`` and ``X-Forwarded-Proto``) to ensures the URLs generated inside TileJSON etc. are using the desired domain and protocol.
|
||||
|
||||
@@ -6,18 +6,18 @@ If you visit the server on the configured port (default 8080) you can see your m
|
||||
|
||||
Styles
|
||||
======
|
||||
* Styles are served at ``/styles/{id}.json`` (+ array at ``/styles.json``)
|
||||
* Styles are served at ``/styles/{id}/style.json`` (+ array at ``/styles.json``)
|
||||
|
||||
* Sprites at ``/styles/{id}/sprite[@2x].{format}``
|
||||
* Fonts at ``/fonts/{fontstack}/{start}-{end}.pbf``
|
||||
|
||||
Rendered tiles
|
||||
==============
|
||||
* Rendered tiles are served at ``/styles/{id}/rendered/{z}/{x}/{y}[@2x].{format}``
|
||||
* Rendered tiles are served at ``/styles/{id}/{z}/{x}/{y}[@2x].{format}``
|
||||
|
||||
* The optional ``@2x`` (or ``@3x``, ``@4x``) part can be used to render HiDPI (retina) tiles
|
||||
* Available formats: ``png``, ``jpg`` (``jpeg``), ``webp``
|
||||
* TileJSON at ``/styles/{id}/rendered.json``
|
||||
* TileJSON at ``/styles/{id}.json``
|
||||
|
||||
* The rendered tiles are not available in the ``tileserver-gl-light`` version.
|
||||
|
||||
@@ -64,3 +64,10 @@ Array of all TileJSONs is at ``/index.json`` (``/rendered.json``; ``/data.json``
|
||||
List of available fonts
|
||||
=======================
|
||||
Array of names of the available fonts is at ``/fonts.json``
|
||||
|
||||
Health check
|
||||
============
|
||||
Endpoint reporting health status is at ``/health`` and currently returns:
|
||||
|
||||
* ``503`` Starting - for a short period before everything is initialized
|
||||
* ``200`` OK - when the server is running
|
||||
|
||||
@@ -41,7 +41,7 @@ Alternatively, you can use ``tileserver-gl-light`` package instead, which is pur
|
||||
From source
|
||||
===========
|
||||
|
||||
Make sure you have Node v4 (nvm install 4) and run::
|
||||
Make sure you have Node v6 (nvm install 6) and run::
|
||||
|
||||
npm install
|
||||
node .
|
||||
|
||||
26
package.json
26
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tileserver-gl",
|
||||
"version": "1.5.0",
|
||||
"version": "2.0.0",
|
||||
"description": "Map tile server for JSON GL styles - vector and server side generated raster tiles",
|
||||
"main": "src/main.js",
|
||||
"bin": "src/main.js",
|
||||
@@ -13,34 +13,34 @@
|
||||
},
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=4.2.1 <5"
|
||||
"node": ">=6 <7"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha test/**.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "2.2.0",
|
||||
"@mapbox/mapbox-gl-native": "3.5.4",
|
||||
"@mapbox/mbtiles": "0.9.0",
|
||||
"@mapbox/sphericalmercator": "1.0.5",
|
||||
"@mapbox/vector-tile": "1.3.0",
|
||||
"advanced-pool": "0.3.2",
|
||||
"base64url": "2.0.0",
|
||||
"canvas": "1.6.5",
|
||||
"clone": "2.1.1",
|
||||
"color": "1.0.3",
|
||||
"cors": "2.8.2",
|
||||
"express": "4.15.2",
|
||||
"cors": "2.8.3",
|
||||
"express": "4.15.3",
|
||||
"glyph-pbf-composite": "0.0.2",
|
||||
"handlebars": "4.0.6",
|
||||
"mbtiles": "0.9.0",
|
||||
"morgan": "1.8.1",
|
||||
"handlebars": "4.0.10",
|
||||
"http-shutdown": "^1.2.0",
|
||||
"morgan": "1.8.2",
|
||||
"node-pngquant-native": "1.0.4",
|
||||
"nomnom": "1.8.1",
|
||||
"pbf": "3.0.5",
|
||||
"proj4": "2.4.3",
|
||||
"request": "2.81.0",
|
||||
"sharp": "0.17.2",
|
||||
"tileserver-gl-styles": "1.1.1",
|
||||
"vector-tile": "1.3.0",
|
||||
"@mapbox/mapbox-gl-native": "3.4.4",
|
||||
"@mapbox/sphericalmercator": "1.0.5"
|
||||
"sharp": "0.18.1",
|
||||
"tileserver-gl-styles": "1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"should": "^11.2.0",
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
{{#each styles}}
|
||||
<div class="item">
|
||||
{{#if thumbnail}}
|
||||
<img src="/styles/{{@key}}/rendered/{{thumbnail}}{{&../key_query}}" alt="{{name}} preview" />
|
||||
<img src="/styles/{{@key}}/{{thumbnail}}{{&../key_query}}" alt="{{name}} preview" />
|
||||
{{else}}
|
||||
<img src="/images/placeholder.png" alt="{{name}} preview" />
|
||||
{{/if}}
|
||||
@@ -35,10 +35,10 @@
|
||||
<p class="services">
|
||||
services:
|
||||
{{#if serving_data}}
|
||||
<a href="/styles/{{@key}}.json{{&../key_query}}">GL Style</a>
|
||||
<a href="/styles/{{@key}}/style.json{{&../key_query}}">GL Style</a>
|
||||
{{/if}}
|
||||
{{#if serving_rendered}}
|
||||
{{#if serving_data}}| {{/if}}<a href="/styles/{{@key}}/rendered.json{{&../key_query}}">TileJSON</a>
|
||||
{{#if serving_data}}| {{/if}}<a href="/styles/{{@key}}.json{{&../key_query}}">TileJSON</a>
|
||||
{{/if}}
|
||||
{{#if wmts_link}}
|
||||
| <a href="{{&wmts_link}}">WMTS</a>
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
mapboxgl.setRTLTextPlugin('/mapbox-gl-rtl-text.js{{&key_query}}');
|
||||
var map = new mapboxgl.Map({
|
||||
container: 'map',
|
||||
style: '/styles/{{id}}.json{{&key_query}}',
|
||||
style: '/styles/{{id}}/style.json{{&key_query}}',
|
||||
hash: true
|
||||
});
|
||||
map.addControl(new mapboxgl.NavigationControl());
|
||||
} else {
|
||||
var map = L.mapbox.map('map', '/styles/{{id}}/rendered.json{{&key_query}}', { zoomControl: false });
|
||||
var map = L.mapbox.map('map', '/styles/{{id}}.json{{&key_query}}', { zoomControl: false });
|
||||
new L.Control.Zoom({ position: 'topright' }).addTo(map);
|
||||
setTimeout(function() {
|
||||
new L.Hash(map);
|
||||
|
||||
15
src/main.js
15
src/main.js
@@ -6,7 +6,7 @@ var fs = require('fs'),
|
||||
path = require('path'),
|
||||
request = require('request');
|
||||
|
||||
var mbtiles = require('mbtiles');
|
||||
var mbtiles = require('@mapbox/mbtiles');
|
||||
|
||||
var packageJson = require('../package');
|
||||
|
||||
@@ -32,6 +32,10 @@ var opts = require('nomnom')
|
||||
default: 8080,
|
||||
help: 'Port'
|
||||
})
|
||||
.option('cors', {
|
||||
default: true,
|
||||
help: 'Enable Cross-origin resource sharing headers'
|
||||
})
|
||||
.option('verbose', {
|
||||
abbr: 'V',
|
||||
flag: true,
|
||||
@@ -54,7 +58,8 @@ var startServer = function(configPath, config) {
|
||||
configPath: configPath,
|
||||
config: config,
|
||||
bind: opts.bind,
|
||||
port: opts.port
|
||||
port: opts.port,
|
||||
cors: opts.cors
|
||||
});
|
||||
};
|
||||
|
||||
@@ -70,6 +75,12 @@ var startWithMBTiles = function(mbtilesFile) {
|
||||
}
|
||||
var instance = new mbtiles(mbtilesFile, function(err) {
|
||||
instance.getInfo(function(err, info) {
|
||||
if (err || !info) {
|
||||
console.log('ERROR: Metadata missing in the MBTiles.');
|
||||
console.log(' Make sure ' + path.basename(mbtilesFile) +
|
||||
' is valid MBTiles.');
|
||||
process.exit(1);
|
||||
}
|
||||
var bounds = info.bounds;
|
||||
|
||||
var styleDir = path.resolve(__dirname, "../node_modules/tileserver-gl-styles/");
|
||||
|
||||
@@ -6,9 +6,9 @@ var fs = require('fs'),
|
||||
|
||||
var clone = require('clone'),
|
||||
express = require('express'),
|
||||
mbtiles = require('mbtiles'),
|
||||
mbtiles = require('@mapbox/mbtiles'),
|
||||
pbf = require('pbf'),
|
||||
VectorTile = require('vector-tile').VectorTile;
|
||||
VectorTile = require('@mapbox/vector-tile').VectorTile;
|
||||
|
||||
var tileshrinkGl;
|
||||
try {
|
||||
@@ -34,20 +34,24 @@ module.exports = function(options, repo, params, id, styles) {
|
||||
if (!mbtilesFileStats.isFile() || mbtilesFileStats.size == 0) {
|
||||
throw Error('Not valid MBTiles file: ' + mbtilesFile);
|
||||
}
|
||||
var source = new mbtiles(mbtilesFile, function(err) {
|
||||
source.getInfo(function(err, info) {
|
||||
tileJSON['name'] = id;
|
||||
tileJSON['format'] = 'pbf';
|
||||
var source;
|
||||
var sourceInfoPromise = new Promise(function(resolve, reject) {
|
||||
source = new mbtiles(mbtilesFile, function(err) {
|
||||
source.getInfo(function(err, info) {
|
||||
tileJSON['name'] = id;
|
||||
tileJSON['format'] = 'pbf';
|
||||
|
||||
Object.assign(tileJSON, info);
|
||||
Object.assign(tileJSON, info);
|
||||
|
||||
tileJSON['tilejson'] = '2.0.0';
|
||||
delete tileJSON['filesize'];
|
||||
delete tileJSON['mtime'];
|
||||
delete tileJSON['scheme'];
|
||||
tileJSON['tilejson'] = '2.0.0';
|
||||
delete tileJSON['filesize'];
|
||||
delete tileJSON['mtime'];
|
||||
delete tileJSON['scheme'];
|
||||
|
||||
Object.assign(tileJSON, params.tilejson || {});
|
||||
utils.fixTileJSONCenter(tileJSON);
|
||||
Object.assign(tileJSON, params.tilejson || {});
|
||||
utils.fixTileJSONCenter(tileJSON);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -161,5 +165,9 @@ module.exports = function(options, repo, params, id, styles) {
|
||||
return res.send(info);
|
||||
});
|
||||
|
||||
return app;
|
||||
return new Promise(function(resolve, reject) {
|
||||
sourceInfoPromise.then(function() {
|
||||
resolve(app);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -15,16 +15,19 @@ module.exports = function(options, allowedFonts) {
|
||||
var fontPath = options.paths.fonts;
|
||||
|
||||
var existingFonts = {};
|
||||
fs.readdir(options.paths.fonts, function(err, files) {
|
||||
files.forEach(function(file) {
|
||||
fs.stat(path.join(fontPath, file), function(err, stats) {
|
||||
if (!err) {
|
||||
if (stats.isDirectory() &&
|
||||
fs.existsSync(path.join(fontPath, file, '0-255.pbf'))) {
|
||||
existingFonts[path.basename(file)] = true;
|
||||
var fontListingPromise = new Promise(function(resolve, reject) {
|
||||
fs.readdir(options.paths.fonts, function(err, files) {
|
||||
files.forEach(function(file) {
|
||||
fs.stat(path.join(fontPath, file), function(err, stats) {
|
||||
if (!err) {
|
||||
if (stats.isDirectory() &&
|
||||
fs.existsSync(path.join(fontPath, file, '0-255.pbf'))) {
|
||||
existingFonts[path.basename(file)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,19 +36,15 @@ module.exports = function(options, allowedFonts) {
|
||||
var fontstack = decodeURI(req.params.fontstack);
|
||||
var range = req.params.range;
|
||||
|
||||
return utils.getFontsPbf(options.serveAllFonts ? null : allowedFonts,
|
||||
fontPath, fontstack, range, existingFonts,
|
||||
function(err, concated) {
|
||||
if (err || concated.length === 0) {
|
||||
console.log(err);
|
||||
console.log(concated.length);
|
||||
return res.status(400).send('');
|
||||
} else {
|
||||
utils.getFontsPbf(options.serveAllFonts ? null : allowedFonts,
|
||||
fontPath, fontstack, range, existingFonts).then(function(concated) {
|
||||
res.header('Content-type', 'application/x-protobuf');
|
||||
res.header('Last-Modified', lastModified);
|
||||
return res.send(concated);
|
||||
}, function(err) {
|
||||
return res.status(400).send(err);
|
||||
}
|
||||
});
|
||||
);
|
||||
});
|
||||
|
||||
app.get('/fonts.json', function(req, res, next) {
|
||||
@@ -55,5 +54,9 @@ module.exports = function(options, allowedFonts) {
|
||||
);
|
||||
});
|
||||
|
||||
return app;
|
||||
return new Promise(function(resolve, reject) {
|
||||
fontListingPromise.then(function() {
|
||||
resolve(app);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
advancedPool = require('advanced-pool'),
|
||||
var advancedPool = require('advanced-pool'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
util = require('util'),
|
||||
@@ -17,7 +16,7 @@ var Canvas = require('canvas'),
|
||||
express = require('express'),
|
||||
mercator = new (require('@mapbox/sphericalmercator'))(),
|
||||
mbgl = require('@mapbox/mapbox-gl-native'),
|
||||
mbtiles = require('mbtiles'),
|
||||
mbtiles = require('@mapbox/mbtiles'),
|
||||
pngquant = require('node-pngquant-native'),
|
||||
proj4 = require('proj4'),
|
||||
request = require('request');
|
||||
@@ -59,15 +58,18 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
};
|
||||
|
||||
var existingFonts = {};
|
||||
fs.readdir(options.paths.fonts, function(err, files) {
|
||||
files.forEach(function(file) {
|
||||
fs.stat(path.join(options.paths.fonts, file), function(err, stats) {
|
||||
if (!err) {
|
||||
if (stats.isDirectory()) {
|
||||
existingFonts[path.basename(file)] = true;
|
||||
var fontListingPromise = new Promise(function(resolve, reject) {
|
||||
fs.readdir(options.paths.fonts, function(err, files) {
|
||||
files.forEach(function(file) {
|
||||
fs.stat(path.join(options.paths.fonts, file), function(err, stats) {
|
||||
if (!err) {
|
||||
if (stats.isDirectory()) {
|
||||
existingFonts[path.basename(file)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -89,9 +91,12 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
var parts = req.url.split('/');
|
||||
var fontstack = unescape(parts[2]);
|
||||
var range = parts[3].split('.')[0];
|
||||
utils.getFontsPbf(null, options.paths[protocol], fontstack, range, existingFonts,
|
||||
function(err, concated) {
|
||||
callback(err, {data: concated});
|
||||
utils.getFontsPbf(
|
||||
null, options.paths[protocol], fontstack, range, existingFonts
|
||||
).then(function(concated) {
|
||||
callback(null, {data: concated});
|
||||
}, function(err) {
|
||||
callback(err, {data: null});
|
||||
});
|
||||
} else if (protocol == 'mbtiles') {
|
||||
var parts = req.url.split('/');
|
||||
@@ -166,7 +171,7 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
});
|
||||
};
|
||||
|
||||
var styleJSONPath = path.join(options.paths.styles, styleFile);
|
||||
var styleJSONPath = path.resolve(options.paths.styles, styleFile);
|
||||
styleJSON = clone(require(styleJSONPath));
|
||||
|
||||
var httpTester = /^(http(s)?:)?\/\//;
|
||||
@@ -218,12 +223,12 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
}
|
||||
mbtilesFile = dataResolver(mbtilesFile);
|
||||
if (!mbtilesFile) {
|
||||
console.log('ERROR: data "' + mbtilesFile + '" not found!');
|
||||
console.error('ERROR: data "' + mbtilesFile + '" not found!');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
queue.push(function(callback) {
|
||||
queue.push(new Promise(function(resolve, reject) {
|
||||
mbtilesFile = path.resolve(options.paths.mbtiles, mbtilesFile);
|
||||
var mbtilesFileStats = fs.statSync(mbtilesFile);
|
||||
if (!mbtilesFileStats.isFile() || mbtilesFileStats.size == 0) {
|
||||
@@ -233,6 +238,7 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
map.sources[name].getInfo(function(err, info) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dataProjWGStoInternalWGS && info.proj4) {
|
||||
@@ -279,14 +285,14 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
}
|
||||
tileJSON.attribution += source.attribution;
|
||||
}
|
||||
callback(null);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
async.parallel(queue, function(err, results) {
|
||||
var renderersReadyPromise = Promise.all(queue).then(function() {
|
||||
// TODO: make pool sizes configurable
|
||||
for (var s = 1; s <= maxScaleFactor; s++) {
|
||||
var minPoolSize = 2;
|
||||
@@ -304,17 +310,19 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
|
||||
repo[id] = tileJSON;
|
||||
|
||||
var tilePattern = '/rendered/:z(\\d+)/:x(\\d+)/:y(\\d+)' +
|
||||
var tilePattern = '/' + id + '/:z(\\d+)/:x(\\d+)/:y(\\d+)' +
|
||||
':scale(' + scalePattern + ')?\.:format([\\w]+)';
|
||||
|
||||
var respondImage = function(z, lon, lat, bearing, pitch,
|
||||
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) {
|
||||
return res.status(400).send('Invalid center');
|
||||
}
|
||||
if (Math.min(width, height) <= 0 ||
|
||||
Math.max(width, height) * scale > (options.maxSize || 2048)) {
|
||||
Math.max(width, height) * scale > (options.maxSize || 2048) ||
|
||||
width != width || height != height) {
|
||||
return res.status(400).send('Invalid size');
|
||||
}
|
||||
if (format == 'png' || format == 'webp') {
|
||||
@@ -341,7 +349,10 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
}
|
||||
renderer.render(params, function(err, data) {
|
||||
pool.release(renderer);
|
||||
if (err) console.log(err);
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var image = sharp(data, {
|
||||
raw: {
|
||||
@@ -466,9 +477,19 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
return [px[0] * scale, px[1] * scale];
|
||||
};
|
||||
|
||||
var center = precisePx([x, y], z);
|
||||
|
||||
var mapHeight = 512 * (1 << z);
|
||||
var maxEdge = center[1] + h / 2;
|
||||
var minEdge = center[1] - h / 2;
|
||||
if (maxEdge > mapHeight) {
|
||||
center[1] -= (maxEdge - mapHeight);
|
||||
} else if (minEdge < 0) {
|
||||
center[1] -= minEdge;
|
||||
}
|
||||
|
||||
var canvas = new Canvas(scale * w, scale * h);
|
||||
var ctx = canvas.getContext('2d');
|
||||
var center = precisePx([x, y], z);
|
||||
ctx.scale(scale, scale);
|
||||
if (bearing) {
|
||||
ctx.translate(w / 2, h / 2);
|
||||
@@ -523,7 +544,7 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
|
||||
if (options.serveStaticMaps !== false) {
|
||||
var staticPattern =
|
||||
'/static/:raw(raw)?/%s/:width(\\d+)x:height(\\d+)' +
|
||||
'/' + id + '/static/:raw(raw)?/%s/:width(\\d+)x:height(\\d+)' +
|
||||
':scale(' + scalePattern + ')?\.:format([\\w]+)';
|
||||
|
||||
var centerPattern =
|
||||
@@ -564,14 +585,11 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
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 serveBounds = function(req, res, next) {
|
||||
var raw = req.params.raw;
|
||||
var bbox = [+req.params.minx, +req.params.miny,
|
||||
+req.params.maxx, +req.params.maxy];
|
||||
var center = [(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2];
|
||||
|
||||
var transformer = raw ?
|
||||
mercator.inverse.bind(mercator) : dataProjWGStoInternalWGS;
|
||||
@@ -583,6 +601,7 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
bbox[1] = minCorner[1];
|
||||
bbox[2] = maxCorner[0];
|
||||
bbox[3] = maxCorner[1];
|
||||
center = transformer(center);
|
||||
}
|
||||
|
||||
var w = req.params.width | 0,
|
||||
@@ -591,8 +610,8 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
format = req.params.format;
|
||||
|
||||
var z = calcZForBBox(bbox, w, h, req.query),
|
||||
x = (bbox[0] + bbox[2]) / 2,
|
||||
y = (bbox[1] + bbox[3]) / 2,
|
||||
x = center[0],
|
||||
y = center[1],
|
||||
bearing = 0,
|
||||
pitch = 0;
|
||||
|
||||
@@ -601,6 +620,34 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
path, req.query);
|
||||
return respondImage(z, x, y, bearing, pitch, w, h, scale, format,
|
||||
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), serveBounds);
|
||||
|
||||
app.get('/' + id + '/static/', function(req, res, next) {
|
||||
for (var key in req.query) {
|
||||
req.query[key.toLowerCase()] = req.query[key];
|
||||
}
|
||||
req.params.raw = true;
|
||||
req.params.format = (req.query.format || 'image/png').split('/').pop();
|
||||
var bbox = (req.query.bbox || '').split(',');
|
||||
req.params.minx = bbox[0];
|
||||
req.params.miny = bbox[1];
|
||||
req.params.maxx = bbox[2];
|
||||
req.params.maxy = bbox[3];
|
||||
req.params.width = req.query.width || '256';
|
||||
req.params.height = req.query.height || '256';
|
||||
if (req.query.scale) {
|
||||
req.params.width /= req.query.scale;
|
||||
req.params.height /= req.query.scale;
|
||||
req.params.scale = '@' + req.query.scale;
|
||||
}
|
||||
|
||||
return serveBounds(req, res, next);
|
||||
});
|
||||
|
||||
var autoPattern = 'auto';
|
||||
@@ -630,9 +677,14 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
bbox[3] = Math.max(bbox[3], pair[1]);
|
||||
});
|
||||
|
||||
var bbox_ = mercator.convert(bbox, '900913');
|
||||
var center = mercator.inverse(
|
||||
[(bbox_[0] + bbox_[2]) / 2, (bbox_[1] + bbox_[3]) / 2]
|
||||
);
|
||||
|
||||
var z = calcZForBBox(bbox, w, h, req.query),
|
||||
x = (bbox[0] + bbox[2]) / 2,
|
||||
y = (bbox[1] + bbox[3]) / 2;
|
||||
x = center[0],
|
||||
y = center[1];
|
||||
|
||||
var overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale,
|
||||
path, req.query);
|
||||
@@ -642,12 +694,16 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
});
|
||||
}
|
||||
|
||||
app.get('/rendered.json', function(req, res, next) {
|
||||
app.get('/' + id + '.json', function(req, res, next) {
|
||||
var info = clone(tileJSON);
|
||||
info.tiles = utils.getTileUrls(req, info.tiles,
|
||||
'styles/' + id + '/rendered', info.format);
|
||||
'styles/' + id, info.format);
|
||||
return res.send(info);
|
||||
});
|
||||
|
||||
return app;
|
||||
return new Promise(function(resolve, reject) {
|
||||
Promise.all([fontListingPromise, renderersReadyPromise]).then(function() {
|
||||
resolve(app);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ var clone = require('clone'),
|
||||
module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||
var app = express().disable('x-powered-by');
|
||||
|
||||
var styleFile = path.join(options.paths.styles, params.style);
|
||||
var styleFile = path.resolve(options.paths.styles, params.style);
|
||||
|
||||
var styleJSON = clone(require(styleFile));
|
||||
Object.keys(styleJSON.sources).forEach(function(name) {
|
||||
@@ -62,7 +62,7 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||
|
||||
repo[id] = styleJSON;
|
||||
|
||||
app.get('/' + id + '.json', function(req, res, next) {
|
||||
app.get('/' + id + '/style.json', function(req, res, next) {
|
||||
var fixUrl = function(url, opt_nokey, opt_nostyle) {
|
||||
if (!url || (typeof url !== 'string') || url.indexOf('local://') !== 0) {
|
||||
return url;
|
||||
@@ -117,5 +117,5 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||
});
|
||||
});
|
||||
|
||||
return app;
|
||||
return Promise.resolve(app);
|
||||
};
|
||||
|
||||
163
src/server.js
163
src/server.js
@@ -10,6 +10,7 @@ var fs = require('fs'),
|
||||
var base64url = require('base64url'),
|
||||
clone = require('clone'),
|
||||
cors = require('cors'),
|
||||
enableShutdown = require('http-shutdown'),
|
||||
express = require('express'),
|
||||
handlebars = require('handlebars'),
|
||||
mercator = new (require('@mapbox/sphericalmercator'))(),
|
||||
@@ -28,7 +29,7 @@ if (!isLight) {
|
||||
serve_rendered = require('./serve_rendered');
|
||||
}
|
||||
|
||||
module.exports = function(opts, callback) {
|
||||
function start(opts) {
|
||||
console.log('Starting server');
|
||||
|
||||
var app = express().disable('x-powered-by'),
|
||||
@@ -41,10 +42,9 @@ module.exports = function(opts, callback) {
|
||||
|
||||
app.enable('trust proxy');
|
||||
|
||||
callback = callback || function() {};
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' &&
|
||||
process.env.NODE_ENV !== 'test') {
|
||||
if (process.env.NODE_ENV == 'production') {
|
||||
app.use(morgan('tiny'));
|
||||
} else if (process.env.NODE_ENV !== 'test') {
|
||||
app.use(morgan('dev'));
|
||||
}
|
||||
|
||||
@@ -76,6 +76,8 @@ module.exports = function(opts, callback) {
|
||||
paths.sprites = path.resolve(paths.root, paths.sprites || '');
|
||||
paths.mbtiles = path.resolve(paths.root, paths.mbtiles || '');
|
||||
|
||||
var startupPromises = [];
|
||||
|
||||
var checkPath = function(type) {
|
||||
if (!fs.existsSync(paths[type])) {
|
||||
console.error('The specified path for "' + type + '" does not exist (' + paths[type] + ').');
|
||||
@@ -89,7 +91,9 @@ module.exports = function(opts, callback) {
|
||||
|
||||
var data = clone(config.data || {});
|
||||
|
||||
app.use(cors());
|
||||
if (opts.cors) {
|
||||
app.use(cors());
|
||||
}
|
||||
|
||||
Object.keys(config.styles || {}).forEach(function(id) {
|
||||
var item = config.styles[id];
|
||||
@@ -99,7 +103,7 @@ module.exports = function(opts, callback) {
|
||||
}
|
||||
|
||||
if (item.serve_data !== false) {
|
||||
app.use('/styles/', serve_style(options, serving.styles, item, id,
|
||||
startupPromises.push(serve_style(options, serving.styles, item, id,
|
||||
function(mbtiles, fromData) {
|
||||
var dataItemId;
|
||||
Object.keys(data).forEach(function(id) {
|
||||
@@ -128,28 +132,38 @@ module.exports = function(opts, callback) {
|
||||
}
|
||||
}, function(font) {
|
||||
serving.fonts[font] = true;
|
||||
}).then(function(sub) {
|
||||
app.use('/styles/', sub);
|
||||
}));
|
||||
}
|
||||
if (item.serve_rendered !== false) {
|
||||
if (serve_rendered) {
|
||||
app.use('/styles/' + id + '/',
|
||||
serve_rendered(options, serving.rendered, item, id,
|
||||
function(mbtiles) {
|
||||
var mbtilesFile;
|
||||
Object.keys(data).forEach(function(id) {
|
||||
if (id == mbtiles) {
|
||||
mbtilesFile = data[id].mbtiles;
|
||||
startupPromises.push(
|
||||
serve_rendered(options, serving.rendered, item, id,
|
||||
function(mbtiles) {
|
||||
var mbtilesFile;
|
||||
Object.keys(data).forEach(function(id) {
|
||||
if (id == mbtiles) {
|
||||
mbtilesFile = data[id].mbtiles;
|
||||
}
|
||||
});
|
||||
return mbtilesFile;
|
||||
}
|
||||
});
|
||||
return mbtilesFile;
|
||||
}));
|
||||
).then(function(sub) {
|
||||
app.use('/styles/', sub);
|
||||
})
|
||||
);
|
||||
} else {
|
||||
item.serve_rendered = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
app.use('/', serve_font(options, serving.fonts));
|
||||
startupPromises.push(
|
||||
serve_font(options, serving.fonts).then(function(sub) {
|
||||
app.use('/', sub);
|
||||
})
|
||||
);
|
||||
|
||||
Object.keys(data).forEach(function(id) {
|
||||
var item = data[id];
|
||||
@@ -158,7 +172,11 @@ module.exports = function(opts, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.use('/data/', serve_data(options, serving.data, item, id, serving.styles));
|
||||
startupPromises.push(
|
||||
serve_data(options, serving.data, item, id, serving.styles).then(function(sub) {
|
||||
app.use('/data/', sub);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
app.get('/styles.json', function(req, res, next) {
|
||||
@@ -171,7 +189,7 @@ module.exports = function(opts, callback) {
|
||||
name: styleJSON.name,
|
||||
id: id,
|
||||
url: req.protocol + '://' + req.headers.host +
|
||||
'/styles/' + id + '.json' + query
|
||||
'/styles/' + id + '/style.json' + query
|
||||
});
|
||||
});
|
||||
res.send(result);
|
||||
@@ -182,7 +200,7 @@ module.exports = function(opts, callback) {
|
||||
var info = clone(serving[type][id]);
|
||||
var path = '';
|
||||
if (type == 'rendered') {
|
||||
path = 'styles/' + id + '/rendered';
|
||||
path = 'styles/' + id;
|
||||
} else {
|
||||
path = type + '/' + id;
|
||||
}
|
||||
@@ -219,28 +237,32 @@ module.exports = function(opts, callback) {
|
||||
templateFile = path.resolve(paths.root, options.frontPage);
|
||||
}
|
||||
}
|
||||
fs.readFile(templateFile, function(err, content) {
|
||||
if (err) {
|
||||
console.error('Template not found:', err);
|
||||
}
|
||||
var compiled = handlebars.compile(content.toString());
|
||||
|
||||
app.use(urlPath, function(req, res, next) {
|
||||
var data = {};
|
||||
if (dataGetter) {
|
||||
data = dataGetter(req);
|
||||
if (!data) {
|
||||
return res.status(404).send('Not found');
|
||||
}
|
||||
startupPromises.push(new Promise(function(resolve, reject) {
|
||||
fs.readFile(templateFile, function(err, content) {
|
||||
if (err) {
|
||||
console.error('Template not found:', err);
|
||||
reject(err);
|
||||
}
|
||||
data['server_version'] = packageJson.name + ' v' + packageJson.version;
|
||||
data['is_light'] = isLight;
|
||||
data['key_query_part'] =
|
||||
req.query.key ? 'key=' + req.query.key + '&' : '';
|
||||
data['key_query'] = req.query.key ? '?key=' + req.query.key : '';
|
||||
return res.status(200).send(compiled(data));
|
||||
var compiled = handlebars.compile(content.toString());
|
||||
|
||||
app.use(urlPath, function(req, res, next) {
|
||||
var data = {};
|
||||
if (dataGetter) {
|
||||
data = dataGetter(req);
|
||||
if (!data) {
|
||||
return res.status(404).send('Not found');
|
||||
}
|
||||
}
|
||||
data['server_version'] = packageJson.name + ' v' + packageJson.version;
|
||||
data['is_light'] = isLight;
|
||||
data['key_query_part'] =
|
||||
req.query.key ? 'key=' + req.query.key + '&' : '';
|
||||
data['key_query'] = req.query.key ? '?key=' + req.query.key : '';
|
||||
return res.status(200).send(compiled(data));
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}));
|
||||
};
|
||||
|
||||
serveTemplate('/$', 'index', function(req) {
|
||||
@@ -266,11 +288,11 @@ module.exports = function(opts, callback) {
|
||||
var query = req.query.key ? ('?key=' + req.query.key) : '';
|
||||
style.wmts_link = 'http://wmts.maptiler.com/' +
|
||||
base64url('http://' + req.headers.host +
|
||||
'/styles/' + id + '/rendered.json' + query) + '/wmts';
|
||||
'/styles/' + id + '.json' + query) + '/wmts';
|
||||
|
||||
var tiles = utils.getTileUrls(
|
||||
req, style.serving_rendered.tiles,
|
||||
'styles/' + id + '/rendered', style.serving_rendered.format);
|
||||
'styles/' + id, style.serving_rendered.format);
|
||||
style.xyz_link = tiles[0];
|
||||
}
|
||||
});
|
||||
@@ -353,20 +375,57 @@ module.exports = function(opts, callback) {
|
||||
return data;
|
||||
});
|
||||
|
||||
var startupComplete = false;
|
||||
var startupPromise = Promise.all(startupPromises).then(function() {
|
||||
console.log('Startup complete');
|
||||
startupComplete = true;
|
||||
});
|
||||
app.get('/health', function(req, res, next) {
|
||||
if (startupComplete) {
|
||||
return res.status(200).send('OK');
|
||||
} else {
|
||||
return res.status(503).send('Starting');
|
||||
}
|
||||
});
|
||||
|
||||
var server = app.listen(process.env.PORT || opts.port, process.env.BIND || opts.bind, function() {
|
||||
console.log('Listening at http://%s:%d/',
|
||||
this.address().address, this.address().port);
|
||||
|
||||
return callback();
|
||||
var address = this.address().address;
|
||||
if (address.indexOf('::') === 0) {
|
||||
address = '[' + address + ']'; // literal IPv6 address
|
||||
}
|
||||
console.log('Listening at http://%s:%d/', address, this.address().port);
|
||||
});
|
||||
|
||||
process.on('SIGINT', function() {
|
||||
process.exit();
|
||||
});
|
||||
// add server.shutdown() to gracefully stop serving
|
||||
enableShutdown(server);
|
||||
|
||||
setTimeout(callback, 1000);
|
||||
return {
|
||||
app: app,
|
||||
server: server
|
||||
server: server,
|
||||
startupPromise: startupPromise
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = function(opts) {
|
||||
var running = start(opts);
|
||||
|
||||
process.on('SIGINT', function() {
|
||||
process.exit();
|
||||
});
|
||||
|
||||
process.on('SIGHUP', function() {
|
||||
console.log('Stopping server and reloading config');
|
||||
|
||||
running.server.shutdown(function() {
|
||||
for (var key in require.cache) {
|
||||
delete require.cache[key];
|
||||
}
|
||||
|
||||
var restarted = start(opts);
|
||||
running.server = restarted.server;
|
||||
running.app = restarted.app;
|
||||
});
|
||||
});
|
||||
|
||||
return running;
|
||||
};
|
||||
|
||||
49
src/utils.js
49
src/utils.js
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
path = require('path'),
|
||||
var path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
var clone = require('clone'),
|
||||
@@ -73,47 +72,47 @@ module.exports.fixTileJSONCenter = function(tileJSON) {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.getFontsPbf = function(allowedFonts, fontPath, names, range, fallbacks, callback) {
|
||||
var getFontPbf = function(allowedFonts, name, range, callback, fallbacks) {
|
||||
var getFontPbf = function(allowedFonts, fontPath, name, range, fallbacks) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (!allowedFonts || (allowedFonts[name] && fallbacks)) {
|
||||
var filename = path.join(fontPath, name, range + '.pbf');
|
||||
if (!fallbacks) {
|
||||
fallbacks = clone(allowedFonts || {});
|
||||
}
|
||||
delete fallbacks[name];
|
||||
return fs.readFile(filename, function(err, data) {
|
||||
fs.readFile(filename, function(err, data) {
|
||||
if (err) {
|
||||
console.error('ERROR: Font not found:', name);
|
||||
if (fallbacks && Object.keys(fallbacks).length) {
|
||||
var fallbackName = Object.keys(fallbacks)[0];
|
||||
console.error('ERROR: Trying to use', fallbackName, 'as a fallback');
|
||||
delete fallbacks[fallbackName];
|
||||
return getFontPbf(null, fallbackName, range, callback, fallbacks);
|
||||
getFontPbf(null, fontPath, fallbackName, range, fallbacks).then(resolve, reject);
|
||||
} else {
|
||||
return callback(new Error('Font load error: ' + name));
|
||||
reject('Font load error: ' + name);
|
||||
}
|
||||
} else {
|
||||
return callback(null, data);
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return callback(new Error('Font not allowed: ' + name));
|
||||
}
|
||||
};
|
||||
|
||||
var fonts = names.split(',');
|
||||
var queue = [];
|
||||
fonts.forEach(function(font) {
|
||||
queue.push(function(callback) {
|
||||
getFontPbf(allowedFonts, font, range, callback, clone(allowedFonts || fallbacks));
|
||||
});
|
||||
});
|
||||
|
||||
return async.parallel(queue, function(err, results) {
|
||||
if (err) {
|
||||
callback(err, new Buffer([]));
|
||||
} else {
|
||||
callback(err, glyphCompose.combine(results));
|
||||
reject('Font not allowed: ' + name);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getFontsPbf = function(allowedFonts, fontPath, names, range, fallbacks) {
|
||||
var fonts = names.split(',');
|
||||
var queue = [];
|
||||
fonts.forEach(function(font) {
|
||||
queue.push(
|
||||
getFontPbf(allowedFonts, fontPath, font, range, clone(allowedFonts || fallbacks))
|
||||
);
|
||||
});
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
Promise.all(queue).then(function(values) {
|
||||
return resolve(glyphCompose.combine(values));
|
||||
}, reject);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -38,6 +38,14 @@ var testTileJSON = function(url) {
|
||||
};
|
||||
|
||||
describe('Metadata', function() {
|
||||
describe('/health', function() {
|
||||
it('returns 200', function(done) {
|
||||
supertest(app)
|
||||
.get('/health')
|
||||
.expect(200, done);
|
||||
});
|
||||
});
|
||||
|
||||
testTileJSONArray('/index.json');
|
||||
testTileJSONArray('/rendered.json');
|
||||
testTileJSONArray('/data.json');
|
||||
@@ -63,6 +71,6 @@ describe('Metadata', function() {
|
||||
});
|
||||
});
|
||||
|
||||
testTileJSON('/styles/test-style/rendered.json');
|
||||
testTileJSON('/styles/test-style.json');
|
||||
testTileJSON('/data/openmaptiles.json');
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ before(function() {
|
||||
});
|
||||
global.app = running.app;
|
||||
global.server = running.server;
|
||||
return running.startupPromise;
|
||||
});
|
||||
|
||||
after(function() {
|
||||
|
||||
@@ -11,12 +11,12 @@ var testIs = function(url, type, status) {
|
||||
var prefix = 'test-style';
|
||||
|
||||
describe('Styles', function() {
|
||||
describe('/styles/' + prefix + '.json is valid style', function() {
|
||||
testIs('/styles/' + prefix + '.json', /application\/json/);
|
||||
describe('/styles/' + prefix + '/style.json is valid style', function() {
|
||||
testIs('/styles/' + prefix + '/style.json', /application\/json/);
|
||||
|
||||
it('contains expected properties', function(done) {
|
||||
supertest(app)
|
||||
.get('/styles/' + prefix + '.json')
|
||||
.get('/styles/' + prefix + '/style.json')
|
||||
.expect(function(res) {
|
||||
res.body.version.should.equal(8);
|
||||
res.body.name.should.be.String();
|
||||
@@ -27,8 +27,8 @@ describe('Styles', function() {
|
||||
}).end(done);
|
||||
});
|
||||
});
|
||||
describe('/styles/streets.json is not served', function() {
|
||||
testIs('/styles/streets.json', /./, 404);
|
||||
describe('/styles/streets/style.json is not served', function() {
|
||||
testIs('/styles/streets/style.json', /./, 404);
|
||||
});
|
||||
|
||||
describe('/styles/' + prefix + '/sprite[@2x].{format}', function() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var testTile = function(prefix, z, x, y, format, status, scale, type) {
|
||||
if (scale) y += '@' + scale + 'x';
|
||||
var path = '/styles/' + prefix + '/rendered/' + z + '/' + x + '/' + y + '.' + format;
|
||||
var path = '/styles/' + prefix + '/' + z + '/' + x + '/' + y + '.' + format;
|
||||
it(path + ' returns ' + status, function(done) {
|
||||
var test = supertest(app).get(path);
|
||||
test.expect(status);
|
||||
|
||||
Reference in New Issue
Block a user