Skip to content

Commit 1cef9a0

Browse files
authored
Merge pull request #69 from ubilabs/feat/add-max-zoom-hook
Feat/add max zoom hook
2 parents 97c5940 + adce25b commit 1cef9a0

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,49 @@ const MyComponent = () => {
501501
};
502502
```
503503
504+
#### Return value
505+
504506
Returns the [`DistanceMatrixService`](google.maps.DistanceMatrixService) class to use directly.
505507
506508
```TypeScript
507509
google.maps.DistanceMatrixService
508510
```
509511
512+
### useMaxZoomService
513+
514+
React hook to use the [Maximum Zoom Imagery Service](https://developers.google.com/maps/documentation/javascript/maxzoom) in any component.
515+
516+
#### Usage
517+
518+
```tsx
519+
import React, {useEffect} from 'react';
520+
import {useMaxZoomService} from '@ubilabs/google-maps-react-hooks';
521+
522+
const MyComponent = () => {
523+
const maxZoomService = useMaxZoomService();
524+
const location = /** google.maps.LatLng */;
525+
526+
useEffect(() => {
527+
maxZoomService?.getMaxZoomAtLatLng(
528+
location,
529+
(result: google.maps.MaxZoomResult) => {
530+
// Do something with result
531+
}
532+
);
533+
}, [location]);
534+
535+
return (...);
536+
};
537+
```
538+
539+
#### Return value
540+
541+
Returns the [`MaxZoomService`](google.maps.places.MaxZoomService) class to use directly.
542+
543+
```TypeScript
544+
google.maps.places.MaxZoomService
545+
```
546+
510547
### useElevationService
511548
512549
React hook to use the [Elevation Service](https://developers.google.com/maps/documentation/javascript/elevation) in any component.
@@ -529,6 +566,9 @@ const MyComponent = () => {
529566
}
530567
);
531568
}, [location]);
569+
570+
return (...);
571+
};
532572
```
533573
534574
#### Return value
@@ -539,7 +579,6 @@ Returns the [`ElevationService`](google.maps.places.ElevationService) class to u
539579
google.maps.places.ElevationService
540580
```
541581
542-
543582
## Publish (only for maintainers)
544583
545584
`npm publish --access public`

src/hooks/max-zoom.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {useMemo} from 'react';
2+
3+
import useGoogleMap from './map-instance';
4+
5+
/**
6+
* Hook to get Max Zoom Service instance
7+
*/
8+
const useMaxZoomService = (): google.maps.MaxZoomService | null => {
9+
const {map} = useGoogleMap();
10+
11+
// Creates a Max Zoom Service instance
12+
const maxZoomService =
13+
useMemo<google.maps.MaxZoomService | null>(() => {
14+
// Wait for map to be initialized
15+
if (!map) {
16+
return null;
17+
}
18+
19+
return new google.maps.MaxZoomService();
20+
}, [map]);
21+
22+
return maxZoomService;
23+
};
24+
25+
export default useMaxZoomService;

0 commit comments

Comments
 (0)