]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/routing_engines/mapquest.js
Merge pull request #18 from danstowell/jsrouting-durationcalc
[rails.git] / app / assets / javascripts / routing_engines / mapquest.js
index eb92893b32e3fa1b947ff2dc9c328d12029a7314..dc854ccdc9dffd38ccbfc5b88888e110f01adb12 100644 (file)
@@ -40,7 +40,7 @@ MapQuestEngine.prototype.createConfig = function() {
             18: 1  // straight fork
         },
         getRoute: function(isFinal,points) {
             18: 1  // straight fork
         },
         getRoute: function(isFinal,points) {
-            var url="http://open.mapquestapi.com/directions/v2/route?key=Fmjtd%7Cluur290anu%2Crl%3Do5-908a0y";
+            var url=document.location.protocol+"//open.mapquestapi.com/directions/v2/route?key=Fmjtd%7Cluur290anu%2Crl%3Do5-908a0y";
             var from=points[0]; var to=points[points.length-1];
             url+="&from="+from.join(',');
             url+="&to="+to.join(',');
             var from=points[0]; var to=points[points.length-1];
             url+="&from="+from.join(',');
             url+="&to="+to.join(',');
@@ -60,14 +60,27 @@ MapQuestEngine.prototype.createConfig = function() {
             }
             router.setPolyline(poly);
 
             }
             router.setPolyline(poly);
 
-            // data.shape.maneuverIndexes links turns to polyline positions
-            // data.legs[0].maneuvers is list of turns
+            // data.route.shape.maneuverIndexes links turns to polyline positions
+            // data.route.legs[0].maneuvers is list of turns
             var steps=[];
             var mq=data.route.legs[0].maneuvers;
             for (var i=0; i<mq.length; i++) {
                 var s=mq[i];
             var steps=[];
             var mq=data.route.legs[0].maneuvers;
             for (var i=0; i<mq.length; i++) {
                 var s=mq[i];
-                var d=(i==mq.length-1) ? 15: this.MQ_SPRITE_MAP[s.turnType];
-                steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance*1000]);
+                var d;
+                var linesegstart, linesegend, lineseg;
+                linesegstart = data.route.shape.maneuverIndexes[i];
+                if (i==mq.length-1) {
+                    d = 15;
+                    linesegend = linesegstart + 1;
+                } else {
+                    d = this.MQ_SPRITE_MAP[s.turnType];
+                    linesegend = data.route.shape.maneuverIndexes[i+1] + 1;
+                }
+                lineseg = [];
+                for (var j=linesegstart; j<linesegend; j++) {
+                    lineseg.push(L.latLng(data.route.shape.shapePoints[j*2], data.route.shape.shapePoints[j*2+1]));
+                }
+                steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance*1000, lineseg]);
             }
             router.setItinerary( { steps: steps, distance: data.route.distance*1000, time: data.route['time'] });
             return true;
             }
             router.setItinerary( { steps: steps, distance: data.route.distance*1000, time: data.route['time'] });
             return true;
@@ -75,7 +88,7 @@ MapQuestEngine.prototype.createConfig = function() {
     };
 };
 
     };
 };
 
-OSM.RoutingEngines.list.push(new MapQuestEngine("Bicycle", "routeType=bicycle").createConfig());
-OSM.RoutingEngines.list.push(new MapQuestEngine("Foot", "routeType=pedestrian").createConfig());
-OSM.RoutingEngines.list.push(new MapQuestEngine("Car", "routeType=fastest").createConfig());
+OSM.RoutingEngines.add(true, new MapQuestEngine("Bicycle", "routeType=bicycle").createConfig());
+OSM.RoutingEngines.add(true, new MapQuestEngine("Foot", "routeType=pedestrian").createConfig());
+OSM.RoutingEngines.add(true, new MapQuestEngine("Car", "routeType=fastest").createConfig());
 // can be: routeType=fastest|shortest|pedestrian|multimodal|bicycle
 // can be: routeType=fastest|shortest|pedestrian|multimodal|bicycle