Compare commits
266 Commits
v1.3.0-bet
...
v3.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c89a5ae029 | ||
|
|
a3d7f8bcbd | ||
|
|
7c1420982c | ||
|
|
51baa9b67b | ||
|
|
6b3f557b1f | ||
|
|
8d2ddd8f95 | ||
|
|
9f59f67087 | ||
|
|
1d21648969 | ||
|
|
16de5be673 | ||
|
|
6b96f224ae | ||
|
|
6ff4cae9b9 | ||
|
|
644db6cd8a | ||
|
|
a98404e921 | ||
|
|
559cfc462c | ||
|
|
559c3a913e | ||
|
|
4036d528ec | ||
|
|
6ae4116ccb | ||
|
|
39bb7ffbf1 | ||
|
|
e249a3f67d | ||
|
|
04b49d8a98 | ||
|
|
309d481117 | ||
|
|
7ce4805cdd | ||
|
|
5377414710 | ||
|
|
042b8b986a | ||
|
|
038bfe29d6 | ||
|
|
f8563e1f2b | ||
|
|
10431d70d0 | ||
|
|
a5a8ae1e95 | ||
|
|
3c411cd1ac | ||
|
|
79bd70942b | ||
|
|
5585f49396 | ||
|
|
d5a079d8f4 | ||
|
|
29d3e72dd3 | ||
|
|
c3bff5ac5f | ||
|
|
e16de39b93 | ||
|
|
13415fd29f | ||
|
|
9a9b920455 | ||
|
|
b55b8adb63 | ||
|
|
9e12ee6f8c | ||
|
|
0e85e0058f | ||
|
|
3a94a8f9d2 | ||
|
|
28dbc78264 | ||
|
|
8f77be3037 | ||
|
|
f2dc13e298 | ||
|
|
cf0eedb379 | ||
|
|
95bb59dcfe | ||
|
|
224a1300df | ||
|
|
9fd381640e | ||
|
|
b7c384f1ee | ||
|
|
8126b31081 | ||
|
|
caa641c550 | ||
|
|
d02ce0663b | ||
|
|
ea89d11021 | ||
|
|
aa933e5154 | ||
|
|
298d09845d | ||
|
|
d7a34f3a74 | ||
|
|
cb700181d3 | ||
|
|
226b979592 | ||
|
|
13ad268b43 | ||
|
|
e2387d164b | ||
|
|
515c295898 | ||
|
|
cdc7803ad8 | ||
|
|
b839979351 | ||
|
|
0a7c403f0b | ||
|
|
b3d810817d | ||
|
|
96161fc656 | ||
|
|
58c769b448 | ||
|
|
bdd0a5c868 | ||
|
|
5048388d1f | ||
|
|
4c7a227e11 | ||
|
|
7f8be27844 | ||
|
|
736e8d393a | ||
|
|
1c24d12b0d | ||
|
|
f77ccd06af | ||
|
|
4996848bdc | ||
|
|
aa7ae575d0 | ||
|
|
9603703908 | ||
|
|
1445c545b0 | ||
|
|
17a73b1d4a | ||
|
|
e44104254e | ||
|
|
58b536036f | ||
|
|
a68e095400 | ||
|
|
53b28b35f1 | ||
|
|
58f92ae947 | ||
|
|
e506014763 | ||
|
|
7c5e7e94e9 | ||
|
|
e6747ebb78 | ||
|
|
2a87ad19c9 | ||
|
|
ba62f0bf30 | ||
|
|
08369a666d | ||
|
|
f771d41788 | ||
|
|
9dda95ee8e | ||
|
|
63483a3155 | ||
|
|
bca5191ad9 | ||
|
|
245d9765a9 | ||
|
|
e8134dfeb0 | ||
|
|
a1a8996d3f | ||
|
|
bea528ab64 | ||
|
|
cde0233130 | ||
|
|
c99a1a5425 | ||
|
|
243bdbdaa0 | ||
|
|
0631a76a51 | ||
|
|
8e1071aad0 | ||
|
|
e283569897 | ||
|
|
507da8567e | ||
|
|
9cd6feb56d | ||
|
|
059b0f11a0 | ||
|
|
7acbc93ba9 | ||
|
|
bc3d79bfdc | ||
|
|
58168eb0a5 | ||
|
|
f993b01387 | ||
|
|
782c28cd64 | ||
|
|
76a0064f0c | ||
|
|
55fa8bf8c1 | ||
|
|
0c42fdd6b3 | ||
|
|
e8b3c02546 | ||
|
|
56089c0a62 | ||
|
|
857ff2d8d7 | ||
|
|
e310fa5165 | ||
|
|
71fab2a2a1 | ||
|
|
1c59e3d742 | ||
|
|
6e24f6ec8e | ||
|
|
5d5ed1153f | ||
|
|
baf01a117b | ||
|
|
2cc2cc1b3b | ||
|
|
45ed8d90ca | ||
|
|
8e66736955 | ||
|
|
72ea5ab05d | ||
|
|
9d642fa0b3 | ||
|
|
1d734f9b42 | ||
|
|
80146ed7d9 | ||
|
|
a28df7ef8f | ||
|
|
c333197a7c | ||
|
|
45df72df51 | ||
|
|
e737753891 | ||
|
|
edff8ce06c | ||
|
|
df05ce3f2a | ||
|
|
a74ca20375 | ||
|
|
1c890b0157 | ||
|
|
7a9f04a024 | ||
|
|
1354c7f663 | ||
|
|
da3cb1e7f5 | ||
|
|
19e821a8fe | ||
|
|
659289d85c | ||
|
|
734d1f01f0 | ||
|
|
c1055a9647 | ||
|
|
2afb460191 | ||
|
|
8eb736b821 | ||
|
|
83e20b7a4e | ||
|
|
81f65af3a8 | ||
|
|
f5ea790878 | ||
|
|
a0eb5800fd | ||
|
|
27eb7f0ed8 | ||
|
|
2f9059d09e | ||
|
|
e11c8f9315 | ||
|
|
650718e0f6 | ||
|
|
5ed632c229 | ||
|
|
f545076986 | ||
|
|
3d48485475 | ||
|
|
c060dedf20 | ||
|
|
cd1f5fd04a | ||
|
|
dc6be5047c | ||
|
|
47ff33166d | ||
|
|
875521c5a8 | ||
|
|
82f179b07c | ||
|
|
51d6ca0880 | ||
|
|
89878015bb | ||
|
|
ac948b6dee | ||
|
|
440775dbbf | ||
|
|
ea408f8ec9 | ||
|
|
da646868c3 | ||
|
|
d60996e3c6 | ||
|
|
02cf45bbd9 | ||
|
|
d9f8582279 | ||
|
|
54f11a2125 | ||
|
|
598c8c590b | ||
|
|
438a18eec1 | ||
|
|
7bdb7afcb9 | ||
|
|
2e46700cd9 | ||
|
|
bb09f3df64 | ||
|
|
42f24c2c99 | ||
|
|
427a0f0687 | ||
|
|
da5ea4b426 | ||
|
|
2208ff1e24 | ||
|
|
cf521058be | ||
|
|
a9b38022bb | ||
|
|
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 | ||
|
|
e1654a51de | ||
|
|
5372bab6c5 | ||
|
|
6a960e8593 | ||
|
|
1577cfa54a | ||
|
|
640038a115 | ||
|
|
49a8562441 | ||
|
|
1e402ed207 | ||
|
|
f8949c1aa9 | ||
|
|
7b952ee5c0 | ||
|
|
0673c8990a | ||
|
|
37386bfb29 | ||
|
|
b93bc5fadc | ||
|
|
ca7a6ac515 | ||
|
|
9cc3f9df6a | ||
|
|
e6ebb918fb | ||
|
|
ba0f441490 | ||
|
|
e3ac9fbb4e | ||
|
|
2f2e4b8f42 | ||
|
|
bfadeb799b | ||
|
|
2da1bac6c7 | ||
|
|
6f5a7ed704 | ||
|
|
3722c653f1 | ||
|
|
6231f9f7a7 | ||
|
|
1079ece860 | ||
|
|
841cb82f85 | ||
|
|
5c1d396ed2 | ||
|
|
4992bc4194 | ||
|
|
f14d8b1e57 | ||
|
|
14350a4338 | ||
|
|
01fbaad962 | ||
|
|
26e6d56d9b | ||
|
|
66e3a3da1b | ||
|
|
63482a2a39 | ||
|
|
58ccc5477c | ||
|
|
bbbb38d70f | ||
|
|
2ef0540478 | ||
|
|
85692e9659 | ||
|
|
b66ae40a1e | ||
|
|
88022f9297 | ||
|
|
b127dacc0d | ||
|
|
c162a6647d | ||
|
|
b48f7edc1d | ||
|
|
6d68c93871 | ||
|
|
1fef895e67 | ||
|
|
920b6c19b6 | ||
|
|
7f280feeb1 |
@@ -1,4 +1,6 @@
|
||||
.git
|
||||
node_modules
|
||||
test_data
|
||||
test
|
||||
*
|
||||
!src
|
||||
!public
|
||||
!package.json
|
||||
!package-lock.json
|
||||
!docker-entrypoint.sh
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "4"
|
||||
- "10"
|
||||
env:
|
||||
- CXX=g++-4.8
|
||||
addons:
|
||||
@@ -12,10 +12,10 @@ 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
|
||||
- wget -O test_data.zip https://github.com/maptiler/tileserver-gl/releases/download/v1.3.0/test_data.zip
|
||||
- unzip -q test_data.zip -d test_data
|
||||
script:
|
||||
- xvfb-run --server-args="-screen 0 1024x768x24" npm test
|
||||
|
||||
55
Dockerfile
@@ -1,30 +1,55 @@
|
||||
FROM debian:stretch
|
||||
MAINTAINER Petr Sloup <petr.sloup@klokantech.com>
|
||||
FROM node:10-buster AS builder
|
||||
|
||||
RUN apt-get -qq update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get -y install \
|
||||
RUN export DEBIAN_FRONTEND=noninteractive \
|
||||
&& apt-get -qq update \
|
||||
&& apt-get -y --no-install-recommends install \
|
||||
apt-transport-https \
|
||||
curl \
|
||||
unzip \
|
||||
build-essential \
|
||||
python \
|
||||
libcairo2-dev \
|
||||
libgles2-mesa-dev \
|
||||
libgbm-dev \
|
||||
libllvm7 \
|
||||
libprotobuf-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 \
|
||||
&& apt-get -qq update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get -y --allow-unauthenticated install \
|
||||
nodejs \
|
||||
&& rm /etc/apt/sources.list.d/nodejs.list \
|
||||
&& apt-get clean
|
||||
&& apt-get -y --purge autoremove \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY . /usr/src/app
|
||||
|
||||
ENV NODE_ENV="production"
|
||||
|
||||
RUN mkdir -p /usr/src/app
|
||||
COPY / /usr/src/app
|
||||
RUN cd /usr/src/app && npm install --production
|
||||
|
||||
|
||||
FROM node:10-buster-slim AS final
|
||||
|
||||
RUN export DEBIAN_FRONTEND=noninteractive \
|
||||
&& apt-get -qq update \
|
||||
&& apt-get -y --no-install-recommends install \
|
||||
libgles2-mesa \
|
||||
libegl1 \
|
||||
xvfb \
|
||||
xauth \
|
||||
&& apt-get -y --purge autoremove \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=builder /usr/src/app /app
|
||||
|
||||
ENV NODE_ENV="production"
|
||||
ENV CHOKIDAR_USEPOLLING=1
|
||||
ENV CHOKIDAR_INTERVAL=500
|
||||
|
||||
VOLUME /data
|
||||
WORKDIR /data
|
||||
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["/usr/src/app/run.sh"]
|
||||
|
||||
USER node:node
|
||||
|
||||
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
||||
|
||||
CMD ["-p", "80"]
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
FROM node:4
|
||||
MAINTAINER Petr Sloup <petr.sloup@klokantech.com>
|
||||
FROM node:10-stretch
|
||||
|
||||
ENV NODE_ENV="production"
|
||||
ENV CHOKIDAR_USEPOLLING=1
|
||||
ENV CHOKIDAR_INTERVAL=500
|
||||
EXPOSE 80
|
||||
VOLUME /data
|
||||
WORKDIR /data
|
||||
ENTRYPOINT ["node", "/usr/src/app/", "-p", "80"]
|
||||
|
||||
RUN mkdir -p /usr/src/app
|
||||
COPY / /usr/src/app
|
||||
RUN cd /usr/src/app && npm install --production
|
||||
|
||||
VOLUME /data
|
||||
WORKDIR /data
|
||||
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["node", "/usr/src/app/", "-p", "80"]
|
||||
|
||||
34
Dockerfile_test
Normal file
@@ -0,0 +1,34 @@
|
||||
# Run tests inside docker without requiring full installation of dependencies on local machine
|
||||
# Simply run "docker build -f Dockerfile_test ."
|
||||
# WARNING: sometimes it fails with a core dumped exception
|
||||
|
||||
FROM node:10-stretch
|
||||
|
||||
RUN apt-get -qq update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get -y install \
|
||||
apt-transport-https \
|
||||
curl \
|
||||
unzip \
|
||||
build-essential \
|
||||
python \
|
||||
libcairo2-dev \
|
||||
libgles2-mesa-dev \
|
||||
libgbm-dev \
|
||||
libllvm3.9 \
|
||||
libprotobuf-dev \
|
||||
libxxf86vm-dev \
|
||||
xvfb \
|
||||
&& apt-get clean
|
||||
|
||||
RUN mkdir -p /usr/src/app
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
RUN wget -O test_data.zip https://github.com/maptiler/tileserver-gl/releases/download/v1.3.0/test_data.zip
|
||||
RUN unzip -q test_data.zip -d test_data
|
||||
|
||||
ENV NODE_ENV="test"
|
||||
|
||||
COPY package.json .
|
||||
RUN npm install
|
||||
COPY / .
|
||||
RUN xvfb-run --server-args="-screen 0 1024x768x24" npm test
|
||||
21
ISSUE_TEMPLATE.md
Normal file
@@ -0,0 +1,21 @@
|
||||
It is great you want to help us making TileServer GL project better!
|
||||
|
||||
This is the right place only for a software bug report or a new software feature request.
|
||||
|
||||
NOTE: Questions about OpenMapTiles data, OpenMapTiles Server, TileHosting and other software/products do not belong here (and will not be answered)!
|
||||
|
||||
The usage and installation questions belongs to https://stackoverflow.com/questions/tagged/openmaptiles
|
||||
A guaranteed support and consulting from the core developers via https://openmaptiles.com/support/
|
||||
|
||||
Please search this GitHub repo for similar requests before posting (check also closed tickets).
|
||||
|
||||
When reporting a problem you have with the TileServer GL software please provide:
|
||||
|
||||
- Clear description of the problem: What steps will lead to reproducing the error on our computer? What is exactly wrong?
|
||||
- Version of the TileServer GL software you have used
|
||||
- Version and name of the operating system you use or other details of your setup
|
||||
- Information about your used config / styles / vector tiles
|
||||
- URL / link to the specific location in a live map demo where a bug is visible is always great
|
||||
- Screenshot of the problem are cool! Drag&drop an image to the report here...
|
||||
|
||||
We love pull requests! If you are able to code, please send us your fix or code modification via GitHub... Thanks!
|
||||
16
README.md
@@ -2,23 +2,25 @@
|
||||
|
||||
|
||||
# TileServer GL
|
||||
[](https://travis-ci.org/klokantech/tileserver-gl)
|
||||
[](https://hub.docker.com/r/klokantech/tileserver-gl/)
|
||||
[](https://travis-ci.org/maptiler/tileserver-gl)
|
||||
[](https://hub.docker.com/r/maptiler/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.
|
||||
|
||||
## Get Started
|
||||
|
||||
Make sure you have Node.js version **10** installed (running `node -v` it should output something like `v10.17.0`).
|
||||
|
||||
Install `tileserver-gl` with server-side raster rendering of vector tiles with npm
|
||||
|
||||
```bash
|
||||
npm install -g tileserver-gl
|
||||
```
|
||||
|
||||
Now download vector tiles from [OSM2VectorTiles](http://osm2vectortiles.org/downloads/).
|
||||
Now download vector tiles from [OpenMapTiles](https://openmaptiles.org/downloads/).
|
||||
|
||||
```bash
|
||||
curl -o zurich_switzerland.mbtiles https://osm2vectortiles-downloads.os.zhdk.cloud.switch.ch/v2.0/extracts/zurich_switzerland.mbtiles
|
||||
curl -o zurich_switzerland.mbtiles https://[GET-YOUR-LINK]/extracts/zurich_switzerland.mbtiles
|
||||
```
|
||||
|
||||
Start `tileserver-gl` with the downloaded vector tiles.
|
||||
@@ -31,10 +33,10 @@ Alternatively, you can use the `tileserver-gl-light` package instead, which is p
|
||||
|
||||
## 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:
|
||||
An alternative to npm to start the packed software easier is to install [Docker](https://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
|
||||
docker run --rm -it -v $(pwd):/data -p 8080:80 maptiler/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.
|
||||
@@ -43,4 +45,4 @@ On laptop you can use [Docker Kitematic](https://kitematic.com/) and search "til
|
||||
|
||||
## Documentation
|
||||
|
||||
You can read full documentation of this project at http://tileserver.readthedocs.io/.
|
||||
You can read full documentation of this project at https://tileserver.readthedocs.io/.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# TileServer GL light
|
||||
[](https://travis-ci.org/klokantech/tileserver-gl)
|
||||
[](https://hub.docker.com/r/klokantech/tileserver-gl/)
|
||||
[](https://travis-ci.org/maptiler/tileserver-gl)
|
||||
[](https://hub.docker.com/r/maptiler/tileserver-gl/)
|
||||
|
||||
Vector maps with GL styles. Map tile server for Mapbox Android, iOS, GL JS, Leaflet, OpenLayers, etc. without server side rendering.
|
||||
|
||||
@@ -11,7 +11,25 @@ Then you can simply run `tileserver-gl-light zurich_switzerland.mbtiles` to star
|
||||
|
||||
See also `tileserver-gl` which contains server side rendering.
|
||||
|
||||
Prepared vector tiles can be downloaded from [OSM2VectorTiles](http://osm2vectortiles.org/).
|
||||
Prepared vector tiles can be downloaded from [OpenMapTiles.com](https://openmaptiles.com/downloads/planet/).
|
||||
|
||||
## Building docker image
|
||||
|
||||
You can build TileServer GL light image from source.
|
||||
|
||||
```
|
||||
git clone https://github.com/maptiler/tileserver-gl.git
|
||||
cd tileserver-gl
|
||||
node publish.js --no-publish
|
||||
cd light
|
||||
docker build -t tileserver-gl-light .
|
||||
```
|
||||
|
||||
[Download from OpenMapTiles.com](https://openmaptiles.com/downloads/planet/) or [create](https://github.com/openmaptiles/openmaptiles) your vector tile, and run following in directory contains your *.mbtiles.
|
||||
|
||||
```
|
||||
docker run --rm -it -v $(pwd):/data -p 8000:80 tileserver-gl-light
|
||||
```
|
||||
|
||||
## Documentation
|
||||
You can read full documentation of this project at http://tileserver.readthedocs.io/.
|
||||
You can read full documentation of this project at https://tileserver.readthedocs.io/.
|
||||
23
docker-entrypoint.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
handle() {
|
||||
SIGNAL=$(( $? - 128 ))
|
||||
echo "Caught signal ${SIGNAL}, stopping gracefully"
|
||||
kill -s ${SIGNAL} $(pidof node) 2>/dev/null
|
||||
}
|
||||
|
||||
trap handle INT TERM
|
||||
|
||||
if ! which -- "${1}"; then
|
||||
# first arg is not an executable
|
||||
xvfb-run -a --server-args="-screen 0 1024x768x24" -- node /app/ "$@" &
|
||||
# Wait exits immediately on signals which have traps set. Store return value and wait
|
||||
# again for all jobs to actually complete before continuing.
|
||||
wait $! || RETVAL=$?
|
||||
wait
|
||||
exit ${RETVAL}
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -4,7 +4,9 @@ Configuration file
|
||||
|
||||
The configuration file defines the behavior of the application. It's a regular JSON file.
|
||||
|
||||
Example::
|
||||
Example:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"options": {
|
||||
@@ -21,12 +23,15 @@ Example::
|
||||
],
|
||||
"formatQuality": {
|
||||
"jpeg": 80,
|
||||
"webp": 90,
|
||||
"pngQuantization": false,
|
||||
"png": 90
|
||||
"webp": 90
|
||||
},
|
||||
"maxScaleFactor": 3,
|
||||
"maxSize": 2048,
|
||||
"serveAllFonts": false
|
||||
"pbfAlias": "pbf",
|
||||
"serveAllFonts": false,
|
||||
"serveAllStyles": false,
|
||||
"serveStaticMaps": true,
|
||||
"tileMargin": 0
|
||||
},
|
||||
"styles": {
|
||||
"basic": {
|
||||
@@ -67,17 +72,74 @@ The value of ``root`` is used as prefix for all data types.
|
||||
|
||||
You can use this to optionally specify on what domains the rendered tiles are accessible. This can be used for basic load-balancing or to bypass browser's limit for the number of connections per domain.
|
||||
|
||||
``frontPage``
|
||||
-----------------
|
||||
|
||||
Path to the html (relative to ``root`` path) to use as a front page.
|
||||
|
||||
Use ``true`` (or nothing) to serve the default TileServer GL front page with list of styles and data.
|
||||
Use ``false`` to disable the front page altogether (404).
|
||||
|
||||
``formatQuality``
|
||||
-----------------
|
||||
|
||||
Quality of the compression of individual image formats. [0-100]
|
||||
|
||||
The value for ``png`` is only used when ``pngQuantization`` is ``true``.
|
||||
``maxScaleFactor``
|
||||
-----------
|
||||
|
||||
Maximum scale factor to allow in raster tile and static maps requests (e.g. ``@3x`` suffix).
|
||||
Also see ``maxSize`` below.
|
||||
Default value is ``3``, maximum ``9``.
|
||||
|
||||
``maxSize``
|
||||
-----------
|
||||
|
||||
Maximum image side length to be allowed to be rendered (including scale factor). Default is ``2048``.
|
||||
Maximum image side length to be allowed to be rendered (including scale factor).
|
||||
Be careful when changing this value since there are hardware limits that need to be considered.
|
||||
Default is ``2048``.
|
||||
|
||||
``tileMargin``
|
||||
--------------
|
||||
|
||||
Additional image side length added during tile rendering that is cropped from the delivered tile. This is useful for resolving the issue with cropped labels,
|
||||
but it does come with a performance degradation, because additional, adjacent vector tiles need to be loaded to generate a single tile.
|
||||
Default is ``0`` to disable this processing.
|
||||
|
||||
``minRendererPoolSizes``
|
||||
------------------------
|
||||
|
||||
Minimum amount of raster tile renderers per scale factor.
|
||||
The value is an array: the first element is the minimum amount of renderers for scale factor one, the second for scale factor two and so on.
|
||||
If the array has less elements than ``maxScaleFactor``, then the last element is used for all remaining scale factors as well.
|
||||
Selecting renderer pool sizes is a trade-off between memory use and speed.
|
||||
A reasonable value will depend on your hardware and your amount of styles and scale factors.
|
||||
If you have plenty of memory, you'll want to set this equal to ``maxRendererPoolSizes`` to avoid increased latency due to renderer destruction and recreation.
|
||||
If you need to conserve memory, you'll want something lower than ``maxRendererPoolSizes``, possibly allocating more renderers to scale factors that are more common.
|
||||
Default is ``[8, 4, 2]``.
|
||||
|
||||
``maxRendererPoolSizes``
|
||||
------------------------
|
||||
|
||||
Maximum amount of raster tile renderers per scale factor.
|
||||
The value and considerations are similar to ``minRendererPoolSizes`` above.
|
||||
If you have plenty of memory, try setting these equal to or slightly above your processor count, e.g. if you have four processors, try a value of ``[6]``.
|
||||
If you need to conserve memory, try lower values for scale factors that are less common.
|
||||
Default is ``[16, 8, 4]``.
|
||||
|
||||
``serveAllStyles``
|
||||
------------------------
|
||||
|
||||
If this option is enabled, all the styles from the ``paths.styles`` will be served. (No recursion, only ``.json`` files are used.)
|
||||
The process will also watch for changes in this directory and remove/add more styles dynamically.
|
||||
It is recommended to also use the ``serveAllFonts`` option when using this option.
|
||||
|
||||
``watermark``
|
||||
-----------
|
||||
|
||||
Optional string to be rendered into the raster tiles (and static maps) as watermark (bottom-left corner).
|
||||
Can be used for hard-coding attributions etc. (can also be specified per-style).
|
||||
Not used by default.
|
||||
|
||||
``styles``
|
||||
==========
|
||||
@@ -86,7 +148,7 @@ Each item in this object defines one style (map). It can have the following opti
|
||||
|
||||
* ``style`` -- name of the style json file [required]
|
||||
* ``serve_rendered`` -- whether to render the raster tiles for this style or not
|
||||
* ``serve_data`` -- whether to allow acces to the original tiles, sprites and required glyphs
|
||||
* ``serve_data`` -- whether to allow access to the original tiles, sprites and required glyphs
|
||||
* ``tilejson`` -- properties to add to the TileJSON created for the raster data
|
||||
|
||||
* ``format`` and ``bounds`` can be especially useful
|
||||
@@ -129,7 +191,7 @@ Sprites
|
||||
|
||||
If your style requires any sprites, make sure the style JSON contains proper path in the ``sprite`` property.
|
||||
|
||||
It can be a local path (e.g. ``my-style/sprite``) or remove http(s) location (e.g. ``https://mycdn.com/my-style/sprite``). Several possible extension are added to this path, so the following files should be present:
|
||||
It can be a local path (e.g. ``my-style/sprite``) or remote http(s) location (e.g. ``https://mycdn.com/my-style/sprite``). Several possible extension are added to this path, so the following files should be present:
|
||||
|
||||
* ``sprite.json``
|
||||
* ``sprite.png``
|
||||
|
||||
@@ -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,21 +6,25 @@ 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.
|
||||
|
||||
WMTS Capabilities
|
||||
==============
|
||||
* WMTS Capabilities are served at ``/styles/{id}/wmts.xml``
|
||||
|
||||
Static images
|
||||
=============
|
||||
* Several endpoints:
|
||||
@@ -39,7 +43,7 @@ Static images
|
||||
* ``fill`` - color to use as the fill (e.g. ``red``, ``rgba(255,255,255,0.5)``, ``#0000ff``)
|
||||
* ``stroke`` - color of the path stroke
|
||||
* ``width`` - width of the stroke
|
||||
* ``padding`` - "percetange" padding for fitted endpoints (area-based and path autofit)
|
||||
* ``padding`` - "percentage" padding for fitted endpoints (area-based and path autofit)
|
||||
|
||||
* value of ``0.1`` means "add 10% size to each side to make sure the area of interest is nicely visible"
|
||||
|
||||
@@ -63,4 +67,11 @@ 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 ``/fontstacks.json``
|
||||
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
|
||||
|
||||
@@ -7,12 +7,12 @@ Docker
|
||||
|
||||
When running docker image, no special installation is needed -- the docker will automatically download the image if not present.
|
||||
|
||||
Just run ``docker run -it -v $(pwd):/data -p 8080:80 klokantech/tileserver-gl``.
|
||||
Just run ``docker run --rm -it -v $(pwd):/data -p 8080:80 maptiler/tileserver-gl``.
|
||||
|
||||
Additional options (see :doc:`/usage`) can be passed to the TileServer GL by appending them to the end of this command. You can, for example, do the following:
|
||||
|
||||
* ``docker run ... klokantech/tileserver-gl my-tiles.mbtiles`` -- explicitly specify which mbtiles to use (if you have more in the folder)
|
||||
* ``docker run ... klokantech/tileserver-gl --verbose`` -- to see the default config created automatically
|
||||
* ``docker run ... maptiler/tileserver-gl --mbtiles my-tiles.mbtiles`` -- explicitly specify which mbtiles to use (if you have more in the folder)
|
||||
* ``docker run ... maptiler/tileserver-gl --verbose`` -- to see the default config created automatically
|
||||
|
||||
npm
|
||||
===
|
||||
@@ -41,7 +41,7 @@ Alternatively, you can use ``tileserver-gl-light`` package instead, which is pur
|
||||
From source
|
||||
===========
|
||||
|
||||
Make sure you have Node v4 or higher (nvm install 4) and run::
|
||||
Make sure you have Node v10 (nvm install 10) and run::
|
||||
|
||||
npm install
|
||||
node .
|
||||
@@ -50,6 +50,9 @@ Make sure you have Node v4 or higher (nvm install 4) and run::
|
||||
On OSX
|
||||
======
|
||||
|
||||
Make sure to have ``pkg-config`` and ``cairo`` installed::
|
||||
Make sure to have dependencies of canvas_ package installed::
|
||||
|
||||
brew install pkg-config cairo
|
||||
brew install pkg-config cairo libpng jpeg giflib
|
||||
|
||||
|
||||
.. _canvas: https://www.npmjs.com/package/canvas
|
||||
|
||||
@@ -4,25 +4,33 @@ Usage
|
||||
|
||||
Getting started
|
||||
======
|
||||
|
||||
::
|
||||
|
||||
Usage: tileserver-gl [mbtiles] [options]
|
||||
|
||||
mbtiles MBTiles file (uses demo configuration);
|
||||
ignored if the configuration file is also specified
|
||||
Usage: main.js tileserver-gl [mbtiles] [options]
|
||||
|
||||
Options:
|
||||
-c, --config Configuration file [config.json]
|
||||
-b, --bind Bind address
|
||||
-p, --port Port [8080]
|
||||
|
||||
-h, --help output usage information
|
||||
--mbtiles <file> MBTiles file (uses demo configuration);
|
||||
ignored if the configuration file is also specified
|
||||
-c, --config <file> Configuration file [config.json]
|
||||
-b, --bind <address> Bind address
|
||||
-p, --port <port> Port [8080]
|
||||
-C|--no-cors Disable Cross-origin resource sharing headers
|
||||
-u|--public_url <url> Enable exposing the server on subpaths, not necessarily the root of the domain
|
||||
-V, --verbose More verbose output
|
||||
-s, --silent Less verbose output
|
||||
-v, --version Version info
|
||||
|
||||
|
||||
|
||||
Default styles and configuration
|
||||
Default preview style and configuration
|
||||
======
|
||||
|
||||
- If no configuration file is specified, the default styles (compatible with osm2vectortiles) are used.
|
||||
- If no mbtiles file is specified (and is not found in the current working directory), an extract is downloaded directly from osm2vectortiles.
|
||||
- If no configuration file is specified, a default preview style (compatible with openmaptiles) is used.
|
||||
- If no mbtiles file is specified (and is not found in the current working directory), a sample file is downloaded (showing the Zurich area)
|
||||
|
||||
Reloading configuration
|
||||
======
|
||||
|
||||
It is possible to reload the configuration file without restarting the whole process by sending a SIGHUP signal to the node process.
|
||||
However, this does not currently work when running the tileserver-gl docker container (the signal is not passed to the subprocess, see https://github.com/maptiler/tileserver-gl/issues/420#issuecomment-597507663).
|
||||
|
||||
66
package.json
@@ -1,53 +1,49 @@
|
||||
{
|
||||
"name": "tileserver-gl",
|
||||
"version": "1.3.0-beta.2",
|
||||
"version": "3.1.1",
|
||||
"description": "Map tile server for JSON GL styles - vector and server side generated raster tiles",
|
||||
"main": "src/main.js",
|
||||
"bin": "src/main.js",
|
||||
"authors": [
|
||||
"Petr Sloup <petr.sloup@klokantech.com>"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/klokantech/tileserver-gl.git"
|
||||
"url": "https://github.com/maptiler/tileserver-gl.git"
|
||||
},
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=4.2.1 <5"
|
||||
"node": ">=10 <11"
|
||||
},
|
||||
"engineStrict": true,
|
||||
"scripts": {
|
||||
"test": "mocha test/**.js"
|
||||
"test": "mocha test/**.js --timeout 10000",
|
||||
"docker": "docker build -f Dockerfile . && docker run --rm -i -p 8080:80 $(docker build -q .)"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "2.1.4",
|
||||
"advanced-pool": "0.3.2",
|
||||
"base64url": "2.0.0",
|
||||
"canvas": "1.6.2",
|
||||
"clone": "2.1.0",
|
||||
"color": "1.0.3",
|
||||
"cors": "2.8.1",
|
||||
"express": "4.14.0",
|
||||
"glyph-pbf-composite": "0.0.2",
|
||||
"handlebars": "4.0.6",
|
||||
"mapbox-gl-native": "3.4.2",
|
||||
"mbtiles": "0.9.0",
|
||||
"morgan": "1.7.0",
|
||||
"node-pngquant-native": "1.0.4",
|
||||
"nomnom": "1.8.1",
|
||||
"pbf": "3.0.5",
|
||||
"request": "2.79.0",
|
||||
"sharp": "0.16.2",
|
||||
"sphericalmercator": "1.0.5",
|
||||
"tileserver-gl-styles": "1.0.0",
|
||||
"vector-tile": "1.3.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"tileshrink-gl": "./plugins/tileshrink-gl"
|
||||
"@mapbox/glyph-pbf-composite": "0.0.3",
|
||||
"@mapbox/mapbox-gl-native": "5.0.2",
|
||||
"@mapbox/mapbox-gl-style-spec": "13.12.0",
|
||||
"@mapbox/mbtiles": "0.11.0",
|
||||
"@mapbox/sphericalmercator": "1.1.0",
|
||||
"@mapbox/vector-tile": "1.3.1",
|
||||
"advanced-pool": "0.3.3",
|
||||
"canvas": "2.6.1",
|
||||
"chokidar": "3.3.1",
|
||||
"clone": "2.1.2",
|
||||
"color": "3.1.2",
|
||||
"commander": "4.1.1",
|
||||
"cors": "2.8.5",
|
||||
"esm": "3.2.25",
|
||||
"express": "4.17.1",
|
||||
"handlebars": "4.7.3",
|
||||
"http-shutdown": "1.2.2",
|
||||
"morgan": "1.9.1",
|
||||
"pbf": "3.2.1",
|
||||
"proj4": "2.6.0",
|
||||
"request": "2.88.2",
|
||||
"sharp": "0.26.2",
|
||||
"tileserver-gl-styles": "2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"should": "^11.1.1",
|
||||
"mocha": "^3.2.0",
|
||||
"supertest": "^2.0.1"
|
||||
"mocha": "^7.1.0",
|
||||
"should": "^13.2.3",
|
||||
"supertest": "^4.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 171 KiB After Width: | Height: | Size: 171 KiB |
|
Before Width: | Height: | Size: 250 KiB |
|
Before Width: | Height: | Size: 530 KiB |
|
Before Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
67
public/resources/images/maptiler-logo.svg
Normal file
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
width="2034.203px" height="552.055px" viewBox="0 0 2034.203 552.055" enable-background="new 0 0 2034.203 552.055"
|
||||
xml:space="preserve">
|
||||
<g>
|
||||
<path fill="#3A1888" d="M3.604-242.717"/>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path fill="#3A1888" d="M152.645,436.647c25.674,25.668,94.015,95.335,93.983,95.406c-0.249,0.454,67.892-67.963,95.032-95.087
|
||||
l-94.67-94.665L152.645,436.647z"/>
|
||||
<path fill="#03A1C4" d="M246.99,342.301l94.67,94.665c0.141-0.157,0.314-0.336,0.466-0.477l94.578-94.583l-94.66-94.662
|
||||
L246.99,342.301z"/>
|
||||
<path fill="#05D0DF" d="M436.704,341.907l0.243-0.244c52.317-52.312,52.36-137.096,0.157-189.473l-95.06,95.055L436.704,341.907z"
|
||||
/>
|
||||
<path fill="#761FE8" d="M151.931,247.245l-94.329,94.326c0.027,0.032,0.043,0.064,0.076,0.092l94.811,94.827
|
||||
c0.054,0.049,0.108,0.098,0.157,0.157l94.345-94.346L151.931,247.245z"/>
|
||||
<path fill="#FFAA01" d="M246.99,152.184l95.054,95.061l95.06-95.055c-0.076-0.054-0.103-0.108-0.157-0.162l-94.821-94.816
|
||||
c-0.022-0.027-0.054-0.054-0.082-0.081L246.99,152.184z"/>
|
||||
<path fill="#F1175D" d="M57.201,152.514c-51.852,52.377-51.722,136.848,0.4,189.057l94.329-94.326L57.201,152.514z"/>
|
||||
<path fill="#FB3A1B" d="M246.99,152.184L152.255,57.45l-94.578,94.578c-0.163,0.162-0.309,0.336-0.476,0.486l94.729,94.73
|
||||
L246.99,152.184z"/>
|
||||
<path fill="#FBC935" d="M342.044,57.13C289.663,4.846,204.832,4.874,152.488,57.211l-0.233,0.238l94.735,94.734L342.044,57.13z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#333359" d="M734.146,365.616v-96.875c0-23.851-12.479-45.492-37.077-45.492c-24.224,0-38.517,21.642-38.517,45.492
|
||||
v96.875h-44.761V184.347h41.46l3.301,22.021c9.542-18.353,30.458-24.949,47.685-24.949c21.669,0,43.306,8.811,53.588,33.754
|
||||
c16.144-25.685,37.066-33.022,60.537-33.022c51.38,0,76.692,31.551,76.692,85.859v97.605h-44.767V268.01
|
||||
c0-23.84-9.904-44.037-34.106-44.037c-24.234,0-39.279,20.917-39.279,44.768v96.875H734.146z"/>
|
||||
<path fill="#333359" d="M1086.026,184.726h42.938v180.89h-42.208l-2.208-26.41c-10.266,21.269-38.516,31.535-58.702,31.914
|
||||
c-53.556,0.368-93.198-32.655-93.198-96.137c0-62.375,41.477-95.029,94.313-94.662c24.212,0,47.321,11.371,57.587,29.354
|
||||
L1086.026,184.726z M977.416,274.983c0,34.479,23.85,55.039,53.573,55.039c70.446,0,70.446-109.713,0-109.713
|
||||
C1001.266,220.309,977.416,240.496,977.416,274.983z"/>
|
||||
<path fill="#333359" d="M1166.756,441.214V184.726h41.839l2.923,24.949c13.951-20.187,38.175-28.991,58.719-28.991
|
||||
c55.753,0,92.835,41.471,92.835,94.667c0,52.847-33.401,94.675-91.374,94.675c-19.065,0-47.332-5.888-60.18-25.695v96.884
|
||||
H1166.756z M1318.305,275.351c0-28.253-19.082-51.378-51.37-51.378c-32.298,0-51.38,23.125-51.38,51.378
|
||||
c0,28.244,20.922,51.38,51.38,51.38C1297.404,326.731,1318.305,303.595,1318.305,275.351z"/>
|
||||
<path fill="#333359" d="M1443.064,129.682v54.665h61.642v15.046h-61.642v110.453c0,24.575,5.146,41.823,33.392,41.823
|
||||
c8.805,0,18.709-2.938,27.882-7.339l6.24,14.666c-11.382,5.521-22.763,9.185-34.122,9.185c-38.527,0-51.002-22.752-51.002-58.335
|
||||
V199.393h-38.538v-15.046h38.538v-52.831L1443.064,129.682z"/>
|
||||
<path fill="#333359" d="M1570.027,125.272c0,19.082-28.986,19.082-28.986,0C1541.041,106.2,1570.027,106.2,1570.027,125.272z
|
||||
M1546.188,183.612v182.004h17.962V183.612H1546.188z"/>
|
||||
<path fill="#333359" d="M1633.503,108.776v256.84h-17.983v-256.84H1633.503z"/>
|
||||
<path fill="#333359" d="M1918.606,184.347l0.73,32.304c11.365-24.603,37.066-34.133,60.181-34.133
|
||||
c13.589-0.367,26.772,3.307,38.896,10.646l-8.08,14.671c-9.525-5.871-20.187-8.441-30.815-8.441
|
||||
c-33.771,0.379-59.817,27.524-59.817,60.553v105.67h-17.979V184.347H1918.606z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="none" d="M1694.655,305.711c0.006,0.016,0.014,0.031,0.02,0.047l146.748-38.832c-0.007-0.055-0.012-0.11-0.018-0.166
|
||||
L1694.655,305.711z"/>
|
||||
<path fill="none" d="M1765.447,197.873c-42.255,0-76.514,34.997-76.514,78.169c0,4.196,0.333,8.312,0.956,12.329l147.452-39.137
|
||||
C1826.633,219.268,1798.486,197.873,1765.447,197.873z"/>
|
||||
<g>
|
||||
<path fill="none" d="M1765.447,198.374c-42.255,0-76.514,34.996-76.514,78.169c0,4.196,0.333,8.312,0.956,12.329l147.452-39.137
|
||||
C1826.633,219.768,1798.486,198.374,1765.447,198.374z"/>
|
||||
<path fill="#333359" d="M1765.447,354.709c-31.946,0-59.308-20.014-70.764-48.431l-0.1,0.004l0.091-0.024
|
||||
c-0.006-0.016-0.014-0.031-0.02-0.047l146.75-38.951c0.006,0.056,0.011,0.111,0.018,0.166l15.616-4.133
|
||||
c-6.306-45.918-44.904-81.253-91.59-81.253c-51.089,0-92.501,42.31-92.501,94.5s41.412,94.501,92.501,94.501
|
||||
c38.213,0,71.011-23.675,85.115-57.448l-14.717-6.398C1824.179,335.126,1797.054,354.709,1765.447,354.709z M1688.934,276.542
|
||||
c0-43.173,34.259-78.169,76.514-78.169c33.039,0,61.186,21.395,71.895,51.361l-147.452,39.137
|
||||
C1689.267,284.854,1688.934,280.739,1688.934,276.542z"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 5.0 KiB |
@@ -23,6 +23,9 @@ body{
|
||||
font-family:'OpenSans', sans-serif, Arial;
|
||||
font-size: 14px;
|
||||
margin:0;
|
||||
background-repeat:no-repeat !important;
|
||||
background-size: contain !important;
|
||||
background-image: url(/images/header-map-1280px.png);
|
||||
}
|
||||
a{
|
||||
color: #499DCE;
|
||||
@@ -81,6 +84,7 @@ section{
|
||||
}
|
||||
.item img {
|
||||
position: absolute;
|
||||
display: block;
|
||||
margin: 30px;
|
||||
width: 128px;
|
||||
height: 128px;
|
||||
@@ -134,8 +138,11 @@ footer{
|
||||
font-size:12px;
|
||||
}
|
||||
footer img {
|
||||
width: 118px;
|
||||
height: 32px;
|
||||
width: 113px;
|
||||
height: 31px;
|
||||
}
|
||||
footer .t {
|
||||
display:none;
|
||||
}
|
||||
footer p {
|
||||
margin-top:0;
|
||||
@@ -144,27 +151,9 @@ footer a {
|
||||
color: #787878;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* body background image */
|
||||
body {
|
||||
background-repeat:no-repeat !important;
|
||||
background-size: contain !important;
|
||||
background-image: url(/images/header-map-640px.png);
|
||||
}
|
||||
@media only screen and (min-width: 641px) {
|
||||
body {
|
||||
background-image: url(/images/header-map-1280px.png);
|
||||
}
|
||||
}
|
||||
@media only screen and (min-width: 1281px) {
|
||||
body {
|
||||
background-image: url(/images/header-map-1600px.png);
|
||||
}
|
||||
}
|
||||
@media only screen and (min-width: 1601px) {
|
||||
body {
|
||||
background-image: url(/images/header-map-2560px.png);
|
||||
}
|
||||
.details h3, .identifier {
|
||||
max-width: 550px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
|
||||
6
public/resources/mapbox-gl-rtl-text.js
Normal file
@@ -5,22 +5,22 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{{name}} - TileServer GL</title>
|
||||
{{#is_vector}}
|
||||
<link rel="stylesheet" type="text/css" href="/mapbox-gl.css{{&key_query}}" />
|
||||
<link rel="stylesheet" type="text/css" href="/mapbox-gl-inspect.css{{&key_query}}" />
|
||||
<script src="/mapbox-gl.js{{&key_query}}"></script>
|
||||
<script src="/mapbox-gl-inspect.min.js{{&key_query}}"></script>
|
||||
<link rel="stylesheet" type="text/css" href="{{public_url}}mapbox-gl.css{{&key_query}}" />
|
||||
<link rel="stylesheet" type="text/css" href="{{public_url}}mapbox-gl-inspect.css{{&key_query}}" />
|
||||
<script src="{{public_url}}mapbox-gl.js{{&key_query}}"></script>
|
||||
<script src="{{public_url}}mapbox-gl-inspect.min.js{{&key_query}}"></script>
|
||||
<style>
|
||||
body {background:#fff;color:#333;}
|
||||
body {background:#fff;color:#333;font-family:Arial, sans-serif;}
|
||||
#map {position:absolute;top:0;left:0;right:250px;bottom:0;}
|
||||
h1 {position:absolute;top:5px;right:0;width:240px;margin:0;line-height:20px;font-size:20px;}
|
||||
#layerList {position:absolute;top:35px;right:0;bottom:60%;width:240px;overflow:auto;}
|
||||
#layerList {position:absolute;top:35px;right:0;bottom:0;width:240px;overflow:auto;}
|
||||
#layerList div div {width:15px;height:15px;display:inline-block;}
|
||||
</style>
|
||||
{{/is_vector}}
|
||||
{{^is_vector}}
|
||||
<link rel="stylesheet" type="text/css" href="/mapbox.css{{&key_query}}" />
|
||||
<script src="/mapbox.js{{&key_query}}"></script>
|
||||
<script src="/leaflet-hash.js{{&key_query}}"></script>
|
||||
<link rel="stylesheet" type="text/css" href="{{public_url}}mapbox.css{{&key_query}}" />
|
||||
<script src="{{public_url}}mapbox.js{{&key_query}}"></script>
|
||||
<script src="{{public_url}}leaflet-hash.js{{&key_query}}"></script>
|
||||
<style>
|
||||
body { margin:0; padding:0; }
|
||||
#map { position:absolute; top:0; bottom:0; width:100%; }
|
||||
@@ -42,7 +42,7 @@
|
||||
sources: {
|
||||
'vector_layer_': {
|
||||
type: 'vector',
|
||||
url: '/data/{{id}}.json{{&key_query}}'
|
||||
url: '{{public_url}}data/{{id}}.json{{&key_query}}'
|
||||
}
|
||||
},
|
||||
layers: []
|
||||
@@ -74,7 +74,7 @@
|
||||
<h1 style="display:none;">{{name}}</h1>
|
||||
<div id='map'></div>
|
||||
<script>
|
||||
var map = L.mapbox.map('map', '/data/{{id}}.json{{&key_query}}', { zoomControl: false });
|
||||
var map = L.mapbox.map('map', '{{public_url}}data/{{id}}.json{{&key_query}}', { zoomControl: false });
|
||||
map.eachLayer(function(layer) {
|
||||
// do not add scale prefix even if retina display is detected
|
||||
layer.scalePrefix = '.';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>TileServer GL - Server for vector and raster maps with GL styles</title>
|
||||
<link rel="stylesheet" type="text/css" href="/index.css{{&key_query}}" />
|
||||
<link rel="stylesheet" type="text/css" href="{{public_url}}index.css{{&key_query}}" />
|
||||
<script>
|
||||
function toggle_xyz(id) {
|
||||
var el = document.getElementById(id);
|
||||
@@ -17,16 +17,17 @@
|
||||
</head>
|
||||
<body>
|
||||
<section>
|
||||
<h1 class="title {{#if is_light}}light{{/if}}"><img src="/images/logo.png" alt="TileServer GL" /></h1>
|
||||
<h1 class="title {{#if is_light}}light{{/if}}"><img src="{{public_url}}images/logo.png" alt="TileServer GL" /></h1>
|
||||
<h2 class="subtitle">Vector {{#if is_light}}<s>and raster</s>{{else}}and raster{{/if}} maps with GL styles</h2>
|
||||
{{#if styles}}
|
||||
<h2 class="box-header">Styles</h2>
|
||||
<div class="box">
|
||||
{{#each styles}}
|
||||
<div class="item">
|
||||
{{#if thumbnail}}
|
||||
<img src="/styles/{{@key}}/rendered/{{thumbnail}}{{&../key_query}}" alt="{{name}} preview" />
|
||||
<img src="{{public_url}}styles/{{@key}}/{{thumbnail}}{{&../key_query}}" alt="{{name}} preview" />
|
||||
{{else}}
|
||||
<img src="/images/placeholder.png" alt="{{name}} preview" />
|
||||
<img src="{{public_url}}images/placeholder.png" alt="{{name}} preview" />
|
||||
{{/if}}
|
||||
<div class="details">
|
||||
<h3>{{name}}</h3>
|
||||
@@ -34,13 +35,13 @@
|
||||
<p class="services">
|
||||
services:
|
||||
{{#if serving_data}}
|
||||
<a href="/styles/{{@key}}.json{{&../key_query}}">GL Style</a>
|
||||
<a href="{{public_url}}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="{{public_url}}styles/{{@key}}.json{{&../key_query}}">TileJSON</a>
|
||||
{{/if}}
|
||||
{{#if wmts_link}}
|
||||
| <a href="{{&wmts_link}}">WMTS</a>
|
||||
{{#if serving_rendered}}
|
||||
| <a href="/styles/{{@key}}/wmts.xml{{&../key_query}}">WMTS</a>
|
||||
{{/if}}
|
||||
{{#if xyz_link}}
|
||||
| <a href="#" onclick="return toggle_xyz('xyz_style_{{@key}}');">XYZ</a>
|
||||
@@ -51,33 +52,35 @@
|
||||
<div class="viewers">
|
||||
{{#if serving_data}}
|
||||
{{#if serving_rendered}}
|
||||
<a class="btn" href="/styles/{{@key}}/{{&../key_query}}{{viewer_hash}}">Viewer</a>
|
||||
<a class="btn" href="{{public_url}}styles/{{@key}}/{{&../key_query}}{{viewer_hash}}">Viewer</a>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{#if serving_rendered}}
|
||||
<a class="btn" href="/styles/{{@key}}/?{{&../key_query_part}}raster{{viewer_hash}}">Raster</a>
|
||||
<a class="btn" href="{{public_url}}styles/{{@key}}/?{{&../key_query_part}}raster{{viewer_hash}}">Raster</a>
|
||||
{{/if}}
|
||||
{{#if serving_data}}
|
||||
<a class="btn" href="/styles/{{@key}}/?{{&../key_query_part}}vector{{viewer_hash}}">Vector</a>
|
||||
<a class="btn" href="{{public_url}}styles/{{@key}}/?{{&../key_query_part}}vector{{viewer_hash}}">Vector</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#if data}}
|
||||
<h2 class="box-header">Data</h2>
|
||||
<div class="box">
|
||||
{{#each data}}
|
||||
<div class="item">
|
||||
{{#if thumbnail}}
|
||||
<img src="/data/{{@key}}/{{thumbnail}}{{&../key_query}}" alt="{{name}} preview" />
|
||||
<img src="{{public_url}}data/{{@key}}/{{thumbnail}}{{&../key_query}}" alt="{{name}} preview" />
|
||||
{{else}}
|
||||
<img src="/images/placeholder.png" alt="{{name}} preview" />
|
||||
<img src="{{public_url}}images/placeholder.png" alt="{{name}} preview" />
|
||||
{{/if}}
|
||||
<div class="details">
|
||||
<h3>{{name}}</h3>
|
||||
<p class="identifier">identifier: {{@key}}{{#if formatted_filesize}} | size: {{formatted_filesize}}{{/if}} | type: {{#is_vector}}vector{{/is_vector}}{{^is_vector}}raster{{/is_vector}} data</p>
|
||||
<p class="services">
|
||||
services: <a href="/data/{{@key}}.json{{&../key_query}}">TileJSON</a>
|
||||
services: <a href="{{public_url}}data/{{@key}}.json{{&../key_query}}">TileJSON</a>
|
||||
{{#if wmts_link}}
|
||||
| <a href="{{&wmts_link}}">WMTS</a>
|
||||
{{/if}}
|
||||
@@ -89,20 +92,21 @@
|
||||
</div>
|
||||
<div class="viewers">
|
||||
{{#is_vector}}
|
||||
<a class="btn" href="/data/{{@key}}/{{&../key_query}}{{viewer_hash}}">Inspect</a>
|
||||
<a class="btn" href="{{public_url}}data/{{@key}}/{{&../key_query}}{{viewer_hash}}">Inspect</a>
|
||||
{{/is_vector}}
|
||||
{{^is_vector}}
|
||||
<a class="btn" href="/data/{{@key}}/{{&../key_query}}{{viewer_hash}}">View</a>
|
||||
<a class="btn" href="{{public_url}}data/{{@key}}/{{&../key_query}}{{viewer_hash}}">View</a>
|
||||
{{/is_vector}}
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</section>
|
||||
<footer>
|
||||
<a href="https://www.klokantech.com/" target="_blank"><img src="/images/klokantech.png" /></a>
|
||||
<a href="https://www.maptiler.com/" target="_blank"><img src="{{public_url}}images/maptiler-logo.svg" /></a>
|
||||
<p>
|
||||
<a href="https://github.com/klokantech/tileserver-gl" target="_blank">Powered by TileServer GL ({{server_version}})</a> – <a href="https://www.klokantech.com/" target="_blank">open-source project from Klokan Technologies GmbH.</a>
|
||||
<a href="https://github.com/maptiler/tileserver-gl" target="_blank">Powered by TileServer GL ({{server_version}})</a> – <a href="https://www.maptiler.com/" target="_blank">an open-source project from MapTiler.</a>
|
||||
</p>
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{{name}} - TileServer GL</title>
|
||||
<link rel="stylesheet" type="text/css" href="/mapbox-gl.css{{&key_query}}" />
|
||||
<script src="/mapbox-gl.js{{&key_query}}"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/mapbox.css{{&key_query}}" />
|
||||
<script src="/mapbox.js{{&key_query}}"></script>
|
||||
<script src="/leaflet-hash.js{{&key_query}}"></script>
|
||||
<link rel="stylesheet" type="text/css" href="{{public_url}}mapbox-gl.css{{&key_query}}" />
|
||||
<script src="{{public_url}}mapbox-gl.js{{&key_query}}"></script>
|
||||
<link rel="stylesheet" type="text/css" href="{{public_url}}mapbox.css{{&key_query}}" />
|
||||
<script src="{{public_url}}mapbox.js{{&key_query}}"></script>
|
||||
<script src="{{public_url}}leaflet-hash.js{{&key_query}}"></script>
|
||||
<style>
|
||||
body { margin:0; padding:0; }
|
||||
#map { position:absolute; top:0; bottom:0; width:100%; }
|
||||
@@ -24,14 +24,15 @@
|
||||
(q.indexOf('raster') >= 0 ? 'raster' :
|
||||
(mapboxgl.supported() ? 'vector' : 'raster'));
|
||||
if (preference == 'vector') {
|
||||
mapboxgl.setRTLTextPlugin('{{public_url}}mapbox-gl-rtl-text.js{{&key_query}}');
|
||||
var map = new mapboxgl.Map({
|
||||
container: 'map',
|
||||
style: '/styles/{{id}}.json{{&key_query}}',
|
||||
style: '{{public_url}}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', '{{public_url}}styles/{{id}}.json{{&key_query}}', { zoomControl: false });
|
||||
new L.Control.Zoom({ position: 'topright' }).addTo(map);
|
||||
setTimeout(function() {
|
||||
new L.Hash(map);
|
||||
|
||||
407
public/templates/wmts.tmpl
Normal file
@@ -0,0 +1,407 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
|
||||
<!-- Service Identification -->
|
||||
<ows:ServiceIdentification>
|
||||
<ows:Title>TileServer GL</ows:Title>
|
||||
<ows:ServiceType>OGC WMTS</ows:ServiceType>
|
||||
<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
|
||||
</ows:ServiceIdentification>
|
||||
<!-- Operations Metadata -->
|
||||
<ows:OperationsMetadata>
|
||||
<ows:Operation name="GetCapabilities">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="{{baseUrl}}/wmts/{{id}}/">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>RESTful</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
<ows:Operation name="GetTile">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="{{baseUrl}}/styles/">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>RESTful</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
</ows:OperationsMetadata>
|
||||
<Contents>
|
||||
<Layer>
|
||||
<ows:Title>{{name}}</ows:Title>
|
||||
<ows:Identifier>{{id}}</ows:Identifier>
|
||||
<ows:WGS84BoundingBox crs="urn:ogc:def:crs:OGC:2:84">
|
||||
<ows:LowerCorner>-180 -85.051128779807</ows:LowerCorner>
|
||||
<ows:UpperCorner>180 85.051128779807</ows:UpperCorner>
|
||||
</ows:WGS84BoundingBox>
|
||||
<Style isDefault="true">
|
||||
<ows:Identifier>default</ows:Identifier>
|
||||
</Style>
|
||||
<Format>image/png</Format>
|
||||
<TileMatrixSetLink>
|
||||
<TileMatrixSet>GoogleMapsCompatible</TileMatrixSet>
|
||||
</TileMatrixSetLink>
|
||||
<ResourceURL format="image/png" resourceType="tile" template="{{baseUrl}}/styles/{{id}}/{TileMatrix}/{TileCol}/{TileRow}.png{{key_query}}"/>
|
||||
</Layer><TileMatrixSet>
|
||||
<ows:Title>GoogleMapsCompatible</ows:Title>
|
||||
<ows:Abstract>GoogleMapsCompatible EPSG:3857</ows:Abstract>
|
||||
<ows:Identifier>GoogleMapsCompatible</ows:Identifier>
|
||||
<ows:SupportedCRS>urn:ogc:def:crs:EPSG::3857</ows:SupportedCRS>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>0</ows:Identifier>
|
||||
<ScaleDenominator>559082264.02872</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>1</MatrixWidth>
|
||||
<MatrixHeight>1</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>1</ows:Identifier>
|
||||
<ScaleDenominator>279541132.01436</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>2</MatrixWidth>
|
||||
<MatrixHeight>2</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>2</ows:Identifier>
|
||||
<ScaleDenominator>139770566.00718</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>4</MatrixWidth>
|
||||
<MatrixHeight>4</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>3</ows:Identifier>
|
||||
<ScaleDenominator>69885283.00359</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>8</MatrixWidth>
|
||||
<MatrixHeight>8</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>4</ows:Identifier>
|
||||
<ScaleDenominator>34942641.501795</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>16</MatrixWidth>
|
||||
<MatrixHeight>16</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>5</ows:Identifier>
|
||||
<ScaleDenominator>17471320.750897</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>32</MatrixWidth>
|
||||
<MatrixHeight>32</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>6</ows:Identifier>
|
||||
<ScaleDenominator>8735660.3754487</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>64</MatrixWidth>
|
||||
<MatrixHeight>64</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>7</ows:Identifier>
|
||||
<ScaleDenominator>4367830.1877244</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>128</MatrixWidth>
|
||||
<MatrixHeight>128</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>8</ows:Identifier>
|
||||
<ScaleDenominator>2183915.0938622</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>256</MatrixWidth>
|
||||
<MatrixHeight>256</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>9</ows:Identifier>
|
||||
<ScaleDenominator>1091957.5469311</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>512</MatrixWidth>
|
||||
<MatrixHeight>512</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>10</ows:Identifier>
|
||||
<ScaleDenominator>545978.77346554</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>1024</MatrixWidth>
|
||||
<MatrixHeight>1024</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>11</ows:Identifier>
|
||||
<ScaleDenominator>272989.38673277</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>2048</MatrixWidth>
|
||||
<MatrixHeight>2048</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>12</ows:Identifier>
|
||||
<ScaleDenominator>136494.69336639</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>4096</MatrixWidth>
|
||||
<MatrixHeight>4096</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>13</ows:Identifier>
|
||||
<ScaleDenominator>68247.346683193</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>8192</MatrixWidth>
|
||||
<MatrixHeight>8192</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>14</ows:Identifier>
|
||||
<ScaleDenominator>34123.673341597</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>16384</MatrixWidth>
|
||||
<MatrixHeight>16384</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>15</ows:Identifier>
|
||||
<ScaleDenominator>17061.836670798</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>32768</MatrixWidth>
|
||||
<MatrixHeight>32768</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>16</ows:Identifier>
|
||||
<ScaleDenominator>8530.9183353991</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>65536</MatrixWidth>
|
||||
<MatrixHeight>65536</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>17</ows:Identifier>
|
||||
<ScaleDenominator>4265.4591676996</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>131072</MatrixWidth>
|
||||
<MatrixHeight>131072</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>18</ows:Identifier>
|
||||
<ScaleDenominator>2132.7295838498</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34 20037508.34</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>262144</MatrixWidth>
|
||||
<MatrixHeight>262144</MatrixHeight>
|
||||
</TileMatrix></TileMatrixSet><TileMatrixSet>
|
||||
<ows:Title>WGS84</ows:Title>
|
||||
<ows:Abstract>WGS84 EPSG:4326</ows:Abstract>
|
||||
<ows:Identifier>WGS84</ows:Identifier>
|
||||
<ows:SupportedCRS>urn:ogc:def:crs:EPSG::4326</ows:SupportedCRS>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>0</ows:Identifier>
|
||||
<ScaleDenominator>279541132.01436</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>2</MatrixWidth>
|
||||
<MatrixHeight>1</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>1</ows:Identifier>
|
||||
<ScaleDenominator>139770566.00718</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>4</MatrixWidth>
|
||||
<MatrixHeight>2</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>2</ows:Identifier>
|
||||
<ScaleDenominator>69885283.00359</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>8</MatrixWidth>
|
||||
<MatrixHeight>4</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>3</ows:Identifier>
|
||||
<ScaleDenominator>34942641.501795</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>16</MatrixWidth>
|
||||
<MatrixHeight>8</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>4</ows:Identifier>
|
||||
<ScaleDenominator>17471320.750897</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>32</MatrixWidth>
|
||||
<MatrixHeight>16</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>5</ows:Identifier>
|
||||
<ScaleDenominator>8735660.3754487</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>64</MatrixWidth>
|
||||
<MatrixHeight>32</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>6</ows:Identifier>
|
||||
<ScaleDenominator>4367830.1877244</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>128</MatrixWidth>
|
||||
<MatrixHeight>64</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>7</ows:Identifier>
|
||||
<ScaleDenominator>2183915.0938622</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>256</MatrixWidth>
|
||||
<MatrixHeight>128</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>8</ows:Identifier>
|
||||
<ScaleDenominator>1091957.5469311</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>512</MatrixWidth>
|
||||
<MatrixHeight>256</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>9</ows:Identifier>
|
||||
<ScaleDenominator>545978.77346554</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>1024</MatrixWidth>
|
||||
<MatrixHeight>512</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>10</ows:Identifier>
|
||||
<ScaleDenominator>272989.38673277</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>2048</MatrixWidth>
|
||||
<MatrixHeight>1024</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>11</ows:Identifier>
|
||||
<ScaleDenominator>136494.69336639</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>4096</MatrixWidth>
|
||||
<MatrixHeight>2048</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>12</ows:Identifier>
|
||||
<ScaleDenominator>68247.346683193</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>8192</MatrixWidth>
|
||||
<MatrixHeight>4096</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>13</ows:Identifier>
|
||||
<ScaleDenominator>34123.673341597</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>16384</MatrixWidth>
|
||||
<MatrixHeight>8192</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>14</ows:Identifier>
|
||||
<ScaleDenominator>17061.836670798</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>32768</MatrixWidth>
|
||||
<MatrixHeight>16384</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>15</ows:Identifier>
|
||||
<ScaleDenominator>8530.9183353991</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>65536</MatrixWidth>
|
||||
<MatrixHeight>32768</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>16</ows:Identifier>
|
||||
<ScaleDenominator>4265.4591676996</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>131072</MatrixWidth>
|
||||
<MatrixHeight>65536</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>17</ows:Identifier>
|
||||
<ScaleDenominator>2132.7295838498</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>262144</MatrixWidth>
|
||||
<MatrixHeight>131072</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>18</ows:Identifier>
|
||||
<ScaleDenominator>1066.3647919249</ScaleDenominator>
|
||||
<TopLeftCorner>90 -180</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>524288</MatrixWidth>
|
||||
<MatrixHeight>262144</MatrixHeight>
|
||||
</TileMatrix></TileMatrixSet>
|
||||
</Contents>
|
||||
<ServiceMetadataURL xlink:href="{{baseUrl}}/wmts/{{id}}/"/>
|
||||
</Capabilities>
|
||||
11
publish.js
@@ -22,17 +22,24 @@ var packageJson = require('./package');
|
||||
packageJson.name += '-light';
|
||||
packageJson.description = 'Map tile server for JSON GL styles - serving vector tiles';
|
||||
delete packageJson.dependencies['canvas'];
|
||||
delete packageJson.dependencies['mapbox-gl-native'];
|
||||
delete packageJson.dependencies['node-pngquant-native'];
|
||||
delete packageJson.dependencies['@mapbox/mapbox-gl-native'];
|
||||
delete packageJson.dependencies['sharp'];
|
||||
|
||||
delete packageJson.optionalDependencies;
|
||||
delete packageJson.devDependencies;
|
||||
|
||||
packageJson.engines.node = '>= 10';
|
||||
|
||||
var str = JSON.stringify(packageJson, undefined, 2);
|
||||
fs.writeFileSync('light/package.json', str);
|
||||
fs.renameSync('light/README_light.md', 'light/README.md');
|
||||
fs.renameSync('light/Dockerfile_light', 'light/Dockerfile');
|
||||
|
||||
// for Build tileserver-gl-light docker image, don't publish
|
||||
if (process.argv.length > 2 && process.argv[2] == "--no-publish") {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
/* PUBLISH */
|
||||
|
||||
// tileserver-gl
|
||||
|
||||
36
run.sh
@@ -1,3 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
_term() {
|
||||
echo "Caught signal, stopping gracefully"
|
||||
kill -TERM "$child" 2>/dev/null
|
||||
}
|
||||
|
||||
trap _term SIGTERM
|
||||
trap _term SIGINT
|
||||
|
||||
xvfbMaxStartWaitTime=60
|
||||
displayNumber=99
|
||||
screenNumber=0
|
||||
|
||||
# Delete files if they were not cleaned by last run
|
||||
rm -rf /tmp/.X11-unix /tmp/.X${displayNumber}-lock ~/xvfb.pid
|
||||
|
||||
echo "Starting Xvfb on display ${displayNumber}"
|
||||
start-stop-daemon --start --pidfile ~/xvfb.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :${displayNumber} -screen ${screenNumber} 1024x768x24 -ac +extension GLX +render -noreset
|
||||
|
||||
# Wait to be able to connect to the port. This will exit if it cannot in 1 minute.
|
||||
timeout ${xvfbMaxStartWaitTime} bash -c "while ! xdpyinfo -display :${displayNumber} >/dev/null; do sleep 0.5; done"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Could not connect to display ${displayNumber} in ${xvfbMaxStartWaitTime} seconds time."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export DISPLAY=:${displayNumber}.${screenNumber}
|
||||
|
||||
echo
|
||||
cd /data
|
||||
xvfb-run -a -e /dev/stdout --server-args="-screen 0 1024x768x24" node /usr/src/app/ -p 80 "$@"
|
||||
node /usr/src/app/ -p 80 "$@" &
|
||||
child=$!
|
||||
wait "$child"
|
||||
|
||||
start-stop-daemon --stop --retry 5 --pidfile ~/xvfb.pid # stop xvfb when exiting
|
||||
rm ~/xvfb.pid
|
||||
|
||||
222
src/main.js
@@ -2,79 +2,125 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
request = require('request');
|
||||
require = require('esm')(module);
|
||||
|
||||
var mbtiles = require('mbtiles');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const request = require('request');
|
||||
|
||||
var packageJson = require('../package');
|
||||
const MBTiles = require('@mapbox/mbtiles');
|
||||
|
||||
var opts = require('nomnom')
|
||||
.option('mbtiles', {
|
||||
default: undefined,
|
||||
help: 'MBTiles file (uses demo configuration);\n' +
|
||||
'\t ignored if the configuration file is also specified',
|
||||
position: 0
|
||||
})
|
||||
.option('config', {
|
||||
abbr: 'c',
|
||||
default: 'config.json',
|
||||
help: 'Configuration file'
|
||||
})
|
||||
.option('bind', {
|
||||
abbr: 'b',
|
||||
default: undefined,
|
||||
help: 'Bind address'
|
||||
})
|
||||
.option('port', {
|
||||
abbr: 'p',
|
||||
default: 8080,
|
||||
help: 'Port'
|
||||
})
|
||||
.option('verbose', {
|
||||
abbr: 'V',
|
||||
flag: true,
|
||||
help: 'More verbose output'
|
||||
})
|
||||
.option('version', {
|
||||
abbr: 'v',
|
||||
flag: true,
|
||||
help: 'Version info',
|
||||
callback: function() {
|
||||
return packageJson.name + ' v' + packageJson.version;
|
||||
const packageJson = require('../package');
|
||||
|
||||
const args = process.argv;
|
||||
if (args.length >= 3 && args[2][0] !== '-') {
|
||||
args.splice(2, 0, '--mbtiles');
|
||||
}
|
||||
}).parse();
|
||||
|
||||
const opts = require('commander')
|
||||
.description('tileserver-gl startup options')
|
||||
.usage('tileserver-gl [mbtiles] [options]')
|
||||
.option(
|
||||
'--mbtiles <file>',
|
||||
'MBTiles file (uses demo configuration);\n' +
|
||||
'\t ignored if the configuration file is also specified'
|
||||
)
|
||||
.option(
|
||||
'-c, --config <file>',
|
||||
'Configuration file [config.json]',
|
||||
'config.json'
|
||||
)
|
||||
.option(
|
||||
'-b, --bind <address>',
|
||||
'Bind address'
|
||||
)
|
||||
.option(
|
||||
'-p, --port <port>',
|
||||
'Port [8080]',
|
||||
8080,
|
||||
parseInt
|
||||
)
|
||||
.option(
|
||||
'-C|--no-cors',
|
||||
'Disable Cross-origin resource sharing headers'
|
||||
)
|
||||
.option(
|
||||
'-u|--public_url <url>',
|
||||
'Enable exposing the server on subpaths, not necessarily the root of the domain'
|
||||
)
|
||||
.option(
|
||||
'-V, --verbose',
|
||||
'More verbose output'
|
||||
)
|
||||
.option(
|
||||
'-s, --silent',
|
||||
'Less verbose output'
|
||||
)
|
||||
.option(
|
||||
'-l|--log_file <file>',
|
||||
'output log file (defaults to standard out)'
|
||||
)
|
||||
.option(
|
||||
'-f|--log_format <format>',
|
||||
'define the log format: https://github.com/expressjs/morgan#morganformat-options'
|
||||
)
|
||||
.version(
|
||||
packageJson.version,
|
||||
'-v, --version'
|
||||
)
|
||||
.parse(args);
|
||||
|
||||
console.log('Starting ' + packageJson.name + ' v' + packageJson.version);
|
||||
console.log(`Starting ${packageJson.name} v${packageJson.version}`);
|
||||
|
||||
var startServer = function(configPath, config) {
|
||||
const startServer = (configPath, config) => {
|
||||
let publicUrl = opts.public_url;
|
||||
if (publicUrl && publicUrl.lastIndexOf('/') !== publicUrl.length - 1) {
|
||||
publicUrl += '/';
|
||||
}
|
||||
return require('./server')({
|
||||
configPath: configPath,
|
||||
config: config,
|
||||
bind: opts.bind,
|
||||
port: opts.port
|
||||
port: opts.port,
|
||||
cors: opts.cors,
|
||||
verbose: opts.verbose,
|
||||
silent: opts.silent,
|
||||
logFile: opts.log_file,
|
||||
logFormat: opts.log_format,
|
||||
publicUrl: publicUrl
|
||||
});
|
||||
};
|
||||
|
||||
var startWithMBTiles = function(mbtilesFile) {
|
||||
console.log('Automatically creating config file for ' + mbtilesFile);
|
||||
const startWithMBTiles = (mbtilesFile) => {
|
||||
console.log(`[INFO] Automatically creating config file for ${mbtilesFile}`);
|
||||
console.log(`[INFO] Only a basic preview style will be used.`);
|
||||
console.log(`[INFO] See documentation to learn how to create config.json file.`);
|
||||
|
||||
mbtilesFile = path.resolve(process.cwd(), mbtilesFile);
|
||||
|
||||
var mbtilesStats = fs.statSync(mbtilesFile);
|
||||
const mbtilesStats = fs.statSync(mbtilesFile);
|
||||
if (!mbtilesStats.isFile() || mbtilesStats.size === 0) {
|
||||
console.log('ERROR: Not valid MBTiles file: ' + mbtilesFile);
|
||||
console.log(`ERROR: Not valid MBTiles file: ${mbtilesFile}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const instance = new MBTiles(mbtilesFile, (err) => {
|
||||
if (err) {
|
||||
console.log('ERROR: Unable to open MBTiles.');
|
||||
console.log(` Make sure ${path.basename(mbtilesFile)} is valid MBTiles.`);
|
||||
process.exit(1);
|
||||
}
|
||||
var instance = new mbtiles(mbtilesFile, function(err) {
|
||||
instance.getInfo(function(err, info) {
|
||||
var bounds = info.bounds;
|
||||
|
||||
var styleDir = path.resolve(__dirname, "../node_modules/tileserver-gl-styles/");
|
||||
instance.getInfo((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);
|
||||
}
|
||||
const bounds = info.bounds;
|
||||
|
||||
var config = {
|
||||
const styleDir = path.resolve(__dirname, "../node_modules/tileserver-gl-styles/");
|
||||
|
||||
const config = {
|
||||
"options": {
|
||||
"paths": {
|
||||
"root": styleDir,
|
||||
@@ -87,58 +133,32 @@ var startWithMBTiles = function(mbtilesFile) {
|
||||
"data": {}
|
||||
};
|
||||
|
||||
if (info.format == 'pbf' &&
|
||||
if (info.format === 'pbf' &&
|
||||
info.name.toLowerCase().indexOf('openmaptiles') > -1) {
|
||||
config['data']['openmaptiles'] = {
|
||||
|
||||
config['data'][`v3`] = {
|
||||
"mbtiles": path.basename(mbtilesFile)
|
||||
};
|
||||
|
||||
var omtV = (info.version || '').split('.');
|
||||
|
||||
var styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
|
||||
for (var i = 0; i < styles.length; i++) {
|
||||
var styleName = styles[i];
|
||||
var styleFileRel = styleName + '/style.json';
|
||||
var styleFile = path.resolve(styleDir, 'styles', styleFileRel);
|
||||
const styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
|
||||
for (let styleName of styles) {
|
||||
const styleFileRel = styleName + '/style.json';
|
||||
const styleFile = path.resolve(styleDir, 'styles', styleFileRel);
|
||||
if (fs.existsSync(styleFile)) {
|
||||
var styleJSON = require(styleFile);
|
||||
var omtVersionCompatibility =
|
||||
((styleJSON || {}).metadata || {})['openmaptiles:version'] || 'x';
|
||||
var m = omtVersionCompatibility.toLowerCase().split('.');
|
||||
|
||||
var isCompatible = !(
|
||||
m[0] != 'x' && (
|
||||
m[0] != omtV[0] || (
|
||||
(m[1] || 'x') != 'x' && (
|
||||
m[1] != omtV[1] || (
|
||||
(m[2] || 'x') != 'x' &&
|
||||
m[2] != omtV[2]
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if (isCompatible) {
|
||||
var styleObject = {
|
||||
config['styles'][styleName] = {
|
||||
"style": styleFileRel,
|
||||
"tilejson": {
|
||||
"bounds": bounds
|
||||
}
|
||||
};
|
||||
config['styles'][styleName] = styleObject;
|
||||
} else {
|
||||
console.log('Style', styleName, 'requires OpenMapTiles version',
|
||||
omtVersionCompatibility, 'but mbtiles is version', info.version);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('WARN: MBTiles not in "openmaptiles" format. ' +
|
||||
'Serving raw data only...');
|
||||
console.log(`WARN: MBTiles not in "openmaptiles" format. Serving raw data only...`);
|
||||
config['data'][(info.id || 'mbtiles')
|
||||
.replace(/\//g, '_')
|
||||
.replace(/\:/g, '_')
|
||||
.replace(/:/g, '_')
|
||||
.replace(/\?/g, '_')] = {
|
||||
"mbtiles": path.basename(mbtilesFile)
|
||||
};
|
||||
@@ -155,16 +175,15 @@ var startWithMBTiles = function(mbtilesFile) {
|
||||
});
|
||||
};
|
||||
|
||||
fs.stat(path.resolve(opts.config), function(err, stats) {
|
||||
fs.stat(path.resolve(opts.config), (err, stats) => {
|
||||
if (err || !stats.isFile() || stats.size === 0) {
|
||||
var mbtiles = opts.mbtiles;
|
||||
let mbtiles = opts.mbtiles;
|
||||
if (!mbtiles) {
|
||||
// try to find in the cwd
|
||||
var files = fs.readdirSync(process.cwd());
|
||||
for (var i=0; i < files.length; i++) {
|
||||
var filename = files[i];
|
||||
const files = fs.readdirSync(process.cwd());
|
||||
for (let filename of files) {
|
||||
if (filename.endsWith('.mbtiles')) {
|
||||
var mbTilesStats = fs.statSync(filename);
|
||||
const mbTilesStats = fs.statSync(filename);
|
||||
if (mbTilesStats.isFile() && mbTilesStats.size > 0) {
|
||||
mbtiles = filename;
|
||||
break;
|
||||
@@ -172,16 +191,15 @@ fs.stat(path.resolve(opts.config), function(err, stats) {
|
||||
}
|
||||
}
|
||||
if (mbtiles) {
|
||||
console.log('No MBTiles specified, using ' + mbtiles);
|
||||
console.log(`No MBTiles specified, using ${mbtiles}`);
|
||||
return startWithMBTiles(mbtiles);
|
||||
} else {
|
||||
var url = 'https://github.com/klokantech/tileserver-gl/releases/download/v1.3.0/zurich_switzerland.mbtiles';
|
||||
var filename = 'zurich_switzerland.mbtiles';
|
||||
var stream = fs.createWriteStream(filename);
|
||||
console.log('Downloading sample data (' + filename + ') from ' + url);
|
||||
stream.on('finish', function() {
|
||||
return startWithMBTiles(filename);
|
||||
});
|
||||
const url = 'https://github.com/maptiler/tileserver-gl/releases/download/v1.3.0/zurich_switzerland.mbtiles';
|
||||
const filename = 'zurich_switzerland.mbtiles';
|
||||
const stream = fs.createWriteStream(filename);
|
||||
console.log(`No MBTiles found`);
|
||||
console.log(`[DEMO] Downloading sample data (${filename}) from ${url}`);
|
||||
stream.on('finish', () => startWithMBTiles(filename));
|
||||
return request.get(url).pipe(stream);
|
||||
}
|
||||
}
|
||||
@@ -189,7 +207,7 @@ fs.stat(path.resolve(opts.config), function(err, stats) {
|
||||
return startWithMBTiles(mbtiles);
|
||||
}
|
||||
} else {
|
||||
console.log('Using specified config file from ' + opts.config);
|
||||
console.log(`Using specified config file from ${opts.config}`);
|
||||
return startServer(opts.config, null);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,74 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
zlib = require('zlib');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const zlib = require('zlib');
|
||||
|
||||
var clone = require('clone'),
|
||||
express = require('express'),
|
||||
mbtiles = require('mbtiles'),
|
||||
pbf = require('pbf'),
|
||||
VectorTile = require('vector-tile').VectorTile;
|
||||
const clone = require('clone');
|
||||
const express = require('express');
|
||||
const MBTiles = require('@mapbox/mbtiles');
|
||||
const Pbf = require('pbf');
|
||||
const VectorTile = require('@mapbox/vector-tile').VectorTile;
|
||||
|
||||
var tileshrinkGl;
|
||||
try {
|
||||
tileshrinkGl = require('tileshrink-gl');
|
||||
} catch (e) {}
|
||||
const utils = require('./utils');
|
||||
|
||||
var utils = require('./utils');
|
||||
module.exports = {
|
||||
init: (options, repo) => {
|
||||
const app = express().disable('x-powered-by');
|
||||
|
||||
module.exports = function(options, repo, params, id, styles) {
|
||||
var app = express().disable('x-powered-by');
|
||||
|
||||
var mbtilesFile = path.resolve(options.paths.mbtiles, params.mbtiles);
|
||||
var tileJSON = {
|
||||
'tiles': params.domains || options.domains
|
||||
};
|
||||
|
||||
var shrinkers = {};
|
||||
|
||||
repo[id] = tileJSON;
|
||||
|
||||
var mbtilesFileStats = fs.statSync(mbtilesFile);
|
||||
if (!mbtilesFileStats.isFile() || mbtilesFileStats.size == 0) {
|
||||
throw Error('Not valid MBTiles file: ' + mbtilesFile);
|
||||
app.get('/:id/:z(\\d+)/:x(\\d+)/:y(\\d+).:format([\\w.]+)', (req, res, next) => {
|
||||
const item = repo[req.params.id];
|
||||
if (!item) {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
var source = new mbtiles(mbtilesFile, function(err) {
|
||||
source.getInfo(function(err, info) {
|
||||
tileJSON['name'] = id;
|
||||
tileJSON['format'] = 'pbf';
|
||||
|
||||
Object.assign(tileJSON, info);
|
||||
|
||||
tileJSON['tilejson'] = '2.0.0';
|
||||
delete tileJSON['filesize'];
|
||||
delete tileJSON['mtime'];
|
||||
delete tileJSON['scheme'];
|
||||
|
||||
Object.assign(tileJSON, params.tilejson || {});
|
||||
utils.fixTileJSONCenter(tileJSON);
|
||||
});
|
||||
});
|
||||
|
||||
var tilePattern = '/' + id + '/:z(\\d+)/:x(\\d+)/:y(\\d+).:format([\\w]+)';
|
||||
|
||||
app.get(tilePattern, function(req, res, next) {
|
||||
var z = req.params.z | 0,
|
||||
x = req.params.x | 0,
|
||||
y = req.params.y | 0;
|
||||
if (req.params.format != tileJSON.format &&
|
||||
!(req.params.format == 'geojson' && tileJSON.format == 'pbf')) {
|
||||
let tileJSONFormat = item.tileJSON.format;
|
||||
const z = req.params.z | 0;
|
||||
const x = req.params.x | 0;
|
||||
const y = req.params.y | 0;
|
||||
let format = req.params.format;
|
||||
if (format === options.pbfAlias) {
|
||||
format = 'pbf';
|
||||
}
|
||||
if (format !== tileJSONFormat &&
|
||||
!(format === 'geojson' && tileJSONFormat === 'pbf')) {
|
||||
return res.status(404).send('Invalid format');
|
||||
}
|
||||
if (z < tileJSON.minzoom || 0 || x < 0 || y < 0 ||
|
||||
z > tileJSON.maxzoom ||
|
||||
if (z < item.tileJSON.minzoom || 0 || x < 0 || y < 0 ||
|
||||
z > item.tileJSON.maxzoom ||
|
||||
x >= Math.pow(2, z) || y >= Math.pow(2, z)) {
|
||||
return res.status(404).send('Out of bounds');
|
||||
}
|
||||
source.getTile(z, x, y, function(err, data, headers) {
|
||||
item.source.getTile(z, x, y, (err, data, headers) => {
|
||||
let isGzipped;
|
||||
if (err) {
|
||||
if (/does not exist/.test(err.message)) {
|
||||
return res.status(404).send(err.message);
|
||||
return res.status(204).send();
|
||||
} else {
|
||||
return res.status(500).send(err.message);
|
||||
}
|
||||
@@ -76,39 +50,20 @@ module.exports = function(options, repo, params, id, styles) {
|
||||
if (data == null) {
|
||||
return res.status(404).send('Not found');
|
||||
} else {
|
||||
if (tileJSON['format'] == 'pbf') {
|
||||
var isGzipped = data.slice(0,2).indexOf(
|
||||
new Buffer([0x1f, 0x8b])) === 0;
|
||||
var style = req.query.style;
|
||||
if (style && tileshrinkGl) {
|
||||
if (!shrinkers[style]) {
|
||||
var styleJSON = styles[style];
|
||||
if (styleJSON) {
|
||||
var sourceName = null;
|
||||
for (var sourceName_ in styleJSON.sources) {
|
||||
var source = styleJSON.sources[sourceName_];
|
||||
if (source &&
|
||||
source.type == 'vector' &&
|
||||
source.url.endsWith('/' + id + '.json')) {
|
||||
sourceName = sourceName_;
|
||||
}
|
||||
}
|
||||
shrinkers[style] = tileshrinkGl.createPBFShrinker(styleJSON, sourceName);
|
||||
}
|
||||
}
|
||||
if (shrinkers[style]) {
|
||||
if (tileJSONFormat === 'pbf') {
|
||||
isGzipped = data.slice(0, 2).indexOf(
|
||||
Buffer.from([0x1f, 0x8b])) === 0;
|
||||
if (options.dataDecoratorFunc) {
|
||||
if (isGzipped) {
|
||||
data = zlib.unzipSync(data);
|
||||
isGzipped = false;
|
||||
}
|
||||
data = shrinkers[style](data, z, tileJSON.maxzoom);
|
||||
//console.log(shrinkers[style].getStats());
|
||||
data = options.dataDecoratorFunc(id, 'data', data, z, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (req.params.format == 'pbf') {
|
||||
if (format === 'pbf') {
|
||||
headers['Content-Type'] = 'application/x-protobuf';
|
||||
} else if (req.params.format == 'geojson') {
|
||||
} else if (format === 'geojson') {
|
||||
headers['Content-Type'] = 'application/json';
|
||||
|
||||
if (isGzipped) {
|
||||
@@ -116,16 +71,16 @@ module.exports = function(options, repo, params, id, styles) {
|
||||
isGzipped = false;
|
||||
}
|
||||
|
||||
var tile = new VectorTile(new pbf(data));
|
||||
var geojson = {
|
||||
const tile = new VectorTile(new Pbf(data));
|
||||
const geojson = {
|
||||
"type": "FeatureCollection",
|
||||
"features": []
|
||||
};
|
||||
for (var layerName in tile.layers) {
|
||||
var layer = tile.layers[layerName];
|
||||
for (var i = 0; i < layer.length; i++) {
|
||||
var feature = layer.feature(i);
|
||||
var featureGeoJSON = feature.toGeoJSON(x, y, z);
|
||||
for (let layerName in tile.layers) {
|
||||
const layer = tile.layers[layerName];
|
||||
for (let i = 0; i < layer.length; i++) {
|
||||
const feature = layer.feature(i);
|
||||
const featureGeoJSON = feature.toGeoJSON(x, y, z);
|
||||
featureGeoJSON.properties.layer = layerName;
|
||||
geojson.features.push(featureGeoJSON);
|
||||
}
|
||||
@@ -147,12 +102,70 @@ module.exports = function(options, repo, params, id, styles) {
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/' + id + '.json', function(req, res, next) {
|
||||
var info = clone(tileJSON);
|
||||
app.get('/:id.json', (req, res, next) => {
|
||||
const item = repo[req.params.id];
|
||||
if (!item) {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
const info = clone(item.tileJSON);
|
||||
info.tiles = utils.getTileUrls(req, info.tiles,
|
||||
'data/' + id, info.format);
|
||||
`data/${req.params.id}`, info.format, item.publicUrl, {
|
||||
'pbf': options.pbfAlias
|
||||
});
|
||||
return res.send(info);
|
||||
});
|
||||
|
||||
return app;
|
||||
},
|
||||
add: (options, repo, params, id, publicUrl) => {
|
||||
const mbtilesFile = path.resolve(options.paths.mbtiles, params.mbtiles);
|
||||
let tileJSON = {
|
||||
'tiles': params.domains || options.domains
|
||||
};
|
||||
|
||||
const mbtilesFileStats = fs.statSync(mbtilesFile);
|
||||
if (!mbtilesFileStats.isFile() || mbtilesFileStats.size === 0) {
|
||||
throw Error(`Not valid MBTiles file: ${mbtilesFile}`);
|
||||
}
|
||||
let source;
|
||||
const sourceInfoPromise = new Promise((resolve, reject) => {
|
||||
source = new MBTiles(mbtilesFile, err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
source.getInfo((err, info) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
tileJSON['name'] = id;
|
||||
tileJSON['format'] = 'pbf';
|
||||
|
||||
Object.assign(tileJSON, info);
|
||||
|
||||
tileJSON['tilejson'] = '2.0.0';
|
||||
delete tileJSON['filesize'];
|
||||
delete tileJSON['mtime'];
|
||||
delete tileJSON['scheme'];
|
||||
|
||||
Object.assign(tileJSON, params.tilejson || {});
|
||||
utils.fixTileJSONCenter(tileJSON);
|
||||
|
||||
if (options.dataDecoratorFunc) {
|
||||
tileJSON = options.dataDecoratorFunc(id, 'tilejson', tileJSON);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return sourceInfoPromise.then(() => {
|
||||
repo[id] = {
|
||||
tileJSON,
|
||||
publicUrl,
|
||||
source
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,59 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
var clone = require('clone'),
|
||||
express = require('express'),
|
||||
fs = require('fs'),
|
||||
path = require('path');
|
||||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
var utils = require('./utils');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = function(options, allowedFonts) {
|
||||
var app = express().disable('x-powered-by');
|
||||
module.exports = (options, allowedFonts) => {
|
||||
const app = express().disable('x-powered-by');
|
||||
|
||||
var lastModified = new Date().toUTCString();
|
||||
const lastModified = new Date().toUTCString();
|
||||
|
||||
var fontPath = options.paths.fonts;
|
||||
const 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) {
|
||||
const existingFonts = {};
|
||||
const fontListingPromise = new Promise((resolve, reject) => {
|
||||
fs.readdir(options.paths.fonts, (err, files) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
for (const file of files) {
|
||||
fs.stat(path.join(fontPath, file), (err, stats) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
if (stats.isDirectory() &&
|
||||
fs.existsSync(path.join(fontPath, file, '0-255.pbf'))) {
|
||||
existingFonts[path.basename(file)] = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/fonts/:fontstack/:range([\\d]+-[\\d]+).pbf',
|
||||
function(req, res, next) {
|
||||
var fontstack = decodeURI(req.params.fontstack);
|
||||
var range = req.params.range;
|
||||
app.get('/fonts/:fontstack/:range([\\d]+-[\\d]+).pbf', (req, res, next) => {
|
||||
const fontstack = decodeURI(req.params.fontstack);
|
||||
const 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(concated => {
|
||||
res.header('Content-type', 'application/x-protobuf');
|
||||
res.header('Last-Modified', lastModified);
|
||||
return res.send(concated);
|
||||
}
|
||||
});
|
||||
}, err => res.status(400).send(err)
|
||||
);
|
||||
});
|
||||
|
||||
app.get('/fontstacks.json', function(req, res, next) {
|
||||
app.get('/fonts.json', (req, res, next) => {
|
||||
res.header('Content-type', 'application/json');
|
||||
return res.send(
|
||||
Object.keys(options.serveAllFonts ? existingFonts : allowedFonts).sort()
|
||||
);
|
||||
});
|
||||
|
||||
return app;
|
||||
return fontListingPromise.then(() => app);
|
||||
};
|
||||
|
||||
@@ -1,37 +1,128 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path'),
|
||||
fs = require('fs');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
var clone = require('clone'),
|
||||
express = require('express');
|
||||
const clone = require('clone');
|
||||
const express = require('express');
|
||||
import {validate} from '@mapbox/mapbox-gl-style-spec';
|
||||
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||
var app = express().disable('x-powered-by');
|
||||
const httpTester = /^(http(s)?:)?\/\//;
|
||||
|
||||
var styleFile = path.join(options.paths.styles, params.style);
|
||||
const fixUrl = (req, url, publicUrl, opt_nokey) => {
|
||||
if (!url || (typeof url !== 'string') || url.indexOf('local://') !== 0) {
|
||||
return url;
|
||||
}
|
||||
const queryParams = [];
|
||||
if (!opt_nokey && req.query.key) {
|
||||
queryParams.unshift(`key=${encodeURIComponent(req.query.key)}`);
|
||||
}
|
||||
let query = '';
|
||||
if (queryParams.length) {
|
||||
query = `?${queryParams.join('&')}`;
|
||||
}
|
||||
return url.replace(
|
||||
'local://', utils.getPublicUrl(publicUrl, req)) + query;
|
||||
};
|
||||
|
||||
var styleJSON = clone(require(styleFile));
|
||||
Object.keys(styleJSON.sources).forEach(function(name) {
|
||||
var source = styleJSON.sources[name];
|
||||
var url = source.url;
|
||||
module.exports = {
|
||||
init: (options, repo) => {
|
||||
const app = express().disable('x-powered-by');
|
||||
|
||||
app.get('/:id/style.json', (req, res, next) => {
|
||||
const item = repo[req.params.id];
|
||||
if (!item) {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
const styleJSON_ = clone(item.styleJSON);
|
||||
for (const name of Object.keys(styleJSON_.sources)) {
|
||||
const source = styleJSON_.sources[name];
|
||||
source.url = fixUrl(req, source.url, item.publicUrl);
|
||||
}
|
||||
// mapbox-gl-js viewer cannot handle sprite urls with query
|
||||
if (styleJSON_.sprite) {
|
||||
styleJSON_.sprite = fixUrl(req, styleJSON_.sprite, item.publicUrl, false);
|
||||
}
|
||||
if (styleJSON_.glyphs) {
|
||||
styleJSON_.glyphs = fixUrl(req, styleJSON_.glyphs, item.publicUrl, false);
|
||||
}
|
||||
return res.send(styleJSON_);
|
||||
});
|
||||
|
||||
app.get('/:id/sprite:scale(@[23]x)?.:format([\\w]+)', (req, res, next) => {
|
||||
const item = repo[req.params.id];
|
||||
if (!item || !item.spritePath) {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
const scale = req.params.scale,
|
||||
format = req.params.format;
|
||||
const filename = `${item.spritePath + (scale || '')}.${format}`;
|
||||
return fs.readFile(filename, (err, data) => {
|
||||
if (err) {
|
||||
console.log('Sprite load error:', filename);
|
||||
return res.sendStatus(404);
|
||||
} else {
|
||||
if (format === 'json') res.header('Content-type', 'application/json');
|
||||
if (format === 'png') res.header('Content-type', 'image/png');
|
||||
return res.send(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return app;
|
||||
},
|
||||
remove: (repo, id) => {
|
||||
delete repo[id];
|
||||
},
|
||||
add: (options, repo, params, id, publicUrl, reportTiles, reportFont) => {
|
||||
const styleFile = path.resolve(options.paths.styles, params.style);
|
||||
|
||||
let styleFileData;
|
||||
try {
|
||||
styleFileData = fs.readFileSync(styleFile);
|
||||
} catch (e) {
|
||||
console.log('Error reading style file');
|
||||
return false;
|
||||
}
|
||||
|
||||
let validationErrors = validate(styleFileData);
|
||||
if (validationErrors.length > 0) {
|
||||
console.log(`The file "${params.style}" is not valid a valid style file:`);
|
||||
for (const err of validationErrors) {
|
||||
console.log(`${err.line}: ${err.message}`);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
let styleJSON = JSON.parse(styleFileData);
|
||||
|
||||
for (const name of Object.keys(styleJSON.sources)) {
|
||||
const source = styleJSON.sources[name];
|
||||
const url = source.url;
|
||||
if (url && url.lastIndexOf('mbtiles:', 0) === 0) {
|
||||
var mbtilesFile = url.substring('mbtiles://'.length);
|
||||
var fromData = mbtilesFile[0] == '{' &&
|
||||
mbtilesFile[mbtilesFile.length - 1] == '}';
|
||||
let mbtilesFile = url.substring('mbtiles://'.length);
|
||||
const fromData = mbtilesFile[0] === '{' &&
|
||||
mbtilesFile[mbtilesFile.length - 1] === '}';
|
||||
|
||||
if (fromData) {
|
||||
mbtilesFile = mbtilesFile.substr(1, mbtilesFile.length - 2);
|
||||
const mapsTo = (params.mapping || {})[mbtilesFile];
|
||||
if (mapsTo) {
|
||||
mbtilesFile = mapsTo;
|
||||
}
|
||||
}
|
||||
const identifier = reportTiles(mbtilesFile, fromData);
|
||||
if (!identifier) {
|
||||
return false;
|
||||
}
|
||||
source.url = `local://data/${identifier}.json`;
|
||||
}
|
||||
var identifier = reportTiles(mbtilesFile, fromData);
|
||||
source.url = 'local://data/' + identifier + '.json';
|
||||
}
|
||||
});
|
||||
|
||||
styleJSON.layers.forEach(function(obj) {
|
||||
if (obj['type'] == 'symbol') {
|
||||
var fonts = (obj['layout'] || {})['text-font'];
|
||||
for (let obj of styleJSON.layers) {
|
||||
if (obj['type'] === 'symbol') {
|
||||
const fonts = (obj['layout'] || {})['text-font'];
|
||||
if (fonts && fonts.length) {
|
||||
fonts.forEach(reportFont);
|
||||
} else {
|
||||
@@ -39,76 +130,29 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||
reportFont('Arial Unicode MS Regular');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var spritePath;
|
||||
let spritePath;
|
||||
|
||||
var httpTester = /^(http(s)?:)?\/\//;
|
||||
if (styleJSON.sprite && !httpTester.test(styleJSON.sprite)) {
|
||||
spritePath = path.join(options.paths.sprites,
|
||||
styleJSON.sprite
|
||||
.replace('{style}', path.basename(styleFile, '.json'))
|
||||
.replace('{styleJsonFolder}', path.relative(options.paths.sprites, path.dirname(styleFile)))
|
||||
);
|
||||
styleJSON.sprite = 'local://styles/' + id + '/sprite';
|
||||
styleJSON.sprite = `local://styles/${id}/sprite`;
|
||||
}
|
||||
if (styleJSON.glyphs && !httpTester.test(styleJSON.glyphs)) {
|
||||
styleJSON.glyphs = 'local://fonts/{fontstack}/{range}.pbf';
|
||||
}
|
||||
|
||||
repo[id] = styleJSON;
|
||||
|
||||
app.get('/' + id + '.json', function(req, res, next) {
|
||||
var fixUrl = function(url, opt_nokey, opt_nostyle) {
|
||||
var queryParams = [];
|
||||
if (!opt_nostyle) {
|
||||
queryParams.push('style=' + id);
|
||||
}
|
||||
if (!opt_nokey && req.query.key) {
|
||||
queryParams.unshift('key=' + req.query.key);
|
||||
}
|
||||
var query = '';
|
||||
if (queryParams.length) {
|
||||
query = '?' + queryParams.join('&');
|
||||
}
|
||||
return url.replace(
|
||||
'local://', req.protocol + '://' + req.headers.host + '/') + query;
|
||||
repo[id] = {
|
||||
styleJSON,
|
||||
spritePath,
|
||||
publicUrl,
|
||||
name: styleJSON.name
|
||||
};
|
||||
|
||||
var styleJSON_ = clone(styleJSON);
|
||||
Object.keys(styleJSON_.sources).forEach(function(name) {
|
||||
var source = styleJSON_.sources[name];
|
||||
source.url = fixUrl(source.url);
|
||||
});
|
||||
// mapbox-gl-js viewer cannot handle sprite urls with query
|
||||
if (styleJSON_.sprite) {
|
||||
styleJSON_.sprite = fixUrl(styleJSON_.sprite, true, true);
|
||||
return true;
|
||||
}
|
||||
if (styleJSON_.glyphs) {
|
||||
styleJSON_.glyphs = fixUrl(styleJSON_.glyphs, false, true);
|
||||
}
|
||||
return res.send(styleJSON_);
|
||||
});
|
||||
|
||||
app.get('/' + id + '/sprite:scale(@[23]x)?\.:format([\\w]+)',
|
||||
function(req, res, next) {
|
||||
if (!spritePath) {
|
||||
return res.status(404).send('File not found');
|
||||
}
|
||||
var scale = req.params.scale,
|
||||
format = req.params.format;
|
||||
var filename = spritePath + (scale || '') + '.' + format;
|
||||
return fs.readFile(filename, function(err, data) {
|
||||
if (err) {
|
||||
console.log('Sprite load error:', filename);
|
||||
return res.status(404).send('File not found');
|
||||
} else {
|
||||
if (format == 'json') res.header('Content-type', 'application/json');
|
||||
if (format == 'png') res.header('Content-type', 'image/png');
|
||||
return res.send(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return app;
|
||||
};
|
||||
|
||||
474
src/server.js
@@ -4,34 +4,35 @@
|
||||
process.env.UV_THREADPOOL_SIZE =
|
||||
Math.ceil(Math.max(4, require('os').cpus().length * 1.5));
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
var base64url = require('base64url'),
|
||||
clone = require('clone'),
|
||||
cors = require('cors'),
|
||||
express = require('express'),
|
||||
handlebars = require('handlebars'),
|
||||
mercator = new (require('sphericalmercator'))(),
|
||||
morgan = require('morgan');
|
||||
const chokidar = require('chokidar');
|
||||
const clone = require('clone');
|
||||
const cors = require('cors');
|
||||
const enableShutdown = require('http-shutdown');
|
||||
const express = require('express');
|
||||
const handlebars = require('handlebars');
|
||||
const mercator = new (require('@mapbox/sphericalmercator'))();
|
||||
const morgan = require('morgan');
|
||||
|
||||
var packageJson = require('../package'),
|
||||
serve_font = require('./serve_font'),
|
||||
serve_rendered = null,
|
||||
serve_style = require('./serve_style'),
|
||||
serve_data = require('./serve_data'),
|
||||
utils = require('./utils');
|
||||
const packageJson = require('../package');
|
||||
const serve_font = require('./serve_font');
|
||||
const serve_style = require('./serve_style');
|
||||
const serve_data = require('./serve_data');
|
||||
const utils = require('./utils');
|
||||
|
||||
var isLight = packageJson.name.slice(-6) == '-light';
|
||||
let serve_rendered = null;
|
||||
const isLight = packageJson.name.slice(-6) === '-light';
|
||||
if (!isLight) {
|
||||
// do not require `serve_rendered` in the light package
|
||||
serve_rendered = require('./serve_rendered');
|
||||
}
|
||||
|
||||
module.exports = function(opts, callback) {
|
||||
function start(opts) {
|
||||
console.log('Starting server');
|
||||
|
||||
var app = express().disable('x-powered-by'),
|
||||
const app = express().disable('x-powered-by'),
|
||||
serving = {
|
||||
styles: {},
|
||||
rendered: {},
|
||||
@@ -41,15 +42,17 @@ module.exports = function(opts, callback) {
|
||||
|
||||
app.enable('trust proxy');
|
||||
|
||||
callback = callback || function() {};
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' &&
|
||||
process.env.NODE_ENV !== 'test') {
|
||||
app.use(morgan('dev'));
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
const defaultLogFormat = process.env.NODE_ENV === 'production' ? 'tiny' : 'dev';
|
||||
const logFormat = opts.logFormat || defaultLogFormat;
|
||||
app.use(morgan(logFormat, {
|
||||
stream: opts.logFile ? fs.createWriteStream(opts.logFile, { flags: 'a' }) : process.stdout,
|
||||
skip: (req, res) => opts.silent && (res.statusCode === 200 || res.statusCode === 304)
|
||||
}));
|
||||
}
|
||||
|
||||
var config = opts.config || null;
|
||||
var configPath = null;
|
||||
let config = opts.config || null;
|
||||
let configPath = null;
|
||||
if (opts.configPath) {
|
||||
configPath = path.resolve(opts.configPath);
|
||||
try {
|
||||
@@ -65,8 +68,8 @@ module.exports = function(opts, callback) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var options = config.options || {};
|
||||
var paths = options.paths || {};
|
||||
const options = config.options || {};
|
||||
const paths = options.paths || {};
|
||||
options.paths = paths;
|
||||
paths.root = path.resolve(
|
||||
configPath ? path.dirname(configPath) : process.cwd(),
|
||||
@@ -76,121 +79,207 @@ module.exports = function(opts, callback) {
|
||||
paths.sprites = path.resolve(paths.root, paths.sprites || '');
|
||||
paths.mbtiles = path.resolve(paths.root, paths.mbtiles || '');
|
||||
|
||||
var data = clone(config.data || {});
|
||||
const startupPromises = [];
|
||||
|
||||
app.use(cors());
|
||||
const checkPath = type => {
|
||||
if (!fs.existsSync(paths[type])) {
|
||||
console.error(`The specified path for "${type}" does not exist (${paths[type]}).`);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
checkPath('styles');
|
||||
checkPath('fonts');
|
||||
checkPath('sprites');
|
||||
checkPath('mbtiles');
|
||||
|
||||
Object.keys(config.styles || {}).forEach(function(id) {
|
||||
var item = config.styles[id];
|
||||
if (!item.style || item.style.length == 0) {
|
||||
console.log('Missing "style" property for ' + id);
|
||||
return;
|
||||
if (options.dataDecorator) {
|
||||
try {
|
||||
options.dataDecoratorFunc = require(path.resolve(paths.root, options.dataDecorator));
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
const data = clone(config.data || {});
|
||||
|
||||
if (opts.cors) {
|
||||
app.use(cors());
|
||||
}
|
||||
|
||||
app.use('/data/', serve_data.init(options, serving.data));
|
||||
app.use('/styles/', serve_style.init(options, serving.styles));
|
||||
if (serve_rendered) {
|
||||
startupPromises.push(
|
||||
serve_rendered.init(options, serving.rendered)
|
||||
.then(sub => {
|
||||
app.use('/styles/', sub);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
let addStyle = (id, item, allowMoreData, reportFonts) => {
|
||||
let success = true;
|
||||
if (item.serve_data !== false) {
|
||||
app.use('/styles/', serve_style(options, serving.styles, item, id,
|
||||
function(mbtiles, fromData) {
|
||||
var dataItemId;
|
||||
Object.keys(data).forEach(function(id) {
|
||||
success = serve_style.add(options, serving.styles, item, id, opts.publicUrl,
|
||||
(mbtiles, fromData) => {
|
||||
let dataItemId;
|
||||
for (const id of Object.keys(data)) {
|
||||
if (fromData) {
|
||||
if (id == mbtiles) {
|
||||
if (id === mbtiles) {
|
||||
dataItemId = id;
|
||||
}
|
||||
} else {
|
||||
if (data[id].mbtiles == mbtiles) {
|
||||
if (data[id].mbtiles === mbtiles) {
|
||||
dataItemId = id;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (dataItemId) { // mbtiles exist in the data config
|
||||
return dataItemId;
|
||||
} else if (fromData) {
|
||||
console.log('ERROR: data "' + mbtiles + '" not found!');
|
||||
process.exit(1);
|
||||
} else {
|
||||
var id = mbtiles.substr(0, mbtiles.lastIndexOf('.')) || mbtiles;
|
||||
if (fromData || !allowMoreData) {
|
||||
console.log(`ERROR: style "${item.style}" using unknown mbtiles "${mbtiles}"! Skipping...`);
|
||||
return undefined;
|
||||
} else {
|
||||
let id = mbtiles.substr(0, mbtiles.lastIndexOf('.')) || mbtiles;
|
||||
while (data[id]) id += '_';
|
||||
data[id] = {
|
||||
'mbtiles': mbtiles
|
||||
};
|
||||
return id;
|
||||
}
|
||||
}, function(font) {
|
||||
serving.fonts[font] = true;
|
||||
}));
|
||||
}
|
||||
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;
|
||||
}, font => {
|
||||
if (reportFonts) {
|
||||
serving.fonts[font] = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (success && item.serve_rendered !== false) {
|
||||
if (serve_rendered) {
|
||||
startupPromises.push(serve_rendered.add(options, serving.rendered, item, id, opts.publicUrl,
|
||||
mbtiles => {
|
||||
let mbtilesFile;
|
||||
for (const id of Object.keys(data)) {
|
||||
if (id === mbtiles) {
|
||||
mbtilesFile = data[id].mbtiles;
|
||||
}
|
||||
}
|
||||
return mbtilesFile;
|
||||
}));
|
||||
}
|
||||
));
|
||||
} else {
|
||||
item.serve_rendered = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (Object.keys(serving.styles).length > 0) {
|
||||
// serve fonts only if serving some styles
|
||||
app.use('/', serve_font(options, serving.fonts));
|
||||
for (const id of Object.keys(config.styles || {})) {
|
||||
const item = config.styles[id];
|
||||
if (!item.style || item.style.length === 0) {
|
||||
console.log(`Missing "style" property for ${id}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
Object.keys(data).forEach(function(id) {
|
||||
var item = data[id];
|
||||
if (!item.mbtiles || item.mbtiles.length == 0) {
|
||||
console.log('Missing "mbtiles" property for ' + id);
|
||||
addStyle(id, item, true, true);
|
||||
}
|
||||
|
||||
startupPromises.push(
|
||||
serve_font(options, serving.fonts).then(sub => {
|
||||
app.use('/', sub);
|
||||
})
|
||||
);
|
||||
|
||||
for (const id of Object.keys(data)) {
|
||||
const item = data[id];
|
||||
if (!item.mbtiles || item.mbtiles.length === 0) {
|
||||
console.log(`Missing "mbtiles" property for ${id}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
startupPromises.push(
|
||||
serve_data.add(options, serving.data, item, id, opts.publicUrl)
|
||||
);
|
||||
}
|
||||
|
||||
if (options.serveAllStyles) {
|
||||
fs.readdir(options.paths.styles, {withFileTypes: true}, (err, files) => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.use('/data/', serve_data(options, serving.data, item, id, serving.styles));
|
||||
for (const file of files) {
|
||||
if (file.isFile() &&
|
||||
path.extname(file.name).toLowerCase() == '.json') {
|
||||
let id = path.basename(file.name, '.json');
|
||||
let item = {
|
||||
style: file.name
|
||||
};
|
||||
addStyle(id, item, false, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/styles.json', function(req, res, next) {
|
||||
var result = [];
|
||||
var query = req.query.key ? ('?key=' + req.query.key) : '';
|
||||
Object.keys(serving.styles).forEach(function(id) {
|
||||
var styleJSON = serving.styles[id];
|
||||
const watcher = chokidar.watch(path.join(options.paths.styles, '*.json'),
|
||||
{
|
||||
});
|
||||
watcher.on('all',
|
||||
(eventType, filename) => {
|
||||
if (filename) {
|
||||
let id = path.basename(filename, '.json');
|
||||
console.log(`Style "${id}" changed, updating...`);
|
||||
|
||||
serve_style.remove(serving.styles, id);
|
||||
if (serve_rendered) {
|
||||
serve_rendered.remove(serving.rendered, id);
|
||||
}
|
||||
|
||||
if (eventType == "add" || eventType == "change") {
|
||||
let item = {
|
||||
style: filename
|
||||
};
|
||||
addStyle(id, item, false, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.get('/styles.json', (req, res, next) => {
|
||||
const result = [];
|
||||
const query = req.query.key ? (`?key=${encodeURIComponent(req.query.key)}`) : '';
|
||||
for (const id of Object.keys(serving.styles)) {
|
||||
const styleJSON = serving.styles[id].styleJSON;
|
||||
result.push({
|
||||
version: styleJSON.version,
|
||||
name: styleJSON.name,
|
||||
id: id,
|
||||
url: req.protocol + '://' + req.headers.host +
|
||||
'/styles/' + id + '.json' + query
|
||||
});
|
||||
url: `${utils.getPublicUrl(opts.publicUrl, req)}styles/${id}/style.json${query}`
|
||||
});
|
||||
}
|
||||
res.send(result);
|
||||
});
|
||||
|
||||
var addTileJSONs = function(arr, req, type) {
|
||||
Object.keys(serving[type]).forEach(function(id) {
|
||||
var info = clone(serving[type][id]);
|
||||
var path = '';
|
||||
if (type == 'rendered') {
|
||||
path = 'styles/' + id + '/rendered';
|
||||
const addTileJSONs = (arr, req, type) => {
|
||||
for (const id of Object.keys(serving[type])) {
|
||||
const info = clone(serving[type][id].tileJSON);
|
||||
let path = '';
|
||||
if (type === 'rendered') {
|
||||
path = `styles/${id}`;
|
||||
} else {
|
||||
path = type + '/' + id;
|
||||
path = `${type}/${id}`;
|
||||
}
|
||||
info.tiles = utils.getTileUrls(req, info.tiles, path, info.format);
|
||||
arr.push(info);
|
||||
info.tiles = utils.getTileUrls(req, info.tiles, path, info.format, opts.publicUrl, {
|
||||
'pbf': options.pbfAlias
|
||||
});
|
||||
arr.push(info);
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
app.get('/rendered.json', function(req, res, next) {
|
||||
app.get('/rendered.json', (req, res, next) => {
|
||||
res.send(addTileJSONs([], req, 'rendered'));
|
||||
});
|
||||
app.get('/data.json', function(req, res, next) {
|
||||
app.get('/data.json', (req, res, next) => {
|
||||
res.send(addTileJSONs([], req, 'data'));
|
||||
});
|
||||
app.get('/index.json', function(req, res, next) {
|
||||
app.get('/index.json', (req, res, next) => {
|
||||
res.send(addTileJSONs(addTileJSONs([], req, 'rendered'), req, 'data'));
|
||||
});
|
||||
|
||||
@@ -198,93 +287,92 @@ module.exports = function(opts, callback) {
|
||||
// serve web presentations
|
||||
app.use('/', express.static(path.join(__dirname, '../public/resources')));
|
||||
|
||||
var templates = path.join(__dirname, '../public/templates');
|
||||
var serveTemplate = function(path, template, dataGetter) {
|
||||
fs.readFile(templates + '/' + template + '.tmpl', function(err, content) {
|
||||
if (err) {
|
||||
console.log('Template not found:', err);
|
||||
const templates = path.join(__dirname, '../public/templates');
|
||||
const serveTemplate = (urlPath, template, dataGetter) => {
|
||||
let templateFile = `${templates}/${template}.tmpl`;
|
||||
if (template === 'index') {
|
||||
if (options.frontPage === false) {
|
||||
return;
|
||||
} else if (options.frontPage &&
|
||||
options.frontPage.constructor === String) {
|
||||
templateFile = path.resolve(paths.root, options.frontPage);
|
||||
}
|
||||
var compiled = handlebars.compile(content.toString());
|
||||
}
|
||||
startupPromises.push(new Promise((resolve, reject) => {
|
||||
fs.readFile(templateFile, (err, content) => {
|
||||
if (err) {
|
||||
err = new Error(`Template not found: ${err.message}`);
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
const compiled = handlebars.compile(content.toString());
|
||||
|
||||
app.use(path, function(req, res, next) {
|
||||
var data = {};
|
||||
app.use(urlPath, (req, res, next) => {
|
||||
let data = {};
|
||||
if (dataGetter) {
|
||||
data = dataGetter(req);
|
||||
if (!data) {
|
||||
return res.status(404).send('Not found');
|
||||
}
|
||||
}
|
||||
data['server_version'] = packageJson.name + ' v' + packageJson.version;
|
||||
data['server_version'] = `${packageJson.name} v${packageJson.version}`;
|
||||
data['public_url'] = opts.publicUrl || '/';
|
||||
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 : '';
|
||||
req.query.key ? `key=${encodeURIComponent(req.query.key)}&` : '';
|
||||
data['key_query'] = req.query.key ? `?key=${encodeURIComponent(req.query.key)}` : '';
|
||||
if (template === 'wmts') res.set('Content-Type', 'text/xml');
|
||||
return res.status(200).send(compiled(data));
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
}));
|
||||
};
|
||||
|
||||
serveTemplate('/$', 'index', function(req) {
|
||||
var styles = clone(config.styles || {});
|
||||
Object.keys(styles).forEach(function(id) {
|
||||
var style = styles[id];
|
||||
serveTemplate('/$', 'index', req => {
|
||||
const styles = clone(serving.styles || {});
|
||||
for (const id of Object.keys(styles)) {
|
||||
const style = styles[id];
|
||||
style.name = (serving.styles[id] || serving.rendered[id] || {}).name;
|
||||
style.serving_data = serving.styles[id];
|
||||
style.serving_rendered = serving.rendered[id];
|
||||
if (style.serving_rendered) {
|
||||
var center = style.serving_rendered.center;
|
||||
const center = style.serving_rendered.tileJSON.center;
|
||||
if (center) {
|
||||
style.viewer_hash = '#' + center[2] + '/' +
|
||||
center[1].toFixed(5) + '/' +
|
||||
center[0].toFixed(5);
|
||||
style.viewer_hash = `#${center[2]}/${center[1].toFixed(5)}/${center[0].toFixed(5)}`;
|
||||
|
||||
var centerPx = mercator.px([center[0], center[1]], center[2]);
|
||||
style.thumbnail = center[2] + '/' +
|
||||
Math.floor(centerPx[0] / 256) + '/' +
|
||||
Math.floor(centerPx[1] / 256) + '.png';
|
||||
const centerPx = mercator.px([center[0], center[1]], center[2]);
|
||||
style.thumbnail = `${center[2]}/${Math.floor(centerPx[0] / 256)}/${Math.floor(centerPx[1] / 256)}.png`;
|
||||
}
|
||||
|
||||
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';
|
||||
|
||||
var tiles = utils.getTileUrls(
|
||||
req, style.serving_rendered.tiles,
|
||||
'styles/' + id + '/rendered', style.serving_rendered.format);
|
||||
style.xyz_link = tiles[0];
|
||||
style.xyz_link = utils.getTileUrls(
|
||||
req, style.serving_rendered.tileJSON.tiles,
|
||||
`styles/${id}`, style.serving_rendered.tileJSON.format, opts.publicUrl)[0];
|
||||
}
|
||||
});
|
||||
var data = clone(serving.data || {});
|
||||
Object.keys(data).forEach(function(id) {
|
||||
var data_ = data[id];
|
||||
var center = data_.center;
|
||||
}
|
||||
const data = clone(serving.data || {});
|
||||
for (const id of Object.keys(data)) {
|
||||
const data_ = data[id];
|
||||
const tilejson = data[id].tileJSON;
|
||||
const center = tilejson.center;
|
||||
if (center) {
|
||||
data_.viewer_hash = '#' + center[2] + '/' +
|
||||
center[1].toFixed(5) + '/' +
|
||||
center[0].toFixed(5);
|
||||
data_.viewer_hash = `#${center[2]}/${center[1].toFixed(5)}/${center[0].toFixed(5)}`;
|
||||
}
|
||||
data_.is_vector = data_.format == 'pbf';
|
||||
data_.is_vector = tilejson.format === 'pbf';
|
||||
if (!data_.is_vector) {
|
||||
if (center) {
|
||||
var centerPx = mercator.px([center[0], center[1]], center[2]);
|
||||
data_.thumbnail = center[2] + '/' +
|
||||
Math.floor(centerPx[0] / 256) + '/' +
|
||||
Math.floor(centerPx[1] / 256) + '.' + data_.format;
|
||||
const centerPx = mercator.px([center[0], center[1]], center[2]);
|
||||
data_.thumbnail = `${center[2]}/${Math.floor(centerPx[0] / 256)}/${Math.floor(centerPx[1] / 256)}.${data_.tileJSON.format}`;
|
||||
}
|
||||
|
||||
var query = req.query.key ? ('?key=' + req.query.key) : '';
|
||||
data_.wmts_link = 'http://wmts.maptiler.com/' +
|
||||
base64url('http://' + req.headers.host +
|
||||
'/data/' + id + '.json' + query) + '/wmts';
|
||||
|
||||
var tiles = utils.getTileUrls(
|
||||
req, data_.tiles, 'data/' + id, data_.format);
|
||||
data_.xyz_link = tiles[0];
|
||||
data_.xyz_link = utils.getTileUrls(
|
||||
req, tilejson.tiles, `data/${id}`, tilejson.format, opts.publicUrl, {
|
||||
'pbf': options.pbfAlias
|
||||
})[0];
|
||||
}
|
||||
if (data_.filesize) {
|
||||
var suffix = 'kB';
|
||||
var size = parseInt(data_.filesize, 10) / 1024;
|
||||
let suffix = 'kB';
|
||||
let size = parseInt(data_.filesize, 10) / 1024;
|
||||
if (size > 1024) {
|
||||
suffix = 'MB';
|
||||
size /= 1024;
|
||||
@@ -293,18 +381,18 @@ module.exports = function(opts, callback) {
|
||||
suffix = 'GB';
|
||||
size /= 1024;
|
||||
}
|
||||
data_.formatted_filesize = size.toFixed(2) + ' ' + suffix;
|
||||
data_.formatted_filesize = `${size.toFixed(2)} ${suffix}`;
|
||||
}
|
||||
}
|
||||
});
|
||||
return {
|
||||
styles: styles,
|
||||
data: data
|
||||
styles: Object.keys(styles).length ? styles : null,
|
||||
data: Object.keys(data).length ? data : null
|
||||
};
|
||||
});
|
||||
|
||||
serveTemplate('/styles/:id/$', 'viewer', function(req) {
|
||||
var id = req.params.id;
|
||||
var style = clone((config.styles || {})[id]);
|
||||
serveTemplate('/styles/:id/$', 'viewer', req => {
|
||||
const id = req.params.id;
|
||||
const style = clone(((serving.styles || {})[id] || {}).styleJSON);
|
||||
if (!style) {
|
||||
return null;
|
||||
}
|
||||
@@ -320,32 +408,88 @@ module.exports = function(opts, callback) {
|
||||
return res.redirect(301, '/styles/' + req.params.id + '/');
|
||||
});
|
||||
*/
|
||||
serveTemplate('/styles/:id/wmts.xml', 'wmts', req => {
|
||||
const id = req.params.id;
|
||||
const wmts = clone((serving.styles || {})[id]);
|
||||
if (!wmts) {
|
||||
return null;
|
||||
}
|
||||
if (wmts.hasOwnProperty("serve_rendered") && !wmts.serve_rendered) {
|
||||
return null;
|
||||
}
|
||||
wmts.id = id;
|
||||
wmts.name = (serving.styles[id] || serving.rendered[id]).name;
|
||||
wmts.baseUrl = `${req.get('X-Forwarded-Protocol') ? req.get('X-Forwarded-Protocol') : req.protocol}://${req.get('host')}`;
|
||||
return wmts;
|
||||
});
|
||||
|
||||
serveTemplate('/data/:id/$', 'data', function(req) {
|
||||
var id = req.params.id;
|
||||
var data = clone(serving.data[id]);
|
||||
serveTemplate('/data/:id/$', 'data', req => {
|
||||
const id = req.params.id;
|
||||
const data = clone(serving.data[id]);
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
data.id = id;
|
||||
data.is_vector = data.format == 'pbf';
|
||||
data.is_vector = data.tileJSON.format === 'pbf';
|
||||
return data;
|
||||
});
|
||||
|
||||
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();
|
||||
let startupComplete = false;
|
||||
const startupPromise = Promise.all(startupPromises).then(() => {
|
||||
console.log('Startup complete');
|
||||
startupComplete = true;
|
||||
});
|
||||
app.get('/health', (req, res, next) => {
|
||||
if (startupComplete) {
|
||||
return res.status(200).send('OK');
|
||||
} else {
|
||||
return res.status(503).send('Starting');
|
||||
}
|
||||
});
|
||||
|
||||
process.on('SIGINT', function() {
|
||||
const server = app.listen(process.env.PORT || opts.port, process.env.BIND || opts.bind, function () {
|
||||
let address = this.address().address;
|
||||
if (address.indexOf('::') === 0) {
|
||||
address = `[${address}]`; // literal IPv6 address
|
||||
}
|
||||
console.log(`Listening at http://${address}:${this.address().port}/`);
|
||||
});
|
||||
|
||||
// add server.shutdown() to gracefully stop serving
|
||||
enableShutdown(server);
|
||||
|
||||
return {
|
||||
app: app,
|
||||
server: server,
|
||||
startupPromise: startupPromise
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = opts => {
|
||||
const running = start(opts);
|
||||
|
||||
running.startupPromise.catch(err => {
|
||||
console.error(err.message);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
process.exit();
|
||||
});
|
||||
|
||||
setTimeout(callback, 1000);
|
||||
return {
|
||||
app: app,
|
||||
server: server
|
||||
};
|
||||
process.on('SIGHUP', () => {
|
||||
console.log('Stopping server and reloading config');
|
||||
|
||||
running.server.shutdown(() => {
|
||||
for (const key in require.cache) {
|
||||
delete require.cache[key];
|
||||
}
|
||||
|
||||
const restarted = start(opts);
|
||||
running.server = restarted.server;
|
||||
running.app = restarted.app;
|
||||
});
|
||||
});
|
||||
|
||||
return running;
|
||||
};
|
||||
|
||||
121
src/utils.js
@@ -1,46 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
var clone = require('clone'),
|
||||
glyphCompose = require('glyph-pbf-composite');
|
||||
const clone = require('clone');
|
||||
const glyphCompose = require('@mapbox/glyph-pbf-composite');
|
||||
|
||||
module.exports.getTileUrls = function(req, domains, path, format) {
|
||||
|
||||
module.exports.getPublicUrl = (publicUrl, req) => publicUrl || `${req.protocol}://${req.headers.host}/`;
|
||||
|
||||
module.exports.getTileUrls = (req, domains, path, format, publicUrl, aliases) => {
|
||||
|
||||
if (domains) {
|
||||
if (domains.constructor === String && domains.length > 0) {
|
||||
domains = domains.split(',');
|
||||
}
|
||||
const host = req.headers.host;
|
||||
const hostParts = host.split('.');
|
||||
const relativeSubdomainsUsable = hostParts.length > 1 &&
|
||||
!/^([0-9]{1,3}\.){3}[0-9]{1,3}(\:[0-9]+)?$/.test(host);
|
||||
const newDomains = [];
|
||||
for (const domain of domains) {
|
||||
if (domain.indexOf('*') !== -1) {
|
||||
if (relativeSubdomainsUsable) {
|
||||
const newParts = hostParts.slice(1);
|
||||
newParts.unshift(domain.replace('*', hostParts[0]));
|
||||
newDomains.push(newParts.join('.'));
|
||||
}
|
||||
} else {
|
||||
newDomains.push(domain);
|
||||
}
|
||||
}
|
||||
domains = newDomains;
|
||||
}
|
||||
if (!domains || domains.length == 0) {
|
||||
domains = [req.headers.host];
|
||||
}
|
||||
|
||||
var key = req.query.key;
|
||||
var queryParams = [];
|
||||
const key = req.query.key;
|
||||
const queryParams = [];
|
||||
if (req.query.key) {
|
||||
queryParams.push('key=' + req.query.key);
|
||||
queryParams.push(`key=${encodeURIComponent(req.query.key)}`);
|
||||
}
|
||||
if (req.query.style) {
|
||||
queryParams.push('style=' + req.query.style);
|
||||
queryParams.push(`style=${encodeURIComponent(req.query.style)}`);
|
||||
}
|
||||
var query = queryParams.length > 0 ? ('?' + queryParams.join('&')) : '';
|
||||
const query = queryParams.length > 0 ? (`?${queryParams.join('&')}`) : '';
|
||||
|
||||
var uris = [];
|
||||
domains.forEach(function(domain) {
|
||||
uris.push(req.protocol + '://' + domain + '/' + path +
|
||||
'/{z}/{x}/{y}.' + format + query);
|
||||
});
|
||||
if (aliases && aliases[format]) {
|
||||
format = aliases[format];
|
||||
}
|
||||
|
||||
const uris = [];
|
||||
if (!publicUrl) {
|
||||
for (const domain of domains) {
|
||||
uris.push(`${req.protocol}://${domain}/${path}/{z}/{x}/{y}.${format}${query}`);
|
||||
}
|
||||
} else {
|
||||
uris.push(`${publicUrl}${path}/{z}/{x}/{y}.${format}${query}`)
|
||||
}
|
||||
|
||||
return uris;
|
||||
};
|
||||
|
||||
module.exports.fixTileJSONCenter = function(tileJSON) {
|
||||
module.exports.fixTileJSONCenter = tileJSON => {
|
||||
if (tileJSON.bounds && !tileJSON.center) {
|
||||
var fitWidth = 1024;
|
||||
var tiles = fitWidth / 256;
|
||||
const fitWidth = 1024;
|
||||
const tiles = fitWidth / 256;
|
||||
tileJSON.center = [
|
||||
(tileJSON.bounds[0] + tileJSON.bounds[2]) / 2,
|
||||
(tileJSON.bounds[1] + tileJSON.bounds[3]) / 2,
|
||||
@@ -52,47 +78,54 @@ module.exports.fixTileJSONCenter = function(tileJSON) {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.getFontsPbf = function(allowedFonts, fontPath, names, range, fallbacks, callback) {
|
||||
var getFontPbf = function(allowedFonts, name, range, callback, fallbacks) {
|
||||
const getFontPbf = (allowedFonts, fontPath, name, range, fallbacks) => new Promise((resolve, reject) => {
|
||||
if (!allowedFonts || (allowedFonts[name] && fallbacks)) {
|
||||
var filename = path.join(fontPath, name, range + '.pbf');
|
||||
const 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, (err, data) => {
|
||||
if (err) {
|
||||
console.error('ERROR: Font not found:', name);
|
||||
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');
|
||||
let fallbackName;
|
||||
|
||||
let fontStyle = name.split(' ').pop();
|
||||
if (['Regular', 'Bold', 'Italic'].indexOf(fontStyle) < 0) {
|
||||
fontStyle = 'Regular';
|
||||
}
|
||||
fallbackName = `Noto Sans ${fontStyle}`;
|
||||
if (!fallbacks[fallbackName]) {
|
||||
fallbackName = `Open Sans ${fontStyle}`;
|
||||
if (!fallbacks[fallbackName]) {
|
||||
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));
|
||||
reject(`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));
|
||||
module.exports.getFontsPbf = (allowedFonts, fontPath, names, range, fallbacks) => {
|
||||
const fonts = names.split(',');
|
||||
const queue = [];
|
||||
for (const font of fonts) {
|
||||
queue.push(
|
||||
getFontPbf(allowedFonts, fontPath, font, range, clone(allowedFonts || fallbacks))
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return Promise.all(queue).then(values => glyphCompose.combine(values));
|
||||
};
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
@@ -3,18 +3,22 @@ process.env.NODE_ENV = 'test';
|
||||
global.should = require('should');
|
||||
global.supertest = require('supertest');
|
||||
|
||||
require = require('esm')(module);
|
||||
|
||||
before(function() {
|
||||
console.log('global setup');
|
||||
process.chdir('test_data');
|
||||
var running = require('../src/server')({
|
||||
configPath: 'config.json',
|
||||
port: 8888
|
||||
port: 8888,
|
||||
publicUrl: '/test/'
|
||||
});
|
||||
global.app = running.app;
|
||||
global.server = running.server;
|
||||
return running.startupPromise;
|
||||
});
|
||||
|
||||
after(function() {
|
||||
console.log('global teardown');
|
||||
global.server.close(function() { console.log('Done'); });
|
||||
global.server.close(function() { console.log('Done'); process.exit(); });
|
||||
});
|
||||
|
||||
@@ -11,24 +11,25 @@ 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();
|
||||
res.body.sources.should.be.Object();
|
||||
res.body.glyphs.should.be.String();
|
||||
res.body.sprite.should.be.String();
|
||||
res.body.sprite.should.equal('/test/styles/test-style/sprite');
|
||||
res.body.layers.should.be.Array();
|
||||
}).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() {
|
||||
|
||||
@@ -23,6 +23,6 @@ describe('Vector tiles', function() {
|
||||
testTile(prefix, 0, 1, 0, 404);
|
||||
testTile(prefix, 0, 0, 1, 404);
|
||||
|
||||
testTile(prefix, 14, 0, 0, 404); // non existent tile
|
||||
testTile(prefix, 14, 0, 0, 204); // non existent tile
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
@@ -26,7 +26,6 @@ describe('Raster tiles', function() {
|
||||
testTile(prefix, 0, 0, 0, 'png', 200, 2);
|
||||
testTile(prefix, 0, 0, 0, 'png', 200, 3);
|
||||
testTile(prefix, 2, 1, 1, 'png', 200, 3);
|
||||
testTile(prefix, 0, 0, 0, 'png', 200, 4);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||