UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 2.81 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{__decorate as t}from"tslib";import e from"../../core/Accessor.js";import i from"../../core/Collection.js";import{deprecatedModule as s}from"../../core/deprecate.js";import r from"../../core/Logger.js";import{watch as o,when as a,on as n}from"../../core/reactiveUtils.js";import{property as l,subclass as d}from"../../core/accessorSupport/decorators.js";import{getLyr3DWasm as c}from"../../views/3d/layers/Lyr3DWasm.js";function m(t,e){return t.length!==e.length||t.some((t,i)=>t.text!==e[i].text)}function h(t,e,i){if(!i||!e)return;t.find(t=>t.layerView===e&&t.text===i)||t.push({text:i,layerView:e})}const u=Symbol("attributions");let p=class extends e{constructor(t){super(t),this._clear=()=>{this.removeHandles(u)},this.items=new i,this.view=null,this._allLayerViewsChange=()=>{this.removeHandles(u);const t=this.view?.allLayerViews;let e=!1;if(t){for(const i of t)this.addHandles(o(()=>[i.attributionItems],()=>this._updateAttributionItems()),u),"type"in i&&"integrated-mesh-3dtiles"===i.type&&(e=!0,this.addHandles([o(()=>i.suspended,()=>this._updateAttributionItems()),i.on("visible-geometry-changed",()=>this._updateAttributionItems())],u));e&&this.addHandles(a(()=>!0===this.view?.stationary,()=>this._updateAttributionItems()),u)}this._updateAttributionItems()},s(r.getLogger("esri.widgets.Attribution.AttributionViewModel"),"This ViewModel is deprecated. Use attributionVisible and attributionItems on arcgis-map, arcgis-scene, arcgis-link-chart, and View instead.",{replacement:"attributionVisible and attributionItems on arcgis-map, arcgis-scene, arcgis-link-chart, and View",warnOnce:!0}),this.addHandles([n(()=>this.view?.allLayerViews,"change",this._allLayerViewsChange,{onListenerAdd:this._allLayerViewsChange,onListenerRemove:this._clear})])}destroy(){this.view=null,this.items.removeAll()}get state(){return this.view?.ready?this.view.allLayerViews.some(t=>t.attributionUpdating)?"loading":"ready":"disabled"}_updateAttributionItems(){const t=this.view,e=t?.allLayerViews,i=[];let s=!1,r=null,o=null;if(t&&e){for(const t of e){if(t.suspended)continue;"type"in t&&"integrated-mesh-3dtiles"===t.type&&(o||=t,t.layer.hasGoogleUrl&&(s=!0,r=t));const e=t.attributionItems.slice().sort((t,e)=>e.score-t.score).map(t=>t.text).join(", ");h(i,t,e)}if(o){const e=c(t);if(e){const t=e.getAttributionText();for(let e=t.length-1;e>-1;--e)i.unshift({text:t[e],layerView:o})}}s&&r&&i.unshift({text:"Google Maps",layerView:r}),m(this.items,i)&&(this.items.removeAll(),this.items.addMany(i))}else this._clear()}};t([l({readOnly:!0,type:i})],p.prototype,"items",void 0),t([l({readOnly:!0})],p.prototype,"state",null),t([l()],p.prototype,"view",void 0),p=t([d("esri.widgets.Attribution.AttributionViewModel")],p);const y=p;export{y as default};