MapView.js 26 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../chunks/tslib.es6.js";import t from"../Graphic.js";import i from"../Viewpoint.js";import s from"../core/Collection.js";import r from"../core/CollectionFlattener.js";import n from"../core/Error.js";import has from"../core/has.js";import{isIterable as a}from"../core/iteratorUtils.js";import o from"../core/Logger.js";import{isSome as l,unwrap as p,isNone as h}from"../core/maybe.js";import{throwIfAborted as c}from"../core/promiseUtils.js";import{watch as d,whenOnce as u,sync as g,syncAndInitial as m}from"../core/reactiveUtils.js";import{createScreenPoint as y}from"../core/screenUtils.js";import w from"../core/Warning.js";import{initialize as f}from"../core/workers/workers.js";import{property as _}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/accessorSupport/ensureType.js";import{subclass as v}from"../core/accessorSupport/decorators/subclass.js";import V from"../geometry/Extent.js";import S from"../geometry/Point.js";import{load as j,canProjectWithoutEngine as T,project as b,isLoaded as M}from"../geometry/projection.js";import{equals as R}from"../geometry/support/spatialReferenceUtils.js";import x from"../layers/support/TileInfo.js";import{BreakpointsOwner as L}from"./BreakpointsOwner.js";import{DOMContainer as O}from"./DOMContainer.js";import{PopupView as k}from"./PopupView.js";import C from"./View.js";import z from"./ViewAnimation.js";import P from"./2d/AnimationManager.js";import E from"./2d/FrameTask.js";import{layerView2DImporter as G}from"./2d/layerViewModuleImportUtils.js";import N from"./2d/MapViewConstraints.js";import q from"./2d/PaddedViewState.js";import"./2d/tiling/PagedTileQueue.js";import D from"./2d/tiling/TileInfoView.js";import"./2d/tiling/TileKey.js";import"./2d/tiling/TileQueue.js";import"./2d/tiling/TileStrategy.js";import{centerAt as U,setExtent as A,rotateTo as F,scaleTo as I,copy as W,create as $,extentToScale as B,resize as H,angleBetween as J}from"./2d/viewpointUtils.js";import Q from"./2d/input/MapViewInputManager.js";import Z from"./2d/layers/features/support/TileStore.js";import K from"./2d/support/HighlightOptions.js";import{Timeline as Y}from"./2d/support/Timeline.js";import X from"./support/createScreenshotPlan.js";import{encode as ee,encodeData as te,getMaximumResolutionScale as ie,getFormatAndQuality as se}from"./support/screenshotUtils.js";import{isSupportedScreenPointEvent as re,createScreenPointFromSupportedEvent as ne}from"./support/screenUtils.js";import{check as ae}from"./support/WebGLRequirements.js";import oe from"./ui/2d/DefaultUI2D.js";import le from"../webmap/background/ColorBackground.js";let pe,he,ce,de,ue,ge;async function me(){const[,{GraphicsView2D:e,GraphicContainer:t,LabelManager:i,MapViewNavigation:s,MagnifierView2D:r,Stage:n}]=await Promise.all([import("./2d/webglDeps.js"),import("./2d/mapViewDeps.js")]);he=e,ce=t,de=i,ue=s,ge=r,pe=n}const ye=160;function we(e){return e&&"esri.Viewpoint"===e.declaredClass}let fe=class extends(L(O(k(C)))){constructor(e){super(e),this._magnifierView=null,this._stage=null,this._resolveWhenReady=[],this.rootLayerViews=new r({getCollections:()=>[this.basemapView?.baseLayerViews,this.layerViews,this.basemapView?.referenceLayerViews],getChildrenFunction:()=>null}),this.featuresTilingScheme=null,this.fullOpacity=1,this.graphicsView=null,this.labelManager=null,this.mapViewNavigation=null,this.renderingOptions={samplingMode:"dynamic",edgeLabelsVisible:!0,labelsAnimationTime:125,labelCollisionsEnabled:!0},this.rendering=!1,this.supersampleScreenshotsEnabled=!1,this.supportsGround=!1,this._stationaryTimer=null,this.frameTask=new E(this),this._pePromise=null,this.floors=new s,this.highlightOptions=new K,this.inputManager=new Q({view:this}),this.map=null,this.resizeAlign="center",this.spatialReferenceLocked=!1,this.timeline=new Y,this.type="2d",this.ui=new oe,this._pixelFormat={flipY:!0,premultipliedAlpha:!0},this.constraints=new N,this.padding={top:0,right:0,bottom:0,left:0},this.handles.add([d((()=>this.viewpoint),(()=>{this._lastStationaryEventTimestamp=performance.now(),this._flipStationary(ye)}),g),this.on("resize",(e=>this._resizeHandler(e))),d((()=>this.animationManager?.animation),(e=>{this.animation=e}))]),f()}destroy(){this._set("preconditionsReady",!1),this._gotoTask=this.frameTask=null,this.rootLayerViews.destroy(),this.inputManager.destroy(),this._set("inputManager",null)}get graphicsTileStore(){return new Z(this.featuresTilingScheme)}get initialExtentRequired(){const{scale:e,constraints:t,center:i,viewpoint:s,extent:r}=this;let n=this.zoom;return!(this.map&&"initialViewProperties"in this.map&&this.map.initialViewProperties?.viewpoint)&&(!r&&(t?.effectiveLODs||(n=-1),(!i||0===e&&-1===n)&&(!s||!l(s.targetGeometry)||"extent"!==s.targetGeometry.type&&!s.scale)))}get resourceManager(){return this._stage.resourceManager}get textureManager(){return this._stage.painter.textureManager}get _defaultsFromMapSettings(){return{required:{tileInfo:!0,heightModelInfo:!1,extent:!1},requiresExtentInSpatialReference:this.spatialReferenceLocked}}get _projectionEngineLoaded(){return!!M()||(this._pePromise||(this._pePromise=j().finally((()=>{this._pePromise=null}))),!1)}get typeSpecificPreconditionsReady(){const e=this._getDefaultViewpoint();if(!e)return!1;const t=this.spatialReference,i=p(e.targetGeometry);return!!T(i.spatialReference,t)||this._projectionEngineLoaded}set animation(e){const t=this._get("animation");if(e===t)return;if(t&&t.stop(),!e||e.isFulfilled())return void this._set("animation",null);this._set("animation",e),this.frameTask.animationInProgress=!0;const i=()=>{e===this._get("animation")&&(this._set("animation",null),this.frameTask?.requestFrame()),this.frameTask&&(this.frameTask.animationInProgress=!1)};e.when(i,i)}get background(){return je(this.map)?this.map.initialViewProperties.background:null}set background(e){this._override("background",e)}get center(){if(!this.ready)return this._get("center");const{center:e,spatialReference:t}=this.state.paddedViewState;return new S({x:e[0],y:e[1],spatialReference:t})}set center(e){if(null==e)return;if(!this.ready)return this._set("center",e),void this.notifyChange("initialExtentRequired");let t;try{t=this._project(e,this.spatialReference)}catch(s){return void o.getLogger(this.declaredClass).error(new n("mapview:invalid-center","could not project the value in the view's spatial reference",{input:e,error:s}))}const i=this.viewpoint;U(i,i,t),this.viewpoint=i}set constraints(e){const t=this._get("constraints");t&&(this.handles.remove("map-view-constraints"),t.destroy()),this._set("constraints",e),e&&(e.view=this,this.ready&&(this.state.viewpoint=e.fit(this.state.paddedViewState.viewpoint)),this.handles.add(d((()=>e.version),(()=>{this.ready&&this.state&&(this.state.viewpoint=e.fit(this.state.paddedViewState.viewpoint))}),g),"map-view-constraints"))}get extent(){return this.ready?this.state.paddedViewState.extent.clone():this._get("extent")}set extent(e){if(null==e)return;if(!e.width||!e.height)return void o.getLogger(this.declaredClass).error(new n("mapview:invalid-extent","invalid extent size"));if(!this.ready)return this._set("extent",e),this._set("center",null),this._set("viewpoint",null),this._set("scale",0),this._set("zoom",-1),void this.notifyChange("initialExtentRequired");let t;try{t=this._project(e,this.spatialReference)}catch(s){return void o.getLogger(this.declaredClass).error(new n("mapview:invalid-extent","could not project the value in the view's spatial reference",{error:s}))}const i=this.viewpoint;A(i,i,t,this.size,{constraints:this.constraints}),this.viewpoint=i}get padding(){return this.ready?this.state.padding:this._get("padding")}set padding(e){this.ready?(this.state.padding=e,this._set("padding",this.state.padding)):this._set("padding",e)}get resolution(){return this.state?this.state.resolution:0}get rotation(){return this.ready?this.state.rotation:this._get("rotation")}set rotation(e){if(isNaN(e))return;if(!this.ready)return void this._set("rotation",e);const t=this.viewpoint;F(t,t,e),this.viewpoint=t}get scale(){return this.ready?this.state.scale:this._get("scale")}set scale(e){if(!e||isNaN(e))return;if(!this.ready){this._set("scale",e),this._set("zoom",-1);const t=this._get("extent");return t&&(this._set("extent",null),this._set("center",t.center)),void this.notifyChange("initialExtentRequired")}const t=this.viewpoint;I(t,t,e),this.viewpoint=t}get stationary(){return!(this.animation||this.navigating||this.resizing||this._stationaryTimer)}get updating(){const e=!this.destroyed&&(!this.layerViewManager||!this.labelManager||!this.graphicsView||!0===this.layerViewManager.updating||!0===this.labelManager.updating||!0===this.graphicsView.updating||this.allLayerViews.some((e=>!e.destroyed&&!("layerViews"in e)&&!0===e.updating)));if(has("esri-2d-log-updating")){const t=this.allLayerViews.reduce(((e,t)=>({...e,[t.layer.id]:!t.destroyed&&!("layerViews"in t)&&t.updating})),{});console.log(`Updating MapView: ${e}\n-> Null LayerViewManager: ${!this.layerViewManager}\n-> Null LabelManager: ${!this.labelManager}\n-> Null GraphicsView: ${!this.graphicsView}\n-> layerViewManager.updating: ${this.layerViewManager?.updating}\n-> labelManager.updating: ${this.labelManager?.updating}\n-> graphicsView.updating: ${this.graphicsView?.updating}\n-> allLayerViews: ${JSON.stringify(t)}\n`)}return e}get viewpoint(){if(!this.ready)return this._get("viewpoint");const e=this.state.paddedViewState;return e&&e.viewpoint.clone()}set viewpoint(e){if(null==e)return;if(!this.ready)return this._set("viewpoint",e),this._set("extent",null),this._set("center",null),this._set("zoom",-1),this._set("scale",0),void this.notifyChange("initialExtentRequired");let t,s;try{t=this._project(e,this.spatialReference),!e.scale||isNaN(e.scale)?s=new n("mapview:invalid-viewpoint",`invalid scale value of ${e.scale}`):h(e.targetGeometry)&&(s=new n("mapview:invalid-viewpoint","geometry not defined"))}catch(a){s=new n("mapview:invalid-viewpoint","could not project the value in the view's spatial reference",{error:a})}if(s)return void o.getLogger(this.declaredClass).error(s);this._scaleBeforeChangingSpatialReference=null;const r=new i({targetGeometry:new S,scale:0,rotation:0});W(r,t),this.constraints.constrain(r,this.state.paddedViewState.viewpoint),this.state.viewpoint=r,this.frameTask.requestFrame(),this._set("viewpoint",r)}get zoom(){return this.ready?this.constraints.scaleToZoom(this.scale):this._get("zoom")}set zoom(e){if(null==e)return;if(!this.ready){this._set("zoom",e),this._set("scale",0);const t=this._get("extent");return t&&(this._set("extent",null),this._set("center",t.center)),void this.notifyChange("initialExtentRequired")}if(!this.constraints.effectiveLODs)return void this._set("zoom",-1);const t=this.viewpoint;I(t,t,this.constraints.zoomToScale(e)),this.viewpoint=t,this._set("zoom",this.constraints.scaleToZoom(this.scale))}get navigating(){return!(!this.mapViewNavigation||!this.mapViewNavigation.interacting)}goTo(e,t){if(e)return this.animation&&(this.animation=null),this._createAnimation(),u((()=>this.ready),t).then((()=>{const i={animate:!0,...t},s=$(e,this);return this.animation.update(s),this._gotoTask={},i.animate?this._gotoAnimated(s,i):this._gotoImmediate(s,i)}));o.getLogger(this.declaredClass).error("#goTo()","target cannot be null or undefined")}async hitTest(e,t){const i=re(e)?ne(this,e):e;if(!this.ready||isNaN(i.x)||isNaN(i.y))return{screenPoint:i,results:[]};let s=new Set,r=!1,n=null,a=null;t?.include?Se(t.include,Ve(this,(e=>s.add(e)),(e=>{n||(n=new Set),n.add(e)}),(e=>s.add(e)),(()=>r=!0))):(r=!0,s=new Set(this.allLayerViews)),t?.exclude&&Se(t.exclude,Ve(this,(e=>s.delete(e)),(e=>{a||(a=new Set),a.add(e)})));const o=this.allLayerViews.filter((e=>!e.suspended&&s.has(e))).reverse(),p=this.toMap(i);let h=[...r?this.graphicsView.hitTest(p).map((e=>({type:"graphic",graphic:e,layer:null,mapPoint:p}))):[],...await Promise.all(o.map((e=>e.hitTest(p,i))).toArray())].filter(l).flat().filter(l);return n&&(h=h.filter((e=>!("graphic"in e)||!e.graphic||n.has(ve(e.graphic))))),a&&(h=h.filter((e=>!("graphic"in e)||!e.graphic||a.has(ve(e.graphic))))),{screenPoint:i,results:h}}async takeScreenshot(e){const t=this._createScreenshotPlan(e),i=await this._stage.takeScreenshot(t);return ee(i,{format:t.format,quality:t.quality,rotation:0,disableDecorations:!1},this._pixelFormat)}async _takeScreenshot(e){const t=this._createScreenshotPlan(e),i=await this._stage.takeScreenshot(t);return te(i,this._pixelFormat)}_createScreenshotPlan(e){e=e||{};const t=this.supersampleScreenshotsEnabled?Math.min(4,ie(this.size,Math.min(4096,this._stage.context.parameters.maxTextureSize))):1;let i;e.layers?(i=[],e.layers.forEach((e=>{const t=this.allLayerViews.find((t=>t.layer.id===e.id));t&&"container"in t&&t.container&&i.push(t.container)}))):i=this._stage.children;const{format:s,quality:r}=se(e.format,e.quality);return X(e,t,this.size,this.padding,s,r,i,e.rotation)}get test(){return{takeScreenshot:e=>this._takeScreenshot(e)}}toMap(e){if(!this.ready)return null;const t=re(e)?ne(this,e):e,i=[0,0],[s,r]=this.state.toMap(i,[t.x,t.y]),n=this.spatialReference;return new S({x:s,y:r,spatialReference:n})}toScreen(e){if(!this.ready)return null;const t=this._project(e,this.spatialReference),i=[t.x,t.y];return this.state.toScreen(i,i),y(i[0],i[1])}on(e,t,i,s){const r=this.inputManager&&this.viewEvents.on(e,t,i,s);return r||super.on(e,t)}hasEventListener(e){return super.hasEventListener(e)||this.viewEvents.hasHandler(e)}whenLayerView(e){return super.whenLayerView(e)}graphicChanged(e){if(this.graphicsView){this.graphicsView.graphicUpdateHandler(e)}}whenReady(){return new Promise((e=>{this.ready?e(this):this._resolveWhenReady.push(e)}))}forceDOMReadyCycle(){this.forceReadyCycle()}getDefaultSpatialReference(){return this.map&&"initialViewProperties"in this.map&&this.map?.initialViewProperties?.spatialReference||this.defaultsFromMap?.spatialReference||null}hasLayerViewModule(e){return G.hasLayerViewModule(e)}importLayerView(e){return G.importLayerView(e)}pixelSizeAt(){return this.ready?this.state.resolution:(o.getLogger(this.declaredClass).error("#pixelSizeAt()","Map view cannot be used before it is ready"),null)}popupHitTest(e){return this.hitTest(e).then((t=>({...t,mapPoint:this.toMap(e)})))}requestUpdate(){this.ready&&this.frameTask.requestUpdate()}validate(){let e=ae(this.type);return has("safari")&&has("safari")<9&&(e=new n("mapview:browser-not-supported","This browser is not supported by MapView (Safari < 9)",{type:"safari",requiredVersion:9,detectedVersion:has("safari")})),l(e)?(o.getLogger(this.declaredClass).warn("#validate()",e.message),Promise.reject(e)):me()}_createAnimation(){return this.animation&&!this.animation.done||(this.animation=new z),this.animation}_cancellableGoTo(e,t,i){const s=()=>e===this._gotoTask,r=i.then((()=>{s()&&(this.animation=null)})).catch((e=>{throw s()&&(this.animation=null,t.done||(t.stop(),this.frameTask.animationInProgress=!1)),e})),n=new Promise((e=>e(r)));return t.when().catch((()=>{s()&&n.cancel&&n.cancel()})),n}_gotoImmediate(e,t){const i=this._gotoTask,s=this.animation,r=e.then((e=>{if(c(t),i!==this._gotoTask)throw new n("view:goto-interrupted","Goto was interrupted");this.viewpoint=s.target=e,s.finish()}));return this._cancellableGoTo(i,s,r)}_flipStationary(e){return null!==this._stationaryTimer||(this._stationaryTimer=setTimeout((()=>{this._stationaryTimer=null;const e=performance.now()-this._lastStationaryEventTimestamp;e<ye&&(this._stationaryTimer=this._flipStationary(e))}),e)),this._stationaryTimer}_getDefaultViewpoint(){const{constraints:e,initialExtent:t,map:s,padding:r,size:n}=this;if(!e)return null;const a=s&&"initialViewProperties"in s&&s.initialViewProperties,o={zoom:this._get("zoom"),scale:this._get("scale"),center:this._get("center"),extent:this._get("extent"),rotation:this._get("rotation"),viewpoint:this._get("viewpoint"),spatialReference:this._userSpatialReference};e.effectiveLODs?-1!==o.zoom&&(o.scale=e.zoomToScale(o.zoom)):o.zoom=-1;let h=null,c=null,d=0;const u=o.viewpoint&&o.viewpoint.rotation,g=o.viewpoint&&o.viewpoint.targetGeometry;l(g)&&("extent"===g.type?h=g:"point"===g.type&&(c=g,d=o.viewpoint.scale));const m=o.extent||h||p(a?.viewpoint?.targetGeometry)?.extent||t,y=o.center||c||m?.center,w=o.scale||d||a?.viewpoint?.scale||m&&B(m,[n[0]-r.left-r.right,n[1]-r.top-r.bottom]),f=o.rotation||u||a?.viewpoint?.rotation||0;return y&&w?new i({targetGeometry:y,scale:w,rotation:f}):null}_gotoAnimated(e,t){const i=this._gotoTask,s=this.animation,r=e.then((e=>{if(c(t),i!==this._gotoTask)throw new n("view:goto-interrupted","Goto was interrupted");return s.update(e),this.animationManager.animate(s,this.viewpoint,t),s.when().then((()=>{}),(()=>{}))}));return this._cancellableGoTo(i,s,r)}_project(e,t){const i=e&&e.targetGeometry||e;if(!t)return e;if(!i)return null;if(t.imageCoordinateSystem||i.spatialReference?.imageCoordinateSystem)return e;if(R(t,i.spatialReference))return e;const s=b(i,t);if(!s)throw new n("mapview:projection-not-possible","projecting input geometry to target spatial reference returned a null value",{geometry:i,spatialReference:t});return we(e)?(e.targetGeometry=s,e):s}_resizeHandler(e){if(!this.ready)return;const t=this.state;let i=this.state.paddedViewState.viewpoint;const s=this.state.paddedViewState.size.concat();t.size=[e.width,e.height],H(i,i,s,this.state.paddedViewState.size,this.resizeAlign),i=this.constraints.constrain(i,null),this.state.viewpoint=i}_startup(){this.timeline.begin("MapView Startup");const e=this._getDefaultViewpoint(),t=e.targetGeometry;try{this._project(e,this.spatialReference)}catch(l){o.getLogger(this.declaredClass).warn(new w("mapview:startup-projection-error","projection of initial viewpoint to the view's spatial reference, defaulting to the initial viewpoint.",{center:t.toJSON(),spatialReference:this.spatialReference,error:l})),e.targetGeometry=this.defaultsFromMap.extent?.center||new S({x:0,y:0,spatialReference:this.spatialReference})}this.constraints?.fit(e),this._set("state",new q({padding:this._get("padding"),size:this.size,viewpoint:e})),this.graphics.owner=this;const i=new pe(this.surface,{canvas:this.renderCanvas,supersampleScreenshots:this.supersampleScreenshotsEnabled,contextOptions:{disabledExtensions:this.deactivatedWebGLExtensions,debugWebGLExtensions:this.debugWebGLExtensions},renderingOptions:this.renderingOptions,timeline:this.timeline});this._stage=i,this._magnifierView=new ge,this._magnifierView.magnifier=this.magnifier;const s=new de({view:this});this._set("labelManager",s);const r=new P({view:this});this._set("animationManager",r);const n=new ue({view:this,animationManager:r});this._set("mapViewNavigation",n),this._setupSpatialReferenceDependentProperties(),this.handles.add([this.rootLayerViews.on("change",(()=>this._updateStageChildren())),i.on("post-render",(()=>this._set("rendering",i.renderRequested))),i.on("will-render",(()=>this._set("rendering",i.renderRequested))),i.on("webgl-error",(e=>this.fatalError=e.error)),d((()=>this.stationary),(e=>i.stationary=e),m),d((()=>this.background),(e=>{i.background=e,this._magnifierView.background=e}),m),d((()=>this.magnifier),(e=>this._magnifierView.magnifier=e),m),d((()=>this.renderingOptions),(e=>i.renderingOptions=e),m),d((()=>this.highlightOptions),(e=>i.highlightOptions=e),m),d((()=>this.state.id),(()=>i.state=this.state),m)],"map-view"),this._updateStageChildren();const a=this._resolveWhenReady;this._resolveWhenReady=[],a.forEach((e=>e(this))),this.timeline.end("MapView Startup"),this.frameTask&&this.frameTask.start(),this._set("ready",!0)}_teardown(){this._destroySpatialReferenceDependentProperties(),this.handles.remove("map-view"),this.mapViewNavigation.destroy(),this._set("mapViewNavigation",null),this.animationManager.destroy(),this._set("animationManager",null),this.layerViewManager.clear(),this.labelManager.destroy(),this._magnifierView.destroy(),this._stage.destroy(),this._stage=null,this._set("graphicsView",null),this._magnifierView=null,this._set("labelManager",null),this._set("mapViewNavigation",null),this.graphics.owner=null,this.frameTask&&this.frameTask.stop(),this._stationaryTimer&&(clearTimeout(this._stationaryTimer),this._stationaryTimer=null),this._set("ready",!1);const{center:[e,t],spatialReference:i,rotation:s,scale:r}=this.state.paddedViewState,n=new S({x:e,y:t,spatialReference:i});this._set("viewpoint",null),this._set("extent",null),this._set("center",n),this._set("zoom",-1),this._set("rotation",s),this._set("scale",r),this._set("spatialReference",i),this._set("state",null),this.animation=null}_updateStageChildren(){this._stage.removeAllChildren(),this.rootLayerViews.forEach((e=>{this._stage.addChild(e.container)}));const e=this.graphicsView;this._stage.addChild(e.container),this._stage.addChild(this._magnifierView)}_setupSpatialReferenceDependentProperties(){const e=new D(x.create({spatialReference:this.spatialReference,size:512,numLODs:36}));this._set("featuresTilingScheme",e);const t=new he({view:this,graphics:this.graphics,requestUpdateCallback:()=>this.requestUpdate(),container:new ce(e)});this.frameTask.graphicsView=t,this._set("graphicsView",t)}_destroySpatialReferenceDependentProperties(){const e=this.graphicsView;this._set("graphicsView",null),this.frameTask.graphicsView=null,e.destroy(),this._set("featuresTilingScheme",null)}_spatialReferenceChanged(e){if(!this.ready)return;this.frameTask.stop();for(const i of this.allLayerViews)i.processDetach();this._destroySpatialReferenceDependentProperties();const t=this.state.paddedViewState.clone();if(h(this._scaleBeforeChangingSpatialReference))this._scaleBeforeChangingSpatialReference=t.scale;else{const e=t.viewpoint.clone();e.scale=this._scaleBeforeChangingSpatialReference,t.viewpoint=e}const s=t.clone(),[r,n]=t.center;let a=null;try{a=this._project(new S({x:r,y:n,spatialReference:t.spatialReference}),e)}catch(p){M()||o.getLogger(this.declaredClass).warn(new w("mapview:spatial-reference-change","could not project the view's center to the new spatial reference",{center:a.toJSON(),spatialReference:e,error:p}))}a||(a=new S({x:0,y:0,spatialReference:e}));const l=U(new i({targetGeometry:new S,scale:0,rotation:0}),t.viewpoint,a);s.viewpoint=l;try{const i=20,r=[t.size[0]/2,t.size[1]/2],n=[r[0]+i,r[1]],a=t.toMap([0,0],n),{x:o,y:p}=this._project(new S({x:a[0],y:a[1],spatialReference:t.spatialReference}),e);a[0]=o,a[1]=p,s.toScreen(a,a);const h=J(r,a,n),c=Math.hypot(a[0]-r[0],a[1]-r[1])/i;!Number.isFinite(c)||Math.abs(c)>4?(l.rotation=0,l.targetGeometry=new S({x:0,y:0,spatialReference:e})):(l.scale*=c,l.scale>has("mapview-srswitch-adjust-rotation-scale-threshold")?l.rotation=0:l.rotation+=Number.isFinite(h)?h:0)}catch{}this._get("constraints").constrain(l,null),this._get("state").viewpoint=l,this._stage.state=this.state,this._setupSpatialReferenceDependentProperties();for(const i of this.allLayerViews)i.processAttach();this.frameTask.requestFrame(),this.frameTask.start(),this._updateStageChildren()}};fe.type="2d",e([_({readOnly:!0})],fe.prototype,"animationManager",void 0),e([_({constructOnly:!0})],fe.prototype,"deactivatedWebGLExtensions",void 0),e([_({constructOnly:!0})],fe.prototype,"debugWebGLExtensions",void 0),e([_({readOnly:!0})],fe.prototype,"featuresTilingScheme",void 0),e([_({readOnly:!0})],fe.prototype,"fullOpacity",void 0),e([_({readOnly:!0})],fe.prototype,"graphicsTileStore",null),e([_()],fe.prototype,"graphicsView",void 0),e([_({readOnly:!0})],fe.prototype,"state",void 0),e([_()],fe.prototype,"initialExtentRequired",null),e([_()],fe.prototype,"labelManager",void 0),e([_({readOnly:!0})],fe.prototype,"resourceManager",null),e([_({readOnly:!0})],fe.prototype,"textureManager",null),e([_({readOnly:!0})],fe.prototype,"mapViewNavigation",void 0),e([_({constructOnly:!0})],fe.prototype,"renderCanvas",void 0),e([_()],fe.prototype,"renderingOptions",void 0),e([_({readOnly:!0})],fe.prototype,"rendering",void 0),e([_({constructOnly:!0})],fe.prototype,"supersampleScreenshotsEnabled",void 0),e([_({readOnly:!0})],fe.prototype,"supportsGround",void 0),e([_()],fe.prototype,"_stationaryTimer",void 0),e([_()],fe.prototype,"_defaultsFromMapSettings",null),e([_()],fe.prototype,"_pePromise",void 0),e([_({readOnly:!0})],fe.prototype,"typeSpecificPreconditionsReady",null),e([_()],fe.prototype,"animation",null),e([_({type:le})],fe.prototype,"background",null),e([_({value:null,type:S,dependsOn:["state.id","ready"]})],fe.prototype,"center",null),e([_({type:N})],fe.prototype,"constraints",null),e([_({value:null,type:V,dependsOn:["state.id","ready"]})],fe.prototype,"extent",null),e([_()],fe.prototype,"floors",void 0),e([_({type:K})],fe.prototype,"highlightOptions",void 0),e([_({readOnly:!0})],fe.prototype,"inputManager",void 0),e([_()],fe.prototype,"map",void 0),e([_({value:{top:0,right:0,bottom:0,left:0},cast:e=>({top:0,right:0,bottom:0,left:0,...e})})],fe.prototype,"padding",null),e([_()],fe.prototype,"resizeAlign",void 0),e([_({readOnly:!0,dependsOn:["state.id"]})],fe.prototype,"resolution",null),e([_({value:0,type:Number,dependsOn:["state.id","ready"]})],fe.prototype,"rotation",null),e([_({value:0,type:Number,dependsOn:["state.id","ready"]})],fe.prototype,"scale",null),e([_({constructOnly:!0})],fe.prototype,"spatialReferenceLocked",void 0),e([_()],fe.prototype,"stationary",null),e([_({type:Y,readOnly:!0})],fe.prototype,"timeline",void 0),e([_({readOnly:!0})],fe.prototype,"type",void 0),e([_({readOnly:!0})],fe.prototype,"updating",null),e([_({value:null,type:i,dependsOn:["state.id","ready"]})],fe.prototype,"viewpoint",null),e([_({value:-1,dependsOn:["state.id","ready"]})],fe.prototype,"zoom",null),e([_({readOnly:!0})],fe.prototype,"navigating",null),e([_({type:oe})],fe.prototype,"ui",void 0),fe=e([v("esri.views.MapView")],fe);const _e=fe;function ve(e){const t=e.getObjectId();return t?`${e.layer?.uid??e.sourceLayer?.uid??"MapView"}/${t}`:`"MapView/${e.uid}`}function Ve(e,i,s,r,n){return a=>{if(a instanceof t){if(a.layer===e)n?.();else{const t=e.allLayerViews.find((e=>e.layer===a.layer));t&&r?.(t)}s(ve(a))}else{const t=e.allLayerViews.find((e=>e.layer===a));t&&i(t)}}}function Se(e,t){if(e)if(a(e))for(const i of e)if(a(i))for(const e of i)t(e);else t(i);else t(e)}function je(e){return"esri.WebMap"===e?.declaredClass}export{_e as default};