qa-prevention-gwj-vue/static/map/cesium91/CesiumUnminified/Workers/TerrainWorker.js

2 lines
5.5 KiB
JavaScript

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<<e},w.prototype.getNumberOfYTilesAtLevel=function(e){return this._numberOfLevelZeroTilesY<<e},w.prototype.rectangleToNativeRectangle=function(e,t){const r=this._projection,o=r.project(i.Rectangle.southwest(e)),s=r.project(i.Rectangle.northeast(e));return n.defined(t)?(t.west=o.x,t.south=o.y,t.east=s.x,t.north=s.y,t):new i.Rectangle(o.x,o.y,s.x,s.y)},w.prototype.tileXYToNativeRectangle=function(e,t,r,o){const s=this.getNumberOfXTilesAtLevel(r),l=this.getNumberOfYTilesAtLevel(r),a=(this._rectangleNortheastInMeters.x-this._rectangleSouthwestInMeters.x)/s,c=this._rectangleSouthwestInMeters.x+e*a,u=this._rectangleSouthwestInMeters.x+(e+1)*a,h=(this._rectangleNortheastInMeters.y-this._rectangleSouthwestInMeters.y)/l,f=this._rectangleNortheastInMeters.y-t*h,g=this._rectangleNortheastInMeters.y-(t+1)*h;return n.defined(o)?(o.west=c,o.south=g,o.east=u,o.north=f,o):new i.Rectangle(c,g,u,f)},w.prototype.tileXYToRectangle=function(e,t,n,i){const o=this.tileXYToNativeRectangle(e,t,n,i),s=this._projection,l=s.unproject(new r.Cartesian2(o.west,o.south)),a=s.unproject(new r.Cartesian2(o.east,o.north));return o.west=l.longitude,o.south=l.latitude,o.east=a.longitude,o.north=a.latitude,o},w.prototype.positionToTileXY=function(e,t,o){const s=this._rectangle;if(!i.Rectangle.contains(s,e))return;const l=this.getNumberOfXTilesAtLevel(t),a=this.getNumberOfYTilesAtLevel(t),c=(this._rectangleNortheastInMeters.x-this._rectangleSouthwestInMeters.x)/l,u=(this._rectangleNortheastInMeters.y-this._rectangleSouthwestInMeters.y)/a,h=this._projection.project(e);let f=(h.x-this._rectangleSouthwestInMeters.x)/c|0;f>=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;t<n;t++)for(let i=0;i<n;i++){const o=4*(t*n+i);r[t*n+i]=R(e[o],e[o+1],e[o+2])}return r}(new Uint8Array(o),i.width);t.xyz.z==S&&T.set(t.xyzStr,s);let c=j(s,i.width,n);a.updateElevation(v[m],m,t.xyzStr,s).promise.then((function(t){e.resolve(c)}),(function(t){e.resolve(c)}))}.bind(this,r)):r.reject(null)}function j(e,t,r){let n=Math.floor(t/(z-1)),i=new Int16Array(z*z),o=1e4,s=-2e4;for(let r=0;r<z;r++){let l=r*n*t;r==z-1&&(l=t*t-t);let a=l+t-1;for(let t=0;t<z;t++){let c=t*n+l;t==z-1&&(c=a),i[t+r*z]=e[c],o>e[c]&&(o=e[c]),s<e[c]&&(s=e[c])}}return r.push(i.buffer),{sData:i,_minimumHeight:o,_maximumHeight:s}}function R(e,t,r){return Math.round((256*e*256+256*t+r)/10-1e4)}return h((function(e,r){if(1==e.init)return function(e){return z=e.w,m=e.indexDbName,I=e.tileSize,M="GeographicTilingScheme"==e.tilingSchemeName?new t.GeographicTilingScheme({tileSize:I}):new w({tileSize:I}),S=e.maxLevel,a.getDBMap([m],v)}(e);let n=s.when.defer();return e.xyzStr=e.xyz.x+"_"+e.xyz.y+"_"+e.xyz.z,a.getElevation(v,[m],e.xyzStr).promise.then((function(t){for(let e in t){let i=t[e];if(i){let e=j(i.data,I,r);return void n.resolve(e)}}if(e.xyz.z>S)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}))}));