mapping-component-package-jp 0.0.56 → 0.0.57
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/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
- package/src/components/JPMapComponentNew.tsx +92 -0
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mapping-component-package-jp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.57",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
|
-
"rollup": "rollup -c --bundleConfigAsCjs",
|
|
11
|
-
"build": "rollup -c --bundleConfigAsCjs",
|
|
10
|
+
"rollup": "npx rollup -c --bundleConfigAsCjs",
|
|
11
|
+
"build": "npx rollup -c --bundleConfigAsCjs",
|
|
12
12
|
"prepublishOnly": "npm run build",
|
|
13
13
|
"vp": "npm version patch",
|
|
14
14
|
"vm": "npm version minor",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"install": "^0.13.0",
|
|
27
27
|
"polylabel": "^2.0.1",
|
|
28
28
|
"polyline": "^0.2.0",
|
|
29
|
+
"postcss": "^8.5.6",
|
|
29
30
|
"react": "^18.3.1",
|
|
30
31
|
"tslib": "^2.7.0",
|
|
31
32
|
"typescript": "^5.6.3"
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
41
42
|
"@rollup/plugin-terser": "^0.4.4",
|
|
42
43
|
"@rollup/plugin-typescript": "^12.1.0",
|
|
44
|
+
"@vis.gl/react-google-maps": "^1.7.1",
|
|
43
45
|
"rollup-plugin-dts": "^6.1.1",
|
|
44
46
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
45
47
|
"rollup-plugin-postcss": "^4.0.2",
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React, { memo, useEffect } from "react";
|
|
2
|
+
// Import from the new modern library:
|
|
3
|
+
import { APIProvider, Map, useMap } from "@vis.gl/react-google-maps";
|
|
4
|
+
|
|
5
|
+
// Assuming useMapManager is compatible and imported correctly
|
|
6
|
+
import { useMapManager } from "../hooks/useMapManager";
|
|
7
|
+
|
|
8
|
+
const containerStyle = {
|
|
9
|
+
width: "100%",
|
|
10
|
+
height: "100%",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const center = {
|
|
14
|
+
lat: -25.7652061,
|
|
15
|
+
lng: 28.2710333,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const DISABLE_DEFAULT_UI = true;
|
|
19
|
+
const MAP_TYPE_ID = 'hybrid' as google.maps.MapTypeId;
|
|
20
|
+
const MAP_TYPE_CONTROL = true;
|
|
21
|
+
const ZOOM_CONTROL = true;
|
|
22
|
+
const MAP_ID = 'JP_DEMO_MAP';
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// Define the type that matches your existing expectation
|
|
26
|
+
export type jpMapType = {
|
|
27
|
+
isMapInitialized: boolean;
|
|
28
|
+
mapObject: google.maps.Map | null;
|
|
29
|
+
mapManager: any; // Type this more specifically if possible
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
interface JPMapComponentNewProps {
|
|
33
|
+
gmAPIkey: string;
|
|
34
|
+
// The callback to pass the initialized map data back up to the parent App
|
|
35
|
+
jpMap: (jpMap: jpMapType) => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// --- 1. The Handler Component: Gets Map context via Hook ---
|
|
40
|
+
// This component sits inside the <Map> component and uses the useMap hook
|
|
41
|
+
const MapHandlerComponent: React.FC<{ jpMap: JPMapComponentNewProps['jpMap'] }> = ({ jpMap }) => {
|
|
42
|
+
// Access the map instance using the hook provided by @vis.gl/react-google-maps
|
|
43
|
+
const mapInstance = useMap();
|
|
44
|
+
|
|
45
|
+
// Assuming useMapManager needs the map instance passed to it
|
|
46
|
+
const { mapManager } = useMapManager({ mapInstance });
|
|
47
|
+
|
|
48
|
+
// Use useEffect to trigger the parent callback once the map and manager are ready
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (mapInstance && mapManager) {
|
|
51
|
+
// Pass the necessary objects back to the parent component
|
|
52
|
+
jpMap({
|
|
53
|
+
isMapInitialized: true,
|
|
54
|
+
mapObject: mapInstance,
|
|
55
|
+
mapManager: mapManager,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Note: A cleanup function is optional here as the APIProvider handles cleanup
|
|
59
|
+
}, [mapInstance, mapManager, jpMap]);
|
|
60
|
+
|
|
61
|
+
// This component renders nothing visually
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// --- 2. The Main Map Component: Sets up Provider and Map ---
|
|
67
|
+
const JPMapComponentNew: React.FC<JPMapComponentNewProps> = ({ gmAPIkey, jpMap }) => {
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
// The APIProvider handles key, script loading, and libraries
|
|
71
|
+
<APIProvider
|
|
72
|
+
apiKey={gmAPIkey}
|
|
73
|
+
libraries={['places', 'marker', 'geometry']}
|
|
74
|
+
>
|
|
75
|
+
<Map
|
|
76
|
+
mapId={MAP_ID}
|
|
77
|
+
style={containerStyle}
|
|
78
|
+
center={center}
|
|
79
|
+
zoom={5}
|
|
80
|
+
disableDefaultUI={DISABLE_DEFAULT_UI}
|
|
81
|
+
mapTypeId={MAP_TYPE_ID}
|
|
82
|
+
mapTypeControl={MAP_TYPE_CONTROL}
|
|
83
|
+
zoomControl={ZOOM_CONTROL}
|
|
84
|
+
>
|
|
85
|
+
{/* Render the handler component inside the Map context */}
|
|
86
|
+
<MapHandlerComponent jpMap={jpMap} />
|
|
87
|
+
</Map>
|
|
88
|
+
</APIProvider>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export default memo(JPMapComponentNew);
|