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