-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(map): add support for new and missing mapOptions (#501)
- add support for colorScheme - add support for renderingType - add missing options to mapOptionKeys - update docs with new props - update tests for props that can't be changed after map creation
- Loading branch information
1 parent
f275735
commit f22af50
Showing
6 changed files
with
161 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/* eslint-disable complexity */ | ||
import React, { | ||
ComponentType, | ||
CSSProperties, | ||
PropsWithChildren, | ||
ReactNode, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,8 @@ export function useMapInstance( | |
defaultHeading, | ||
defaultTilt, | ||
reuseMaps, | ||
renderingType, | ||
colorScheme, | ||
|
||
...mapOptions | ||
} = props; | ||
|
@@ -114,8 +116,10 @@ export function useMapInstance( | |
|
||
const {addMapInstance, removeMapInstance} = context; | ||
|
||
const mapId = props.mapId; | ||
const cacheKey = mapId || 'default'; | ||
// note: colorScheme (upcoming feature) isn't yet in the typings, remove once that is fixed: | ||
const {mapId} = props; | ||
const cacheKey = `${mapId || 'default'}:${renderingType || 'default'}:${colorScheme || 'LIGHT'}`; | ||
|
||
let mapDiv: HTMLElement; | ||
let map: google.maps.Map; | ||
|
||
|
@@ -133,7 +137,15 @@ export function useMapInstance( | |
mapDiv = document.createElement('div'); | ||
mapDiv.style.height = '100%'; | ||
container.appendChild(mapDiv); | ||
map = new google.maps.Map(mapDiv, mapOptions); | ||
map = new google.maps.Map(mapDiv, { | ||
...mapOptions, | ||
renderingType: renderingType as google.maps.RenderingType, | ||
// The colorScheme option and google.maps.ColorScheme type haven't been added | ||
// to the @types/google.maps package yet, so this will cause a TS error: | ||
// @ts-expect-error TS2353: Object literal may only specify known properties, | ||
Check failure on line 145 in src/components/map/use-map-instance.ts GitHub Actions / test
|
||
// and colorScheme does not exist in type MapOptions | ||
colorScheme: colorScheme as google.maps.ColorScheme | ||
}); | ||
} | ||
|
||
setMap(map); | ||
|
@@ -186,7 +198,17 @@ export function useMapInstance( | |
// changes should be ignored | ||
// - mapOptions has special hooks that take care of updating the options | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[container, apiIsLoaded, id, props.mapId] | ||
[ | ||
container, | ||
apiIsLoaded, | ||
id, | ||
|
||
// these props can't be changed after initialization and require a new | ||
// instance to be created | ||
props.mapId, | ||
props.renderingType, | ||
props.colorScheme | ||
] | ||
); | ||
|
||
return [map, containerRef, cameraStateRef] as const; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters