@molecule/app-maps-leaflet 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -0
- package/package.json +8 -5
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-08-04T01:52:05.723Z
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
# @molecule/app-maps-leaflet
|
|
10
|
+
|
|
11
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
+
|
|
15
|
+
`@molecule/app-maps-leaflet` — a Leaflet-backed provider for `@molecule/app-maps`.
|
|
16
|
+
Renders real slippy maps with OpenStreetMap tiles (NO API key). Bond it once at
|
|
17
|
+
startup and every `createMap` call shows a real map — the built-in default only
|
|
18
|
+
paints a grey placeholder panel.
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// In your app entry, ONCE — REQUIRED: import 'leaflet/dist/leaflet.css'
|
|
24
|
+
// (without that CSS the tiles + markers are mispositioned):
|
|
25
|
+
import { setProvider, createMap } from '@molecule/app-maps'
|
|
26
|
+
import { provider } from '@molecule/app-maps-leaflet'
|
|
27
|
+
setProvider(provider)
|
|
28
|
+
|
|
29
|
+
// then anywhere (the container element needs an explicit height):
|
|
30
|
+
const el = document.getElementById('map') as HTMLElement
|
|
31
|
+
const map = await createMap({ container: el, center: { lat: 51.5, lng: -0.12 }, zoom: 12 })
|
|
32
|
+
map.addMarker({ id: 'a', position: { lat: 51.5, lng: -0.12 }, popup: 'Here' })
|
|
33
|
+
// …later, on unmount: map.destroy()
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Type
|
|
37
|
+
|
|
38
|
+
`provider`
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @molecule/app-maps-leaflet @molecule/app-maps leaflet
|
|
44
|
+
npm install -D @types/leaflet
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API
|
|
48
|
+
|
|
49
|
+
### Functions
|
|
50
|
+
|
|
51
|
+
#### `createProvider()`
|
|
52
|
+
|
|
53
|
+
Creates a Leaflet-backed `MapProvider`.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
function createProvider(): MapProvider
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Returns:** A `MapProvider` that renders real OpenStreetMap-tiled maps.
|
|
60
|
+
|
|
61
|
+
### Constants
|
|
62
|
+
|
|
63
|
+
#### `provider`
|
|
64
|
+
|
|
65
|
+
The default Leaflet map provider, ready to bond with `setProvider(provider)`.
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
const provider: MapProvider
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Core Interface
|
|
72
|
+
|
|
73
|
+
Implements `@molecule/app-maps` interface.
|
|
74
|
+
|
|
75
|
+
## Bond Wiring
|
|
76
|
+
|
|
77
|
+
Setup function to register this provider with the core interface:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { setProvider } from '@molecule/app-maps'
|
|
81
|
+
import { provider } from '@molecule/app-maps-leaflet'
|
|
82
|
+
|
|
83
|
+
export function setupMapsLeaflet(): void {
|
|
84
|
+
setProvider(provider)
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Injection Notes
|
|
89
|
+
|
|
90
|
+
### Requirements
|
|
91
|
+
|
|
92
|
+
Peer dependencies:
|
|
93
|
+
|
|
94
|
+
- `@molecule/app-maps` ^1.0.1
|
|
95
|
+
|
|
96
|
+
### Runtime Dependencies
|
|
97
|
+
|
|
98
|
+
- `@molecule/app-maps`
|
|
99
|
+
- `leaflet`
|
|
100
|
+
|
|
101
|
+
TWO gotchas that decide whether the map is visible at all:
|
|
102
|
+
|
|
103
|
+
- **Import `leaflet/dist/leaflet.css` once** (app entry). Without it, tiles and
|
|
104
|
+
markers are mispositioned — the #1 "my Leaflet map looks broken" cause.
|
|
105
|
+
- **The container needs an explicit height** (e.g. `style={{ height: 400 }}`); a
|
|
106
|
+
zero-height container renders a blank map.
|
|
107
|
+
|
|
108
|
+
Markers use a self-contained inline-SVG pin by default (no image-asset wiring —
|
|
109
|
+
this sidesteps Leaflet's default-icon 404 under bundlers); pass `icon` for a
|
|
110
|
+
custom URL. ALWAYS `destroy()` on unmount — Leaflet attaches DOM + resize
|
|
111
|
+
listeners, and re-initialising over a live container throws "Map container is
|
|
112
|
+
already initialized".
|
|
113
|
+
|
|
114
|
+
`getSnapshot()` rejects (Leaflet has no built-in export) and `getCanvas()`
|
|
115
|
+
returns a best-effort surface — both are WebGL-provider (Mapbox/MapLibre)
|
|
116
|
+
concepts. Everything else (markers/polylines/polygons/circles/popups/viewport/
|
|
117
|
+
fitBounds/project/events) renders for real.
|
|
118
|
+
|
|
119
|
+
BROWSER-ONLY: draws to the DOM via Leaflet. Import + wire from app/client code.
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-maps-leaflet",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Leaflet (OpenStreetMap) provider for @molecule/app-maps",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-maps-leaflet",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "dist/index.js",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
@@ -17,7 +18,8 @@
|
|
|
17
18
|
}
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
20
|
-
"dist"
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md"
|
|
21
23
|
],
|
|
22
24
|
"keywords": [
|
|
23
25
|
"molecule",
|
|
@@ -28,17 +30,18 @@
|
|
|
28
30
|
"license": "Apache-2.0",
|
|
29
31
|
"repository": {
|
|
30
32
|
"type": "git",
|
|
33
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
31
34
|
"directory": "packages/app/bonds/maps/leaflet"
|
|
32
35
|
},
|
|
33
36
|
"peerDependencies": {
|
|
34
|
-
"@molecule/app-maps": "^1.0.
|
|
37
|
+
"@molecule/app-maps": "^1.0.1"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
37
|
-
"@molecule/app-maps": "1.0.
|
|
40
|
+
"@molecule/app-maps": "1.0.2",
|
|
38
41
|
"@types/leaflet": "1.9.21",
|
|
39
42
|
"@types/node": "26.1.2",
|
|
40
43
|
"typescript": "6.0.3",
|
|
41
|
-
"vitest": "4.1.
|
|
44
|
+
"vitest": "4.1.11"
|
|
42
45
|
},
|
|
43
46
|
"dependencies": {
|
|
44
47
|
"leaflet": "1.9.4"
|