@maplibre/maplibre-gl-directions
Version:
A plugin to show routing directions on a MapLibre GL JS map. Supports any [OSRM](http://project-osrm.org/) or [Mapbox Directions API](https://docs.mapbox.com/api/navigation/directions/) compatible Routing-provider.
3 lines (2 loc) • 42.3 kB
JavaScript
"use strict";var Ae=Object.defineProperty;var Ne=(t,i,e)=>i in t?Ae(t,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[i]=e;var u=(t,i,e)=>(Ne(t,typeof i!="symbol"?i+"":i,e),e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class $e{constructor(i){u(this,"map");u(this,"listeners",{});u(this,"oneTimeListeners",{});this.map=i}fire(i){var n,o;i.target=this.map;const e=i.type;(n=this.listeners[e])==null||n.forEach(s=>s(i)),(o=this.oneTimeListeners[e])==null||o.forEach(s=>{var a,h;s(i);const r=(a=this.oneTimeListeners[e])==null?void 0:a.indexOf(s);r!==void 0&&~r&&((h=this.oneTimeListeners[e])==null||h.splice(r,1))})}on(i,e){this.listeners[i]=this.listeners[i]??[],this.listeners[i].push(e)}off(i,e){var o,s;const n=(o=this.listeners[i])==null?void 0:o.indexOf(e);n!==void 0&&~n&&((s=this.listeners[i])==null||s.splice(n,1))}once(i,e){this.oneTimeListeners[i]=this.oneTimeListeners[i]??[],this.oneTimeListeners[i].push(e)}}class N{constructor(i,e,n){u(this,"type");u(this,"target");u(this,"originalEvent");u(this,"data");this.type=i,this.originalEvent=e,this.data=n}}class ee{constructor(i,e,n){u(this,"type");u(this,"target");u(this,"originalEvent");u(this,"data");this.type=i,this.originalEvent=e,this.data=n}}const je={api:"https://router.project-osrm.org/route/v1",profile:"driving",requestOptions:{},requestTimeout:null,makePostRequest:!1,sourceName:"maplibre-gl-directions",pointsScalingFactor:1,linesScalingFactor:1,sensitiveWaypointLayers:["maplibre-gl-directions-waypoint","maplibre-gl-directions-waypoint-casing"],sensitiveSnappointLayers:["maplibre-gl-directions-snappoint","maplibre-gl-directions-snappoint-casing"],sensitiveRoutelineLayers:["maplibre-gl-directions-routeline","maplibre-gl-directions-routeline-casing"],sensitiveAltRoutelineLayers:["maplibre-gl-directions-alt-routeline","maplibre-gl-directions-alt-routeline-casing"],dragThreshold:10,refreshOnMove:!1,bearings:!1},M={snapline:"#34343f",altRouteline:"#9e91be",routelineFoot:"#3665ff",routelineBike:"#63c4ff",routeline:"#7b51f8",congestionLow:"#42c74c",congestionHigh:"#d72359",hoverpoint:"#30a856",snappoint:"#cb3373",snappointHighlight:"#e50d3f",waypointFoot:"#3665ff",waypointFootHighlight:"#0942ff",waypointBike:"#63c4ff",waypointBikeHighlight:"#0bb8ff",waypoint:"#7b51f8",waypointHighlight:"#6d26d7"},le=["case",["==",["get","profile",["get","arriveSnappointProperties"]],"foot"],M.routelineFoot,["==",["get","profile",["get","arriveSnappointProperties"]],"bike"],M.routelineBike,["interpolate-hcl",["linear"],["get","congestion"],0,M.routeline,1,M.congestionLow,100,M.congestionHigh]],he=["case",["==",["get","profile"],"foot"],["case",["boolean",["get","highlight"],!1],M.waypointFootHighlight,M.waypointFoot],["==",["get","profile"],"bike"],["case",["boolean",["get","highlight"],!1],M.waypointBikeHighlight,M.waypointBike],["case",["boolean",["get","highlight"],!1],M.waypointHighlight,M.waypoint]],pe=["case",["boolean",["get","highlight"],!1],M.snappointHighlight,M.snappoint];function we(t=1,i=1,e="maplibre-gl-directions"){const n=["interpolate",["exponential",1.5],["zoom"],0,["case",["boolean",["get","highlight"],["==",["get","type"],"HOVERPOINT"]],14*t,12*t],5,["case",["boolean",["get","highlight"],["==",["get","type"],"HOVERPOINT"]],14*t,12*t],18,["case",["boolean",["get","highlight"],["==",["get","type"],"HOVERPOINT"]],33*t,28*t]],o=["interpolate",["exponential",1.5],["zoom"],0,["case",["boolean",["get","highlight"],["==",["get","type"],"HOVERPOINT"]],9*t,7*t],5,["case",["boolean",["get","highlight"],["==",["get","type"],"HOVERPOINT"]],9*t,7*t],18,["case",["boolean",["get","highlight"],["==",["get","type"],"HOVERPOINT"]],21*t,16*t]],s=["interpolate",["exponential",1.5],["zoom"],0,3*i,5,3*i,18,10*i],r=["interpolate",["exponential",1.5],["zoom"],0,["case",["boolean",["get","highlight"],!1],10*i,7*i],5,["case",["boolean",["get","highlight"],!1],10*i,7*i],18,["case",["boolean",["get","highlight"],!1],32*i,23*i]];return[{id:`${e}-snapline`,type:"line",source:e,layout:{"line-cap":"round","line-join":"round"},paint:{"line-dasharray":[3,3],"line-color":M.snapline,"line-opacity":.65,"line-width":3},filter:["==",["get","type"],"SNAPLINE"]},{id:`${e}-alt-routeline-casing`,type:"line",source:e,layout:{"line-cap":"butt","line-join":"round"},paint:{"line-color":M.altRouteline,"line-opacity":.55,"line-width":r},filter:["==",["get","route"],"ALT"]},{id:`${e}-alt-routeline`,type:"line",source:e,layout:{"line-cap":"butt","line-join":"round"},paint:{"line-color":M.altRouteline,"line-opacity":.85,"line-width":s},filter:["==",["get","route"],"ALT"]},{id:`${e}-routeline-casing`,type:"line",source:e,layout:{"line-cap":"butt","line-join":"round"},paint:{"line-color":le,"line-opacity":.55,"line-width":r},filter:["==",["get","route"],"SELECTED"]},{id:`${e}-routeline`,type:"line",source:e,layout:{"line-cap":"butt","line-join":"round"},paint:{"line-color":le,"line-opacity":.85,"line-width":s},filter:["==",["get","route"],"SELECTED"]},{id:`${e}-hoverpoint-casing`,type:"circle",source:e,paint:{"circle-radius":n,"circle-color":M.hoverpoint,"circle-opacity":.65},filter:["==",["get","type"],"HOVERPOINT"]},{id:`${e}-hoverpoint`,type:"circle",source:e,paint:{"circle-radius":o,"circle-color":M.hoverpoint},filter:["==",["get","type"],"HOVERPOINT"]},{id:`${e}-snappoint-casing`,type:"circle",source:e,paint:{"circle-radius":n,"circle-color":pe,"circle-opacity":.65},filter:["==",["get","type"],"SNAPPOINT"]},{id:`${e}-snappoint`,type:"circle",source:e,paint:{"circle-radius":o,"circle-color":pe},filter:["==",["get","type"],"SNAPPOINT"]},{id:`${e}-waypoint-casing`,type:"circle",source:e,paint:{"circle-radius":n,"circle-color":he,"circle-opacity":.65},filter:["==",["get","type"],"WAYPOINT"]},{id:`${e}-waypoint`,type:"circle",source:e,paint:{"circle-radius":o,"circle-color":he},filter:["==",["get","type"],"WAYPOINT"]}]}const xe="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let De=(t=21)=>{let i="",e=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)i+=xe[e[t]&63];return i};function ce(t){return t&1?~(t>>1):t>>1}function de(t,i=5){const e=Math.pow(10,i);let n=0,o=0,s=0;const r=[];let a=0,h=0,c=null,d,l;for(;n<t.length;){c=null,a=0,h=0;do c=t.charCodeAt(n++)-63,h|=(c&31)<<a,a+=5;while(c>=32);d=ce(h),a=h=0;do c=t.charCodeAt(n++)-63,h|=(c&31)<<a,a+=5;while(c>=32);l=ce(h),o+=d,s+=l,r.push([s/e,o/e])}return r}function ze(t,i){return t.geometries==="geojson"?i.coordinates:t.geometries==="polyline6"?de(i,6):de(i,5)}function qe(t,i,e){var n,o,s,r;if((n=t.annotations)!=null&&n.includes("congestion_numeric"))return((o=i==null?void 0:i.congestion_numeric)==null?void 0:o[e])??0;if((s=t.annotations)!=null&&s.includes("congestion"))switch(((r=i==null?void 0:i.congestion)==null?void 0:r[e])??""){case"unknown":return 0;case"low":return 1;case"moderate":return 34;case"heavy":return 77;case"severe":return 100;default:return 0}else return 0}function Ue(t,i,e){return!t.geometries||t.geometries==="polyline"?Math.abs(i[0]-e[0])<=1e-5&&Math.abs(i[1]-e[1])<=1e-5:i[0]===e[0]&&i[1]===e[1]}function ge(t){return t.map(i=>[i.geometry.coordinates[0],i.geometry.coordinates[1]])}function ue(t){return t.map(i=>{var e,n,o;return Array.isArray((e=i.properties)==null?void 0:e.bearing)?[(n=i.properties)==null?void 0:n.bearing[0],(o=i.properties)==null?void 0:o.bearing[1]]:void 0})}function Ee(t){const i=we(t==null?void 0:t.pointsScalingFactor,t==null?void 0:t.linesScalingFactor,t==null?void 0:t.sourceName);return Object.assign({},je,{layers:i},t)}function Me(t,i,e){const n=t.makePostRequest?"post":"get";let o,s;if(n==="get")o=`${t.api}/${t.profile}/${i.join(";")}`,s=new URLSearchParams(t.requestOptions);else{o=`${t.api}/${t.profile}${t.requestOptions.access_token?`?access_token=${t.requestOptions.access_token}`:""}`;const r=new FormData;Object.entries(t.requestOptions).forEach(([a,h])=>{a!=="access_token"&&r.set(a,h)}),r.set("coordinates",i.join(";")),s=new URLSearchParams(r)}return t.bearings&&e&&s.set("bearings",e.map(r=>r?`${r[0]},${r[1]}`:"").join(";")),{method:n,url:o,payload:s}}function Le(t,i,e){return{type:"Feature",geometry:{type:"Point",coordinates:t},properties:{type:i,id:De(),...e??{}}}}function Se(t,i,e,n,o=!1){if(t.length!==i.length)return[];const s=t.map((r,a)=>({type:"Feature",geometry:{type:"LineString",coordinates:[[r[0],r[1]],[i[a][0],i[a][1]]]},properties:{type:"SNAPLINE"}}));return~n&&e!==void 0&&o&&(s.push({type:"Feature",geometry:{type:"LineString",coordinates:[[e[0],e[1]],[i[n][0],i[n][1]]]},properties:{type:"SNAPLINE"}}),s.push({type:"Feature",geometry:{type:"LineString",coordinates:[[e[0],e[1]],[i[n+1][0],i[n+1][1]]]},properties:{type:"SNAPLINE"}})),s}function Pe(t,i,e,n){return i.map((o,s)=>{const r=ze(t,o.geometry),a=n.map(m=>m.geometry.coordinates);let h=0;const c=a.map((m,f)=>{const E=r.slice(h).findIndex(v=>Ue(t,v,m)),D=f===a.length-1;if(E!==-1)h+=E;else if(D)return r.length-1;return h}).slice(1);let d=0;const l=c.map(m=>r.slice(d,d=m+1)),g=[];return l.forEach((m,f)=>{const E=De();m.forEach((D,v)=>{var b,R,T;const _=g[g.length-1],y=qe(t,(b=o.legs[f])==null?void 0:b.annotation,v);if(f===((R=_==null?void 0:_.properties)==null?void 0:R.legIndex)&&((T=_.properties)==null?void 0:T.congestion)===y)_.geometry.coordinates.push(D);else{const j=n[f].properties??{},W=n[f+1].properties??{},C={type:"Feature",geometry:{type:"LineString",coordinates:[]},properties:{id:E,routeIndex:s,route:s===e?"SELECTED":"ALT",legIndex:f,congestion:y,departSnappointProperties:j,arriveSnappointProperties:W}};_&&C.geometry.coordinates.push(_.geometry.coordinates[_.geometry.coordinates.length-1]),C.geometry.coordinates.push(D),g.push(C)}})}),g})}const Ve=Object.freeze(Object.defineProperty({__proto__:null,buildConfiguration:Ee,buildPoint:Le,buildRequest:Me,buildRoutelines:Pe,buildSnaplines:Se},Symbol.toStringTag,{value:"Module"}));class Ge extends $e{constructor(e,n){super(e);u(this,"configuration");u(this,"_interactive",!1);u(this,"_hoverable",!1);u(this,"buildRequest",Me);u(this,"buildPoint",Le);u(this,"buildSnaplines",Se);u(this,"buildRoutelines",Pe);u(this,"onMoveHandler");u(this,"onDragDownHandler");u(this,"onDragMoveHandler");u(this,"onDragUpHandler");u(this,"onClickHandler");u(this,"liveRefreshHandler");u(this,"profiles",[]);u(this,"_waypoints",[]);u(this,"snappoints",[]);u(this,"routelines",[]);u(this,"selectedRouteIndex",0);u(this,"hoverpoint");u(this,"highlightedWaypoints",[]);u(this,"highlightedSnappoints",[]);u(this,"dragDownPosition",{x:0,y:0});u(this,"waypointBeingDragged");u(this,"waypointBeingDraggedInitialCoordinates");u(this,"departSnappointIndex",-1);u(this,"currentMousePosition",{x:0,y:0});u(this,"refreshOnMoveIsRefreshing",!1);u(this,"noMouseMovementTimer");u(this,"lastRequestMousePosition",{x:0,y:0});u(this,"allowRouteSwitch",!1);u(this,"abortController");this.map=e,this.configuration=Ee(n),this.onMoveHandler=this.onMove.bind(this),this.onDragDownHandler=this.onDragDown.bind(this),this.onDragMoveHandler=this.onDragMove.bind(this),this.onDragUpHandler=this.onDragUp.bind(this),this.onClickHandler=this.onClick.bind(this),this.liveRefreshHandler=this.liveRefresh.bind(this),this.init()}get waypointsCoordinates(){return ge(this._waypoints)}get snappointsCoordinates(){return this.snappoints.map(e=>[e.geometry.coordinates[0],e.geometry.coordinates[1]])}get snaplines(){var e,n,o;return this.buildSnaplines(this.waypointsCoordinates,this.snappointsCoordinates,(e=this.hoverpoint)==null?void 0:e.geometry.coordinates,this.departSnappointIndex,(o=(n=this.hoverpoint)==null?void 0:n.properties)==null?void 0:o.showSnaplines)}init(){this.map.addSource(this.configuration.sourceName,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.configuration.layers.forEach(e=>{this.map.addLayer(e)})}async fetch({method:e,url:n,payload:o}){var r,a;const s=await(e==="get"?await fetch(`${n}?${o}`,{signal:(r=this.abortController)==null?void 0:r.signal}):await fetch(`${n}`,{signal:(a=this.abortController)==null?void 0:a.signal,method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:o})).json();if(s.code!=="Ok")throw new Error(s.message??"An unexpected error occurred.");return s}async fetchDirections(e){var n;if((n=this.abortController)==null||n.abort(),this._waypoints.length>=2){this.fire(new ee("fetchroutesstart",e)),this.abortController=new AbortController;let o;this.configuration.requestTimeout!==null&&(o=setTimeout(()=>{var l;return(l=this.abortController)==null?void 0:l.abort()},this.configuration.requestTimeout)),this.profiles.length||(this.profiles=[this.configuration.profile]);const s=[],r=[];this.profiles.reduce((l,g,m)=>{const f=m===this.profiles.length-1,E=m>0?this.profiles[m-1]:void 0,D=g===E,v=f?this._waypoints.length:D?l+1:l+2;return D?r[r.length-1].push(...this._waypoints.slice(l,v)):(r.push(this._waypoints.slice(l,v)),s.push(g)),v},0);const a=s.map((l,g)=>this.buildRequest({...this.configuration,profile:l},ge(r[g]),this.configuration.bearings?ue(r[g]):void 0));let h;try{h=await Promise.all(a.map(async l=>{let g;try{g=await this.fetch(l)}finally{this.fire(new ee("fetchroutesend",e,g))}return g}))}finally{clearTimeout(o)}const c=h.flatMap((l,g)=>{const m=s[g],f=l.waypoints.map((D,v)=>this.buildPoint(D.location,"SNAPPOINT",{profile:m,waypointProperties:r[g][v].properties??{}})),E=this.buildRoutelines(this.configuration.requestOptions,l.routes,this.selectedRouteIndex,f);return{snappoints:f,routelines:E}}),d=h.flatMap(l=>l.routes);this.snappoints=c.flatMap(l=>l.snappoints),this.routelines=c.flatMap(l=>l.routelines),d.length<=this.selectedRouteIndex&&(this.selectedRouteIndex=0)}else this.snappoints=[],this.routelines=[];this.draw(!1)}draw(e=!0){const n=[...this._waypoints,...this.snappoints,...this.snaplines,...this.routelines.reduce((s,r)=>e?s.concat(...r):s.concat(...r.map(a=>(a.properties&&(a.properties.route=a.properties.routeIndex===this.selectedRouteIndex?"SELECTED":"ALT"),a))),[])];this.hoverpoint&&n.push(this.hoverpoint);const o={type:"FeatureCollection",features:n};this.map.getSource(this.configuration.sourceName)&&this.map.getSource(this.configuration.sourceName).setData(o)}deHighlight(){this.highlightedWaypoints.forEach(e=>{e!=null&&e.properties&&(e.properties.highlight=!1)}),this.highlightedSnappoints.forEach(e=>{e!=null&&e.properties&&(e.properties.highlight=!1)}),this.routelines.forEach(e=>{e.forEach(n=>{n.properties&&(n.properties.highlight=!1)})})}onMove(e){var o,s,r,a;const n=this.map.queryRenderedFeatures(e.point,{layers:[...this.configuration.sensitiveWaypointLayers,...this.configuration.sensitiveSnappointLayers,...this.configuration.sensitiveRoutelineLayers,...this.configuration.sensitiveAltRoutelineLayers]})[0];if(this.deHighlight(),this.configuration.sensitiveWaypointLayers.includes((n==null?void 0:n.layer.id)??"")){this.map.getCanvas().style.cursor="pointer",this.interactive&&this.map.dragPan.disable();const h=this._waypoints.find(d=>{var l,g;return((l=d.properties)==null?void 0:l.id)===((g=n==null?void 0:n.properties)==null?void 0:g.id)}),c=h&&this.snappoints.find(d=>{var l,g,m;return((g=(l=d.properties)==null?void 0:l.waypointProperties)==null?void 0:g.id)===((m=h.properties)==null?void 0:m.id)});h&&(this.highlightedWaypoints=[h]),c&&(this.highlightedSnappoints=[c]),(o=this.highlightedWaypoints[0])!=null&&o.properties&&(this.highlightedWaypoints[0].properties.highlight=!0),(s=this.highlightedSnappoints[0])!=null&&s.properties&&(this.highlightedSnappoints[0].properties.highlight=!0),this.hoverpoint&&(this.hoverpoint=void 0)}else if(this.configuration.sensitiveSnappointLayers.includes((n==null?void 0:n.layer.id)??"")){this.map.getCanvas().style.cursor="pointer";const h=this.snappoints.findIndex(c=>{var d,l;return((d=c.properties)==null?void 0:d.id)===((l=n==null?void 0:n.properties)==null?void 0:l.id)});this.highlightedSnappoints=[this.snappoints[h]],this.highlightedWaypoints=[this._waypoints[h]],this.highlightedSnappoints[0].properties&&(this.highlightedSnappoints[0].properties.highlight=!0),this.highlightedWaypoints[0].properties&&(this.highlightedWaypoints[0].properties.highlight=!0),this.hoverpoint&&(this.hoverpoint=void 0)}else this.configuration.sensitiveRoutelineLayers.includes((n==null?void 0:n.layer.id)??"")?(this.map.getCanvas().style.cursor="pointer",this.interactive&&(this.map.dragPan.disable(),this.hoverpoint?this.hoverpoint.geometry.coordinates=[e.lngLat.lng,e.lngLat.lat]:this.hoverpoint=this.buildPoint([e.lngLat.lng,e.lngLat.lat],"HOVERPOINT",{departSnappointProperties:{...JSON.parse(((r=n==null?void 0:n.properties)==null?void 0:r.departSnappointProperties)??"{}")},arriveSnappointProperties:{...JSON.parse(((a=n==null?void 0:n.properties)==null?void 0:a.arriveSnappointProperties)??"{}")}})),this.routelines.forEach(h=>{h.forEach(c=>{var d,l;c.properties&&((d=c.properties)==null?void 0:d.id)===((l=n==null?void 0:n.properties)==null?void 0:l.id)&&(c.properties.highlight=!0)})})):this.configuration.sensitiveAltRoutelineLayers.includes((n==null?void 0:n.layer.id)??"")?(this.map.getCanvas().style.cursor="pointer",this.routelines.forEach(h=>{h.forEach(c=>{var d,l;c.properties&&((d=c.properties)==null?void 0:d.id)===((l=n==null?void 0:n.properties)==null?void 0:l.id)&&(c.properties.highlight=!0)})}),this.hoverpoint&&(this.hoverpoint=void 0)):(this.map.dragPan.enable(),this.map.getCanvas().style.cursor="",this.hoverpoint=void 0);this.draw()}onDragDown(e){var o,s,r,a,h,c;if(e.type==="touchstart"&&e.originalEvent.touches.length!==1||e.type==="mousedown"&&e.originalEvent.which!==1)return;const n=this.map.queryRenderedFeatures(e.point);if(n.length&&n[0].source===this.configuration.sourceName){const d=n.filter(l=>this.configuration.sensitiveWaypointLayers.includes((l==null?void 0:l.layer.id)??"")||this.configuration.sensitiveSnappointLayers.includes((l==null?void 0:l.layer.id)??"")||this.configuration.sensitiveRoutelineLayers.includes((l==null?void 0:l.layer.id)??""))[0];if(this.dragDownPosition=e.point,this.currentMousePosition=e.point,this.configuration.sensitiveWaypointLayers.includes((d==null?void 0:d.layer.id)??""))this.waypointBeingDragged=this._waypoints.find(l=>{var g,m;return((g=l.properties)==null?void 0:g.id)===((m=d==null?void 0:d.properties)==null?void 0:m.id)}),this.waypointBeingDraggedInitialCoordinates=(o=this.waypointBeingDragged)==null?void 0:o.geometry.coordinates;else if(this.configuration.sensitiveRoutelineLayers.includes((d==null?void 0:d.layer.id)??"")){if(this.departSnappointIndex=JSON.parse((s=d==null?void 0:d.properties)==null?void 0:s.legIndex),this.hoverpoint)if(this.configuration.refreshOnMove){const l=this.departSnappointIndex!==void 0?this.departSnappointIndex+1:void 0;this._addWaypoint([e.lngLat.lng,e.lngLat.lat],l,e),this.waypointBeingDragged=l?this._waypoints[l]:void 0,this.hoverpoint=void 0}else this.hoverpoint.geometry.coordinates=[e.lngLat.lng,e.lngLat.lat];else this.hoverpoint=this.buildPoint([e.lngLat.lng,e.lngLat.lat],"HOVERPOINT",{departSnappointProperties:{...JSON.parse(((r=d==null?void 0:d.properties)==null?void 0:r.departSnappointProperties)??"{}")},arriveSnappointProperties:{...JSON.parse(((a=d==null?void 0:d.properties)==null?void 0:a.arriveSnappointProperties)??"{}")}});(h=this.hoverpoint)!=null&&h.properties&&(this.hoverpoint.properties.showSnaplines=!0),~this.departSnappointIndex&&((c=this.snappoints[this.departSnappointIndex])!=null&&c.properties)&&(this.snappoints[this.departSnappointIndex].properties.highlight=!0,this.highlightedSnappoints.push(this.snappoints[this.departSnappointIndex]),this.snappoints[this.departSnappointIndex+1].properties.highlight=!0,this.highlightedSnappoints.push(this.snappoints[this.departSnappointIndex+1]))}this.map.off("touchstart",this.onMoveHandler),this.map.off("mousemove",this.onMoveHandler),e.type==="touchstart"?(this.map.on("touchmove",this.onDragMoveHandler),this.map.on("touchend",this.onDragUpHandler)):e.type==="mousedown"&&(this.map.on("mousemove",this.onDragMoveHandler),this.map.on("mouseup",this.onDragUpHandler)),this.draw()}}onDragMove(e){if(this.configuration.refreshOnMove&&(clearTimeout(this.noMouseMovementTimer),this.noMouseMovementTimer=setTimeout(this.liveRefreshHandler,300,e)),e.type==="touchmove"&&e.originalEvent.touches.length!==1)return e.originalEvent.preventDefault();e.type==="mousemove"&&e.originalEvent.which!==1||(this.waypointBeingDragged?this.waypointBeingDragged.geometry.coordinates=[e.lngLat.lng,e.lngLat.lat]:this.hoverpoint&&(this.hoverpoint.geometry.coordinates=[e.lngLat.lng,e.lngLat.lat]),this.currentMousePosition=e.point,this.draw(),this.configuration.refreshOnMove&&!this.refreshOnMoveIsRefreshing&&this.liveRefreshHandler(e))}onDragUp(e){var n,o,s;if(this.configuration.refreshOnMove&&clearTimeout(this.noMouseMovementTimer),!(e.type==="mouseup"&&e.originalEvent.which!==1)){if((n=this.hoverpoint)!=null&&n.properties&&(this.hoverpoint.properties.showSnaplines=!1),Math.abs(e.point.x-((o=this.dragDownPosition)==null?void 0:o.x))>(this.configuration.dragThreshold>=0?this.configuration.dragThreshold:0)||Math.abs(e.point.y-((s=this.dragDownPosition)==null?void 0:s.y))>(this.configuration.dragThreshold>=0?this.configuration.dragThreshold:0))if(this.waypointBeingDragged){this.waypointBeingDragged.geometry.coordinates=[e.lngLat.lng,e.lngLat.lat];const r=new N("movewaypoint",e,{index:this._waypoints.indexOf(this.waypointBeingDragged),initialCoordinates:this.waypointBeingDraggedInitialCoordinates});this.fire(r),this.fetchDirections(r).catch(a=>{a instanceof DOMException&&a.name=="AbortError"||this.waypointBeingDragged&&this.waypointBeingDraggedInitialCoordinates&&(this.waypointBeingDragged.geometry.coordinates=this.waypointBeingDraggedInitialCoordinates)}),this.waypointBeingDragged=void 0,this.waypointBeingDraggedInitialCoordinates=void 0}else this.hoverpoint&&(this._addWaypoint([e.lngLat.lng,e.lngLat.lat],this.departSnappointIndex!==void 0?this.departSnappointIndex+1:void 0,e),this.hoverpoint=void 0);else this.waypointBeingDragged&&this.waypointBeingDraggedInitialCoordinates?(this.waypointBeingDragged.geometry.coordinates=this.waypointBeingDraggedInitialCoordinates,this.waypointBeingDragged=void 0,this.waypointBeingDraggedInitialCoordinates=void 0):this.hoverpoint&&(this.hoverpoint=void 0);this.deHighlight(),e.type==="touchend"?(this.map.off("touchmove",this.onDragMoveHandler),this.map.off("touchend",this.onDragUpHandler)):e.type==="mouseup"&&(this.map.off("mousemove",this.onDragMoveHandler),this.map.off("mouseup",this.onDragUpHandler)),this.map.on("touchstart",this.onMoveHandler),this.map.on("mousemove",this.onMoveHandler),this.map.dragPan.enable(),this.draw(),this.map.once("idle",()=>{this.onMove(e)})}}async liveRefresh(e){var n,o,s,r;if(Math.abs(((n=this.lastRequestMousePosition)==null?void 0:n.x)-((o=this.currentMousePosition)==null?void 0:o.x))>(this.configuration.dragThreshold>=0?this.configuration.dragThreshold:0)||Math.abs(((s=this.lastRequestMousePosition)==null?void 0:s.y)-((r=this.currentMousePosition)==null?void 0:r.y))>(this.configuration.dragThreshold>=0?this.configuration.dragThreshold:0)){if(this.refreshOnMoveIsRefreshing=!0,this.lastRequestMousePosition=this.currentMousePosition,this.waypointBeingDragged){const a=new N("movewaypoint",e,{index:this._waypoints.indexOf(this.waypointBeingDragged),initialCoordinates:this.waypointBeingDraggedInitialCoordinates});this.fire(a);try{await this.fetchDirections(a)}catch{}}this.refreshOnMoveIsRefreshing=!1}}onClick(e){const n=this.map.queryRenderedFeatures(e.point,{layers:[...this.configuration.sensitiveWaypointLayers,...this.configuration.sensitiveSnappointLayers,...this.configuration.sensitiveAltRoutelineLayers,...this.configuration.sensitiveRoutelineLayers]})[0];if(this.interactive&&this.configuration.sensitiveWaypointLayers.includes((n==null?void 0:n.layer.id)??"")){const o=this._waypoints.findIndex(s=>{var r,a;return((r=s.properties)==null?void 0:r.id)===((a=n==null?void 0:n.properties)==null?void 0:a.id)});~o&&this._removeWaypoint(o,e)}else if(this.interactive&&this.configuration.sensitiveSnappointLayers.includes((n==null?void 0:n.layer.id)??"")){const o=this.snappoints.findIndex(s=>{var r,a;return((r=s.properties)==null?void 0:r.id)===((a=n==null?void 0:n.properties)==null?void 0:a.id)});~o&&this._removeWaypoint(o,e)}else(this.interactive||this.allowRouteSwitch)&&this.configuration.sensitiveAltRoutelineLayers.includes((n==null?void 0:n.layer.id)??"")?this.selectedRouteIndex=this.routelines.findIndex(o=>!!o.find(s=>{var r,a;return((r=s.properties)==null?void 0:r.id)===((a=n==null?void 0:n.properties)==null?void 0:a.id)})):this.interactive&&!this.configuration.sensitiveRoutelineLayers.includes((n==null?void 0:n.layer.id)??"")&&this._addWaypoint([e.lngLat.lng,e.lngLat.lat],void 0,e);this.draw(!1),this.map.once("idle",()=>{this.onMove(e)})}assignWaypointsCategories(){this._waypoints.forEach((e,n)=>{const o=n===0?"ORIGIN":n===this._waypoints.length-1?"DESTINATION":void 0;e.properties&&(e.properties.index=n,e.properties.category=o)})}async _addWaypoint(e,n,o){var r;(r=this.abortController)==null||r.abort(),n=n??this._waypoints.length,this._waypoints.splice(n,0,this.buildPoint(e,"WAYPOINT",this.configuration.bearings?{bearing:void 0}:void 0)),this.assignWaypointsCategories();const s=new N("addwaypoint",o,{index:n});this.fire(s),this.draw();try{await this.fetchDirections(s)}catch{}}async _removeWaypoint(e,n){var s;(s=this.abortController)==null||s.abort(),this._waypoints.splice(e,1),this.snappoints.splice(e,1),this.assignWaypointsCategories();const o=new N("removewaypoint",n,{index:e});this.fire(o),this.draw();try{await this.fetchDirections(o)}catch{}}get interactive(){return this._interactive}set interactive(e){this._interactive=e,e?(this.map.on("touchstart",this.onMoveHandler),this.map.on("touchstart",this.onDragDownHandler),this.map.on("mousedown",this.onDragDownHandler),this.map.on("click",this.onClickHandler),this.hoverable||(this.map.on("mousemove",this.onMoveHandler),this.map.on("click",this.onClickHandler))):(this.map.off("touchstart",this.onMoveHandler),this.map.off("touchstart",this.onDragDownHandler),this.map.off("mousedown",this.onDragDownHandler),this.hoverable||(this.map.off("mousemove",this.onMoveHandler),this.map.off("click",this.onClickHandler)),this.map.dragPan.enable())}get hoverable(){return this._hoverable}set hoverable(e){this._hoverable=e,e&&!this.interactive?(this.map.on("mousemove",this.onMoveHandler),this.map.on("click",this.onClickHandler)):this.interactive||(this.map.off("mousemove",this.onMoveHandler),this.map.off("click",this.onClickHandler))}get waypoints(){return this.waypointsCoordinates}set waypoints(e){this.setWaypoints(e)}get waypointsBearings(){return this.configuration.bearings?ue(this._waypoints):(console.warn("The `waypointsBearings` getter was referred to, but the `bearings` configuration option is not enabled!"),[])}set waypointsBearings(e){if(!this.configuration.bearings){console.warn("The `waypointsBearings` setter was referred to, but the `bearings` configuration option is not enabled!");return}this._waypoints.forEach((o,s)=>{(o.properties||(o.properties={})).bearing=e[s]});const n=new N("rotatewaypoints",void 0);this.fire(n),this.draw();try{this.fetchDirections(n)}catch{}}async setWaypoints(e,n=[]){var s;(s=this.abortController)==null||s.abort(),this.profiles=n.slice(0,e.length-1),this.profiles.length===0&&this.profiles.push(this.configuration.profile),this._waypoints=this.profiles.flatMap((r,a)=>{const h=a===this.profiles.length-1,c=a>0?this.profiles[a-1]:void 0,l=r===c?a+1:a,g=h?e.length:a+2;return e.slice(l,g).map((m,f)=>this.buildPoint(m,"WAYPOINT",{profile:r,...this.configuration.bearings?{bearing:this.waypointsBearings[f]}:void 0}))}),this.assignWaypointsCategories();const o=new N("setwaypoints",void 0);this.fire(o),this.draw();try{await this.fetchDirections(o)}catch{}}async addWaypoint(e,n){await this._addWaypoint(e,n)}async removeWaypoint(e){await this._removeWaypoint(e)}clear(){this.setWaypoints([]),this.routelines=[]}destroy(){var e;(e=this.abortController)==null||e.abort(),this.clear(),this.hoverable=!1,this.interactive=!1,this.configuration.layers.forEach(n=>{this.map.removeLayer(n.id)}),this.map.removeSource(this.configuration.sourceName)}}function $(){}function Re(t){return t()}function fe(){return Object.create(null)}function J(t){t.forEach(Re)}function Ie(t){return typeof t=="function"}function Te(t,i){return t!=t?i==i:t!==i||t&&typeof t=="object"||typeof t=="function"}function Je(t){return Object.keys(t).length===0}function w(t,i){t.appendChild(i)}function B(t,i,e){t.insertBefore(i,e||null)}function O(t){t.parentNode&&t.parentNode.removeChild(t)}function Ye(t,i){for(let e=0;e<t.length;e+=1)t[e]&&t[e].d(i)}function S(t){return document.createElement(t)}function P(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function X(t){return document.createTextNode(t)}function k(){return X(" ")}function Fe(){return X("")}function F(t,i,e,n){return t.addEventListener(i,e,n),()=>t.removeEventListener(i,e,n)}function p(t,i,e){e==null?t.removeAttribute(i):t.getAttribute(i)!==e&&t.setAttribute(i,e)}function K(t){return t===""?null:+t}function Xe(t){return Array.from(t.childNodes)}function Ke(t,i){i=""+i,t.data!==i&&(t.data=i)}function Q(t,i){t.value=i??""}function A(t,i,e,n){e==null?t.style.removeProperty(i):t.style.setProperty(i,e,n?"important":"")}let G;function V(t){G=t}function Qe(){if(!G)throw new Error("Function called outside component initialization");return G}function Ze(t){Qe().$$.on_destroy.push(t)}const z=[],te=[];let q=[];const me=[],et=Promise.resolve();let ie=!1;function tt(){ie||(ie=!0,et.then(Ce))}function ne(t){q.push(t)}const Z=new Set;let x=0;function Ce(){if(x!==0)return;const t=G;do{try{for(;x<z.length;){const i=z[x];x++,V(i),it(i.$$)}}catch(i){throw z.length=0,x=0,i}for(V(null),z.length=0,x=0;te.length;)te.pop()();for(let i=0;i<q.length;i+=1){const e=q[i];Z.has(e)||(Z.add(e),e())}q.length=0}while(z.length);for(;me.length;)me.pop()();ie=!1,Z.clear(),V(t)}function it(t){if(t.fragment!==null){t.update(),J(t.before_update);const i=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,i),t.after_update.forEach(ne)}}function nt(t){const i=[],e=[];q.forEach(n=>t.indexOf(n)===-1?i.push(n):e.push(n)),e.forEach(n=>n()),q=i}const ot=new Set;function st(t,i){t&&t.i&&(ot.delete(t),t.i(i))}function ye(t){return(t==null?void 0:t.length)!==void 0?t:Array.from(t)}function rt(t,i,e){const{fragment:n,after_update:o}=t.$$;n&&n.m(i,e),ne(()=>{const s=t.$$.on_mount.map(Re).filter(Ie);t.$$.on_destroy?t.$$.on_destroy.push(...s):J(s),t.$$.on_mount=[]}),o.forEach(ne)}function at(t,i){const e=t.$$;e.fragment!==null&&(nt(e.after_update),J(e.on_destroy),e.fragment&&e.fragment.d(i),e.on_destroy=e.fragment=null,e.ctx=[])}function lt(t,i){t.$$.dirty[0]===-1&&(z.push(t),tt(),t.$$.dirty.fill(0)),t.$$.dirty[i/31|0]|=1<<i%31}function He(t,i,e,n,o,s,r=null,a=[-1]){const h=G;V(t);const c=t.$$={fragment:null,ctx:[],props:s,update:$,not_equal:o,bound:fe(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(i.context||(h?h.$$.context:[])),callbacks:fe(),dirty:a,skip_bound:!1,root:i.target||h.$$.root};r&&r(c.root);let d=!1;if(c.ctx=e?e(t,i.props||{},(l,g,...m)=>{const f=m.length?m[0]:g;return c.ctx&&o(c.ctx[l],c.ctx[l]=f)&&(!c.skip_bound&&c.bound[l]&&c.bound[l](f),d&<(t,l)),g}):[],c.update(),d=!0,J(c.before_update),c.fragment=n?n(c.ctx):!1,i.target){if(i.hydrate){const l=Xe(i.target);c.fragment&&c.fragment.l(l),l.forEach(O)}else c.fragment&&c.fragment.c();i.intro&&st(t.$$.fragment),rt(t,i.target,i.anchor),Ce()}V(h)}class Oe{constructor(){u(this,"$$");u(this,"$$set")}$destroy(){at(this,1),this.$destroy=$}$on(i,e){if(!Ie(e))return $;const n=this.$$.callbacks[i]||(this.$$.callbacks[i]=[]);return n.push(e),()=>{const o=n.indexOf(e);o!==-1&&n.splice(o,1)}}$set(i){this.$$set&&!Je(i)&&(this.$$.skip_bound=!0,this.$$set(i),this.$$.skip_bound=!1)}}const ht="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ht);function ve(t){let i,e,n,o,s,r,a,h,c,d,l,g,m,f,E,D;return{c(){i=P("svg"),e=P("circle"),o=P("path"),r=P("g"),a=P("path"),c=P("path"),l=P("path"),m=P("animateTransform"),p(e,"cx","64.13"),p(e,"cy","64.13"),p(e,"r","27.63"),p(e,"fill",n=t[0].fill),p(o,"d","M64.13 18.5A45.63 45.63 0 1 1 18.5 64.13 45.63 45.63 0 0 1 64.13 18.5zm0 7.85a37.78 37.78 0 1 1-37.78 37.78 37.78 37.78 0 0 1 37.78-37.78z"),p(o,"fill-rule","evenodd"),p(o,"fill",s=t[0].fill),p(a,"d","M95.25 17.4a56.26 56.26 0 0 0-76.8 13.23L12.1 26.2a64 64 0 0 1 87.6-15.17z"),p(a,"fill",h=t[0].fill),p(c,"d","M95.25 17.4a56.26 56.26 0 0 0-76.8 13.23L12.1 26.2a64 64 0 0 1 87.6-15.17z"),p(c,"fill",d=t[0].fill),p(c,"transform","rotate(120 64 64)"),p(l,"d","M95.25 17.4a56.26 56.26 0 0 0-76.8 13.23L12.1 26.2a64 64 0 0 1 87.6-15.17z"),p(l,"fill",g=t[0].fill),p(l,"transform","rotate(240 64 64)"),p(m,"attributeName","transform"),p(m,"type","rotate"),p(m,"from","0 64 64"),p(m,"to","120 64 64"),p(m,"dur","360ms"),p(m,"repeatCount","indefinite"),p(i,"xmlns","http://www.w3.org/2000/svg"),p(i,"width",f=t[0].size),p(i,"height",E=t[0].size),p(i,"viewBox","0 0 128 128"),p(i,"xml:space","preserve"),p(i,"class",D=t[0].class)},m(v,_){B(v,i,_),w(i,e),w(i,o),w(i,r),w(r,a),w(r,c),w(r,l),w(r,m)},p(v,_){_&1&&n!==(n=v[0].fill)&&p(e,"fill",n),_&1&&s!==(s=v[0].fill)&&p(o,"fill",s),_&1&&h!==(h=v[0].fill)&&p(a,"fill",h),_&1&&d!==(d=v[0].fill)&&p(c,"fill",d),_&1&&g!==(g=v[0].fill)&&p(l,"fill",g),_&1&&f!==(f=v[0].size)&&p(i,"width",f),_&1&&E!==(E=v[0].size)&&p(i,"height",E),_&1&&D!==(D=v[0].class)&&p(i,"class",D)},d(v){v&&O(i)}}}function pt(t){let i,e=t[1]&&ve(t);return{c(){e&&e.c(),i=Fe()},m(n,o){e&&e.m(n,o),B(n,i,o)},p(n,[o]){n[1]?e?e.p(n,o):(e=ve(n),e.c(),e.m(i.parentNode,i)):e&&(e.d(1),e=null)},i:$,o:$,d(n){n&&O(i),e&&e.d(n)}}}function ct(t,i,e){let{directions:n}=i,{configuration:o}=i,s;return n.on("fetchroutesstart",()=>{e(1,s=!0)}),n.on("fetchroutesend",()=>{e(1,s=!1)}),t.$$set=r=>{"directions"in r&&e(2,n=r.directions),"configuration"in r&&e(0,o=r.configuration)},[o,s,n]}class dt extends Oe{constructor(i){super(),He(this,i,ct,pt,Te,{directions:2,configuration:0})}}const gt={fill:"#6d26d7",size:"24px",class:""};class ut{constructor(i,e){u(this,"controlElement");u(this,"directions");u(this,"configuration");this.directions=i,this.configuration=Object.assign({},gt,e)}onAdd(){return this.controlElement=document.createElement("div"),new dt({target:this.controlElement,props:{directions:this.directions,configuration:this.configuration}}),this.controlElement}onRemove(){this.controlElement.remove()}}function be(t,i,e){const n=t.slice();return n[16]=i[e],n[17]=i,n[18]=e,n}function ft(t){let i,e,n,o,s,r,a,h,c;function d(){t[11].call(i,t[17],t[18])}return{c(){i=S("input"),r=k(),a=S("span"),a.textContent="°",p(i,"type","number"),i.disabled=e=!t[16].enabled,p(i,"min",n=t[0].degreesMin),p(i,"max",o=t[0].degreesMax),p(i,"step",s=t[0].degreesStep),p(i,"class","maplibre-gl-directions-bearings-control__input"),p(a,"class","maplibre-gl-directions-bearings-control__text")},m(l,g){B(l,i,g),Q(i,t[16].degrees),B(l,r,g),B(l,a,g),h||(c=F(i,"input",d),h=!0)},p(l,g){t=l,g&2&&e!==(e=!t[16].enabled)&&(i.disabled=e),g&1&&n!==(n=t[0].degreesMin)&&p(i,"min",n),g&1&&o!==(o=t[0].degreesMax)&&p(i,"max",o),g&1&&s!==(s=t[0].degreesStep)&&p(i,"step",s),g&2&&K(i.value)!==t[16].degrees&&Q(i,t[16].degrees)},d(l){l&&(O(i),O(r),O(a)),h=!1,c()}}}function mt(t){let i,e=t[0].fixedDegrees+"",n,o;return{c(){i=S("span"),n=X(e),o=X("°"),p(i,"class","maplibre-gl-directions-bearings-control__text")},m(s,r){B(s,i,r),w(i,n),w(i,o)},p(s,r){r&1&&e!==(e=s[0].fixedDegrees+"")&&Ke(n,e)},d(s){s&&O(i)}}}function _e(t){let i,e,n,o,s,r,a,h,c,d,l,g=t[18],m,f,E,D,v,_,y,b,R,T,j,W,C,U,oe;function ke(){t[7].call(o,t[17],t[18])}const se=()=>t[8](r,g),re=()=>t[8](null,g);function Be(...H){return t[9](t[18],...H)}function We(){t[10].call(f,t[17],t[18])}function ae(H,L){return H[0].fixedDegrees?mt:ft}let Y=ae(t),I=Y(t);return{c(){i=S("div"),e=S("span"),e.textContent=`${t[18]+1}.`,n=k(),o=S("input"),s=k(),r=S("div"),a=P("svg"),h=P("circle"),l=P("circle"),m=k(),f=S("input"),y=k(),b=S("span"),b.textContent="°",R=k(),T=S("span"),T.textContent="±",j=k(),I.c(),W=k(),p(e,"class","maplibre-gl-directions-bearings-control__number text-slate-800"),p(o,"type","checkbox"),p(o,"class","maplibre-gl-directions-bearings-control__checkbox"),p(h,"r","5"),p(h,"cx","10"),p(h,"cy","10"),p(h,"fill","transparent"),p(h,"stroke","rgba(109, 38, 215, 0.65)"),p(h,"stroke-width","10"),p(h,"stroke-dasharray",c=t[16].degrees/3.6*31.42/100+" 31.42"),p(h,"transform",d="rotate("+(-90-t[16].degrees/2+t[16].angle-t[3])+")"),A(h,"transform-origin","10px 10px"),p(l,"r","6"),p(l,"cx","10"),p(l,"cy","10"),p(l,"fill","rgb(109, 38, 215)"),p(a,"height","20"),p(a,"width","20"),p(a,"viewBox","0 0 20 20"),p(a,"class","maplibre-gl-directions-bearings-control__waypoint-image"),A(a,"width",t[0].imageSize+"px"),A(a,"height",t[0].imageSize+"px"),A(a,"opacity",t[16].enabled?1:.25),p(r,"role","spinbutton"),p(r,"tabindex","0"),p(f,"type","number"),f.disabled=E=!t[16].enabled,p(f,"min",D=t[0].angleMin),p(f,"max",v=t[0].angleMax),p(f,"step",_=t[0].angleStep),p(f,"class","maplibre-gl-directions-bearings-control__input"),p(b,"class","maplibre-gl-directions-bearings-control__text"),p(T,"class","maplibre-gl-directions-bearings-control__text"),p(i,"class",C="maplibre-gl-directions-bearings-control__list-item "+(t[16].enabled?"maplibre-gl-directions-bearings-control__list-item--enabled":"maplibre-gl-directions-bearings-control__list-item--disabled")+" flex items-center gap-2 text-slate-800"+(t[16].enabled?"":"/50"))},m(H,L){B(H,i,L),w(i,e),w(i,n),w(i,o),o.checked=t[16].enabled,w(i,s),w(i,r),w(r,a),w(a,h),w(a,l),se(),w(i,m),w(i,f),Q(f,t[16].angle),w(i,y),w(i,b),w(i,R),w(i,T),w(i,j),I.m(i,null),w(i,W),U||(oe=[F(o,"change",ke),F(r,"mousedown",Be),F(f,"input",We)],U=!0)},p(H,L){t=H,L&2&&(o.checked=t[16].enabled),L&2&&c!==(c=t[16].degrees/3.6*31.42/100+" 31.42")&&p(h,"stroke-dasharray",c),L&10&&d!==(d="rotate("+(-90-t[16].degrees/2+t[16].angle-t[3])+")")&&p(h,"transform",d),L&1&&A(a,"width",t[0].imageSize+"px"),L&1&&A(a,"height",t[0].imageSize+"px"),L&2&&A(a,"opacity",t[16].enabled?1:.25),g!==t[18]&&(re(),g=t[18],se()),L&2&&E!==(E=!t[16].enabled)&&(f.disabled=E),L&1&&D!==(D=t[0].angleMin)&&p(f,"min",D),L&1&&v!==(v=t[0].angleMax)&&p(f,"max",v),L&1&&_!==(_=t[0].angleStep)&&p(f,"step",_),L&2&&K(f.value)!==t[16].angle&&Q(f,t[16].angle),Y===(Y=ae(t))&&I?I.p(t,L):(I.d(1),I=Y(t),I&&(I.c(),I.m(i,W))),L&2&&C!==(C="maplibre-gl-directions-bearings-control__list-item "+(t[16].enabled?"maplibre-gl-directions-bearings-control__list-item--enabled":"maplibre-gl-directions-bearings-control__list-item--disabled")+" flex items-center gap-2 text-slate-800"+(t[16].enabled?"":"/50"))&&p(i,"class",C)},d(H){H&&O(i),re(),I.d(),U=!1,J(oe)}}}function yt(t){let i,e,n,o=ye(t[1]),s=[];for(let r=0;r<o.length;r+=1)s[r]=_e(be(t,o,r));return{c(){i=S("div"),e=S("div");for(let r=0;r<s.length;r+=1)s[r].c();p(e,"class","maplibre-gl-directions-bearings-control__list flex flex-col max-h-96 overflow-y-auto"),p(i,"class",n="maplibre-gl-directions-bearings-control maplibregl-ctrl maplibregl-ctrl-group p-4 "+(t[1].length?"block":"hidden")+" bg-white text-base rounded")},m(r,a){B(r,i,a),w(i,e);for(let h=0;h<s.length;h+=1)s[h]&&s[h].m(e,null)},p(r,[a]){if(a&31){o=ye(r[1]);let h;for(h=0;h<o.length;h+=1){const c=be(r,o,h);s[h]?s[h].p(c,a):(s[h]=_e(c),s[h].c(),s[h].m(e,null))}for(;h<s.length;h+=1)s[h].d(1);s.length=o.length}a&2&&n!==(n="maplibre-gl-directions-bearings-control maplibregl-ctrl maplibregl-ctrl-group p-4 "+(r[1].length?"block":"hidden")+" bg-white text-base rounded")&&p(i,"class",n)},i:$,o:$,d(r){r&&O(i),Ye(s,r)}}}function vt(t,i,e){let{directions:n}=i,{configuration:o}=i;n.configuration.bearings||console.warn("The Bearings Control is used, but the `bearings` configuration option is not enabled!");let s=[];n.on("addwaypoint",r),n.on("removewaypoint",r),n.on("movewaypoint",r),n.on("setwaypoints",r);function r(){e(1,s=n.waypointsBearings.map((y,b)=>s[b]?s[b]:{enabled:o.defaultEnabled||!!y,angle:y?y[0]:o.angleDefault,degrees:y?y[1]:o.fixedDegrees?o.fixedDegrees:o.degreesDefault}))}r();let a;const h=[];let c=-1;function d(y,b){var R;(R=s[b])!=null&&R.enabled&&(c=b,document.addEventListener("mouseup",l),document.addEventListener("mousemove",g))}function l(){c=-1,document.removeEventListener("mouseup",l),document.removeEventListener("mousemove",g)}function g(y){const b=h[c];if(b){const R=b.getBoundingClientRect().x+o.imageSize/2,T=b.getBoundingClientRect().y+o.imageSize/2,j=y.pageX,W=y.pageY,U=Math.atan2(j-R,W-T)*(180/Math.PI)*-1+90;e(1,s[c].angle=90+U+m|0,s)}}Ze(()=>{document.removeEventListener("mouseup",l),document.removeEventListener("mousemove",g)});let m=0;o.respectMapBearing&&n.map.on("rotate",()=>e(3,m=n.map.getBearing()));function f(y,b){y[b].enabled=this.checked,e(1,s)}function E(y,b){te[y?"unshift":"push"](()=>{h[b]=y,e(2,h)})}const D=(y,b)=>d(b,y);function v(y,b){y[b].angle=K(this.value),e(1,s)}function _(y,b){y[b].degrees=K(this.value),e(1,s)}return t.$$set=y=>{"directions"in y&&e(5,n=y.directions),"configuration"in y&&e(0,o=y.configuration)},t.$$.update=()=>{t.$$.dirty&67&&(a&&clearTimeout(a),e(6,a=setTimeout(()=>{e(5,n.waypointsBearings=s.map(y=>y.enabled?[y.angle,y.degrees]:void 0),n)},o.debounceTimeout)))},[o,s,h,m,d,n,a,f,E,D,v,_]}let bt=class extends Oe{constructor(i){super(),He(this,i,vt,yt,Te,{directions:5,configuration:0})}};const _t={defaultEnabled:!1,debounceTimeout:150,angleDefault:0,angleMin:0,angleMax:359,angleStep:1,fixedDegrees:0,degreesDefault:45,degreesMin:15,degreesMax:360,degreesStep:15,respectMapBearing:!1,imageSize:50};class wt{constructor(i,e){u(this,"controlElement");u(this,"directions");u(this,"configuration");this.directions=i,this.configuration=Object.assign({},_t,e)}onAdd(){return this.controlElement=document.createElement("div"),new bt({target:this.controlElement,props:{directions:this.directions,configuration:this.configuration}}),this.controlElement}onRemove(){this.controlElement.remove()}}exports.BearingsControl=wt;exports.LoadingIndicatorControl=ut;exports.MapLibreGlDirectionsRoutingEvent=ee;exports.MapLibreGlDirectionsWaypointEvent=N;exports.default=Ge;exports.layersFactory=we;exports.utils=Ve;
//# sourceMappingURL=maplibre-gl-directions.cjs.map