-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapp.tsx
101 lines (89 loc) · 2.98 KB
/
app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React, {FunctionComponent, useState, useCallback} from 'react';
import {GoogleMapsProvider} from '@ubilabs/google-maps-react-hooks';
import MapCanvas from './components/map-canvas/map-canvas';
import {GOOGLE_MAPS_API_KEY} from '../constants';
import './main.module.css';
const basicMapOptions = {
zoom: 10,
disableDefaultUI: true,
zoomControl: true,
zoomControlOptions: {
position: 3 // Right top
}
};
// The Google Maps API parameters must be the same for all `GoogleMapsProvider` components!
const googleMapsAPIParameters = {
googleMapsAPIKey: GOOGLE_MAPS_API_KEY,
language: 'it',
region: 'IT'
};
const App: FunctionComponent<Record<string, unknown>> = () => {
const [hamburgMapContainer, setHamburgMapContainer] =
useState<HTMLDivElement | null>(null);
const hamburgMapRef = useCallback(
(node: React.SetStateAction<HTMLDivElement | null>) => {
node && setHamburgMapContainer(node);
},
[]
);
const hamburgMapOptions = {
...basicMapOptions,
center: {lat: 53.551086, lng: 9.993682}
};
const [munichMapContainer, setMunichMapContainer] =
useState<HTMLDivElement | null>(null);
const munichMapRef = useCallback(
(node: React.SetStateAction<HTMLDivElement | null>) => {
node && setMunichMapContainer(node);
},
[]
);
const munichMapOptions = {
...basicMapOptions,
center: {lat: 48.137154, lng: 11.576124}
};
const [sanFranciscoMapContainer, setSanFranciscoMapContainer] =
useState<HTMLDivElement | null>(null);
const sanFranciscoMapRef = useCallback(
(node: React.SetStateAction<HTMLDivElement | null>) => {
node && setSanFranciscoMapContainer(node);
},
[]
);
const sanFranciscoMapOptions = {
...basicMapOptions,
center: {lat: 37.773972, lng: -122.431297}
};
return (
<div id="grid">
<GoogleMapsProvider
mapContainer={hamburgMapContainer}
mapOptions={hamburgMapOptions}
{...googleMapsAPIParameters}>
<React.StrictMode>
<MapCanvas ref={hamburgMapRef} />
{/** The `useGoogleMap()` hook called inside this provider will return the map showing Hamburg. */}
</React.StrictMode>
</GoogleMapsProvider>
<GoogleMapsProvider
mapContainer={munichMapContainer}
mapOptions={munichMapOptions}
{...googleMapsAPIParameters}>
<React.StrictMode>
<MapCanvas ref={munichMapRef} />
{/** The `useGoogleMap()` hook called inside this provider will return the map showing Munich. */}
</React.StrictMode>
</GoogleMapsProvider>
<GoogleMapsProvider
mapContainer={sanFranciscoMapContainer}
mapOptions={sanFranciscoMapOptions}
{...googleMapsAPIParameters}>
<React.StrictMode>
<MapCanvas ref={sanFranciscoMapRef} />
{/** The `useGoogleMap()` hook called inside this provider will return the map showing San Francisco. */}
</React.StrictMode>
</GoogleMapsProvider>
</div>
);
};
export default App;