# Map tiles for apps and websites

> Raster XYZ map tiles from OpenStreetMap for interactive maps in Leaflet, MapLibre and flutter_map, with publishable keys restricted by origin.

Source: https://www.wayline.cloud/docs/guides/map-tiles

For a live, zoomable map like Google Maps, load the **vector style** below with MapLibre (web, Flutter, Android, iOS). Raster tiles (`/v1/tiles/{z}/{x}/{y}.png`) are also available for Leaflet and `flutter_map`. Try it on the [interactive map page](/maps).

## Vector maps (recommended)

```
https://api.wayline.cloud/v1/maps/styles/wayline-light.json?key=YOUR_PUBLISHABLE_KEY
```

The style points MapLibre at Wayline vector tiles (`/v1/tiles/vector/{z}/{x}/{y}.pbf`, OpenMapTiles schema, detail up to zoom 14 and sharp overzoom beyond) and fonts (`/v1/maps/fonts/...`), all with your key. Labels rotate with the map and stay crisp on every screen. The style and fonts are free; each vector tile is one `map_tile` unit.

### MapLibre GL JS (web)

```html
<link href="https://unpkg.com/maplibre-gl@5.6.0/dist/maplibre-gl.css" rel="stylesheet" />
<script src="https://unpkg.com/maplibre-gl@5.6.0/dist/maplibre-gl.js"></script>
<div id="map" style="height: 480px"></div>
<script>
  const map = new maplibregl.Map({
    container: "map",
    style: "https://api.wayline.cloud/v1/maps/styles/wayline-light.json?key=YOUR_PUBLISHABLE_KEY",
    center: [90.3875, 23.7808], // [lng, lat]
    zoom: 12,
  });
  map.addControl(new maplibregl.NavigationControl());
</script>
```

### Flutter (`maplibre_gl`)

```dart
MapLibreMap(
  styleString: 'https://api.wayline.cloud/v1/maps/styles/wayline-light.json?key=$waylineMapKey',
  initialCameraPosition: const CameraPosition(target: LatLng(23.7808, 90.3875), zoom: 12),
  myLocationEnabled: true,
)
```

Android and iOS native apps use the same style URL with MapLibre Native.

## Raster tiles

`/v1/tiles/{z}/{x}/{y}.png` serves standard XYZ (Web Mercator) raster tiles, the same base map used by [static map images](/docs/guides/static-maps). Use them for an interactive map in a web page or a mobile app.

```
https://api.wayline.cloud/v1/tiles/{z}/{x}/{y}.png?key=YOUR_PUBLISHABLE_KEY      256 px
https://api.wayline.cloud/v1/tiles/{z}/{x}/{y}@2x.png?key=YOUR_PUBLISHABLE_KEY   512 px (retina)
```

Zoom 0 to 18. Street names are readable from zoom 15. Tiles are cacheable for 24 hours.

## Publishable keys (required for tiles)

Every other Wayline endpoint is called from your server, and its key must stay there. Tiles are different: the browser or the app downloads them directly, so the key is visible to anyone who looks. Create a separate **publishable key** for tiles:

1. In the dashboard, create a key and give it **only the `map_tile` scope**. Even if someone copies it, it cannot call routing, geocoding or any other paid endpoint.
2. For websites, add your sites under **Allowed origins** (for example `https://app.example.com`, `https://*.example.com`). Requests from other origins get `403 KEY_NOT_ALLOWED_FROM_ORIGIN`. Image requests do not send an `Origin` header, so Wayline also checks the `Referer`.
3. Set a monthly **spend limit** on the billing page as a backstop.

Mobile apps send no origin, so for an app the scope and the spend limit are the protection. Our [Terms](/legal/terms) allow a `map_tile`-only key inside a mobile app or web page; all other keys must stay on your servers.

## Leaflet

```js
L.tileLayer("https://api.wayline.cloud/v1/tiles/{z}/{x}/{y}{r}.png?key=" + WAYLINE_TILE_KEY, {
  maxZoom: 18,
  tileSize: 256,
  attribution:
    '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>',
}).addTo(map);
```

Leaflet replaces `{r}` with `@2x` on retina screens.

## MapLibre GL JS (raster source)

```js
new maplibregl.Map({
  container: "map",
  center: [90.376, 23.7465], // [lng, lat]
  zoom: 14,
  style: {
    version: 8,
    sources: {
      wayline: {
        type: "raster",
        tiles: ["https://api.wayline.cloud/v1/tiles/{z}/{x}/{y}@2x.png?key=" + WAYLINE_TILE_KEY],
        tileSize: 256,
        maxzoom: 18,
        attribution: "© OpenStreetMap contributors",
      },
    },
    layers: [{ id: "wayline", type: "raster", source: "wayline" }],
  },
});
```

## Flutter (`flutter_map`)

```dart
FlutterMap(
  options: const MapOptions(initialCenter: LatLng(23.7465, 90.3760), initialZoom: 14, maxZoom: 18),
  children: [
    TileLayer(
      urlTemplate: 'https://api.wayline.cloud/v1/tiles/{z}/{x}/{y}@2x.png?key={key}',
      additionalOptions: const {'key': waylineTileKey},
      userAgentPackageName: 'com.example.app',
    ),
    const RichAttributionWidget(attributions: [TextSourceAttribution('OpenStreetMap contributors')]),
  ],
)
```

Keep the OpenStreetMap attribution visible on the map; the ODbL license requires it.

## Billing

One `map_tile` unit per tile returned with HTTP 200 (see [pricing](/pricing)). Tiles the browser or `flutter_map` already cached are not requested again, so they are not billed again. Usage appears in the dashboard as **Map tiles**.

Vector tiles and a style JSON for MapLibre are planned; [contact us](/contact) if you need them.
