You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
9 lines
2.7 KiB
9 lines
2.7 KiB
// All material copyright Esri, All Rights Reserved, unless otherwise specified. |
|
// See https://js.arcgis.com/4.30/esri/copyright.txt for details. |
|
//>>built |
|
define(["../../request","../../core/Error","../../core/Logger","../../core/typedArrayUtil","../../core/urlUtils"],function(h,g,n,k,l){function m(a){var b=document.createElement("canvas");const e=b.getContext("2d");b.width=a.width;b.height=a.height;e.drawImage(a,0,0,a.width,a.height);b=e.getImageData(0,0,a.width,a.height);return{width:a.width,height:a.height,data:new Uint8Array(b.data)}}class p{constructor(a,b){this._spriteSource=a;this._maxTextureSize=b;this.devicePixelRatio=1;this._spriteImageFormat= |
|
"png";this._isRetina=!1;this._spritesData={};this.height=this.width=this.image=null;this.loadStatus="not-loaded";"url"===a.type&&a.spriteFormat&&(this._spriteImageFormat=a.spriteFormat);a.pixelRatio&&(this.devicePixelRatio=a.pixelRatio);this.baseURL=a.spriteUrl}get spriteNames(){const a=[];for(const b in this._spritesData)a.push(b);a.sort();return a}getSpriteInfo(a){return this._spritesData?this._spritesData[a]:null}async load(a){if(this.baseURL){this.loadStatus="loading";try{await this._loadSprites(a), |
|
this.loadStatus="loaded"}catch{this.loadStatus="failed"}}else this.loadStatus="failed"}async _loadSprites(a){this._isRetina=1.15<this.devicePixelRatio;const {width:b,height:e,data:c,json:f}=await this._getSpriteData(this._spriteSource,a);if((a=Object.keys(f))&&0!==a.length&&c){this._spritesData=f;this.width=b;this.height=e;a=Math.max(this._maxTextureSize,4096);if(b>a||e>a)throw a=`Sprite resource for style ${this.baseURL} is bigger than the maximum allowed of ${a} pixels}`,n.getLogger("esri.layers.support.SpriteSource").error(a), |
|
new g("SpriteSource",a);for(let d=0;d<c.length;d+=4)a=c[d+3]/255,c[d]*=a,c[d+1]*=a,c[d+2]*=a;this.image=c}else this._spritesData=this.image=null,this.width=this.height=0}async _getSpriteData(a,b){if("image"===a.type){if(1.15>this.devicePixelRatio){if(!a.spriteSource1x)throw new g("SpriteSource","no image data provided for low resolution sprites!");b=a.spriteSource1x.image;a=a.spriteSource1x.json}else{if(!a.spriteSource2x)throw new g("SpriteSource","no image data provided for high resolution sprites!"); |
|
b=a.spriteSource2x.image;a=a.spriteSource2x.json}return"width"in b&&"height"in b&&"data"in b&&(k.isArrayBuffer(b.data)||k.isUint8ClampedArray(b.data))?{width:b.width,height:b.height,data:new Uint8Array(b.data),json:a}:{...m(b),json:a}}a=l.urlToObject(this.baseURL);const e=a.query?"?"+l.objectToQuery(a.query):"",c=this._isRetina?"@2x":"",f=`${a.path}${c}.${this._spriteImageFormat}${e}`,[d,q]=await Promise.all([h(`${a.path}${c}.json${e}`,b),h(f,{responseType:"image",...b})]);return{...m(q.data),json:d.data}}} |
|
return p}); |