PageSourceSearch

https://www.openstreetmap.org/assets/index_modules/directions-9fa8…b2c2218750bbea7e7e74991f5ce960ee0b84af24.js

js openstreetmap.org collected 2026-09-24 06:40:40 UTC 19,030 bytes, 1 lines download raw bytes

1function Endpoint(e,t,n,r,o){function i(n){const{lat:o,lng:i}=OSM.cropLocation(n.target.getLatLng(),e.getZoom()),a=L.latLng(o,i);h.geocodeRequest&&h.geocodeRequest.abort(),delete h.geocodeRequest,u(a),g(a),h.value=t.val(),"dragend"===n.type&&d(),r("drag"===n.type)}function a(){t.removeClass("is-invalid")}function s(e){const t=e.target.value;h.setValue(t)}function c(e,t){if(!e)return null;for(const n of t){const t=e.find(e=>e.type===n);if(t)return t}return null}function l(){function n(e){if(delete h.geocodeRequest,0===e.length)return t.addClass("is-invalid"),void OSM.showAlert(OSM.i18n.t("javascripts.directions.errors.no_place.title"),OSM.i18n.t("javascripts.directions.errors.no_place.body",{place:h.value}));u(L.latLng(c(e[0].entrances,["main","yes"])||e[0])),h.value=e[0].display_name,t.val(e[0].display_name),o()}const r=e.getBounds().toBBoxString(),i=OSM.NOMINATIM_URL+"search?"+new URLSearchParams({q:h.value,format:"json",viewbox:r,limit:1,entrances:1});h.geocodeRequest=new AbortController,fetch(i,{signal:h.geocodeRequest.signal}).then(e=>e.json()).then(n).catch(()=>{})}function d(){function e(e){delete h.geocodeRequest,e&&e.display_name?(h.value=e.display_name,t.val(e.display_name),h.cachedReverseGeocode={latlng:n,value:h.value}):h.cachedReverseGeocode={latlng:n,notFound:!0}}const n=h.latlng.clone(),{lat:r,lng:o}=n,i=OSM.NOMINATIM_URL+"reverse?"+new URLSearchParams({lat:r,lon:o,format:"json"});h.geocodeRequest=new AbortController,fetch(i,{signal:h.geocodeRequest.signal}).then(e=>e.json()).then(e).catch(()=>{})}function u(n){t.attr("data-lat",n.lat).attr("data-lon",n.lng),h.latlng=n,h.marker.setLatLng(n).addTo(e)}function f(){t.removeAttr("data-lat").removeAttr("data-lon"),delete h.latlng}function g(e){t.val(e.lat+", "+e.lng)}const h={};return h.marker=L.marker([0,0],{icon:OSM.getMarker(n),draggable:!0,autoPan:!0}),h.enableListeners=function(){h.marker.on("drag",i),h.marker.on("dragend",i),t.on("keydown",a),t.on("change",s)},h.disableListeners=function(){h.marker.off("drag",i),h.marker.off("dragend",i),t.off("keydown",a),t.off("change",s)},h.setValue=function(e){h.geocodeRequest&&h.geocodeRequest.abort(),delete h.geocodeRequest,t.removeClass("is-invalid");const n=e.match(/^\s*([+-]?\d+(?:\.\d*)?)(?:\s+|\s*[/,]\s*)([+-]?\d+(?:\.\d*)?)\s*$/),r=n&&L.latLng(n[1],n[2]);if(r&&h.cachedReverseGeocode&&h.cachedReverseGeocode.latlng.equals(r))return u(r),h.cachedReverseGeocode.notFound?(h.value=e,t.addClass("is-invalid")):h.value=h.cachedReverseGeocode.value,t.val(h.value),void o();h.value=e,f(),t.val(e),r?(u(r),g(r),d(),o()):h.value&&l()},h.clearValue=function(){h.geocodeRequest&&h.geocodeRequest.abort(),delete h.geocodeRequest,f(),delete h.value,t.val(""),e.removeLayer(h.marker)},h.swapCachedReverseGeocodes=function(e){const t=h.cachedReverseGeocode,n=e.cachedReverseGeocode;delete h.cachedReverseGeocode,delete e.cachedReverseGeocode,t&&(e.cachedReverseGeocode=t),n&&(h.cachedReverseGeocode=n)},h}function py2_round(e){return Math.floor(Math.abs(e)+.5)*(e>=0?1:-1)}function encode(e,t,n){var r=2*((e=py2_round(e*n))-(t=py2_round(t*n)));r<0&&(r=-r-1);for(var o="";r>=32;)o+=String.fromCharCode(63+(32|31&r)),r/=32;return o+=String.fromCharCode(63+(0|r))}function flipped(e){for(var t=[],n=0;n<e.length;n++){var r=e[n].slice();t.push([r[1],r[0]])}return t}function RouteOutput(e){function t({distance:e,time:t,ascend:r,descend:o,steps:i}){$("#directions_route_distance").val(c.totalDistance(e)),$("#directions_route_time").val(c.time(t)),$("#directions_route_ascend_descend").prop("hidden",isNaN(r)||isNaN(o)),$("#directions_route_ascend").val(c.height(r)),$("#directions_route_descend").val(c.height(o)),$("#directions_route_steps").empty().append(...i.map(n))}function n([t,n,o,a],s){const l=`<b>${s+1}.</b> ${n}`;let d="";return t&&(d=`<svg width="20" height="20" class="d-block"><use href="#routing-sprite-${t}" /></svg>`),$("<tr class='turn'/>").append(`<td class='ps-3'>${d}</td>`).append(`<td class="text-break">${l}</td>`).append(`<td class="pe-3 distance text-body-secondary text-end">${c.stepDistance(o)}</td>`).on("click",()=>r.setLatLng(a[0]).setContent(`<p>${l}</p>`).openOn(e)).on("mouseenter",()=>i.setLatLngs(a).addTo(e)).on("mouseleave",()=>e.removeLayer(i))}const r=L.popup({autoPanPadding:[100,100]}),o=L.polyline([],{color:"#03f",opacity:.3,weight:10}),i=L.polyline([],{color:"#ff0",opacity:.5,weight:12});class a{constructor(e){const t=Object.entries(e).sort((e,t)=>
1e[1]-t[1]);[[this.minorName,this.minorScale],[this.majorName,this.majorScale]]=t}print(e,t){const n="javascripts.directions.distance_in_units";return OSM.i18n.t(e,{scope:n,distance:t})}totalDistance(e){const t=e/this.minorScale,n=e/this.majorScale;return t<1e3||n<.25?this.print(this.minorName,Math.round(t)):n<10?this.print(this.majorName,n.toFixed(1)):this.print(this.majorName,Math.round(n))}stepDistance(e){const t=e/this.minorScale,n=e/this.majorScale;return t<5?"":t<200?this.print(this.minorName,10*Math.round(t/10)):t<1500||n<.25?this.print(this.minorName,100*Math.round(t/100)):n<5?this.print(this.majorName,n.toFixed(1)):this.print(this.majorName,Math.round(n))}height(e){if(isNaN(e))return"";const t=e/this.minorScale;return this.print(this.minorName,Math.round(t))}time(e){let t=Math.round(e/60);const n=Math.floor(t/60);return t-=60*n,n+":"+(t<10?"0":"")+t}}const s={km_m:new a({km:1e3,m:1}),mi_ft:new a({mi:1609.344,ft:.3048}),mi_yd:new a({mi:1609.344,yd:.9144})};let c=s.km_m,l=null;const d={write:function(n){o.setLatLngs(n.line).addTo(e),t(n),$("#directions_distance_units_settings input").off().on("change",function(){c=s[this.value]||s.km_m,t(n)});const r=new Blob([JSON.stringify(o.toGeoJSON())],{type:"application/geo+json"});URL.revokeObjectURL(l),l=URL.createObjectURL(r),$("#directions_route_download").prop("href",l),$("#directions_route_credit").text(n.credit).prop("href",n.creditlink),$("#directions_route_demo").text(n.credit).prop("href",n.demolink)},fit:()=>e.fitBounds(o.getBounds().pad(.05)),isVisible:()=>e.hasLayer(o),remove:function(){e.removeLayer(r).removeLayer(o),$("#directions_distance_units_settings input").off(),$("#directions_route_steps").empty(),URL.revokeObjectURL(l),$("#directions_route_download").prop("href","")}};return d}OSM.directionsEngines=[],OSM.directionsEngines.add=function(e,t){("http:"===location.protocol||t)&&(e.id=e.provider+"_"+e.mode,OSM.directionsEngines.push(e))};var polyline={decode:function(e,t){for(var n,r=0,o=0,i=0,a=[],s=0,c=0,l=null,d=Math.pow(10,Number.isInteger(t)?t:5);r<e.length;){l=null,s=1,c=0;do{c+=(31&(l=e.charCodeAt(r++)-63))*s,s*=32}while(l>=32);n=1&c?(-c-1)/2:c/2,s=1,c=0;do{c+=(31&(l=e.charCodeAt(r++)-63))*s,s*=32}while(l>=32);o+=n,i+=1&c?(-c-1)/2:c/2,a.push([o/d,i/d])}return a},encode:function(e,t){if(!e.length)return"";for(var n=Math.pow(10,Number.isInteger(t)?t:5),r=encode(e[0][0],0,n)+encode(e[0][1],0,n),o=1;o<e.length;o++){var i=e[o],a=e[o-1];r+=encode(i[0],a[0],n),r+=encode(i[1],a[1],n)}return r},fromGeoJSON:function(e,t){if(e&&"Feature"===e.type&&(e=e.geometry),!e||"LineString"!==e.type)throw new Error("Input must be a GeoJSON LineString");return polyline.encode(flipped(e.coordinates),t)},toGeoJSON:function(e,t){return{type:"LineString",coordinates:flipped(polyline.decode(e,t))}}};"object"==typeof module&&module.exports&&(module.exports=polyline),OSM.decodePolyline=function(e,{precision:t}){return polyline.decode(e,t).map(([e,t])=>({lat:e,lng:t}))},function(){function e(e,t,n){function r(e){function t(e){return["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth"][e-1]}const n="javascripts.directions.instructions.";let r=n+{continue:"continue","merge right":"merge_right","merge left":"merge_left","off ramp right":"offramp_right","off ramp left":"offramp_left","on ramp right":"onramp_right","on ramp left":"onramp_left","fork right":"fork_right","fork left":"fork_left","end of road right":"endofroad_right","end of road left":"endofroad_left","turn straight":"continue","turn slight right":"slight_right","turn right":"turn_right","turn sharp right":"sharp_right","turn uturn from left":"uturn","turn uturn from right":"uturn","turn sharp left":"sharp_left","turn left":"turn_left","turn slight left":"slight_left",roundabout:"roundabout",rotary:"roundabout","exit roundabout":"exit_roundabout","exit rotary":"exit_roundabout",ferry:"ferry",depart:"start",arrive:"destination"}[e.maneuverId];const o="<b>"+e.destinations+"</b>";let i,a=!0;if(e.name&&e.ref?i="<b>"+e.name+" ("+e.ref+")</b>":e.name?i="<b>"+e.name+"</b>":e.ref?i="<b>"+e.ref+"</b>":(i=OSM.i18n.t(n+"unnamed"),a=!1),e.maneuver.type.match(/^exit (rotary|roundabout)$/))return OSM.i18n.t(r,{name:i});if(e.maneuver.type.match(/^(rotary|roundabout)$/))return e.maneuver.exit?e.maneuver.exit>10?OSM.i18n.t(r+"_with_exit",{exit:e.maneuver.exit,name:i}):OSM.i18n.t(r+"_with_exit_ordinal",{exit:OSM.i18n.t(n+"exit_counts."+t(e.maneuver.exit)),name:i}):OSM.i18n.t(r+"_without_exit",{name:i});if(!e.maneuver.type.match(/^(on ramp|off ramp)$/))return OSM.i18n.t(r+"_without_exit",{name:i});const s={};return e.exits&&e.maneuver.type.match(/^(off ramp)$/)&&(s.exit=e.exits),e.destinations&&(s.directions=o),a&&(s.directions=i),Object.keys(s).length>0&&(r=r+"_with_"+Object.keys(s).join("_")),OSM.i18n.t(r,s)}function o(e){function t({maneuver:{type:e,modifier:t},mode:n,intersections:r,driving_side:o}){if("ferry"===n)return"ferry";if(r.some(e=>e.classes?.includes("ferry")))return"ferry";if("uturn"===t)return"turn uturn from "+o;switch(e){case"on ramp":case"off ramp":case"merge":case"end of road":case"fork":return e+" "+(t.includes("left")?"left":"right");case"depart":case"arrive":case"roundabout":case"rotary":case"exit roundabout":case"exit rotary":return e;default:return"turn "+t}}const n={continue:"straight","merge right":"merge-right","merge left":"merge-left","off ramp right":"exit-right","off ramp left":"exit-left","on ramp right":"right","on ramp left":"left","fork right":"fork-right","fork left"
1:"fork-left","end of road right":"end-of-road-right","end of road left":"end-of-road-left","turn straight":"straight","turn slight right":"slight-right","turn right":"right","turn sharp right":"sharp-right","turn uturn from right":"u-turn-left","turn uturn from left":"u-turn-right","turn slight left":"slight-left","turn left":"left","turn sharp left":"sharp-left",roundabout:"roundabout",rotary:"roundabout","exit roundabout":"roundabout","exit rotary":"roundabout",ferry:"ferry",depart:"start",arrive:"destination"};for(const n of e.steps)n.maneuverId=t(n);const o=e.steps.map(e=>[n[e.maneuverId],r(e),e.distance,OSM.decodePolyline(e.geometry,{precision:5})]);return{line:o.flatMap(e=>e[3]),steps:o,distance:e.distance,time:e.duration}}let i=[];return{mode:e,provider:"fossgis_osrm",draggable:!0,getRoute:function(e,r){const a=new URLSearchParams({overview:"false",geometries:"polyline",steps:!0});i.length===e.length?a.set("hints",i.join(";")):i=[];const s=new URLSearchParams({srv:n});for(const{lat:t,lng:n}of e)s.append("loc",[t,n]);const c={credit:"OSRM (FOSSGIS)",creditlink:"https://routing.openstreetmap.de/about.html",demolink:"https://routing.openstreetmap.de/?"+s},l="routed-"+t+"/route/v1/driving/"+e.map(e=>e.lng+","+e.lat).join(";");return fetch(OSM.FOSSGIS_OSRM_URL+l+"?"+a,{signal:r}).then(e=>e.json()).then(e=>{if("Ok"!==e.code)throw new Error;return i=e.waypoints.map(e=>e.hint),{...o(e.routes[0].legs[0]),...c}})}}}OSM.directionsEngines.add(new e("car","car","0"),!0),OSM.directionsEngines.add(new e("bicycle","bike","1"),!0),OSM.directionsEngines.add(new e("foot","foot","2"),!0)}(),function(){function e(e,t,n){function r(e){const t=OSM.decodePolyline(e.shape,{precision:6}),n=e.maneuvers.map(e=>[o[e.type],e.instruction,1e3*e.length,t.slice(e.begin_shape_index,e.end_shape_index+1)]);return{line:t,steps:n,distance:1e3*e.summary.length,time:e.summary.time}}const o=["straight","start","start","start","destination","destination","destination","straight","straight","slight-right","right","sharp-right","u-turn-right","u-turn-left","sharp-left","left","slight-left","straight","exit-right","exit-left","exit-right","exit-left","straight","fork-right","fork-left","merge-left","roundabout","roundabout","ferry","straight",null,null,null,null,null,null,null,"merge-right","merge-left"];return{mode:e,provider:"fossgis_valhalla",draggable:!1,getRoute:function(e,o){const i=new URLSearchParams({json:JSON.stringify({locations:e.map(function(e){return{lat:e.lat,lon:e.lng,radius:5}}),costing:t,directions_options:{units:"km",language:OSM.i18n.locale}})}),a={credit:"Valhalla (FOSSGIS)",creditlink:"https://valhalla.openstreetmap.de/",demolink:"https://valhalla.openstreetmap.de/directions?"+new URLSearchParams({profile:n,wps:e.flatMap(({lat:e,lng:t})=>[t,e])})};return fetch(OSM.FOSSGIS_VALHALLA_URL+"?"+i,{signal:o}).then(e=>e.json()).then(({trip:e})=>{if(0!==e.status)throw new Error;return{...r(e.legs[0]),...a}})}}}OSM.directionsEngines.add(new e("car","auto","car"),!0),OSM.directionsEngines.add(new e("bicycle","bicycle","bicycle"),!0),OSM.directionsEngines.add(new e("foot","pedestrian","pedestrian"),!0)}(),function(){function e(e,t,n){function r(e){const t=OSM.decodePolyline(e.points,{precision:5}),n=e.instructions.map(e=>[o[e.sign],e.text,e.distance,t.slice(e.interval[0],e.interval[1]+1)]);return n.at(-1)[0]="destination",{line:t,steps:n,distance:e.distance,time:e.time/1e3,ascend:e.ascend,descend:e.desce
1nd}}const o={"-3":"sharp-left","-2":"left","-1":"slight-left",0:"straight",1:"slight-right",2:"right",3:"sharp-right",4:"destination",5:"destination",6:"roundabout","-7":"fork-left",7:"fork-right","-98":"u-turn-left","-8":"u-turn-left",8:"u-turn-right"};return{mode:e,provider:"graphhopper",draggable:!1,getRoute:function(e,o){const i=new URLSearchParams({profile:t,locale:OSM.i18n.locale,key:"7cb4eb19-e0f4-40a3-a5e0-f2c039366f32",elevation:!1,instructions:!0}),a=new URLSearchParams({profile:n});for(const{lat:t,lng:n}of e)i.append("point",[t,n]),a.append("point",[t,n]);const s={credit:"GraphHopper",creditlink:"https://www.graphhopper.com/",demolink:"https://graphhopper.com/maps/?"+a};return fetch(OSM.GRAPHHOPPER_URL+"?"+i,{signal:o}).then(e=>e.json()).then(({paths:e})=>{if(!e||0===e.length)throw new Error;return{...r(e[0]),...s}})}}}OSM.directionsEngines.add(new e("car","car","car"),!0),OSM.directionsEngines.add(new e("bicycle","bike","bike"),!0),OSM.directionsEngines.add(new e("foot","foot","foot"),!0)}();export default function(e){function t(e){const t=OSM.directionsEngines,n=t.find(t=>t.id===e);if(!n||l&&l.id===e)return;l=n;const r=t.filter(e=>e.provider===l.provider).map(e=>e.mode);v.find("input[id]").prop("disabled",function(){return!r.includes(this.value)}).prop("checked",function(){return this.value===l.mode});const o=t.filter(e=>e.mode===l.mode).map(e=>e.provider);_.find("option[value]").prop("disabled",function(){return!o.includes(this.value)}),_.val(l.provider)}function n(t=!0,n=!0){d&&d.abort();const r=p.map(e=>e.latlng);r[0]&&r[1]&&($(".navbar-toggler:not(.collapsed)").trigger("click"),OSM.router.replace("/directions?"+new URLSearchParams({engine:l.id,route:r.map(e=>`${e.lat},${e.lng}`).join(";")})),$("#directions_loader").prop("hidden",!1),$("#directions_error").prop("hidden",!0).empty(),$("#directions_route").prop("hidden",!0),e.setSidebarOverlaid(!1),d=new AbortController,l.getRoute(r,d.signal).then(async function(e){await c(),$("#directions_route").prop("hidden",!1),g.write(e),t&&g.fit()}).catch(async function(e){"AbortError"!==e.name&&(await c(),g.remove(),n&&$("#directions_error").prop("hidden",!1).html('<div class="alert alert-danger">'+OSM.i18n.t("javascripts.directions.errors.no_route")+"</div>"))}).finally(function(){$("#directions_loader").prop("hidden",!0),d=null}))}function r(t){t.stopPropagation(),g.remove(),f=null,e.setSidebarOverlaid(!0)}function o({latlng:{lat:t,lng:n}}){e.fire("startinglocation",{lat:t,lng:n})}function i({lat:e,lng:t}){p[0].value||p[0].setValue(`${e}, ${t}`)}function a(){const e=new URLSearchParams(location.search),n=(e.get("route")||"").split(";");e.has("engine")&&t(e.get("engine"));const r=u?`${u.lat}, ${u.lng}`:"";p[0].setValue(e.get("from")||n[0]||r),p[1].setValue(e.get("to")||n[1]||"")}function s(){$("#sidebar .sidebar-close-controls button").on("click",r),$("#map").on("dragend dragover",function(e){e.preventDefault()}),$("#map").on("drop",function(t){t.preventDefault();const n=t.originalEvent,r=JSON.parse(n.dataTransfer.getData("text")).type,o=L.DomEvent.getMousePosition(n,e.getContainer());o.y+=20;const i=e.containerPointToLatLng(o),{lat:a,lng:s}=OSM.cropLocation(i,e.getZoom());p["from"===r?0:1].setValue(`${a}, ${s}`)}),e.on("locationfound",o),p[0].enableListeners(),p[1].enableListeners()}function c(){return $("#directions_route").length?(f=null,Promise.resolve()):f??=OSM.loadSidebarContent("/directions")}let l,d=null,u=null,f=null;const g=RouteOutput(e),h=function(e){g.isVisible()&&(e&&!l.draggable||e&&d||n(!1,!e))},p=[Endpoint(e,$("input[name='route_from']"),{icon:"start",color:"var(--marker-green)"},h,n),Endpoint(e,$("input[name='route_to']"),{icon:"destination",color:"var(--marker-red)"},h,n)],m=new Date;m.setFullYear(m.getFullYear()+10);const v=$(".routing_modes"),_=$("select#routing_engines");$(".directions_form .reverse_directions").on("click",function(){const e=p[0].latlng,t=p[1].latlng;let n="",r="";e&&(n=e.lat+","+e.lng),t&&(r=t.lat+","+t.lng),p[0].swapCachedReverseGeocodes(p[1]),OSM.router.route("/directions?"+new URLSearchParams({route:r+";"+n}))}),$(".directions_form .btn-close").on("click",function(t){t.preventDefault(),$(".search_form input[name='query']").val(p[1].value),OSM.router.route("/"+OSM.formatHash(e))}
1),t("fossgis_osrm_car"),t(OSM.cookies.get("_osm_directions_engine")),v.on("change","input[name='modes']",function(e){t(l.provider+"_"+e.target.value),OSM.cookies.set("_osm_directions_engine",l.id,{expires:m}),n()}),_.on("change",function(e){t(e.target.value+"_"+l.mode),OSM.cookies.set("_osm_directions_engine",l.id,{expires:m}),n()}),$(".directions_form").on("submit",function(e){e.preventDefault(),n()}),$(".routing_marker_column span").on("dragstart",function(e){const t=e.originalEvent.dataTransfer;t.effectAllowed="move";const n=$(this);if(t.setData("text",JSON.stringify(n.data())),t.setDragImage){const e=n.clone().appendTo(document.body);e.find("svg").toggleClass("position-absolute bottom-100 end-100").attr({width:"25",height:"40"}),t.setDragImage(e.get(0),12,21),setTimeout(()=>e.remove(),0)}}),e.on("locationfound",({latlng:{lat:e,lng:t}})=>u={lat:e,lng:t}).on("locateactivate",()=>{e.once("startinglocation",i)});const S={};return S.load=S.init=function(){a(),$(".search_form").hide(),$(".directions_form").show(),c().then(s),e.setSidebarOverlaid(!p[0].latlng||!p[1].latlng)},S.unload=function(){$(".search_form").show(),$(".directions_form").hide(),$("#sidebar .sidebar-close-controls button").off("click",r),$("#map").off("dragend dragover drop"),e.off("locationfound",o),p[0].disableListeners(),p[1].disableListeners(),p[0].clearValue(),p[1].clearValue(),g.remove(),f=null},S}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.