@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 7.56 kB
JavaScript
import{_ as e}from"../../../../../chunks/tslib.es6.js";import{bidiText as t}from"../../../../../core/BidiText.js";import"../../../../../core/Error.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import{applySome as s,isNone as r,isSome as i,unwrapOrThrow as a,unwrap as o}from"../../../../../core/maybe.js";import{throwIfAborted as n,isAbortError as l}from"../../../../../core/promiseUtils.js";import"../../../../../core/accessorSupport/ensureType.js";import"../../../../../core/arrayUtils.js";import{subclass as c}from"../../../../../core/accessorSupport/decorators/subclass.js";import{diff as d,hasDiff as h}from"../../../../../core/accessorSupport/diffUtils.js";import f from"../../../../../geometry/SpatialReference.js";import{isAggregateId as m}from"../../../engine/webgl/DisplayId.js";import{WGLSymbologyType as u}from"../../../engine/webgl/enums.js";import{MeshData as g}from"../../../engine/webgl/mesh/MeshData.js";import{WGLMeshFactory as p}from"../../../engine/webgl/mesh/factories/WGLMeshFactory.js";import{WGLTemplateStore as y}from"../../../engine/webgl/mesh/templates/WGLTemplateStore.js";import{createMatcher as _}from"../../../engine/webgl/util/Matcher.js";import{codepoints as b}from"../textUtils.js";import S from"./BaseProcessor.js";import w from"../support/ResourceManagerProxy.js";function I(e,t){return(!e.minScale||e.minScale>=t)&&(!e.maxScale||e.maxScale<=t)}function v(e){const t=e.message,r={message:{data:{},tileKey:t.tileKey,tileKeyOrigin:t.tileKeyOrigin,version:t.version},transferList:new Array};for(const a in t.data){const e=t.data[a];if(r.message.data[a]=null,i(e)){const t=e.stride,i=e.indices.slice(0),o=e.vertices.slice(0),n=e.records.slice(0),l={stride:t,indices:i,vertices:o,records:n,metrics:s(e.metrics,(e=>e.slice(0)))};r.transferList.push(i,o,n),r.message.data[a]=l}}return r}let M=class extends S{constructor(){super(...arguments),this.type="symbol",this._matchers={feature:null,aggregate:null},this._bufferData=new Map,this._bufferIds=new Map}initialize(){this.handles.add([this.tileStore.on("update",this.onTileUpdate.bind(this))]),this._resourceManagerProxy=new w(this.remoteClient)}destroy(){this._resourceManagerProxy.destroy()}get supportsTileUpdates(){return!0}forEachBufferId(e){this._bufferIds.forEach((t=>{t.forEach(e)}))}async update(e,t){const s=t.schema.processors[0];if("symbol"!==s.type)return;const r=d(this._schema,s);(h(r,"mesh")||h(r,"target"))&&(e.mesh=!0,e.why?.mesh.push("Symbology changed"),this._schema=s,this._factory=this._createFactory(s),this._factory.update(s,this.tileStore.tileScheme.tileInfo))}onTileMessage(e,t,s,r){return n(r),this._onTileData(e,t,s,r)}onTileClear(e){const t={clear:!0};return this._bufferData.delete(e.key.id),this._bufferIds.delete(e.key.id),this.remoteClient.invoke("tileRenderer.onTileData",{tileKey:e.id,data:t})}onTileError(e,t,s){const r=s.signal,i={tileKey:e.id,error:t};return this.remoteClient.invoke("tileRenderer.onTileError",i,{signal:r})}onTileUpdate(e){for(const t of e.removed)this._bufferData.has(t.key.id)&&this._bufferData.delete(t.key.id),this._bufferIds.has(t.key.id)&&this._bufferIds.delete(t.key.id);for(const t of e.added)this._bufferData.forEach((e=>{for(const s of e)s.message.tileKey===t.id&&this._updateTileMesh("append",t,v(s),[],!1,!1,null)}))}_addBufferData(e,t){this._bufferData.has(e)||this._bufferData.set(e,[]),this._bufferData.get(e)?.push(v(t))}_createFactory(e){const{geometryType:t,objectIdField:r,fields:i}=this.service,a=(e,t)=>this.remoteClient.invoke("tileRenderer.getMaterialItems",e,t),o={geometryType:t,fields:i,spatialReference:f.fromJSON(this.spatialReference)},n=new y(a,this.tileStore.tileScheme.tileInfo),{matcher:l,aggregateMatcher:c}=e.mesh;return this._store=n,this._matchers.feature=_(l,n,o,this._resourceManagerProxy),this._matchers.aggregate=s(c,(e=>_(e,n,o,this._resourceManagerProxy))),new p(t,r,n)}async _onTileData(e,t,s,a){n(a);const{type:o,addOrUpdate:l,remove:c,clear:d,end:h}=t,f=!!this._schema.mesh.sortKey;if(!l){const t={type:o,addOrUpdate:null,remove:c,clear:d,end:h,sort:f};return this.remoteClient.invoke("tileRenderer.onTileData",{tileKey:e.id,data:t},a)}const m=this._processFeatures(e,l,s,a,t.status?.version);try{const s=await m;if(r(s)){const t={type:o,addOrUpdate:null,remove:c,clear:d,end:h,sort:f};return this.remoteClient.invoke("tileRenderer.onTileData",{tileKey:e.id,data:t},a)}const n=[];for(const t of s){let s=!1;const r=t.message.bufferIds,a=e.key.id,o=t.message.tileKey;if(a!==o&&i(r)){if(!this.tileStore.get(o)){this._addBufferData(a,t),n.push(t);continue}let e=this._bufferIds.get(o);e||(e=new Set,this._bufferIds.set(o,e));const i=Array.from(r);for(const t of i){if(e.has(t)){s=!0;break}e.add(t)}}s||(this._addBufferData(a,t),n.push(t))}await Promise.all(n.map((s=>{const r=e.key.id===s.message.tileKey,i=r?t.remove:[],n=r&&t.end;return this._updateTileMesh(o,e,s,i,n,!!t.clear,a.signal)})))}catch(u){this._handleError(e,u,a)}}async _updateTileMesh(e,t,r,i,a,l,c){const d=e,h=r.message.tileKey,f=!!this._schema.mesh.sortKey;h!==t.key.id&&(a=!1);const m=s(r,(e=>e.message)),u=s(r,(e=>e.transferList))||[],g={type:d,addOrUpdate:m,remove:i,clear:l,end:a,sort:f},p={transferList:o(u)||[],signal:c};return n(p),this.remoteClient.invoke("tileRenderer.onTileData",{tileKey:h,data:g},p)}async _processFeatures(e,t,s,i,a){if(r(t)||!t.hasFeatures)return null;const o={transform:e.transform,hasZ:!1,hasM:!1},l=this._factory,c={viewingMode:"",scale:e.scale},d=await this._matchers.feature,h=await this._matchers.aggregate;n(i);const f=this._getLabelInfos(e,t);return await l.analyze(t.getCursor(),this._resourceManagerProxy,d,h,o,c),n(i),this._writeFeatureSet(e,t,o,f,l,s,a)}_writeFeatureSet(e,t,s,r,a,o,n){const l=t.getSize(),c=this._schema.mesh.matcher.symbologyType,d=new g(e.key.id,{features:l,records:l,metrics:0},c,o,c!==u.HEATMAP,n),h={viewingMode:"",scale:e.scale},f=t.getCursor();for(;f.next();)try{const t=f.getDisplayId(),o=i(r)?r.get(t):null;a.writeCursor(d,f,s,h,e.level,o,this._resourceManagerProxy)}catch(p){}const m=e.tileInfoView.tileInfo.isWrappable;return d.serialize(m)}_handleError(e,t,s){if(!l(t)){const r={tileKey:e.id,error:t.message};return this.remoteClient.invoke("tileRenderer.onTileError",r,{signal:s.signal})}return Promise.resolve()}_getLabelingSchemaForScale(e){const t=this._schema.mesh.labels;if(r(t))return null;if("subtype"===t.type){const s={type:"subtype",classes:{}};let r=!1;for(const i in t.classes){const a=t.classes[i].filter((t=>I(t,e.scale)));r=r||!!a.length,s.classes[i]=a}return r?s:null}const s=t.classes.filter((t=>I(t,e.scale)));return s.length?{type:"simple",classes:s}:null}_getLabels(e,t){if("subtype"===t.type){const s=this.service.subtypeField,r=a(s,"Expected to find subtype Field"),i=e.readAttribute(r);return null==i?[]:t.classes[i]??[]}return t.classes}_getLabelInfos(e,s){const i=this._getLabelingSchemaForScale(e);if(r(i))return null;const a=new Map,o=s.getCursor();for(;o.next();){const e=o.getDisplayId(),s=[],r=m(e),n=r&&1!==o.readAttribute("cluster_count")?"aggregate":"feature",l=this._getLabels(o,i);for(const i of l){if(i.target!==n)continue;const a=o.getStorage(),l=r&&"feature"===n?a.getComputedStringAtIndex(o.readAttribute("referenceId"),i.fieldIndex):a.getComputedStringAtIndex(e,i.fieldIndex);if(!l)continue;const c=t(l.toString()),d=c[0],h=c[1];this._store.getMosaicItem(i.symbol,b(d)).then((e=>{s[i.index]={glyphs:e.glyphMosaicItems??[],rtl:h,index:i.index}}))}a.set(e,s)}return a}};M=e([c("esri.views.2d.layers.features.processors.SymbolProcessor")],M);const T=M;export{T as default};