]> git.openstreetmap.org Git - rails.git/commitdiff
Start MapQuest Open support
authorRichard Fairhurst <richard@systemeD.net>
Wed, 22 Jan 2014 15:53:35 +0000 (15:53 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Wed, 22 Jan 2014 15:53:35 +0000 (15:53 +0000)
app/assets/javascripts/routing_engines/cloudmade_foot.js
app/assets/javascripts/routing_engines/mapquest_bicycle.js [new file with mode: 0644]

index 3d047f8ab766862d17b82be65a76797c2ad05738..149ceb31a3f4848584e2bcaf476260fc7aac3a26 100644 (file)
@@ -1,6 +1,7 @@
 // CloudMade foot engine
 // *** again, this should be shared from a Cloudmade library somewhere
 // *** this API key is taken from some example code, not for real live use!
 // CloudMade foot engine
 // *** again, this should be shared from a Cloudmade library somewhere
 // *** this API key is taken from some example code, not for real live use!
+// http://cloudmade.com/documentation/routing
 
 OSM.RoutingEngines.list.push({
        name: 'Foot (CloudMade)',
 
 OSM.RoutingEngines.list.push({
        name: 'Foot (CloudMade)',
@@ -16,7 +17,7 @@ OSM.RoutingEngines.list.push({
                url+="/foot.js";
                this.requestJSONP(url+"?callback=");
        },
                url+="/foot.js";
                this.requestJSONP(url+"?callback=");
        },
-       gotRoute: function(data) {
+       gotRoute: function(router,data) {
                console.log(data);
                // *** todo
                // *** will require some degree of refactoring because instruction text is pre-assembled
                console.log(data);
                // *** todo
                // *** will require some degree of refactoring because instruction text is pre-assembled
diff --git a/app/assets/javascripts/routing_engines/mapquest_bicycle.js b/app/assets/javascripts/routing_engines/mapquest_bicycle.js
new file mode 100644 (file)
index 0000000..123f270
--- /dev/null
@@ -0,0 +1,35 @@
+// see: 
+// http://developer.mapquest.com/web/products/open/directions-service
+// http://open.mapquestapi.com/directions/
+// https://github.com/apmon/openstreetmap-website/blob/21edc353a4558006f0ce23f5ec3930be6a7d4c8b/app/controllers/routing_controller.rb#L153
+
+// *** needs to give credit
+
+OSM.RoutingEngines.list.push({
+       name: 'Bicycle (MapQuest Open)',
+       draggable: true,
+       _hints: {},
+       getRoute: function(final,points) {
+               var url="http://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(',');
+               url+="&routeType=bicycle";
+               url+="&manMaps=false";
+               url+="&shapeFormat=raw&generalize=0";
+               this.requestJSONP(url+"&callback=");
+       },
+       gotRoute: function(router,data) {
+               var poly=[];
+               var shape=data.route.shape.shapePoints;
+               for (var i=0; i<shape.length; i+=2) {
+                       poly.push(L.latLng(shape[i],shape[i+1]));
+               }
+               router.setPolyline(poly);
+
+               // data.shape.maneuverIndexes links turns to polyline positions
+               // data.legs[0].maneuvers is list of turns
+               console.log(data);
+//             router.setItinerary(data.route_instructions);
+       }
+});