google-map-react icon indicating copy to clipboard operation
google-map-react copied to clipboard

export map & maps objects from 'google-map-react'

Open naazim opened this issue 4 years ago • 2 comments

Once again, thanks a lot for the amazing efforts and helping the community.

We've been using this library in our project for more than a year. Since we have more than 10000 markers. we paint the markers externally using map & maps objects via canvas, and assign them the events. (Since adding these markers as react components slows down the performance for large amount of markers).

And the main problem, to have access to map and maps objects, we're having to store these in global states. I see that maps is available in window.google.maps, but not map. Would have been great if both map & maps were accessible in a global context - either from window.google.x, or as imports from the library, instead of users having to extract the objects from onGoogleApiLoaded and spread globally

naazim avatar Mar 04 '21 14:03 naazim

+1 on this. I'm trying to use google-map-react with use-places-autocomplete. use-places-autocomplete takes a Google Maps object. It makes sense for this library to do that as well, so we can choose to load the API in whichever way we'd like.

Qrtn avatar Mar 07 '21 00:03 Qrtn

Set a state in apiLoaded function and pass the map to the autocomplete such as


onGoogleApiLoaded={({ map, maps }) => handleApiLoaded(map, maps)}

const handleApiLoaded = (map, maps) => {
    setConfig({
      mapApiLoaded: true,
      mapInstance: map,
      mapApi: maps,
    })
  }


...
... Later in render
...


 {config.mapApiLoaded && (
  <AutoComplete
    map={config.mapInstance}
    api={config.mapApi}
  />
)}

``

gokhandemirhan avatar Mar 19 '21 17:03 gokhandemirhan