X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=www%2Fmaps%2Fmaps%2Ftemplates%2Fjavascript%2Frouting.mako;h=3477d6b38fe6e68559d2e4f93dc79c40bcd7f99a;hb=709872b2c5db961fb12ce52a4122478e716dce00;hp=49e10b74d21274cbd867f153e7560053b0401272;hpb=01fd7fbb997f6e7017c92005702f4b80c9dbafb1;p=dead%2Fcensus-tools.git diff --git a/www/maps/maps/templates/javascript/routing.mako b/www/maps/maps/templates/javascript/routing.mako index 49e10b7..3477d6b 100644 --- a/www/maps/maps/templates/javascript/routing.mako +++ b/www/maps/maps/templates/javascript/routing.mako @@ -1,6 +1,8 @@ var producers = new Array(); var consumers = new Array(); +var postback_url = "${c.postback_url}"; + /* The URL encoding changes all of our double quotes to ", so we * have to convert them back before we do anything with the JSON * data. */ @@ -31,12 +33,12 @@ function routing_callback(result, status) { if (status == google.maps.DirectionsStatus.OK) { json_string += JSON.stringify(result); - for (var trip_idx = 0; trip_idx < result.trips.length; trip_idx++) { - num_routes = result.trips[trip_idx].routes.length; - if (num_routes > 1) { - alert("Unexpected number of routes (" + - result.trips.routes.length.toString() + - ") on trip number " + trip_idx.toString() + '.'); + for (var route_idx = 0; route_idx < result.routes.length; route_idx++) { + var num_legs = result.routes[route_idx].legs.length; + if (num_legs > 1) { + alert("Unexpected number of legs (" + + result.routes.legs.length.toString() + + ") on route number " + route_idx.toString() + '.'); } } } @@ -49,8 +51,8 @@ function routing_callback(result, status) { if (completed_requests == total_requests) { // Close the array, and do something with the result. json_string += ']'; - mu = new MapUtils(); - mu.post_data('/directions/json_to_kml', json_string); + var F = new Form(); + F.post_data(postback_url, json_string); } else { // Continue the array. @@ -81,17 +83,32 @@ function get_directions(pairs_to_skip) { continue; } - var producer_latlng = new google.maps.LatLng(producers[i].latitude, - producers[i].longitude); - - var consumer_latlng = new google.maps.LatLng(consumers[i].latitude, - consumers[i].longitude); + /* We'll pass these to the DirectionsRequest object. They aren't + * necessarily LatLngs, since if either the latitude or + * longitude is missing, we'll fall back to using the name. */ + var producer_latlng; + var consumer_latlng; + if (producers[i].latitude && producers[i].longitude) { + producer_latlng = new google.maps.LatLng(producers[i].latitude, + producers[i].longitude); + } + else { + producer_latlng = producers[i].name; + } + + if (consumers[j].latitude && consumers[j].longitude) { + consumer_latlng = new google.maps.LatLng(consumers[j].latitude, + consumers[j].longitude); + } + else { + consumer_latlng = consumers[j].name; + } + var directions_request = { origin: producer_latlng, destination: consumer_latlng, - provideTripAlternatives: true, - + provideTripAlternatives: true, travelMode: google.maps.DirectionsTravelMode.DRIVING }