/
DirectionsRenderer.js
80 lines (67 loc) · 2.2 KB
/
DirectionsRenderer.js
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
import {
default as React,
Component,
PropTypes,
} from "react";
import {
default as canUseDOM,
} from "can-use-dom";
import {
default as DirectionsRendererCreator,
directionsRendererDefaultPropTypes,
directionsRendererControlledPropTypes,
directionsRendererEventPropTypes,
} from "./creators/DirectionsRendererCreator";
import { default as GoogleMapHolder } from "./creators/GoogleMapHolder";
/*
* Original author: @alexishevia
* Original PR: https://github.com/tomchentw/react-google-maps/pull/22
*/
export default class DirectionsRenderer extends Component {
static propTypes = {
// Uncontrolled default[props] - used only in componentDidMount
...directionsRendererDefaultPropTypes,
// Controlled [props] - used in componentDidMount/componentDidUpdate
...directionsRendererControlledPropTypes,
// Event [onEventName]
...directionsRendererEventPropTypes,
}
static contextTypes = {
mapHolderRef: PropTypes.instanceOf(GoogleMapHolder),
}
// Public APIs
//
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#DirectionsRenderer
//
// [].map.call($0.querySelectorAll("tr>td>code"), function(it){ return it.textContent; }).filter(function(it){ return it.match(/^get/) && !it.match(/^getMap/); })
getDirections() { return this.state.directionsRenderer.getDirections(); }
getPanel() { return this.state.directionsRenderer.getPanel(); }
getRouteIndex() { return this.state.directionsRenderer.getRouteIndex(); }
// END - Public APIs
//
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#DirectionsRenderer
state = {
}
componentWillMount() {
const { mapHolderRef } = this.context;
if (!canUseDOM) {
return;
}
const directionsRenderer = DirectionsRendererCreator._createDirectionsRenderer({
...this.props,
mapHolderRef,
});
this.setState({ directionsRenderer });
}
render() {
if (this.state.directionsRenderer) {
return (
<DirectionsRendererCreator directionsRenderer={this.state.directionsRenderer} {...this.props}>
{this.props.children}
</DirectionsRendererCreator>
);
} else {
return (<noscript />);
}
}
}