UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 879 B
import{useRef as m}from"react";import s from"../../store";import{useReaction as L}from"../../utils/mobx";import{fitMapToLocalRect as b}from"./utils/geo-config";import{collectLayerDefsByName as h}from"./utils/layer-defs";export function useLayerVisibilitySync(f,u,y){const t=m(null),a=m(null);L(()=>s.layerStore.layers.map(e=>`${e.name}:${e.visible?1:0}`),()=>{const e=f.scene;if(!e)return;t.current?.rootLayer!==e.rootLayer&&(t.current={rootLayer:e.rootLayer,defsByName:h(e.rootLayer)});const d=t.current.defsByName,n=[];for(const o of s.layerStore.layers){const c=d.get(o.name);if(c?.length)for(const i of c){const l=!o.visible;i.hidden!==l&&(i.hidden=l,n.push(i))}}n.length&&f.update(...n);const r=s.layerStore.layers.find(o=>o.visible&&!o.frozen&&!o.rootParent&&!o.pathway);if(!r||a.current===r.name)return;a.current=r.name;const p=r.viewbox??r.rect;b(u.current,p??null,y)})}