@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 5.62 kB
JavaScript
import{__decorate as n}from"tslib";import{Box as p}from"@expofp/geometry";import{action as c,computed as f,observable as h,runInAction as m}from"mobx";import y from"../components/Map/drawing/config/config-load-layer";import{getFpSvgJs as b}from"../data/fp-payloads";import w from"../tools/settings";import{areLayersEnabled as v}from"../utils/areLayersEnabled";import{shortenName as g}from"../utils/shortenName";import a from".";const x=["money2020usa","rodion2","possible2025","2025virtuosotravelweek","zscalerskofy26","gamescom2025"];export var LayersMode;(function(s){s[s.Default=0]="Default",s[s.Separated=1]="Separated",s[s.Radio=2]="Radio",s[s.CheckBox=3]="CheckBox"})(LayersMode||(LayersMode={}));export var LayerMode;(function(s){s[s.Unset=0]="Unset",s[s.AlwaysVisible=1]="AlwaysVisible",s[s.AlwaysHidden=2]="AlwaysHidden",s[s.TurnedOn=3]="TurnedOn",s[s.TurnedOff=4]="TurnedOff"})(LayerMode||(LayerMode={}));export class Layer{constructor(){this.basePriority=0,this.name="",this.description="",this.frozen=!1,this.rect=null,this.viewbox=null,this.configured=!1,this.childLayers=[],this.rootParent=null,this.mode=LayerMode.Unset,this.children=[],this.loaded=!1,this.visible=!1}get shortName(){return g(this.description)}}n([h],Layer.prototype,"loaded",void 0),n([h],Layer.prototype,"visible",void 0);export default class l{constructor(){this.layers=[],this.mode=LayersMode.Default,this.layersLoaded=!1,this.updateVisibilityTimeout=0,this.selectFloorTimeout=0}get visible(){return this.layers.filter(r=>r.frozen||r.visible)}get loaded(){return this.layers.filter(r=>r.loaded)}get rectangle(){const r=this.visible.filter(e=>!e.frozen).map(e=>e.viewbox??e.rect).filter(e=>!!e);return this.mode!==LayersMode.Radio||!r.length?null:p.fromUnion(...r)||null}get bounds(){const r=this.visible.map(e=>e.viewbox??e.rect).filter(Boolean);return r.length?p.fromUnion(...r):void 0}get viewboxRectangle(){const r=this.visible.filter(e=>!e.frozen).map(e=>e.viewbox).filter(e=>!!e);return r.length&&p.fromUnion(...r)||null}get pathwayLayers(){return this.layers.filter(r=>r.pathway)}get floors(){if(!v())return[];const r=new Set(this.layers.filter(t=>t&&!t.frozen&&!t.rootParent&&!t.pathway).concat(a.routeStore.layers.filter(t=>t&&t.mode!==LayerMode.AlwaysHidden&&t.mode!==LayerMode.AlwaysVisible))),e=Array.from(r).reverse();return e.map((t,i)=>{const o=a.routeStore.layers.length>0&&a.routeStore.layers.indexOf(t)===-1,u=a.toursStore.tourLayers.length>0&&a.toursStore.tourLayers.indexOf(t)===-1;return{layer:t,name:t.name,shortName:t.shortName,description:t.description,active:t.visible,disabled:!!(o||u),index:t.floorIndex??e.length-i-1}})}selectFloor(r){if(this.selectFloorTimeout)return;this.selectFloorTimeout=window.setTimeout(()=>this.selectFloorTimeout=0,500);const e=this.layers.find(i=>i.description===r.description);if(!e)return;if(this.mode===LayersMode.Radio){if(this.updateVisibility(e,!0),a.maplibreStore.showMaplibre)return;if(!!b().__fpSettings?.fpVer||x.includes(w.EXPO)){const o=e.viewbox??e.rect;a.uiState.moveToRect=o}else{const o=this.layers.indexOf(this.layers.filter(d=>!d.frozen&&d.visible)[0]),u=this.layers.indexOf(e);if(o===u)return;a.uiState.zoomBy=u<o?.95:1.05}}else this.updateVisibility(e,!e.visible);const t=a.toursStore.getTourLayerInfo(e.name)||a.toursStore.getTourLayerInfo(e.description);if(t){this.showPathWay(t.id);return}a.toursStore.stopTour()}updateVisibility(r,e){if(this.mode===LayersMode.Radio&&!e)return;const t=r instanceof Layer?r:this.findLayer(r);if(!t||t.visible===e){t&&a.routeStore.currentRouteLayer!==t&&(a.routeStore.currentRouteLayer=t);return}y(t).then(()=>{this.mode===LayersMode.Radio&&this.layers.filter(i=>!i.pathway).forEach(i=>{i.name!==t.name&&!i.frozen&&i.visible&&(i.visible=!1,i.childLayers.forEach(o=>{o.visible=!1}))}),t&&(t.visible=e,t.childLayers.forEach(i=>{i.visible=e}),e&&(a.routeStore.currentRouteLayer=t),typeof a.fp.onFloorActivated=="function"&&(clearTimeout(this.updateVisibilityTimeout),this.updateVisibilityTimeout=window.setTimeout(()=>{const i=a.fp.getFloors();a.fp.onFloorActivated(i.find(o=>o.name===t.name))})))})}findLayer(r){if(r==null)return null;const e=this.layers.filter(o=>!o.rootParent);if(typeof r=="number"){const o=e.filter(u=>!u.frozen)[r];if(o)return o}const t=r.toString().toLowerCase(),i=e.find(o=>{const u=(o.name.match(/(-?[0-9]+)/)||"")[0];return t===o?.name.toLowerCase()||t===o?.description.toLowerCase()||t===o?.shortName.toLowerCase()||t===u});return i||(/\D/.test(t)?null:e.filter(o=>!o.frozen)[parseInt(t)]??null)}getPathwayList(){return this.layers.filter(r=>r.pathway)}async showPathWay(r){try{const e=this.findLayer(r);if(!e)throw new Error(`There is no pathway with this name. ${r}`);await y(e);const t=this.getPathwayList();m(()=>{t.forEach(i=>{const o=i.name===r;i.visible=o,i.childLayers.forEach(u=>{u.visible=o})})})}catch(e){console.error("showPathWay",e)}}hidePathways(){this.getPathwayList().forEach(e=>{e.visible=!1,e.childLayers.forEach(t=>{t.visible=!1})})}}n([h],l.prototype,"layers",void 0),n([h],l.prototype,"defaultLayer",void 0),n([h],l.prototype,"mode",void 0),n([h],l.prototype,"layersLoaded",void 0),n([f({keepAlive:!0})],l.prototype,"visible",null),n([f({keepAlive:!0})],l.prototype,"loaded",null),n([f({keepAlive:!0})],l.prototype,"rectangle",null),n([f({keepAlive:!0})],l.prototype,"bounds",null),n([f({keepAlive:!0})],l.prototype,"viewboxRectangle",null),n([f],l.prototype,"pathwayLayers",null),n([f],l.prototype,"floors",null),n([c],l.prototype,"selectFloor",null),n([c],l.prototype,"updateVisibility",null),n([c],l.prototype,"showPathWay",null),n([c],l.prototype,"hidePathways",null);