Skip to content

Commit 1a93502

Browse files
authored
Merge pull request #474 from geolonia/docs/add-embed-core-usage
docs: README に @geolonia/embed/core の使い方を追加
2 parents 8e7b4e6 + c701de1 commit 1a93502

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Specify `.geolonia` class for target elements.
2323
<html>
2424
<body>
2525
<div class="geolonia" ...></div>
26-
<script src="https://cdn.geolonia.com/v1/embed?geolonia-api-key=YOUR-API-KEY"></script>
26+
<script src="https://cdn.geolonia.com/embed/v5/embed?geolonia-api-key=YOUR-API-KEY"></script>
2727
</body>
2828
</html>
2929
```
@@ -35,11 +35,34 @@ Or
3535
<html>
3636
<body>
3737
<div class="geolonia" data-key="YOUR-API-KEY" ...></div>
38-
<script src="https://cdn.geolonia.com/v1/embed"></script>
38+
<script src="https://cdn.geolonia.com/embed/v5/embed"></script>
3939
</body>
4040
</html>
4141
```
4242

43+
### Using with npm (for React, Next.js, Astro, Fresh, etc.)
44+
45+
For modern web frameworks, use `@geolonia/embed/core` — a side-effect-free entry point designed for programmatic use.
46+
47+
```shell
48+
npm install @geolonia/embed
49+
```
50+
51+
```typescript
52+
import { GeoloniaMap, keyring } from "@geolonia/embed/core";
53+
54+
keyring.apiKey = "YOUR-API-KEY";
55+
56+
const map = new GeoloniaMap({
57+
container: "#map",
58+
style: "geolonia/gsi",
59+
center: [139.7671, 35.6812],
60+
zoom: 14,
61+
});
62+
```
63+
64+
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.
65+
4366
### Using External Styles Without API Key
4467

4568
You can use external style.json URLs without a Geolonia API key. This is useful when:
@@ -62,7 +85,7 @@ You can use external style.json URLs without a Geolonia API key. This is useful
6285
data-zoom="14"
6386
data-style="https://tile.openstreetmap.jp/styles/osm-bright/style.json"
6487
></div>
65-
<script src="https://cdn.geolonia.com/v1/embed"></script>
88+
<script src="https://cdn.geolonia.com/embed/v5/embed"></script>
6689
</body>
6790
</html>
6891
```

0 commit comments

Comments
 (0)