-
Notifications
You must be signed in to change notification settings - Fork 936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GoogleMap public api - no methods work #133
Comments
I think it works on the Code: react-google-maps/examples/gh-pages/scripts/components/GeojsonToComponents.js Lines 74 to 101 in 67895ab
Demo: https://tomchentw.github.io/react-google-maps/#geojson |
Here's the code I'm using: I tried cloning the repo to set up the gh-pages and see if it worked locally, but none of the pages will load. |
So you can't load The gist looks okay though. However, in componentDidUpdate, could you try to call |
Same error. The line highlighted is this here:
I'm running node 4.1.2 and npm 2.14.4 |
Did you load google.mas script before React?
|
Yes. I should mention the rest of the map stuff is working great, it's just these couple exposed methods that don't work. |
It's really weird. I updated the |
Ok I did some more testing and I was able to reproduce what is causing the problem. In your examples, the map is loaded as soon as the component is mounted. If something prevents the component from mounting immediately (i.e. I load data and show a spinner gif before the map is shown on the page), something in the GoogleMap state is not bound I created a repo so you can see how this happens: Do you have any suggestions to work around this? |
I tried to update the componentDidUpdate() {
if (this.refs.map) {
console.log('Zoom level:', this.refs.map.getZoom());
}
} But it doesn't work. Still the error of |
@Dyyylan I had a workaround here: https://github.com/dyyylan/map-error/compare/master...tomchentw:master |
@tomchentw I'm having exact same problem but I cannot view your workaround you posted. |
@Dyyylan @tomchentw , Can you change the value of 'ref' attribute in the component render block ?
Please let me know the result. |
Sorry, I cleaned up some repositories I wasn't using and deleted my fork of this project. @PanJ, the workaround was to just create a wrapper component for the map. Whichever component the map is in, it must render when the component mounts, or you won't get the api exposed. That was the cause of my issue |
I'm having this problem too after upgrading to newer version.
|
A reproducible jsfiddle would be appreciated! @beeant |
@tomchentw sorry, it works after I moved options to |
* Ref #92 BREAKING CHANGE: ScriptjsLoader will delegate to GoogleMapLoader when the script is loaded Before: ```js <ScriptjsLoader hostname={"maps.googleapis.com"} pathname={"/maps/api/js"} query={{v: `3.${ AsyncGettingStarted.version }`, libraries: "geometry,drawing,places"}} loadingElement={ <div {...this.props} style={{ height: "100%" }}> <FaSpinner /> </div> } googleMapElement={ <GoogleMap containerProps={{ ...this.props, style: { height: "100%", }, }} ref={googleMap => { // Wait until GoogleMap is fully loaded. Related to #133 setTimeout(() => { googleMap && console.log(`Zoom: ${ googleMap.getZoom() }`); }, 50); }} defaultZoom={3} defaultCenter={{lat: -25.363882, lng: 131.044922}} onClick={::this.handleMapClick} > <Marker {...this.state.marker} onRightclick={this.handleMarkerRightclick} /> </GoogleMap> } /> ``` After: ```js <ScriptjsLoader hostname={"maps.googleapis.com"} pathname={"/maps/api/js"} query={{v: `3.${ AsyncGettingStarted.version }`, libraries: "geometry,drawing,places"}} loadingElement={ <div {...this.props} style={{ height: "100%" }}> <FaSpinner /> </div> } containerElement={ <div {...this.props} style={{ height: "100%" }} /> } googleMapElement={ <GoogleMap ref={googleMap => { googleMap && console.log(`Zoom: ${ googleMap.getZoom() }`); }} defaultZoom={3} defaultCenter={{lat: -25.363882, lng: 131.044922}} onClick={::this.handleMapClick} > <Marker {...this.state.marker} onRightclick={this.handleMarkerRightclick} /> </GoogleMap> } /> ```
Separating |
Released v4.6.0 |
I'm having an issue accessing any of the methods that should be exposed on the GoogleMap component.
In any of these methods,
this.state
is undefined:react-google-maps/src/GoogleMap.js
Lines 32 to 65 in 0e41701
The text was updated successfully, but these errors were encountered: