tomchentw / react-google-maps

React.js Google Maps integration component
https://tomchentw.github.io/react-google-maps/
MIT License
4.62k stars 939 forks source link

react google map zoom_changed event #963

Open qaqnass opened 5 years ago

qaqnass commented 5 years ago

I want to hide and present something else while the map has zoom in or out. please, would you mind to let me know how can I add zoom_changed to the map?

remi95 commented 5 years ago

You can use the onZoomChanged property to handle this, and get the zoom value with getZoom().

...
const [map, setMap] = useState(null);
const [zoomValue, setZoomValue] = useState(10);

<GoogleMap
  defaultZoom={10}
  defaultCenter={{ lat: xx.xxxxx, lng: -x.xxxxx }}
  ref={googleMap => setMap(googleMap)}
  onZoomChanged={() => setZoom(map.getZoom())}
>
  ...
</GoogleMap>
...