Skip to content

Commit 13f5ee8

Browse files
authored
Merge pull request #205 from arbass22/fitBounds
Expose fitBounds() on Map component
2 parents 5efda4d + 9ca71ae commit 13f5ee8

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,31 @@ center: Takes an object containing latitude and longitude coordinates. Use this
127127
onClick={this.onMapClicked}
128128
>
129129
```
130+
bounds: Takes a [google.maps.LatLngBounds()](https://developers.google.com/maps/documentation/javascript/reference/3/#LatLngBounds) object to adjust the center and zoom of the map.
131+
```javascript
132+
var points = [
133+
{ lat: 42.02, lng: -77.01 },
134+
{ lat: 42.03, lng: -77.02 },
135+
{ lat: 41.03, lng: -77.04 },
136+
{ lat: 42.05, lng: -77.02 }
137+
]
138+
var bounds = new this.props.google.maps.LatLngBounds();
139+
for (var i = 0; i < points.length; i++) {
140+
bounds.extend(points[i]);
141+
}
142+
return (
143+
<Map
144+
google={this.props.google}
145+
initialCenter={{
146+
lat: 42.39,
147+
lng: -72.52
148+
}}
149+
bounds={bounds}>
150+
</Map>
151+
);
152+
153+
```
154+
130155
It also takes event handlers described below:
131156

132157
### Events

dist/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@
199199
if (prevState.currentLocation !== this.state.currentLocation) {
200200
this.recenterMap();
201201
}
202+
if (this.props.bounds !== prevProps.bounds) {
203+
this.map.fitBounds(this.props.bounds);
204+
}
202205
}
203206
}, {
204207
key: 'componentWillUnmount',
@@ -394,7 +397,8 @@
394397
disableDoubleClickZoom: _propTypes2.default.bool,
395398
noClear: _propTypes2.default.bool,
396399
styles: _propTypes2.default.array,
397-
gestureHandling: _propTypes2.default.string
400+
gestureHandling: _propTypes2.default.string,
401+
bounds: _propTypes2.default.object
398402
};
399403

400404
evtNames.forEach(function (e) {

dist/lib/GoogleApi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
var loading = false;
4444
var channel = null;
4545
var language = opts.language;
46-
var region = null;
46+
var region = opts.region || null;
4747

4848
var onLoadEvents = [];
4949

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ export class Map extends React.Component {
111111
if (prevState.currentLocation !== this.state.currentLocation) {
112112
this.recenterMap();
113113
}
114+
if (this.props.bounds !== prevProps.bounds) {
115+
this.map.fitBounds(this.props.bounds);
116+
}
114117
}
115118

116119
componentWillUnmount() {
@@ -288,7 +291,8 @@ Map.propTypes = {
288291
disableDoubleClickZoom: PropTypes.bool,
289292
noClear: PropTypes.bool,
290293
styles: PropTypes.array,
291-
gestureHandling: PropTypes.string
294+
gestureHandling: PropTypes.string,
295+
bounds: PropTypes.object
292296
};
293297

294298
evtNames.forEach(e => (Map.propTypes[camelize(e)] = PropTypes.func));

0 commit comments

Comments
 (0)