Skip to content

Commit 19e4bc5

Browse files
committed
Improve Map Performance
1 parent 13a628d commit 19e4bc5

File tree

5 files changed

+489
-272
lines changed

5 files changed

+489
-272
lines changed

js/stores/stationStore.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ export class stationStore extends Events {
242242
this.tripData = trips
243243
this.realtimeData = this.realtimeModifier(trips, realtime, stations, region)
244244
this.trigger('times', stations)
245-
}).catch(() => {
245+
}).catch((err) => {
246+
console.error(err)
246247
this.trigger('error', t('station.error'))
247248
})
248249
}
@@ -329,7 +330,7 @@ export class stationStore extends Events {
329330
return d
330331
}
331332
realtimeModifier(tripData, rtData, stop, region) {
332-
if (tripData[0].route_type === 2) {
333+
if (tripData.length > 0 && tripData[0].route_type === 2) {
333334
const stationId = region + '|' + stop.split('+')[0]
334335
const station = this.StationData[stationId] || this.stationCache[stationId.split('|')[1]]
335336
if (typeof station === 'undefined') {

js/views/root/region.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ export default class RegionPopover extends React.Component {
1717
}
1818
}
1919
render() {
20+
let dev = null
21+
if (process.env.NODE_ENV !== 'production') {
22+
dev = (
23+
<li className="au-syd" onTouchTap={this.changeCity('au-syd')}>
24+
<h2>{t('regions.au-syd-long').split(',')[0]}</h2>
25+
<h1>{t('regions.au-syd-long').split(',')[1]}</h1>
26+
</li>
27+
)
28+
}
2029
const className = 'region-popover ' + (this.props.visible ? 'show' : '')
2130
return (
2231
<div className={className}>
@@ -35,10 +44,7 @@ export default class RegionPopover extends React.Component {
3544
<h2>{t('regions.nz-wlg-long').split(',')[0]}</h2>
3645
<h1>{t('regions.nz-wlg-long').split(',')[1]}</h1>
3746
</li>
38-
<li className="au-syd" onTouchTap={this.changeCity('au-syd')}>
39-
<h2>{t('regions.au-syd-long').split(',')[0]}</h2>
40-
<h1>{t('regions.au-syd-long').split(',')[1]}</h1>
41-
</li>
47+
{dev}
4248
</ul>
4349
<div className="vote">
4450
<p>{t('regions.vote', { appname: t('app.name') })}</p>

js/views/search.jsx

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Search extends React.Component {
6868
static propTypes = {
6969
history: PropTypes.object,
7070
}
71+
myIcons = {}
7172
state = {
7273
station: '',
7374
stops: [],
@@ -95,17 +96,19 @@ class Search extends React.Component {
9596
}
9697
// stops requesting location when not in use
9798
componentWillReceiveProps() {
98-
if (window.location.pathname === '/') {
99-
this.setState({
100-
showIcons: true,
101-
currentStation: null
102-
})
103-
} else {
104-
this.setState({
105-
showIcons: false
106-
})
107-
CurrentLocation.stopWatch()
108-
}
99+
setTimeout(() => {
100+
if (window.location.pathname === '/') {
101+
this.setState({
102+
showIcons: true,
103+
currentStation: null
104+
})
105+
} else {
106+
this.setState({
107+
showIcons: false
108+
})
109+
CurrentLocation.stopWatch()
110+
}
111+
}, 300)
109112
}
110113
componentWillUnmount() {
111114
window.removeEventListener('online', this.triggerRetry)
@@ -141,8 +144,11 @@ class Search extends React.Component {
141144
getData(lat, lon, dist) {
142145
fetch(`${local.endpoint}/auto/station/search?lat=${lat.toFixed(4)}&lon=${lon.toFixed(4)}&distance=${dist}`).then((response) => {
143146
response.json().then((data) => {
144-
data.forEach(function(item) {
147+
data.forEach((item) => {
145148
StationStore.stationCache[item.stop_id] = item
149+
if (typeof(this.myIcons[item.route_type.toString()]) === 'undefined') {
150+
this.myIcons[item.route_type.toString()] = IconHelper.getIcon(StationStore.currentCity, item.route_type)
151+
}
146152
})
147153
this.setState({
148154
stops: data
@@ -201,19 +207,19 @@ class Search extends React.Component {
201207
}
202208
}
203209
moveEnd = (e) => {
204-
var zoom = e.target.getZoom()
210+
const zoom = e.target.getZoom()
205211
// we're basing this off screensize
206212
var screensize = document.body.offsetWidth
207213
if (document.body.offsetHeight > screensize) {
208214
screensize = document.body.offsetHeight
209215
}
210-
var newPos = e.target.getCenter()
216+
let newPos = e.target.getCenter()
211217
StationStore.getCity(newPos.lat, newPos.lng)
212-
var dist = Math.ceil(0.2 * screensize)
218+
let dist = Math.ceil(0.2 * screensize)
213219
if (zoom === 17) {
214-
dist = Math.ceil(0.35 * screensize)
220+
dist = Math.ceil(0.45 * screensize)
215221
} else if (zoom === 16) {
216-
dist = Math.ceil(0.6 * screensize)
222+
dist = Math.ceil(0.8 * screensize)
217223
} else if (zoom < 16) {
218224
this.setState({
219225
stops: []
@@ -285,13 +291,6 @@ class Search extends React.Component {
285291
)
286292
}
287293

288-
const myIcons = {}
289-
this.state.stops.forEach((stop) => {
290-
if (typeof(myIcons[stop.route_type.toString()]) === 'undefined') {
291-
myIcons[stop.route_type.toString()] = IconHelper.getIcon(StationStore.currentCity, stop.route_type)
292-
}
293-
})
294-
295294
let mapview
296295
if (this.state.loadmap) {
297296
mapview = (
@@ -310,7 +309,7 @@ class Search extends React.Component {
310309
{this.state.stops.map((stop) => {
311310
let icon, markericon
312311
icon = IconHelper.getRouteType(stop.route_type)
313-
markericon = myIcons[stop.route_type.toString()]
312+
markericon = this.myIcons[stop.route_type.toString()]
314313
if (icon === 'bus') {
315314
const stopSplit = stop.stop_name.split('Stop')
316315
const platformSplit = stop.stop_name.split('Platform')

0 commit comments

Comments
 (0)