UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 4.46 kB
import{_ as e}from"../../../chunks/tslib.es6.js";import i from"../../../Graphic.js";import s from"../../../core/Collection.js";import{isSome as t,isNone as r}from"../../../core/maybe.js";import{watch as a,on as h,initial as o}from"../../../core/reactiveUtils.js";import"../../../core/Logger.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import"../../../core/Error.js";import"../../../core/has.js";import{subclass as n}from"../../../core/accessorSupport/decorators/subclass.js";import{Container as p}from"../engine/Container.js";import{GroupContainer as c}from"../engine/webgl/GroupContainer.js";import{LayerView2DMixin as l}from"./LayerView2D.js";import g from"./graphics/GraphicContainer.js";import d from"./graphics/GraphicsView2D.js";import u from"../../layers/LayerView.js";const f="sublayers",m="layerView",w=Object.freeze({remove(){},pause(){},resume(){}});let y=class extends(l(u)){constructor(){super(...arguments),this._highlightIds=new Map,this.container=new c}async fetchPopupFeatures(e){return Array.from(this.graphicsViews(),(i=>i.hitTest(e).filter((e=>!!e.popupTemplate)))).flat()}*graphicsViews(){t(this._graphicsViewsFeatureCollectionMap)?yield*this._graphicsViewsFeatureCollectionMap.keys():t(this._graphicsViews)?yield*this._graphicsViews:yield*[]}async hitTest(e,i){return Array.from(this.graphicsViews(),(i=>{const s=i.hitTest(e);if(t(this._graphicsViewsFeatureCollectionMap)){const e=this._graphicsViewsFeatureCollectionMap.get(i);for(const i of s)!i.popupTemplate&&e.popupTemplate&&(i.popupTemplate=e.popupTemplate),i.sourceLayer=i.layer=this.layer}return s})).flat().map((i=>({type:"graphic",graphic:i,layer:this.layer,mapPoint:e})))}highlight(e){let r;"number"==typeof e?r=[e]:e instanceof i?r=[e.uid]:Array.isArray(e)&&e.length>0?r="number"==typeof e[0]?e:e.map((e=>e&&e.uid)):s.isCollection(e)&&(r=e.map((e=>e&&e.uid)).toArray());const a=r?.filter(t);return a?.length?(this._addHighlight(a),{remove:()=>{this._removeHighlight(a)}}):w}update(e){for(const i of this.graphicsViews())i.processUpdate(e)}attach(){const e=this.view,i=()=>this.requestUpdate(),s=this.layer.featureCollections;if(t(s)&&s.length){this._graphicsViewsFeatureCollectionMap=new Map;for(const t of s){const s=new g(this.view.featuresTilingScheme),r=new d({view:e,graphics:t.source,renderer:t.renderer,requestUpdateCallback:i,container:s});this._graphicsViewsFeatureCollectionMap.set(r,t),this.container.addChild(r.container),this.addHandles([a((()=>t.visible),(e=>r.container.visible=e),o),a((()=>r.updating),(()=>this.notifyChange("updating")),o)],m)}this._updateHighlight()}else t(this.layer.sublayers)&&this.addHandles(h((()=>this.layer.sublayers),"change",(()=>this._createGraphicsViews()),{onListenerAdd:()=>this._createGraphicsViews(),onListenerRemove:()=>this._destroyGraphicsViews()}),f)}detach(){this._destroyGraphicsViews(),this.removeHandles(f)}moveStart(){}moveEnd(){}viewChange(){for(const e of this.graphicsViews())e.viewChange()}isUpdating(){for(const e of this.graphicsViews())if(e.updating)return!0;return!1}_destroyGraphicsViews(){this.container.removeAllChildren(),this.removeHandles(m);for(const e of this.graphicsViews())e.destroy();this._graphicsViews=null,this._graphicsViewsFeatureCollectionMap=null}_createGraphicsViews(){if(this._destroyGraphicsViews(),r(this.layer.sublayers))return;const e=[],i=this.view,s=()=>this.requestUpdate();for(const t of this.layer.sublayers){const r=new p,h=new g(this.view.featuresTilingScheme);h.fadeTransitionEnabled=!0;const n=new d({view:i,graphics:t.graphics,requestUpdateCallback:s,container:h});this.addHandles([t.on("graphic-update",n.graphicUpdateHandler),a((()=>t.visible),(e=>n.container.visible=e),o),a((()=>n.updating),(()=>this.notifyChange("updating")),o)],m),r.addChild(n.container),this.container.addChild(r),e.push(n)}this._graphicsViews=e,this._updateHighlight()}_addHighlight(e){for(const i of e)if(this._highlightIds.has(i)){const e=this._highlightIds.get(i);this._highlightIds.set(i,e+1)}else this._highlightIds.set(i,1);this._updateHighlight()}_removeHighlight(e){for(const i of e)if(this._highlightIds.has(i)){const e=this._highlightIds.get(i)-1;0===e?this._highlightIds.delete(i):this._highlightIds.set(i,e)}this._updateHighlight()}_updateHighlight(){const e=Array.from(this._highlightIds.keys());for(const i of this.graphicsViews())i.setHighlight(e)}};y=e([n("esri.views.2d.layers.MapNotesLayerView2D")],y);const _=y;export{_ as default};