UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 4.35 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as i}from"../../../chunks/tslib.es6.js";import e from"../../../Graphic.js";import{isSome as s}from"../../../core/arrayUtils.js";import t from"../../../core/Collection.js";import{makeHandle as r}from"../../../core/handleUtils.js";import{watch as h,initial as a,on as o}from"../../../core/reactiveUtils.js";import"../../../core/Logger.js";import"../../../core/has.js";import"../../../core/Error.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import{LayerView2DMixin as n}from"./LayerView2D.js";import c from"./graphics/GraphicContainer.js";import p from"./graphics/GraphicsView2D.js";import g from"../../layers/LayerView.js";const d="sublayers",u="layerView",f=new Set(["default"]);let m=class extends(n(g)){constructor(){super(...arguments),this._highlightIds=new Map}*graphicsViews(){null==this._graphicsViewsFeatureCollectionMap?null==this._graphicsViews?yield*[]:yield*this._graphicsViews:yield*this._graphicsViewsFeatureCollectionMap.keys()}async hitTest(i,e){return Array.from(this.graphicsViews(),(e=>{const s=e.hitTest(i);if(null!=this._graphicsViewsFeatureCollectionMap){const i=this._graphicsViewsFeatureCollectionMap.get(e);for(const e of s)!e.popupTemplate&&i.popupTemplate&&(e.popupTemplate=i.popupTemplate),e.sourceLayer=e.layer=this.layer}return s})).flat().map((e=>({type:"graphic",graphic:e,layer:this.layer,mapPoint:i})))}highlight(i,h="default"){let a;"number"==typeof i?a=[i]:i instanceof e?a=[i.uid]:Array.isArray(i)&&i.length>0?a="number"==typeof i[0]?i:i.map((i=>i&&i.uid)):t.isCollection(i)&&(a=i.map((i=>i&&i.uid)).toArray());const o=a?.filter(s);return o?.length?(this._addHighlight(o),r((()=>this._removeHighlight(o)))):r()}update(i){for(const e of this.graphicsViews())e.processUpdate(i)}attach(){const i=this.view,e=()=>this.requestUpdate(),s=this.layer.featureCollections;if(null!=s&&s.length){this._graphicsViewsFeatureCollectionMap=new Map;for(const t of s){const s=new c(this.view.featuresTilingScheme),r=new p({view:i,graphics:t.source,renderer:t.renderer,requestUpdateCallback:e,container:s});this._graphicsViewsFeatureCollectionMap.set(r,t),this.container.addChild(r.container),this.addHandles([h((()=>t.visible),(i=>r.container.visible=i),a),h((()=>r.updating),(()=>this.notifyChange("updating")),a)],u)}this._updateHighlight()}else null!=this.layer.sublayers&&this.addHandles(o((()=>this.layer.sublayers),"change",(()=>this._createGraphicsViews()),{onListenerAdd:()=>this._createGraphicsViews(),onListenerRemove:()=>this._destroyGraphicsViews()}),d)}detach(){this._destroyGraphicsViews(),this.removeHandles(d)}moveEnd(){}viewChange(){for(const i of this.graphicsViews())i.viewChange()}isUpdating(){for(const i of this.graphicsViews())if(i.updating)return!0;return!1}_destroyGraphicsViews(){this.container.removeAllChildren(),this.removeHandles(u);for(const i of this.graphicsViews())i.destroy();this._graphicsViews=null,this._graphicsViewsFeatureCollectionMap=null}_createGraphicsViews(){if(this._destroyGraphicsViews(),null==this.layer.sublayers)return;const i=[],e=this.view,s=()=>this.requestUpdate();for(const t of this.layer.sublayers){const r=new c(this.view.featuresTilingScheme);r.fadeTransitionEnabled=!0;const o=new p({view:e,graphics:t.graphics,requestUpdateCallback:s,container:r});this.addHandles([t.on("graphic-update",o.graphicUpdateHandler),h((()=>t.visible),(i=>o.container.visible=i),a),h((()=>o.updating),(()=>this.notifyChange("updating")),a)],u),this.container.addChild(o.container),i.push(o)}this._graphicsViews=i,this._updateHighlight()}_addHighlight(i){for(const e of i)if(this._highlightIds.has(e)){const i=this._highlightIds.get(e);this._highlightIds.set(e,i+1)}else this._highlightIds.set(e,1);this._updateHighlight()}_removeHighlight(i){for(const e of i)if(this._highlightIds.has(e)){const i=this._highlightIds.get(e)-1;0===i?this._highlightIds.delete(e):this._highlightIds.set(e,i)}this._updateHighlight()}_updateHighlight(){const i=Array.from(this._highlightIds.keys()),e=this._getHighlightBits(f.values());for(const s of this.graphicsViews())s.setHighlight(i.map((i=>({objectId:i,highlightFlags:e}))))}};m=i([l("esri.views.2d.layers.MapNotesLayerView2D")],m);const w=m;export{w as default};