Skip to content

Commit

Permalink
Add support for mbtiles 1.3 'center' metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
systemed committed Feb 18, 2018
1 parent 9202e38 commit 8dacb3a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ It also includes these global settings:
* `compress` - whether to compress vector tiles (Any of "gzip","deflate" or "none"(default))
* `name`, `version` and `description` - about your project (these are written into the MBTiles file)
* `bounding_box` (optional) - the bounding box to output, in [minlon, minlat, maxlon, maxlat] order
* `default_view` (optional) - the default location for the client to view, in [lon, lat, zoom] order (MBTiles only)
* `mvt_version` (optional) - the version of the [Mapbox Vector Tile](https://github.com/mapbox/vector-tile-spec) spec to use; defaults to 2

A typical config file would look like this:
Expand Down Expand Up @@ -81,6 +82,8 @@ This would combine the `roads` (z12-14) and `low_roads` (z9-11) layers into a si

### Additional metadata

Tilemaker writes a `json` metadata field containing a `vector_layers` key, whose value is an array of JSON objects describing each layer and its attributes. This is part of the MBTiles 1.3 spec and required by certain clients.

If you need to add additional metadata fields to your .mbtiles output, include the keys/values as an (optional) "metadata" entry under "settings". These will usually be string key/value pairs. (The value can also be another JSON entity - hash, array etc. - in which case it'll be encoded as JSON when written into the .mbtiles metadata table.)

For example:
Expand Down
6 changes: 6 additions & 0 deletions src/shared_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class SharedData
int threadNum;
bool clippingBoxFromJSON;
double minLon, minLat, maxLon, maxLat;
string defaultView;
OSMObject osmObject;
OSMStore *osmStore;
bool includeID, compress, gzip;
Expand Down Expand Up @@ -58,6 +59,11 @@ class SharedData
clippingBox = Box(geom::make<Point>(minLon, lat2latp(minLat)),
geom::make<Point>(maxLon, lat2latp(maxLat)));
}
if (jsonConfig["settings"].HasMember("default_view")) {
defaultView = to_string(jsonConfig["settings"]["default_view"][0].GetDouble()) + "," +
to_string(jsonConfig["settings"]["default_view"][1].GetDouble()) + "," +
to_string(jsonConfig["settings"]["default_view"][2].GetInt());
}

// Check config is valid
if (endZoom > baseZoom) { cerr << "maxzoom must be the same or smaller than basezoom." << endl; exit (EXIT_FAILURE); }
Expand Down
1 change: 1 addition & 0 deletions src/tilemaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ int main(int argc, char* argv[]) {
sharedData.mbtiles.writeMetadata("bounds",bounds.str());
sharedData.mbtiles.writeMetadata("minzoom",to_string(sharedData.startZoom));
sharedData.mbtiles.writeMetadata("maxzoom",to_string(sharedData.endZoom));
if (!sharedData.defaultView.empty()) { sharedData.mbtiles.writeMetadata("center",sharedData.defaultView); }
}

// ---- Read all PBFs
Expand Down

0 comments on commit 8dacb3a

Please sign in to comment.