UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 1.42 kB
import{makeHandle as e}from"../../../../core/handleUtils.js";import{isSome as t}from"../../../../core/maybe.js";import{Object3DState as i}from"../../webgl-engine/lib/basicInterfaces.js";import{Object3DStateID as h}from"../../webgl-engine/lib/Object3DStateID.js";class s{constructor(e){this._context=e,this._highlights=new Set}get hasHighlights(){return this._highlights.size>0}destroy(){this._highlights=null}add(t){const i=new o(t);return this._highlights.add(i),this._enableSet(i),e((()=>this._removeSet(i)))}_removeSet(e){this._disableSet(e),this._highlights.delete(e)}_enableSet(e){e.enabled||(e.enabled=!0,this._context.forEachNode((t=>this._enableSetForNode(e,t))))}_enableSetForNode(e,t){if(!e.enabled)return;const i=e.ids.get(t.id);i&&i.forEach((i=>this._context.addHighlight(t,i,e.id)))}_disableSet(e){e.enabled&&(e.enabled=!1,this._context.forEachNode((t=>this._disableSetForNode(e,t))))}_disableSetForNode(e,t){e.enabled||this._context.removeHighlight(t,e.id)}nodeAdded(e){this._highlights.forEach((t=>this._enableSetForNode(t,e)))}nodeRemoved(e){this._highlights.forEach((t=>this._disableSetForNode(t,e)))}removeAll(){this._highlights.forEach((e=>this._disableSet(e)))}}class o{constructor(e){this.id=new h(i.Highlight),this.ids=new Map,this.enabled=!1;for(const i of e)t(i)&&this._add(i.nodeId,i.pointId)}_add(e,t){const i=this.ids.get(e);i?i.add(t):this.ids.set(e,new Set([t]))}}export{s as PointHighlights};