]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/routing_engines/osrm_car.js
Move routing engines into their own files
[rails.git] / app / assets / javascripts / routing_engines / osrm_car.js
1 // OSRM car engine
2 // *** this should all be shared from an OSRM library somewhere
3 // *** need to clear hints at some point
4
5 OSM.RoutingEngines.list.push({
6         name: 'Car (OSRM)',
7         draggable: true,
8         _hints: {},
9         getRoute: function(final,points) {
10                 var url="http://router.project-osrm.org/viaroute?z=14&output=json";
11                 for (var i=0; i<points.length; i++) {
12                         var pair=points[i].join(',');
13                         url+="&loc="+pair;
14                         if (this._hints[pair]) url+= "&hint="+this._hints[pair];
15                 }
16                 if (final) url+="&instructions=true";
17                 this.requestJSONP(url+"&jsonp=");
18         },
19         gotRoute: function(router,data) {
20                 if (data.status==207) {
21                         alert("Couldn't find route between those two places");
22                         return false;
23                 }
24                 // *** store hints
25                 var line=L.PolylineUtil.decode(data.route_geometry);
26                 for (i=0; i<line.length; i++) { line[i].lat/=10; line[i].lng/=10; }
27                 router.setPolyline(line);
28                 router.setItinerary(data.route_instructions);
29         }
30 });