UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 856 B
import{useRef as m}from"react";import s from"../../store";import{useReaction as p}from"../../utils/mobx";import{fitMapToLocalRect as L}from"./utils/geo-config";import{collectLayerDefsByName as b}from"./utils/layer-defs";export function useLayerVisibilitySync(a,y,u){const t=m(null),f=m(null);p(()=>s.layerStore.layers.map(e=>`${e.name}:${e.visible?1:0}`),()=>{const e=a.scene;if(!e)return;t.current?.rootLayer!==e.rootLayer&&(t.current={rootLayer:e.rootLayer,defsByName:b(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&&a.update(...n);const r=s.layerStore.layers.find(o=>o.visible&&!o.frozen&&!o.rootParent&&!o.pathway);!r||f.current===r.name||(f.current=r.name,L(y.current,r.viewbox??r.rect,u))})}