Replies: 1 comment 1 reply
-
In your example, the function App() {
const [mapProps, setMapProps] = useState<MapCameraProps>(INITIAL_CAMERA);
const handleCameraChange = useCallback((ev: MapCameraChangedEvent) => {
console.log('camera changed', ev.detail);
setMapProps(ev.detail);
}, []);
const mapContent = useMemo(()=>(
<AdvancedMarker
position={{lat: 20, lng: 10}}
title={'AdvancedMarker with customized pin.'}
>
<Pin
background={'#22ccff'}
borderColor={'#1e89a1'}
glyphColor={'#0f677a'}></Pin>
</AdvancedMarker>
{/* ... */}
), []); // the dependencies here control when the content gets re-rendered
return (
<APIProvider apiKey={API_KEY} libraries={['marker']}>
<Map {...mapProps}>
{mapContent}
</Map>
</APIProvider>
);
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I've built a map using InfoWindow on AdvancedMarker, and I've used MapCameraProps because I have a select where the user can change the map center.
The problem is that when I have an InfoWindow open and I drag the map, MapCameraProps change, causing the re-rendering of all markers and the open InfoWindow.
I tried using MapCameraProps in your example as well, and I was able to replicate the problem.
There's another way to achieve the result without causing a re-render every time I drag the map?
Beta Was this translation helpful? Give feedback.
All reactions