UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 8.65 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import has from"../../../../core/has.js";import{destroyMaybe as t}from"../../../../core/maybe.js";import{notDeepEqual as e}from"../../../../core/object.js";import{throwIfNotAbortError as s,throwIfAborted as r,after as i}from"../../../../core/promiseUtils.js";import{diff as a}from"../../../../core/accessorSupport/diffUtils.js";import{ignoreConnectionErrors as o}from"../../../../core/workers/utils.js";import{normalizeTransform as n,quantizeX as c,quantizeY as h}from"../../../../geometry/support/quantizationUtils.js";import{MultiTileMeshData as u}from"../../engine/webgl/mesh/MultiTileMeshData.js";import{FeatureMeshFactory as g}from"../../engine/webgl/mesh/factories/FeatureMeshFactory.js";import{ResourceProxy as p}from"../../engine/webgl/mesh/factories/ResourceProxy.js";import{MeshWriterRegistry as y}from"../../engine/webgl/shaderGraph/techniques/mesh/MeshWriterRegistry.js";import{MatcherContext as d}from"../../engine/webgl/util/MatcherContext.js";import{ProcessorTileMessageQueue as _}from"./ProcessorTileMessageQueue.js";import{BinningStrategy as l}from"./processor/BinningStrategy.js";import{ClusterStrategy as m}from"./processor/ClusterStrategy.js";import{FeatureUpdateStrategy as f}from"./processor/FeatureUpdateStrategy.js";import{TrackStrategy as b}from"./processor/TrackStrategy.js";import{AttributeStore as w}from"./support/AttributeStore.js";import{ComputedAttributeStorage as S}from"./support/ComputedAttributeStorage.js";class j{constructor(t,e){this._connection=t,this._source=e,this._version=1,this._registry=new y,this._proxy=new p({fetch:(t,e)=>this._connection.layerView.fetch(t,e),fetchDictionary:(t,e)=>this._connection.layerView.fetchDictionary(t,e)}),this._attributeStore=new w({isLocal:!1,update:t=>o(this._connection.container.updateAttributeView(t))})}destroy(){this._proxy.destroy(),this._strategy?.destroy(),this._attributeStore.destroy()}get aggregateQueryEngine(){return this._strategy?.aggregateQueryEngine}get usedMemory(){let t=0;return t+=this._attributeStore.usedMemory,this._strategy&&(t+=this._strategy.usedMemory),t}get version(){return this._version}getDisplayFeatures(t){return this._strategy?this._strategy.getDisplayFeatures(t):{features:[],aggregates:[],tracks:[]}}getDisplayIds(t){const e={};return this._strategy?(this._strategy.displayMap(t,t=>t,(t,s,r)=>{e[r]=t}),e):e}getFeatureObjectIdsForAggregate(t){return this._strategy?this._strategy.getFeatureObjectIdsForAggregate(t):[]}onSubscribe(t){this._strategy?.onSubscribe(t)}onUnsubscribe(t){this._strategy?.onUnsubscribe(t)}requiresInvalidation(){return this._strategy?.requiresInvalidation()??!1}async update(t,s,r,i,o){const n=t.processor,c=e(this._schema?.storage,n.storage),h=e(this._schema?.mesh.properties,n.mesh.properties),u=e(this._schema?.mesh.factory,n.mesh.factory),p=e(this._schema?.mesh.strategy,n.mesh.strategy),y=I(this._schema?.expressionProperties,n.expressionProperties),_=y.some(t=>this._attributeStore.hasArcadeDependency(t)),l=y.some(t=>this._factory?.hasArcadeDependency(t)??!1),m=y.some(t=>this._strategy?.hasArcadeDependency(t))||this._strategy?.isAggregate&&_,f=l||m,b=h||u||p;if(!(c||b||(l||_||m))&&!i)return!1;has("esri-2d-update-debug")&&console.debug(`Version[${this._version}] SymbolProcessor.update`,{changes:a(this._schema,n),schema:n}),this._schema=n;const w=new S({fields:this._source.metadata.fieldsIndex,spatialReference:this._source.metadata.outSpatialReference}),j={currentUser:n.mesh.properties.currentUser};if((c||b||_)&&(await this._attributeStore.update(n.storage,w,this._source.metadata,s),this._strategy?.invalidateAttributeData(x(n))),!i&&!b&&!f)return!1;(p||h||f)&&await this._updateStrategy(n.mesh.strategy,o,x(n),j),this._updateSortKey(w,"sortKey"in n.mesh.properties?n.mesh.properties.sortKey:null);const v="dictionary"===n.mesh.factory.symbology.type?n.mesh.factory.symbology.fieldMap:null,M=new d(w,this._proxy,r,this._registry,v);return(u||"dictionary"===n.mesh.factory.symbology.type)&&(this._factory=await g.create(M,n.mesh.factory)),this._version=s,!0}async applyOverrideUpdate(t,e){if(!this._strategy)return;const s=this._strategy.applyOverrideUpdate(t);for await(const i of s)try{await this._process(i,e)}catch(r){}}async updateChunks(t){await this._doUpdateChunks(t),this._strategy?.afterUpdateChunks()}async removeChunks(t){this._strategy?.removeChunks(t),this._attributeStore.incrementDisplayIdGeneration()}updateHighlight({highlights:t}){if(!this._strategy||!this._strategy.hasSubscribers)return void this._attributeStore.setHighlight(t.map(({objectId:t,highlightFlags:e})=>({objectId:t,highlightFlags:e,displayId:-1})),t);const e=this._strategy.displayMap(t,({objectId:t})=>t,(t,{highlightFlags:e},s)=>({objectId:s,displayId:t,highlightFlags:e}));this._attributeStore.setHighlight(e,t)}invalidate(){this._strategy&&this._strategy.invalidate()}async _doUpdateChunks(t){if(!this._strategy)return;const e=this._strategy.updateChunks(),r=[],i=new Map;for await(const o of e){let e=i.get(o.id);null==e&&(e=new _({concurrency:16,process:e=>this._process(e,t)}),i.set(o.id,e));const a=e.push(o).catch(t=>s(t));r.push(a)}try{await Promise.all(r)}catch(a){}has("esri-2d-update-debug")&&console.log("SendUpdates"),this._attributeStore.sendUpdates(),has("esri-2d-update-debug")&&console.log("SendUpdates.await")}async _updateStrategy(t,e,s,r){switch(this._strategy?.destroy(),t.type){case"feature":this._strategy=new f(this._source,this._attributeStore,s,r);break;case"binning":this._strategy=await l.create(t,this._source,this._attributeStore,s,r);break;case"cluster":this._strategy=await m.create(this._connection,t,this._source,this._attributeStore,s,r);break;case"track":this._strategy=await b.create(t,this._source,this._attributeStore,s,r)}for(const i of e)this._strategy.onSubscribe(i)}async _updateSortKey(e,s){if(this._sortInfo=t(this._sortInfo?.computed),null!=s){const t=s.byRenderer?null:await e.createComputedField(s);this._sortInfo={...s,computed:t}}}async _process(t,e){const s=t.subscription;if(has("esri-2d-update-debug")){const e=s.tile;console.debug(`Version[${this._version}] Tile[${e.key.id}, end=${t.end}] Processor._process`)}const i={currentUser:this._schema?.mesh.properties.currentUser};await this._fetchResources(t,i),r(s.signal);const a=await this._write(t,s.tile.createArcadeEvaluationOptions(x(this._schema)),i,e),o=s.tile.tileInfoView.getLODInfoAt(s.tile.key);r(s.signal);const{message:n,transferList:c}=a.serialize(o),h={objectIdMap:null,inner:t.createMessage(n,this._version,this._attributeStore.epoch)};if(this._schema?.mesh.properties.returnMeshObjectId){h.objectIdMap={};const e=t.reader?.getCursor();if(e)for(;e.next();)h.objectIdMap[e.getDisplayId()]=e.getObjectId()}if(r(s.signal),await this._connection.container.onMessage(h,{signal:s.signal,transferList:c}),this._attributeStore.sendUpdates(),has("esri-2d-update-debug")){const e=s.tile;console.debug(`Version[${this._version}] Tile[${e.key.id}, end=${t.end}] Processor._process.await`)}}async _fetchResources(t,e){await this._fetchMatcherResources(t),await this._fetchWriterResources(t,e)}async _fetchMatcherResources(t){if(t.reader)return this._factory.enqueueMatcherRequests(this._proxy,t.reader)}async _fetchWriterResources(t,e){if(!t.reader)return;const s=t.reader.getCursor(),r=t.subscription.tile.createArcadeEvaluationOptions(x(this._schema));for(;s.next();)this._factory.enqueueWriterRequests(this._proxy,s,r,e);await this._proxy.fetchEnqueuedResources()}async _write(t,e,s,a){const o=t.subscription.tile,n=t.reader?.getCursor(),c=n?.getSize()??0,h=o.tileInfoView.tileInfo.isWrappable,g=o.tileInfoView.spatialReference.isWGS84,p=new u(o.key,this._strategy.enablePixelBuffering,h,g,c);if(!n)return p;const y=v(o.transform,a),d=o.createArcadeEvaluationOptions(x(this._schema));let _=0;for(;n.next();){++_%1e3||(await i(0),r(t.subscription));const a=this._getSortKeyValue(n,e);p.entityStart(n.getDisplayId(),a);try{this._factory.write(p,this._proxy,n,d,s,o.level,y)}catch(l){}p.entityEnd()}return p}_getSortKeyValue(t,e){if(!this._sortInfo)return 0;const{computed:s,order:r,byRenderer:i}=this._sortInfo,a=i?this._factory.getSortKey(t,e):s?.read(t,e);return null==a||isNaN(a)?0:a*("asc"===r?-1:1)}}function I(t,e){const s=[];return t?.timeExtent?.start===e.timeExtent?.start&&t?.timeExtent?.end===e.timeExtent?.end||s.push("timeProperties"),s}function x(t){const{timeZone:e}=t?.mesh.properties??{},{timeExtent:s}=t?.expressionProperties??{};return{timeZone:e,timeExtent:s}}function v(t,e){const s=n(t),r=[];for(const i of e.rings){const t=[];for(const e of i)t.push([c(s,e[0]),h(s,e[1])]);r.push(t)}return{rings:r}}export{j as default};