Skip to content
This repository has been archived by the owner on Mar 12, 2022. It is now read-only.

[WIP] Station hierarchy #293

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
48 changes: 48 additions & 0 deletions app/components/stop-map/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Ember from 'ember';
/* global L */

var stopStationIcon = L.icon({
iconUrl: 'assets/images/search-active.png',
iconSize: [36, 54],
iconAnchor: [18, 54],
popupAnchor: [0, -54]
});

var stopPlatformIcon = L.icon({
iconUrl: 'assets/images/capital-l.png',
iconSize: [16, 16],
iconAnchor: [8, 8],
popupAnchor: [0, -16]
});

var stopEgressIcon = L.icon({
iconUrl: 'assets/images/capital-l.png',
iconSize: [16, 16],
iconAnchor: [8, 8],
popupAnchor: [0, -16]
});

export default Ember.Component.extend({
stopPlatformIcon: stopPlatformIcon,
stopEgressIcon: stopEgressIcon,
stopStationIcon: stopStationIcon,
lat: 0,
lng: 0,
zoom: 0,
bounds: null,
actions: {
selectStop(stop) {
this.sendAction('selectStop', stop);
},
unselectStop(stop) {
this.sendAction('unselectStop', stop);
},
setOnestopId(stop) {
this.sendAction('setOnestopId', stop);
},
updateStopLocation(stop, e) {
let location = e.target.getLatLng();
stop.setCoordinates([location.lng, location.lat]);
}
}
});
54 changes: 54 additions & 0 deletions app/components/stop-map/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{#each stops as |stop|}}

{{#marker-layer
icon=stopStationIcon
location=stop.coordinates
clickable=true
draggable=false
riseOnHover=true
riseOffset=1000
onMouseover=(action "selectStop" stop)
onMouseout=(action "unselectStop" stop)
onClick=(action "setOnestopId" stop)
}}
{{/marker-layer}}

{{#each stop.stop_platforms as |stop_platform|}}
{{#marker-layer
icon=stopPlatformIcon
location=stop_platform.coordinates
clickable=true
draggable=false
riseOnHover=true
riseOffset=1000
onMouseover=(action "selectStop" stop_platform)
onMouseout=(action "unselectStop" stop_platform)
onClick=(action "setOnestopId" stop_platform)
}}
{{/marker-layer}}
{{/each}}

{{#each stop.stop_egresses as |stop_egress|}}
{{#marker-layer
icon=stopEgressIcon
location=stop_egress.coordinates
clickable=true
draggable=false
riseOnHover=true
riseOffset=1000
onMouseover=(action "selectStop" stop_egress)
onMouseout=(action "unselectStop" stop_egress)
onClick=(action "setOnestopId" stop_egress)
}}
{{/marker-layer}}
{{/each}}

{{#polygon-layer locations=stop.stationPlatformLines color="red"}}
Platforms
{{/polygon-layer}}

{{#polygon-layer locations=stop.stationEgressLines color="blue"}}
Egresses
{{/polygon-layer}}

{{/each}}
30 changes: 30 additions & 0 deletions app/data/transitland/stop-egress/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Ember from 'ember';
import DS from 'ember-data';
import Stop from '../stop/model';

export default Stop.extend({
parent_stop: DS.belongsTo('data/transitland/stop-station', { modelFor: 'data/transitland/stop-station' }),
parent_stop_onestop_id: Ember.computed('parent_stop', {
get(key) {
return this.get('parent_stop').get('id');
},
set(key, value) {
this.set('parent_stop', value);
}
}),
entityType: function() {
return 'stopEgress';
},
toChange: function() {
return {
onestopId: this.id,
parentStopOnestopId: this.get('parent_stop').get('id'),
name: this.get('name'),
timezone: this.get('timezone'),
geometry: {
type: "Point",
coordinates: this.get('geometry').coordinates
}
};
}
});
5 changes: 5 additions & 0 deletions app/data/transitland/stop-egress/serializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import DS from 'ember-data';
import TransitlandSerializer from "../serializer";

export default TransitlandSerializer.extend({
});
30 changes: 30 additions & 0 deletions app/data/transitland/stop-platform/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Ember from 'ember';
import DS from 'ember-data';
import Stop from '../stop/model';

export default Stop.extend({
parent_stop: DS.belongsTo('data/transitland/stop-station', { modelFor: 'data/transitland/stop-station' }),
parent_stop_onestop_id: Ember.computed('parent_stop', {
get(key) {
return this.get('parent_stop').get('id');
},
set(key, value) {
this.set('parent_stop', value);
}
}),
entityType: function() {
return 'stopPlatform';
},
toChange: function() {
return {
onestopId: this.id,
parentStopOnestopId: this.get('parent_stop').get('id'),
name: this.get('name'),
timezone: this.get('timezone'),
geometry: {
type: "Point",
coordinates: this.get('geometry').coordinates
}
};
}
});
5 changes: 5 additions & 0 deletions app/data/transitland/stop-platform/serializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import DS from 'ember-data';
import TransitlandSerializer from "../serializer";

export default TransitlandSerializer.extend({
});
7 changes: 7 additions & 0 deletions app/data/transitland/stop-station/adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import TransitlandAdapter from "../adapter";

export default TransitlandAdapter.extend({
pathForType: function(modelName){
return "stop_stations";
}
});
56 changes: 56 additions & 0 deletions app/data/transitland/stop-station/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Ember from 'ember';
import DS from 'ember-data';
import Stop from '../stop/model';

function next_fragment(entities, separator) {
var ids = entities.map(function(i) {return i.id.split(separator)[1]; });
var fragment = "";
for (var i=0; i < 1000; i++) {
fragment = String(i);
if (ids.indexOf(fragment) === -1) {
break;
}
}
return fragment;
}

export default Stop.extend({
stop_platforms: DS.hasMany('data/transitland/stop-platform', { modelFor: 'data/transitland/stop-platform', inverse: 'parent_stop'}),
stop_egresses: DS.hasMany('data/transitland/stop-egress', { modelFor: 'data/transitland/stop-platform', inverse: 'parent_stop'}),
stationPlatformLines: Ember.computed('geometry', 'stop_platforms.@each.geometry', function() {
var origin = this.get('coordinates');
return this.get('stop_platforms').map(function(stop_platform) {
return [origin, stop_platform.get('coordinates')];
});
}),
stationEgressLines: Ember.computed('geometry', 'stop_egresses.@each.geometry', function() {
var origin = this.get('coordinates');
return this.get('stop_egresses').map(function(stop_platform) {
return [origin, stop_platform.get('coordinates')];
});
}),
newPlatform: function() {
var separator = '<';
var fragment = next_fragment(this.get('stop_platforms'), separator);
return this.get('stop_platforms').createRecord(
{
id: this.id + separator + fragment,
timezone: this.get('timezone'),
geometry: this.get('geometry'),
name: 'New Platform'
}
);
},
newEgress: function() {
var separator = '>';
var fragment = next_fragment(this.get('stop_egresses'), separator);
return this.get('stop_egresses').createRecord(
{
id: this.id + separator + fragment,
timezone: this.get('timezone'),
geometry: this.get('geometry'),
name: 'New Egress'
}
);
}
});
16 changes: 16 additions & 0 deletions app/data/transitland/stop-station/serializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import DS from 'ember-data';
import TransitlandSerializer from "../serializer";

export default TransitlandSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
stop_platforms: {
deserialize: 'records'
},
stop_egresses: {
deserialize: 'records'
}
},
modelNameFromPayloadKey: function(payloadKey){
return "data/transitland/stop-station";
}
});
42 changes: 33 additions & 9 deletions app/data/transitland/stop/model.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import Ember from 'ember';
import DS from 'ember-data';

var Stop = DS.Model.extend({
identifiers: DS.attr(),
imported_from_feed_onestop_ids: DS.attr('string'),
export default DS.Model.extend({
// Datastore
// created_or_updated_in_changeset: DS.belongsTo('changeset', { async: true }),
onestop_id: Ember.computed.alias('id'),
geometry: DS.attr(),
name: DS.attr('string'),
tags: DS.attr(),
timezone: DS.attr('string'),
created_at: DS.attr('date'),
updated_at: DS.attr('date'),
geometry: DS.attr(),
tags: DS.attr(),
timezone: DS.attr('string'),
identifiers: DS.attr(),
imported_from_feed_onestop_ids: DS.attr('string'),
operators_serving_stop: DS.attr(),
routes_serving_stop: DS.attr(),

// Explorer
rsp_stop_pattern_number: null,
location: (function(){
return this.get('geometry')['coordinates'].reverse();
}).property('geometry'),
Expand All @@ -24,7 +29,26 @@ var Stop = DS.Model.extend({
return 'svg-stop';
}
}),
rsp_stop_pattern_number: null
});

export default Stop;
// Dispatcher
coordinates: Ember.computed('geometry', function () {
return this.get('geometry').coordinates.slice().reverse();
}),
setCoordinates: function(value) {
this.set('geometry', {type: 'Point', coordinates: value.map(function(c) { return parseFloat(c.toFixed(5)); } ) });
},
entityType: function() {
return 'stop';
},
toChange: function() {
return {
onestopId: this.id,
name: this.get('name'),
timezone: this.get('timezone'),
geometry: {
type: "Point",
coordinates: this.get('geometry').coordinates
}
};
}
});
2 changes: 1 addition & 1 deletion app/stops/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default Ember.Route.extend(mapBboxRoute, setLoading, {
this.store.unloadAll('data/transitland/stop');
this.store.unloadAll('data/transitland/route');
this.store.unloadAll('data/transitland/route_stop_pattern');
return this.store.query('data/transitland/stop', params).then(function(stops) {
return this.store.query('data/transitland/stop_station', params).then(function(stops) {
var onlyStop, stopLocation, mode, url;
if (stops.get('query.isochrone_mode')){
onlyStop = stops.get('firstObject');
Expand Down
Loading