forked from visgl/deck.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
88 lines (71 loc) · 2.18 KB
/
Copy pathmap.js
File metadata and controls
88 lines (71 loc) · 2.18 KB
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
import 'babel-polyfill';
import React, {Component} from 'react';
import {connect} from 'react-redux';
import autobind from 'autobind-decorator';
import MapGL from 'react-map-gl';
import Demos from './demos';
import {updateMap, updateMeta, loadData, useParams} from '../actions/app-actions';
import {MAPBOX_STYLES} from '../constants/defaults';
import MAPBOX_ACCESS_TOKEN from '../constants/mapbox-token';
import ViewportAnimation from '../utils/map-utils';
class Map extends Component {
componentDidMount() {
this._loadDemo(this.props.demo, false);
}
componentWillReceiveProps(nextProps) {
const {demo} = nextProps;
if (demo !== this.props.demo) {
this._loadDemo(demo, true);
}
}
_loadDemo(demo, useTransition) {
const {loadData, useParams, updateMap} = this.props;
const DemoComponent = Demos[demo];
if (DemoComponent) {
loadData(demo, DemoComponent.data);
useParams(DemoComponent.parameters);
if (useTransition) {
const {viewport} = this.props;
ViewportAnimation.fly(viewport, DemoComponent.viewport, 1000, updateMap)
.easing(ViewportAnimation.Easing.Exponential.Out)
.start();
} else {
updateMap(DemoComponent.viewport);
}
}
}
@autobind
_onUpdateMap(viewport) {
this.props.onInteract();
this.props.updateMap(viewport);
}
render() {
const {viewport, demo, params, owner, data, updateMeta, isInteractive} = this.props;
const DemoComponent = Demos[demo];
if (!DemoComponent) {
return null;
}
return (
<MapGL
mapboxApiAccessToken={MAPBOX_ACCESS_TOKEN}
perspectiveEnabled={true}
{ ...viewport }
onChangeViewport={ isInteractive ? this._onUpdateMap : undefined }>
<DemoComponent ref="demo" viewport={viewport} params={params}
onStateChange={updateMeta}
data={owner === demo ? data : null} />
</MapGL>
)
}
}
function mapStateToProps(state) {
return {
viewport: state.viewport,
...state.vis
}
}
Map.defaultProps = {
onInteract: () => {},
isInteractive: true
};
export default connect(mapStateToProps, {updateMap, updateMeta, loadData, useParams})(Map);