File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 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 } ,
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 )
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments