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