@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 1.16 kB
JavaScript
import{createImageDef as w,getBounds as d}from"../../renderer";import{computeTrailPoints as g}from"../core";const D=40;export function createTrailManager(l,c){const s=new Map;function f(t){return`trail#${t}`}function u(t){if(!t.dotDefs.length)return;const e=l.touchLayer(t.layerName),n=new Set(t.dotDefs);e.children=e.children.filter(r=>!n.has(r)),t.dotDefs=[]}function i(t){const e=l.touchLayer(t.layerName),n=c.scale,r=D*n,a=g(t.from,t.to,r),o=t.canvas,h=a.map(m=>w(o,d(m.x,m.y,o.width,o.height,n)));u(t),e.children.push(...h),t.dotDefs=h}function y(t){const e=s.get(t);e&&(u(e),c.ptScaleRegistry.unregisterByName(f(t)),s.delete(t))}return{setTrail(t,e,n,r){if(e===null||n===null){y(t);return}if(!r)throw new Error(`renderer: setTrail("${t}") requires options when from/to are non-null`);const a=s.get(t);if(a){if(a.canvas!==r.canvas||a.layerName!==r.layer)throw new Error(`renderer: trail "${t}" cannot change canvas or layer after first call`);a.from=e,a.to=n,i(a);return}const o={from:e,to:n,canvas:r.canvas,layerName:r.layer,dotDefs:[]};s.set(t,o),c.onPtScale(f(t),()=>(i(o),l.touchLayer(o.layerName))),i(o)},destroy(){for(const t of[...s.keys()])y(t)}}}