UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 5.58 kB
import{applySome as e,isNone as t,isSome as r,unwrap as i}from"../../../../../../core/maybe.js";import{pt2px as o}from"../../../../../../core/screenUtils.js";import{deltaDecodeGeometry as s,convertFromGeometry as n}from"../../../../../../layers/graphics/featureConversionUtils.js";import{CIMMarkerPlacementHelper as h}from"../../../../../../symbols/cim/placements/CIMMarkerPlacementHelper.js";import{MAGIC_LABEL_LINE_HEIGHT as a}from"../../definitions.js";import{WGLGeometryType as d}from"../../enums.js";import{i8888to32 as x,i1616to32 as c}from"../../number.js";import{MaterialKeyBase as _}from"../../materialKey/MaterialKey.js";import{shapeGlyphs as l}from"./shapingUtils.js";const u=8,g=c(4,4),m=c(4,2),f=c(4,6),y=[m,m,f,f],p=[m,f,m,f],v=[f,f,g,g],w=[g,g,f,f],W=[f,g,f,g],B=[g,f,g,f],b=m=>class extends m{constructor(...e){super(...e),this._isCIM=!1,this._vertexBoundsScale=1,this.geometryType=d.TEXT,this._aux=x(0,0,this._referenceSize,this._bitset)}bindTextInfo(t,r){t&&t.length?this._shapingInfo=e(t,(e=>l(e,r,{scale:this._scale,angle:this._angle,xOffset:this._xOffset,yOffset:this._yOffset,hAlign:this._xAlignD,vAlign:this._yAlignD,maxLineWidth:Math.max(32,Math.min(this._lineWidth,512)),lineHeight:a*Math.max(.25,Math.min(this._lineHeight,4)),decoration:this._decoration,isCIM:this._isCIM,hasBackground:!!this._backgroundColor,borderLineSize:this._borderLineSize}))):this._shapingInfo=null}_write(e,t,r,i){const o=t.getDisplayId();this._writeGeometry(e,t,o,r,i)}_writeGeometry(e,i,o,h,a){const d=this._shapingInfo;if(t(d))return;if(r(this._textPlacement)){const t=a??i.readLegacyGeometryForDisplay();return this._writePlacedText(e,o,t,d,h)}const x=a?s(n(a),2):"esriGeometryPolygon"===i.geometryType?i.readCentroid():i.readGeometryForDisplay();if(!t(x)){if(x.isPoint){const[t,r]=x.coords;if(!e.hasAggregates&&e.hasPixelBufferEnabled&&(t<0||t>=512||r<0||r>=512))return;return this._writeGlyphs(e,o,{x:t,y:r},d)}x.forEachVertex(((t,r)=>this._writeGlyphs(e,o,{x:t,y:r},d)))}}_writePlacedText(e,t,r,s,n){const a=i(this._textPlacement),d=h.getPlacement(r,a,o(1),e.tileKey,n.geometryEngine);if(!d)return;let x=d.next();for(;null!=x;){const r=-x.getAngle();s.setRotation(r);const i=x.tx,o=-x.ty;i<0||i>=512||o<0||o>=512?x=d.next():(this._writeGlyphs(e,t,{x:i,y:o},s),s.setRotation(-r),x=d.next())}}_writeGlyphs(e,t,r,i){const o=_.load(this._materialKey),s=c(Math.round(u*r.x),Math.round(u*r.y)),n=this._vertexBoundsScale,{bounds:h,background:a,glyphs:d}=i;d.length>0&&(this._borderLineColor||this._backgroundColor)&&(o.textureBinding=d[0].textureBinding,e.recordStart(t,o.data,this.geometryType,!0),this._writeBackgroundGeometry(e,t,r,h,a),e.recordEnd());const x=2*Math.max(h.width,h.height);for(const c of i.glyphs)o.textureBinding=c.textureBinding,e.recordStart(t,o.data,this.geometryType,!0),e.vertexBounds(r.x+h.x+this._xOffset,r.y+h.y-this._yOffset,x*n,x*n),this._writeVertices(e,t,s,c),e.recordEnd()}_writeGlyph(e,t,r,i,o){const s=_.load(this._materialKey),n=c(Math.round(u*r),Math.round(u*i));s.textureBinding=o.textureBinding,e.recordStart(t,s.data,this.geometryType,!0);const h=o.bounds,a=this._vertexBoundsScale;e.vertexBounds(r+h.x*a,i+h.y*a,h.width*a,h.height*a),this._writeVertices(e,t,n,o),e.recordEnd()}_writeVertices(e,t,r,i){const o=e.vertexCount();this._writeVertexCommon(e,t,r,i),e.vertexWrite(i.offsets.upperLeft),e.vertexWrite(i.texcoords.upperLeft),e.vertexEnd(),this._writeVertexCommon(e,t,r,i),e.vertexWrite(i.offsets.upperRight),e.vertexWrite(i.texcoords.upperRight),e.vertexEnd(),this._writeVertexCommon(e,t,r,i),e.vertexWrite(i.offsets.lowerLeft),e.vertexWrite(i.texcoords.lowerLeft),e.vertexEnd(),this._writeVertexCommon(e,t,r,i),e.vertexWrite(i.offsets.lowerRight),e.vertexWrite(i.texcoords.lowerRight),e.vertexEnd(),e.indexWrite(o+0),e.indexWrite(o+1),e.indexWrite(o+2),e.indexWrite(o+1),e.indexWrite(o+3),e.indexWrite(o+2)}_writeVertexCommon(e,t,r,i){const o=this._color,s=this._haloColor,n=x(0,0,this._referenceSize,this._bitset),h=x(0,0,this._size,this._haloSize);e.vertexWrite(r),e.vertexWrite(t),e.vertexWrite(o),e.vertexWrite(s),e.vertexWrite(h),e.vertexWrite(n),e.vertexWrite(this._minMaxZoom)}_writeBackgroundVertex(e,t,r,i,o,s){const n=x(0,1,this._referenceSize,this._bitset),h=x(0,0,this._size,this._haloSize),a=x(0,0,0,0);e.vertexWrite(r),e.vertexWrite(t),e.vertexWrite(i),e.vertexWrite(a),e.vertexWrite(h),e.vertexWrite(n),e.vertexWrite(this._minMaxZoom),e.vertexWrite(o),e.vertexWrite(s),e.vertexEnd()}_writeBackgroundQuad(e,t,r,i,o,s){const n=e.vertexCount();this._writeBackgroundVertex(e,t,r,i,o.upperLeft,s[0]),this._writeBackgroundVertex(e,t,r,i,o.upperRight,s[1]),this._writeBackgroundVertex(e,t,r,i,o.lowerLeft,s[2]),this._writeBackgroundVertex(e,t,r,i,o.lowerRight,s[3]),e.indexWrite(n+0),e.indexWrite(n+1),e.indexWrite(n+2),e.indexWrite(n+1),e.indexWrite(n+3),e.indexWrite(n+2)}_writeBackgroundGeometry(e,t,r,i,o){const s=c(Math.round(u*r.x),Math.round(u*r.y)),{x:n,y:h,width:a,height:d}=i,x=2*Math.max(a,d);if(e.vertexBounds(r.x+n+this._xOffset,r.y+h-this._yOffset,x*this._vertexBoundsScale,x*this._vertexBoundsScale),this._backgroundColor){const r=[g,g,g,g];this._writeBackgroundQuad(e,t,s,this._backgroundColor,o.main,r)}if(this._borderLineColor||this._backgroundColor){const r=!!this._borderLineColor&&!!this._borderLineSize&&this._borderLineSize>0,[i,n,h,a,d]=r?[y,y,p,p,this._borderLineColor]:[v,w,W,B,this._backgroundColor];this._writeBackgroundQuad(e,t,s,d,o.top,i),this._writeBackgroundQuad(e,t,s,d,o.bot,n),this._writeBackgroundQuad(e,t,s,d,o.left,h),this._writeBackgroundQuad(e,t,s,d,o.right,a)}}};export{b as default};