@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 3.9 kB
JavaScript
import{a as e}from"../../../../../chunks/mat3f32.js";import{COLLISION_GRID_CELL_SIZE as t}from"./config.js";import{GridIndex as n}from"./util.js";import{SymbolPlacement as o,RotationAlignment as r,TranslateAnchor as s}from"../style/StyleDefinition.js";function i(e,t,n,o,i,l){const{iconRotationAlignment:a,textRotationAlignment:c,iconTranslate:h,iconTranslateAnchor:u,textTranslate:d,textTranslateAnchor:y}=o;let x=0;for(const g of e.colliders){const[e,o]=0===g.partIndex?h:d,m=0===g.partIndex?u:y,f=g.minLod<=l&&l<=g.maxLod;x+=f?0:1,g.enabled=f,g.xScreen=g.xTile*i[0]+g.yTile*i[3]+i[6],g.yScreen=g.xTile*i[1]+g.yTile*i[4]+i[7],m===s.MAP?(g.xScreen+=n*e-t*o,g.yScreen+=t*e+n*o):(g.xScreen+=e,g.yScreen+=o),r.VIEWPORT===(0===g.partIndex?a:c)?(g.dxScreen=g.dxPixels,g.dyScreen=g.dyPixels):(g.dxScreen=n*(g.dxPixels+g.width/2)-t*(g.dyPixels+g.height/2)-g.width/2,g.dyScreen=t*(g.dxPixels+g.width/2)+n*(g.dyPixels+g.height/2)-g.height/2)}e.colliders.length>0&&x===e.colliders.length&&(e.unique.show=!1)}class l{constructor(o,r,s,i,l,a){this._symbols=o,this._styleRepository=i,this._zoom=l,this._currentLayerCursor=0,this._currentSymbolCursor=0,this._styleProps=new Map,this._allNeededMatrices=new Map,this._gridIndex=new n(r,s,t),this._si=Math.sin(Math.PI*a/180),this._co=Math.cos(Math.PI*a/180);for(const t of o)for(const n of t.symbols)this._allNeededMatrices.has(n.tile)||this._allNeededMatrices.set(n.tile,e(n.tile.transforms.tileUnitsToPixels))}work(e){const t=this._gridIndex;function n(e){const n=e.xScreen+e.dxScreen,o=e.yScreen+e.dyScreen,r=n+e.width,s=o+e.height,[i,l,a,c]=t.getCellSpan(n,o,r,s);for(let h=l;h<=c;h++)for(let e=i;e<=a;e++){const i=t.cells[h][e];for(const e of i){const t=e.xScreen+e.dxScreen,i=e.yScreen+e.dyScreen,l=t+e.width,a=i+e.height;if(!(r<t||n>l||s<i||o>a))return!0}}return!1}const o=performance.now();for(;this._currentLayerCursor<this._symbols.length;this._currentLayerCursor++,this._currentSymbolCursor=0){const t=this._symbols[this._currentLayerCursor],r=this._getProperties(t.styleLayerUID);for(;this._currentSymbolCursor<t.symbols.length;this._currentSymbolCursor++){if(this._currentSymbolCursor%100==99&&performance.now()-o>e)return!1;const s=t.symbols[this._currentSymbolCursor];if(!s.unique.show)continue;i(s,this._si,this._co,r,this._allNeededMatrices.get(s.tile),this._zoom);const l=s.unique;if(!l.show)continue;const{iconAllowOverlap:a,iconIgnorePlacement:c,textAllowOverlap:h,textIgnorePlacement:u}=r;for(const e of s.colliders){if(!e.enabled)continue;const t=l.parts[e.partIndex];if(!t.show)continue;!(e.partIndex?h:a)&&n(e)&&(e.hard?l.show=!1:t.show=!1)}if(l.show)for(const e of s.colliders){if(!e.enabled)continue;if(e.partIndex?u:c)continue;if(!l.parts[e.partIndex].show)continue;const t=e.xScreen+e.dxScreen,n=e.yScreen+e.dyScreen,o=t+e.width,r=n+e.height,[s,i,a,h]=this._gridIndex.getCellSpan(t,n,o,r);for(let l=i;l<=h;l++)for(let t=s;t<=a;t++){this._gridIndex.cells[l][t].push(e)}}}}return!0}_getProperties(e){const t=this._styleProps.get(e);if(t)return t;const n=this._zoom,s=this._styleRepository.getStyleLayerByUID(e),i=s.getLayoutValue("symbol-placement",n)!==o.POINT;let l=s.getLayoutValue("icon-rotation-alignment",n);l===r.AUTO&&(l=i?r.MAP:r.VIEWPORT);let a=s.getLayoutValue("text-rotation-alignment",n);a===r.AUTO&&(a=i?r.MAP:r.VIEWPORT);const c=s.getPaintValue("icon-translate",n),h=s.getPaintValue("icon-translate-anchor",n),u=s.getPaintValue("text-translate",n),d=s.getPaintValue("text-translate-anchor",n),y={iconAllowOverlap:s.getLayoutValue("icon-allow-overlap",n),iconIgnorePlacement:s.getLayoutValue("icon-ignore-placement",n),textAllowOverlap:s.getLayoutValue("text-allow-overlap",n),textIgnorePlacement:s.getLayoutValue("text-ignore-placement",n),iconRotationAlignment:l,textRotationAlignment:a,iconTranslateAnchor:h,iconTranslate:c,textTranslateAnchor:d,textTranslate:u};return this._styleProps.set(e,y),y}}export{l as CollisionJob};