-
Notifications
You must be signed in to change notification settings - Fork 314
/
events_map_page.jsx
90 lines (75 loc) · 2.53 KB
/
events_map_page.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* GoogleMap hover example
*/
import React, {PropTypes, Component} from 'react/addons';
import shouldPureComponentUpdate from 'react-pure-render/function';
import controllable from 'react-controllables';
import GoogleMap from 'google-map-react';
import MyGreatPlaceWithControllableHover from './my_great_place_with_controllable_hover.jsx';
import {K_SIZE} from './my_great_place_with_controllable_hover_styles.js';
@controllable(['center', 'zoom', 'hoverKey', 'clickKey'])
export default class EventsMapPage extends Component {
static propTypes = {
center: PropTypes.array, // @controllable
zoom: PropTypes.number, // @controllable
hoverKey: PropTypes.string, // @controllable
clickKey: PropTypes.string, // @controllable
onCenterChange: PropTypes.func, // @controllable generated fn
onZoomChange: PropTypes.func, // @controllable generated fn
onHoverKeyChange: PropTypes.func, // @controllable generated fn
greatPlaces: PropTypes.array
};
static defaultProps = {
center: [59.838043, 30.337157],
zoom: 9,
greatPlaces: [
{id: 'A', lat: 59.955413, lng: 30.337844},
{id: 'B', lat: 59.724, lng: 30.080}
]
};
shouldComponentUpdate = shouldPureComponentUpdate;
constructor(props) {
super(props);
}
_onBoundsChange = (center, zoom /* , bounds, marginBounds */) => {
this.props.onCenterChange(center);
this.props.onZoomChange(zoom);
}
_onChildClick = (key, childProps) => {
this.props.onCenterChange([childProps.lat, childProps.lng]);
}
_onChildMouseEnter = (key /*, childProps */) => {
this.props.onHoverKeyChange(key);
}
_onChildMouseLeave = (/* key, childProps */) => {
this.props.onHoverKeyChange(null);
}
render() {
const places = this.props.greatPlaces
.map(place => {
const {id, ...coords} = place;
return (
<MyGreatPlaceWithControllableHover
key={id}
{...coords}
text={id}
// use your hover state (from store, react-controllables etc...)
hover={this.props.hoverKey === id} />
);
});
return (
<GoogleMap
// apiKey={YOUR_GOOGLE_MAP_API_KEY} // set if you need stats etc ...
center={this.props.center}
zoom={this.props.zoom}
hoverDistance={K_SIZE / 2}
onBoundsChange={this._onBoundsChange}
onChildClick={this._onChildClick}
onChildMouseEnter={this._onChildMouseEnter}
onChildMouseLeave={this._onChildMouseLeave}
>
{places}
</GoogleMap>
);
}
}