Using these maps in an app

Your app loads one address per map, the style. Every tile, font and icon address comes from the style and points back at this proxy, so the app needs no map keys and providers never see your users.

1. Show a map

With MapLibre GL JS (version 3 or later):

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maplibre-gl@5/dist/maplibre-gl.css">
<script src="https://cdn.jsdelivr.net/npm/maplibre-gl@5/dist/maplibre-gl.js"></script>
<div id="map" style="height: 400px"></div>
<script>
  const STYLE = '/v1/styles/.json';
  const map = new maplibregl.Map({
    container: 'map',
    style: STYLE,
    center: [10.75, 59.91], // [longitude, latitude]
    zoom: 11,
  });
</script>

In Flutter, with the maplibre_gl package:

MapLibreMap(
  styleString: '/v1/styles/.json',
  initialCameraPosition: const CameraPosition(target: LatLng(59.91, 10.75), zoom: 11),
)

2. Pick a style

  • GET /v1/styles lists the names: .
  • Styles ending in -premium use Norkart inside Norway and our own map everywhere else. If Norkart is unavailable, the whole map switches to our own map; it never mixes the two in one place.
  • The style the app loaded says who drew it: metadata["autoreg:tile-proxy"] is { provider, fallback }, plus recheck_seconds on a fallback.

3. Follow the proxy when a provider is down or back

A map keeps the style it loaded. Load it again when it is a fallback (to get Norkart back) and when tiles start failing (to move to the fallback):

let timer = null;
function reloadIn(seconds) {
  if (timer) return;
  timer = setTimeout(() => {
    timer = null;
    map.setStyle(STYLE, { diff: false });
  }, seconds * 1000);
}
map.on('style.load', () => {
  const m = map.getStyle().metadata?.['autoreg:tile-proxy'];
  if (m?.fallback) reloadIn(m.recheck_seconds ?? 60);
  // Add your own sources and layers here: a new style removes them.
});
map.on('error', e => {
  if (e.error?.status >= 500) reloadIn(5);
});

4. Address search

Our own geocoder (Photon, OpenStreetMap data for Norway, Sweden, Finland and Lithuania). The answer is GeoJSON; lang can be the user's locale.

const q = encodeURIComponent('Storgata 1 Leknes');
const res = await fetch(`/v1/services/geocode/api?q=${q}&lang=${navigator.language}&limit=5`);
const { features } = await res.json();
// features[0].geometry.coordinates is [longitude, latitude]

// Nearest address to a point:
// /v1/services/geocode/reverse?lat=68.15&lon=13.61

Rules

  • Do not build or store tile, font or icon addresses. Read them from the style. They change when a provider changes.
  • Load the style by its address every time the map starts. Do not bundle a copy in the app; the browser cache honours the proxy's cache headers.
  • Keep the attribution control. It shows the credits each provider's licence requires.
  • Premium styles hold two icon sets (sprite is a list). They need a MapLibre version that supports more than one sprite; GL JS 3 and later do.
  • No keys, cookies or headers are needed. The proxy sends none of yours on to a provider.