@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 20.4 kB
JavaScript
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Graphic.js";import{binaryIndexOf as r}from"../../../core/arrayUtils.js";import i from"../../../core/Logger.js";import{destroyMaybe as s,isNone as o,isSome as a,unwrap as n}from"../../../core/maybe.js";import{initial as d,watch as l}from"../../../core/reactiveUtils.js";import{property as h}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as u}from"../../../core/accessorSupport/decorators/subclass.js";import{s as c}from"../../../chunks/vec3.js";import{c as p}from"../../../chunks/vec3f64.js";import{projectBuffer as g,projectVectorToVector as m}from"../../../geometry/projection.js";import{extentContainsCoords3D as y}from"../../../geometry/support/contains.js";import{getGeometryZScaler as f}from"../../../geometry/support/zscale.js";import{fallbackObjectIDAttribute as _}from"../../../layers/LayerConstants.js";import{makeDehydratedPoint as b,estimateSize as v}from"../../../layers/graphics/dehydratedFeatures.js";import{hydrateGraphic as x}from"../../../layers/graphics/hydratedFeatures.js";import E from"../../../layers/graphics/controllers/I3SOnDemandController.js";import I from"../../../layers/support/FeatureFilter.js";import w from"../../../rest/support/Query.js";import{I3SPointsWorkerHandle as N}from"./I3SPointsWorkerHandle.js";import{LayerView3D as C}from"./LayerView3D.js";import O from"./graphics/Graphics3DFeatureProcessor.js";import{QueryEngine as D}from"./graphics/QueryEngine.js";import{createInteractiveEditSession as F,processAttributeEdits as j}from"./i3s/attributeEditing.js";import{I3SGraphicsMap as S}from"./i3s/I3SGraphicsMap.js";import{I3SOverrides as G}from"./i3s/I3SOverrides.js";import{checkRecyclable as A,checkSpatialReferences as L,containsDraco as P,whenGraphicAttributes as V,getCachedAttributeValue as R}from"./i3s/I3SUtil.js";import{DefinitionExpressionSceneLayerView as M}from"./support/DefinitionExpressionSceneLayerView.js";import{defineFieldProperties as H}from"./support/fieldProperties.js";import{PopupSceneLayerView as q}from"./support/PopupSceneLayerView.js";import{SceneLayerViewRequiredFields as U}from"./support/SceneLayerViewRequiredFields.js";import Q from"../support/debugFlags.js";import{compute as T}from"../support/orientedBoundingBox.js";import{updatingProgress as B}from"../support/updatingProperties.js";import{Attribute as k}from"../webgl-engine/lib/Attribute.js";import{newDoubleArray as z}from"../webgl-engine/lib/DoubleArray.js";import{UpdatePolicy as W}from"../webgl-engine/lib/UpdatePolicy.js";import Z from"../../layers/SceneLayerView.js";import{TaskPriority as K}from"../../support/Scheduler.js";const Y=H();let $=class extends(M(q(C(Z)))){constructor(){super(...arguments),this.type="scene-layer-graphics-3d",this._queryEngine=null,this._memCache=null,this._interactiveEditingSessions=new Map,this.loadedGraphics=new S(((e,t,r)=>te(e,t,r)),(e=>this.processor.graphicsCore.recreateGraphics(e))),this.holeFilling="always",this.progressiveLoadFactor=1,this.supportsHeightUnitConversion=!0,this._coordinatesOutsideExtentErrors=0,this._maxCoordinatesOutsideExtentErrors=20}tryRecycleWith(e,t){return e.url===this.layer.url&&this._i3sOverrides.isEmpty?e.load(t).then((()=>{A(this.layer,e,this._i3sOverrides),this.layer=e,this._i3sOverrides.destroy();const t=this.view.resourceController?.memoryController;this._i3sOverrides=new G({view:this.view,layer:e,memoryController:t}),s(this._queryEngine),this._setupQueryEngine(),this.processor.resetObjectStates()})):null}initialize(){this.addResolvingPromise(this.layer.indexInfo);const e=this.view.resourceController?.memoryController;this._i3sOverrides=new G({view:this.view,layer:this.layer,memoryController:e}),L(this.layer,this.view.spatialReference,this.view.viewingMode),this._fieldsHelper=new U({layerView:this}),this.updatingHandles.add((()=>this.layer.rangeInfos),(e=>this._rangeInfosChanged(e)),d),this.updatingHandles.add((()=>this.layer.renderer),((e,t)=>this._rendererChange(e,t))),this.updatingHandles.add((()=>[this.parsedDefinitionExpression,this._excludeObjectIdsSorted]),(()=>this._filterChange())),this.handles.add(l((()=>Q.I3S_TREE_SHOW_TILES),(e=>{if(e&&!this._treeDebugger){const e=this._controller.crsIndex;import("./support/I3STreeDebugger.js").then((({I3STreeDebugger:t})=>{!this._treeDebugger&&Q.I3S_TREE_SHOW_TILES&&(this._treeDebugger=new t({lv:this,view:this.view,nodeSR:e}))}))}else e||!this._treeDebugger||Q.I3S_TREE_SHOW_TILES||(this._treeDebugger.destroy(),this._treeDebugger=null)}),d)),this._set("processor",new O({owner:this,preferredUpdatePolicy:W.ASYNC,scaleVisibilityEnabled:!0,filterVisibilityEnabled:!0,timeExtentEnabled:!1,frustumVisibilityEnabled:!1,elevationAlignmentEnabled:!0,elevationFeatureExpressionEnabled:!1,setUidToIdOnAdd:!1,dataExtent:this.layer.fullExtent,updateClippingExtent:e=>this._updateClippingExtent(e)})),this.processor.elevationAlignment?.events.on("invalidate-elevation",(e=>this._controller.updateElevationChanged(e.extent,e.spatialReference))),this.supportsHeightUnitConversion&&(this._verticalScale=f("point",this.layer.spatialReference,this.view.spatialReference)),this.addResolvingPromise(this.processor.initializePromise),this._memCache=this.view.resourceController.memoryController.newCache(this.uid),this._controller=new E({layerView:this,scaleVisibilityEnabled:!1}),P(this.layer.geometryDefinitions)&&(this._worker=new N((e=>this.view.resourceController.immediate.schedule(e)))),this.handles.add(this.layer.on("apply-edits",(e=>this.updatingHandles.addPromise(e.result)))),this.handles.add(this.layer.on("edits",(e=>this._handleEdits(e)))),this.when((()=>{this._setupQueryEngine(),this.updatingHandles.add((()=>this.maximumNumberOfFeatures),(e=>this._controller.featureTarget=e),d),this.updatingHandles.add((()=>this.suspended),(e=>{e&&this._removeAllNodeData()}))}))}destroy(){this._treeDebugger=s(this._treeDebugger),this._i3sOverrides=s(this._i3sOverrides),this._set("processor",s(this.processor)),this._controller=s(this._controller),this._queryEngine=s(this._queryEngine),this._worker=s(this._worker),this._memCache=s(this._memCache),this.loadedGraphics.clear(),this._fieldsHelper=s(this._fieldsHelper)}get i3slayer(){return this.layer}get updatingProgressValue(){return this._controller?.updatingProgress??1}get requiredFields(){return this._fieldsHelper?.requiredFields??[]}get maximumNumberOfFeatures(){const e=this.processor?.graphicsCore?.displayFeatureLimit;return e?.maximumNumberOfFeatures??0}set maximumNumberOfFeatures(e){null!=e?(this._override("maximumNumberOfFeatures",e),this._controller.fixedFeatureTarget=!0):(this._clearOverride("maximumNumberOfFeatures"),this._controller.fixedFeatureTarget=!1)}get maximumNumberOfFeaturesExceeded(){return!this.suspended&&(!!this._controller?.useMaximumNumberOfFeatures&&!this._controller.leavesReached)}get _excludeObjectIdsSorted(){const e=this.layer.excludeObjectIds;return e.length?e.toArray().sort(((e,t)=>e-t)):null}get lodFactor(){return"Labels"===this.layer.semantic?1:this.view.qualitySettings.sceneService.point.lodFactor}get hasM(){return!1}get hasZ(){return!0}async whenGraphicAttributes(e,t){return V(this.layer,e,this._getObjectIdField(),t,(()=>[...this.loadedGraphics.nodes()]))}getHit(e){if(!this.loadedGraphics)return null;const t=x(this.loadedGraphics.find((t=>t.uid===e)),this.layer),r=this._getObjectIdField();return t&&t.attributes&&t.attributes[r]?(t.layer=this.layer,t.sourceLayer=this.layer,{type:"graphic",graphic:t,layer:t.layer}):null}whenGraphicBounds(e,t){return this.processor.whenGraphicBounds(e,t)}computeAttachmentOrigin(e,t){return this.processor.computeAttachmentOrigin(e,t)}canResume(){return super.canResume()&&(!this._controller||this._controller.rootNodeVisible)}isUpdating(){return!!(this._controller?.updating||this.processor?.updating||this._fieldsHelper?.updating||this.layerFilterUpdating)}highlight(e){return this.processor.highlight(e,this.layer.objectIdField)}get updatePolicy(){return this.processor.graphicsCore.effectiveUpdatePolicy}createInteractiveEditSession(e){return F(this._attributeEditingContext,e)}async _decompressBinaryPointData(e,t){const r={geometryBuffer:e.geometryBuffer};o(this._worker)&&(this._worker=new N((e=>this.view.resourceController.immediate.schedule(e))));const i=await this._worker.invoke(r,t);if(o(i))throw new Error("Failed to decompress Draco point data");return{positionData:i.positions,featureIds:i.featureIds}}async addNode(e,t,r){if(!ee(t)&&!X(t))throw new Error;if(this.loadedGraphics.hasNode(e.index))return void i.getLogger(this.declaredClass).error("I3S node "+e.id+" already added");const s=a(this.layer.fullExtent)?ie(this.layer.fullExtent.clone(),.5):null,o=[],{featureIds:n,pointPositions:d}=ee(t)?await this._extractBinaryPointPositions(e,t,r):this._extractLegacyPointPositions(t);this._validatePositions(e,n,d,s,o);const l=this._controller.crsVertex,h=this.view.spatialReference;g(d,l,0,d,h,0,n.length);const u=ee(t)?e.level:0,c={graphics:this._createGraphics(n,d,e.index,u),featureIds:n,attributeInfo:t.attributeDataInfo,node:e};if(await this._i3sOverrides.apply(c.featureIds,t.attributeDataInfo,r),e.numFeatures=c.graphics.length,this._updateNodeMemory(e),re(c),o.length>0&&(this._computeObb(e,o,l),this._controller.updateVisibility(e.index)),!this._controller.isGeometryVisible(e))return void this._cacheNodeData(c);if(a(this._verticalScale))for(const i of c.graphics)this._verticalScale(i.geometry);const p=this.view._stage.renderView.objectAndLayerIdRenderHelper;if(a(p))for(let i=0;i<c.featureIds.length;i++){const e=c.featureIds[i];p.setUidToObjectAndLayerId(e,c.graphics[i].uid,this.layer.id,this.layer.uid,this.layer.popupEnabled,c.node.resources.attributes,i)}this.loadedGraphics.addNode(e.index,c),this._controller.updateLoadStatus(e.index,!0),this._filterNode(c),this._treeDebugger&&this._treeDebugger.update()}_computeObb(e,t,r){const i=this._controller.crsIndex,s=i.isGeographic?this.view.renderSpatialReference:i;g(t,r,0,t,s,0,t.length/3),e.serviceObb=T(new k(t,3)),i.isGeographic&&m(e.serviceObb.center,s,e.serviceObb.center,i)}isNodeLoaded(e){return this.loadedGraphics.hasNode(e)}isNodeReloading(){return!1}updateNodeState(){}async _extractBinaryPointPositions(e,t,r){const i=await this._decompressBinaryPointData(t,r),s=i.positionData,o=3,n=s.length/o,d=z(3*n),l=a(e.serviceObb)?e.serviceObb.center:[0,0,0],h=Math.abs(l[2])*2**-20;for(let a=0;a<n;a++){const e=a*o;d[e+0]=s[e+0]+l[0],d[e+1]=s[e+1]+l[1],d[e+2]=s[e+2]+l[2],Math.abs(d[e+2])<h&&(d[e+2]=0)}return{featureIds:i.featureIds?Array.from(i.featureIds):[],pointPositions:d}}_extractLegacyPointPositions(e){const t=e.pointData.length,r=z(3*t),i=new Array;for(let s=0;s<t;s++){const t=e.pointData[s],o=t.featureDataPosition,a=o.length,n=t.geometries?.[0]??se[a],d=t.featureIds[0];if("Embedded"!==n.type||"points"!==n.params.type||a<2||a>3)continue;const l=n.params.vertexAttributes?.position??[0,0,0],h=3*i.length;r[h+0]=o[0]+l[0],r[h+1]=o[1]+l[1],r[h+2]=3===a?o[2]+l[2]:NaN,i.push(d)}return{featureIds:i,pointPositions:r}}_validatePositions(e,t,r,s,n){if(o(s)&&e.serviceObb)return;const d=t.length,l=3;for(let o=0;o<d;o++){const t=o*l;c(oe,r[t],r[t+1],r[t+2]),a(s)&&!y(s,oe)&&(this._coordinatesOutsideExtentErrors<this._maxCoordinatesOutsideExtentErrors&&i.getLogger(this.declaredClass).error("Service Error: Coordinates outside of layer extent"),this._coordinatesOutsideExtentErrors+1===this._maxCoordinatesOutsideExtentErrors&&i.getLogger(this.declaredClass).error("Maximum number of errors reached. Further errors are ignored."),this._coordinatesOutsideExtentErrors++),e.serviceObb||n.push(oe[0],oe[1],oe[2])}}_createGraphics(e,r,i,s){const o=e.length,d=3,l=this._getObjectIdField(),h=this.processor.graphicsCore,u=new Array,c=this.view.spatialReference;for(let p=0;p<o;p++){const o=e[p],g={};null!=o&&(g[l]=o);const m=o??t.generateUID(),y=p*d,f=isNaN(r[y+2])?void 0:r[y+2],_=b(r[y],r[y+1],f,c),v=this.loadedGraphics.get(m);if(a(v))(null==v.level||v.level<s)&&(ae.property="geometry",ae.graphic=v,ae.oldValue=n(v.geometry),ae.newValue=_,v.geometry=_,v.level=s,h.graphicUpdateHandler(ae)),u.push(v);else{const e=t.generateUID();u.push({objectId:m,uid:e,geometry:_,attributes:g,visible:!0,nodeIndex:i,level:s})}}return u}_updateNodeMemory(e){e.memory=4096+(a(e.numFeatures)?e.numFeatures*this.processor.graphicsCore.usedMemoryPerGraphic:0)}_cacheNodeData(e){const t=e.graphics.reduce(((e,t)=>v(t)+e),512+8*e.featureIds.length+1024);this._memCache.put(this._getMemCacheKey(e.node),e,t)}_getMemCacheKey(e){return`${e.index}`}_removeAllNodeData(){this.loadedGraphics.forEachNode(((e,t)=>{if(e){const t=e.node;this._updateNodeMemory(t),this._cacheNodeData(e)}this._controller.updateLoadStatus(t,!1)})),this._treeDebugger&&this._treeDebugger.update(),this.loadedGraphics.clear()}removeNode(e){const t=this._removeNodeStageData(e);t&&(this._updateNodeMemory(t.node),this._cacheNodeData(t))}_removeNodeStageData(e){const t=this.loadedGraphics.getNode(e);return o(t)?null:(this._controller.updateLoadStatus(e,!1),this.loadedGraphics.removeNode(e),this._treeDebugger&&this._treeDebugger.update(),t)}async loadCachedNodeData(e){return this._memCache?.pop(this._getMemCacheKey(e))}async addCachedNodeData(e,t,r,s){this.loadedGraphics.hasNode(e.index)?i.getLogger(this.declaredClass).error("I3S node "+e.id+" already added"):(await this._i3sOverrides.apply(t.featureIds,r,s),this.loadedGraphics.addNode(e.index,t),this._controller.updateLoadStatus(e.index,!0),this._updateNodeMemory(e),t.attributeInfo=r,this._attributeValuesChanged(t),this._filterNode(t),this._treeDebugger&&this._treeDebugger.update())}getLoadedNodeIds(){const e=[];return this.loadedGraphics.forEachNode((t=>e.push(t.node.id))),e.sort()}getVisibleNodes(){const e=new Array;return this.loadedGraphics.forEachNode((t=>e.push(t.node))),e}getLoadedNodeIndices(e){this.loadedGraphics.forEachNode(((t,r)=>e.push(r)))}getLoadedAttributes(e){const t=this.loadedGraphics.getNode(e);if(a(t)&&a(t.attributeInfo))return t.attributeInfo.loadedAttributes}getAttributeData(e){const t=this.loadedGraphics.getNode(e);if(a(t)&&a(t.attributeInfo))return t.attributeInfo.attributeData}_setAttributeData(e,t){const r=this.loadedGraphics.getNode(e);o(r)||o(r.attributeInfo)||(r.attributeInfo.attributeData=t,this._attributeValuesChanged(r))}async updateAttributes(e,t,r){const i=this.loadedGraphics.getNode(e);o(i)||(await this._i3sOverrides.apply(i.featureIds,t,r),i.attributeInfo=t,this._attributeValuesChanged(i))}_attributeValuesChanged(e){if(re(e),this._filterNode(e),this.processor.graphicsCore.labelsEnabled){const t=e.graphics.map((e=>e.uid));this.processor.graphicsCore.updateLabelingInfo(t)}}_updateClippingExtent(e){return this._controller&&this._controller.updateClippingArea(e),!1}_getObjectIdField(){return this.layer.objectIdField||_}async _rendererChange(e,t){const{layer:{fieldsIndex:r}}=this,i=new Set;let s,o;e?(await e.collectRequiredFields(i,r),s=Array.from(i).sort()):s=[],i.clear(),t?(await t.collectRequiredFields(i,r),o=Array.from(i).sort()):o=[],s.length===o.length&&s.every(((e,t)=>s[t]===o[t]))||this._reloadAllNodes()}_rangeInfosChanged(e){null!=e&&e.length>0&&i.getLogger(this.declaredClass).warn("Unsupported property: rangeInfos are currently only serialized to and from web scenes but do not affect rendering.")}_filterChange(){this.loadedGraphics.forEachNode((e=>this._filterNode(e)))}_reloadAllNodes(){this._removeAllNodeData(),this._controller&&this._controller.restartNodeLoading()}_filterNode(e){const t=this.parsedDefinitionExpression,i=this._excludeObjectIdsSorted,s=this._getObjectIdField();for(const a of e.graphics){const e=a.visible,n=!t||this._evaluateClause(t,a),d=o(i)||r(i,a.attributes[s])<0;a.visible=n&&d,e!==a.visible&&(ae.graphic=a,ae.property="visible",ae.oldValue=e,ae.newValue=a.visible,this.processor.graphicsCore.graphicUpdateHandler(ae))}}createQuery(){const e={outFields:["*"],returnGeometry:!0,outSpatialReference:this.view.spatialReference};return a(this.filter)?this.filter.createQuery(e):new w(e)}queryFeatures(e,t){return this._queryEngine.executeQuery(this._ensureQuery(e),t?.signal)}queryObjectIds(e,t){return this._queryEngine.executeQueryForIds(this._ensureQuery(e),t?.signal)}queryFeatureCount(e,t){return this._queryEngine.executeQueryForCount(this._ensureQuery(e),t?.signal)}queryExtent(e,t){return this._queryEngine.executeQueryForExtent(this._ensureQuery(e),t?.signal)}_ensureQuery(e){return this._addDefinitionExpressionToQuery(o(e)?this.createQuery():w.from(e))}_setupQueryEngine(){const e=()=>this.processor.featureStore;this._queryEngine=new D({context:{spatialReference:this.view.spatialReference,layer:this.layer,scheduler:this.view.resourceController.scheduler,get featureStore(){return e()},hasZ:this.hasZ,hasM:this.hasM},priority:K.FEATURE_QUERY_ENGINE})}getUsedMemory(){return this.processor?.graphicsCore?.usedMemory??0}getUnloadedMemory(){return.8*((this._controller?.unloadedMemoryEstimate??0)+(this.processor?.graphicsCore?.unprocessedMemoryEstimate??0))}ignoresMemoryFactor(){return this._controller&&this._controller.fixedFeatureTarget}_handleEdits(e){j(this._attributeEditingContext,e)}get _attributeEditingContext(){const e=this._getObjectIdField();return{sessions:this._interactiveEditingSessions,fieldsIndex:this.layer.fieldsIndex,objectIdField:e,forEachNode:e=>this.loadedGraphics.forEachNode((t=>e(t.node,t.featureIds))),attributeStorageInfo:this.i3slayer.attributeStorageInfo??[],i3sOverrides:this._i3sOverrides,getAttributeData:e=>this.getAttributeData(e),setAttributeData:(t,r,i)=>{this._setAttributeData(t,r);const s=this.loadedGraphics.getNode(t);if(a(i)){const t=this.loadedGraphics.get(i.attributes[e]);a(t)&&this.processor.graphicsCore.recreateGraphics([t])}else a(s)&&this.processor.graphicsCore.recreateGraphics(s.graphics)},clearMemCache:()=>{}}}get performanceInfo(){const e={displayedNumberOfFeatures:this.loadedGraphics.length,maximumNumberOfFeatures:this.maximumNumberOfFeatures,totalNumberOfFeatures:-1,nodes:this.loadedGraphics.nodeCount,core:this.processor.graphicsCore.performanceInfo};return this._controller&&this._controller.updateStats(e),e}get test(){return{controller:this._controller,numNodes:this.loadedGraphics.nodeCount,loadedGraphics:this.loadedGraphics}}};e([h()],$.prototype,"processor",void 0),e([h({type:I})],$.prototype,"filter",void 0),e([h()],$.prototype,"loadedGraphics",void 0),e([h()],$.prototype,"i3slayer",null),e([h()],$.prototype,"_controller",void 0),e([h()],$.prototype,"updating",void 0),e([h()],$.prototype,"suspended",void 0),e([h()],$.prototype,"holeFilling",void 0),e([h(B)],$.prototype,"updatingProgress",void 0),e([h()],$.prototype,"updatingProgressValue",null),e([h(Y.requiredFields)],$.prototype,"requiredFields",null),e([h(Y.availableFields)],$.prototype,"availableFields",void 0),e([h()],$.prototype,"_fieldsHelper",void 0),e([h({type:Number})],$.prototype,"maximumNumberOfFeatures",null),e([h({readOnly:!0})],$.prototype,"maximumNumberOfFeaturesExceeded",null),e([h()],$.prototype,"_excludeObjectIdsSorted",null),e([h({readOnly:!0})],$.prototype,"lodFactor",null),e([h({readOnly:!0})],$.prototype,"hasM",null),e([h({readOnly:!0})],$.prototype,"hasZ",null),$=e([u("esri.views.3d.layers.SceneLayerGraphicsView3D")],$);const J=$;function X(e){return"pointData"in e}function ee(e){return"geometryBuffer"in e&&null!==e.geometryBuffer}function te(e,t,r){const i=t.attributeInfo;if(o(i)||o(i.loadedAttributes)||o(i.attributeData))return!1;let s=!1;for(const{name:o}of i.loadedAttributes)if(i.attributeData[o]){const t=R(i.attributeData[o],r);t!==e.attributes[o]&&(e.attributes[o]=t,s=!0)}return s}function re(e){const t=e.attributeInfo,r=e.node.index;if(!(o(t)||o(t.loadedAttributes)||o(t.attributeData)))for(let i=0;i<e.graphics.length;i++){const s=e.graphics[i];if(s.nodeIndex===r){s.attributes||(s.attributes={});for(const{name:e}of t.loadedAttributes)t.attributeData[e]&&(s.attributes[e]=R(t.attributeData[e],i))}}}function ie(e,t){return e.xmin-=t,e.ymin-=t,e.xmax+=t,e.ymax+=t,null!=e.zmin&&null!=e.zmax&&(e.zmin-=t,e.zmax+=t),null!=e.mmin&&null!=e.mmax&&(e.mmin-=t,e.mmax+=t),e}const se={2:{type:"Embedded",params:{type:"points",vertexAttributes:{position:[0,0]}}},3:{type:"Embedded",params:{type:"points",vertexAttributes:{position:[0,0,0]}}}},oe=p(),ae={graphic:null,property:null,oldValue:null,newValue:null};export{J as default};