Commit a6d5c053 authored by dagal's avatar dagal
Browse files

Display lines by stop

parent 62d73518
<template>
<div class="trippy-search-field">
<autocomplete v-model="selectedStop" :options="stops" option-key="id" option-label="name" :placeholder="placeholder"></autocomplete>
<autocomplete v-model="selectedStop" :options="stops" option-key="id"
option-label="name" :placeholder="placeholder" :get-option-description="getDescription"></autocomplete>
</div>
</template>
......@@ -35,6 +36,13 @@
this.$emit("input", s);
}
}
},
methods: {
getDescription(option) {
//return option.name + " (" + option.lines.map(l => l.short_name).join() + ")";
return `${option.name} (${option.lines.map(l => l.short_name).join()})`
}
}
}
</script>
......
......@@ -42,8 +42,8 @@ let app = new Vue({
start: null,
end: null
},
stops: [],
lines: [],
stops: {},
lines: {},
startStops: [],
endStops: [],
startLines: [],
......@@ -87,16 +87,16 @@ let app = new Vue({
selectLine(l, isEndLine) {
if (isEndLine) {
if (!l) {
this.endStops = this.stops;
this.endStops = Object.values(this.stops);
} else {
this.endStops = this.stops.filter(s => l.stops.indexOf(s.id) > -1);
this.endStops = l.stops.map(sid => app.stops[sid]);
}
} else {
if (!l) {
this.startStops = this.stops;
this.startStops = Object.values(this.stops);
} else {
this.startStops = this.stops.filter(s => l.stops.indexOf(s.id) > -1);
this.startStops = l.stops.map(sid => app.stops[sid]);
}
}
},
......@@ -190,11 +190,24 @@ map.on("contextmenu.hide", (e) => {
}
});
var stopsResolver = null;
let stopsPromise = new Promise(function(resolve, reject) {
stopsResolver = resolve;
});
var linesResolver = null;
let linesPromise = new Promise(function(resolve, reject) {
linesResolver = resolve;
});
getty.jsonGet("/stops").then(function (fc) {
stopLayer.addData(fc);
app.stops = fc.features.map(f => f.properties);
app.startStops = app.stops;
app.endStops = app.stops;
fc.features.map(f => f.properties).forEach(s => app.stops[s.id] = s);
app.startStops = Object.values(app.stops);
app.endStops = Object.values(app.stops);
/*
app.stops.sort((f1,f2) => {
if (f1.name < f2.name) {
return -1;
......@@ -204,13 +217,18 @@ getty.jsonGet("/stops").then(function (fc) {
return 0;
}
});
*/
stopsResolver();
});
getty.jsonGet("/lines").then(function (fc) {
lineLayer.addData(fc);
app.lines = fc.features.map(f => f.properties);
app.startLines = app.lines;
app.endLines = app.lines;
fc.features.map(f => f.properties).forEach(l => app.lines[l.id] = l);
app.startLines = Object.values(app.lines);
app.endLines = Object.values(app.lines);
linesResolver();
});
getty.jsonGet("/time").then(function (timeRange) {
......@@ -220,5 +238,10 @@ getty.jsonGet("/time").then(function (timeRange) {
app.maxDate = maxDate;
});
Promise.all([stopsPromise, linesPromise]).then(function() {
Object.values(app.stops).forEach(s => s.lines = []);
Object.values(app.lines).forEach(l => l.stops.forEach(sid => app.stops[sid].lines.push(l)));
});
window.app = app;
window.map = map;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment