diff options
author | Christopher Baines <cb15g11@soton.ac.uk> | 2014-05-28 17:42:23 +0100 |
---|---|---|
committer | Christopher Baines <cb15g11@soton.ac.uk> | 2014-05-28 17:42:23 +0100 |
commit | e4598474147b7250e798056a3bede51f30517c60 (patch) | |
tree | 8f1fa7dcbee0b19a22616fb445f7531d1256640f | |
parent | 46a9b15c8a24d6186c85b61c0239c1b99a15d070 (diff) | |
download | leaflet-soton-e4598474147b7250e798056a3bede51f30517c60.tar leaflet-soton-e4598474147b7250e798056a3bede51f30517c60.tar.gz |
Bus routes are back
-rwxr-xr-x | create-data.js | 49 | ||||
-rw-r--r-- | src/leaflet-soton.js | 11 |
2 files changed, 41 insertions, 19 deletions
diff --git a/create-data.js b/create-data.js index 2b0db11..9b4cfe3 100755 --- a/create-data.js +++ b/create-data.js @@ -960,6 +960,11 @@ function loadBusData(collections, callback) { function(routeMasters, callback) { var stopAreaRoutes = {} // Mapping from id to stop area, also contains the route names for that stop area + collections.busRoutes = { + type: "FeatureCollection", + features: [] + }; + async.each(routeMasters, function(routeMaster, callback) { async.each(routeMaster.members, function(member, callback) { getRelation(member.ref, function(err, route) { @@ -1000,11 +1005,23 @@ function loadBusData(collections, callback) { }); } - var flattenedCoords = []; - flattenedCoords = flattenedCoords.concat.apply(flattenedCoords, routeCoords); - var colour = ('colour' in route.tags) ? route.tags.colour : routeMaster.tags.colour; + var busRoute = { + type: "Feature", + geometry: { + type: "LineString", + coordinates: routeCoords + }, + properties: { + colour: colour, + name: route.tags.name, + ref: route.tags.ref + } + } + + collections.busRoutes.features.push(busRoute); + callback(); }); }); @@ -1030,6 +1047,9 @@ function loadBusData(collections, callback) { function createRouteGeometry(ways, callback) { var routeCoords = []; + var errors = []; + + //console.log(JSON.stringify(ways.slice(2)), null, 4); function last(way) { return way.slice(-1)[0]; @@ -1043,26 +1063,31 @@ function createRouteGeometry(ways, callback) { return coord1[0] === coord2[0] && coord1[1] === coord2[1]; } - // Determine the orientation of the first way - if (equal(last(ways[0]), first(ways[1])) || equal(last(ways[0]), last(ways[1]))) { - routeCoords = ways[0]; - } else { - routeCords = ways[0].reverse(); + // If the first way end joins with the 2nd way start or end, leave it as is + if (!(equal(last(ways[0]), first(ways[1])) || equal(last(ways[0]), last(ways[1])))) { + ways[0].reverse(); + + // Check if this reversed starting way works + if (!(equal(last(ways[0]), first(ways[1])) || equal(last(ways[0]), last(ways[1])))) { + errors.push("cannot determine correct alignment of first way"); + } } - var errors = []; + // Add a clone such that the pop in the following loop does not modify the + // original array + routeCoords = ways[0].slice(0); for (var i=1; i<ways.length; i++) { var way = ways[i]; // pop the end node, as this will be present on the next way added - routeCords.pop(); + routeCoords.pop(); if (equal(last(ways[i-1]), first(way))) { - routeCords.push.apply(routeCords, way); + routeCoords.push.apply(routeCoords, way); } else { if (!equal(last(ways[i-1]), last(way))) { - errors.push("break detected at " + i); + errors.push("break detected at " + i + " " + last(ways[i-1]) + " " + last(way)); } routeCoords.push.apply(routeCoords, way.reverse()); } diff --git a/src/leaflet-soton.js b/src/leaflet-soton.js index 5f97e43..77f0d02 100644 --- a/src/leaflet-soton.js +++ b/src/leaflet-soton.js @@ -315,7 +315,7 @@ SELECT * WHERE {\ var emptyFeatureCollection = { type: "FeatureCollection", features: [] }; var transparaentStyle = function(feature) {return {weight: 0, opacity: 0, fillOpacity: 0};}; - var layerNames = ['sites', 'parking', 'bicycleParking', 'buildings', 'busStops' /*'busRoutes',*/]; + var layerNames = ['sites', 'parking', 'bicycleParking', 'buildings', 'busStops', 'busRoutes']; var busRouteStyle = function(feature) { return {weight: 5, opacity: 0.5, color: feature.properties.colour}; @@ -354,10 +354,6 @@ SELECT * WHERE {\ options.highlight = {}; } - var overlayMaps = { - //"Bus Routes": self.layers.busRoutes, - }; - if ("Hash" in L) { var hash; if (this.options.indoor) { @@ -384,7 +380,7 @@ SELECT * WHERE {\ return {weight: 5, opacity: 0.5, color: 'blue'}; } else if (layerName === "busRoutes") { - return busRouteStyle(); + return busRouteStyle(feature); } else { return blankStyle(); } @@ -897,7 +893,8 @@ SELECT * WHERE {\ buildings: buildingTemplate, bicycleParking: bicycleParkingTemplate, parking: parkingTemplate, - busStops: busStopTemplate + busStops: busStopTemplate, + busRoutes: busRouteTemplate }; function roomPopupTemplate(properties) { |