Skip to content

Commit

Permalink
Add pmtiles support (#1009)
Browse files Browse the repository at this point in the history
Adds pmtiles support to TileServer-GL

Signed-off-by: Andrew Calcutt <[email protected]>
Signed-off-by: Michael Nutt <[email protected]>
Co-authored-by: Michael Nutt <[email protected]>
  • Loading branch information
acalcutt and mnutt authored Oct 15, 2023
1 parent 7d8a6ad commit a6dadfd
Show file tree
Hide file tree
Showing 12 changed files with 980 additions and 377 deletions.
32 changes: 32 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,38 @@ modification, are permitted provided that the following conditions are met:
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```
---

### [PMTiles](https://github.com/protomaps/pmtiles)
```
BSD 3-Clause License
Copyright 2021 Protomaps LLC
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand Down
62 changes: 52 additions & 10 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Example:
"sprites": "sprites",
"icons": "icons",
"styles": "styles",
"mbtiles": ""
"mbtiles": "data",
"pmtiles": "data"
},
"domains": [
"localhost:8080",
Expand Down Expand Up @@ -180,11 +181,27 @@ Each item in this object defines one style (map). It can have the following opti
``data``
========

Each item specifies one data source which should be made accessible by the server. It has the following options:
Each item specifies one data source which should be made accessible by the server. It has to have one of the following options:

* ``mbtiles`` -- name of the mbtiles file [required]
* ``mbtiles`` -- name of the mbtiles file
* ``pmtiles`` -- name of the pmtiles file or url.

The mbtiles file does not need to be specified here unless you explicitly want to serve the raw data.
For example::

"data": {
"source1": {
"mbtiles": "source1.mbtiles"
},
"source2": {
"pmtiles": "source2.pmtiles"
},
"source3": {
"pmtiles": "https://foo.lan/source3.pmtiles"
}
}


The data source does not need to be specified here unless you explicitly want to serve the raw data.

Referencing local files from style JSON
=======================================
Expand All @@ -194,21 +211,46 @@ You can link various data sources from the style JSON (for example even remote T
MBTiles
-------

To specify that you want to use local mbtiles, use to following syntax: ``mbtiles://switzerland.mbtiles``.
The TileServer-GL will try to find the file ``switzerland.mbtiles`` in ``root`` + ``mbtiles`` path.
To specify that you want to use local mbtiles, use to following syntax: ``mbtiles://source1.mbtiles``.
TileServer-GL will try to find the file ``source1.mbtiles`` in ``root`` + ``mbtiles`` path.

For example::

"sources": {
"source1": {
"url": "mbtiles://switzerland.mbtiles",
"url": "mbtiles://source1.mbtiles",
"type": "vector"
}
}

Alternatively, you can use ``mbtiles://{zurich-vector}`` to reference existing data object from the config.
In this case, the server will look into the ``config.json`` to determine what mbtiles file to use.
For the config above, this is equivalent to ``mbtiles://zurich.mbtiles``.
Alternatively, you can use ``mbtiles://{source1}`` to reference existing data object from the config.
In this case, the server will look into the ``config.json`` to determine what file to use by data id.
For the config above, this is equivalent to ``mbtiles://source1.mbtiles``.

PMTiles
-------

To specify that you want to use local pmtiles, use to following syntax: ``pmtiles://source2.pmtiles``.
TileServer-GL will try to find the file ``source2.pmtiles`` in ``root`` + ``pmtiles`` path.

To specify that you want to use a url based pmtiles, use to following syntax: ``pmtiles://https://foo.lan/source3.pmtiles``.

For example::

"sources": {
"source2": {
"url": "pmtiles://source2.pmtiles",
"type": "vector"
},
"source3": {
"url": "pmtiles://https://foo.lan/source3.pmtiles",
"type": "vector"
},
}

Alternatively, you can use ``pmtiles://{source2}`` to reference existing data object from the config.
In this case, the server will look into the ``config.json`` to determine what file to use by data id.
For the config above, this is equivalent to ``pmtiles://source2.mbtiles``.

Sprites
-------
Expand Down
54 changes: 40 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@mapbox/vector-tile": "1.3.1",
"@maplibre/maplibre-gl-native": "5.2.0",
"@maplibre/maplibre-gl-style-spec": "18.0.0",
"@sindresorhus/fnv1a": "3.0.0",
"advanced-pool": "0.3.3",
"canvas": "2.11.2",
"chokidar": "3.5.3",
Expand All @@ -37,6 +38,7 @@
"http-shutdown": "1.2.2",
"morgan": "1.10.0",
"pbf": "3.2.1",
"pmtiles": "2.11.0",
"proj4": "2.9.1",
"request": "2.88.2",
"sanitize-filename": "1.6.3",
Expand Down
5 changes: 3 additions & 2 deletions public/templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@
<img src="{{public_url}}images/placeholder.png{{&key_query}}" 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>
<h3>{{tileJSON.name}}</h3>
<div class="identifier">identifier: {{@key}}{{#if formatted_filesize}} | size: {{formatted_filesize}}{{/if}}</div>
<div class="identifier">type: {{#is_vector}}vector{{/is_vector}}{{^is_vector}}raster{{/is_vector}} data {{#if source_type}} | ext: {{source_type}}{{/if}}</div>
<p class="services">
services: <a href="{{public_url}}data/{{@key}}.json{{&../key_query}}">TileJSON</a>
{{#if wmts_link}}
Expand Down
Loading

0 comments on commit a6dadfd

Please sign in to comment.