|
| 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; |
0 commit comments