MCPcopy
hub / github.com/visgl/react-google-maps / useMap

Function useMap

src/hooks/use-map.ts:12–37  ·  view source on GitHub ↗
(id: string | null = null)

Source from the content-addressed store, hash-verified

10 * Returns null if neither can be found.
11 */
12export const useMap = (id: string | null = null): google.maps.Map | null => {
13 const ctx = useContext(APIProviderContext);
14 const {map} = useContext(GoogleMapsContext) || {};
15
16 if (ctx === null) {
17 logErrorOnce(
18 'useMap(): failed to retrieve APIProviderContext. ' +
19 'Make sure that the <APIProvider> component exists and that the ' +
20 'component you are calling `useMap()` from is a sibling of the ' +
21 '<APIProvider>.'
22 );
23
24 return null;
25 }
26
27 const {mapInstances} = ctx;
28
29 // if an id is specified, the corresponding map or null is returned
30 if (id !== null) return mapInstances[id] || null;
31
32 // otherwise, return the closest ancestor
33 if (map) return map;
34
35 // finally, return the default map instance
36 return mapInstances['default'] || null;
37};

Callers 15

useMarkerFunction · 0.90
useRectangleFunction · 0.90
usePolylineFunction · 0.90
usePolygonFunction · 0.90
useCircleFunction · 0.90
InfoWindowFunction · 0.90
MapControlFunction · 0.90
useAdvancedMarkerFunction · 0.90
useMapViewportFunction · 0.90
use-map.test.tsxFile · 0.90
PolylineFunction · 0.90
MiniMapFunction · 0.85

Calls 1

logErrorOnceFunction · 0.90

Tested by

no test coverage detected