Skip to content

Commit 55d6b45

Browse files
mattwigwaytrevorgerhardt
authored andcommitted
fix(transitive): Generate transitive data without latitude longitude snapping to query grid. BREAKIN
Generate transitive dat without lat lon snapping, required some API changes. getTransitiveData is now gone, replaced with getDestinationData, and params have chnaged. API of getDestinationData has a BREAKING CHANGE.
1 parent f373050 commit 55d6b45

File tree

4 files changed

+32
-39
lines changed

4 files changed

+32
-39
lines changed

lib/get-transitive-data.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Color from 'color'
44
import dbg from 'debug'
55
import fill from 'lodash.fill'
66
import slice from 'lodash.slice'
7+
import ll from 'lonlng'
78

89
import {pixelToLat, pixelToLon} from './mercator'
910
import {getNonTransitTime, ITERATION_WIDTH} from './origin'
@@ -18,25 +19,33 @@ const MAX_PATH_SEGMENTS = 8
1819
// arbitrary value that determines how aggressively to cluster results (higher is more aggressive, and a high number is something like 1e-3)
1920
const MAXIMUM_DISSIMILARITY = 5e-6
2021

21-
export default function getTransitiveData ({origin, query, stopTreeCache, network, to}) {
22+
export default function getTransitiveData ({ origin, query, stopTreeCache, network, from, to }) {
2223
// create the journeys
2324
let output = {
2425
places: [],
2526
journeys: []
2627
}
2728

29+
// from can be left null and it will be inferred from the destination
30+
const fromCoord = from != null ? ll(from) : {}
31+
2832
output.places.push({
2933
place_id: 'from',
30-
place_name: 'Origin', // todo do this with icons, avoid English works (or Portuguese words, for that matter)
31-
place_lat: pixelToLat(query.north + origin.y, query.zoom),
32-
place_lon: pixelToLon(query.west + origin.x, query.zoom)
34+
place_name: from.name || 'Origin', // todo do this with icons, avoid English works (or Portuguese words, for that matter)
35+
place_lat: fromCoord.lat || pixelToLat(query.north + origin.y, query.zoom),
36+
place_lon: fromCoord.lon || pixelToLon(query.west + origin.x, query.zoom)
3337
})
3438

39+
// to cannot be undefined
40+
// Omit X and Y so as not to confuse lonlng
41+
const { x, y, ...rest } = to
42+
const toCoord = ll(rest)
43+
3544
output.places.push({
3645
place_id: 'to',
3746
place_name: to.name || 'Destination',
38-
place_lat: pixelToLat(query.north + to.y, query.zoom),
39-
place_lon: pixelToLon(query.west + to.x, query.zoom)
47+
place_lat: toCoord.lat || pixelToLat(query.north + to.y, query.zoom),
48+
place_lon: toCoord.lon || pixelToLon(query.west + to.x, query.zoom)
4049
})
4150

4251
// find relevant paths at each minute

lib/index.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,16 @@ export default class Browsochrones extends WebWorkerPromiseInterface {
8787
})
8888
}
8989

90-
generateDestinationData (point) {
90+
generateDestinationData ({ from, to }) {
91+
if (!this.isLoaded()) {
92+
return Promise.reject(new Error('Transitive data cannot be generated if Browsochrones is not fully loaded.'))
93+
}
94+
9195
return this.work({
9296
command: 'generateDestinationData',
9397
message: {
94-
point
98+
from,
99+
to
95100
}
96101
})
97102
}
@@ -114,19 +119,6 @@ export default class Browsochrones extends WebWorkerPromiseInterface {
114119
})
115120
}
116121

117-
generateTransitiveData (point) {
118-
if (!this.isLoaded()) {
119-
return Promise.reject(new Error('Transitive data cannot be generated if Browsochrones is not fully loaded.'))
120-
}
121-
122-
return this.work({
123-
command: 'generateTransitiveData',
124-
message: {
125-
point
126-
}
127-
})
128-
}
129-
130122
generateSurface (which = 'MEDIAN') {
131123
if (!this.isLoaded()) {
132124
return Promise.reject(new Error('Surface cannot be generated if Browsochrones is not fully loaded.'))

lib/worker-handlers.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,45 +55,36 @@ module.exports = createHandler({
5555
})
5656
},
5757
generateDestinationData (ctx, message) {
58-
const {point} = message
58+
const { to, from } = message
5959

60-
let travelTime = ctx.surface.surface[point.y * ctx.query.width + point.x]
61-
let waitTime = ctx.surface.waitTimes[point.y * ctx.query.width + point.x]
60+
let travelTime = ctx.surface.surface[to.y * ctx.query.width + to.x]
61+
let waitTime = ctx.surface.waitTimes[to.y * ctx.query.width + to.x]
6262
// NB separate walk time surface because some summary statistics don't preserve stat(wait) +
6363
// stat(walk) + stat(inVehicle) = stat(total)
64-
let walkTime = ctx.surface.walkTimes[point.y * ctx.query.width + point.x]
65-
let inVehicleTravelTime = ctx.surface.inVehicleTravelTimes[point.y * ctx.query.width + point.x]
64+
let walkTime = ctx.surface.walkTimes[to.y * ctx.query.width + to.x]
65+
let inVehicleTravelTime = ctx.surface.inVehicleTravelTimes[to.y * ctx.query.width + to.x]
6666

6767
return {
6868
paths: getPaths({
6969
origin: ctx.origin,
7070
query: ctx.query,
7171
stopTreeCache: ctx.stopTreeCache,
72-
to: point
72+
to
7373
}),
7474
transitive: getTransitiveData({
7575
network: ctx.transitiveNetwork,
7676
origin: ctx.origin,
77+
from,
78+
to,
7779
query: ctx.query,
78-
stopTreeCache: ctx.stopTreeCache,
79-
to: point
80+
stopTreeCache: ctx.stopTreeCache
8081
}),
8182
travelTime,
8283
waitTime,
8384
inVehicleTravelTime,
8485
walkTime
8586
}
8687
},
87-
generateTransitiveData (ctx, message) {
88-
ctx.transitiveData = getTransitiveData({
89-
network: ctx.transitiveNetwork,
90-
origin: ctx.origin,
91-
query: ctx.query,
92-
stopTreeCache: ctx.stopTreeCache,
93-
to: message.point
94-
})
95-
return ctx.transitiveData
96-
},
9788
getContour (ctx, message) {
9889
ctx.contour = getContour({
9990
cutoff: message.cutoff,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"leaflet": "^0.7.7",
2424
"lodash.fill": "^3.3.2",
2525
"lodash.slice": "^4.0.2",
26+
"lonlng": "^0.2.0",
2627
"web-worker-promise-interface": "^0.2.0"
2728
},
2829
"devDependencies": {

0 commit comments

Comments
 (0)