define(["./Resource-8ae1a924","./GeographicTilingScheme-86cef90e","./Cartesian2-bd414876","./defaultValue-81eec7ed","./Rectangle-cf3e0e3e","./WebMercatorProjection-44373a3d","./when-422ea0ae","./UPNG","./ElevationTool","./TerrainUpsample","./Cache","./createTaskProcessorWorker","./Check-741c5f3c","./combine-3c023bda","./Math-e73894ab","./RuntimeError-26acdd3b","./GeographicProjection-c931c7fb","./Cartesian3-e0307675","./LinkedQueue"],(function(e,t,r,n,i,o,s,l,a,c,u,h,f,g,p,d,y,_,x){"use strict";function w(e){if(e=n.defaultValue(e,n.defaultValue.EMPTY_OBJECT),this._ellipsoid=n.defaultValue(e.ellipsoid,r.Ellipsoid.WGS84),this._numberOfLevelZeroTilesX=n.defaultValue(e.numberOfLevelZeroTilesX,1),this._numberOfLevelZeroTilesY=n.defaultValue(e.numberOfLevelZeroTilesY,1),this._projection=new o.WebMercatorProjection(this._ellipsoid),n.defined(e.rectangleSouthwestInMeters)&&n.defined(e.rectangleNortheastInMeters))this._rectangleSouthwestInMeters=e.rectangleSouthwestInMeters,this._rectangleNortheastInMeters=e.rectangleNortheastInMeters;else{const e=this._ellipsoid.maximumRadius*Math.PI;this._rectangleSouthwestInMeters=new r.Cartesian2(-e,-e),this._rectangleNortheastInMeters=new r.Cartesian2(e,e)}const t=this._projection.unproject(this._rectangleSouthwestInMeters),s=this._projection.unproject(this._rectangleNortheastInMeters);this._rectangle=new i.Rectangle(t.longitude,t.latitude,s.longitude,s.latitude)}Object.defineProperties(w.prototype,{ellipsoid:{get:function(){return this._ellipsoid}},rectangle:{get:function(){return this._rectangle}},projection:{get:function(){return this._projection}}}),w.prototype.getNumberOfXTilesAtLevel=function(e){return this._numberOfLevelZeroTilesX<=l&&(f=l-1);let g=(this._rectangleNortheastInMeters.y-h.y)/u|0;return g>=a&&(g=a-1),n.defined(o)?(o.x=f,o.y=g,o):new r.Cartesian2(f,g)};let m,M,z=65,v={},S=16,I=512,T=new u(100),b={};function N(t,r,n){var i=t.url,o=new e.Resource({url:i});o.request.throttle=!1,o.request.throttleByServer=!0,o.request.type=1;var s=o.fetchArrayBuffer();s?s.then(function(e,r){let i=l.decode(r),o=l.toRGBA8(i)[0],s=function(e,t){let r=new Int16Array(t*t);const n=t;for(let t=0;te[c]&&(o=e[c]),sS)return function(e,t,r,n){let i=Math.pow(2,e.xyz.z-t),o={x:Math.floor(e.xyz.x/i),y:Math.floor(e.xyz.y/i),z:t},l=e.xyz,u=o.x+"_"+o.y+"_"+o.z,h=T.get(u);if(h){let t=c.upsample(M,h,I,I,o,l),i=j(t,I,n);a.updateElevation(v[m],m,e.xyzStr,t).promise.always((function(e){r.resolve(i)}))}else{let t=e.resourceUrl;if(t=t.replace("{x}",o.x),t=t.replace("{y}",o.y),t=t.replace("{z}",o.z),e.url=t,e.xyz=o,e.xyzStr=e.xyz.x+"_"+e.xyz.y+"_"+e.xyz.z,b[t])r.reject(null);else{let i=s.when.defer();N(e,i,n),b[t]=!0,i.promise.then((function(){let i=T.get(e.xyzStr),s=c.upsample(M,i,I,I,o,l),u=j(s,I,n),h=l.x+"_"+l.y+"_"+l.z;a.updateElevation(v[m],m,h,s).promise.always((function(e){delete b[t],r.resolve(u)}))}),(function(){delete b[t],r.reject(null)}))}}}(e,S,n,r),n.promise;N(e,n,r)})),n.promise}))}));