UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.56 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 t from"../../core/Accessor.js";import e from"../../core/Collection.js";import{watch as r,initial as s}from"../../core/reactiveUtils.js";import{property as o}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as l}from"../../core/accessorSupport/decorators/subclass.js";import n from"../../views/layers/support/ClipRect.js";function a(i,t){const e=10**t;return Math.round(i*e)/e}const p={left:0,right:0,top:0,bottom:0};let c=class extends t{constructor(i){super(i),this._leadingClips=new Map,this._trailingClips=new Map,this.direction="horizontal",this.leadingLayers=new e,this.max=100,this.min=0,this.precision=4,this.step=.5,this.stepMultiplier=10,this.trailingLayers=new e,this.view=null}initialize(){this.addHandles([r((()=>[this.view,this.view?.ready,this.position,this.direction]),(()=>this._clipLayers()),s),r((()=>this.leadingLayers.toArray()),(()=>this._clipLeadingLayers()),s),r((()=>this.trailingLayers.toArray()),(()=>this._clipTrailingLayers()),s)])}destroy(){this._removeExistingClips()}get position(){return 25}set position(i){const{precision:t,min:e,max:r}=this;this._set("position",a(Math.max(Math.min(i,r),e),t))}get state(){return this.view?.ready?"ready":"disabled"}_clipLayers(){this._clipLeadingLayers(),this._clipTrailingLayers()}_clipLeadingLayers(){this._removeClips("leading");const{leadingLayers:i}=this;i.forEach((i=>this._clipLayer({layer:i,type:"leading"})))}_clipTrailingLayers(){this._removeClips("trailing");const{trailingLayers:i}=this;i.forEach((i=>this._clipLayer({layer:i,type:"trailing"})))}async _getLayerView(i){const{view:t}=this;if(!i||!t)return null;const e=await t.whenLayerView(i);return"clips"in e?e:null}_getVerticalClipRect(i){const{position:t}=this;return"leading"===i?new n({...p,bottom:100-t+"%"}):"trailing"===i?new n({...p,top:`${t}%`}):null}_getHorizontalClipRect(i){const{position:t}=this;return"leading"===i?new n({...p,right:100-t+"%"}):"trailing"===i?new n({...p,left:`${t}%`}):null}_getClipRect(i){const{direction:t}=this;return"vertical"===t?this._getVerticalClipRect(i):"horizontal"===t?this._getHorizontalClipRect(i):null}async _clipLayer(i){const{_leadingClips:t,_trailingClips:e}=this,{layer:r,type:s}=i,o="trailing"===s?e:"leading"===s?t:null,l=await this._getLayerView(r);if(!(l&&"clips"in l&&o&&l.hasOwnProperty("clips")))return;const n=o.get(l);n&&l.clips.remove(n);const a=this._getClipRect(s);a&&(o.set(l,a),l.clips.add(a))}_removeClips(i){const{_leadingClips:t,_trailingClips:e}=this,r="trailing"===i?e:"leading"===i?t:null;r&&(r.forEach(((i,t)=>{t&&t.hasOwnProperty("clips")&&t.clips.remove(i)})),r.clear())}_removeExistingClips(){this._removeClips("leading"),this._removeClips("trailing")}};i([o()],c.prototype,"direction",void 0),i([o({type:e,nonNullable:!0})],c.prototype,"leadingLayers",void 0),i([o({readOnly:!0})],c.prototype,"max",void 0),i([o({readOnly:!0})],c.prototype,"min",void 0),i([o()],c.prototype,"position",null),i([o()],c.prototype,"precision",void 0),i([o({readOnly:!0})],c.prototype,"state",null),i([o()],c.prototype,"step",void 0),i([o()],c.prototype,"stepMultiplier",void 0),i([o({type:e,nonNullable:!0})],c.prototype,"trailingLayers",void 0),i([o()],c.prototype,"view",void 0),c=i([l("esri.widgets.Swipe.SwipeViewModel")],c);const h=c;export{h as default};