@geolonia/maps-react 0.3.0 → 0.5.0
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 +15 -1
- package/dist/index.js +19 -9
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -71,6 +71,12 @@ Root component. Creates a Geolonia map instance and provides it to children via
|
|
|
71
71
|
| `minZoom` / `maxZoom` | `number` | Zoom range |
|
|
72
72
|
| `gestureHandling` | `boolean` | Gesture handling on scrollable pages |
|
|
73
73
|
| `loader` | `boolean` | Loading animation |
|
|
74
|
+
| `geojson` | `string \| FeatureCollection` | GeoJSON (or its URL) drawn with simplestyle. `<Map>` always passes a `center` (default `[0, 0]`), so the view is not fitted to the data: set `center` and `zoom` yourself |
|
|
75
|
+
| `cluster` | `boolean` | Cluster the point features of `geojson` (default `true`). Ignored when `heatmap` or `circle` is set: those never cluster |
|
|
76
|
+
| `clusterColor` | `string` | Color of the cluster markers |
|
|
77
|
+
| `choropleth` | `string \| ChoroplethOptions` | Color the polygons of `geojson` by a property value. A property name, or `{ property, colors?, range? }` |
|
|
78
|
+
| `heatmap` | `boolean \| string \| HeatmapOptions` | Draw the points of `geojson` as a heatmap. `true` for equal weight, a property name for its weight, or `{ weight?, colors? }` |
|
|
79
|
+
| `circle` | `CircleOptions` | Size and color the points of `geojson` by property values: `{ size?, color?, colors? }` |
|
|
74
80
|
| `3d` | `boolean` | Enable 3D mode |
|
|
75
81
|
| `className` | `string` | CSS class for the container |
|
|
76
82
|
| `containerStyle` | `CSSProperties` | Inline styles for the container |
|
|
@@ -80,6 +86,14 @@ Root component. Creates a Geolonia map instance and provides it to children via
|
|
|
80
86
|
|
|
81
87
|
`ControlPosition` = `'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'`
|
|
82
88
|
|
|
89
|
+
`geojson`, `cluster`, `clusterColor`, `choropleth`, `heatmap` and `circle` are read once when the map is created. Changing them afterwards has no effect, so remount `<Map>` with a `key` to change them. To update GeoJSON data on a live map, use `<Source>` and `<Layer>` below.
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
<Map apiKey="YOUR-API-KEY" center={[139.76, 35.68]} zoom={12} geojson={meshes} choropleth="population" />
|
|
93
|
+
<Map apiKey="YOUR-API-KEY" center={[139.76, 35.68]} zoom={12} geojson={spots} heatmap="weight" />
|
|
94
|
+
<Map apiKey="YOUR-API-KEY" center={[139.76, 35.68]} zoom={12} geojson={spots} circle={{ size: 'weight', color: 'category' }} />
|
|
95
|
+
```
|
|
96
|
+
|
|
83
97
|
### `<Marker>`
|
|
84
98
|
|
|
85
99
|
Displays a marker at the given coordinates. Children are rendered as a popup.
|
|
@@ -112,7 +126,7 @@ Displays a standalone popup at the given coordinates.
|
|
|
112
126
|
|------|------|-------------|
|
|
113
127
|
| `lat` | `number` | Latitude (required) |
|
|
114
128
|
| `lng` | `number` | Longitude (required) |
|
|
115
|
-
| `onClose` | `() => void` | Callback when popup
|
|
129
|
+
| `onClose` | `() => void` | Callback when the user closes the popup (close button, click on the map, or `closeOnMove`). Not called when the popup or the whole `<Map>` unmounts |
|
|
116
130
|
| `children` | `ReactNode` | Popup content |
|
|
117
131
|
|
|
118
132
|
### `<Source>` / `<Layer>`
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,12 @@ function useMaps() {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// src/components/control.tsx
|
|
26
|
+
function safeRemoveControl(map, ctrl) {
|
|
27
|
+
try {
|
|
28
|
+
if (map.hasControl(ctrl)) map.removeControl(ctrl);
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
26
32
|
function Control({
|
|
27
33
|
position = "top-right",
|
|
28
34
|
onAdd,
|
|
@@ -52,7 +58,7 @@ function Control({
|
|
|
52
58
|
};
|
|
53
59
|
map.addControl(control, position);
|
|
54
60
|
return () => {
|
|
55
|
-
map
|
|
61
|
+
safeRemoveControl(map, control);
|
|
56
62
|
};
|
|
57
63
|
}, [map]);
|
|
58
64
|
return container ? createPortal(children, container) : null;
|
|
@@ -79,12 +85,6 @@ function defined(obj) {
|
|
|
79
85
|
}
|
|
80
86
|
return out;
|
|
81
87
|
}
|
|
82
|
-
function safeRemoveControl(map, ctrl) {
|
|
83
|
-
try {
|
|
84
|
-
map.removeControl(ctrl);
|
|
85
|
-
} catch {
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
88
|
function NavigationControl2({
|
|
89
89
|
position = "top-right",
|
|
90
90
|
showCompass,
|
|
@@ -748,6 +748,11 @@ function Popup3(props) {
|
|
|
748
748
|
const onCloseRef = useRef4(onClose);
|
|
749
749
|
onCloseRef.current = onClose;
|
|
750
750
|
useEffect6(() => {
|
|
751
|
+
let mapRemoving = false;
|
|
752
|
+
const handleMapRemove = () => {
|
|
753
|
+
mapRemoving = true;
|
|
754
|
+
};
|
|
755
|
+
map.on("remove", handleMapRemove);
|
|
751
756
|
const popup = new maplibregl3.Popup(
|
|
752
757
|
defined2({
|
|
753
758
|
anchor,
|
|
@@ -759,10 +764,15 @@ function Popup3(props) {
|
|
|
759
764
|
className
|
|
760
765
|
})
|
|
761
766
|
).setLngLat([lng, lat]).setDOMContent(containerEl.current).addTo(map);
|
|
762
|
-
|
|
767
|
+
const handleClose = () => {
|
|
768
|
+
if (!mapRemoving) onCloseRef.current?.();
|
|
769
|
+
};
|
|
770
|
+
popup.on("close", handleClose);
|
|
763
771
|
popupRef.current = popup;
|
|
764
772
|
return () => {
|
|
765
|
-
|
|
773
|
+
map.off("remove", handleMapRemove);
|
|
774
|
+
popup.off("close", handleClose);
|
|
775
|
+
if (popup.isOpen()) popup.remove();
|
|
766
776
|
};
|
|
767
777
|
}, [map, anchor, closeButton, closeOnClick, closeOnMove]);
|
|
768
778
|
useEffect6(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geolonia/maps-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@geolonia/maps-core": "^0.
|
|
17
|
+
"@geolonia/maps-core": "^0.8.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"maplibre-gl": "^6.0.0",
|
|
@@ -22,20 +22,20 @@
|
|
|
22
22
|
"react-dom": ">=18"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@biomejs/biome": "^2.
|
|
26
|
-
"@playwright/test": "^1.
|
|
27
|
-
"@testing-library/react": "^16.3.
|
|
25
|
+
"@biomejs/biome": "^2.5.15",
|
|
26
|
+
"@playwright/test": "^1.63.0",
|
|
27
|
+
"@testing-library/react": "^16.3.3",
|
|
28
28
|
"@types/react": "^18",
|
|
29
29
|
"@types/react-dom": "^18",
|
|
30
|
-
"@vitejs/plugin-react": "^
|
|
31
|
-
"@vitest/coverage-v8": "^5.0.
|
|
32
|
-
"jsdom": "^
|
|
30
|
+
"@vitejs/plugin-react": "^6.1.2",
|
|
31
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
32
|
+
"jsdom": "^30.1.3",
|
|
33
33
|
"maplibre-gl": "6.11.2",
|
|
34
34
|
"react": "^18",
|
|
35
35
|
"react-dom": "^18",
|
|
36
36
|
"tsup": "^8",
|
|
37
37
|
"typescript": "^5.8",
|
|
38
|
-
"vite": "^
|
|
38
|
+
"vite": "^8.3.4",
|
|
39
39
|
"vitest": "^5.0.2"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|