]> gitweb.michael.orlitzky.com - dead/census-tools.git/commitdiff
Added a postback_url parameter to determine where the JSON data is posted.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 24 Feb 2010 18:09:09 +0000 (13:09 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 24 Feb 2010 18:09:09 +0000 (13:09 -0500)
Modified the construction of the DirectionsRequest so that latitude and longitude are optional.

www/maps/maps/templates/javascript/routing.mako

index e399959a5af1cfe738257e645ad78100291e7e6e..ecab0247e9252e8b1af10409f41ef6e039dd3057 100644 (file)
@@ -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 &quot;, 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
       }