Skip to content
geoloniaPublic

About

Embed API for Geolonia Maps

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

6 stars

Watchers

8 watching

Forks

Latest commit

 

History

1,220 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@geolonia/embed

build

JS embed API for Geolonia service.

Features

  • webGL vector map rendering
  • simple configuration
  • map lazy rendering

Examples

https://geolonia.github.io/embed/

Usage

Specify .geolonia class for target elements.

<!DOCTYPE html>
<html>
  <body>
    <div class="geolonia" ...></div>
    <script src="https://cdn.geolonia.com/embed/v6/embed?geolonia-api-key=YOUR-API-KEY"></script>
  </body>
</html>

Or

<!DOCTYPE html>
<html>
  <body>
    <div class="geolonia" data-key="YOUR-API-KEY" ...></div>
    <script src="https://cdn.geolonia.com/embed/v6/embed"></script>
  </body>
</html>

Using with npm (for React, Next.js, Astro, Fresh, etc.)

For modern web frameworks, use @geolonia/embed/core — an entry point designed for programmatic use.

npm install @geolonia/embed
import { GeoloniaMap, keyring } from "@geolonia/embed/core";

keyring.setApiKey("YOUR-API-KEY");

const map = new GeoloniaMap({
  container: "#map",
  style: "geolonia/gsi",
  center: [139.7671, 35.6812],
  zoom: 14,
});

Unlike the default @geolonia/embed entry point, /core does not automatically scan the DOM or set window.geolonia. This makes it safe to use in SSR environments and avoids double-initialization issues in frameworks like React, Preact, and Vue. (Its only import-time side effect is registering the bundled MapLibre worker, which is skipped outside the browser.)

Content Security Policy

@geolonia/embed ships as a single file, so the MapLibre worker is embedded in the bundle and started from a blob: URL. If your page sets a Content Security Policy, allow blob: as a worker source:

Content-Security-Policy: worker-src blob:;

Using External Styles Without API Key

You can use external style.json URLs without a Geolonia API key. This is useful when:

  • Using open-source tile servers like OpenStreetMap Japan
  • Self-hosting your own tiles and styles
  • Distributing maps without API key dependencies

Note: Geolonia API key is only required when using Geolonia's hosted styles and tiles.

<!DOCTYPE html>
<html>
  <body>
    <!-- Using OpenStreetMap Japan tiles (no API key needed) -->
    <!-- Note: tile.openstreetmap.jp is for non-commercial use only -->
    <div
      class="geolonia"
      data-lat="35.6812"
      data-lng="139.7671"
      data-zoom="14"
      data-style="https://tile.openstreetmap.jp/styles/osm-bright/style.json"
    ></div>
    <script src="https://cdn.geolonia.com/embed/v6/embed"></script>
  </body>
</html>

You can also use npm/unpkg/jsDelivr for self-hosted or CDN distribution:

<!-- Using npm CDN (unpkg) -->
<script src="https://unpkg.com/@geolonia/embed@latest/dist/embed.js"></script>

<!-- Using jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/@geolonia/embed@latest/dist/embed.js"></script>

data-style attribute

The data-style attribute accepts:

  • Geolonia style names: geolonia/basic, geolonia/gsi (requires API key)
  • Full URLs: https://example.com/style.json
  • Relative paths: ./custom-style.json, /styles/my-style.json
  • Files ending in .json: Automatically resolved to absolute URLs

data-lang attribute

The data-lang attribute controls the language of map labels (when data-style is omitted or a Geolonia style name) and of the gesture handling messages:

  • ja / ja-jp: Japanese labels
  • en (or any value other than ja, ja-jp, auto and an empty value): English labels
  • auto: follow the browser language (navigator.languages)
  • empty value: same as auto
  • omitted: same as auto (follows the browser language)

ja / ja-jp always resolve to Japanese; auto, an empty value and an omitted attribute follow the browser language; every other value resolves to English. The match is case-sensitive, so ja-JP resolves to English.

Important: when neither data-lang nor lang is specified, the language follows the browser setting. On a non-Japanese browser this loads the English style (en.json). Set it explicitly to force a language:

<div class="geolonia" data-lang="ja" ...></div>

When using the JavaScript API (new GeoloniaMap({...})), pass lang in the options instead of a data-lang attribute:

const map = new GeoloniaMap({ container: "#map", lang: "ja" });

data-projection attribute

The data-projection attribute sets the map projection: globe shows the map as a globe, and mercator shows it flat.

<div
  class="geolonia"
  data-zoom="2"
  data-projection="globe"
></div>

Leading and trailing spaces are removed. Any other value is reported in the console and ignored. When the attribute is omitted or empty, the projection of the style is used (mercator if the style has none).

data-raster-tiles attribute

The data-raster-tiles attribute overlays raster tiles from another provider (hazard maps, GSI tiles and so on). Give a URL template that contains {z}, {x} and {y}:

<div
  class="geolonia"
  data-raster-tiles="https://example.com/tiles/{z}/{x}/{y}.png"
  data-raster-tiles-attribution="Example tiles"
  data-raster-tiles-opacity="0.7"
  data-raster-tiles-max-zoom="17"
></div>

data-raster-tiles-attribution is shown in the attribution control. It accepts the same HTML as MapLibre's attribution: links and basic formatting tags are kept, and everything else is removed (scripts, event handler attributes such as onclick, and other elements together with their content). A href or src whose scheme is not http:, https: or mailto: (for example javascript:) is removed; relative URLs are kept. This requires @geolonia/maps-core 0.9.1 or later: versions of @geolonia/embed that bundle an earlier maps-core render the value as HTML without sanitizing it.

data-extrusion attribute

The data-extrusion attribute draws the polygons of data-geojson in 3D, with a height (and, unless data-extrusion-color names another property, a color) from the given property. It has no effect without data-geojson.

<div
  class="geolonia"
  data-geojson="https://example.com/areas.geojson"
  data-extrusion="population"
  data-extrusion-max-height="3000"
  data-pitch="60"
></div>

Important: set data-pitch as well. With the default pitch of 0 the map is seen from straight above, so the polygons look flat.

data-mask attribute

The data-mask attribute darkens everything outside an area. Give the URL of a GeoJSON file with the boundary:

<div
  class="geolonia"
  data-mask="https://example.com/city.geojson"
  data-mask-opacity="0.5"
  data-mask-outline="on"
></div>

When the map has no center (data-lat and data-lng), no data-geojson and no data-simple-vector, it fits to the boundary.

You can see more examples at https://geolonia.github.io/embed/.

Contributing

Development

Requirements

  • node.js >= 22.22.2 (the floor required by jsdom 30; .tool-versions pins the latest 22.x)

How to build

This project uses pnpm. The version is pinned in two places, which must be kept in sync: the packageManager field of package.json (used by Corepack and by pnpm/action-setup in CI) and .tool-versions (used by asdf and mise). pnpm-workspace.yaml sets pmOnFail: ignore, so pnpm itself will not correct a mismatch; the build workflow compares the two pins instead and fails if they disagree.

$ git clone git@github.com:geolonia/embed.git
$ cd embed
$ pnpm install
$ pnpm start # run dev server
$ pnpm test # run tests
$ pnpm run e2e # run e2e tests (run `pnpm run build` first to include the production-bundle test)
$ pnpm run build # build production bundle

Then you can see http://localhost:3000/.

Dependency updates

Dependencies are updated by Dependabot, configured in .github/dependabot.yml. Minor and patch updates arrive as one grouped weekly PR. Major version updates are ignored for now — there is a backlog of them and each needs its own plan — but security updates still arrive for any version, major included, because an ignore on version-update:semver-major only scopes version updates.

pnpm-workspace.yaml sets pmOnFail: ignore, and that line is load-bearing: without it pnpm 12 writes pnpm-lock.yaml as two YAML documents, GitHub's dependency-graph parser reads only the first one (which holds nothing but pnpm itself), and no npm package ever reaches the graph — so no Dependabot alert is raised. See pnpm-workspace.yaml and dependabot-core#15904. Keep the lockfile a single YAML document.

To check by hand:

$ pnpm audit            # vulnerabilities
$ pnpm outdated         # available updates
$ pnpm why maplibre-gl  # who pulls a package in

Run Bundle analyzer

$ pnpm run analyze

Snapshot testing

preparation

$ cp .envrc.sample .envrc
$ vi .envrc
$ pnpm run build
$ docker build . -t geolonia/embed

About

Embed API for Geolonia Maps

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

6 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages