react-google-maps
Advanced tools
Changelog
4.6.0 (2015-11-22)
Before:
<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:
<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>
}
/>
We also suggest switching to callback based ref so that you'll get the component instance when it is mounted.
Before:
<GoogleMap containerProps={{
...this.props,
style: {
height: "100%",
},
}}
ref="map"
defaultZoom={3}
defaultCenter={{lat: -25.363882, lng: 131.044922}}
onClick={::this.handleMapClick}>
{this.state.markers.map((marker, index) => {
return (
<Marker
{...marker}
onRightclick={this.handleMarkerRightclick.bind(this, index)} />
);
})}
</GoogleMap>
After:
<GoogleMapLoader
containerElement={
<div
{...this.props}
style={{
height: "100%",
}}
/>
}
googleMapElement={
<GoogleMap
ref={(map) => console.log(map)}
defaultZoom={3}
defaultCenter={{lat: -25.363882, lng: 131.044922}}
onClick={::this.handleMapClick}>
{this.state.markers.map((marker, index) => {
return (
<Marker
{...marker}
onRightclick={this.handleMarkerRightclick.bind(this, index)} />
);
})}
</GoogleMap>
}
/>
<a name="4.5.1"></a>