react-googlemaps icon indicating copy to clipboard operation
react-googlemaps copied to clipboard

Cannot call getMapNode()

Open lpiepiora opened this issue 10 years ago • 4 comments

When created a map component like this:

var ReactGoogleMaps = require('react-googlemaps');
var Map = ReactGoogleMaps.Map;

<Map
        ref="myMap"
        initialZoom={15}
        initialCenter={new google.maps.LatLng(53.4335187, 14.5497363)}
      </Map>

In the parent component, that created it, I would like to do this.refs.myMap.getMapNode(). However this is not possible, because the ReactGoogleMaps.Map is not exposing such method.

My motivation is to centre the map after the component is rendered, in componentDidMount. I want to do it using map.panTo method of Google API.

lpiepiora avatar Nov 02 '14 18:11 lpiepiora

I had the same problem, try this: this.refs.myMap.refs.map.getMapNode().

MicheleBertoli avatar Dec 01 '14 14:12 MicheleBertoli

Thanks for a tip.

lpiepiora avatar Dec 01 '14 18:12 lpiepiora

Is that really the best way to get the map instance? It seems so brittle :confused:

aaronpowell avatar Jan 14 '15 04:01 aaronpowell

any status on this? would be nice to know best practice regarding getMapNode().

davidlashlee avatar Aug 14 '15 22:08 davidlashlee