UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) • 2.69 kB
import{getConfig as R}from"@expofp/config";import{resolve as N}from"@expofp/resolve";import{BOOTHS_PAINTER_MARKER as _,SEPARATOR as s}from"../../../../constants";import{getFpPaths as M}from"../../../../data/fp-payloads";import{createImageDef as w,createLayerDef as h}from"../../../../engine/defs";import m,{boothStore as O,uiState as C}from"../../../../store";import v from"../../../../store/init/init-booths";import{getChildLayers as D}from"../../../../store/init/init-layers";import{LayersMode as T}from"../../../../store/LayerStore";import{chunkArray as F}from"../../../../utils";import{loadLayerImages as G}from"../../../../utils/loadLayerImages";import H,{BG_LAYER_NAME as y,FG_LAYER_NAME as b}from"./config-bg";import k,{BOOTHS_CHUNK_SIZE as x}from"./config-booths";import{configOutdoorPoiLayer as K}from"./config-outdoor-poi";import{registerLayerImages as Y}from"./layer-images";import{createModelDefFromElement as J}from"./layer-models";import{getImageLayerName as U,getLayerGraphics as Z,getModelLayerName as j}from"./loadBoothsImages";function q(e){return e.childLayers.length?e.childLayers:D(e,e.basePriority,15).layers}async function $(e,i){const r=[],n=v(m,e);if(K(e,n))return e.loaded=!0,e.configured=!0,e.children=[],h(e.name,[],{hidden:!0});const a=await H(e),c=[],E=F(n,x),d=O.booths.filter(o=>o.rect&&(!o.layer||o.layer===e||o.layer.childLayers.includes(e))&&o.exhibitors.find(t=>!!t.logoInBooth&&!!t.logo?.url)&&!C.hideLogoInBooth),S=new Map(d.map(o=>[o,o.noLabels]));d.forEach(o=>o.noLabels=!0),n.length&&E.forEach((o,t)=>{c.push(k(`${e.name}${s}${_}${s}${t}`,o))});for(const[o,t]of S)o.noLabels=t;e.loaded=!0;const l=a.children.find(o=>o.name===y),u=a.children.find(o=>o.name===b),g=U(e.name),{icons:f,models:A}=Z(e),p={name:g,children:[]},L={name:j(e.name),children:A.map(J)};f.length&&Y(g,async()=>{const o=await G(f),t=[];for(const{bounds:I,source:P}of o)t.push(w(P,I));return{layer:p,children:t}}),l&&r.push({...l,name:`${a.name}${s}${y}`}),c.length&&r.push(...c),u&&r.push({...u,name:`${a.name}${s}${b}`}),f.length&&r.push(p),L.children.length&&r.push(L);const B=await Promise.all(e.childLayers.sort((o,t)=>o.basePriority-t.basePriority).map(o=>$(o,!0)));return r.push(...B),e.children=r,e.configured=!0,h(e.name,r,{hidden:!i})}export default async function z(e){if(e.configured)return h(e.name,e.children,{hidden:!e.visible});if(m.layerStore.mode!==T.Default&&!M(e.name)&&!e.rootParent)try{const n=R().fpSvgLayerJsRefs[e.name];n&&await N(n)}catch(n){console.warn(`Layer data not loaded: ${e.name}`,n)}const i=q(e);i.length&&(e.childLayers=i);const{layers:r}=m.layerStore;return m.layerStore.layers=[...r,...i.filter(n=>!r.some(a=>a.name===n.name))],$(e,e.visible)}