Skip to content

Commit 8dacb3a

Browse files
committed
Add support for mbtiles 1.3 'center' metadata
1 parent 9202e38 commit 8dacb3a

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

CONFIGURATION.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ It also includes these global settings:
3030
* `compress` - whether to compress vector tiles (Any of "gzip","deflate" or "none"(default))
3131
* `name`, `version` and `description` - about your project (these are written into the MBTiles file)
3232
* `bounding_box` (optional) - the bounding box to output, in [minlon, minlat, maxlon, maxlat] order
33+
* `default_view` (optional) - the default location for the client to view, in [lon, lat, zoom] order (MBTiles only)
3334
* `mvt_version` (optional) - the version of the [Mapbox Vector Tile](https://github.com/mapbox/vector-tile-spec) spec to use; defaults to 2
3435

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

8283
### Additional metadata
8384

85+
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.
86+
8487
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.)
8588

8689
For example:

src/shared_data.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class SharedData
88
int threadNum;
99
bool clippingBoxFromJSON;
1010
double minLon, minLat, maxLon, maxLat;
11+
string defaultView;
1112
OSMObject osmObject;
1213
OSMStore *osmStore;
1314
bool includeID, compress, gzip;
@@ -58,6 +59,11 @@ class SharedData
5859
clippingBox = Box(geom::make<Point>(minLon, lat2latp(minLat)),
5960
geom::make<Point>(maxLon, lat2latp(maxLat)));
6061
}
62+
if (jsonConfig["settings"].HasMember("default_view")) {
63+
defaultView = to_string(jsonConfig["settings"]["default_view"][0].GetDouble()) + "," +
64+
to_string(jsonConfig["settings"]["default_view"][1].GetDouble()) + "," +
65+
to_string(jsonConfig["settings"]["default_view"][2].GetInt());
66+
}
6167

6268
// Check config is valid
6369
if (endZoom > baseZoom) { cerr << "maxzoom must be the same or smaller than basezoom." << endl; exit (EXIT_FAILURE); }

src/tilemaker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ int main(int argc, char* argv[]) {
433433
sharedData.mbtiles.writeMetadata("bounds",bounds.str());
434434
sharedData.mbtiles.writeMetadata("minzoom",to_string(sharedData.startZoom));
435435
sharedData.mbtiles.writeMetadata("maxzoom",to_string(sharedData.endZoom));
436+
if (!sharedData.defaultView.empty()) { sharedData.mbtiles.writeMetadata("center",sharedData.defaultView); }
436437
}
437438

438439
// ---- Read all PBFs

0 commit comments

Comments
 (0)