Convert geographic data into vector map tiles.
$ npm install -g pantiler
Alternatively, don't install it and just prepend the command with
In the terminal:
$ pantiler <tilefile> <directory>
The directory is where the tiles will be created, and should not already exist. Downloaded and processed files will be cached into a directory named
.pantiler-cache, and can then be used to speed up subsequent runs. The cache can be automatically removed when Pantiler finishes successfully with
The tiles are just static files that can then be hosted on S3, for example. They can then be rendered in the browser with Mapbox GL, or any other library that supports vector tiles. See
example.html for what this looks like.
Pantiler can also be used as a library. To import it:
import Pantiler from 'pantiler'
Then set it up:
const pantiler = Pantiler(directory, cache, clearCache, bounds, alert)
directoryWhere the tiles will be created, should not already exist.
cacheThe name of a directory where files will be cached. Optional. Default is
clearCacheRemove the cache after completing. Optional. Default is false.
boundsA set of coordinates to clip the data with as
minLong,minLat,maxLong,maxLat(using WGS84). Optional.
alertA function to be called with informational messages as Pantiler runs. Optional. Default does nothing.
Then run it:
tiledata is an object following the tilefile format, described below.
Tilefiles are written in Yaml or Json. There is an
example.yaml included for reference.
hostThe location the tiles will be served from.
zoomFromThe most zoomed-out level of tiles to generate.
zoomToThe most zoomed-in level of tiles to generate.
fontsAn array of inputs specifying fonts in TTF or OTF format, which can then be referenced by name in the styling. Optional.
spritesAn array of inputs specifying images in SVG format, which can then be referenced by name in the styling. Optional.
sourcesAn array of sources.
stylingFollows the Vector Tile Style specification, though with the
sourcessections automatically generated, and so only needs to include a
layerssection at a minimum, which should expect a source named
primary. This can be generated with Maputnik.
Inputs have this format:
nameA unique name for this input.
urlSpecify either this or
path. For a file that should be downloaded from the web.
pathSpecify either this or
url. For a file that exists somewhere on your computer.
urldoesn't end with an extension indicating the file format, specify it here. Optional.
matchingFor archives containing multiple files specify a regular expression here to match which to use. Optional.
Inputs are merged together to produce each output. If the file is determined to be a Zip file (either through the extension or specified with
format) it will be decompressed. Any
txt files are ignored. If there is only one file left(or the files left constitute a Shapefile) that gets passed through to the next stage. If there are multiple files left then you'll get an error.
Sources have this format:
nameA unique name for this source.
systemA Proj string describing the spatial reference system (note this FAQ item about axis ordering).
fieldLongitudeFor CSV inputs with separate coordinates, specify the longitude column name. Optional.
fieldLatitudeFor CSV inputs with separate coordinates, specify the latitude column name. Optional.
inputsAn array of inputs specifying geographical data.
outputsAn array of outputs.
Outputs have this format:
nameA unique name for this output, which can then be referenced as a source layer in the styling.
layerThe name of the input layer that this output should use. Optional. Default is the first layer it finds.
filterFilter which features should be included, using SQL WHERE-clause format. Optional.
fieldsAn object listing fields you want in the output to the names of those fields in the input layer. Optional.
zoomMinThe most zoomed-out level of tiles that should include this data. Optional.
zoomMaxThe most zoomed-in level of tiles that should include this data. Optional.
Download the example tilefile:
$ curl -L https://github.com/maxharlow/pantiler/raw/master/example.yaml > example.yaml
Run Pantiler, putting the output into a directory named
$ npx pantiler example.yaml tiles
Download the example tile viewer:
$ curl -L https://github.com/maxharlow/pantiler/raw/master/example.html > example.html
Serve the tiles and viewer locally:
$ npx local-web-server --hostname localhost --port 8080
You should now be able to see a map at localhost:8080/example.html.
There is also another example tilefile,
example2.yaml, based on OpenStreetMap data.