@vinctus/react-maplibre 0.1.4 → 0.2.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/dist/Map.d.ts +1 -3
- package/dist/Map.js +32 -57
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +8 -11
package/dist/Map.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare const viewStateFromMap: (map: maplibre.Map) => {
|
|
|
19
19
|
};
|
|
20
20
|
export declare const useMap: () => {
|
|
21
21
|
map: maplibre.Map | null;
|
|
22
|
-
|
|
22
|
+
setMap: React.Dispatch<React.SetStateAction<maplibre.Map | null>>;
|
|
23
23
|
mapLoaded: boolean;
|
|
24
24
|
setMapLoaded: React.Dispatch<React.SetStateAction<boolean>>;
|
|
25
25
|
};
|
|
@@ -27,7 +27,6 @@ export declare const MapProvider: FC<{
|
|
|
27
27
|
children?: ReactNode;
|
|
28
28
|
}>;
|
|
29
29
|
export type MapProps = {
|
|
30
|
-
reuseMaps?: boolean;
|
|
31
30
|
accessToken?: string;
|
|
32
31
|
antialias?: boolean;
|
|
33
32
|
children?: ReactNode | ReactNode[];
|
|
@@ -45,6 +44,5 @@ export type MapProps = {
|
|
|
45
44
|
ref?: RefAttributes<maplibre.Map | null>;
|
|
46
45
|
style?: CSSProperties;
|
|
47
46
|
zoom: number;
|
|
48
|
-
options?: any;
|
|
49
47
|
};
|
|
50
48
|
export declare const Map: React.ForwardRefExoticComponent<Omit<MapProps, "ref"> & React.RefAttributes<maplibre.Map | null>>;
|
package/dist/Map.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
13
|
import React, { useRef, useEffect, useState, useContext, useImperativeHandle, useMemo, } from 'react';
|
|
3
14
|
import maplibre from 'maplibre-gl';
|
|
@@ -5,7 +16,10 @@ import { ErrorBoundary } from './ErrorBoundary'; // eslint-disable-line import/n
|
|
|
5
16
|
const DEFAULT_STYLE = 'https://demotiles.maplibre.org/style.json';
|
|
6
17
|
const DISABLE_PITCH = 0;
|
|
7
18
|
const MapContext = React.createContext({
|
|
8
|
-
|
|
19
|
+
map: null,
|
|
20
|
+
setMap: () => {
|
|
21
|
+
throw new Error('Use <MapProvider>');
|
|
22
|
+
},
|
|
9
23
|
mapLoaded: false,
|
|
10
24
|
setMapLoaded: () => {
|
|
11
25
|
throw new Error('Use <MapProvider>');
|
|
@@ -16,92 +30,53 @@ export const viewStateFromMap = (map) => ({
|
|
|
16
30
|
latitude: map.getCenter().lat,
|
|
17
31
|
zoom: map.getZoom(),
|
|
18
32
|
});
|
|
19
|
-
export const useMap = () =>
|
|
20
|
-
const context = useContext(MapContext);
|
|
21
|
-
if (!context) {
|
|
22
|
-
throw new Error('useMap must be used within a MapProvider');
|
|
23
|
-
}
|
|
24
|
-
const { mapRef, mapLoaded, setMapLoaded } = context;
|
|
25
|
-
return {
|
|
26
|
-
map: mapRef.current,
|
|
27
|
-
mapRef,
|
|
28
|
-
mapLoaded,
|
|
29
|
-
setMapLoaded,
|
|
30
|
-
};
|
|
31
|
-
};
|
|
33
|
+
export const useMap = () => useContext(MapContext);
|
|
32
34
|
export const MapProvider = ({ children }) => {
|
|
33
|
-
const
|
|
35
|
+
const [map, setMap] = useState(null);
|
|
34
36
|
const [mapLoaded, setMapLoaded] = useState(false);
|
|
35
|
-
return (_jsx(MapContext.Provider,
|
|
37
|
+
return (_jsx(MapContext.Provider, { value: { map, setMap, mapLoaded, setMapLoaded }, children: children }));
|
|
36
38
|
};
|
|
37
39
|
function addEventHandler(map, type, handler) {
|
|
38
40
|
map.on(type, (ev) => handler(Object.assign({ viewState: viewStateFromMap(map) }, ev)));
|
|
39
41
|
}
|
|
40
|
-
export const Map = React.forwardRef((
|
|
42
|
+
export const Map = React.forwardRef((_a, ref) => {
|
|
43
|
+
var { children, style, id, longitude, latitude, maxPitch = DISABLE_PITCH, mapStyle = DEFAULT_STYLE, zoom, onDragEnd, onLoad, onMoveEnd, onZoomEnd, fallback } = _a, options = __rest(_a, ["children", "style", "id", "longitude", "latitude", "maxPitch", "mapStyle", "zoom", "onDragEnd", "onLoad", "onMoveEnd", "onZoomEnd", "fallback"]);
|
|
41
44
|
const mapContainer = useRef(null);
|
|
42
|
-
const {
|
|
43
|
-
useImperativeHandle(ref, () =>
|
|
44
|
-
mapRef,
|
|
45
|
-
]);
|
|
45
|
+
const { map, setMap, setMapLoaded } = useMap();
|
|
46
|
+
useImperativeHandle(ref, () => map, [map]);
|
|
46
47
|
useEffect(() => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
mapRef.current.resize(); // resize map in case container dimensions have changed
|
|
52
|
-
}
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (!reuseMaps || (mapContainer.current && !mapRef.current)) {
|
|
48
|
+
console.log('Map useEffect running', { map, mapContainer: mapContainer.current });
|
|
49
|
+
if (map)
|
|
50
|
+
return; // initialize map only once
|
|
51
|
+
if (mapContainer.current) {
|
|
56
52
|
const m = new maplibre.Map(Object.assign({ container: mapContainer.current, style: mapStyle, center: [longitude, latitude], zoom }, options));
|
|
57
53
|
if (onDragEnd)
|
|
58
54
|
addEventHandler(m, 'dragend', onDragEnd);
|
|
59
55
|
if (onLoad)
|
|
60
56
|
addEventHandler(m, 'load', (ev) => {
|
|
61
57
|
onLoad(ev);
|
|
62
|
-
|
|
63
|
-
setMapLoaded(true);
|
|
58
|
+
setMapLoaded(true);
|
|
64
59
|
});
|
|
65
60
|
if (onMoveEnd)
|
|
66
61
|
addEventHandler(m, 'moveend', onMoveEnd);
|
|
67
62
|
if (onZoomEnd)
|
|
68
63
|
addEventHandler(m, 'zoomend', onZoomEnd);
|
|
69
|
-
|
|
64
|
+
setMap(m);
|
|
70
65
|
}
|
|
71
|
-
// further investigation: calling .remove() causes the following error:
|
|
72
|
-
//
|
|
73
|
-
// Cannot read properties of undefined (reading 'off')
|
|
74
|
-
// TypeError: Cannot read properties of undefined (reading 'off')
|
|
75
|
-
// at t.GeolocateControl.onRemove (http://localhost:3002/static/js/bundle.js:107201:393)
|
|
76
|
-
// at t.Map.removeControl (http://localhost:3002/static/js/bundle.js:107351:57)
|
|
77
|
-
// at http://localhost:3002/static/js/bundle.js:853:53
|
|
78
|
-
// at safelyCallDestroy (http://localhost:3002/static/js/bundle.js:39324:9)
|
|
79
|
-
// at commitHookEffectListUnmount (http://localhost:3002/static/js/bundle.js:39462:15)
|
|
80
|
-
// at commitPassiveUnmountInsideDeletedTreeOnFiber (http://localhost:3002/static/js/bundle.js:41143:15)
|
|
81
|
-
// at commitPassiveUnmountEffectsInsideOfDeletedTree_begin (http://localhost:3002/static/js/bundle.js:41099:9)
|
|
82
|
-
// at commitPassiveUnmountEffects_begin (http://localhost:3002/static/js/bundle.js:41021:15)
|
|
83
|
-
// at commitPassiveUnmountEffects (http://localhost:3002/static/js/bundle.js:41009:7)
|
|
84
|
-
// at flushPassiveEffectsImpl (http://localhost:3002/static/js/bundle.js:42830:7)
|
|
85
|
-
//
|
|
86
|
-
// return () => {
|
|
87
|
-
// if (!reuseMaps && mapRef.current) {
|
|
88
|
-
// mapRef.current.remove()
|
|
89
|
-
// mapRef.current = null
|
|
90
|
-
// }
|
|
91
|
-
// }
|
|
92
66
|
}, [
|
|
93
|
-
|
|
67
|
+
map,
|
|
94
68
|
onDragEnd,
|
|
95
69
|
onLoad,
|
|
96
70
|
onMoveEnd,
|
|
97
71
|
onZoomEnd,
|
|
72
|
+
setMap,
|
|
98
73
|
setMapLoaded,
|
|
99
74
|
mapStyle,
|
|
100
75
|
longitude,
|
|
101
76
|
latitude,
|
|
102
77
|
zoom,
|
|
103
|
-
|
|
78
|
+
options,
|
|
104
79
|
]);
|
|
105
80
|
const memoizedStyle = useMemo(() => (Object.assign({ position: 'relative', width: '100%', height: '100%' }, style)), [style]);
|
|
106
|
-
return (_jsx(ErrorBoundary,
|
|
81
|
+
return (_jsx(ErrorBoundary, { fallback: fallback, children: _jsx("div", { id: id, ref: mapContainer, style: memoizedStyle, children: children }) }));
|
|
107
82
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/ErrorBoundary.tsx","../src/GeolocateControl.tsx","../src/Layer.tsx","../src/Map.tsx","../src/Marker.tsx","../src/Popup.tsx","../src/ScaleControl.tsx","../src/index.tsx","../src/types.tsx"],"version":"5.7.2"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vinctus/react-maplibre",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Minimalist MapLibre GL JS React wrapper library",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"types": "dist/index.d.ts",
|
|
6
7
|
"publishConfig": {
|
|
7
8
|
"access": "public"
|
|
@@ -13,25 +14,21 @@
|
|
|
13
14
|
".": "./dist/index.js",
|
|
14
15
|
"./dist/*": "./dist/*.js"
|
|
15
16
|
},
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"react-scripts": "5.0.1"
|
|
18
|
-
},
|
|
19
17
|
"peerDependencies": {
|
|
20
|
-
"maplibre-gl": "^4.
|
|
18
|
+
"maplibre-gl": "^4.7.1",
|
|
21
19
|
"react": "^18.3.1",
|
|
22
20
|
"react-dom": "^18.3.1"
|
|
23
21
|
},
|
|
24
22
|
"devDependencies": {
|
|
25
|
-
"@types/node": "^
|
|
23
|
+
"@types/node": "^22.10.2",
|
|
26
24
|
"@types/react": "^18.3.3",
|
|
27
25
|
"@types/react-dom": "^18.3.0",
|
|
28
|
-
"typescript": "^
|
|
26
|
+
"typescript": "^5.7.2",
|
|
27
|
+
"vite": "^6.0.3"
|
|
29
28
|
},
|
|
30
29
|
"scripts": {
|
|
31
|
-
"
|
|
32
|
-
"build": "
|
|
33
|
-
"test": "react-scripts test",
|
|
34
|
-
"eject": "react-scripts eject",
|
|
30
|
+
"dev": "vite",
|
|
31
|
+
"build": "tsc -b && vite build",
|
|
35
32
|
"prepublishOnly": "tsc"
|
|
36
33
|
},
|
|
37
34
|
"eslintConfig": {
|