From 72f202f9df8b7a29300da5ee3e0788c802d48980 Mon Sep 17 00:00:00 2001 From: Matt Ross Date: Fri, 20 Nov 2015 09:14:15 -0800 Subject: [PATCH 1/2] Onload function that receives map as prop --- src/GoogleMap.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GoogleMap.js b/src/GoogleMap.js index 4665d3fc..053b1e4b 100644 --- a/src/GoogleMap.js +++ b/src/GoogleMap.js @@ -19,6 +19,7 @@ export default class GoogleMap extends Component { static propTypes = { containerTagName: PropTypes.string.isRequired, containerProps: PropTypes.object.isRequired, + onLoad: PropTypes.func, // Uncontrolled default[props] - used only in componentDidMount ...mapDefaultPropTypes, // Controlled [props] - used in componentDidMount/componentDidUpdate @@ -80,13 +81,14 @@ export default class GoogleMap extends Component { componentDidMount () { const domEl = findDOMNode(this); - const {containerTagName, containerProps, children, ...mapProps} = this.props; + const {containerTagName, containerProps, children, onLoad, ...mapProps} = this.props; // TODO: support asynchronous load of google.maps API at this level. // // Create google.maps.Map instance so that dom is initialized before // React's children creators. // const map = GoogleMapHolder._createMap(domEl, mapProps); + onLoad ? onLoad(map) : null this.setState({ map }); } From ee5bfe89bfebdd60bca94522752dfa756174d395 Mon Sep 17 00:00:00 2001 From: Matt Ross Date: Sat, 21 Nov 2015 13:55:26 -0800 Subject: [PATCH 2/2] update lib --- lib/GoogleMap.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/GoogleMap.js b/lib/GoogleMap.js index ff1f2108..2bb98002 100644 --- a/lib/GoogleMap.js +++ b/lib/GoogleMap.js @@ -134,8 +134,9 @@ var GoogleMap = (function (_Component) { var containerTagName = _props.containerTagName; var containerProps = _props.containerProps; var children = _props.children; + var onLoad = _props.onLoad; - var mapProps = _objectWithoutProperties(_props, ["containerTagName", "containerProps", "children"]); + var mapProps = _objectWithoutProperties(_props, ["containerTagName", "containerProps", "children", "onLoad"]); // TODO: support asynchronous load of google.maps API at this level. // @@ -143,6 +144,7 @@ var GoogleMap = (function (_Component) { // React's children creators. // var map = _creatorsGoogleMapHolder2["default"]._createMap(domEl, mapProps); + onLoad ? onLoad(map) : null; this.setState({ map: map }); } }, { @@ -178,7 +180,8 @@ var GoogleMap = (function (_Component) { key: "propTypes", value: _extends({ containerTagName: _react.PropTypes.string.isRequired, - containerProps: _react.PropTypes.object.isRequired + containerProps: _react.PropTypes.object.isRequired, + onLoad: _react.PropTypes.func }, _creatorsGoogleMapHolder.mapDefaultPropTypes, _creatorsGoogleMapHolder.mapControlledPropTypes, _creatorsGoogleMapHolder.mapEventPropTypes), enumerable: true }, {