Skip to content

Commit 1ee3106

Browse files
author
David Emory
committed
fix(map): fix scaling issues in transitive overlay
1 parent 1805af3 commit 1ee3106

File tree

2 files changed

+106
-3
lines changed

2 files changed

+106
-3
lines changed

lib/components/map/transitive-overlay.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { PropTypes } from 'react'
22
import { MapLayer } from 'react-leaflet'
33
import L from 'leaflet'
4+
import { connect } from 'react-redux'
45

56
import * as d3 from 'd3'
67

8+
import { getActiveSearch } from '../../util/state'
9+
710
import Transitive from 'transitive-js'
811

912
class TransitiveOverlay extends MapLayer {
@@ -55,15 +58,20 @@ class TransitiveOverlay extends MapLayer {
5558
this._redraw()
5659
})
5760

61+
const leafletContainer = document.getElementsByClassName('leaflet-container')[0]
62+
5863
// set up the transitive instance
5964
const mapBounds = map.getBounds()
6065
this._transitive = new Transitive({
6166
data: this.props.transitiveData,
62-
svgContainer: document.getElementsByClassName('leaflet-container')[0],
67+
svgContainer: leafletContainer,
6368
svg: this._svgMain,
6469
initialBounds: [[mapBounds.getWest(), mapBounds.getSouth()], [mapBounds.getEast(), mapBounds.getNorth()]],
6570
zoomEnabled: false,
66-
autoResize: false
71+
autoResize: false,
72+
styles: require('./transitive-styles'),
73+
drawGrid: false,
74+
gridCellSize: 300
6775
})
6876

6977
// the initial map draw
@@ -73,6 +81,7 @@ class TransitiveOverlay extends MapLayer {
7381
componentWillReceiveProps (nextProps) {
7482
if (nextProps.transitiveData !== this.props.transitiveData) {
7583
this._transitive.updateData(nextProps.transitiveData)
84+
this._transitive.render()
7685
this._redraw()
7786
}
7887
}
@@ -95,4 +104,16 @@ class TransitiveOverlay extends MapLayer {
95104
}
96105
}
97106

98-
export default TransitiveOverlay
107+
// connect to the redux store
108+
109+
const mapStateToProps = (state, ownProps) => {
110+
const activeSearch = getActiveSearch(state.otp)
111+
return {
112+
transitiveData: activeSearch && activeSearch.profileResponse && activeSearch.profileResponse.otp
113+
}
114+
}
115+
116+
const mapDispatchToProps = {
117+
}
118+
119+
export default connect(mapStateToProps, mapDispatchToProps)(TransitiveOverlay)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
var STYLES = {}
2+
3+
STYLES.segments = {
4+
5+
// override the default stroke color
6+
stroke: (display, segment) => {
7+
if (!segment.focused) return
8+
9+
switch (segment.type) {
10+
case 'CAR':
11+
return '#888'
12+
case 'WALK':
13+
return '#00f'
14+
case 'BICYCLE':
15+
return '#f00'
16+
}
17+
},
18+
19+
// override the default stroke width
20+
'stroke-width': (display, segment, index, utils) => {
21+
switch (segment.type) {
22+
case 'CAR':
23+
return utils.pixels(display.zoom.scale(), 2, 4, 6) + 'px'
24+
case 'WALK':
25+
case 'BICYCLE':
26+
return '4px'
27+
case 'TRANSIT':
28+
// bus segments:
29+
if (segment.mode === 3) {
30+
return utils.pixels(display.zoom.scale(), 2, 4, 8) + 'px'
31+
}
32+
// all others:
33+
return utils.pixels(display.zoom.scale(), 4, 8, 12) + 'px'
34+
}
35+
},
36+
37+
// specify the dash-array
38+
'stroke-dasharray': (display, segment) => {
39+
switch (segment.type) {
40+
case 'CAR':
41+
return '3,2'
42+
case 'WALK':
43+
case 'BICYCLE':
44+
return '0.01,6'
45+
}
46+
},
47+
48+
// specify the line cap type
49+
'stroke-linecap': (display, segment) => {
50+
switch (segment.type) {
51+
case 'CAR':
52+
return 'butt'
53+
case 'WALK':
54+
case 'BICYCLE':
55+
return 'round'
56+
}
57+
}
58+
}
59+
60+
/** style overrides for places (i.e. the start and end icons) **/
61+
62+
STYLES.places_icon = {
63+
x: [-16],
64+
y: [-16],
65+
width: [
66+
32
67+
],
68+
height: [
69+
32
70+
],
71+
'xlink:href': [
72+
(display, data) => {
73+
// if (data.owner.getId() === 'from') return 'assets/img/star60.svg'
74+
// if (data.owner.getId() === 'to') return 'assets/img/map25.svg'
75+
}
76+
],
77+
visibility: [
78+
'visible'
79+
]
80+
}
81+
82+
export default STYLES

0 commit comments

Comments
 (0)