oslew docs
Console
Menu

Static maps

/v1/static answers a PNG of the basemap centred on a point: the tiles under the view, drawn and stitched by the service. It is for the places a live map cannot run or is not worth running — an email, a PDF, a receipt, a thumbnail in a list.

curl
curl "https://api.oslew.com/v1/static?at=19.4326%2C-99.1332&zoom=15&width=600&height=400" \
  -H "Authorization: Bearer $GEO_API_KEY" \
  -o map.png
Python
from oslew import Client

# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")

data = client.static("19.4326,-99.1332", zoom=15, width=600, height=400)
open("map.png", "wb").write(data)
TypeScript
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.static_("19.4326,-99.1332", { zoom: 15, width: 600, height: 400 });
await writeFile("map.png", data);
HTTP/1.1 200 OK · content-type: image/png · ratelimit-limit: 100 · ratelimit-remaining: 297 · ratelimit-reset: 1 · cache-control: public, max-age=3600
The 600×400 PNG this request returned

A real response, captured from the service at commit b8f4bde-dirty.

Asking

ParameterDefaultIs
atrequiredlat,lon: the centre of the image.
zoom13Clamped to 0–20, then rounded to a whole zoom — and no deeper than four past the basemap's own deepest, below.
width, height800 × 600Pixels, each clamped to 64–2,048.

The answer is image/png with Cache-Control: public, max-age=3600. The Python client'sclient.static(at, zoom=…, width=…, height=…) returns the bytes; in TypeScript the method isclient.static_(at, { zoom, width, height }), because static is a reserved word there, and returns a Uint8Array. Refusals are JSON as usual — a centre off the globe, say, orno tile archive loaded from a deployment without a basemap.

Zoom and scale

zoom counts 512-pixel tiles, as MapLibre does: at zoom z the world is 512 × 2z pixels around. So one pixel is40,075,017 m × cos(latitude) ÷ (512 × 2z) — at the Zócalo and zoom 15, about 2.25 m, and the 600-pixel image above is about 1.35 km across. Services that count 256-pixel tiles, Leaflet and Google's static maps among them, show the same scale at a zoom number one higher: this API's 15 is their 16.

  • A fractional zoom is rounded to the nearest whole one. Send whole numbers, so you know which you got.
  • Past the basemap's deepest zoom — the maxzoom in tiles.json, 14 for the archive here — the tiles are magnified, up to four zooms deeper. Beyond that the image is drawn atmaxzoom + 4 anyway: here, zoom 19 and 20 come back at 18's scale, covering more ground than asked for.
  • For a high-density screen, ask for twice the width and height at one zoom deeper, and show it at half size: the same ground, twice the pixels.

What it draws, and what it leaves to you

The basemap's shapes in the style's colours — land cover, water, roads and rail by class, buildings — and nothing else:

  • No labels. The service draws no text, so there are no street or place names on the image.
  • No markers or overlays. There are no parameters for them. Draw your own on top, below.
  • No attribution on the image; it is yours to print beside it, below.
  • Background where there is no map, in the basemap's land colour, #F2EFE9: outside the area the archive covers — see its bounds in the TileJSON — and beyond the top and bottom of the world. A centre outside the archive is a 200 with a plain picture, not an error, so check the point against bounds if an empty image would be a bug.
  • The world wraps sideways. A view across the antimeridian shows both sides of it; there is no edge at ±180°. It does not wrap vertically.

Drawing on top

A marker is a few lines, if you place it with the projection the service used: Web Mercator at 512-pixel tiles, with at at the centre of the image. A point's pixel is its world pixel minus the centre's, plus half the image. With Pillow, and the same whole zoom you asked for:

Python
import io, math
from PIL import Image, ImageDraw
from oslew import Client

client = Client(base_url="https://api.oslew.com")

def pixel(lat, lon, centre, zoom, width, height):
    """Where (lat, lon) lands on a static map: Web Mercator, 512-pixel tiles, as the service draws it."""
    def world(la, lo):
        n = 512 * 2 ** zoom
        s = min(max(math.sin(math.radians(la)), -0.9999), 0.9999)
        return (lo + 180) / 360 * n, (0.5 - math.log((1 + s) / (1 - s)) / (4 * math.pi)) * n
    (cx, cy), (x, y) = world(*centre), world(lat, lon)
    return x - cx + width / 2, y - cy + height / 2

centre, zoom, width, height = (19.4326, -99.1332), 15, 600, 400
png = client.static(f"{centre[0]},{centre[1]}", zoom=zoom, width=width, height=height)

img = Image.open(io.BytesIO(png)).convert("RGB")
draw = ImageDraw.Draw(img)
for lat, lon in [(19.4326, -99.1332), (19.4346, -99.1318)]:     # the Zócalo, the Templo Mayor
    x, y = pixel(lat, lon, centre, zoom, width, height)
    draw.ellipse([x - 7, y - 7, x + 7, y + 7], fill=(200, 40, 40), outline=(255, 255, 255), width=2)
img.save("zocalo-marked.png")

The formula is the whole of the service's placement, so a marker lands within a pixel of where the map has the point. Use a zoom no deeper than maxzoom + 4, or the service will have drawn a different zoom from the one you are placing markers for. A point more than half the image from the centre falls outside it; for a set of points, pick the centre and zoom that fit them first.

In emails and documents

The API's URL cannot go into an email or a page. An <img src> sends noAuthorization header, and a key must never be in a URL. Fetch the PNG on your server, keep it, and serve your copy — attach it to the email, embed it in the PDF, or put it on your own storage.

Keep it. The image for one centre, zoom and size is the same until the basemap is rebuilt; the service's Cache-Control says an hour, and for a document, a map as of when it was made is usually exactly what you want. Each fetch takes a token from the key's platform bucket, so a thousand order confirmations for one shop should be one request, not a thousand:

Python
import hashlib, pathlib
from oslew import Client

client = Client(base_url="https://api.oslew.com")
cache = pathlib.Path("static-maps")
cache.mkdir(exist_ok=True)

def static_map(at: str, zoom: int = 15, width: int = 600, height: int = 400) -> pathlib.Path:
    """The PNG for one view, fetched once and kept: one request per distinct map, not per email."""
    key = hashlib.sha256(f"{at}|{zoom}|{width}|{height}".encode()).hexdigest()[:16]
    path = cache / f"{key}.png"
    if not path.exists():
        path.write_bytes(client.static(at, zoom=zoom, width=width, height=height))
    return path
TypeScript
import { createHash } from "node:crypto";
import { access, mkdir, writeFile } from "node:fs/promises";
import { Client } from "@oslew/client";

const client = new Client({ baseUrl: "https://api.oslew.com" });
await mkdir("static-maps", { recursive: true });

/** The PNG for one view, fetched once and kept: one request per distinct map, not per email. */
async function staticMap(at: string, zoom = 15, width = 600, height = 400): Promise<string> {
  const key = createHash("sha256").update([at, zoom, width, height].join("|")).digest("hex").slice(0, 16);
  const path = "static-maps/" + key + ".png";
  try {
    await access(path);
  } catch {
    await writeFile(path, await client.static_(at, { zoom, width, height }));
  }
  return path;
}

Print the attribution beside it. The basemap is built from OpenStreetMap data under the Open Database Licence, and the image carries no attribution of its own: put© OpenStreetMap contributors · Overture Maps Foundation in the caption, the email's text or the page footer. See data and licensing.

Endpoints

GET/v1/staticplatform

A PNG of the basemap around a point: the tiles it needs, rasterised and stitched here.