@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 8.92 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import has from"../../../../core/has.js";import{destroyMaybe as e}from"../../../../core/maybe.js";import{notDeepEqual as t}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(e,t,s,r){this._connection=e,this._source=t,this._requiredLevel=s,this._requiredScale=r,this._version=1,this._registry=new y,this._proxy=new p({fetch:(e,t)=>this._connection.layerView.fetch(e,t),fetchDictionary:(e,t)=>this._connection.layerView.fetchDictionary(e,t)}),this._attributeStore=new w({isLocal:!1,update:e=>o(this._connection.container.updateAttributeView(e))})}destroy(){this._proxy.destroy(),this._strategy?.destroy(),this._attributeStore.destroy()}get hasClusters(){return"cluster"===this._schema?.mesh.strategy.type}get aggregateQueryEngine(){return this._strategy?.aggregateQueryEngine}get usedMemory(){let e=0;return e+=this._attributeStore.usedMemory,this._strategy&&(e+=this._strategy.usedMemory),e}get version(){return this._version}getDisplayFeatures(e){return this._strategy?this._strategy.getDisplayFeatures(e):{features:[],aggregates:[],tracks:[]}}getDisplayIds(e){const t={};return this._strategy?(this._strategy.displayMap(e,e=>e,(e,s,r)=>{t[r]=e}),t):t}getFeatureObjectIdsForAggregate(e){return this._strategy?this._strategy.getFeatureObjectIdsForAggregate(e):[]}onSubscribe(e){this._strategy?.onSubscribe(e)}onUnsubscribe(e){this._strategy?.onUnsubscribe(e)}requiresInvalidation(){return this._strategy?.requiresInvalidation()??!1}updateRequiredLevel(e,t){this._strategy?.updateRequiredLevel(e,t),this._requiredLevel=e,this._requiredScale=t}async update(e,s,r,i,o){const n=e.processor,c=t(this._schema?.storage,n.storage),h=t(this._schema?.mesh.properties,n.mesh.properties),u=t(this._schema?.mesh.factory,n.mesh.factory),p=t(this._schema?.mesh.strategy,n.mesh.strategy),y=I(this._schema?.expressionProperties,n.expressionProperties),_=y.some(e=>this._attributeStore.hasArcadeDependency(e)),l=y.some(e=>this._factory?.hasArcadeDependency(e)??!1),m=y.some(e=>this._strategy?.hasArcadeDependency(e))||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(v(n))),!i&&!b&&!f)return!1;(p||h||f)&&await this._updateStrategy(n.mesh.strategy,o,v(n),j),this._updateSortKey(w,"sortKey"in n.mesh.properties?n.mesh.properties.sortKey:null);const x="dictionary"===n.mesh.factory.symbology.type?n.mesh.factory.symbology.fieldMap:null,M=new d(w,this._proxy,r,this._registry,x);return(u||"dictionary"===n.mesh.factory.symbology.type)&&(this._factory=await g.create(M,n.mesh.factory)),this._version=s,!0}async applyOverrideUpdate(e,t){if(!this._strategy)return;const s=this._strategy.applyOverrideUpdate(e);for await(const i of s)try{await this._process(i,t)}catch(r){}}async updateChunks(e){await this._doUpdateChunks(e),this._strategy?.afterUpdateChunks()}async removeChunks(e){this._strategy?.removeChunks(e),this._attributeStore.incrementDisplayIdGeneration()}updateHighlight({highlights:e}){if(!this._strategy||!this._strategy.hasSubscribers)return void this._attributeStore.setHighlight(e.map(({objectId:e,highlightFlags:t})=>({objectId:e,highlightFlags:t,displayId:-1})),e);const t=this._strategy.displayMap(e,({objectId:e})=>e,(e,{highlightFlags:t},s)=>({objectId:s,displayId:e,highlightFlags:t}));this._attributeStore.setHighlight(t,e)}invalidate(){this._strategy&&this._strategy.invalidate()}async _doUpdateChunks(e){if(!this._strategy)return;const t=this._strategy.updateChunks(),r=[],i=new Map;for await(const o of t){let t=i.get(o.id);null==t&&(t=new _({concurrency:16,process:t=>this._process(t,e)}),i.set(o.id,t));const a=t.push(o).catch(e=>s(e));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(e,t,s,r){switch(this._strategy?.destroy(),e.type){case"feature":this._strategy=new f(this._source,this._attributeStore,s,r);break;case"binning":this._strategy=await l.create(e,this._source,this._attributeStore,s,r);break;case"cluster":this._strategy=await m.create(this._connection,e,this._source,this._attributeStore,s,r,this._requiredLevel,this._requiredScale);break;case"track":this._strategy=await b.create(e,this._source,this._attributeStore,s,r)}for(const i of t)this._strategy.onSubscribe(i)}async _updateSortKey(t,s){if(this._sortInfo=e(this._sortInfo?.computed),null!=s){const e=s.byRenderer?null:await t.createComputedField(s);this._sortInfo={...s,computed:e}}}async _process(e,t){const s=e.subscription;if(has("esri-2d-update-debug")){const t=s.tile;console.debug(`Version[${this._version}] Tile[${t.key.id}, end=${e.end}] Processor._process`)}const i={currentUser:this._schema?.mesh.properties.currentUser};await this._fetchResources(e,i),r(s.signal);const a=await this._write(e,s.tile.createArcadeEvaluationOptions(v(this._schema)),i,t),o=s.tile.tileInfoView.getLODInfoAt(s.tile.key);r(s.signal);const{message:n,transferList:c}=a.serialize(o),h={objectIdMap:null,inner:e.createMessage(n,this._version,this._attributeStore.epoch)};if(this._schema?.mesh.properties.returnMeshObjectId){h.objectIdMap={};const t=e.reader?.getCursor();if(t)for(;t.next();)h.objectIdMap[t.getDisplayId()]=t.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 t=s.tile;console.debug(`Version[${this._version}] Tile[${t.key.id}, end=${e.end}] Processor._process.await`)}}async _fetchResources(e,t){await this._fetchMatcherResources(e),await this._fetchWriterResources(e,t)}async _fetchMatcherResources(e){if(e.reader)return this._factory.enqueueMatcherRequests(this._proxy,e.reader)}async _fetchWriterResources(e,t){if(!e.reader)return;const s=e.reader.getCursor(),r=e.subscription.tile.createArcadeEvaluationOptions(v(this._schema));for(;s.next();)this._factory.enqueueWriterRequests(this._proxy,s,r,t);await this._proxy.fetchEnqueuedResources()}async _write(e,t,s,a){const o=e.subscription.tile,n=e.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=x(o.transform,a),d=o.createArcadeEvaluationOptions(v(this._schema));let _=0;for(;n.next();){++_%1e3||(await i(0),r(e.subscription));const a=this._getSortKeyValue(n,t);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(e,t){if(!this._sortInfo)return 0;const{computed:s,order:r,byRenderer:i}=this._sortInfo,a=i?this._factory.getSortKey(e,t):s?.read(e,t);return null==a||isNaN(a)?0:a*("asc"===r?-1:1)}}function I(e,t){const s=[];return e?.timeExtent?.start===t.timeExtent?.start&&e?.timeExtent?.end===t.timeExtent?.end||s.push("timeProperties"),s}function v(e){const{timeZone:t}=e?.mesh.properties??{},{timeExtent:s}=e?.expressionProperties??{};return{timeZone:t,timeExtent:s}}function x(e,t){const s=n(e),r=[];for(const i of t.rings){const e=[];for(const t of i)e.push([c(s,t[0]),h(s,t[1])]);r.push(e)}return{rings:r}}export{j as default};