]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/routing.js.erb
Apparently 'final' is a reserved word in JS...
[rails.git] / app / assets / javascripts / routing.js.erb
index 0c11f93a06af0ba8546dc0a84e7b962f3149f86b..7f18aa472d612f12d37b56240c5c80f3b57c70b9 100644 (file)
@@ -10,6 +10,7 @@
        *** translation (including all alerts and presentation)
        *** export GPX
        *** URL history (or do we consciously not want to support that?)
+       *** spinner when waiting for result (beneath 'Go' button?)
 
        *** add YOURS engine
        *** add GraphHopper engine
@@ -105,7 +106,7 @@ OSM.Routing=function(map,name,jqSearch) {
                field.value=json[0].display_name;
                var lat=Number(json[0].lat), lon=Number(json[0].lon);
                r[field.id]=[lat,lon];
-               r.updateMarkers(field.id);
+               r.updateMarker(field.id);
                if (r.awaitingGeocode) {
                        r.awaitingGeocode=false;
                        r.requestRoute(true);
@@ -119,7 +120,7 @@ OSM.Routing=function(map,name,jqSearch) {
                var ll=r.map.mouseEventToLatLng(e.originalEvent);
                // *** ^^^ this is slightly off - we need to work out the latLng of the tip
                r.createMarker(ll,id);
-               r[id.replace('marker','route')]=[ll.lat,ll.lng];
+               r.setNumericInput(ll,id);
                r.requestRoute(true);
                // update to/from field
        };
@@ -133,25 +134,35 @@ OSM.Routing=function(map,name,jqSearch) {
                r[id].on('drag',r.markerDragged);
                r[id].on('dragend',r.markerDragged);
        };
-       r.updateMarkers=function(id) {
+       // Update marker from geocoded route input
+       r.updateMarker=function(id) {
+               var m=id.replace('route','marker');
+               if (!r[m]) { r.createMarker(r[id],m); return; }
+               var ll=r[m].getLatLng();
+               if (ll.lat!=r[id][0] || ll.lng!=r[id][1]) {
+                       r.createMarker(r[id],m);
+               }
        };
+       // Marker has been dragged
        r.markerDragged=function(e) {
-               // marker has been dragged
                if (e.type=='drag' && !r.chosenEngine.draggable) return;
                if (e.type=='drag' && r.awaitingRoute) return;
-               var id=e.target.options.name;
-               var ll=e.target.getLatLng();
-               r[id.replace('marker','route')]=[ll.lat,ll.lng];
+               r.setNumericInput(e.target.getLatLng(), e.target.options.name);
                r.requestRoute(e.type=='dragend');
-               // update to/from field
        };
+       // Set a route input field to a numeric value
+       r.setNumericInput=function(ll,id) {
+               var routeid=id.replace('marker','route');
+               r[routeid]=[ll.lat,ll.lng];
+               $("[name="+routeid+"]:visible").val(Math.round(ll.lat*10000)/10000+" "+Math.round(ll.lng*10000)/10000);
+       }
        
        // Route-fetching UI
 
-       r.requestRoute=function(final) {
+       r.requestRoute=function(isFinal) {
                if (r.route_from && r.route_to) {
                        r.awaitingRoute=true;
-                       r.chosenEngine.getRoute(final,[r.route_from,r.route_to]);
+                       r.chosenEngine.getRoute(isFinal,[r.route_from,r.route_to]);
                        // then, when the route has been fetched, it'll call the engine's gotRoute function
                } else if (r.route_from==false || r.route_to==false) {
                        // we're waiting for a Nominatim response before we can request a route