# UN Street Map

A reference implementation of the **UN Street Map**, the UN Geospatial vector tile basemap, rendered with [MapLibre GL JS](https://maplibre.org/). It is the detailed companion to the [UN Topo (ClearMap) basemap](../un-topo-base-map/README.md): it has real data at every zoom level, from the world view down to streets and buildings.

## Hosted URLs

```
https://assets.undrr.org/projects/maps/un-street-map/v1/map-reference.html
https://assets.undrr.org/projects/maps/un-street-map/v1/leaflet-reference.html
```

- `map-reference.html`: MapLibre GL JS (recommended). Add `?view=kathmandu` or `?view=geneva` to open at a city view.
- `leaflet-reference.html`: the same basemap inside a Leaflet map, through the [MapLibre GL Leaflet plugin](https://github.com/maplibre/maplibre-gl-leaflet). Use it only if your page is already built on Leaflet.

Both pages use Mangrove 2.1.1 for typography, breadcrumbs, buttons and the
map-loading error panel, with a reload action. Mangrove is served from the asset
library; populate `mangrove/2.1.1/` locally before previewing the pages.

## When to use ClearMap vs UN Street Map

| | [`un-topo-base-map`](../un-topo-base-map/README.md) (ClearMap) | `un-street-map` |
|---|---|---|
| Best for | Small-scale world or regional reference maps | Subnational, city and street-level maps |
| Boundaries | Official UN depiction | UN Map data for boundaries, plus OpenStreetMap detail |
| Tile type | Raster (PNG) | Vector (Mapbox Vector Tiles, styled in the browser) |
| Zoom range | 0–6 only (zoom 7 shows "map not available at this scale"; 8 and above are missing) | 0–23, with data at every level |
| Library | Leaflet (or any raster tile client) | MapLibre GL JS, or Leaflet with a plugin |
| Page weight | Light | Heavier: a WebGL map library and a 491-layer style |

## Service details

| | |
|---|---|
| Web map item | [UN Street Map](https://geoportal.un.org/arcgis/home/item.html?id=6261d032312d42f4a4ca48d041eedc19) on the UN Geoportal (public) |
| Vector tile service item | [`6e777995e88c4e7d8cf810070858f0ac`](https://geoportal.un.org/arcgis/home/item.html?id=6e777995e88c4e7d8cf810070858f0ac) (public) |
| Service URL | `https://pro-ags2.dfs.un.org/arcgis/rest/services/Hosted/Unite_StreetMapVT_CVW_V01/VectorTileServer` |
| Tiles | `{service}/tile/{z}/{y}/{x}.pbf` (ArcGIS order: **y before x**) |
| Style | `{service}/resources/styles/root.json` (Mapbox GL style v8) |
| Sprite | `{service}/resources/sprites/sprite` |
| Glyphs | `{service}/resources/fonts/{fontstack}/{range}.pbf` |
| CORS | Allowed: the service echoes the request origin |

## Gotchas

**The published style uses relative URLs.** `root.json` points to its tiles as `"../../"`, its sprite as `"../sprites/sprite"` and its glyphs as `"../fonts/{fontstack}/{range}.pbf"`. Passing the style URL straight to `new maplibregl.Map({ style: url })` does not work. Fetch the style, rewrite those three to absolute URLs, then pass the style object.

**Combined font stacks return 404.** Some label layers list two fonts (for example `["Noto Sans Display Medium", "Arial Unicode MS Regular"]`). MapLibre requests them as one comma-separated font stack, which the glyph endpoint does not serve. Keep only the first font of each `text-font` list.

**MapLibre GL JS 6 is ES-module only.** Load it with `<script type="module">` and `import`. There is no `maplibre-gl.js` UMD file to add with a classic `<script>` tag. The Leaflet plugin expects a global `maplibregl`, so the Leaflet page sets `window.maplibregl` before loading the plugin.

## Minimal usage

```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maplibre-gl@6.11.2/dist/maplibre-gl.css" />

<div id="map" style="height: 400px;"></div>

<script type="module">
  import * as maplibregl from 'https://cdn.jsdelivr.net/npm/maplibre-gl@6.11.2/dist/maplibre-gl.mjs';

  const UN_STREET_MAP =
    'https://pro-ags2.dfs.un.org/arcgis/rest/services/Hosted/Unite_StreetMapVT_CVW_V01/VectorTileServer';

  async function loadUnStreetMapStyle() {
    const style = await (await fetch(UN_STREET_MAP + '/resources/styles/root.json')).json();

    // Rewrite the style's relative URLs to absolute ones
    const source = style.sources.esri;
    delete source.url;
    source.tiles = [UN_STREET_MAP + '/tile/{z}/{y}/{x}.pbf']; // y before x
    source.attribution =
      'Base map: UN Street Map, United Nations Geospatial, UN Peacekeeping and Political Missions, ' +
      'UN Global Service Centre, © OpenStreetMap contributors';
    style.sprite = UN_STREET_MAP + '/resources/sprites/sprite';
    style.glyphs = UN_STREET_MAP + '/resources/fonts/{fontstack}/{range}.pbf';

    // The glyph endpoint serves one font per request
    style.layers.forEach((layer) => {
      const fonts = layer.layout && layer.layout['text-font'];
      if (Array.isArray(fonts) && fonts.length > 1) layer.layout['text-font'] = [fonts[0]];
    });

    return style;
  }

  new maplibregl.Map({
    container: 'map',
    style: await loadUnStreetMapStyle(),
    center: [0, 20],
    zoom: 1.2
  });
</script>
```

Pin an exact MapLibre version, as above. Do not use `@latest`.

### OpenLayers

The same rewritten style object works with OpenLayers through [`ol-mapbox-style`](https://github.com/openlayers/ol-mapbox-style): call `applyStyle(vectorTileLayer, style, 'esri')` on a `VectorTileLayer` with `declutter: true`.

## Attribution and disclaimer

Credits from the UN Geoportal item, to show with the map:

```
Base map: UN Street Map. United Nations Geospatial, UN Peacekeeping and Political Missions,
UN Global Service Centre, © OpenStreetMap contributors.
```

The item also gives "© UNITED NATIONS 2020" and lists its data sources: UN Map data (UNHQ, former cartographic section), OpenStreetMap, GlobeLand30 land cover and CIAT-CSI SRTM 4.1 hillshade. Send corrections to [UNGeoportal-feedback@un.org](mailto:UNGeoportal-feedback@un.org).

Show the disclaimer from the item description with the map. Both reference pages quote it in full; the text is copied from the item, with one correction: the item omits "and" in the Sudan sentence ("…the Republic of Sudan the Republic of South Sudan…"), which is added here. It differs from the ClearMap disclaimer: it uses the UN Secretariat wording and adds notes on Abyei and the Chagos Archipelago.

## Licence

The UN Geoportal item does not state a reuse licence. Use within the UN family is expected to be fine; confirm with UN Geospatial ([UNGeoportal-feedback@un.org](mailto:UNGeoportal-feedback@un.org)) before external or production use. OpenStreetMap-derived data falls under the [ODbL](https://www.openstreetmap.org/copyright), which requires the OpenStreetMap credit.

## Versions

### v1 (current)

- MapLibre GL JS reference (`map-reference.html`) and Leaflet variant (`leaflet-reference.html`)
- MapLibre GL JS 6.11.2 and `@maplibre/maplibre-gl-leaflet` 0.1.4, from jsDelivr; Leaflet 1.9.4 from the asset library
- Vector tile service: `Unite_StreetMapVT_CVW_V01` on `pro-ags2.dfs.un.org`
