12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{nextPowerOfTwo as e}from"../../core/mathUtils.js";import{slsDashToTemplateArray as t,CIMSymbolHelper as r}from"./CIMSymbolHelper.js";import{rasterizeSimpleFill as a,rasterizeDash as i}from"./rasterizingUtils.js";import n from"./Rect.js";import{getSDFInfo as s,buildSDF as o}from"./SDFHelper.js";import{resampleHermite as m}from"./utils.js";const l=512;class c{constructor(e){this._resourceManager=e}dispose(){this._rasterizationCanvas=null}rasterizeJSONResource(m,l,c){if(this._rasterizationCanvas||(this._rasterizationCanvas=document.createElement("canvas")),"simple-fill"===m.type||"esriSFS"===m.type){const[t,r,i]=a(this._rasterizationCanvas,m.style,l);return{size:[r,i],image:new Uint32Array(t.buffer),sdf:!1,simplePattern:!0,anchorX:0,anchorY:0,rasterizationScale:e(Math.ceil(l))}}if("simple-line"===m.type||"esriSLS"===m.type||"line"===m.type&&m.dashTemplate){let e,r;if("simple-line"===m.type||"esriSLS"===m.type)switch(e=t(m.style,m.cap),m.cap){case"butt":r="Butt";break;case"square":r="Square";break;default:r="Round"}else e=m.dashTemplate,r=m.cim.capStyle;const[a,n,s]=i(e,r);return{size:[n,s],image:new Uint32Array(a.buffer),sdf:!0,simplePattern:!0,anchorX:0,anchorY:0}}let f,h,p,u=1;if("simple-marker"===m.type||"esriSMS"===m.type||"line-marker"===m.type?(f=r.fromSimpleMarker(m),p=s(f)):m.cim&&"CIMHatchFill"===m.cim.type?(f=r.fromCIMHatchFill(m.cim,l),h=new n(f.frame.xmin,-f.frame.ymax,f.frame.xmax-f.frame.xmin,f.frame.ymax-f.frame.ymin),u=l):m.cim.markerPlacement&&"CIMMarkerPlacementInsidePolygon"===m.cim.markerPlacement.type?(f=r.fromCIMInsidePolygon(m.cim),h=new n(f.frame.xmin,-f.frame.ymax,f.frame.xmax-f.frame.xmin,f.frame.ymax-f.frame.ymin)):(f=m.cim,p=s(f)),p&&!c){const[e,t,r]=o(p);return e?{size:[t,r],image:new Uint32Array(e.buffer),sdf:!0,simplePattern:!0,anchorX:0,anchorY:0,rasterizationScale:u}:null}const[y,d,g,C,z]=r.rasterize(this._rasterizationCanvas,f,h,this._resourceManager,!c);return y?{size:[d,g],image:new Uint32Array(y.buffer),sdf:!1,simplePattern:!1,anchorX:C,anchorY:z}:null}rasterizeImageResource(e,t,r,a){this._rasterizationCanvas||(this._rasterizationCanvas=document.createElement("canvas")),this._rasterizationCanvas.width=e,this._rasterizationCanvas.height=t;const i=this._rasterizationCanvas.getContext("2d");r instanceof ImageData?i.putImageData(r,0,0):(r.setAttribute("width",`${e}px`),r.setAttribute("height",`${t}px`),i.drawImage(r,0,0,e,t));const n=i.getImageData(0,0,e,t),s=new Uint8Array(n.data);if(a)for(const m of a)if(m&&m.oldColor&&4===m.oldColor.length&&m.newColor&&4===m.newColor.length){const[e,t,r,a]=m.oldColor,[i,n,o,l]=m.newColor;if(e===i&&t===n&&r===o&&a===l)continue;for(let m=0;m<s.length;m+=4)e===s[m]&&t===s[m+1]&&r===s[m+2]&&a===s[m+3]&&(s[m]=i,s[m+1]=n,s[m+2]=o,s[m+3]=l)}let o;for(let m=0;m<s.length;m+=4)o=s[m+3]/255,s[m]=s[m]*o,s[m+1]=s[m+1]*o,s[m+2]=s[m+2]*o;let c=s,f=e,h=t;const p=l;if(f>=p||h>=p){const r=f/h;r>1?(f=p,h=Math.round(p/r)):(h=p,f=Math.round(p*r)),c=new Uint8Array(4*f*h);const a=new Uint8ClampedArray(c.buffer);m(s,e,t,a,f,h,!1)}return{size:[f,h],image:new Uint32Array(c.buffer),sdf:!1,simplePattern:!1,anchorX:0,anchorY:0}}}export{c as default};
|