@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 686 B
JavaScript
import p from"../../store";import{LayerMode as o}from"../../store/LayerStore";export function createMapViewport(e){return{canvasToPlan:n=>e.current.api.canvasToPlan(n),planToCanvas:n=>e.current.api.planToCanvas(n),isVisible:n=>e.current.api.isVisible(n)}}export function setMapViewport(e){i=e}export function mapViewport(){return i}let i;export function centerCoordinates(e){const n=mapViewport();if(!e||!n)throw new Error("Canvas not ready");const r=n.canvasToPlan({x:e.clientWidth/2,y:e.clientHeight/2});if(!r)throw new Error("The camera is not looking at the plan");const a=p.layerStore.visible.find(t=>t.mode===o.TurnedOff||t.mode===o.TurnedOn);return{x:r.x,y:r.y,z:a?.name||null}}