Skip to content

Commit 4b9f694

Browse files
committed
Wellington Line Stops & Routes
1 parent 529f7a6 commit 4b9f694

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

js/views/lines.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class Lines extends React.Component {
190190
}
191191
return (
192192
<li key={key}>
193-
<a className="line-item" href={'/l/nz-akl/'+item} onClick={this.disable} onTouchTap={this.hijack('/l/nz-akl/'+item)}>
193+
<a className="line-item" href={`/l/${this.props.match.params.region}/${item}`} onClick={this.disable} onTouchTap={this.hijack(`/l/${this.props.match.params.region}/${item}`)}>
194194
<span className="line-pill-wrapper">
195195
<span className={roundelStyle} style={{backgroundColor: this.state.colors[item] || '#000'}}>{code}</span>
196196
</span>

js/views/vehicle_loc.jsx

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ class vehicle_location extends React.Component {
7272
}
7373
getShapeData = (newProps = this.props) => {
7474
let showIcons = true
75-
let url = `${local.endpoint}/nz-akl/stops/trip/${newProps.params.trip_id}`
75+
let url = `${local.endpoint}/${newProps.params.region}/stops/trip/${newProps.params.trip_id}`
7676
if ('line_id' in newProps.params) {
7777
if (typeof(newProps.tripInfo.shape_id) !== 'undefined') {
78-
url = `${local.endpoint}/nz-akl/stops/shape/${newProps.tripInfo.shape_id}`
78+
url = `${local.endpoint}/${newProps.params.region}/stops/shape/${encodeURIComponent(newProps.tripInfo.shape_id)}`
7979
} else {
8080
return
8181
}
@@ -105,8 +105,19 @@ class vehicle_location extends React.Component {
105105
getWKB = (newProps = this.props, force = false) => {
106106
if (typeof(this.state.line) === 'undefined' || force === true) {
107107
if (typeof(newProps.tripInfo.shape_id) !== 'undefined') {
108-
fetch(`${local.endpoint}/nz-akl/shape/${newProps.tripInfo.shape_id}`).then((response) => {
109-
response.text().then(this.convert)
108+
fetch(`${local.endpoint}/${newProps.params.region}/shapejson/${encodeURIComponent(newProps.tripInfo.shape_id)}`).then((response) => {
109+
response.json().then((geoJson) => {
110+
let newState = {
111+
line: geoJson
112+
}
113+
// this centers the line if we're looking at the line
114+
if ('line_id' in this.props.params) {
115+
// it's opposite for some reason, also we shouldn't mutate it
116+
let center = geoJson.coordinates[Math.round(geoJson.coordinates.length/2)]
117+
newState.position = center.slice().reverse()
118+
}
119+
this.setState(newState)
120+
})
110121
})
111122
}
112123
}
@@ -125,22 +136,6 @@ class vehicle_location extends React.Component {
125136
CurrentLocation.stopWatch()
126137
}
127138
}
128-
129-
convert = (data) => {
130-
let wkb = new Buffer(data, 'hex')
131-
let geoJson = wkx.Geometry.parse(wkb).toGeoJSON()
132-
133-
let newState = {
134-
line: geoJson
135-
}
136-
// this centers the line if we're looking at the line
137-
if ('line_id' in this.props.params) {
138-
// it's opposite for some reason, also we shouldn't mutate it
139-
let center = geoJson.coordinates[Math.round(geoJson.coordinates.length/2)]
140-
newState.position = center.slice().reverse()
141-
}
142-
this.setState(newState)
143-
}
144139

145140
componentDidMount() {
146141
CurrentLocation.bind('pinmove', this.pinmove)
@@ -235,14 +230,14 @@ class vehicle_location extends React.Component {
235230

236231
viewServices = (stop) => {
237232
return () => {
238-
this.props.history.push(`/s/nz-akl/${stop}`)
233+
this.props.history.push(`/s/${this.props.params.region}/${stop}`)
239234
}
240235
}
241236

242237
viewTimetable = (stop) => {
243238
return () => {
244239
const line_id = this.props.params.line_id || this.props.tripInfo.route_short_name
245-
this.props.history.push(`/s/nz-akl/${stop}/timetable/${line_id}-2`)
240+
this.props.history.push(`/s/${this.props.params.region}/${stop}/timetable/${line_id}-2`)
246241
}
247242
}
248243

js/views/vehicle_loc_bootstrap.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class VehicleLocationBootstrap extends React.Component {
7070
})
7171
}
7272
lineMountCb = (newProps) => {
73-
StationStore.getLines().then((data) => {
73+
StationStore.getLines(newProps.match.params.region).then((data) => {
7474
this.setState({
7575
tripInfo: {
7676
route_short_name: newProps.match.params.line_id,
@@ -80,7 +80,7 @@ class VehicleLocationBootstrap extends React.Component {
8080
})
8181
}
8282
getLineData = () => {
83-
fetch(`${local.endpoint}/nz-akl/line/${this.props.match.params.line_id}`).then((response) => {
83+
fetch(`${local.endpoint}/${this.props.match.params.region}/line/${this.props.match.params.line_id}`).then((response) => {
8484
response.json().then((data) => {
8585
let tripInfo = JSON.parse(JSON.stringify(this.state.tripInfo))
8686
tripInfo.route_long_name = data[0].route_long_name

server/lines/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ var line = {
256256

257257
getStopsFromTrip: function(req, res){
258258
const sqlRequest = connection.get().request()
259-
sqlRequest.input('prefix', sql.VarChar(50), req.params.prefix || 'nz-akl')
260-
sqlRequest.input('version', sql.VarChar(50), cache.currentVersion())
259+
const prefix = req.params.prefix || 'nz-akl'
260+
sqlRequest.input('prefix', sql.VarChar(50), prefix)
261+
sqlRequest.input('version', sql.VarChar(50), cache.currentVersion(prefix))
261262
sqlRequest.input('trip_id', sql.VarChar(100), req.params.trip_id)
262263
sqlRequest.query(`
263264
SELECT
@@ -286,8 +287,9 @@ var line = {
286287
},
287288
getStopsFromShape: function(req, res) {
288289
const sqlRequest = connection.get().request()
289-
sqlRequest.input('prefix', sql.VarChar(50), req.params.prefix || 'nz-akl')
290-
sqlRequest.input('version', sql.VarChar(50), cache.currentVersion())
290+
const prefix = req.params.prefix || 'nz-akl'
291+
sqlRequest.input('prefix', sql.VarChar(50), prefix)
292+
sqlRequest.input('version', sql.VarChar(50), cache.currentVersion(prefix))
291293
sqlRequest.input('shape_id', sql.VarChar(100), req.params.shape_id)
292294
sqlRequest.query(`SELECT TOP(1) trip_id FROM trips WHERE trips.prefix = @prefix and trips.version = @version and trips.shape_id = @shape_id`).then((result) => {
293295
let trip_id = result.recordset[0].trip_id

0 commit comments

Comments
 (0)