Skip to content

Commit 996d1be

Browse files
committed
Update center now works
fix #2
1 parent a24ce45 commit 996d1be

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

demo/singleMapRefreshable.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
RefreshMap = React.createClass({
2929
getInitialState: function(){
3030
return {
31+
center: {latitude:60.1876172,longitude:24.815366},
3132
points: [ {latitude:60.1876172,longitude:24.815366} ]
3233
}
3334
},
@@ -39,10 +40,15 @@
3940
]
4041
this.setState({points:randomPoints})
4142
},
43+
randomizeCenter: function(){
44+
newCenter = {latitude:60.1876172+2*Math.random()-1,longitude:24.815366+2*Math.random()-1}
45+
this.setState({center:newCenter})
46+
},
4247
render: function(){
4348
return (
4449
<div>
45-
<Map latitude={60.170833} longitude={24.9375} zoom={6} width='100%' height={250} points={this.state.points} />
50+
<Map latitude={this.state.center.latitude} longitude={this.state.center.longitude} zoom={6} width='100%' height={250} points={this.state.points} />
51+
<button onClick={this.randomizeCenter}>Randomize Center</button>
4652
<button onClick={this.randomize}>Randomize Points</button>
4753
</div>
4854
)

src/map.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ var Map = React.createClass({
6464
this.setState( { markers : markers });
6565
},
6666

67+
updateCenter: function(newLat, newLon){
68+
var newCenter = new google.maps.LatLng(newLat, newLon)
69+
this.state.map.setCenter(newCenter)
70+
},
71+
6772
render : function() {
6873

6974
var style = {
@@ -102,6 +107,8 @@ var Map = React.createClass({
102107
// update markers if needed
103108
componentWillReceiveProps : function(props) {
104109
if( props.points ) this.updateMarkers(props.points);
110+
111+
if( props.latitude || props.longitude) this.updateCenter(props.latitude, props.longitude)
105112
}
106113

107114
});

0 commit comments

Comments
 (0)