-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathmap.js
119 lines (105 loc) · 3.11 KB
/
map.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* eslint-disable react/prop-types */
// TODO: Typescript (config object)
import { Button, ButtonGroup } from 'react-bootstrap'
import { connect } from 'react-redux'
import React, { Component } from 'react'
import { setMapillaryId } from '../../actions/map'
import DefaultMap from './default-map'
import LegDiagram from './leg-diagram'
import MapillaryFrame from './mapillary-frame'
import StylizedMap from './stylized-map'
class Map extends Component {
constructor() {
super()
this.state = {
activeViewIndex: 0
}
}
getComponentForView(view) {
// TODO: allow a 'CUSTOM' type
switch (view.type) {
case 'DEFAULT':
return <DefaultMap />
case 'STYLIZED':
return <StylizedMap />
}
}
render() {
const { activeMapillaryImage, diagramLeg, mapConfig, setMapillaryId } =
this.props
const showDiagram = diagramLeg
const showMapillary = activeMapillaryImage
// Use the views defined in the config; if none defined, just show the default map
const views = mapConfig.views || [{ type: 'DEFAULT' }]
return (
<div className="map-container">
{/* The map views -- only one is visible at a time */}
{views.map((view, i) => {
return (
<div
className="map-container"
key={i}
style={{
visibility:
i === this.state.activeViewIndex ? 'visible' : 'hidden'
}}
>
{this.getComponentForView(view)}
</div>
)
})}
{/* The toggle buttons -- only show if multiple views */}
{views.length > 1 && (
<div
style={{
bottom: 12 + (showDiagram ? 192 : 0),
left: 12,
position: 'absolute',
zIndex: 100000
}}
>
<ButtonGroup>
{views.map((view, i) => {
return (
<Button
bsSize="xsmall"
bsStyle={
i === this.state.activeViewIndex ? 'success' : 'default'
}
key={i}
onClick={() => {
this.setState({ activeViewIndex: i })
}}
style={{ padding: '3px 6px' }}
>
{view.text || view.type}
</Button>
)
})}
</ButtonGroup>
</div>
)}
{/* The leg diagram overlay, if active */}
{showDiagram && <LegDiagram leg={diagramLeg} />}
{showMapillary && (
<MapillaryFrame
onClose={() => setMapillaryId(null)}
url={activeMapillaryImage}
/>
)}
</div>
)
}
}
// Connect to Redux store
const mapStateToProps = (state, ownProps) => {
return {
activeMapillaryImage: state.otp.ui.mapillaryId,
diagramLeg: state.otp.ui.diagramLeg,
mapConfig: state.otp.config.map
}
}
const mapDispatchToProps = {
setMapillaryId
}
export default connect(mapStateToProps, mapDispatchToProps)(Map)