Skip to content
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

feat(Declarative Bounds) specify map bounds via props #64

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions lib/GoogleMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ var _internalsEventComponent = require("./internals/EventComponent");

var _internalsEventComponent2 = _interopRequireDefault(_internalsEventComponent);

/*eslint-disable no-unused-vars */

var _internalsVirtualContainer = require("./internals/VirtualContainer");

var _internalsVirtualContainer2 = _interopRequireDefault(_internalsVirtualContainer);

/*eslint-enable no-unused-vars */

var _internalsExposeGetters = require("./internals/exposeGetters");

var _internalsExposeGetters2 = _interopRequireDefault(_internalsExposeGetters);
Expand Down Expand Up @@ -107,15 +111,21 @@ var GoogleMaps = (function (_EventComponent) {
return;
}
// googleMapsApi can be async loaded
/*eslint-disable no-unused-vars */
var containerProps = props.containerProps;
var googleMapsApi = props.googleMapsApi;
var key = props.key;
var ref = props.ref;
var bounds = props.bounds;

var googleMapsConfig = _objectWithoutProperties(props, ["containerProps", "googleMapsApi", "key", "ref"]);
var googleMapsConfig = _objectWithoutProperties(props, ["containerProps", "googleMapsApi", "bounds"]);

/*eslint-enable no-unused-vars */
var instance = this.state.instance;

if (bounds) {
delete googleMapsConfig.zoom;
delete googleMapsConfig.center;
}

if (instance) {
instance.setOptions(googleMapsConfig);
} else {
Expand All @@ -125,6 +135,11 @@ var GoogleMaps = (function (_EventComponent) {

this.setState({ instance: instance });
}

if (bounds) {
instance.fitBounds(bounds);
}

return instance;
}
}, {
Expand Down Expand Up @@ -178,7 +193,9 @@ var GoogleMaps = (function (_EventComponent) {
})(_internalsEventComponent2["default"]);

GoogleMaps.propTypes = _extends({}, _internalsEventComponent2["default"].propTypes, {
containerProps: PropTypes.object.isRequired });
containerProps: PropTypes.object.isRequired,
bounds: _react2["default"].PropTypes.object
});

GoogleMaps._registerEvents = (0, _internalsCreateRegisterEvents2["default"])("bounds_changed center_changed click dblclick drag dragend dragstart heading_changed idle maptypeid_changed mousemove mouseout mouseover projection_changed resize rightclick tilesloaded tilt_changed zoom_changed");

Expand Down
7 changes: 4 additions & 3 deletions lib/addons/InfoBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ var InfoBox = (function (_SimpleChildComponent) {
key: "_createOrUpdateInstance",
value: function _createOrUpdateInstance() {
var props = this.props;
var key = props.key;
var ref = props.ref;
/*eslint-disable no-unused-vars */
var googleMapsApi = props.googleMapsApi;

var googleMapsConfig = _objectWithoutProperties(props, ["key", "ref"]);
var googleMapsConfig = _objectWithoutProperties(props, ["googleMapsApi"]);

/*eslint-enable no-unused-vars */
var instance = this.state.instance;

if (instance) {
Expand Down
2 changes: 1 addition & 1 deletion lib/internals/EventComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function noop() {}
var EventComponent = (function (_React$Component) {
/* Contract
* statics:
* _registerEvents:
* _registerEvents:
* member:
* _createOrUpdateInstance
*/
Expand Down
8 changes: 2 additions & 6 deletions lib/internals/SimpleChildComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var PropTypes = _react2["default"].PropTypes;
var SimpleChildComponent = (function (_EventComponent) {
/* Contract
* statics:
* _GoogleMapsClassName:
* _GoogleMapsClassName:
* state:
* instance
*/
Expand All @@ -70,10 +70,8 @@ var SimpleChildComponent = (function (_EventComponent) {
return;
}
var googleMapsApi = props.googleMapsApi;
var key = props.key;
var ref = props.ref;

var googleMapsConfig = _objectWithoutProperties(props, ["googleMapsApi", "key", "ref"]);
var googleMapsConfig = _objectWithoutProperties(props, ["googleMapsApi"]);

var instance = this.state.instance;

Expand Down Expand Up @@ -110,8 +108,6 @@ var SimpleChildComponent = (function (_EventComponent) {
}, {
key: "render",
value: function render() {
var props = this.props;

return _react2["default"].createElement("noscript", null);
}
}]);
Expand Down
4 changes: 0 additions & 4 deletions lib/internals/VirtualContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _EventComponent = require("./EventComponent");

var _EventComponent2 = _interopRequireDefault(_EventComponent);

var PropTypes = _react2["default"].PropTypes;

var VirtualContainer = (function (_React$Component) {
Expand Down
2 changes: 1 addition & 1 deletion lib/internals/exposeGetters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function exposeGetters(component, prototype, instance) {
component[key] = instance[key].bind(instance);
}
}
};
}

exports["default"] = exposeGetters;
module.exports = exports["default"];
13 changes: 12 additions & 1 deletion src/GoogleMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ class GoogleMaps extends EventComponent {
}
// googleMapsApi can be async loaded
/*eslint-disable no-unused-vars */
const {containerProps, googleMapsApi, ...googleMapsConfig} = props;
const {containerProps, googleMapsApi, bounds, ...googleMapsConfig} = props;
/*eslint-enable no-unused-vars */
var {instance} = this.state;

if (bounds) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why deletion is needed when bounds is present?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand it, fitBounds actually sets zoom/center. So this is a precaution to prevent the map from jumping around.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks!

delete googleMapsConfig.zoom;
delete googleMapsConfig.center;
}

if (instance) {
instance.setOptions(googleMapsConfig);
} else {
Expand All @@ -71,6 +76,11 @@ class GoogleMaps extends EventComponent {

this.setState({instance});
}

if (bounds) {
instance.fitBounds(bounds);
}

return instance;
}

Expand Down Expand Up @@ -120,6 +130,7 @@ class GoogleMaps extends EventComponent {
GoogleMaps.propTypes = {
...EventComponent.propTypes,
containerProps: PropTypes.object.isRequired,
bounds: React.PropTypes.object
};

GoogleMaps._registerEvents = createRegisterEvents(
Expand Down