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