UNPKG

atriusmaps-node-sdk

Version:

This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information

2 lines (1 loc) 5.88 kB
import{bearing as e}from"@turf/bearing";import{point as t}from"@turf/helpers";import{compose as r,not as n,includes as a,__ as s,toLower as i,prop as o,find as c,drop as u,last as T,propEq as A}from"ramda";import{findBoundsOfWaypoints as S}from"../../../src/utils/bounds.js";import{metersToYards as _}from"../../../src/utils/distance.js";import{bearingToDirection as R,distance as E}from"../../../src/utils/geodesy.js";import d from"./segmentBadges.js";import I from"./segmentCategories.js";function O(r,n="",a="",s,i,c={},u,T=[],A){return r.map((u,E)=>{const O=m("securityWaitTimes")(u.waypoints),p=O&&!O.isTemporarilyClosed?O.queueTime:Math.round(function(e){if(1===e.length)return e[0].eta;return e.map(o("eta")).slice(1).reduce((e,t)=>e+t,0)}(u.waypoints)),C=Math.round(function(e){if(1===e.length)return e[0].distance;return e.map(e=>e.distance).slice(1).reduce((e,t)=>e+t,0)}(u.waypoints)),P="yards"===A?_(C):C,W=function(e){switch(e){case I.START:return d.START;case I.WALKING_TO_END:return d.END;case I.ELEVATOR:return d.ELEVATOR;case I.ELEVATOR_UP:return d.ELEVATOR_UP;case I.ELEVATOR_DOWN:return d.ELEVATOR_DOWN;case I.STAIRS:return d.STAIRS;case I.STAIRS_UP:return d.STAIRS_UP;case I.STAIRS_DOWN:return d.STAIRS_DOWN;case I.ACCESSIBLE_STAIRS:return d.ACCESSIBLE_STAIRS;case I.ACCESSIBLE_STAIRS_UP:return d.ACCESSIBLE_STAIRS_UP;case I.ACCESSIBLE_STAIRS_DOWN:return d.ACCESSIBLE_STAIRS_DOWN;case I.ESCALATOR:return d.ESCALATOR;case I.ESCALATOR_UP:return d.ESCALATOR_UP;case I.ESCALATOR_DOWN:return d.ESCALATOR_DOWN;case I.WALKING_TO_PORTAL:case I.WALK:case I.WALK_DOWN:case I.WALK_UP:return d.WALK;case I.TRAIN:return d.TRAIN;case I.TRAIN_UP:return d.TRAIN_UP;case I.TRAIN_DOWN:return d.TRAIN_DOWN;case I.BUS:return d.BUS;case I.BUS_UP:return d.BUS_UP;case I.BUS_DOWN:return d.BUS_DOWN;case I.SECURITY_CHECKPOINT:return d.SECURITY_CHECKPOINT;case I.RAMP:return d.RAMP;case I.RAMP_UP:return d.RAMP_UP;case I.RAMP_DOWN:return d.RAMP_DOWN;default:return d.WALK}}(u.segmentCategory),U=function(e,t){let r;switch(e){case I.START:r=0;break;case I.WALKING_TO_END:r=t.length-1;break;case I.WALKING_TO_PORTAL:r=Math.min(t.length-1,Math.ceil(t.length/2));break;default:r=t.length-1}return t[r].position}(u.segmentCategory,u.waypoints),D=(({waypoints:r},n)=>{const[a]=r,s=r[r.length-1],i=t([a.position.lng,a.position.lat]),o=t([s.position.lng,s.position.lat]),c=e(i,o);return R(c,n)})(u,i),g=function(e,t,r,n,a,s,i,o){const c=e[t];switch(c.segmentCategory){case I.START:return l(c.waypoints[0].position,r);case I.WALKING_TO_END:return l(c.waypoints[c.waypoints.length-1].position,n);case I.WALKING_TO_SECURITY_CHECKPOINT:{const r=e[t+1].waypoints,n=N(o,r),a=n?s("wayfinder:Security Lane",{laneName:n}):null,u=w(r,i);return a||u||s(`wayfinder:${c.type}`)}case I.WALKING_TO_PORTAL:return s(`wayfinder:${e[t+1].type}`);case I.SECURITY_CHECKPOINT:{const e=N(o,c.waypoints),t=e?s("wayfinder:Security Lane",{laneName:e}):null,r=w(c.waypoints,i);return t||r||y(c,a)}case I.ELEVATOR:case I.ELEVATOR_DOWN:case I.ELEVATOR_UP:case I.ESCALATOR:case I.ESCALATOR_DOWN:case I.ESCALATOR_UP:case I.STAIRS:case I.STAIRS_DOWN:case I.STAIRS_UP:case I.ACCESSIBLE_STAIRS:case I.ACCESSIBLE_STAIRS_DOWN:case I.ACCESSIBLE_STAIRS_UP:return y(c,a);default:return s(`wayfinder:${c.type}`)}}(r,E,n,a,s,i,T,c),K={primaryText:g,secondaryText:L(u,p,i,!1),secondaryTextUI:L(u,p,i,!0,D,A,P),icon:W,animationAnchor:U,eta:p,distance:C,bounds:S(u.waypoints),isAccessible:f(u),securityWaitTimes:O};return u.poiId&&(K.poiId=u.poiId),K})}function l(e,t){return e.name?e.name:t}function y(e,t){return t[T(e.waypoints).position.floorId]}function L(e,t,r,n,a,s,i){const o=C(t,r),c="Proceed";switch(e.segmentCategory){case I.START:return r("wayfinder:Begin route at");case I.ELEVATOR:return r("wayfinder:Take elevator to");case I.ELEVATOR_UP:return r("wayfinder:Take elevator up to");case I.ELEVATOR_DOWN:return r("wayfinder:Take elevator down to");case I.STAIRS:return r("wayfinder:Take stairs to");case I.STAIRS_UP:return r("wayfinder:Take stairs up to");case I.STAIRS_DOWN:return r("wayfinder:Take stairs down to");case I.ACCESSIBLE_STAIRS:return r("wayfinder:Take accessible stairs to");case I.ACCESSIBLE_STAIRS_UP:return r("wayfinder:Take accessible stairs up to");case I.ACCESSIBLE_STAIRS_DOWN:return r("wayfinder:Take accessible stairs down to");case I.ESCALATOR:return r("wayfinder:Take escalator to");case I.ESCALATOR_UP:return r("wayfinder:Take escalator up to");case I.ESCALATOR_DOWN:return r("wayfinder:Take escalator down to");case I.WALK:case I.WALKING_TO_SECURITY_CHECKPOINT:case I.WALKING_TO_PORTAL:case I.WALKING_TO_END:return n?p(i,s,a,r):o(`${c} <1 minute to`,`${c} xx minute to`);case I.WALK_DOWN:return o(`${c} <1 minute down to`,`${c} xx minute down to`);case I.WALK_UP:return o(`${c} <1 minute up to`,`${c} xx minute up to`);case I.TRAIN:return o("Take train <1 minute","Take train xx minute");case I.BUS:return o("Take bus <1 minute","Take bus xx minute");case I.SECURITY_CHECKPOINT:return r("wayfinder:Through");case I.RAMP:return r("wayfinder:Take ramp to");case I.RAMP_UP:return r("wayfinder:Take ramp up to");case I.RAMP_DOWN:return r("wayfinder:Take ramp down to");default:return""}}const p=(e,t,r,n)=>n("meters"===t?"wayfinder:Proceed __direction__ __count__ meter to":"wayfinder:Proceed __direction__ __count__ yard to",{direction:r,count:e}),C=(e,t)=>(r,n)=>0===e?t("wayfinder:"+r):t("wayfinder:"+n,{count:e}),f=r(n,a(s,["escalator","stairs"]),i,o("type")),N=(e,t)=>{const r=m("securityLane")(t);if(!r)return;const n=o(r.type,e),a=c(A(r.id,"id"),n);return o("displayText",a)},m=e=>r(o(e),c(o(e)),u(1)),w=(e,t)=>{if(!e||0===e.length)return null;const r=e[0],{lat:n,lng:a,floorId:s}=r.position,i=t.filter(e=>e.position&&e.position.floorId===s);let o=null,c=1/0;return i.forEach(e=>{const t=E(n,a,e.position.latitude,e.position.longitude);t<c&&(c=t,o=e)}),o?o.name:null};export{O as default};