12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as e}from"../../chunks/tslib.es6.js";import"../../geometry.js";import t from"../../Graphic.js";import"../../symbols.js";import i from"../../core/Collection.js";import s from"../../core/Error.js";import r from"../../core/Handles.js";import o from"../../core/Logger.js";import{unwrap as n,isNone as a}from"../../core/maybe.js";import{watch as l,when as h,sync as u}from"../../core/reactiveUtils.js";import{property as c}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import{geographicToWebMercator as p}from"../../geometry/support/webMercatorUtils.js";import g from"../../layers/Layer.js";import{fallbackObjectIDAttribute as f}from"../../layers/LayerConstants.js";import m from"../../support/actions/ActionBase.js";import y from"../../support/actions/ActionButton.js";import w from"../../support/actions/ActionToggle.js";import{getDisplayedSymbol as F}from"../../symbols/support/symbolUtils.js";import{ViewEventPriorities as v}from"../../views/input/InputManager.js";import{highlightsSupported as _}from"../../views/support/layerViewUtils.js";import b from"../Feature/FeatureViewModel.js";import{zoomToFeature as C,zoomToClusteredFeatures as P,browseClusteredFeatures as E}from"./actions.js";import{triggerAction as V,isClusterFeature as A,getSelectedTarget as M,removeClusteredFeaturesForBrowsing as j,displayClusterExtent as L,browseAggregateFeatures as O}from"./actionUtils.js";import T from"../support/AnchorElementViewModel.js";import{GoToMixin as x}from"../support/GoTo.js";import I from"../../symbols/SimpleFillSymbol.js";import S from"../../geometry/Point.js";const B=i.ofType({key:"type",defaultKeyValue:"button",base:m,typeMap:{button:y,toggle:w}}),G=()=>[C.clone()],R=()=>[P.clone(),E.clone()];let z=class extends(x(T)){constructor(e){super(e),this._handles=new r,this._pendingPromises=new Set,this._fetchFeaturesController=null,this._selectedClusterFeature=null,this.featurePage=null,this.actions=new B,this.activeFeature=null,this.defaultPopupTemplateEnabled=!1,this.autoCloseEnabled=!1,this.autoOpenEnabled=!0,this.browseClusterEnabled=!1,this.content=null,this.featuresPerPage=20,this.featureViewModelAbilities=null,this.featureViewModels=[],this.highlightEnabled=!0,this.includeDefaultActions=!0,this.selectedClusterBoundaryFeature=new t({symbol:new I({outline:{width:1.5,color:"cyan"},style:"none"})}),this.title=null,this.updateLocationEnabled=!1,this.view=null,this.visible=!1,this.zoomFactor=4,this.zoomToLocation=null}get isLoadingFeature(){return this.featureViewModels.some((e=>e.waitingForContent))}initialize(){this._handles.add([l((()=>[this.autoOpenEnabled,this.view]),(()=>this._autoOpenEnabledChange())),this.on("view-change",(()=>this._autoClose())),l((()=>[this.highlightEnabled,this.selectedFeature,this.visible,this.view]),(()=>this._highlightSelectedFeature())),l((()=>[this.highlightEnabled,this.activeFeature,this.visible,this.view]),(()=>this._highlightActiveFeature())),l((()=>this.view?.animation?.state),(e=>this._animationStateChange(e))),l((()=>this.location),(e=>this._locationChange(e))),l((()=>this.selectedFeature),(e=>this._selectedFeatureChange(e))),l((()=>[this.selectedFeatureIndex,this.featureCount,this.featuresPerPage]),(()=>this._selectedFeatureIndexChange())),l((()=>[this.featurePage,this.selectedFeatureIndex,this.featureCount,this.featuresPerPage,this.featureViewModels]),(()=>this._setGraphicOnFeatureViewModels())),l((()=>this.featureViewModels),(()=>this._featureViewModelsChange())),this.on("trigger-action",(e=>V({event:e,view:this.view}))),h((()=>!this.waitingForResult),(()=>this._waitingForResultChange()),u),l((()=>[this.features,this.view?.map,this.view?.spatialReference]),(()=>this._updateFeatureVMs())),l((()=>this.view?.scale),(()=>this._viewScaleChange())),h((()=>!this.visible),(()=>this.browseClusterEnabled=!1)),l((()=>this.browseClusterEnabled),(e=>e?this.enableClusterBrowsing():this.disableClusterBrowsing()))])}destroy(){this._cancelFetchingFeatures(),this._handles.destroy(),this._handles=null,this._pendingPromises.clear(),this.browseClusterEnabled=!1,this.view=null}get active(){return!(!this.visible||this.waitingForResult)}get allActions(){const e=this._get("allActions")||new B;e.removeAll();const{actions:t,defaultActions:i,defaultPopupTemplateEnabled:s,includeDefaultActions:r,selectedFeature:o}=this,n=r?i.concat(t):t,a=o&&("function"==typeof o.getEffectivePopupTemplate&&o.getEffectivePopupTemplate(s)||o.popupTemplate),l=a&&a.actions,h=a&&a.overwriteActions?l:l?l.concat(n):n;return h&&h.filter(Boolean).forEach((t=>e.add(t))),e}get defaultActions(){const e=this._get("defaultActions")||new B;return e.removeAll(),e.addMany(A(this.selectedFeature)?R():G()),e}get featureCount(){return this.features.length}get features(){return this._get("features")||[]}set features(e){const t=e||[];this._set("features",t);const{pendingPromisesCount:i,promiseCount:s,selectedFeatureIndex:r}=this,o=s&&t.length;o&&i&&-1===r?this.selectedFeatureIndex=0:o&&-1!==r||(this.selectedFeatureIndex=t.length?0:-1)}get location(){return this._get("location")||null}set location(e){const t=this.get("view.spatialReference.isWebMercator");e&&e.get("spatialReference.isWGS84")&&t&&(e=p(e)),this._set("location",e)}get pendingPromisesCount(){return this._pendingPromises.size}get waitingForResult(){return!(!(!!this._fetchFeaturesController||this.pendingPromisesCount>0)||0!==this.featureCount)}get promiseCount(){return this.promises.length}get promises(){return this._get("promises")||[]}set promises(e){if(this._pendingPromises.clear(),this.features=[],!Array.isArray(e)||!e.length)return this._set("promises",[]),void this.notifyChange("pendingPromisesCount");this._set("promises",e),(e=e.slice(0)).forEach((e=>{this._pendingPromises.add(e);const t=t=>{this._pendingPromises.has(e)&&this._updateFeatures(t),this._updatePendingPromises(e)},i=()=>this._updatePendingPromises(e);e.then(t,i)})),this.notifyChange("pendingPromisesCount")}get selectedFeature(){const{features:e,selectedFeatureIndex:t}=this;if(-1===t)return null;return e[t]||null}get selectedFeatureIndex(){const e=this._get("selectedFeatureIndex");return"number"==typeof e?e:-1}set selectedFeatureIndex(e){const{featureCount:t}=this;e=isNaN(e)||e<-1||!t?-1:(e+t)%t,this.activeFeature=null,this._set("selectedFeatureIndex",e)}get selectedFeatureViewModel(){return this.featureViewModels[this.selectedFeatureIndex]||null}get state(){return this.get("view.ready")?"ready":"disabled"}centerAtLocation(){const{view:e}=this,t=M(this);return t?this.callGoTo({target:{target:t,scale:e.scale}}):Promise.reject(new s("center-at-location:invalid-target-or-view","Cannot center at a location without a target and view.",{target:t,view:e}))}zoomTo(e){return this.callGoTo(e)}clear(){this.set({promises:[],features:[],content:null,title:null,location:null,activeFeature:null})}fetchFeatures(e,t){const{view:i}=this;if(!i||!e)throw new s("fetch-features:invalid-screenpoint-or-view","Cannot fetch features without a screenPoint and view.",{screenPoint:e,view:i});return i.fetchPopupFeatures(e,{event:t&&t.event,defaultPopupTemplateEnabled:this.defaultPopupTemplateEnabled,signal:t&&t.signal})}open(e){const t={updateLocationEnabled:!1,promises:[],fetchFeatures:!1,...e,visible:!0},{fetchFeatures:i}=t;delete t.fetchFeatures,i&&this._setFetchFeaturesPromises(t.location);const s=["actionsMenuOpen","collapsed","featureMenuOpen"];for(const r of s)delete t[r];this.set(t)}triggerAction(e){const t=this.allActions.getItemAt(e);t&&!t.disabled&&this.emit("trigger-action",{action:t})}next(){return this.selectedFeatureIndex=this.selectedFeatureIndex+1,this}previous(){return this.selectedFeatureIndex=this.selectedFeatureIndex-1,this}disableClusterBrowsing(){j(this),this._clearBrowsedClusterGraphics()}async enableClusterBrowsing(){const{view:e,selectedFeature:t}=this;"2d"===e?.type?A(t)?(await L(this),await O(this)):o.getLogger(this.declaredClass).warn("enableClusterBrowsing:invalid-selectedFeature: Selected feature must represent an aggregate/cluster graphic.",t):o.getLogger(this.declaredClass).warn("enableClusterBrowsing:invalid-view: View must be 2d MapView.",t)}_animationStateChange(e){this.zoomToLocation||(C.disabled="waiting-for-target"===e)}_clearBrowsedClusterGraphics(){const e=this.view?.graphics;e&&(e.remove(this.selectedClusterBoundaryFeature),e.remove(this._selectedClusterFeature)),this._selectedClusterFeature=null,this.selectedClusterBoundaryFeature.geometry=null}_viewScaleChange(){if(A(this.selectedFeature))return this.browseClusterEnabled=!1,this.visible=!1,void this.clear();this.browseClusterEnabled&&(this.features=[this.selectedFeature])}_locationChange(e){const{selectedFeature:t,updateLocationEnabled:i}=this;i&&e&&(!t||t.geometry)&&this.centerAtLocation()}_selectedFeatureIndexChange(){this.featurePage=this.featureCount>1?Math.floor(this.selectedFeatureIndex/this.featuresPerPage)+1:null}_featureViewModelsChange(){this.featurePage=this.featureCount>1?1:null}_setGraphicOnFeatureViewModels(){const{features:e,featureCount:t,featurePage:i,featuresPerPage:s,featureViewModels:r}=this;if(null===i)return;const o=((i-1)*s+t)%t,n=o+s;r.slice(o,n).forEach(((t,i)=>{t&&!t.graphic&&(t.graphic=e[o+i])}))}async _selectedFeatureChange(e){if(!e)return;const{location:t,updateLocationEnabled:i,view:s}=this;if(this.browseClusterEnabled){if(this._selectedClusterFeature&&(s.graphics.remove(this._selectedClusterFeature),this._selectedClusterFeature=null),A(e))return;return e.symbol=await F(e),this._selectedClusterFeature=e,void s.graphics.add(this._selectedClusterFeature)}!i&&t||!e.geometry?i&&!e.geometry&&this.centerAtLocation().then((()=>{this.location=s.center.clone()})):this.location=n(this._getPointFromGeometry(e.geometry))}_waitingForResultChange(){!this.featureCount&&this.promises&&(this.visible=!1)}_setFetchFeaturesPromises(e){return this._fetchFeaturesWithController(this._getScreenPoint(e||this.location)).then((e=>{const{clientOnlyGraphics:t,promisesPerLayerView:i}=e,s=Promise.resolve(t),r=i.map((e=>e.promise));this.promises=[s,...r]}))}_destroyFeatureVMs(){this.featureViewModels.forEach((e=>e&&!e.destroyed&&e.destroy())),this._set("featureViewModels",[])}_updateFeatureVMs(){const{selectedFeature:e,features:t,featureViewModels:i}=this;if(A(e)||(this.browseClusterEnabled=!1),this._destroyFeatureVMs(),!t||!t.length)return;const s=i.slice(0),r=[];t.forEach(((t,i)=>{if(!t)return;let o=null;if(s.some(((e,i)=>(e&&e.graphic===t&&(o=e,s.splice(i,1)),!!o))),o)r[i]=o;else{const s=new b({abilities:this.featureViewModelAbilities,defaultPopupTemplateEnabled:this.defaultPopupTemplateEnabled,spatialReference:this.view?.spatialReference,graphic:t===e?t:null,map:this.view?.map,view:this.view});r[i]=s}})),s.forEach((e=>e&&!e.destroyed&&e.destroy())),this._set("featureViewModels",r)}_getScreenPoint(e){const{view:t}=this;return t&&e&&"function"==typeof t.toScreen?t.toScreen(e):null}_autoOpenEnabledChange(){const e="auto-fetch-features",{_handles:t,autoOpenEnabled:i}=this;if(t.remove(e),i&&this.view){const i=this.view.on("click",(e=>{"mouse"===e.pointerType&&0!==e.button||this._fetchFeaturesAndOpen(e)}),v.WIDGET);t.add(i,e)}}_cancelFetchingFeatures(){const e=this._fetchFeaturesController;e&&e.abort(),this._fetchFeaturesController=null,this.notifyChange("waitingForResult")}_fetchFeaturesWithController(e,t){this._cancelFetchingFeatures();const i=new AbortController,{signal:s}=i;this._fetchFeaturesController=i,this.notifyChange("waitingForResult");const r=this.fetchFeatures(e,{signal:s,event:t});return r.catch((()=>{})).then((()=>{this._fetchFeaturesController=null,this.notifyChange("waitingForResult")})),r}_fetchFeaturesAndOpen(e){const{screenPoint:t,mapPoint:i}=e,{view:s}=this;this._fetchFeaturesWithController(t,e).then((e=>{const{clientOnlyGraphics:t,promisesPerLayerView:r,location:o}=e,n=[Promise.resolve(t),...r.map((e=>e.promise))];return s.popup.open({location:o||i,promises:n}),e}))}_updatePendingPromises(e){e&&this._pendingPromises.has(e)&&(this._pendingPromises.delete(e),this.notifyChange("pendingPromisesCount"))}_autoClose(){this.autoCloseEnabled&&(this.visible=!1)}_getPointFromGeometry(e){return a(e)?null:"point"===e.type?e:"extent"===e.type?e.center:"polygon"===e.type?e.centroid:"multipoint"===e.type||"polyline"===e.type?e.extent?.center:null}async _getLayerView(e,t){return await e.when(),e.whenLayerView(t)}_getHighlightLayer(e){const{layer:t,sourceLayer:i}=e;return i&&"layer"in i&&i.layer?i.layer:"map-notes"===i?.type||"subtype-group"===i?.type?i:t}_getHighlightTarget(e,t){const i="imagery"===t.type?void 0:"objectIdField"in t?t.objectIdField||f:null,s=e.attributes;return s&&i&&s[i]||e}async _highlightActiveFeature(){const e="highlight-active-feature";this._handles.remove(e);const{highlightEnabled:t,view:i,activeFeature:s,visible:r}=this;if(!(s&&i&&t&&r))return;const o=this._getHighlightLayer(s);if(!(o&&o instanceof g))return;const n=this._getLayerView(i,o);this._highlightActiveFeaturePromise=n;const a=await n;if(!(a&&_(a)&&this._highlightActiveFeaturePromise===n&&this.activeFeature&&this.highlightEnabled))return;const l=a.highlight(this._getHighlightTarget(s,o));this._handles.add(l,e)}async _highlightSelectedFeature(){const e="highlight-selected-feature";this._handles.remove(e);const{selectedFeature:t,highlightEnabled:i,view:s,visible:r}=this;if(!(t&&s&&i&&r))return;const o=this._getHighlightLayer(t);if(!(o&&o instanceof g))return;const n=this._getLayerView(s,o);this._highlightSelectedFeaturePromise=n;const a=await n;if(!(a&&_(a)&&this._highlightSelectedFeaturePromise===n&&this.selectedFeature&&this.highlightEnabled&&this.visible))return;const l=a.highlight(this._getHighlightTarget(t,o));this._handles.add(l,e)}_updateFeatures(e){const{features:t}=this;if(!e||!e.length)return;if(!t.length)return void(this.features=e);const i=e.filter((e=>!t.includes(e)));this.features=t.concat(i)}};e([c()],z.prototype,"featurePage",void 0),e([c()],z.prototype,"isLoadingFeature",null),e([c({type:B})],z.prototype,"actions",void 0),e([c({readOnly:!0})],z.prototype,"active",null),e([c()],z.prototype,"activeFeature",void 0),e([c({readOnly:!0})],z.prototype,"allActions",null),e([c({type:Boolean})],z.prototype,"defaultPopupTemplateEnabled",void 0),e([c()],z.prototype,"autoCloseEnabled",void 0),e([c()],z.prototype,"autoOpenEnabled",void 0),e([c()],z.prototype,"browseClusterEnabled",void 0),e([c()],z.prototype,"content",void 0),e([c({type:B,readOnly:!0})],z.prototype,"defaultActions",null),e([c({readOnly:!0})],z.prototype,"featureCount",null),e([c()],z.prototype,"features",null),e([c()],z.prototype,"featuresPerPage",void 0),e([c()],z.prototype,"featureViewModelAbilities",void 0),e([c({readOnly:!0})],z.prototype,"featureViewModels",void 0),e([c()],z.prototype,"highlightEnabled",void 0),e([c()],z.prototype,"includeDefaultActions",void 0),e([c({type:S})],z.prototype,"location",null),e([c({readOnly:!0})],z.prototype,"pendingPromisesCount",null),e([c({readOnly:!0})],z.prototype,"selectedClusterBoundaryFeature",void 0),e([c({readOnly:!0})],z.prototype,"waitingForResult",null),e([c({readOnly:!0})],z.prototype,"promiseCount",null),e([c()],z.prototype,"promises",null),e([c({value:null,readOnly:!0})],z.prototype,"selectedFeature",null),e([c({value:-1})],z.prototype,"selectedFeatureIndex",null),e([c({readOnly:!0})],z.prototype,"selectedFeatureViewModel",null),e([c({readOnly:!0})],z.prototype,"state",null),e([c()],z.prototype,"title",void 0),e([c()],z.prototype,"updateLocationEnabled",void 0),e([c()],z.prototype,"view",void 0),e([c()],z.prototype,"visible",void 0),e([c()],z.prototype,"zoomFactor",void 0),e([c()],z.prototype,"zoomToLocation",void 0),e([c()],z.prototype,"centerAtLocation",null),z=e([d("esri.widgets.Popup.PopupViewModel")],z);const H=z;export{H as default};
|