Skip to content

Commit 6d898f5

Browse files
authored
Merge pull request #52 from ubilabs/feat/update-properties-readme
refactor(readme): update and sort properties section
2 parents 0c97f36 + 571bcc7 commit 6d898f5

File tree

1 file changed

+177
-18
lines changed

1 file changed

+177
-18
lines changed

README.md

Lines changed: 177 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,39 +98,198 @@ Component to wrap around the code where the map should be available.
9898

9999
### Properties
100100

101+
Properties that can be passed to the `GoogleMapsProvider` that are either the container to hold the map instance or [Maps JavaScript API URL Parameters](https://developers.google.com/maps/documentation/javascript/url-params).
102+
101103
```TypeScript
102104
interface GoogleMapProviderProps {
103-
children: React.ReactElement;
105+
googleMapsAPIKey: string;
106+
mapContainer?: HTMLElement | null;
107+
options?: google.maps.MapOptions;
108+
libraries?: string[];
109+
language?: string;
110+
region?: string;
111+
version?: string;
112+
authReferrerPolicy?: string;
113+
onLoad?: (map: google.maps.Map) => void;
114+
}
115+
```
116+
- - - -
117+
__googleMapsAPIKey__ (_compulsary property_)
104118

105-
// The Google Maps API Key
119+
The Google Maps JavaScript API Key.
120+
```Typescript
106121
googleMapsAPIKey: string;
122+
```
107123

108-
// A reference to the component that displays the map
109-
mapContainer?: HTMLElement | null;
124+
See: [Use API Key](https://developers.google.com/maps/documentation/embed/get-api-key)
110125

111-
// The Google Maps MapOptions, see: https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions
112-
options?: google.maps.MapOptions;
126+
- - - -
113127

114-
// Additional Google Maps libraries to load ('drawing', 'geometry', 'places' or 'visualization'), see: https://developers.google.com/maps/documentation/javascript/libraries
115-
libraries?: string[];
128+
__mapContainer__ (_optional property_)
116129

117-
// By default Google Maps will use the preferred language from the browser setting. This is the property to set it manually, see: https://developers.google.com/maps/documentation/javascript/localization
118-
language?: string;
130+
A reference to the HTML element that displays the map.
131+
Without the mapContainer provided, no visual map will be displayed.
119132

120-
// By default Google Maps will use the preferred region from the browser setting. This is the property to set it manually, see: https://developers.google.com/maps/documentation/javascript/localization
121-
region?: string;
133+
```Typescript
134+
mapContainer?: HTMLElement | null;
135+
```
122136

123-
// Use this parameter to specify a version, see: https://developers.google.com/maps/documentation/javascript/versions
124-
version?: string;
137+
_Example:_
125138

126-
// Use this parameter to set auth_referrer_policy=origin when an URL on the same origin uses the API Key, to limit the amount of data sent when authorizing requests, see "auth_referrer_policy": https://developers.google.com/maps/documentation/javascript/url-params
127-
authReferrerPolicy?: string;
139+
The mapContainer will be passed to the `mapProvider` and `mapCanvas component` in the following way:
128140

129-
// A callback function that is called, when the map is loaded.
130-
onLoad?: (map: google.maps.Map) => void;
141+
```TypeScript
142+
function App() {
143+
const [mapContainer, setMapContainer] = useState(null);
144+
145+
const mapRef = useCallback((node) => {
146+
node && setMapContainer(node);
147+
}, []);
148+
149+
return (
150+
<GoogleMapProvider
151+
googleMapsAPIKey="my Google Maps API key"
152+
mapContainer={mapContainer}
153+
>
154+
<React.StrictMode>
155+
<MapCanvas ref={mapRef} />
156+
</React.StrictMode>
157+
</GoogleMapProvider>
158+
);
131159
}
132160
```
133161

162+
See: [Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/overview)
163+
164+
- - - -
165+
166+
__options__ (_optional property_)
167+
168+
The Google Maps MapOptions.
169+
170+
```Typescript
171+
options?: google.maps.MapOptions;
172+
```
173+
174+
_Example:_
175+
176+
```Typescript
177+
const mapOptions = {
178+
center: {lat: 53.5582447, lng: 9.647645},
179+
zoom: 6,
180+
disableDefaultUI: true,
181+
};
182+
```
183+
184+
See: [MapOptions](https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions)
185+
186+
**NOTE**: If the `mapOptions` are not provided here, the map will not be displayed until they are set.
187+
188+
_Example:_
189+
190+
MapOptions can be set later in another component in the following way:
191+
192+
```Typescript
193+
import {useGoogleMap} from '@ubilabs/google-maps-react-hooks';
194+
195+
const mapOptions = {
196+
center: {lat: 53.5582447, lng: 9.647645},
197+
zoom: 6,
198+
disableDefaultUI: true,
199+
zoomControl: true,
200+
zoomControlOptions: {
201+
position: 3 // Right top
202+
}
203+
};
204+
205+
const {map} = useGoogleMap();
206+
207+
map?.setOptions(mapOptions);
208+
```
209+
210+
- - - -
211+
212+
__libraries__ (_optional property_)
213+
214+
Additional Google Maps libraries to load ('drawing', 'geometry', 'places' or 'visualization').
215+
216+
```Typescript
217+
libraries?: string[];
218+
```
219+
220+
See: [Libraries](https://developers.google.com/maps/documentation/javascript/libraries)
221+
222+
- - - -
223+
224+
__languages__ (_optional property_)
225+
226+
By default Google Maps will use the preferred region from the browser setting. This is the property to set it manually.
227+
228+
```Typescript
229+
language?: string;
230+
```
231+
232+
See: [Localization](https://developers.google.com/maps/documentation/javascript/localization)
233+
234+
- - - -
235+
236+
__region__ (_optional property_)
237+
238+
By default Google Maps will use the preferred region from the browser setting. This is the property to set it manually.
239+
240+
```Typescript
241+
region?: string;
242+
```
243+
244+
See: [Localization](https://developers.google.com/maps/documentation/javascript/localization)
245+
246+
- - - -
247+
248+
__version__ (_optional property_)
249+
250+
Use this parameter to specify a version.
251+
252+
```Typescript
253+
version?: string;
254+
```
255+
256+
See: [Versions](https://developers.google.com/maps/documentation/javascript/versions)
257+
258+
- - - -
259+
260+
__authReferrerPolicy__ (_optional property_)
261+
262+
Use this parameter to set auth_referrer_policy=origin when an URL on the same origin uses the API Key, to limit the amount of data sent when authorizing requests.
263+
264+
```Typescript
265+
authReferrerPolicy?: string;
266+
```
267+
268+
See: [auth_referrer_policy](https://developers.google.com/maps/documentation/javascript/url-params)
269+
270+
- - - -
271+
272+
__onLoad__ (_optional property_)
273+
274+
A callback function that is called, when the map is loaded.
275+
276+
```Typescript
277+
onLoad?: (map: google.maps.Map) => void;
278+
```
279+
280+
_Example:_
281+
282+
```Typescript
283+
<GoogleMapProvider
284+
googleMapsAPIKey="my Google Maps API key"
285+
onLoad={(map) => map.setZoom(4)}
286+
>
287+
...
288+
</GoogleMapProvider>
289+
```
290+
291+
- - - -
292+
134293
## Hooks
135294

136295
### useGoogleMap

0 commit comments

Comments
 (0)