]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions.js
Update minimum ruby version to 3.2
[rails.git] / app / assets / javascripts / index / directions.js
index 3d6da84fc8d279d51e723dc0babfd3f721833ebb..3d52ec9fb6b19a853e768f1bf3575d62f4db7e23 100644 (file)
@@ -36,6 +36,8 @@ OSM.Directions = function (map) {
     OSM.DirectionsEndpoint(map, $("input[name='route_to']"), OSM.MARKER_RED, endpointDragCallback, endpointChangeCallback)
   ];
 
     OSM.DirectionsEndpoint(map, $("input[name='route_to']"), OSM.MARKER_RED, endpointDragCallback, endpointChangeCallback)
   ];
 
+  let downloadURL = null;
+
   const expiry = new Date();
   expiry.setYear(expiry.getFullYear() + 10);
 
   const expiry = new Date();
   expiry.setYear(expiry.getFullYear() + 10);
 
@@ -189,6 +191,16 @@ OSM.Directions = function (map) {
         turnByTurnTable.append(row);
       });
 
         turnByTurnTable.append(row);
       });
 
+      const blob = new Blob([JSON.stringify(polyline.toGeoJSON())], { type: "application/json" });
+      URL.revokeObjectURL(downloadURL);
+      downloadURL = URL.createObjectURL(blob);
+
+      $("#sidebar_content").append(`<p class="text-center"><a href="${downloadURL}" download="${
+        I18n.t("javascripts.directions.filename")
+      }">${
+        I18n.t("javascripts.directions.download")
+      }</a></p>`);
+
       $("#sidebar_content").append("<p class=\"text-center\">" +
         I18n.t("javascripts.directions.instructions.courtesy", { link: chosenEngine.creditline }) +
         "</p>");
       $("#sidebar_content").append("<p class=\"text-center\">" +
         I18n.t("javascripts.directions.instructions.courtesy", { link: chosenEngine.creditline }) +
         "</p>");