Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Hides garaged buses. #47

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
db = None
curDateTime = None
collectionPrefix = None
busParkJsonString = '[]'

# load bus park data
try:
busParkJsonString = json.dumps(json.load(open('static/data/bus_parks.js')))

except IOError as e:
print 'Error Opening Bus Park File:', e

except ValueError as e:
print 'Bus Park File JSON Format Error:', e

@app.before_request
def beforeRequest():
Expand Down Expand Up @@ -188,6 +199,10 @@ def getNextBus(routeId, stopId):
pass
return json.dumps(data, default=dthandler)

@app.route('/api/bus_parks/')
def getBusParks():
return busParkJsonString

if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
Expand Down
22 changes: 22 additions & 0 deletions web/static/data/bus_parks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"name": "South Garage",
"description": "South Garage 18th St, Norfolk.",
"path": [
[36.86503, -76.28412],
[36.86363, -76.28431],
[36.86381, -76.27974],
[36.86527, -76.28019]
]
},
{
"name": "North Garage",
"description": "North Garage Victoria Blvd, Hampton.",
"path": [
[37.01356, -76.36571],
[37.01210, -76.36551],
[37.01222, -76.36404],
[37.01433, -76.36412]
]
}
]
80 changes: 75 additions & 5 deletions web/static/js/busfinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,88 @@ $(function(){
this.selectedBus.showDetails();
}
});


var BusParkView = Backbone.View.extend({
initialize: function () {
_.bindAll(this);

this.polygons = [];

this.collection = new Backbone.Collection();
this.collection.url = '/api/bus_parks/';
this.collection.on('reset', this.updatePolygons);
this.collection.fetch();
},

updatePolygons: function () {
// remove all polygons from map
this.polygons.forEach(function (polygon) {
polygon.setMap(null);
});

var polygons = this.polygons = [];

// create polygons from busPark collection
this.collection.each(function (busPark) {
// build path from collection
var LatLng = google.maps.LatLng;
var path = [];

busPark.get('path').forEach(function (point) {
path.push(new LatLng(point[0], point[1]));
});

var polygon = new google.maps.Polygon({
map: Map,
fillColor: 'DarkOrchid',
strokeColor: 'DeepPink',
strokeWeight: 1,
paths: [path]
});

polygons.push(polygon);
});
},

contains: function (bus) {
var geometry = google.maps.geometry;

for (var i = 0; i < this.polygons.length; i += 1) {
if (geometry.poly.containsLocation(bus.position,
this.polygons[i])) {

return true;
}
}

return false;
},

destroy: function () {
this.polygons.forEach(function (polygon) {
polygon.setMap(null);
});

this.remove();
}
});

var BusView = Backbone.View.extend({
initialize: function() {
_.bindAll(this);
this.collection = new Backbone.Collection;
this.collection.url = '/api/buses/history/' + this.model.get('busId');
this.collection.on('reset', this.createPath, this);
this.collection.fetch();
this.createMarker();
this.position = new google.maps.LatLng(this.model.get('location')[1], this.model.get('location')[0]);

// don't display marker if in the bus park
if (!busParkView.contains(this)) {
this.createMarker();
}
},

createMarker: function () {
this.position = new google.maps.LatLng(this.model.get('location')[1], this.model.get('location')[0]);

var icon;

if (this.model.get('direction') === 0) {
Expand Down Expand Up @@ -591,7 +659,9 @@ $(function(){
App.ContentView.setSubView(new NextBusView({ collection: stopTimes, stop: stop, route: route }));
}
});


var busParkView = new BusParkView();

var App = {
MapView: new MapView,
ContentView: new ContentView,
Expand Down