Skip to content

Commit 30a3e07

Browse files
author
Ari
committed
Added onResizeEvent example
1 parent b95a1f1 commit 30a3e07

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

examples/components/resizeEvent.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
4+
import Map, {GoogleApiWrapper} from '../../src/index';
5+
6+
const Container = React.createClass({
7+
getInitialState: function() {
8+
return {
9+
showingInfoWindow: false,
10+
activeMarker: {},
11+
selectedPlace: {}
12+
};
13+
},
14+
15+
onMapReady: function(mapProps, map) {
16+
this.map = map;
17+
18+
window.onresize = function() {
19+
var currCenter = map.getCenter();
20+
google.maps.event.trigger(map, 'resize');
21+
map.setCenter(currCenter);
22+
};
23+
},
24+
25+
onMapMoved: function(props, map) {
26+
const center = map.center;
27+
},
28+
29+
onMarkerClick: function(props, marker, e) {
30+
this.setState({
31+
selectedPlace: props,
32+
activeMarker: marker,
33+
showingInfoWindow: true
34+
});
35+
},
36+
37+
onInfoWindowClose: function() {
38+
this.setState({
39+
showingInfoWindow: false,
40+
activeMarker: null
41+
});
42+
},
43+
44+
onMapClicked: function(props) {
45+
if (this.state.showingInfoWindow) {
46+
this.setState({
47+
showingInfoWindow: false,
48+
activeMarker: null
49+
});
50+
}
51+
},
52+
53+
render: function() {
54+
if (!this.props.loaded) {
55+
return <div>Loading...</div>;
56+
}
57+
58+
return (
59+
<Map
60+
google={this.props.google}
61+
style={{width: '100%', height: '100%', position: 'relative'}}
62+
className={'map'}
63+
onReady={this.onMapReady}
64+
zoom={14}
65+
containerStyle={{}}
66+
centerAroundCurrentLocation={true}
67+
onClick={this.onMapClicked}
68+
onDragend={this.onMapMoved}
69+
/>
70+
);
71+
}
72+
});
73+
74+
export default Container;

examples/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const routeMap = {
4545
polyline: {
4646
name: 'Polyline',
4747
component: require('./components/withPolylines').default
48+
},
49+
onResizeEvent: {
50+
name: 'Custom events',
51+
component: require('./components/resizeEvent').default
4852
}
4953
};
5054

0 commit comments

Comments
 (0)