Vector tiles and MapLibre
The basemap is one archive of vector tiles built from open data — Overture's base layers, transportation, buildings, divisions and addresses, with the places and transit stops — and it is served three ways:
/v1/tiles/{z}/{x}/{y}— one tile, as a Mapbox Vector Tile or drawn as a PNG./v1/tiles.json— the TileJSON document that describes the archive: its URL template, zooms, bounds, layers and attribution./v1/style.json— a MapLibre style that draws it.
Tiles
curl "https://api.oslew.com/v1/tiles/14/3680/7290.mvt" \
-H "Authorization: Bearer $GEO_API_KEY" \
-o 7290.mvtfrom oslew import Client
# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")
data = client.tiles(14, 3680, "7290.mvt")
open("7290.mvt", "wb").write(data)import { writeFile } from "node:fs/promises";
import { Client } from "@oslew/client";
// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });
const data = await client.tiles(14, 3680, "7290.mvt");
await writeFile("7290.mvt", data);HTTP/1.1 200 OK
content-type: application/vnd.mapbox-vector-tile
ratelimit-limit: 100
ratelimit-remaining: 290
ratelimit-reset: 1
cache-control: public, max-age=86400
content-encoding: gzip
(422,836 bytes of application/vnd.mapbox-vector-tile)A real response, captured from the service at commit b8f4bde-dirty.
The path is /v1/tiles/{z}/{x}/{y} in the XYZ scheme — y counts down from the north, as the TileJSON's scheme says — with an extension on y: .mvt or.pbf for the vector tile (the same bytes; also the default with no extension), .png for a picture of it.
- The vector tile is sent as stored: gzipped. Every tile comes with
Content-Encoding: gzip, whatever the request'sAccept-Encodingsaid. Browsers andfetchdecompress it transparently — the example above was captured throughfetch, so the size it shows is the decompressed one.curlsaves the gzipped bytes unless given--compressed, and the Python client returns them still gzipped —gzip.decompressthem before decoding. The TypeScript client, onfetch, returns them decompressed. Cache-Control: public, max-age=86400. A tile changes only when the basemap is rebuilt; a day in any cache is safe.204 No Contentmeans there is nothing there: outside the archive's area, where the tile would be empty, and at every zoom deeper than the archive'smaxzoom— 14 for this one. The service does not overzoom vector tiles. MapLibre readsmaxzoomfrom the TileJSON and overzooms the deepest tiles itself, so a map stays sharp at zoom 18 without asking for tiles that do not exist; a client that ignoresmaxzoomsees an empty map past it. Both clients return zero bytes for a 204.- Out of range is a
400: azover 24, or anxoryof 2z or more, is… is off the pyramid; aythat is not a number isy must be a number; another extension isunknown tile format. Azorxthat is not a number is refused by the framework, in plain text. A deployment without a basemap answersno tile archive loaded.
PNG tiles
curl "https://api.oslew.com/v1/tiles/14/3680/7290.png" \
-H "Authorization: Bearer $GEO_API_KEY" \
-o 7290.pngfrom oslew import Client
# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")
data = client.tiles(14, 3680, "7290.png")
open("7290.png", "wb").write(data)import { writeFile } from "node:fs/promises";
import { Client } from "@oslew/client";
// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });
const data = await client.tiles(14, 3680, "7290.png");
await writeFile("7290.png", data);
A real response, captured from the service at commit b8f4bde-dirty.
.png draws the same tile, in the same colours as the style, as a 512-pixel square — for a client that cannot render vectors. Past the archive's deepest zoom it magnifies the deepest stored tile rather than answering204, and an area with no data draws as plain background. It is drawn on request, so it is slower than the vector tile, and it carries the same day-long Cache-Control.
- No labels. The service draws shapes, not text: street and place names exist only in the vector tiles, for a client that renders them with fonts. The same is true of static maps.
- 512 pixels, not 256. A client that assumes 256-pixel tiles has to be told, or everything is at half size one zoom off. In Leaflet, that is
tileSize: 512andzoomOffset: -1.
The TileJSON and the style
curl "https://api.oslew.com/v1/tiles.json" \
-H "Authorization: Bearer $GEO_API_KEY"from oslew import Client
# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")
answer = client.tiles_json()import { Client } from "@oslew/client";
// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });
const answer = await client.tiles_json();HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 292
ratelimit-reset: 1
{
"attribution": "© OpenStreetMap contributors (ODbL) · Overture Maps Foundation",
"bounds": [
-99.35,
19.2,
-98.95,
19.6
],
"center": [
-99.15,
19.4,
10
],
"description": "A basemap from open data: Overture Maps (transportation, base, buildings, divisions, addresses) and the store's places and transit stops.",
"format": "pbf",
"maxzoom": 14,
"minzoom": 0,
"name": "basemap",
"scheme": "xyz",
"tilejson": "3.0.0",
"tiles": [
"http://127.0.0.1:18481/v1/tiles/{z}/{x}/{y}.mvt"
],
"tiles_stored": 547,
"vector_layers": [
{
"fields": {
"class": "String",
"name": "String",
"subclass": "String"
},
"id": "water",
"maxzoom": 14,
"minzoom": 0
},
{
"fields": {
"class": "String",
"name": "String",
"subclass": "String"
},
"id": "waterway",
"maxzoom": 14,
"minzoom": 8
},
{
"fields": {
"class": "String",
"subclass": "String"
},
"id": "landcover",
"maxzoom": 14,
"minzoom": 0
},
{
"fields": {
"class": "String",
"name": "String",
"subclass": "String"
},
"id": "landuse",
"maxzoom": 14,
"minzoom": 6
},
{
"fields": {
"class": "String",
"name": "String",
"subclass": "String"
},
"id": "natural",
"maxzoom": 14,
"minzoom": 10
},
{
"fields": {
"class": "String",
"height": "Number",
"name": "String",
"subclass": "String"
},
"id": "infrastructure",
"maxzoom": 14,
"minzoom": 9
},
{
"fields": {
"height": "Number",
"min_height": "Number",
"part": "Boolean"
},
"id": "building",
"maxzoom": 14,
"minzoom": 14
},
{
"fields": {
"class": "String",
"rank": "Number",
"subclass": "String",
"subtype": "String"
},
"id": "transportation",
"maxzoom": 14,
"minzoom": 4
},
{
"fields": {
"class": "String",
"name": "String",
"subtype": "String"
},
"id": "transportation_name",
"maxzoom": 14,
"minzoom": 12
},
{
"fields": {
"admin_level": "Number",
"class": "String",
"maritime": "Boolean"
},
"id": "boundary",
"maxzoom": 14,
"minzoom": 0
},
{
"fields": {
"class": "String",
"name": "String",
"population": "Number",
"rank": "Number"
},
"id": "place",
"maxzoom": 14,
"minzoom": 3
},
{
"fields": {
"class": "String",
"name": "String",
"rank": "Number"
},
"id": "poi",
"maxzoom": 14,
"minzoom": 12
},
{
"fields": {
"class": "String",
"name": "String"
},
"id": "transit",
"maxzoom": 14,
"minzoom": 13
},
{
"fields": {
"housenumber": "String",
"street": "String"
},
"id": "housenumber",
"maxzoom": 14,
"minzoom": 14
}
]
}A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.
/v1/tiles.json is TileJSON 3.0. bounds and center are longitude first, in TileJSON's order; center ends with a zoom. tiles_stored is how many tiles the archive holds — 547 above, a regional extract of central Mexico City — and vector_layers lists each layer the tiles contain, its fields and the zooms it appears at:
| Layer | Holds | From zoom |
|---|---|---|
water, waterway | Seas, lakes and rivers as areas; rivers, canals and streams as lines | 0; 8 |
landcover, landuse, natural | Forest, grass, snow; parks, residential, industrial; peaks, cliffs, trees | 0; 6; 10 |
infrastructure | Airports, bridges, piers, towers and the like, with height | 9 |
building | Footprints, with height and min_height for extrusion | 14 |
transportation, transportation_name | Roads and railways by class; their names, for labels along the line | 4; 12 |
boundary | Administrative boundaries, with admin_level and a maritime flag | 0 |
place, poi | Division labels with rank and population; places, fewer at lower zooms | 3; 12 |
transit | Transit stops from the loaded timetables, with name and class | 13 |
housenumber | House numbers, with their street | 14 |
The names follow the vocabulary OpenMapTiles-style maps use, so an existing style of that family is a starting point rather than a rewrite. The tiles URL is built from the host the request arrived on —X-Forwarded-Host, else Host, and X-Forwarded-Proto — which is why the document above names the address it was captured from. Fetched by your backend, it namesapi.oslew.com; the proxy below rewrites it.
curl "https://api.oslew.com/v1/style.json" \
-H "Authorization: Bearer $GEO_API_KEY"from oslew import Client
# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")
answer = client.style_json()import { Client } from "@oslew/client";
// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });
const answer = await client.style_json();HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 290
ratelimit-reset: 1
{
"glyphs": "https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf",
"layers": [
{
"id": "background",
"paint": {
"background-color": "#f2efe9"
},
"type": "background"
},
{
"filter": [
"==",
[
"geometry-type"
],
"Polygon"
],
"id": "landcover",
"paint": {
"fill-color": [
"match",
[
"get",
"class"
],
"forest",
"#add19e",
"tree",
"#b5d6a7",
"grass",
"#cdebb0",
"crop",
"#eef0d5",
"shrub",
"#c8d7ab",
"urban",
"#e3dfda",
"snow",
"#f7fbff",
"glacier",
"#ddecec",
"barren",
"#e8dccb",
"rock",
"#e2ddd6",
"sand",
"#f5e9c6",
"wetland",
"#d1e6d6",
"mangrove",
"#b9d6c4",
"moss",
"#d6e3c4",
"reef",
"#c5e0e8",
"physical",
"#e2ddd6",
"land",
"#f2efe9",
"crater",
"#e2ddd6",
"desert",
"#f2e6c9",
"#e6efd8"
],
"fill-opacity": 0.85
},
"source": "basemap",
"source-layer": "landcover",
"type": "fill"
},
{
"filter": [
"==",
[
"geometry-type"
],
"Polygon"
],
"id": "landuse",
"paint": {
"fill-color": [
"match",
[
"get",
"class"
],
"park",
"#c8facc",
"recreation",
"#dff7df",
"protected",
"#d8ebc9",
"horticulture",
"#d6ecc6",
"managed",
"#d8efc8",
"agriculture",
"#eef0d5",
"residential",
"#e8e4df",
"developed",
"#ebe5e1",
"education",
"#f7efe3",
"medical",
"#f5e1e1",
"military",
"#f0d9d9",
"religious",
"#e7e3d8",
"cemetery",
"#d6e4cf",
"transportation",
"#e6e3e1",
"pedestrian",
"#efedea",
"entertainment",
"#f2e4f1",
"golf",
"#d4f0c8",
"campground",
"#e2f0d4",
"construction",
"#e4ddcf",
"winter_sports",
"#eef7fb",
"aquaculture",
"#d6e8ee",
"resource_extraction",
"#e4ddcf",
"#ece8e2"
],
"fill-opacity": 0.9
},
"source": "basemap",
"source-layer": "landuse",
"type": "fill"
},
{
"filter": [
"==",
[
"get",
"class"
],
"bathymetry"
],
"id": "water-bathymetry",
"paint": {
"fill-color": [
"interpolate",
[
"linear"
],
[
"coalesce",
[
"get",
"depth"
],
0
],
0,
"#aad3df",
200,
"#94c5d7",
1000,
"#7cb3cb",
4000,
"#5f9bbb",
8000,
"#4682a7"
]
},
"source": "basemap",
"source-layer": "water",
"type": "fill"
}
],
"name": "oslew basemap",
"sources": {
"basemap": {
"attribution": "© OpenStreetMap contributors · Overture Maps Foundation",
"type": "vector",
"url": "http://127.0.0.1:18481/v1/tiles.json"
}
},
"version": 8
}A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call. Shortened for the page: layers shows 4 of 29.
/v1/style.json is a MapLibre style, version 8, named oslew basemap: one vector source,basemap, whose url is the TileJSON on the same host, and its layers — 29 of them, shortened to four above — in the colours the PNG tiles and static maps are drawn with, so a raster fallback matches. Labels use the Noto Sans Regular font from glyphs, which points at MapLibre's public demo font server. That is the map's one outside dependency, and it needs no key; if you would rather not rely on a demo server, host the glyph files yourself and rewrite glyphs. Whatever you host, keep the font the layers name: MapLibre gives up on a whole tile when a glyph range it needs will not load, so a missing font is a blank map, not a map without labels. There are no sprites.
A map in the browser, through your backend
The proxy does three things. It forwards only the map — the two documents and the tiles — because a proxy that forwards any path is your key, published. It adds the Authorizationheader. And it rewrites the one URL in each document to point at itself, so MapLibre fetches everything from your origin. Tiles pass through untouched: still gzipped, with their cache lifetime.
// map-proxy.ts: the basemap at your own origin, with the key added here.
import http from "node:http";
import https from "node:https";
const API = "https://api.oslew.com";
const KEY = process.env.GEO_API_KEY!; // never sent to the browser
const PUBLIC = process.env.PUBLIC_ORIGIN!; // how browsers reach this server, e.g. https://maps.example.com
const TILE = /^\/map\/tiles\/\d+\/\d+\/\d+\.(mvt|pbf|png)$/;
http.createServer((req, res) => {
const path = new URL(req.url ?? "/", PUBLIC).pathname;
// Only the map: a proxy that forwards anything is the key, published.
if (path !== "/map/style.json" && path !== "/map/tiles.json" && !TILE.test(path)) {
res.writeHead(404).end();
return;
}
const auth = { headers: { authorization: "Bearer " + KEY } };
https.get(API + "/v1" + path.slice("/map".length), auth, (up) => {
const headers: http.OutgoingHttpHeaders = {};
for (const h of ["content-type", "content-encoding", "cache-control", "retry-after"]) {
if (up.headers[h]) headers[h] = up.headers[h];
}
if (!path.endsWith(".json") || up.statusCode !== 200) {
res.writeHead(up.statusCode ?? 502, headers); // tiles as sent: gzipped, cacheable
up.pipe(res);
return;
}
let body = "";
up.setEncoding("utf8");
up.on("data", (chunk) => (body += chunk));
up.on("end", () => {
const doc = JSON.parse(body);
// Each document names the host it was fetched from; point it here instead.
if (doc.tiles) doc.tiles = [PUBLIC + "/map/tiles/{z}/{x}/{y}.mvt"];
if (doc.sources?.basemap) doc.sources.basemap.url = PUBLIC + "/map/tiles.json";
res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify(doc));
});
}).on("error", () => res.writeHead(502).end());
}).listen(8080);# map_proxy.py: the basemap at your own origin, with the key added here.
import json, os, re, urllib.error, urllib.request
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
API = "https://api.oslew.com"
KEY = os.environ["GEO_API_KEY"] # never sent to the browser
PUBLIC = os.environ["PUBLIC_ORIGIN"] # how browsers reach this server, e.g. https://maps.example.com
TILE = re.compile(r"^/map/tiles/\d+/\d+/\d+\.(mvt|pbf|png)$")
class MapProxy(BaseHTTPRequestHandler):
def do_GET(self):
path = self.path.split("?", 1)[0]
# Only the map: a proxy that forwards anything is the key, published.
if path not in ("/map/style.json", "/map/tiles.json") and not TILE.match(path):
return self.send_error(404)
upstream = urllib.request.Request(
API + "/v1" + path[len("/map"):], headers={"Authorization": "Bearer " + KEY}
)
try:
with urllib.request.urlopen(upstream, timeout=10) as up:
status, headers, body = up.status, up.headers, up.read()
except urllib.error.HTTPError as refused:
status, headers, body = refused.code, refused.headers, refused.read()
if status == 200 and path.endswith(".json"):
doc = json.loads(body)
# Each document names the host it was fetched from; point it here instead.
if "tiles" in doc:
doc["tiles"] = [PUBLIC + "/map/tiles/{z}/{x}/{y}.mvt"]
if "basemap" in doc.get("sources", {}):
doc["sources"]["basemap"]["url"] = PUBLIC + "/map/tiles.json"
body = json.dumps(doc).encode()
self.send_response(status)
for name in ("Content-Type", "Content-Encoding", "Cache-Control", "Retry-After"):
if headers.get(name): # tiles as sent: gzipped, cacheable
self.send_header(name, headers[name])
if body:
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
ThreadingHTTPServer(("", 8080), MapProxy).serve_forever()Both are sketches of the shape, with nothing but the standard library; in production the same three rules go in whatever already serves your application, behind its own login if the map is not public. Then the page points MapLibre at the proxied style:
import maplibregl from "maplibre-gl";
import "maplibre-gl/dist/maplibre-gl.css";
const map = new maplibregl.Map({
container: "map", // <div id="map" style="height: 480px"></div>
style: new URL("/map/style.json", location.href).href, // your origin: no key, no CORS
center: [-99.1332, 19.4326], // [lon, lat]: MapLibre's order, not this API's
zoom: 14,
});
map.addControl(new maplibregl.NavigationControl());MapLibre's own transformRequest can add headers to its requests, and it is not the answer here: the header would carry the key into the browser, and the browser would still refuse the cross-origin answer. The same goes for a native mobile app — no CORS there, but a key shipped in an app is a key anyone can extract. Serve the map from your backend, where the key already lives.
Cache in front of the proxy
Every tile is a request, and each request takes a token from the key's platform bucket. A first view is a dozen or more tiles and every pan or zoom is another batch; a hundred people looking at a map at once would spend a plan's rate on tiles alone and meet 429s — which the proxy passes on, Retry-After included, and which MapLibre shows as missing tiles. Tiles are public and good for a day, so put a cache in front of the proxy — a CDN, or your web server's own — and a thousand people's tiles become one fetch each. Seerate limits.
Attribution
The basemap is derived from OpenStreetMap data through Overture's transportation and base themes, under the Open Database Licence: showing it means showing its attribution. The style's source carries it, and MapLibre's attribution control, which is on by default, displays it — leave it on. For PNG tiles, which carry no text, show the TileJSON's attribution line beside the map yourself. What share-alike asks of a database you build from the tiles is in data and licensing.
Endpoints
/v1/tiles/{z}/{x}/{y}platformOne basemap tile. y may carry an extension: .mvt or .pbf for the vector tile as stored, .png to rasterise it here.
/v1/tiles.jsonplatformThe TileJSON 3.0 document for the basemap: the tile URL template, the zoom range, the bounds and the attribution.
/v1/style.jsonplatformA MapLibre GL style over the basemap: layers, colours and the source pointing back at this service.