@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 16.2 kB
JavaScript
import{__esDecorate as a,__runInitializers as r}from"tslib";import{action as m,computed as x,observable as f}from"mobx";import{lineLength as Fe,Point as He}from"simple-geometry";import{getName as Je}from"../components/Kiosk/SetKiosk";import{DEFAULT_UNITS as Ne,ORIENTATION_GRANTED_KEY as Qe}from"../constants";import S from"../core/Rect";import Be from"../data";import{fpGeo as P}from"../data/fpGeo";import{getLayerSvg as et,svgArea as k}from"../data/svg";import{GaEventActions as tt,sendEventToGa as st}from"../tools/gtag";import Ue from"../tools/logger";import{areLayersEnabled as it}from"../utils/areLayersEnabled";import{calcSpeed as Ze}from"../utils/calcSpeed";import{calcTravelTime as qe}from"../utils/calcTravelTime";import{calculateRelativeBearing as at,convertGpsToLocal as $e,isValidPointCoords as Ve}from"../utils/gps";import{boothToEndpoint as Ke,CURRENT_LOCATION_NAME as rt,CURRENT_POSITION_POINT_ID as nt,graphDataSource as je,KIOSK_ANCHOR_POINT_ID as ot,toArbitraryPoint as We}from"../wayfinding/adapters";import{createWayfindingEngine as lt}from"../wayfinding/core";import u,{layersStore as T}from".";import{BoothBase as R}from"./BoothStore";import{uiState as _}from"./index";import{LayersMode as ct}from"./LayerStore";const b=s=>typeof s=="string"?Number(s.replace(",",".")):s;let ut=(()=>{let s=[],n,l=[],p=[],y,v=[],g=[],z,D=[],I=[],A,w=[],M=[],C,G=[],O=[],F,N=[],B=[],U,Z=[],q=[],$,V=[],K=[],j,W=[],X=[],Y,H=[],J=[],Q,ee=[],te=[],se,ie=[],ae=[],re,ne=[],oe=[],le,ce=[],ue=[],de,fe,he,me,pe,_e,ye,ge,ke,be,Re,ve,xe,Ee=[],Le=[],Te,Se,Pe,ze,De,Ie,Ae=[],we=[],Me,Ce,Ge;return class{static{const t=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;n=[f],y=[f],z=[f],A=[f],C=[f],F=[f],U=[f],$=[f],j=[f],Y=[f],Q=[f],se=[f],re=[f],le=[f],de=[x],fe=[m],he=[m],me=[m],pe=[x({keepAlive:!0})],_e=[m],ye=[m],ge=[x({keepAlive:!0})],ke=[x({keepAlive:!0})],be=[m],Re=[m],ve=[m],xe=[f],Te=[x],Se=[m],Pe=[m],ze=[m],De=[m],Ie=[f],Me=[m],Ce=[x({keepAlive:!0})],Ge=[m],a(this,null,de,{kind:"getter",name:"canFindLocation",static:!1,private:!1,access:{has:e=>"canFindLocation"in e,get:e=>e.canFindLocation},metadata:t},null,s),a(this,null,fe,{kind:"method",name:"selectRoute",static:!1,private:!1,access:{has:e=>"selectRoute"in e,get:e=>e.selectRoute},metadata:t},null,s),a(this,null,he,{kind:"method",name:"rebuildRouteFromPosition",static:!1,private:!1,access:{has:e=>"rebuildRouteFromPosition"in e,get:e=>e.rebuildRouteFromPosition},metadata:t},null,s),a(this,null,me,{kind:"method",name:"setStartPoint",static:!1,private:!1,access:{has:e=>"setStartPoint"in e,get:e=>e.setStartPoint},metadata:t},null,s),a(this,null,pe,{kind:"getter",name:"pathLayers",static:!1,private:!1,access:{has:e=>"pathLayers"in e,get:e=>e.pathLayers},metadata:t},null,s),a(this,null,_e,{kind:"method",name:"setMarkers",static:!1,private:!1,access:{has:e=>"setMarkers"in e,get:e=>e.setMarkers},metadata:t},null,s),a(this,null,ye,{kind:"method",name:"selectMarker",static:!1,private:!1,access:{has:e=>"selectMarker"in e,get:e=>e.selectMarker},metadata:t},null,s),a(this,null,ge,{kind:"getter",name:"selectedMarkers",static:!1,private:!1,access:{has:e=>"selectedMarkers"in e,get:e=>e.selectedMarkers},metadata:t},null,s),a(this,null,ke,{kind:"getter",name:"layers",static:!1,private:!1,access:{has:e=>"layers"in e,get:e=>e.layers},metadata:t},null,s),a(this,null,be,{kind:"method",name:"clickRoute",static:!1,private:!1,access:{has:e=>"clickRoute"in e,get:e=>e.clickRoute},metadata:t},null,s),a(this,null,Re,{kind:"method",name:"selectCurrentPosition",static:!1,private:!1,access:{has:e=>"selectCurrentPosition"in e,get:e=>e.selectCurrentPosition},metadata:t},null,s),a(this,null,ve,{kind:"method",name:"findLocation",static:!1,private:!1,access:{has:e=>"findLocation"in e,get:e=>e.findLocation},metadata:t},null,s),a(this,null,Te,{kind:"getter",name:"routeInfo",static:!1,private:!1,access:{has:e=>"routeInfo"in e,get:e=>e.routeInfo},metadata:t},null,s),a(this,null,Se,{kind:"method",name:"updateRoute",static:!1,private:!1,access:{has:e=>"updateRoute"in e,get:e=>e.updateRoute},metadata:t},null,s),a(this,null,Pe,{kind:"method",name:"updateRouteDistance",static:!1,private:!1,access:{has:e=>"updateRouteDistance"in e,get:e=>e.updateRouteDistance},metadata:t},null,s),a(this,null,ze,{kind:"method",name:"updateRoutePoints",static:!1,private:!1,access:{has:e=>"updateRoutePoints"in e,get:e=>e.updateRoutePoints},metadata:t},null,s),a(this,null,De,{kind:"method",name:"checkRoutes",static:!1,private:!1,access:{has:e=>"checkRoutes"in e,get:e=>e.checkRoutes},metadata:t},null,s),a(this,null,Me,{kind:"method",name:"setGpsTrackingEnabled",static:!1,private:!1,access:{has:e=>"setGpsTrackingEnabled"in e,get:e=>e.setGpsTrackingEnabled},metadata:t},null,s),a(this,null,Ce,{kind:"getter",name:"gpsEnabled",static:!1,private:!1,access:{has:e=>"gpsEnabled"in e,get:e=>e.gpsEnabled},metadata:t},null,s),a(this,null,Ge,{kind:"method",name:"setOnlyAccessible",static:!1,private:!1,access:{has:e=>"setOnlyAccessible"in e,get:e=>e.setOnlyAccessible},metadata:t},null,s),a(null,null,n,{kind:"field",name:"routeLines",static:!1,private:!1,access:{has:e=>"routeLines"in e,get:e=>e.routeLines,set:(e,i)=>{e.routeLines=i}},metadata:t},l,p),a(null,null,y,{kind:"field",name:"routeDistance",static:!1,private:!1,access:{has:e=>"routeDistance"in e,get:e=>e.routeDistance,set:(e,i)=>{e.routeDistance=i}},metadata:t},v,g),a(null,null,z,{kind:"field",name:"currentPosition",static:!1,private:!1,access:{has:e=>"currentPosition"in e,get:e=>e.currentPosition,set:(e,i)=>{e.currentPosition=i}},metadata:t},D,I),a(null,null,A,{kind:"field",name:"requestCompass",static:!1,private:!1,access:{has:e=>"requestCompass"in e,get:e=>e.requestCompass,set:(e,i)=>{e.requestCompass=i}},metadata:t},w,M),a(null,null,C,{kind:"field",name:"iconType",static:!1,private:!1,access:{has:e=>"iconType"in e,get:e=>e.iconType,set:(e,i)=>{e.iconType=i}},metadata:t},G,O),a(null,null,F,{kind:"field",name:"tempToBooth",static:!1,private:!1,access:{has:e=>"tempToBooth"in e,get:e=>e.tempToBooth,set:(e,i)=>{e.tempToBooth=i}},metadata:t},N,B),a(null,null,U,{kind:"field",name:"focusEnabled",static:!1,private:!1,access:{has:e=>"focusEnabled"in e,get:e=>e.focusEnabled,set:(e,i)=>{e.focusEnabled=i}},metadata:t},Z,q),a(null,null,$,{kind:"field",name:"prevZ",static:!1,private:!1,access:{has:e=>"prevZ"in e,get:e=>e.prevZ,set:(e,i)=>{e.prevZ=i}},metadata:t},V,K),a(null,null,j,{kind:"field",name:"markersData",static:!1,private:!1,access:{has:e=>"markersData"in e,get:e=>e.markersData,set:(e,i)=>{e.markersData=i}},metadata:t},W,X),a(null,null,Y,{kind:"field",name:"prevMarkers",static:!1,private:!1,access:{has:e=>"prevMarkers"in e,get:e=>e.prevMarkers,set:(e,i)=>{e.prevMarkers=i}},metadata:t},H,J),a(null,null,Q,{kind:"field",name:"showAccessible",static:!1,private:!1,access:{has:e=>"showAccessible"in e,get:e=>e.showAccessible,set:(e,i)=>{e.showAccessible=i}},metadata:t},ee,te),a(null,null,se,{kind:"field",name:"onlyAccessible",static:!1,private:!1,access:{has:e=>"onlyAccessible"in e,get:e=>e.onlyAccessible,set:(e,i)=>{e.onlyAccessible=i}},metadata:t},ie,ae),a(null,null,re,{kind:"field",name:"currentRouteLayer",static:!1,private:!1,access:{has:e=>"currentRouteLayer"in e,get:e=>e.currentRouteLayer,set:(e,i)=>{e.currentRouteLayer=i}},metadata:t},ne,oe),a(null,null,le,{kind:"field",name:"currentRouteExhibitor",static:!1,private:!1,access:{has:e=>"currentRouteExhibitor"in e,get:e=>e.currentRouteExhibitor,set:(e,i)=>{e.currentRouteExhibitor=i}},metadata:t},ce,ue),a(null,null,xe,{kind:"field",name:"routeUnits",static:!1,private:!1,access:{has:e=>"routeUnits"in e,get:e=>e.routeUnits,set:(e,i)=>{e.routeUnits=i}},metadata:t},Ee,Le),a(null,null,Ie,{kind:"field",name:"isGpsTrackingEnabled",static:!1,private:!1,access:{has:e=>"isGpsTrackingEnabled"in e,get:e=>e.isGpsTrackingEnabled,set:(e,i)=>{e.isGpsTrackingEnabled=i}},metadata:t},Ae,we),t&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:t})}rootStore=r(this,s);cpTimeout;routeLines=r(this,l,[]);routeDistance=(r(this,p),r(this,v,null));currentPosition=(r(this,g),r(this,D,null));requestCompass=(r(this,I),r(this,w,!1));iconType=(r(this,M),r(this,G,0));tempToBooth=(r(this,O),r(this,N,null));focusEnabled=(r(this,B),r(this,Z,!0));prevZ=(r(this,q),r(this,V,null));markersData=(r(this,K),r(this,W,{icons:[],markers:[]}));prevMarkers=(r(this,X),r(this,H,[]));showAccessible=(r(this,J),r(this,ee,!!je.getLines().find(t=>t.unaccessible)));onlyAccessible=(r(this,te),r(this,ie,!1));currentRouteLayer=(r(this,ae),r(this,ne,null));currentRouteExhibitor=(r(this,oe),r(this,ce,null));constructor(t){r(this,we),this.rootStore=t,this.focusEnabled=!window.location.search}get canFindLocation(){return!!_.kioskData||!!this.currentPosition}selectRoute(t,e=!0,i=!1){if(e&&(_.list={type:"search",text:"",focused:!1}),t&&!t.from&&t.to){const d=this.resolveFallbackFrom();d&&(t=new Route(d,t.to,t.waypoints))}t?.from&&t?.to&&t.from===t.to&&(t=null);let o=[];t?.from&&t?.to&&window.setTimeout(()=>{this.rootStore.showMap()},navigator.userAgent.toLowerCase().indexOf("android")>-1?400:50),t?.from instanceof R&&t.from.visible&&o.push(t.from),t?.to instanceof R&&t.to.visible&&(this.tempToBooth=null,o.push(t.to)),!t&&u.fp.onDirection&&u.fp.onDirection(null);const c=()=>{if(this.rootStore.moveToList(o),_.details=t,t&&(!t.from||!t.to)&&u.showOverlay(),t?.to&&t?.from){const d=dt(t.from);d&&this.rootStore.layerStore.updateVisibility(d,!0)}if(!this.currentRouteLayer){const d=Xe(this.rootStore.layerStore,t?.from),h=Xe(this.rootStore.layerStore,t?.to);d?this.currentRouteLayer=d:h&&(this.currentRouteLayer=h)}e&&t?.from&&t?.to&&st(tt.ClickDirections,`${t?.from?"From "+t.from.name:""} ${t?.to?"To "+t.to.name:""}`)};i?c():setTimeout(c,200)}rebuildRouteFromPosition(t){const e=_.selectedRoute;e?.to&&this.selectRoute(new Route(t,e.to,e.waypoints),!1,!0)}resolveFallbackFrom(){if(this.currentPosition)return We(this.currentPosition,rt,nt);const t=_.kioskData;return t?We({x:t.x,y:t.y,z:t.z},Je(),ot):null}setStartPoint(t){const e=_.selectedRoute;if(e?.to&&!e?.from&&t){const i=new Route(t,e.to,e.waypoints);this.selectRoute(i)}}get pathLayers(){return u.routeStore.routeLines?.map(t=>t.p0.layer)?.filter((t,e,i)=>i.indexOf(t)===e).reverse().map((t,e)=>({id:e+1,layer:u.layerStore.findLayer(t)}))}getNearestBooth(t){if(!t)return null;let e=this.rootStore.layerStore.findLayer(t.z);const i=t.lat&&t.lng?$e(t,P.properties.config):t;return this.rootStore.boothStore.booths.filter(o=>T.mode===ct.Default||!e?o.visible&&o.rect:o.rect&&(typeof t.z!="number"&&!t.z&&o.visible||e.name===o.layer?.name)).sort((o,c)=>Fe(i,{x:o.rect.cx,y:o.rect.cy})-Fe(i,{x:c.rect.cx,y:c.rect.cy}))[0]||null}setMarkers(t){this.markersData.markers=(t?.markers??[]).map(ft),this.markersData.icons=t?.icons??[]}selectMarker(t,e){const i=this.markersData.markers.find(c=>c.id===t);this.markersData.markers.forEach(c=>c.active=!1),i&&(i.active=!0);let o=u.layerStore.findLayer(i?.z);if(e&&i){const c=u.rendererService.renderer;return o&&!o?.visible&&T.updateVisibility(o,!0),c?c.controls.panTo(i.x,i.y):(Ue.warn("Renderer is not initialized. Cannot pan to marker."),Promise.resolve())}return Promise.resolve()}get selectedMarkers(){return this.markersData.markers.filter(t=>t.active)}get layers(){var t=[];return u.routeStore.routeLines?.map(e=>e.p0.layer).reverse().forEach(e=>{t.indexOf(e)===-1&&t.push(e)}),t.map(e=>u.layerStore.layers.find(i=>i.name===e))}clickRoute(t,e){window.__resett&&window.__resett(),this.rootStore.uiState.menu=null,_.list.type==="route-planner"&&(_.list={type:"search",text:"",focused:!1}),this.selectRoute(new Route(t,e))}selectCurrentPosition(t,e=!0,i){clearTimeout(this.cpTimeout),t&&(t.x=b(t.x),t.y=b(t.y),t.lat=b(t.lat),t.lng=b(t.lng),it()||(t.z=null));const o=e&&this.rootStore.uiState.details&&!(this.rootStore.uiState.details instanceof Route),c=e&&!o&&(this.focusEnabled||this.prevZ!=t?.z);this.focusEnabled&&(this.focusEnabled=!1),this.prevZ=t?.z?.toString(),this.iconType=i?1:0;const d=t?ht(t):null;if(!d){this.currentPosition=null;return}const h=u.layerStore.findLayer(t.z),E=new CurrentPosition(d.x,d.y,h?.name||this.currentRouteLayer?.name,at(d),t.lat,t.lng);let Oe=!this.routeLines?.length;if(h&&this.routeLines?.length&&(Oe=!!this.routeLines.find(L=>L.p0.layer===h.name||L.p1.layer===h.name)),c&&Oe){const L=u.rendererService.renderer;if(h&&!h?.visible&&T.updateVisibility(h,!0),!L){Ue.warn("Renderer is not initialized. Cannot pan to current position.");return}L.controls.panTo(E.x,E.y)}this.currentPosition=E,this.gpsEnabled||(this.cpTimeout=setTimeout(()=>{this.currentPosition&&this.selectCurrentPosition(null,!1)},30*1e3))}findLocation(){if(!this.canFindLocation)return;if(u.maplibreStore.showMaplibre){_.moveToLocation=!0;return}const t=this.currentPosition??_.kioskData;if(!t)return;this.currentPosition&&localStorage.getItem(Qe)==="false"&&(u.routeStore.requestCompass=!0);const e=S.fromCxcywh(t.x,t.y,100,100);let i;if(e.intersects(k))i=e;else{const c=Math.max(k.x1,Math.min(t.x,k.x2)),d=Math.max(k.y1,Math.min(t.y,k.y2)),h=Math.min(k.w,k.h)*.3,E=S.fromCxcywh(c,d,h,h).getIntersection(k);i=S.fromMultiple([e,E])}_.moveToRect=i;const o=u.layerStore.findLayer(t.z);o&&T.updateVisibility(o,!0)}routeUnits=(r(this,ue),r(this,Ee,Ne));get routeInfo(){const t=this.routeDistance,e=this.routeUnits;return t?{distance:`${t}${e}`,units:e,time:qe(t,Ze(e))}:null}updateRoute(t,e){!t?.length&&!this.routeLines.length||(this.routeLines=t,this.updateRoutePoints())}updateRouteDistance(t){if(t==null)return;const e=et(),i=(e.getAttribute("units")||Ne).toLowerCase?.().trim(),o=e.getAttribute("fp-ver")?.startsWith("5")??!1;this.routeDistance=Math.round(t/(o?1:10)),this.routeUnits=i,this.updateRoutePoints()}updateRoutePoints(){const t=_.selectedRoute,e=this.routeDistance,i=this.routeUnits;u.fp.onDirection&&setTimeout(()=>{u.fp.onDirection({from:Ye(t?.from??null),to:Ye(t?.to??null),lines:this.routeLines,distance:`${e}${i}`,units:i,time:qe(e,Ze(i))})},200)}checkRoutes(){const t=lt(je),e=u.boothStore.booths;console.info(`Route check started ${e.length}.... `);for(let i=0;i<e.length;i++){const o=e[i];for(let c=i+1;c<e.length;c++){const d=e[c];t.buildRoute(Ke(o),Ke(d)).lines.length||console.warn(`No route found from ${o.name} to ${d.name}`)}}console.info("Route check done....")}isGpsTrackingEnabled=(r(this,Le),r(this,Ae,!0));setGpsTrackingEnabled(t){this.isGpsTrackingEnabled=t}get gpsEnabled(){return Be.autoTrackingGps&&this.isGpsTrackingEnabled&&!Be.enableIPS}setOnlyAccessible(t){this.onlyAccessible=t}}})();export default ut;function dt(s){if(s)return s instanceof R?s.layer?.name:s.layer}function Xe(s,n){return n?n instanceof R?n.layer??null:s.findLayer(n.layer):null}function ft(s){return{...s,x:b(s.x),y:b(s.y),lat:b(s.lat),lng:b(s.lng)}}function ht(s){let n=null,l=null;return P&&(n=P.properties.config),n&&s.x>=n.p0.x&&s.x<=n.p2.x&&s.y>=n.p0.y&&s.y<=n.p2.y?l={...s}:n&&Ve(s.lat)&&Ve(s.lng)?l=$e(s,n):n||(l=s),l||null}export function findBooth(s){return u.boothStore.findBooth(s)||u.exhibitorStore.findExhibitor(s)?.booths[0]}export function findEntityByExternalId(s){const n=u.boothStore.boothByExternalId.get(s);if(n)return{type:"booth",entity:n};const l=u.exhibitorStore.exhibitorByExternalId.get(s);if(l)return{type:"exhibitor",entity:l}}export function separateExternalIds(s){const n=[],l=[];for(const p of s){const y=findEntityByExternalId(p);y&&(y.type==="booth"?n.push(p):l.push(p))}return{boothExternalIds:n,exhibitorExternalIds:l}}export function extractRoute(s,n,l){return new Route(findBooth(s)??null,findBooth(n)??null,l?.map(p=>findBooth(p)))}export class Route{from;to;waypoints;constructor(n,l,p){this.from=n,this.to=l,this.waypoints=p;const y=n instanceof R?n.id:void 0,v=l instanceof R?l.id:void 0;this.waypoints=p?.filter(g=>g&&g.id!==y&&g.id!==v)}}function Ye(s){return s?s instanceof R?{id:s.id,name:s.name,externalId:s.externalId,layer:{name:s.layer?.name,description:s.layer?.description}}:{id:Number.MAX_SAFE_INTEGER,name:s.name,externalId:void 0,layer:{name:s.layer,description:void 0}}:null}export class CurrentPosition extends He{x;y;z;angle;lat;lng;constructor(n,l,p,y,v,g){super(n,l),this.x=n,this.y=l,this.z=p,this.angle=y,this.lat=v,this.lng=g}}