From: Michael Orlitzky Date: Wed, 24 Feb 2010 18:09:09 +0000 (-0500) Subject: Added a postback_url parameter to determine where the JSON data is posted. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=1488c9240cc00aee34c0bc7a63133625a8225900;p=dead%2Fcensus-tools.git Added a postback_url parameter to determine where the JSON data is posted. Modified the construction of the DirectionsRequest so that latitude and longitude are optional. --- diff --git a/www/maps/maps/templates/javascript/routing.mako b/www/maps/maps/templates/javascript/routing.mako index e399959..ecab024 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. */ @@ -50,7 +52,7 @@ function routing_callback(result, status) { // Close the array, and do something with the result. json_string += ']'; var F = new Form(); - F.post_data('/directions/json_to_kml', json_string); + 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[i].latitude && consumers[i].longitude) { + consumer_latlng = new google.maps.LatLng(consumers[i].latitude, + consumers[i].longitude); + } + else { + consumer_latlng = consumers[i].name; + } + var directions_request = { origin: producer_latlng, destination: consumer_latlng, - provideTripAlternatives: true, - + provideTripAlternatives: true, travelMode: google.maps.DirectionsTravelMode.DRIVING }