Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 21883f490f | |||
| 70515947ca | |||
| 63090802ae | |||
| 131b5e2f81 | |||
| 6e085af7cc | |||
| 345d96d5e6 | |||
| f1c835c21d | |||
| 15ed6d74bf | |||
| a3d8240aac | |||
| 098f057e55 | |||
| 18ba6f5059 | |||
| 820dbdd3dd | |||
| acd7683f18 | |||
| 09859c10c1 | |||
| f201deecdc | |||
| b49521d2ed | |||
| 30c9bc8979 | |||
| 69340bbc83 | |||
| ff9d5a8e5d | |||
| 23c2aa54d0 | |||
| a8fd1b38b7 |
@@ -1,18 +1,46 @@
|
|||||||
|

|
||||||
|
|
||||||
|
|
||||||
# TileServer GL
|
# TileServer GL
|
||||||
[](https://travis-ci.org/klokantech/tileserver-gl)
|
[](https://travis-ci.org/klokantech/tileserver-gl)
|
||||||
[](https://hub.docker.com/r/klokantech/tileserver-gl/)
|
[](https://hub.docker.com/r/klokantech/tileserver-gl/)
|
||||||
|
|
||||||
|
Vector and raster maps with GL styles. Server side rendering by Mapbox GL Native. Map tile server for Mapbox GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.
|
||||||
|
|
||||||
## Quickstart
|
## Get Started
|
||||||
Use `npm install -g tileserver-gl` to install the package from npm.
|
|
||||||
|
|
||||||
Then you can simply run `tileserver-gl zurich_switzerland.mbtiles` to start the server for the given mbtiles.
|
Install `tileserver-gl` with server-side raster rendering of vector tiles with npm
|
||||||
|
|
||||||
Alternatively, you can use `tileserver-gl-light` package instead, which is pure javascript (does not have any native dependencies) and can run anywhere, but does not contain rasterization features.
|
```bash
|
||||||
|
npm install -g tileserver-gl
|
||||||
|
```
|
||||||
|
|
||||||
Or you can use `docker run -it -v $(pwd):/data -p 8080:80 klokantech/tileserver-gl` to run the server inside a docker container.
|
Now download vector tiles from [OSM2VectorTiles](http://osm2vectortiles.org/downloads/).
|
||||||
|
|
||||||
Prepared vector tiles can be downloaded from [OSM2VectorTiles](http://osm2vectortiles.org/).
|
```bash
|
||||||
|
curl -o zurich_switzerland.mbtiles https://osm2vectortiles-downloads.os.zhdk.cloud.switch.ch/v2.0/extracts/zurich_switzerland.mbtiles
|
||||||
|
```
|
||||||
|
|
||||||
|
Start `tileserver-gl` with the downloaded vector tiles.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tileserver-gl zurich_switzerland.mbtiles
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, you can use the `tileserver-gl-light` package instead, which is pure javascript (does not have any native dependencies) and can run anywhere, but does not contain rasterization on the server side made with MapBox GL Native.
|
||||||
|
|
||||||
|
## Using Docker
|
||||||
|
|
||||||
|
An alternative to npm to start the packed software easier is to install [Docker](http://www.docker.com/) on your computer and then run in the directory with the downloaded MBTiles the command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -it -v $(pwd):/data -p 8080:80 klokantech/tileserver-gl
|
||||||
|
```
|
||||||
|
|
||||||
|
This will download and start a ready to use container on your computer and the maps are going to be available in webbrowser on localhost:8080.
|
||||||
|
|
||||||
|
On laptop you can use [Docker Kitematic](https://kitematic.com/) and search "tileserver-gl" and run it, then drop in the 'data' folder the MBTiles.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
You can read full documentation of this project at http://tileserver.readthedocs.io/.
|
You can read full documentation of this project at http://tileserver.readthedocs.io/.
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# TileServer GL light
|
||||||
|
[](https://travis-ci.org/klokantech/tileserver-gl)
|
||||||
|
[](https://hub.docker.com/r/klokantech/tileserver-gl/)
|
||||||
|
|
||||||
|
Vector maps with GL styles. Map tile server for Mapbox Android, iOS, GL JS, Leaflet, OpenLayers, etc. without server side rendering.
|
||||||
|
|
||||||
|
## Quickstart
|
||||||
|
Use `npm install -g tileserver-gl-light` to install the package from npm.
|
||||||
|
|
||||||
|
Then you can simply run `tileserver-gl-light zurich_switzerland.mbtiles` to start the server for the given mbtiles.
|
||||||
|
|
||||||
|
See also `tileserver-gl` which contains server side rendering.
|
||||||
|
|
||||||
|
Prepared vector tiles can be downloaded from [OSM2VectorTiles](http://osm2vectortiles.org/).
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
You can read full documentation of this project at http://tileserver.readthedocs.io/.
|
||||||
@@ -27,3 +27,11 @@ Make sure you have Node v4 or higher (nvm install 4) and run::
|
|||||||
|
|
||||||
npm install
|
npm install
|
||||||
node .
|
node .
|
||||||
|
|
||||||
|
|
||||||
|
On OSX
|
||||||
|
======
|
||||||
|
|
||||||
|
Make sure to have ``pkg-config`` and ``cairo`` installed::
|
||||||
|
|
||||||
|
brew install pkg-config cairo
|
||||||
|
|||||||
+6
-6
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "tileserver-gl",
|
"name": "tileserver-gl",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"description": "Map tile server for JSON GL styles - serverside generated raster tiles",
|
"description": "Map tile server for JSON GL styles - vector and server side generated raster tiles",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"bin": "src/main.js",
|
"bin": "src/main.js",
|
||||||
"authors": [
|
"authors": [
|
||||||
@@ -19,19 +19,19 @@
|
|||||||
"async": "2.0.1",
|
"async": "2.0.1",
|
||||||
"advanced-pool": "0.3.2",
|
"advanced-pool": "0.3.2",
|
||||||
"base64url": "2.0.0",
|
"base64url": "2.0.0",
|
||||||
"canvas": "1.4.0",
|
"canvas": "1.5.0",
|
||||||
"clone": "1.0.2",
|
"clone": "1.0.2",
|
||||||
"color": "0.11.3",
|
"color": "0.11.3",
|
||||||
"cors": "2.8.0",
|
"cors": "2.8.1",
|
||||||
"express": "4.14.0",
|
"express": "4.14.0",
|
||||||
"glyph-pbf-composite": "0.0.2",
|
"glyph-pbf-composite": "0.0.2",
|
||||||
"handlebars": "4.0.5",
|
"handlebars": "4.0.5",
|
||||||
"mapbox-gl-native": "3.3.2",
|
"mapbox-gl-native": "3.3.3",
|
||||||
"mbtiles": "0.9.0",
|
"mbtiles": "0.9.0",
|
||||||
"morgan": "1.7.0",
|
"morgan": "1.7.0",
|
||||||
"node-pngquant-native": "1.0.4",
|
"node-pngquant-native": "1.0.4",
|
||||||
"nomnom": "1.8.1",
|
"nomnom": "1.8.1",
|
||||||
"request": "2.74.0",
|
"request": "2.75.0",
|
||||||
"sharp": "0.16.0",
|
"sharp": "0.16.0",
|
||||||
"sphericalmercator": "1.0.5",
|
"sphericalmercator": "1.0.5",
|
||||||
"tileserver-gl-styles": "0.3.0"
|
"tileserver-gl-styles": "0.3.0"
|
||||||
|
|||||||
@@ -69,6 +69,16 @@
|
|||||||
type: 'line',
|
type: 'line',
|
||||||
paint: {'line-color': colorText}
|
paint: {'line-color': colorText}
|
||||||
});
|
});
|
||||||
|
layers_.push({
|
||||||
|
id: el['id'] + Math.random(),
|
||||||
|
source: 'vector_layer_',
|
||||||
|
'source-layer': el['id'],
|
||||||
|
interactive: true,
|
||||||
|
type: 'circle',
|
||||||
|
paint: {'circle-color': colorText,
|
||||||
|
'circle-radius': 3},
|
||||||
|
filter: ["==", "$type", "Point"]
|
||||||
|
});
|
||||||
var item = document.createElement('div');
|
var item = document.createElement('div');
|
||||||
item.innerHTML = '<div style="' +
|
item.innerHTML = '<div style="' +
|
||||||
'background:rgba(' + color[0] + ',' + color[1] + ',' + color[2] + ',1);' +
|
'background:rgba(' + color[0] + ',' + color[1] + ',' + color[2] + ',1);' +
|
||||||
@@ -124,6 +134,10 @@
|
|||||||
<div id='map'></div>
|
<div id='map'></div>
|
||||||
<script>
|
<script>
|
||||||
var map = L.mapbox.map('map', '/data/{{id}}.json{{&key_query}}', { zoomControl: false });
|
var map = L.mapbox.map('map', '/data/{{id}}.json{{&key_query}}', { zoomControl: false });
|
||||||
|
map.eachLayer(function(layer) {
|
||||||
|
// do not add scale prefix even if retina display is detected
|
||||||
|
layer.scalePrefix = '.';
|
||||||
|
});
|
||||||
new L.Control.Zoom({ position: 'topright' }).addTo(map);
|
new L.Control.Zoom({ position: 'topright' }).addTo(map);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
new L.Hash(map);
|
new L.Hash(map);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ var fs = require('fs');
|
|||||||
var packageJson = require('./package');
|
var packageJson = require('./package');
|
||||||
|
|
||||||
packageJson.name += '-light';
|
packageJson.name += '-light';
|
||||||
|
packageJson.description = 'Map tile server for JSON GL styles - serving vector tiles';
|
||||||
delete packageJson.dependencies['canvas'];
|
delete packageJson.dependencies['canvas'];
|
||||||
delete packageJson.dependencies['mapbox-gl-native'];
|
delete packageJson.dependencies['mapbox-gl-native'];
|
||||||
delete packageJson.dependencies['node-pngquant-native'];
|
delete packageJson.dependencies['node-pngquant-native'];
|
||||||
@@ -29,6 +30,7 @@ delete packageJson.devDependencies;
|
|||||||
|
|
||||||
var str = JSON.stringify(packageJson, undefined, 2);
|
var str = JSON.stringify(packageJson, undefined, 2);
|
||||||
fs.writeFileSync('light/package.json', str);
|
fs.writeFileSync('light/package.json', str);
|
||||||
|
fs.renameSync('light/README_light.md', 'light/README.md');
|
||||||
|
|
||||||
/* PUBLISH */
|
/* PUBLISH */
|
||||||
|
|
||||||
|
|||||||
+14
-9
@@ -70,10 +70,6 @@ var startWithMBTiles = function(mbtilesFile) {
|
|||||||
}
|
}
|
||||||
var instance = new mbtiles(mbtilesFile, function(err) {
|
var instance = new mbtiles(mbtilesFile, function(err) {
|
||||||
instance.getInfo(function(err, info) {
|
instance.getInfo(function(err, info) {
|
||||||
if (info.format != 'pbf') {
|
|
||||||
console.log('ERROR: MBTiles format is not "pbf".');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
var bounds = info.bounds;
|
var bounds = info.bounds;
|
||||||
|
|
||||||
var styleDir = path.resolve(__dirname, "../node_modules/tileserver-gl-styles/");
|
var styleDir = path.resolve(__dirname, "../node_modules/tileserver-gl-styles/");
|
||||||
@@ -89,15 +85,17 @@ var startWithMBTiles = function(mbtilesFile) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"styles": {},
|
"styles": {},
|
||||||
"data": {
|
"data": {}
|
||||||
"osm2vectortiles": {
|
};
|
||||||
|
|
||||||
|
if (info.format == 'pbf' &&
|
||||||
|
info.name.toLowerCase().indexOf('osm2vectortiles') > -1) {
|
||||||
|
config['data']['osm2vectortiles'] = {
|
||||||
"mbtiles": path.basename(mbtilesFile)
|
"mbtiles": path.basename(mbtilesFile)
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
|
var styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
|
||||||
for (var i=0; i < styles.length; i++) {
|
for (var i = 0; i < styles.length; i++) {
|
||||||
var styleFilename = styles[i];
|
var styleFilename = styles[i];
|
||||||
if (styleFilename.endsWith('.json')) {
|
if (styleFilename.endsWith('.json')) {
|
||||||
var styleObject = {
|
var styleObject = {
|
||||||
@@ -110,6 +108,13 @@ var startWithMBTiles = function(mbtilesFile) {
|
|||||||
styleObject;
|
styleObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('WARN: MBTiles not in "osm2vectortiles" format. ' +
|
||||||
|
'Serving raw data only...');
|
||||||
|
config['data'][info.id || 'mbtiles'] = {
|
||||||
|
"mbtiles": path.basename(mbtilesFile)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (opts.verbose) {
|
if (opts.verbose) {
|
||||||
console.log(JSON.stringify(config, undefined, 2));
|
console.log(JSON.stringify(config, undefined, 2));
|
||||||
|
|||||||
+11
-4
@@ -202,6 +202,7 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
|||||||
// meta url which will be detected when requested
|
// meta url which will be detected when requested
|
||||||
'mbtiles://' + name + '/{z}/{x}/{y}.' + (info.format || 'pbf')
|
'mbtiles://' + name + '/{z}/{x}/{y}.' + (info.format || 'pbf')
|
||||||
];
|
];
|
||||||
|
delete source.scheme;
|
||||||
if (source.format == 'pbf') {
|
if (source.format == 'pbf') {
|
||||||
map.sources[name].emptyTile = new Buffer(0);
|
map.sources[name].emptyTile = new Buffer(0);
|
||||||
} else {
|
} else {
|
||||||
@@ -431,14 +432,16 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
|||||||
|
|
||||||
var minCorner = mercator.px([bbox[0], bbox[3]], z),
|
var minCorner = mercator.px([bbox[0], bbox[3]], z),
|
||||||
maxCorner = mercator.px([bbox[2], bbox[1]], z);
|
maxCorner = mercator.px([bbox[2], bbox[1]], z);
|
||||||
w /= (1 + 2 * padding);
|
var w_ = w / (1 + 2 * padding);
|
||||||
h /= (1 + 2 * padding);
|
var h_ = h / (1 + 2 * padding);
|
||||||
|
|
||||||
z -= Math.max(
|
z -= Math.max(
|
||||||
Math.log((maxCorner[0] - minCorner[0]) / w),
|
Math.log((maxCorner[0] - minCorner[0]) / w_),
|
||||||
Math.log((maxCorner[1] - minCorner[1]) / h)
|
Math.log((maxCorner[1] - minCorner[1]) / h_)
|
||||||
) / Math.LN2;
|
) / Math.LN2;
|
||||||
|
|
||||||
|
z = Math.max(Math.log(Math.max(w, h) / 256) / Math.LN2, Math.min(25, z));
|
||||||
|
|
||||||
return z;
|
return z;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -462,6 +465,10 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
|||||||
scale = getScale(req.params.scale),
|
scale = getScale(req.params.scale),
|
||||||
format = req.params.format;
|
format = req.params.format;
|
||||||
|
|
||||||
|
if (z < 0) {
|
||||||
|
return res.status(404).send('Invalid zoom');
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
+1
-1
@@ -249,7 +249,7 @@ module.exports = function(opts, callback) {
|
|||||||
|
|
||||||
var tiles = utils.getTileUrls(
|
var tiles = utils.getTileUrls(
|
||||||
req, style.serving_rendered.tiles,
|
req, style.serving_rendered.tiles,
|
||||||
'styles/' + id, style.serving_rendered.format);
|
'styles/' + id + '/rendered', style.serving_rendered.format);
|
||||||
style.xyz_link = tiles[0];
|
style.xyz_link = tiles[0];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-1
@@ -28,6 +28,8 @@ describe('Static endpoints', function() {
|
|||||||
testStatic(prefix, '0,0,0/300x300', 'png', 200, 2);
|
testStatic(prefix, '0,0,0/300x300', 'png', 200, 2);
|
||||||
testStatic(prefix, '0,0,0/300x300', 'png', 200, 3);
|
testStatic(prefix, '0,0,0/300x300', 'png', 200, 3);
|
||||||
|
|
||||||
|
testStatic(prefix, '0,0,1.5/256x256', 'png', 200);
|
||||||
|
|
||||||
testStatic(prefix, '80,40,20/600x300', 'png', 200, 3);
|
testStatic(prefix, '80,40,20/600x300', 'png', 200, 3);
|
||||||
testStatic(prefix, '8.5,40.5,20/300x150', 'png', 200, 3);
|
testStatic(prefix, '8.5,40.5,20/300x150', 'png', 200, 3);
|
||||||
testStatic(prefix, '-8.5,-40.5,20/300x150', 'png', 200, 3);
|
testStatic(prefix, '-8.5,-40.5,20/300x150', 'png', 200, 3);
|
||||||
@@ -48,7 +50,6 @@ describe('Static endpoints', function() {
|
|||||||
testStatic(prefix, '0,0,0/256x256', 'png', 404, 1);
|
testStatic(prefix, '0,0,0/256x256', 'png', 404, 1);
|
||||||
|
|
||||||
testStatic(prefix, '0,0,-1/256x256', 'png', 404);
|
testStatic(prefix, '0,0,-1/256x256', 'png', 404);
|
||||||
testStatic(prefix, '0,0,1.5/256x256', 'png', 404);
|
|
||||||
testStatic(prefix, '0,0,0/256.5x256.5', 'png', 404);
|
testStatic(prefix, '0,0,0/256.5x256.5', 'png', 404);
|
||||||
|
|
||||||
testStatic(prefix, '0,0,0,/256x256', 'png', 404);
|
testStatic(prefix, '0,0,0,/256x256', 'png', 404);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ describe('Raster tiles', function() {
|
|||||||
testTile(prefix, 0, 0, 0, 'png', 200, 2);
|
testTile(prefix, 0, 0, 0, 'png', 200, 2);
|
||||||
testTile(prefix, 0, 0, 0, 'png', 200, 3);
|
testTile(prefix, 0, 0, 0, 'png', 200, 3);
|
||||||
testTile(prefix, 2, 1, 1, 'png', 200, 3);
|
testTile(prefix, 2, 1, 1, 'png', 200, 3);
|
||||||
|
testTile(prefix, 0, 0, 0, 'png', 200, 4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ describe('Raster tiles', function() {
|
|||||||
testTile(prefix, 0, 0, 0, 'pbf', 400);
|
testTile(prefix, 0, 0, 0, 'pbf', 400);
|
||||||
|
|
||||||
testTile(prefix, 0, 0, 0, 'png', 404, 1);
|
testTile(prefix, 0, 0, 0, 'png', 404, 1);
|
||||||
testTile(prefix, 0, 0, 0, 'png', 404, 4);
|
testTile(prefix, 0, 0, 0, 'png', 404, 5);
|
||||||
|
|
||||||
//testTile('hybrid', 0, 0, 0, 'png', 404); //TODO: test this
|
//testTile('hybrid', 0, 0, 0, 'png', 404); //TODO: test this
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user