---
title: Build a map colored by area code in HTML
description: Use the prefecture, municipality and town boundaries that Queria serves to build a single HTML page that colors each area by its value
---

Queria serves the boundaries of prefectures, municipalities and towns (chōme) as map tiles in PMTiles format. Every area in the tiles carries its area code, so once you have pairs of area code and value, you can build a map that colors each area by that value. You do not need to download or convert boundary files.

The HTML on this page also works as a model when you ask an AI to build a map app. Give the AI the URL of this page.

## Where the tiles are

```
https://assets.queria.io/boundaries/boundaries-20261027.pmtiles
```

The date in the file name is the day the tiles were built. When the boundaries are updated, a new file is placed under a name with a new date. A file that has been placed is never rewritten. This page shows the name of the current file.

## Layers and area codes

One file holds three layers. Each area has a single attribute, `code`.

| Layer | Areas | Form of `code` | Zoom levels with tiles |
|---|---|---|---|
| `prefecture` | Prefectures | 2 digits (Tokyo is `13`) | 0–10 |
| `city` | Municipalities | 5 digits (Shinjuku is `13104`) | 4–12 |
| `small_area` | Towns | 9 or 11 digits (census small-area code) | 10–13 |

When the map is zoomed in past these levels, MapLibre enlarges the most detailed tiles. When the map is zoomed out past them, the layer shows no areas.

`code` is a string. If your values come from a numeric column, check that leading zeros were not dropped (Hokkaido is `01`, not `1`). If you use the 6-digit local government code (Shinjuku is `131041`), take its first 5 digits.

Designated cities have one area per ward and no area for the whole city (there is no `14100` for Yokohama, but there is `14101` for Tsurumi Ward and so on). To color by a city-wide value, give each ward the same value.

## HTML that colors prefectures

Save the following HTML to a file and open it in a browser to see the map. Put pairs of area code and value in `values`: areas with larger values are drawn in a darker color. Areas not in `values` are gray.

```html
<!doctype html>
<html lang="ja">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Population by prefecture</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maplibre-gl@6.14.0/dist/maplibre-gl.css">
  <script src="https://cdn.jsdelivr.net/npm/pmtiles@4.5.0/dist/pmtiles.js"></script>
  <style>html, body, #map { height: 100%; margin: 0; }</style>
</head>
<body>
  <div id="map"></div>
  <script type="module">
    import * as maplibregl from "https://cdn.jsdelivr.net/npm/maplibre-gl@6.14.0/dist/maplibre-gl.mjs";

    // Area codes and values. Put the result of your SQL on Queria here
    const values = { "13": 14047594, "14": 9237337, "27": 8837685 };

    const max = Math.max(...Object.values(values));
    const color = (v) => `rgba(37, 99, 235, ${(0.15 + 0.85 * v / max).toFixed(2)})`;
    const fill = ["match", ["get", "code"],
      ...Object.entries(values).flatMap(([code, v]) => [code, color(v)]),
      "#e5e7eb"];

    const protocol = new pmtiles.Protocol();
    maplibregl.addProtocol("pmtiles", protocol.tile);

    new maplibregl.Map({
      container: "map",
      center: [137, 37],
      zoom: 4,
      style: {
        version: 8,
        sources: {
          boundaries: {
            type: "vector",
            url: "pmtiles://https://assets.queria.io/boundaries/boundaries-20261027.pmtiles",
            maxzoom: 10,
            attribution: "Based on National Land Numerical Information (Administrative Areas), MLIT, processed by Queria",
          },
        },
        layers: [
          { id: "background", type: "background", paint: { "background-color": "#ffffff" } },
          {
            id: "prefecture",
            type: "fill",
            source: "boundaries",
            "source-layer": "prefecture",
            paint: { "fill-color": fill, "fill-outline-color": "#ffffff" },
          },
        ],
      },
    });
  </script>
</body>
</html>
```

## Coloring municipalities or towns

Change three places in the HTML.

- Set `"source-layer"` to `city` or `small_area`
- Set `maxzoom` in `sources.boundaries` to the top of the zoom range in the table above (12 for municipalities, 13 for towns)
- Towns are not shown below zoom 10, so set `center` and `zoom` to the area you want to color (for Shinjuku, `center: [139.70, 35.69]` and `zoom: 12`)

To fit the map to an area, use `boundaries-20261027.bbox.json`, which sits next to the tiles. It holds `[west, south, east, north]` for each prefecture (2-digit) and municipality (5-digit) code. Pass it to `map.fitBounds()` to fit that range on the screen.

## Preparing the values

Put the result of your SQL on Queria into `values` as `{ area code: value }`. You can run SQL from the [Queria CLI](/en/connection/queria-cli) or an [AI chat](/en/ai-chat). Check the form of the area code column (2, 5 or 6 digits, and so on) in the column descriptions on the table details page.

## Attribution

Show the source on the map. The text in `attribution` in the HTML appears at the bottom right of the map.

- Prefectures and municipalities: Based on National Land Numerical Information (Administrative Areas), MLIT, processed by Queria
- Towns: Based on the 2020 Census boundary data (Statistics Bureau of Japan, e-Stat), processed by Queria

Show the source of the values you colored as well. See [Attribution and licenses](/en/data/attribution) for how to write it.
