mapbox-gl-shadow-simulator 0.52.0 → 0.54.0-unity
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mapbox-gl-shadow-simulator.esm.js +2 -2
- package/dist/mapbox-gl-shadow-simulator.umd.min.js +2 -2
- package/dist/shademap/leaflet-shademap/dist/ShadeMap.d.ts +4 -3
- package/dist/shademap/leaflet-shademap/dist/ShadeMapMapbox.d.ts +3 -0
- package/dist/shademap/leaflet-shademap/dist/buildings/BuildingRasterizer.d.ts +4 -1
- package/dist/shademap/leaflet-shademap/dist/lib/heightMap.d.ts +1 -1
- package/dist/shademap/leaflet-shademap/dist/lib/webgl.d.ts +1 -0
- package/dist/shademap/leaflet-shademap/dist/shader/kernel.d.ts +2 -0
- package/dist/shademap/leaflet-shademap/dist/types/shadow3DData.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright Ted Piotrowski 2024
|
|
3
3
|
* Package: mapbox-gl-shadow-simulator
|
|
4
|
-
* Version: 0.
|
|
4
|
+
* Version: 0.54.0-unity
|
|
5
5
|
* For licensing visit: https://shademap.app/about/
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
function t(t,e,r){var i=e[1],o=e[0],n=i-o;return t===i&&r?t:((t-o)%n+n)%n+o}function e(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}var r=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function i(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var o=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function n(t,e,o){return t instanceof i?t:r(t)?new i(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new i(t.x,t.y):new i(t,e,o)}function s(t,e){if(t)for(var r=e?[t,e]:t,i=0,o=r.length;i<o;i++)this.extend(r[i])}function a(t,e){return!t||t instanceof s?t:new s(t,e)}function u(t,e){if(t)for(var r=e?[t,e]:t,i=0,o=r.length;i<o;i++)this.extend(r[i])}function h(t,e){return t instanceof u?t:new u(t,e)}i.prototype={clone:function(){return new i(this.x,this.y)},add:function(t){return this.clone()._add(n(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(n(t))},_subtract:function(t){return this.x-=t.x,this.y-=t.y,this},divideBy:function(t){return this.clone()._divideBy(t)},_divideBy:function(t){return this.x/=t,this.y/=t,this},multiplyBy:function(t){return this.clone()._multiplyBy(t)},_multiplyBy:function(t){return this.x*=t,this.y*=t,this},scaleBy:function(t){return new i(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new i(this.x/t.x,this.y/t.y)},round:function(){return this.clone()._round()},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},floor:function(){return this.clone()._floor()},_floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.clone()._ceil()},_ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},trunc:function(){return this.clone()._trunc()},_trunc:function(){return this.x=o(this.x),this.y=o(this.y),this},distanceTo:function(t){var e=(t=n(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=n(t)).x===this.x&&t.y===this.y},contains:function(t){return t=n(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+e(this.x)+", "+e(this.y)+")"}},s.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof i||"number"==typeof t[0]||"x"in t)e=r=n(t);else if(e=(t=a(t)).min,r=t.max,!e||!r)return this;return this.min||this.max?(this.min.x=Math.min(e.x,this.min.x),this.max.x=Math.max(r.x,this.max.x),this.min.y=Math.min(e.y,this.min.y),this.max.y=Math.max(r.y,this.max.y)):(this.min=e.clone(),this.max=r.clone()),this},getCenter:function(t){return n((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return n(this.min.x,this.max.y)},getTopRight:function(){return n(this.max.x,this.min.y)},getTopLeft:function(){return this.min},getBottomRight:function(){return this.max},getSize:function(){return this.max.subtract(this.min)},contains:function(t){var e,r;return(t="number"==typeof t[0]||t instanceof i?n(t):a(t))instanceof s?(e=t.min,r=t.max):e=r=t,e.x>=this.min.x&&r.x<=this.max.x&&e.y>=this.min.y&&r.y<=this.max.y},intersects:function(t){t=a(t);var e=this.min,r=this.max,i=t.min,o=t.max,n=o.x>=e.x&&i.x<=r.x,s=o.y>=e.y&&i.y<=r.y;return n&&s},overlaps:function(t){t=a(t);var e=this.min,r=this.max,i=t.min,o=t.max,n=o.x>e.x&&i.x<r.x,s=o.y>e.y&&i.y<r.y;return n&&s},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,i=Math.abs(e.x-r.x)*t,o=Math.abs(e.y-r.y)*t;return a(n(e.x-i,e.y-o),n(r.x+i,r.y+o))},equals:function(t){return!!t&&(t=a(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},u.prototype={extend:function(t){var e,r,i=this._southWest,o=this._northEast;if(t instanceof c)e=t,r=t;else{if(!(t instanceof u))return t?this.extend(f(t)||h(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return i||o?(i.lat=Math.min(e.lat,i.lat),i.lng=Math.min(e.lng,i.lng),o.lat=Math.max(r.lat,o.lat),o.lng=Math.max(r.lng,o.lng)):(this._southWest=new c(e.lat,e.lng),this._northEast=new c(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,i=Math.abs(e.lat-r.lat)*t,o=Math.abs(e.lng-r.lng)*t;return new u(new c(e.lat-i,e.lng-o),new c(r.lat+i,r.lng+o))},getCenter:function(){return new c((this._southWest.lat+this._northEast.lat)/2,(this._southWest.lng+this._northEast.lng)/2)},getSouthWest:function(){return this._southWest},getNorthEast:function(){return this._northEast},getNorthWest:function(){return new c(this.getNorth(),this.getWest())},getSouthEast:function(){return new c(this.getSouth(),this.getEast())},getWest:function(){return this._southWest.lng},getSouth:function(){return this._southWest.lat},getEast:function(){return this._northEast.lng},getNorth:function(){return this._northEast.lat},contains:function(t){t="number"==typeof t[0]||t instanceof c||"lat"in t?f(t):h(t);var e,r,i=this._southWest,o=this._northEast;return t instanceof u?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=i.lat&&r.lat<=o.lat&&e.lng>=i.lng&&r.lng<=o.lng},intersects:function(t){t=h(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),o=t.getNorthEast(),n=o.lat>=e.lat&&i.lat<=r.lat,s=o.lng>=e.lng&&i.lng<=r.lng;return n&&s},overlaps:function(t){t=h(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),o=t.getNorthEast(),n=o.lat>e.lat&&i.lat<r.lat,s=o.lng>e.lng&&i.lng<r.lng;return n&&s},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=h(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var l=function(t){var e,r,i,o;for(r=1,i=arguments.length;r<i;r++)for(e in o=arguments[r])t[e]=o[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),i=this.scale(e);return this.transformation._transform(r,i)},pointToLatLng:function(t,e){var r=this.scale(e),i=this.transformation.untransform(t,r);return this.projection.unproject(i)},project:function(t){return this.projection.project(t)},unproject:function(t){return this.projection.unproject(t)},scale:function(t){return 256*Math.pow(2,t)},zoom:function(t){return Math.log(t/256)/Math.LN2},getProjectedBounds:function(t){if(this.infinite)return null;var e=this.projection.bounds,r=this.scale(t);return new s(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(e){var r=this.wrapLng?t(e.lng,this.wrapLng,!0):e.lng;return new c(this.wrapLat?t(e.lat,this.wrapLat,!0):e.lat,r,e.alt)},wrapLatLngBounds:function(t){var e=t.getCenter(),r=this.wrapLatLng(e),i=e.lat-r.lat,o=e.lng-r.lng;if(0===i&&0===o)return t;var n=t.getSouthWest(),s=t.getNorthEast();return new u(new c(n.lat-i,n.lng-o),new c(s.lat-i,s.lng-o))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,i=t.lat*r,o=e.lat*r,n=Math.sin((e.lat-t.lat)*r/2),s=Math.sin((e.lng-t.lng)*r/2),a=n*n+Math.cos(i)*Math.cos(o)*s*s,u=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return this.R*u}});function c(t,e,r){if(isNaN(t)||isNaN(e))throw new Error("Invalid LatLng object: ("+t+", "+e+")");this.lat=+t,this.lng=+e,void 0!==r&&(this.alt=+r)}function f(t,e,i){return t instanceof c?t:r(t)&&"object"!=typeof t[0]?3===t.length?new c(t[0],t[1],t[2]):2===t.length?new c(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new c(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new c(t,e,i)}c.prototype={equals:function(t,e){return!!t&&(t=f(t),Math.max(Math.abs(this.lat-t.lat),Math.abs(this.lng-t.lng))<=(void 0===e?1e-9:e))},toString:function(t){return"LatLng("+e(this.lat,t)+", "+e(this.lng,t)+")"},distanceTo:function(t){return l.distance(this,f(t))},wrap:function(){return l.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return h([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new c(this.lat,this.lng,this.alt)}};const d=t=>{const e=t.valueOf()/864e5-10957.5,r=6.240059966692059+.017201969994578018*e,i=r+.017453292519943295*(1.9148*Math.sin(r)+.02*Math.sin(2*r)+3e-4*Math.sin(3*r))+1.796593062783907+Math.PI,o=Math.atan2(Math.sin(i)*Math.cos(.40909994067971484),Math.cos(i));return{dec:Math.asin(Math.sin(.40909994067971484)*Math.sin(i)),Hi:(4.889714432387314+6.3003876824396166*e-o)%(2*Math.PI)+2*Math.PI}},m=()=>Math.floor(1e7*Math.random()),_=(t,e,r)=>{const i=1/e,o=Math.min(t[0]*i,255),n=Math.min(t[1]*i,255),s=Math.min(t[2]*i,255);let a=0;return o+n+s!==0&&(a=o>0?o/255*.5+.5:s>0?.5*(1-s/255):.5),a*r},g=(t=new Date,e)=>{const r=new Date(t.toLocaleString("en-US",{timeZone:"UTC"})),i=new Date(t.toLocaleString("en-US",e?{timeZone:e}:{}));return r.getTime()-i.getTime()};const x=t=>{const e=()=>!t.getPitch;return{project:(r,o)=>{if(e())return t.project(r,o);{const{lat:t,lng:e}=r;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*256)(e,o),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*256)(t,o))}},unproject:(r,i)=>{return e()?t.unproject(r,i):new c((o=r.y,n=i,s=Math.PI-2*Math.PI*o/256/Math.pow(2,n),180/Math.PI*Math.atan(.5*(Math.exp(s)-Math.exp(-s)))),function(t,e){return t/256/Math.pow(2,e)*360-180}(r.x,i));var o,n,s},screenUnproject:r=>e()?t.containerPointToLatLng(r):t.unproject(r),getZoom:()=>e()?t.getZoom():t.getZoom()+1,getCenter:()=>t.getCenter(),getBounds:()=>t.getBounds(),eachLayer:r=>{e()&&t.eachLayer(r)},getBearing:()=>e()?0:t.getBearing(),getPitch:()=>e()?0:t.getPitch(),rawMap:()=>t,isLeaflet:e,getPixelDimensions:()=>{const e=t.getContainer();return{width:e.clientWidth,height:e.clientHeight}},createBounds:t=>{const{nw:e,se:r}=t;return new u(e,r)}}};function p(t,e,r,i){return new(r||(r=Promise))((function(o,n){function s(t){try{u(i.next(t))}catch(t){n(t)}}function a(t){try{u(i.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((i=i.apply(t,e||[])).next())}))}const E=(t,e)=>{const{lat:r,lng:o}=t;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*256)(o,e),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*256)(r,e))},T=(t,e)=>{return new c((r=t.y,i=e,o=Math.PI-2*Math.PI*r/256/Math.pow(2,i),180/Math.PI*Math.atan(.5*(Math.exp(o)-Math.exp(-o)))),function(t,e){return t/256/Math.pow(2,e)*360-180}(t.x,e));var r,i,o},y=t=>{const{gl:e}=t,{texture:r,imageData:i=null,format:o=e.RGBA,width:n,height:s,filter:a=e.NEAREST,wrap:u=e.CLAMP_TO_EDGE,type:h=e.UNSIGNED_BYTE}=t;e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,a),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,a),e.texImage2D(e.TEXTURE_2D,0,o,n,s,0,o,h,i)};function v(t){const{gl:e,vSrc:r,fSrc:i}=t,o=e.createShader(e.VERTEX_SHADER);e.shaderSource(o,r),e.compileShader(o);const n=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,i),e.compileShader(n);const s=e.createProgram();return e.attachShader(s,o),e.attachShader(s,n),e.linkProgram(s),s}class R{constructor(t){this.gl=t,this.program=v({gl:t,vSrc:"\nuniform vec3 xyz;\nuniform vec2 dimensions;\nuniform bool use_dsm;\nattribute vec2 dsm_position;\nattribute vec2 a_position;\nfloat PI = 3.141592653589793;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\n\tvoid main() {\n\t\tif (use_dsm == true) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = dsm_position;\n v_use_dsm = 1.0;\n\t\t\treturn;\n\t\t}\n\t\tif (abs(a_position) == vec2(1,1)) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = a_position * 0.5 + 0.5;\n\t\t\treturn;\n\t\t}\n\t\tfloat x = ((a_position.x + 180.0) / 360.0 * pow(2.0, xyz.z)) * 256.0 - xyz.x;\n\t\tfloat y = (1.0 - (log(a_position.y) / PI)) / 2.0 * pow(2.0, xyz.z) * 256.0 - xyz.y;\n\t\tvec2 transformed = vec2(x, y);\n\t\tvec2 normalized = transformed / dimensions;\n\t\tvec2 final = normalized * 2.0 - 1.0;\n\t\tgl_Position = vec4(final, 0, 1);\n\t}\n",fSrc:"\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform vec4 color;\nuniform sampler2D height_map;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n if (v_use_dsm == 1.0) {\n\t \t gl_FragColor = vec4(0.0, 0.0, textureColor.b, textureColor.a);\n if (gl_FragColor.zw == vec2(0.0)) {\n discard;\n }\n } else {\n gl_FragColor = vec4(textureColor.b, textureColor.a, textureColor.b, textureColor.a);\n }\n // DSM noData values should not be included in heightMap because they produce ugly borders\n\t\treturn;\n\t} \n\tgl_FragColor = color;\n}\n"}),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.dsmAttributeLocation=t.getAttribLocation(this.program,"dsm_position"),this.useDSMUniformLocation=t.getUniformLocation(this.program,"use_dsm"),this.xyzUniformLocation=t.getUniformLocation(this.program,"xyz"),this.dimensionsUniformLocation=t.getUniformLocation(this.program,"dimensions"),this.heightMapUniformLocation=t.getUniformLocation(this.program,"height_map"),this.colorUniformLocation=t.getUniformLocation(this.program,"color"),this.positionBuffer=t.createBuffer(),this.dsmBuffer=t.createBuffer(),this.indexBuffer=t.createBuffer(),this.targetTexture=t.createTexture()}raster(t){const{features:e,upperLeftTile:r,mapZoom:o,width:n,height:s,imageData:a,dsmCoords:u,dsmSource:h,gl:l}=t,{x:c,y:f,z:d}=r;let m=0;l.useProgram(this.program),l.activeTexture(l.TEXTURE1);const _=l.createTexture();l.bindTexture(l.TEXTURE_2D,_),l.pixelStorei(l.UNPACK_ALIGNMENT,2),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.LUMINANCE_ALPHA,n,s,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,a);const g=n,x=s;l.activeTexture(l.TEXTURE0),l.bindTexture(l.TEXTURE_2D,this.targetTexture),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,g,x,0,l.RGBA,l.UNSIGNED_BYTE,null),o>15&&e.length>5?(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST)):(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.LINEAR)),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.viewport(0,0,g,x);const p=l.createFramebuffer();l.bindFramebuffer(l.FRAMEBUFFER,p);const T=l.COLOR_ATTACHMENT0;l.framebufferTexture2D(l.FRAMEBUFFER,T,l.TEXTURE_2D,this.targetTexture,0),l.disable(l.BLEND),l.bindBuffer(l.ARRAY_BUFFER,this.positionBuffer),l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,this.indexBuffer),l.clearColor(0,0,0,0),l.clear(l.COLOR_BUFFER_BIT);const y=256*c,v=256*f,R=new i(y,v);l.uniform3f(this.xyzUniformLocation,y,v,d),l.uniform2f(this.dimensionsUniformLocation,n,s),l.uniform1i(this.heightMapUniformLocation,1),l.uniform1i(this.useDSMUniformLocation,0);const A=new Float32Array([-1,-1,1,-1,-1,1,1,1]);if(l.enableVertexAttribArray(this.positionAttributeLocation),l.bufferData(l.ARRAY_BUFFER,A,l.STATIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.uniform4f(this.colorUniformLocation,0,0,0,0),l.drawArrays(l.TRIANGLE_STRIP,0,4),e.forEach((t=>{const{buildingHeight:e,aPosition:r,cuts:i,centroid:o,highlight:u}=t,h=E({lng:o[0],lat:o[1]},d).subtract(R).floor();if(h.x<0||h.y<0||h.x>n||h.y>s)return;const c=256*a[h.y*n*2+2*h.x]+a[h.y*n*2+2*h.x+1]+5*e,f=Math.floor(c/256)/255,_=Math.floor(c%256)/255;m=Math.max(m,c/5),l.uniform4f(this.colorUniformLocation,f,_,f,_),l.bufferData(l.ARRAY_BUFFER,r,l.DYNAMIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.bufferData(l.ARRAY_BUFFER,r,l.DYNAMIC_DRAW),l.vertexAttribPointer(this.dsmAttributeLocation,2,l.FLOAT,!1,0,0),l.bufferData(l.ELEMENT_ARRAY_BUFFER,i,l.DYNAMIC_DRAW),l.drawElements(l.TRIANGLES,i.length,i.length>256?l.UNSIGNED_SHORT:l.UNSIGNED_BYTE,0)})),l.deleteTexture(_),0!==h.data.length){l.activeTexture(l.TEXTURE1);const t=l.createTexture();l.bindTexture(l.TEXTURE_2D,t),l.pixelStorei(l.UNPACK_ALIGNMENT,2),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.LUMINANCE_ALPHA,h.width,h.height,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,h.data);const e=[u[0],u[3],u[2],u[3],u[0],u[1],u[2],u[1]],r=new Float32Array(e);l.enableVertexAttribArray(this.positionAttributeLocation),l.bufferData(l.ARRAY_BUFFER,r,l.STATIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.enableVertexAttribArray(this.dsmAttributeLocation),l.bindBuffer(l.ARRAY_BUFFER,this.dsmBuffer),l.bufferData(l.ARRAY_BUFFER,new Float32Array([0,1,1,1,0,0,1,0]),l.STATIC_DRAW),l.vertexAttribPointer(this.dsmAttributeLocation,2,l.FLOAT,!1,0,0),l.uniform4f(this.colorUniformLocation,0,0,0,0),l.uniform1i(this.useDSMUniformLocation,1),l.colorMask(!1,!1,!0,!0),l.drawArrays(l.TRIANGLE_STRIP,0,4),l.deleteTexture(t)}return l.colorMask(!0,!0,!0,!0),l.enable(l.BLEND),l.blendFunc(l.SRC_ALPHA,l.ONE_MINUS_SRC_ALPHA),l.deleteFramebuffer(p),m}}function A(t,e,r){r=r||2;var i,o,n,s,a,u,h,l=e&&e.length,c=l?e[0]*r:t.length,f=b(t,0,c,r,!0),d=[];if(!f||f.next===f.prev)return d;if(l&&(f=function(t,e,r,i){var o,n,s,a=[];for(o=0,n=e.length;o<n;o++)(s=b(t,e[o]*i,o<n-1?e[o+1]*i:t.length,i,!1))===s.next&&(s.steiner=!0),a.push(B(s));for(a.sort(S),o=0;o<a.length;o++)r=P(a[o],r);return r}(t,e,f,r)),t.length>80*r){i=n=t[0],o=s=t[1];for(var m=r;m<c;m+=r)(a=t[m])<i&&(i=a),(u=t[m+1])<o&&(o=u),a>n&&(n=a),u>s&&(s=u);h=0!==(h=Math.max(n-i,s-o))?32767/h:0}return w(f,d,r,i,o,h,0),d}function b(t,e,r,i,o){var n,s;if(o===q(t,e,r,i)>0)for(n=e;n<r;n+=i)s=Y(n,t[n],t[n+1],s);else for(n=r-i;n>=e;n-=i)s=Y(n,t[n],t[n+1],s);return s&&z(s,s.next)&&(K(s),s=s.next),s}function M(t,e){if(!t)return t;e||(e=t);var r,i=t;do{if(r=!1,i.steiner||!z(i,i.next)&&0!==X(i.prev,i,i.next))i=i.next;else{if(K(i),(i=e=i.prev)===i.next)break;r=!0}}while(r||i!==e);return e}function w(t,e,r,i,o,n,s){if(t){!s&&n&&function(t,e,r,i){var o=t;do{0===o.z&&(o.z=I(o.x,o.y,e,r,i)),o.prevZ=o.prev,o.nextZ=o.next,o=o.next}while(o!==t);o.prevZ.nextZ=null,o.prevZ=null,function(t){var e,r,i,o,n,s,a,u,h=1;do{for(r=t,t=null,n=null,s=0;r;){for(s++,i=r,a=0,e=0;e<h&&(a++,i=i.nextZ);e++);for(u=h;a>0||u>0&&i;)0!==a&&(0===u||!i||r.z<=i.z)?(o=r,r=r.nextZ,a--):(o=i,i=i.nextZ,u--),n?n.nextZ=o:t=o,o.prevZ=n,n=o;r=i}n.nextZ=null,h*=2}while(s>1)}(o)}(t,i,o,n);for(var a,u,h=t;t.prev!==t.next;)if(a=t.prev,u=t.next,n?D(t,i,o,n):L(t))e.push(a.i/r|0),e.push(t.i/r|0),e.push(u.i/r|0),K(t),t=u.next,h=u.next;else if((t=u)===h){s?1===s?w(t=U(M(t),e,r),e,r,i,o,n,2):2===s&&F(t,e,r,i,o,n):w(M(t),e,r,i,o,n,1);break}}}function L(t){var e=t.prev,r=t,i=t.next;if(X(e,r,i)>=0)return!1;for(var o=e.x,n=r.x,s=i.x,a=e.y,u=r.y,h=i.y,l=o<n?o<s?o:s:n<s?n:s,c=a<u?a<h?a:h:u<h?u:h,f=o>n?o>s?o:s:n>s?n:s,d=a>u?a>h?a:h:u>h?u:h,m=i.next;m!==e;){if(m.x>=l&&m.x<=f&&m.y>=c&&m.y<=d&&N(o,a,n,u,s,h,m.x,m.y)&&X(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function D(t,e,r,i){var o=t.prev,n=t,s=t.next;if(X(o,n,s)>=0)return!1;for(var a=o.x,u=n.x,h=s.x,l=o.y,c=n.y,f=s.y,d=a<u?a<h?a:h:u<h?u:h,m=l<c?l<f?l:f:c<f?c:f,_=a>u?a>h?a:h:u>h?u:h,g=l>c?l>f?l:f:c>f?c:f,x=I(d,m,e,r,i),p=I(_,g,e,r,i),E=t.prevZ,T=t.nextZ;E&&E.z>=x&&T&&T.z<=p;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=g&&E!==o&&E!==s&&N(a,l,u,c,h,f,E.x,E.y)&&X(E.prev,E,E.next)>=0)return!1;if(E=E.prevZ,T.x>=d&&T.x<=_&&T.y>=m&&T.y<=g&&T!==o&&T!==s&&N(a,l,u,c,h,f,T.x,T.y)&&X(T.prev,T,T.next)>=0)return!1;T=T.nextZ}for(;E&&E.z>=x;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=g&&E!==o&&E!==s&&N(a,l,u,c,h,f,E.x,E.y)&&X(E.prev,E,E.next)>=0)return!1;E=E.prevZ}for(;T&&T.z<=p;){if(T.x>=d&&T.x<=_&&T.y>=m&&T.y<=g&&T!==o&&T!==s&&N(a,l,u,c,h,f,T.x,T.y)&&X(T.prev,T,T.next)>=0)return!1;T=T.nextZ}return!0}function U(t,e,r){var i=t;do{var o=i.prev,n=i.next.next;!z(o,n)&&G(o,i,i.next,n)&&j(o,n)&&j(n,o)&&(e.push(o.i/r|0),e.push(i.i/r|0),e.push(n.i/r|0),K(i),K(i.next),i=t=n),i=i.next}while(i!==t);return M(i)}function F(t,e,r,i,o,n){var s=t;do{for(var a=s.next.next;a!==s.prev;){if(s.i!==a.i&&O(s,a)){var u=Z(s,a);return s=M(s,s.next),u=M(u,u.next),w(s,e,r,i,o,n,0),void w(u,e,r,i,o,n,0)}a=a.next}s=s.next}while(s!==t)}function S(t,e){return t.x-e.x}function P(t,e){var r=function(t,e){var r,i=e,o=t.x,n=t.y,s=-1/0;do{if(n<=i.y&&n>=i.next.y&&i.next.y!==i.y){var a=i.x+(n-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(a<=o&&a>s&&(s=a,r=i.x<i.next.x?i:i.next,a===o))return r}i=i.next}while(i!==e);if(!r)return null;var u,h=r,l=r.x,c=r.y,f=1/0;i=r;do{o>=i.x&&i.x>=l&&o!==i.x&&N(n<c?o:s,n,l,c,n<c?s:o,n,i.x,i.y)&&(u=Math.abs(n-i.y)/(o-i.x),j(i,t)&&(u<f||u===f&&(i.x>r.x||i.x===r.x&&C(r,i)))&&(r=i,f=u)),i=i.next}while(i!==h);return r}(t,e);if(!r)return e;var i=Z(r,t);return M(i,i.next),M(r,r.next)}function C(t,e){return X(t.prev,t,e.prev)<0&&X(e.next,t,t.next)<0}function I(t,e,r,i,o){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*o|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*o|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function B(t){var e=t,r=t;do{(e.x<r.x||e.x===r.x&&e.y<r.y)&&(r=e),e=e.next}while(e!==t);return r}function N(t,e,r,i,o,n,s,a){return(o-s)*(e-a)>=(t-s)*(n-a)&&(t-s)*(i-a)>=(r-s)*(e-a)&&(r-s)*(n-a)>=(o-s)*(i-a)}function O(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==e.i&&r.next.i!==e.i&&G(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(j(t,e)&&j(e,t)&&function(t,e){var r=t,i=!1,o=(t.x+e.x)/2,n=(t.y+e.y)/2;do{r.y>n!=r.next.y>n&&r.next.y!==r.y&&o<(r.next.x-r.x)*(n-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next}while(r!==t);return i}(t,e)&&(X(t.prev,t,e.prev)||X(t,e.prev,e))||z(t,e)&&X(t.prev,t,t.next)>0&&X(e.prev,e,e.next)>0)}function X(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function z(t,e){return t.x===e.x&&t.y===e.y}function G(t,e,r,i){var o=W(X(t,e,r)),n=W(X(t,e,i)),s=W(X(r,i,t)),a=W(X(r,i,e));return o!==n&&s!==a||(!(0!==o||!H(t,r,e))||(!(0!==n||!H(t,i,e))||(!(0!==s||!H(r,t,i))||!(0!==a||!H(r,e,i)))))}function H(t,e,r){return e.x<=Math.max(t.x,r.x)&&e.x>=Math.min(t.x,r.x)&&e.y<=Math.max(t.y,r.y)&&e.y>=Math.min(t.y,r.y)}function W(t){return t>0?1:t<0?-1:0}function j(t,e){return X(t.prev,t,t.next)<0?X(t,e,t.next)>=0&&X(t,t.prev,e)>=0:X(t,e,t.prev)<0||X(t,t.next,e)<0}function Z(t,e){var r=new k(t.i,t.x,t.y),i=new k(e.i,e.x,e.y),o=t.next,n=e.prev;return t.next=e,e.prev=t,r.next=o,o.prev=r,i.next=r,r.prev=i,n.next=i,i.prev=n,i}function Y(t,e,r,i){var o=new k(t,e,r);return i?(o.next=i.next,o.prev=i,i.next.prev=o,i.next=o):(o.prev=o,o.next=o),o}function K(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function k(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function q(t,e,r,i){for(var o=0,n=e,s=r-i;n<r;n+=i)o+=(t[s]-t[n])*(t[n+1]+t[s+1]),s=n;return o}function V(t){t.filter((t=>"MultiPolygon"===t.geometry.type)).forEach((e=>{const{geometry:r,properties:i,type:o}=e;if("MultiPolygon"===r.type)for(let i=0;i<r.coordinates.length;i++)t.push(Object.assign(Object.assign({},e),{geometry:Object.assign(Object.assign({},r),{type:"Polygon",coordinates:r.coordinates[i]})}))}));return t.filter((t=>"Polygon"===t.geometry.type)).map((t=>{const{geometry:e,properties:r}=t,{vertices:i}=A.flatten(e.coordinates),o=new Float32Array(i.map(((t,e)=>{if(e%2==1){const e=t*Math.PI/180;return Math.tan(e)+1/Math.cos(e)}return t}))),n=A(i),s=n.length>256?new Uint16Array(n):new Uint8Array(n),a=function(t){const{height:e=0,levels:r=0,render_height:i=0}=t;if(r)return 3.04*r;return Math.max(e,i)}(r),u=r.highlight||!1;let h=0,l=0,c=0;for(let t=0;t<i.length;t+=2)h+=i[t],l+=i[t+1],c++;return{aPosition:o,cuts:s,buildingHeight:a,centroid:[h/c,l/c],highlight:u}}))}A.deviation=function(t,e,r,i){var o=e&&e.length,n=o?e[0]*r:t.length,s=Math.abs(q(t,0,n,r));if(o)for(var a=0,u=e.length;a<u;a++){var h=e[a]*r,l=a<u-1?e[a+1]*r:t.length;s-=Math.abs(q(t,h,l,r))}var c=0;for(a=0;a<i.length;a+=3){var f=i[a]*r,d=i[a+1]*r,m=i[a+2]*r;c+=Math.abs((t[f]-t[m])*(t[d+1]-t[f+1])-(t[f]-t[d])*(t[m+1]-t[f+1]))}return 0===s&&0===c?0:Math.abs((c-s)/s)},A.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},i=0,o=0;o<t.length;o++){for(var n=0;n<t[o].length;n++)for(var s=0;s<e;s++)r.vertices.push(t[o][n][s]);o>0&&(i+=t[o-1].length,r.holes.push(i))}return r};let $,J={width:0,height:0,imageData:new Uint8ClampedArray(0),visibleDEMPixelBounds:new s(new i(0,0),new i(0,0)),DEMPixelBounds:new s(new i(0,0),new i(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const Q=t=>p(void 0,void 0,void 0,(function*(){const{demZoom:e,getFeatures:r,terrainSource:o,dsmSource:n,tileLoaded:a,gl:h,bounds:l,buildingRasterizer:c,tileMerger:f,forceUpdate:d=!1}=t,{getSourceUrl:m,getElevation:_,maxZoom:g,tileSize:x,_overzoom:T}=o,y=(v={getFeatures:r},p(void 0,void 0,void 0,(function*(){const{getFeatures:t}=v;try{return V(yield t())}catch(t){console.log("Error merging buildings",t)}return[]})));var v;try{const t=l,r=t.getNorthWest(),o=t.getSouthEast(),p=new s(E(r,e),E(o,e));let T=new i(p.min.x,p.min.y),v=p.max.x-p.min.x;const R=p.max.y-p.min.y,A=p.max.subtract(p.min);A.y>A.x&&(T.x-=256,v+=512);const b=(t=>{const{upperLeft:e,width:r,height:i}=t,o=e.divideBy(256).floor().multiplyBy(256),n=256*(Math.ceil(r/256)+1),a=256*(Math.ceil(i/256)+1),u=o.add([n,a]);return new s(o,u)})({upperLeft:T,width:v,height:R}),{x:M,y:w}=b.max.subtract(b.min),L=(t=>{t.sort(((t,e)=>t.y!==e.y?t.y-e.y:t.x-e.x));const e=t.reduce(((t,e)=>e.x<t.x?e:t)).x,r=t.reduce(((t,e)=>e.y<t.y?e:t)).y;return t.map((t=>{const i=Math.pow(2,t.z);return{x:(t.x%i+i)%i,y:(t.y%i+i)%i,z:t.z,xOffset:256*(t.x-e),yOffset:256*(t.y-r)}}))})((t=>{const{upperLeft:e,width:r,height:i,zoom:o}=t,n=e.divideBy(256).floor(),s=n.x+r/256,a=Math.min(n.y+i/256,Math.pow(2,o)-1),u=[];for(var h=n.x;h<s;h++)for(var l=n.y;l<a;l++)u.push({x:h,y:l,z:o});return u})({upperLeft:b.min,width:M,height:w,zoom:e})),D=p.max.x-p.min.x,U=p.max.y-p.min.y,F=D,S=U,P=JSON.stringify(L);if(!d&&P===$&&e<g)return J=Object.assign(Object.assign({},J),{outputWidth:F,outputHeight:S,visibleDEMPixelBounds:p,demZoom:e,dirty:!0}),J;const C=yield f.merge(L,{maxZoom:g,width:M,height:w,crossOrigin:"Anonymous",getSourceUrl:m,getElevation:_,tileSize:x,tileLoaded:a});if(null===C)return J=Object.assign(Object.assign({},J),{visibleDEMPixelBounds:p,demZoom:e,dirty:!1}),J;const I=new s(E(new u(n.bounds).getNorthWest(),e),E(new u(n.bounds).getSouthEast(),e)),B=I.min.subtract(b.min),N=I.max.subtract(b.min),O=[B.x/M,B.y/w,N.x/M,N.y/w].map((t=>2*t-1)),X=yield y,z=c.raster({upperLeftTile:L[0],width:M,height:w,mapZoom:e,features:X,imageData:C,gl:h,dsmSource:n,dsmCoords:O}),G=Math.max(Math.max(n.maxHeight,z),C.maxHeight);$=P,J={maxHeight:G,width:M,height:w,imageData:C,DEMPixelBounds:b,visibleDEMPixelBounds:p,raster:L,demZoom:e,dirty:!0,outputWidth:F,outputHeight:S}}catch(t){console.error("Could not decode height map",t)}return J})),tt=t=>{const{tile:e,maxZoom:r,tileSize:i}=t;let{x:o,y:n,z:s}=e;if(s>r){const t=Math.pow(2,e.z-r);o=Math.floor(o/t),n=Math.floor(n/t),s=r}return{x:256===i?o:Math.floor(o/2),y:256===i?n:Math.floor(n/2),z:256===i?s:s-1}};class et{constructor(t){this.gl=t,this.program=v({vSrc:"\n attribute vec4 a_position;\n varying vec2 v_pos;\n void main() {\n v_pos = ((a_position + 1.0) * 0.5).xy;\n gl_Position = a_position;\n }\n",fSrc:"\n precision mediump float;\n varying vec2 v_pos;\n uniform sampler2D u_texture;\n void main() {\n gl_FragColor = texture2D(u_texture, v_pos);\n }\n",gl:t}),this.positionBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),t.enableVertexAttribArray(this.positionAttributeLocation),t.vertexAttribPointer(this.positionAttributeLocation,2,t.FLOAT,!1,0,0),this.tileTexture=t.createTexture(),this.gl.bindTexture(this.gl.TEXTURE_2D,this.tileTexture),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST),this.outputTexture=t.createTexture(),this.framebuffer=t.createFramebuffer(),this.inProgress=[],this.finished=0}merge(t,e){return p(this,void 0,void 0,(function*(){const{width:r,height:i,crossOrigin:o,getSourceUrl:n,getElevation:s,tileSize:a,tileLoaded:u,maxZoom:h}=e;if(this.gl){const e=new Uint8ClampedArray(2*r*i);e.maxHeight=0,this.inProgress.forEach((t=>t.src="")),this.inProgress=[],this.finished=0;const l=new Set;t.forEach((t=>{l.add(n(tt({tile:t,maxZoom:h,tileSize:a})))}));const c=Array.from(l).map((i=>p(this,void 0,void 0,(function*(){return new Promise(((u,l)=>{const c=new Image;this.inProgress.push(c),c.onload=()=>{t.filter((t=>i===n(tt({tile:t,maxZoom:h,tileSize:a})))).forEach((t=>{let i=0,o=0;const n=514===a?1:0;let u=0,l=256,f=256;if(256!==a&&(i=t.x%2*256,o=t.y%2*256,l=256,f=256),t.z>h){const e=Math.pow(2,t.z-h);256!==a&&(i=Math.floor(t.x/e)%2*256,o=Math.floor(t.y/e)%2*256),i+=t.x%e/e*256,o+=t.y%e/e*256,l=256/e,f=256/e,u=514===a?1:0}this.gl.useProgram(this.program),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,this.tileTexture),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,c),this.gl.activeTexture(this.gl.TEXTURE1),y({gl:this.gl,texture:this.outputTexture,imageData:null,format:this.gl.RGBA,width:a,height:a,wrap:this.gl.CLAMP_TO_EDGE,filter:this.gl.NEAREST}),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.framebuffer),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.outputTexture,0);const d=this.gl.checkFramebufferStatus(this.gl.FRAMEBUFFER);d!==this.gl.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+d),this.gl.viewport(0,0,a,a),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.positionAttributeLocation),this.gl.vertexAttribPointer(this.positionAttributeLocation,2,this.gl.FLOAT,!1,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.drawArrays(this.gl.TRIANGLE_STRIP,0,4);const m=new Uint8Array(4*(l+u)*(f+u));this.gl.readPixels(n+i,n+o,l+u,f+u,this.gl.RGBA,this.gl.UNSIGNED_BYTE,m),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null);const _=new Uint8ClampedArray(131072);let g=new Array((l+u)*(f+u)),x=256/l;for(let t=0;t<m.length;t+=4){const r=s({r:m[t],g:m[t+1],b:m[t+2],a:m[t+3]});e.maxHeight=Math.max(r,e.maxHeight);const i=5*(r||0);g[t/4]=i}if(x>1&&514===a)for(g=function(t,e,r,i){const o=Math.floor(e*i),n=Math.floor(r*i),s=[];for(let a=0;a<n;a++)for(let n=0;n<o;n++){const o=n/i,u=a/i,h=Math.floor(o),l=Math.floor(u),c=Math.min(h+1,e-1),f=Math.min(l+1,r-1),d=o-h,m=u-l,_=l*e+c,g=f*e+h,x=f*e+c,p=t[l*e+h]*(1-d)*(1-m)+t[_]*d*(1-m)+t[g]*(1-d)*m+t[x]*d*m;s.push(p)}return function(t,e,r,i,o){if(i>=e||o>=r)return[];const n=e-i,s=r-o,a=[];for(let r=0;r<s;r++)for(let i=0;i<n;i++){const o=r*e+i;a.push(t[o])}return a}(s,Math.sqrt(s.length),Math.sqrt(s.length),i,i)}(g,l+1,f+1,x);x>1;)x/=2,f*=2,l*=2;for(let t=0;t<_.length;t+=2){const e=g[Math.floor(t/2/256/x)*l+Math.floor(t/2%256/x)],r=Math.floor(e/256),i=Math.floor(e%256);_[t]=r,_[t+1]=i}for(let i=0;i<256;i++)e.set(_.slice(256*i*2,256*(i+1)*2),2*(t.yOffset*r+i*r+t.xOffset))})),u(null)},c.onerror=t=>{if(c.src!==c.originalSource)return l("new tiles requested");u(null)},c.crossOrigin=o||null,c.src=i,c.originalSource=c.src})).then((()=>{this.finished++,u(this.finished,this.inProgress.length)}))}))));try{yield Promise.all(c)}catch(t){return console.log(`${c.length} requests aborted`,t),null}return this.inProgress=[],e}throw new Error("Could not get canvas context for merging tile images")}))}}const rt=(t,e)=>{const{r:r,g:i,b:o}=t;return[r/255,i/255,o/255,e]},it=(t,e)=>{const{date:r}=e,{dec:i,Hi:o}=d(r);t.updateDate({dec:i,Hi:o})},ot=(t,e)=>p(void 0,void 0,void 0,(function*(){return yield t.updateDateRange(Object.assign({},e))})),nt=(t,e)=>{const{color:r,opacity:i}=e,o=rt(r,i);t.updateColor({colorVec:o})};new u([0,0],[0,0]);const st=t=>{const{kernel:e,map:r,heightMap:i,now:o,color:n,opacity:s,belowCanopy:a}=t;try{const{outputHeight:t,outputWidth:h,maxHeight:l,width:c,height:f,DEMPixelBounds:m,imageData:_,visibleDEMPixelBounds:g,demZoom:x}=i;if(0===c||0===f)return;const{min:p,max:E}=g;if(!p||!E)return;const{x:y,y:v}=E.subtract(p),R=m.min,A=r.getPixelDimensions(),b=r.screenUnproject([0,0]),M=r.screenUnproject([A.width,0]),w=r.screenUnproject([A.width,A.height]),L=r.screenUnproject([0,A.height]),D=[L,w,b,M].map((t=>r.project(t,x))),U=D.map((t=>[(t.x-R.x)/c,(t.y-R.y)/f])).flat(),F=D.map((t=>[(t.x-p.x)/y,(t.y-p.y)/v])).map((t=>[2*t[0]-1,-1*(2*t[1]-1)])).flat(),S=R.y/256/Math.pow(2,x),P=f/256/Math.pow(2,x),C=new u(T(m.getTopLeft(),x),T(m.getBottomRight(),x)),I=C.getWest(),B=Math.abs(C.getWest()-C.getEast());((t,e)=>{const{color:r,opacity:i,date:o}=e,n=rt(r,i),{dec:s,Hi:a}=d(o);t.updateLocation(Object.assign({dec:s,Hi:a,colorVec:n,step:1},e))})(e,{imageData:_,maxHeight:l,width:c,height:f,heightMapZoom:x,cornerTextureCoords:U,cornerClipCoords:F,topYCoord:S,ySize:P,west:I,dLng:B,date:o,color:n,opacity:s,outputHeight:t,outputWidth:h,belowCanopy:a})}catch(t){console.error("EXCEPTION",t)}};class at extends class extends class{constructor(){this.events={}}on(t,e){return"object"!=typeof this.events[t]&&(this.events[t]=[]),this.events[t].push(e),()=>this.removeListener(t,e)}removeListener(t,e){if("object"!=typeof this.events[t])return;const r=this.events[t].indexOf(e);r>-1&&this.events[t].splice(r,1)}removeAllListeners(){Object.keys(this.events).forEach((t=>this.events[t].splice(0,this.events[t].length)))}emit(t,...e){"object"==typeof this.events[t]&&[...this.events[t]].forEach((t=>t.apply(this,e)))}once(t,e){const r=this.on(t,((...t)=>{r(),e.apply(this,t)}));return r}}{constructor(...t){super(),this.options={date:new Date,color:"000",opacity:.3,sunExposure:{enabled:!1,startDate:new Date,endDate:new Date,iterations:32},apiKey:"",terrainSource:{maxZoom:15,tileSize:256,_overzoom:15,getSourceUrl:t=>"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/7/17/45.png",getElevation:t=>{const{r:e,g:r,b:i}=t;return 256*e+r+i/256-32768}},dsmSource:{bounds:[{lat:0,lng:0},{lat:0,lng:0}],data:new Uint8ClampedArray,width:0,height:0,maxHeight:0},belowCanopy:!1,getFeatures:()=>Promise.resolve([]),getSize:()=>({width:Number.NaN,height:Number.NaN}),debug:t=>{}};const e=t[0];if(this.options=Object.assign(this.options,e),!this.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:this.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((t=>p(this,void 0,void 0,(function*(){if(200!==t.status)throw new Error(yield t.text())})))).catch((t=>p(this,void 0,void 0,(function*(){throw new Error(`Could not load ShadeMap API. Key: ${this.options.apiKey} Error: ${t}`)}))));const r={preserveDrawingBuffer:!0,antialias:!1};this._canvas=document.createElement("canvas"),this._gl=this._canvas.getContext("webgl",r)||this._canvas.getContext("experimental-webgl",r),this._compiledKernel=function(t){const{context:e}=t,r=e,i=v({gl:r,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 a_pos;attribute vec2 a_tex_pos;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;void main(void){gl_Position=vec4(a_pos,0,1);vTexCoordFull=(gl_Position*0.5+0.5).xy;vTexCoordCropped=a_tex_pos;}",fSrc:"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nprecision lowp int;precision lowp sampler2D;float atan2(float v1,float v2){if(v1==0.0||v2==0.0)return 0.0;return atan(v1,v2);}float _pow(float v1,float v2){if(v2==0.0)return 1.0;return pow(v1,v2);}float integerMod(float x,float y){float res=floor(mod(x,y));return res*(res>floor(y)-1.0 ? 0.0 : 1.0);}float divWithIntCheck(float x,float y){if(floor(x)==x&&floor(y)==y&&integerMod(x,y)==0.0){return float(int(x)/int(y));}return x/y;}float integerCorrectionModulo(float number,float divisor){if(number<0.0){number=abs(number);if(divisor<0.0){divisor=abs(divisor);}return-(number-(divisor*floor(divWithIntCheck(number,divisor))));}if(divisor<0.0){divisor=abs(divisor);}return number-(divisor*floor(divWithIntCheck(number,divisor)));}float getDEMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*255.0*256.0+result.g*255.0)/5000.0;}float getDSMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.b*255.0*256.0+result.a*255.0)/5000.0;}vec4 actualColor;void color(float r,float g,float b,float a){actualColor=vec4(r,g,b,a);}void color(float r,float g,float b){color(r,g,b,1.0);}void color(float r){color(r,r,r,1.0);}void color(vec4 color){actualColor=color;}const int LOOP_MAX=1000;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;uniform sampler2D user_a;uniform float user_width;uniform float user_height;uniform float user_maxHeight;uniform float user_zoom;uniform float user_topYCoord;uniform float user_ySize;uniform vec4 user_color;uniform vec4 u_sunColor;uniform float user_step;uniform float user_west;uniform float user_dLng;uniform float user_dec;uniform float user_Hi;uniform bool u_below_canopy;uniform sampler2D user_sunExposureTexture;uniform bool user_renderToSunExposureTexture;uniform bool user_outputSunExposure;uniform vec4 user_exposureDelta;uniform bool u_outputShadeProfile;uniform sampler2D u_decHiTexture;uniform sampler2D u_gpxTexture;uniform bool u_outputLocationShadeProfile;uniform vec2 u_shadeProfileLocation;float kernelResult;void kernel(){float sunDec=user_dec;float sunHi=user_Hi;vec4 shade_color=user_color;float maxHeight=user_maxHeight/1000.0;float user_x=vTexCoordCropped.x;float user_y=vTexCoordCropped.y;if(u_outputShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;vec4 gpx=texture2D(u_gpxTexture,vec2(vTexCoordFull.x,.5));user_x=gpx.x;user_y=gpx.y;}if(u_outputLocationShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;user_x=u_shadeProfileLocation.x;user_y=u_shadeProfileLocation.y;}float user_lit=1.0;float dsm_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(u_below_canopy==true){float dem_height=getDEMElevationFromSampler2D(user_a,user_x,user_y);if(dsm_height-dem_height>.002){user_lit=0.0;}}float user_z=dsm_height;float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=user_west+(user_dLng*user_x);float user_H=integerCorrectionModulo((sunHi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(sunDec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(sunDec))+((cos(user_lat)*cos(sunDec))*cos(user_H))));float user_zoom_factor=_pow(2.0,user_zoom);float user_kmPerPixel=divWithIntCheck(156.5430339296875,user_zoom_factor)*abs(cos(user_lat));float user_dx=((-sin(sun_azimuth)*cos(sun_altitude))*user_step)/user_width;float user_dy=((cos(sun_azimuth)*cos(sun_altitude))*user_step)/user_height;float user_dz=((sin(sun_altitude)*user_kmPerPixel)*user_step);float shadow_bias=0.0005;float user_curvature=0.0;float cur_height=0.0;float user_distance=0.0;float user_startX=user_x;float user_startY=user_y;user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;if((abs(1.0)<0.0)){kernelResult=0.0;return;}float minAngle=asin((earthRadiusInKm/(earthRadiusInKm+user_z)))-(user_PI/2.0);if(user_z<0.0||sun_altitude<minAngle){user_lit=0.0;}else{float xIter=ceil(user_dx<0.0 ? abs(user_x/user_dx):(1.0-user_x)/user_dx);float yIter=ceil(user_dy<0.0 ? abs(user_y/user_dy):(1.0-user_y)/user_dy);float zIter=ceil(user_dz<0.0 ? float(LOOP_MAX):(maxHeight-user_z)/user_dz);int iter=int(min(xIter,min(yIter,zIter)));float user_distance=(sqrt(pow(user_dx*user_width,2.0)+pow(user_dy*user_height,2.0))*user_kmPerPixel)/earthRadiusInKm;for(int safeI=0;safeI<LOOP_MAX;safeI++){if(safeI>iter){break;}cur_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(cur_height-user_z>shadow_bias){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;vec4 result=texture2D(user_a,vec2(user_x,user_y));iter=0;break;}}user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;}}if((user_lit==1.0)){if(u_outputLocationShadeProfile==true&&u_sunColor==shade_color){float timeInSun=pow(.7,pow(sin(sun_altitude),.678))*sin(sun_altitude)*(1.0/0.7);float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,1.0);}else{color(u_sunColor);}}else{color(shade_color);}if(user_renderToSunExposureTexture){vec4 aggregateColor=texture2D(user_sunExposureTexture,vec2(vTexCoordFull.x,vTexCoordFull.y));if((user_lit==1.0)){color(aggregateColor.r,0.0,0.0,1.0);}else{color(aggregateColor.r+user_exposureDelta.r,0.0,0.0,1.0);}if(user_outputSunExposure){float timeInSun=1.0-aggregateColor.r;float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,0.5);}}}void main(void){kernel();gl_FragColor=actualColor;}"});r.useProgram(i);const o=r.createBuffer(),n=r.getAttribLocation(i,"a_pos"),s=r.createBuffer(),a=r.getAttribLocation(i,"a_tex_pos"),u=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,u),r.bufferData(r.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),r.STATIC_DRAW),r.enable(r.BLEND),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA);const h=r.getUniformLocation(i,"user_a");r.uniform1i(h,0);const l=r.getUniformLocation(i,"user_width"),c=r.getUniformLocation(i,"user_height"),f=r.getUniformLocation(i,"user_maxHeight"),m=r.getUniformLocation(i,"user_zoom"),_=r.getUniformLocation(i,"user_topYCoord"),g=r.getUniformLocation(i,"user_ySize"),x=r.getUniformLocation(i,"user_step"),E=r.getUniformLocation(i,"user_west"),T=r.getUniformLocation(i,"user_dLng"),R=r.getUniformLocation(i,"user_dec"),A=r.getUniformLocation(i,"user_Hi"),b=r.getUniformLocation(i,"user_color"),M=r.getUniformLocation(i,"user_xStart"),w=r.getUniformLocation(i,"user_yStart"),L=r.getUniformLocation(i,"user_xEnd"),D=r.getUniformLocation(i,"user_yEnd"),U=r.getUniformLocation(i,"u_below_canopy"),F=r.getUniformLocation(i,"user_sunExposureTexture"),S=r.getUniformLocation(i,"user_renderToSunExposureTexture"),P=r.getUniformLocation(i,"user_outputSunExposure"),C=r.getUniformLocation(i,"user_exposureDelta"),I=r.getUniformLocation(i,"u_outputShadeProfile"),B=r.getUniformLocation(i,"u_gpxTexture"),N=r.getUniformLocation(i,"u_decHiTexture"),O=r.getUniformLocation(i,"u_sunColor"),X=r.getUniformLocation(i,"u_outputLocationShadeProfile"),z=r.getUniformLocation(i,"u_shadeProfileLocation");let G=0,H=0,W=0;const j=()=>{H&&W&&(r.useProgram(i),r.bindBuffer(r.ARRAY_BUFFER,o),r.enableVertexAttribArray(n),r.bindBuffer(r.ARRAY_BUFFER,s),r.enableVertexAttribArray(a),r.bindFramebuffer(r.FRAMEBUFFER,null),r.viewport(0,0,H,W),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4))};let Z=0;return{updateLocation:function(t){const{width:e,height:u,maxHeight:h,heightMapZoom:d,topYCoord:p,ySize:y,colorVec:v,step:M,west:w,dLng:L,dec:D,Hi:F,cornerClipCoords:S,cornerTextureCoords:P,outputWidth:C,outputHeight:I,belowCanopy:B}=t;r.useProgram(i),H=C,W=I,r.canvas.width=H,r.canvas.height=W,r.bindBuffer(r.ARRAY_BUFFER,o),r.bufferData(r.ARRAY_BUFFER,new Float32Array(S),r.STATIC_DRAW),r.enableVertexAttribArray(n),r.vertexAttribPointer(n,2,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,s),r.bufferData(r.ARRAY_BUFFER,new Float32Array(P),r.STATIC_DRAW),r.enableVertexAttribArray(a),r.vertexAttribPointer(a,2,r.FLOAT,!1,0,0),r.uniform1f(l,e),r.uniform1f(c,u),r.uniform1f(f,h),r.uniform1f(m,d),r.uniform1f(_,p),r.uniform1f(g,y),r.uniform4fv(b,v),r.uniform1f(x,M),r.uniform1f(E,w),r.uniform1f(T,L),r.uniform1f(R,D),r.uniform1f(A,F),r.uniform1f(U,B?1:0),window.cancelAnimationFrame(G),G=window.requestAnimationFrame(j)},updateViewport:function(t){const{xStart:e,yStart:o,xEnd:n,yEnd:s}=t;r.useProgram(i),r.uniform1f(M,e),r.uniform1f(w,o),r.uniform1f(L,n),r.uniform1f(D,s),window.cancelAnimationFrame(G),G=window.requestAnimationFrame(j)},updateDate:t=>{const{dec:e,Hi:o}=t;r.useProgram(i),r.uniform1f(R,e),r.uniform1f(A,o),window.cancelAnimationFrame(G),G=window.requestAnimationFrame(j)},updateDateRange:t=>p(this,void 0,void 0,(function*(){const{startDate:e,endDate:o,iterations:n,emit:s}=t;r.useProgram(i);const a=Z=Date.now();r.uniform4fv(C,new Float32Array([1/n,0,0,0]));const u=Math.floor((o.getTime()-e.getTime())/n),h=H,l=W,c=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,c),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,h,l,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR);const f=r.createTexture();r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,f),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,h,l,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR);const m=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,m);const _=r.COLOR_ATTACHMENT0;r.uniform1i(F,1);for(let t=0;t<n;t++){if(r.useProgram(i),s("tileloaded",t,n-1),a!==Z)return r.deleteFramebuffer(m),r.deleteTexture(c),r.deleteTexture(f),!0;yield new Promise(((o,n)=>{window.requestAnimationFrame((()=>{r.useProgram(i),r.uniform1i(S,1);const n=t%2==0?f:c,s=t%2==0?c:f;r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,n),r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,s),r.bindFramebuffer(r.FRAMEBUFFER,m),r.framebufferTexture2D(r.FRAMEBUFFER,_,r.TEXTURE_2D,s,0);const a=r.checkFramebufferStatus(r.FRAMEBUFFER);a!==r.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+a);const{dec:g,Hi:x}=d(new Date(e.getTime()+u*t));r.uniform1f(R,g),r.uniform1f(A,x),r.viewport(0,0,h,l),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4),o()}))}))}return yield new Promise(((t,e)=>{window.requestAnimationFrame((()=>{if(r.useProgram(i),a!==Z)return r.deleteFramebuffer(m),r.deleteTexture(c),r.deleteTexture(f),void t(!0);r.uniform1i(F,2),r.uniform1i(P,1),j(),r.uniform1i(S,0),r.uniform1i(P,0),r.uniform1i(F,0),r.deleteFramebuffer(m),r.deleteTexture(c),r.deleteTexture(f),t(!1)}))}))})),updateColor:t=>{const{colorVec:e}=t;r.useProgram(i),r.uniform4fv(b,e),window.cancelAnimationFrame(G),G=window.requestAnimationFrame(j)},generateShadeProfile:t=>{if(r.useProgram(i),null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");const{dates:e,texCoords:o,shadeColor:s,sunColor:a}=t,h=o.length,l=e.length,c=r.getUniform(i,b);r.uniform4fv(b,s),r.uniform4fv(O,a),r.uniform1i(I,1);const f=r.createTexture();r.activeTexture(r.TEXTURE3),y({gl:r,imageData:null,width:h,height:l,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST,format:r.RGBA,texture:f});const m=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,m),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,f,0);const _=r.checkFramebufferStatus(r.FRAMEBUFFER);_!==r.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+_);const g=o.map((t=>[t[0],t[1],0,0])).flat(),x=r.createTexture();r.activeTexture(r.TEXTURE2),y({gl:r,texture:x,imageData:new Float32Array(g),width:g.length/4,height:1,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST,format:r.RGBA,type:r.FLOAT}),r.uniform1i(B,2);const p=e.map((t=>{const{dec:e,Hi:r}=d(t);return[-e,r/10,0,0]})).flat(),E=r.createTexture();r.activeTexture(r.TEXTURE1),y({gl:r,texture:E,imageData:new Float32Array(p),width:1,height:e.length,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST,format:r.RGBA,type:r.FLOAT}),r.uniform1i(N,1),r.viewport(0,0,h,l),r.clear(r.COLOR_BUFFER_BIT),r.bindBuffer(r.ARRAY_BUFFER,u),r.enableVertexAttribArray(n),r.drawArrays(r.TRIANGLE_STRIP,0,4);const T=new Uint8Array(h*l*4);return r.readPixels(0,0,h,l,r.RGBA,r.UNSIGNED_BYTE,T),r.deleteTexture(f),r.deleteTexture(E),r.deleteTexture(x),r.deleteFramebuffer(m),r.uniform1i(N,0),r.uniform1i(B,0),r.uniform1i(I,0),r.uniform4fv(b,c),r.uniform4fv(O,[0,0,0,0]),T},generateLocationShadeProfile:t=>{if(r.useProgram(i),null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");const{dates:e,texCoord:o,shadeColor:s,sunColor:a}=t,h=e[0].length,l=e.length,c=r.getUniform(i,b);r.uniform4fv(b,s),r.uniform4fv(O,a),r.uniform1i(X,1),r.uniform2fv(z,[o[0],o[1]]);const f=r.createTexture();r.activeTexture(r.TEXTURE2),y({gl:r,imageData:null,width:h,height:l,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST,format:r.RGBA,texture:f});const m=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,m),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,f,0);const _=r.checkFramebufferStatus(r.FRAMEBUFFER);_!==r.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+_);const g=e.flat().map((t=>{const{dec:e,Hi:r}=d(t);return[-e,r/10,0,0]})).flat(),x=r.createTexture();r.activeTexture(r.TEXTURE1),y({gl:r,texture:x,imageData:new Float32Array(g),width:h,height:l,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST,format:r.RGBA,type:r.FLOAT}),r.uniform1i(N,1),r.viewport(0,0,h,l),r.clear(r.COLOR_BUFFER_BIT),r.bindBuffer(r.ARRAY_BUFFER,u),r.enableVertexAttribArray(n),r.drawArrays(r.TRIANGLE_STRIP,0,4);const p=new Uint8Array(h*l*4);return r.readPixels(0,0,h,l,r.RGBA,r.UNSIGNED_BYTE,p),r.deleteTexture(f),r.deleteTexture(x),r.deleteFramebuffer(m),r.uniform1i(N,0),r.uniform1i(X,0),r.uniform4fv(b,c),r.uniform4fv(O,[0,0,0,0]),p}}}({context:this._gl}),this._color=this._parseColor(this.options.color),this._buildingRasterizer=new R(this._gl),this._tileMerger=new et(this._gl),this._reset=this._reset.bind(this),this._draw=this._draw.bind(this)}onRemove(){return this._map&&this._map.off("moveend",this._reset),this}setDate(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(it(this._compiledKernel,{date:this.options.date}),this._flush())):this.emit("idle"),this}_setDateForTimezone(t,e){let r=0;e&&(r=g(this.options.date)-g(this.options.date,e)),this.setDate(new Date(t.getTime()-r))}setColor(t){return this.options.color!==t&&(this.options.color=t,this._color=this._parseColor(this.options.color),this._compiledKernel&&(nt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setOpacity(t){return this.options.opacity!==t&&(this.options.opacity=t,this._compiledKernel&&(nt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setBelowCanopy(t){return this.options.belowCanopy=t,this._heightMap?this._draw(this._heightMap):this._reset(),this}setTerrainSource(t){return this.options.terrainSource=t,delete this._heightMap,this._reset(),this}setDSMSource(t){return this.options.dsmSource=t,delete this._heightMap,this._reset(),this}setSunExposure(t=!1,e){return p(this,void 0,void 0,(function*(){if(this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:t}),e){const{startDate:r=new Date,endDate:i=new Date,iterations:o=32}=e;this.options.sunExposure={enabled:t,startDate:r,endDate:i,iterations:o}}if(this._map&&this._compiledKernel&&this._heightMap){if(!1===t)it(this._compiledKernel,{date:this.options.date});else{const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!(t instanceof Date&&e instanceof Date))throw new Error("Start date or end date or both are missing");if(e.getTime()<t.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield ot(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._flush()}return this}))}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:i,height:o}=this._heightMap,n=e.min;return t.map((t=>{const e=E(t,r);return[(e.x-n.x)/i,(e.y-n.y)/o]}))}return[]}_getBounds(t,e){const{width:r,height:o}=this.options.getSize();if(Number.isNaN(r)||Number.isNaN(o))return t.getBounds();const n=t.getCenter(),s=E(n,e),a=T(new i(s.x-r/2,s.y-o/2),e),u=T(new i(s.x+r/2,s.y+o/2),e);return t.createBounds({nw:a,se:u})}_getDEMZoom(t){const e=Math.min(this.options.terrainSource._overzoom||this.options.terrainSource.maxZoom,t.getZoom());return Math.round(e)}_reset(){return p(this,void 0,void 0,(function*(){if(this.options.debug("_reset()"),this._map){const t=x(this._map);let e=this._getDEMZoom(t);try{this._bounds=this._getBounds(t,e)}catch(t){return console.error("Invalid bounds returned: ",t),this}try{if(!t.isLeaflet()&&this._map.getPitch()>45){yield new Promise((t=>{this._map.loaded()?t(!0):this._map.once("idle",(function(){t(!0)}))}));const r=this._map.style._sourceCaches["other:composite"].getVisibleCoordinates().reverse(),o=r.reduce(((t,e)=>Math.max(t,e.canonical.z)),Number.MIN_SAFE_INTEGER),n=r.filter((t=>t.canonical.z===o)).map((t=>t.canonical)),[s,a,u,h]=n.reduce(((t,e)=>[Math.min(t[0],e.x),Math.min(t[1],e.y),Math.max(t[2],e.x),Math.max(t[3],e.y)]),[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER]),l=T(new i(512*s,512*a),o+1),c=T(new i(512*(u+1),512*(h+1)),o+1);e=o+1,this._bounds=t.createBounds({nw:l,se:c})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield Q({gl:this._gl,demZoom:e,bounds:this._bounds,terrainSource:this.options.terrainSource,dsmSource:this.options.dsmSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,tileLoaded:(t,e)=>this.emit("tileloaded",t,e),forceUpdate:!this._heightMap});this._heightMap=r,r.dirty&&(yield this._draw(r))}return this}))}_draw(t){return p(this,void 0,void 0,(function*(){if(this.options.debug("_draw()"),this._canvas&&this._compiledKernel&&this._map){if(st({kernel:this._compiledKernel,map:x(this._map),heightMap:t,color:this._color,belowCanopy:this.options.belowCanopy,opacity:this.options.opacity,now:this.options.date,maxZoom:this.options.terrainSource.maxZoom}),this.options.sunExposure.enabled){const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!0===(yield ot(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._bounds&&this._repositionCanvas(this._bounds)}return this}))}readPixel(t,e){const r=new Uint8Array(4);return this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r),r}toGeoTiff(){const t=(t,e,r,i)=>{const o=new Uint8Array(r*i*4);this._gl.readPixels(t,e,r,i,this._gl.RGBA,this._gl.UNSIGNED_BYTE,o);const n=r*i*1,s=1*r,a=(i-1)*s,u=new Uint8Array(n),h=new Uint8Array(n);let l=0;const{startDate:c,endDate:f}=this.options.sunExposure;this.options.sunExposure.enabled&&c&&f&&(l=f.getTime()-c.getTime());for(let t=0;t<o.length;t+=4){let e;if(this.options.sunExposure.enabled){const r=o.subarray(t,t+3),i=_(r,.5,l)/1e3/60,n=Math.min(Math.floor(i/6),255);e=new Uint8Array([n])}else{e=o[t]+o[t+1]+o[t+2]===0?new Uint8Array([255]):new Uint8Array([0])}u.set(e,t/4*1)}for(let t=0;t<n;t+=s)h.set(u.subarray(t,t+s),a-t);return h};if(this._map){const e=this._canvas.width,r=this._canvas.height,i=t(0,0,e,r),o=x(this._map),{lat:n,lng:s}=o.getBounds().getNorthWest(),a=o.getBounds().getSouthEast(),u=[0,0,0,s,n,0],h=[(a.lng-s)/e,(n-a.lat)/r,0];return this.options.sunExposure.enabled,{data:i,metadata:{width:e,height:r,ModelTiepoint:u,ModelPixelScale:h,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}return null}_generateShadeProfile(t){if(this._compiledKernel){const e=this._lngLatToTextureCoords(t.locations);return((t,e)=>{const r=rt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=rt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{texCoords:e}))}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=g(t.startDate)-g(t.startDate,t.tzId),r=t.startDate.getTime()-e,i=(t.endDate.getTime()-e-r)/86400/1e3,o=1440,n=[],s=828e5,a=g(new Date(r),t.tzId);for(let e=0;e<i;e++){const i=g(new Date(r+86400*e*1e3+s),t.tzId)-a;n[e]=i}const u=[];for(let t=0;t<o;t++){const e=[];for(let o=0;o<i;o++){const i=r+86400*o*1e3+60*t*1e3;e.push(new Date(i+n[o]))}u.push(e)}const h=this._lngLatToTextureCoords([t.location])[0],l=((t,e)=>{const r=rt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=rt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateLocationShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{dates:u,texCoord:h}));return l.toArray=function(){const e=new Array;for(let r=0;r<i;r++){const n=[];for(let e=o-1;e>=0;e--){const o=e*i*4+4*r,s=this.slice(o,o+4);n.push(s.join("")===t.sunColor.join("")?1:0)}e.push(n)}return e},{data:l,width:i,height:o}}return{data:new Uint8Array,width:0,height:0}}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this.readPixel(t,e),{startDate:i,endDate:o}=this.options.sunExposure,n=o.getTime()-i.getTime(),s=_(r,.5,n);return Math.abs(s/1e3/3600)}return 0}_repositionCanvas(t){}_flush(){}flushSync(){this._gl.finish()}_parseColor(t){t=t.replace("#","");const e={r:0,g:0,b:0};return/^([0-9A-F]{3}){1,2}$/i.test(t)&&(3===t.length?(e.r=parseInt(t[0]+t[0],16),e.g=parseInt(t[1]+t[1],16),e.b=parseInt(t[2]+t[2],16)):6===t.length&&(e.r=parseInt(t[0]+t[1],16),e.g=parseInt(t[2]+t[3],16),e.b=parseInt(t[4]+t[5],16))),e}}{constructor(t){super(t),this.id="shademap-layer",this.type="custom",this.canvasSourceId="canvas-source",this.attributionSourceId="attribution-source",this.canvasLayerId="canvas-layer",this.attributionLayerId="attribution-layer",this._refreshing=0,this._raf=0,this.id=this.id+m(),this.canvasSourceId=this.canvasSourceId+m(),this.attributionSourceId=this.attributionSourceId+m(),this.canvasLayerId=this.canvasLayerId+m(),this.attributionLayerId=this.attributionLayerId+m(),this.options.terrainSource.tileSize>256&&(this.options.terrainSource.maxZoom=this.options.terrainSource.maxZoom+1),this._moveEndHandler=()=>this._map&&this._reset()}render(t,e){}addTo(t){return t.addLayer(this),this}onAdd(t){this._map=t,document.body.appendChild(this._canvas),this._canvas.style.display="none";const e=t.getBounds(),r=e.getNorthWest(),i=e.getNorthEast(),o=e.getSouthEast(),n=e.getSouthWest(),s=[[r.lng,r.lat],[i.lng,i.lat],[o.lng,o.lat],[n.lng,n.lat]];t.addSource(this.canvasSourceId,{type:"canvas",canvas:this._canvas,coordinates:s,animate:!1}),t.addLayer({id:this.canvasLayerId,type:"raster",source:this.canvasSourceId,paint:{"raster-fade-duration":0}}),t.addSource(this.attributionSourceId,{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[-122.210598,47.769799]}},attribution:'<a href="https://shademap.app/about">© ShadeMap</a>'}),t.addLayer({id:this.attributionLayerId,type:"fill",source:this.attributionSourceId});const a=t.getSource(this.canvasSourceId),u=()=>{this._refreshing>0&&(a.texture.update(this._canvas,{premultiply:!0}),a.fire({type:"data",dataType:"source",sourceDataType:"content"}),this._refreshing--,this.options.debug("repaint"),1===this._refreshing&&this.emit("idle")),this._raf=requestAnimationFrame(u)};return this._raf=requestAnimationFrame(u),this._map.on("moveend",this._moveEndHandler),this._moveEndHandler(),this}onRemove(){return this._map&&(this._map.off("moveend",this._moveEndHandler),this._map.removeLayer(this.attributionLayerId),this._map.removeLayer(this.canvasLayerId),this._map.removeSource(this.attributionSourceId),this._map.removeSource(this.canvasSourceId)),cancelAnimationFrame(this._raf),document.body.removeChild(this._canvas),this.options.debug("onRemove called"),this}_getHeightMapCoords(t,e){if(this._map&&this.options.sunExposure.enabled&&this._bounds&&this._heightMap){const r=this._map.unproject([t,e]);if(r.toString()===this._map.unproject([t,e+1]).toString())return new i(-1,-1);const{visibleDEMPixelBounds:o,demZoom:n}=this._heightMap,s=x(this._map).project(r,n).subtract(o.min);return s.y=o.max.y-o.min.y-s.y,s}return new i(-1,-1)}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this._getHeightMapCoords(t,e),i=this.readPixel(r.x,r.y),{startDate:o,endDate:n}=this.options.sunExposure,s=n.getTime()-o.getTime(),a=_(i,.5,s);return Math.abs(a/1e3/3600)}return 0}remove(){this._map&&this._map.removeLayer(this.id)}_flush(){this._refreshing=2}_repositionCanvas(t){if(this._map){const e=this._map.getSource(this.canvasSourceId);if(e){const r=t.getNorthWest(),i=t.getNorthEast(),o=t.getSouthEast(),n=t.getSouthWest(),s=[[r.lng,r.lat],[i.lng,i.lat],[o.lng,o.lat],[n.lng,n.lat]];window.requestAnimationFrame((()=>{e.texture.update(this._canvas,{premultiply:!0}),e.setCoordinates(s),this.emit("idle")}))}}return this}}export{at as default};
|
|
8
|
+
function t(t,e,r){var i=e[1],o=e[0],n=i-o;return t===i&&r?t:((t-o)%n+n)%n+o}function e(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}var r=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function i(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var o=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function n(t,e,o){return t instanceof i?t:r(t)?new i(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new i(t.x,t.y):new i(t,e,o)}function a(t,e){if(t)for(var r=e?[t,e]:t,i=0,o=r.length;i<o;i++)this.extend(r[i])}function s(t,e){return!t||t instanceof a?t:new a(t,e)}function u(t,e){if(t)for(var r=e?[t,e]:t,i=0,o=r.length;i<o;i++)this.extend(r[i])}function h(t,e){return t instanceof u?t:new u(t,e)}i.prototype={clone:function(){return new i(this.x,this.y)},add:function(t){return this.clone()._add(n(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(n(t))},_subtract:function(t){return this.x-=t.x,this.y-=t.y,this},divideBy:function(t){return this.clone()._divideBy(t)},_divideBy:function(t){return this.x/=t,this.y/=t,this},multiplyBy:function(t){return this.clone()._multiplyBy(t)},_multiplyBy:function(t){return this.x*=t,this.y*=t,this},scaleBy:function(t){return new i(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new i(this.x/t.x,this.y/t.y)},round:function(){return this.clone()._round()},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},floor:function(){return this.clone()._floor()},_floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.clone()._ceil()},_ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},trunc:function(){return this.clone()._trunc()},_trunc:function(){return this.x=o(this.x),this.y=o(this.y),this},distanceTo:function(t){var e=(t=n(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=n(t)).x===this.x&&t.y===this.y},contains:function(t){return t=n(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+e(this.x)+", "+e(this.y)+")"}},a.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof i||"number"==typeof t[0]||"x"in t)e=r=n(t);else if(e=(t=s(t)).min,r=t.max,!e||!r)return this;return this.min||this.max?(this.min.x=Math.min(e.x,this.min.x),this.max.x=Math.max(r.x,this.max.x),this.min.y=Math.min(e.y,this.min.y),this.max.y=Math.max(r.y,this.max.y)):(this.min=e.clone(),this.max=r.clone()),this},getCenter:function(t){return n((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return n(this.min.x,this.max.y)},getTopRight:function(){return n(this.max.x,this.min.y)},getTopLeft:function(){return this.min},getBottomRight:function(){return this.max},getSize:function(){return this.max.subtract(this.min)},contains:function(t){var e,r;return(t="number"==typeof t[0]||t instanceof i?n(t):s(t))instanceof a?(e=t.min,r=t.max):e=r=t,e.x>=this.min.x&&r.x<=this.max.x&&e.y>=this.min.y&&r.y<=this.max.y},intersects:function(t){t=s(t);var e=this.min,r=this.max,i=t.min,o=t.max,n=o.x>=e.x&&i.x<=r.x,a=o.y>=e.y&&i.y<=r.y;return n&&a},overlaps:function(t){t=s(t);var e=this.min,r=this.max,i=t.min,o=t.max,n=o.x>e.x&&i.x<r.x,a=o.y>e.y&&i.y<r.y;return n&&a},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,i=Math.abs(e.x-r.x)*t,o=Math.abs(e.y-r.y)*t;return s(n(e.x-i,e.y-o),n(r.x+i,r.y+o))},equals:function(t){return!!t&&(t=s(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},u.prototype={extend:function(t){var e,r,i=this._southWest,o=this._northEast;if(t instanceof c)e=t,r=t;else{if(!(t instanceof u))return t?this.extend(f(t)||h(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return i||o?(i.lat=Math.min(e.lat,i.lat),i.lng=Math.min(e.lng,i.lng),o.lat=Math.max(r.lat,o.lat),o.lng=Math.max(r.lng,o.lng)):(this._southWest=new c(e.lat,e.lng),this._northEast=new c(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,i=Math.abs(e.lat-r.lat)*t,o=Math.abs(e.lng-r.lng)*t;return new u(new c(e.lat-i,e.lng-o),new c(r.lat+i,r.lng+o))},getCenter:function(){return new c((this._southWest.lat+this._northEast.lat)/2,(this._southWest.lng+this._northEast.lng)/2)},getSouthWest:function(){return this._southWest},getNorthEast:function(){return this._northEast},getNorthWest:function(){return new c(this.getNorth(),this.getWest())},getSouthEast:function(){return new c(this.getSouth(),this.getEast())},getWest:function(){return this._southWest.lng},getSouth:function(){return this._southWest.lat},getEast:function(){return this._northEast.lng},getNorth:function(){return this._northEast.lat},contains:function(t){t="number"==typeof t[0]||t instanceof c||"lat"in t?f(t):h(t);var e,r,i=this._southWest,o=this._northEast;return t instanceof u?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=i.lat&&r.lat<=o.lat&&e.lng>=i.lng&&r.lng<=o.lng},intersects:function(t){t=h(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),o=t.getNorthEast(),n=o.lat>=e.lat&&i.lat<=r.lat,a=o.lng>=e.lng&&i.lng<=r.lng;return n&&a},overlaps:function(t){t=h(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),o=t.getNorthEast(),n=o.lat>e.lat&&i.lat<r.lat,a=o.lng>e.lng&&i.lng<r.lng;return n&&a},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=h(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var l=function(t){var e,r,i,o;for(r=1,i=arguments.length;r<i;r++)for(e in o=arguments[r])t[e]=o[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),i=this.scale(e);return this.transformation._transform(r,i)},pointToLatLng:function(t,e){var r=this.scale(e),i=this.transformation.untransform(t,r);return this.projection.unproject(i)},project:function(t){return this.projection.project(t)},unproject:function(t){return this.projection.unproject(t)},scale:function(t){return 256*Math.pow(2,t)},zoom:function(t){return Math.log(t/256)/Math.LN2},getProjectedBounds:function(t){if(this.infinite)return null;var e=this.projection.bounds,r=this.scale(t);return new a(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(e){var r=this.wrapLng?t(e.lng,this.wrapLng,!0):e.lng;return new c(this.wrapLat?t(e.lat,this.wrapLat,!0):e.lat,r,e.alt)},wrapLatLngBounds:function(t){var e=t.getCenter(),r=this.wrapLatLng(e),i=e.lat-r.lat,o=e.lng-r.lng;if(0===i&&0===o)return t;var n=t.getSouthWest(),a=t.getNorthEast();return new u(new c(n.lat-i,n.lng-o),new c(a.lat-i,a.lng-o))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,i=t.lat*r,o=e.lat*r,n=Math.sin((e.lat-t.lat)*r/2),a=Math.sin((e.lng-t.lng)*r/2),s=n*n+Math.cos(i)*Math.cos(o)*a*a,u=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s));return this.R*u}});function c(t,e,r){if(isNaN(t)||isNaN(e))throw new Error("Invalid LatLng object: ("+t+", "+e+")");this.lat=+t,this.lng=+e,void 0!==r&&(this.alt=+r)}function f(t,e,i){return t instanceof c?t:r(t)&&"object"!=typeof t[0]?3===t.length?new c(t[0],t[1],t[2]):2===t.length?new c(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new c(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new c(t,e,i)}c.prototype={equals:function(t,e){return!!t&&(t=f(t),Math.max(Math.abs(this.lat-t.lat),Math.abs(this.lng-t.lng))<=(void 0===e?1e-9:e))},toString:function(t){return"LatLng("+e(this.lat,t)+", "+e(this.lng,t)+")"},distanceTo:function(t){return l.distance(this,f(t))},wrap:function(){return l.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return h([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new c(this.lat,this.lng,this.alt)}};const d=t=>{const e=t.valueOf()/864e5-10957.5,r=6.240059966692059+.017201969994578018*e,i=r+.017453292519943295*(1.9148*Math.sin(r)+.02*Math.sin(2*r)+3e-4*Math.sin(3*r))+1.796593062783907+Math.PI,o=Math.atan2(Math.sin(i)*Math.cos(.40909994067971484),Math.cos(i));return{dec:Math.asin(Math.sin(.40909994067971484)*Math.sin(i)),Hi:(4.889714432387314+6.3003876824396166*e-o)%(2*Math.PI)+2*Math.PI}},m=()=>Math.floor(1e7*Math.random()),_=(t,e,r)=>{const i=1/e,o=Math.min(t[0]*i,255),n=Math.min(t[1]*i,255),a=Math.min(t[2]*i,255);let s=0;return o+n+a!==0&&(s=o>0?o/255*.5+.5:a>0?.5*(1-a/255):.5),s*r},x=(t=new Date,e)=>{const r=new Date(t.toLocaleString("en-US",{timeZone:"UTC"})),i=new Date(t.toLocaleString("en-US",e?{timeZone:e}:{}));return r.getTime()-i.getTime()};const g=t=>{const e=()=>!t.getPitch;return{project:(r,o)=>{if(e())return t.project(r,o);{const{lat:t,lng:e}=r;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*256)(e,o),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*256)(t,o))}},unproject:(r,i)=>{return e()?t.unproject(r,i):new c((o=r.y,n=i,a=Math.PI-2*Math.PI*o/256/Math.pow(2,n),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/256/Math.pow(2,e)*360-180}(r.x,i));var o,n,a},screenUnproject:r=>e()?t.containerPointToLatLng(r):t.unproject(r),getZoom:()=>e()?t.getZoom():t.getZoom()+1,getCenter:()=>t.getCenter(),getBounds:()=>t.getBounds(),eachLayer:r=>{e()&&t.eachLayer(r)},getBearing:()=>e()?0:t.getBearing(),getPitch:()=>e()?0:t.getPitch(),rawMap:()=>t,isLeaflet:e,getPixelDimensions:()=>{const e=t.getContainer();return{width:e.clientWidth,height:e.clientHeight}},createBounds:t=>{const{nw:e,se:r}=t;return new u(e,r)}}};function p(t,e,r,i){return new(r||(r=Promise))((function(o,n){function a(t){try{u(i.next(t))}catch(t){n(t)}}function s(t){try{u(i.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((i=i.apply(t,e||[])).next())}))}function E(t,e,r){r=r||2;var i,o,n,a,s,u,h,l=e&&e.length,c=l?e[0]*r:t.length,f=T(t,0,c,r,!0),d=[];if(!f||f.next===f.prev)return d;if(l&&(f=function(t,e,r,i){var o,n,a,s=[];for(o=0,n=e.length;o<n;o++)(a=T(t,e[o]*i,o<n-1?e[o+1]*i:t.length,i,!1))===a.next&&(a.steiner=!0),s.push(L(a));for(s.sort(w),o=0;o<s.length;o++)r=U(s[o],r);return r}(t,e,f,r)),t.length>80*r){i=n=t[0],o=a=t[1];for(var m=r;m<c;m+=r)(s=t[m])<i&&(i=s),(u=t[m+1])<o&&(o=u),s>n&&(n=s),u>a&&(a=u);h=0!==(h=Math.max(n-i,a-o))?32767/h:0}return y(f,d,r,i,o,h,0),d}function T(t,e,r,i,o){var n,a;if(o===j(t,e,r,i)>0)for(n=e;n<r;n+=i)a=z(n,t[n],t[n+1],a);else for(n=r-i;n>=e;n-=i)a=z(n,t[n],t[n+1],a);return a&&I(a,a.next)&&(H(a),a=a.next),a}function v(t,e){if(!t)return t;e||(e=t);var r,i=t;do{if(r=!1,i.steiner||!I(i,i.next)&&0!==C(i.prev,i,i.next))i=i.next;else{if(H(i),(i=e=i.prev)===i.next)break;r=!0}}while(r||i!==e);return e}function y(t,e,r,i,o,n,a){if(t){!a&&n&&function(t,e,r,i){var o=t;do{0===o.z&&(o.z=D(o.x,o.y,e,r,i)),o.prevZ=o.prev,o.nextZ=o.next,o=o.next}while(o!==t);o.prevZ.nextZ=null,o.prevZ=null,function(t){var e,r,i,o,n,a,s,u,h=1;do{for(r=t,t=null,n=null,a=0;r;){for(a++,i=r,s=0,e=0;e<h&&(s++,i=i.nextZ);e++);for(u=h;s>0||u>0&&i;)0!==s&&(0===u||!i||r.z<=i.z)?(o=r,r=r.nextZ,s--):(o=i,i=i.nextZ,u--),n?n.nextZ=o:t=o,o.prevZ=n,n=o;r=i}n.nextZ=null,h*=2}while(a>1)}(o)}(t,i,o,n);for(var s,u,h=t;t.prev!==t.next;)if(s=t.prev,u=t.next,n?A(t,i,o,n):R(t))e.push(s.i/r|0),e.push(t.i/r|0),e.push(u.i/r|0),H(t),t=u.next,h=u.next;else if((t=u)===h){a?1===a?y(t=b(v(t),e,r),e,r,i,o,n,2):2===a&&M(t,e,r,i,o,n):y(v(t),e,r,i,o,n,1);break}}}function R(t){var e=t.prev,r=t,i=t.next;if(C(e,r,i)>=0)return!1;for(var o=e.x,n=r.x,a=i.x,s=e.y,u=r.y,h=i.y,l=o<n?o<a?o:a:n<a?n:a,c=s<u?s<h?s:h:u<h?u:h,f=o>n?o>a?o:a:n>a?n:a,d=s>u?s>h?s:h:u>h?u:h,m=i.next;m!==e;){if(m.x>=l&&m.x<=f&&m.y>=c&&m.y<=d&&S(o,s,n,u,a,h,m.x,m.y)&&C(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function A(t,e,r,i){var o=t.prev,n=t,a=t.next;if(C(o,n,a)>=0)return!1;for(var s=o.x,u=n.x,h=a.x,l=o.y,c=n.y,f=a.y,d=s<u?s<h?s:h:u<h?u:h,m=l<c?l<f?l:f:c<f?c:f,_=s>u?s>h?s:h:u>h?u:h,x=l>c?l>f?l:f:c>f?c:f,g=D(d,m,e,r,i),p=D(_,x,e,r,i),E=t.prevZ,T=t.nextZ;E&&E.z>=g&&T&&T.z<=p;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=x&&E!==o&&E!==a&&S(s,l,u,c,h,f,E.x,E.y)&&C(E.prev,E,E.next)>=0)return!1;if(E=E.prevZ,T.x>=d&&T.x<=_&&T.y>=m&&T.y<=x&&T!==o&&T!==a&&S(s,l,u,c,h,f,T.x,T.y)&&C(T.prev,T,T.next)>=0)return!1;T=T.nextZ}for(;E&&E.z>=g;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=x&&E!==o&&E!==a&&S(s,l,u,c,h,f,E.x,E.y)&&C(E.prev,E,E.next)>=0)return!1;E=E.prevZ}for(;T&&T.z<=p;){if(T.x>=d&&T.x<=_&&T.y>=m&&T.y<=x&&T!==o&&T!==a&&S(s,l,u,c,h,f,T.x,T.y)&&C(T.prev,T,T.next)>=0)return!1;T=T.nextZ}return!0}function b(t,e,r){var i=t;do{var o=i.prev,n=i.next.next;!I(o,n)&&B(o,i,i.next,n)&&X(o,n)&&X(n,o)&&(e.push(o.i/r|0),e.push(i.i/r|0),e.push(n.i/r|0),H(i),H(i.next),i=t=n),i=i.next}while(i!==t);return v(i)}function M(t,e,r,i,o,n){var a=t;do{for(var s=a.next.next;s!==a.prev;){if(a.i!==s.i&&P(a,s)){var u=G(a,s);return a=v(a,a.next),u=v(u,u.next),y(a,e,r,i,o,n,0),void y(u,e,r,i,o,n,0)}s=s.next}a=a.next}while(a!==t)}function w(t,e){return t.x-e.x}function U(t,e){var r=function(t,e){var r,i=e,o=t.x,n=t.y,a=-1/0;do{if(n<=i.y&&n>=i.next.y&&i.next.y!==i.y){var s=i.x+(n-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(s<=o&&s>a&&(a=s,r=i.x<i.next.x?i:i.next,s===o))return r}i=i.next}while(i!==e);if(!r)return null;var u,h=r,l=r.x,c=r.y,f=1/0;i=r;do{o>=i.x&&i.x>=l&&o!==i.x&&S(n<c?o:a,n,l,c,n<c?a:o,n,i.x,i.y)&&(u=Math.abs(n-i.y)/(o-i.x),X(i,t)&&(u<f||u===f&&(i.x>r.x||i.x===r.x&&F(r,i)))&&(r=i,f=u)),i=i.next}while(i!==h);return r}(t,e);if(!r)return e;var i=G(r,t);return v(i,i.next),v(r,r.next)}function F(t,e){return C(t.prev,t,e.prev)<0&&C(e.next,t,t.next)<0}function D(t,e,r,i,o){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*o|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*o|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function L(t){var e=t,r=t;do{(e.x<r.x||e.x===r.x&&e.y<r.y)&&(r=e),e=e.next}while(e!==t);return r}function S(t,e,r,i,o,n,a,s){return(o-a)*(e-s)>=(t-a)*(n-s)&&(t-a)*(i-s)>=(r-a)*(e-s)&&(r-a)*(n-s)>=(o-a)*(i-s)}function P(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==e.i&&r.next.i!==e.i&&B(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(X(t,e)&&X(e,t)&&function(t,e){var r=t,i=!1,o=(t.x+e.x)/2,n=(t.y+e.y)/2;do{r.y>n!=r.next.y>n&&r.next.y!==r.y&&o<(r.next.x-r.x)*(n-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next}while(r!==t);return i}(t,e)&&(C(t.prev,t,e.prev)||C(t,e.prev,e))||I(t,e)&&C(t.prev,t,t.next)>0&&C(e.prev,e,e.next)>0)}function C(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function I(t,e){return t.x===e.x&&t.y===e.y}function B(t,e,r,i){var o=O(C(t,e,r)),n=O(C(t,e,i)),a=O(C(r,i,t)),s=O(C(r,i,e));return o!==n&&a!==s||(!(0!==o||!N(t,r,e))||(!(0!==n||!N(t,i,e))||(!(0!==a||!N(r,t,i))||!(0!==s||!N(r,e,i)))))}function N(t,e,r){return e.x<=Math.max(t.x,r.x)&&e.x>=Math.min(t.x,r.x)&&e.y<=Math.max(t.y,r.y)&&e.y>=Math.min(t.y,r.y)}function O(t){return t>0?1:t<0?-1:0}function X(t,e){return C(t.prev,t,t.next)<0?C(t,e,t.next)>=0&&C(t,t.prev,e)>=0:C(t,e,t.prev)<0||C(t,t.next,e)<0}function G(t,e){var r=new W(t.i,t.x,t.y),i=new W(e.i,e.x,e.y),o=t.next,n=e.prev;return t.next=e,e.prev=t,r.next=o,o.prev=r,i.next=r,r.prev=i,n.next=i,i.prev=n,i}function z(t,e,r,i){var o=new W(t,e,r);return i?(o.next=i.next,o.prev=i,i.next.prev=o,i.next=o):(o.prev=o,o.next=o),o}function H(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function W(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function j(t,e,r,i){for(var o=0,n=e,a=r-i;n<r;n+=i)o+=(t[a]-t[n])*(t[n+1]+t[a+1]),a=n;return o}function Z(t){t.filter((t=>"MultiPolygon"===t.geometry.type)).forEach((e=>{const{geometry:r,properties:i,type:o}=e;if("MultiPolygon"===r.type)for(let i=0;i<r.coordinates.length;i++)t.push(Object.assign(Object.assign({},e),{geometry:Object.assign(Object.assign({},r),{type:"Polygon",coordinates:r.coordinates[i]})}))}));return t.filter((t=>"Polygon"===t.geometry.type)).map((t=>{const{geometry:e,properties:r}=t,{vertices:i}=E.flatten(e.coordinates),o=new Float32Array(i.map(((t,e)=>{if(e%2==1){const e=t*Math.PI/180;return Math.tan(e)+1/Math.cos(e)}return t}))),n=E(i),a=n.length>256?new Uint16Array(n):new Uint8Array(n),s=function(t){const{height:e=0,levels:r=0,render_height:i=0}=t;if(r)return 3.04*r;return Math.max(e,i)}(r),u=r.highlight||!1;let h=0,l=0,c=0;for(let t=0;t<i.length;t+=2)h+=i[t],l+=i[t+1],c++;return{aPosition:o,cuts:a,buildingHeight:s,centroid:[h/c,l/c],highlight:u}}))}E.deviation=function(t,e,r,i){var o=e&&e.length,n=o?e[0]*r:t.length,a=Math.abs(j(t,0,n,r));if(o)for(var s=0,u=e.length;s<u;s++){var h=e[s]*r,l=s<u-1?e[s+1]*r:t.length;a-=Math.abs(j(t,h,l,r))}var c=0;for(s=0;s<i.length;s+=3){var f=i[s]*r,d=i[s+1]*r,m=i[s+2]*r;c+=Math.abs((t[f]-t[m])*(t[d+1]-t[f+1])-(t[f]-t[d])*(t[m+1]-t[f+1]))}return 0===a&&0===c?0:Math.abs((c-a)/a)},E.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},i=0,o=0;o<t.length;o++){for(var n=0;n<t[o].length;n++)for(var a=0;a<e;a++)r.vertices.push(t[o][n][a]);o>0&&(i+=t[o-1].length,r.holes.push(i))}return r};const Y=(t,e)=>{const{lat:r,lng:o}=t;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*256)(o,e),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*256)(r,e))},K=(t,e)=>{return new c((r=t.y,i=e,o=Math.PI-2*Math.PI*r/256/Math.pow(2,i),180/Math.PI*Math.atan(.5*(Math.exp(o)-Math.exp(-o)))),function(t,e){return t/256/Math.pow(2,e)*360-180}(t.x,e));var r,i,o};let k,q={heightMapTex:null,width:0,height:0,visibleDEMPixelBounds:new a(new i(0,0),new i(0,0)),DEMPixelBounds:new a(new i(0,0),new i(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const V=t=>p(void 0,void 0,void 0,(function*(){const{demZoom:e,getFeatures:r,terrainSource:o,dsmSource:n,tileLoaded:s,gl:h,bounds:l,buildingRasterizer:c,tileMerger:f,forceUpdate:d=!1}=t,{getSourceUrl:m,getElevation:_,maxZoom:x,tileSize:g,_overzoom:E}=o,T=(v={getFeatures:r},p(void 0,void 0,void 0,(function*(){const{getFeatures:t}=v;try{return Z(yield t())}catch(t){console.log("Error merging buildings",t)}return[]})));var v;try{const t=l,r=t.getNorthWest(),o=t.getSouthEast(),p=new a(Y(r,e),Y(o,e));let E=new i(p.min.x,p.min.y),v=p.max.x-p.min.x;const y=p.max.y-p.min.y,R=p.max.subtract(p.min);R.y>R.x&&(E.x-=256,v+=512);const A=(t=>{const{upperLeft:e,width:r,height:i}=t,o=e.divideBy(256).floor().multiplyBy(256),n=256*(Math.ceil(r/256)+1),s=256*(Math.ceil(i/256)+1),u=o.add([n,s]);return new a(o,u)})({upperLeft:E,width:v,height:y}),{x:b,y:M}=A.max.subtract(A.min),w=(t=>{t.sort(((t,e)=>t.y!==e.y?t.y-e.y:t.x-e.x));const e=t.reduce(((t,e)=>e.x<t.x?e:t)).x,r=t.reduce(((t,e)=>e.y<t.y?e:t)).y;return t.map((t=>{const i=Math.pow(2,t.z);return{x:(t.x%i+i)%i,y:(t.y%i+i)%i,z:t.z,xOffset:256*(t.x-e),yOffset:256*(t.y-r)}}))})((t=>{const{upperLeft:e,width:r,height:i,zoom:o}=t,n=e.divideBy(256).floor(),a=n.x+r/256,s=Math.min(n.y+i/256,Math.pow(2,o)-1),u=[];for(var h=n.x;h<a;h++)for(var l=n.y;l<s;l++)u.push({x:h,y:l,z:o});return u})({upperLeft:A.min,width:b,height:M,zoom:e})),U=p.max.x-p.min.x,F=p.max.y-p.min.y,D=Math.round(U),L=Math.round(F),S=JSON.stringify(w);if(!d&&S===k&&e<x)return q=Object.assign(Object.assign({},q),{outputWidth:D,outputHeight:L,visibleDEMPixelBounds:p,demZoom:e,dirty:!0}),q;const P=yield f.merge(w,{maxZoom:x,width:b,height:M,crossOrigin:"Anonymous",getSourceUrl:m,getElevation:_,tileSize:g,tileLoaded:s});if(null===P)return q=Object.assign(Object.assign({},q),{visibleDEMPixelBounds:p,demZoom:e,dirty:!1}),q;const C=new a(Y(new u(n.bounds).getNorthWest(),e),Y(new u(n.bounds).getSouthEast(),e)),I=C.min.subtract(A.min),B=C.max.subtract(A.min),N=[I.x/b,I.y/M,B.x/b,B.y/M].map((t=>2*t-1)),O=yield T,{maxHeight:X,heightMapTex:G}=c.raster({upperLeftTile:w[0],width:b,height:M,mapZoom:e,features:O,imageData:P,gl:h,dsmSource:n,dsmCoords:N}),z=Math.max(Math.max(n.maxHeight,X),P.maxHeight);k=S,q={heightMapTex:G,maxHeight:z,width:b,height:M,DEMPixelBounds:A,visibleDEMPixelBounds:p,raster:w,demZoom:e,dirty:!0,outputWidth:D,outputHeight:L}}catch(t){console.error("Could not decode height map",t)}return q})),$=(t,e)=>{const{r:r,g:i,b:o}=t;return[r/255,i/255,o/255,e]},J=(t,e)=>{const{date:r}=e,{dec:i,Hi:o}=d(r);t.updateDate({dec:i,Hi:o})},Q=(t,e)=>p(void 0,void 0,void 0,(function*(){return yield t.updateDateRange(Object.assign({},e))})),tt=(t,e)=>{const{color:r,opacity:i}=e,o=$(r,i);t.updateColor({colorVec:o})};new u([0,0],[0,0]);const et=t=>{const{kernel:e,map:r,heightMap:i,now:o,color:n,opacity:a,belowCanopy:s}=t;try{const{heightMapTex:t,outputHeight:h,outputWidth:l,maxHeight:c,width:f,height:m,DEMPixelBounds:_,visibleDEMPixelBounds:x,demZoom:g}=i;if(0===f||0===m)return;const{min:p,max:E}=x;if(!p||!E)return;const{x:T,y:v}=E.subtract(p),y=_.min,R=r.getPixelDimensions(),A=r.screenUnproject([0,0]),b=r.screenUnproject([R.width,0]),M=r.screenUnproject([R.width,R.height]),w=r.screenUnproject([0,R.height]),U=[w,M,A,b].map((t=>r.project(t,g))),F=U.map((t=>[(t.x-y.x)/f,(t.y-y.y)/m])).flat(),D=U.map((t=>[(t.x-p.x)/T,(t.y-p.y)/v])).map((t=>[2*t[0]-1,(2*t[1]-1)*(r.isLeaflet()?-1:1)])).flat(),L=y.y/256/Math.pow(2,g),S=m/256/Math.pow(2,g),P=new u(K(_.getTopLeft(),g),K(_.getBottomRight(),g)),C=P.getWest(),I=Math.abs(P.getWest()-P.getEast());((t,e)=>{const{color:r,opacity:i,date:o}=e,n=$(r,i),{dec:a,Hi:s}=d(o);t.updateLocation(Object.assign({dec:a,Hi:s,colorVec:n,step:1},e))})(e,{heightMapTex:t,maxHeight:c,width:f,height:m,heightMapZoom:g,cornerTextureCoords:F,cornerClipCoords:D,topYCoord:L,ySize:S,west:C,dLng:I,date:o,color:n,opacity:a,outputHeight:h,outputWidth:l,belowCanopy:s})}catch(t){console.error("EXCEPTION",t)}};const rt=t=>{const{gl:e}=t,{texture:r,imageData:i=null,format:o=e.RGBA,width:n,height:a,filter:s=e.NEAREST,wrap:u=e.CLAMP_TO_EDGE,type:h=e.UNSIGNED_BYTE,internalFormat:l=o}=t;e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,s),e.texImage2D(e.TEXTURE_2D,0,l,n,a,0,o,h,i)};function it(t){const{gl:e,vSrc:r,fSrc:i}=t,o=e.createShader(e.VERTEX_SHADER);e.shaderSource(o,r),e.compileShader(o);const n=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,i),e.compileShader(n);const a=e.createProgram();return e.attachShader(a,o),e.attachShader(a,n),e.linkProgram(a),a}class ot{constructor(t){this.gl=t,this.program=it({gl:t,vSrc:"\nuniform vec3 xyz;\nuniform vec2 dimensions;\nuniform bool use_dsm;\nattribute vec2 dsm_position;\nattribute vec2 a_position;\nfloat PI = 3.141592653589793;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\n\tvoid main() {\n\t\tif (use_dsm == true) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = dsm_position;\n v_use_dsm = 1.0;\n\t\t\treturn;\n\t\t}\n\t\tif (abs(a_position) == vec2(1,1)) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = a_position * 0.5 + 0.5;\n\t\t\treturn;\n\t\t}\n\t\tfloat x = ((a_position.x + 180.0) / 360.0 * pow(2.0, xyz.z)) * 256.0 - xyz.x;\n\t\tfloat y = (1.0 - (log(a_position.y) / PI)) / 2.0 * pow(2.0, xyz.z) * 256.0 - xyz.y;\n\t\tvec2 transformed = vec2(x, y);\n\t\tvec2 normalized = transformed / dimensions;\n\t\tvec2 final = normalized * 2.0 - 1.0;\n\t\tgl_Position = vec4(final, 0, 1);\n\t}\n",fSrc:"\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform vec4 color;\nuniform sampler2D height_map;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n if (v_use_dsm == 1.0) {\n\t \t gl_FragColor = vec4(0.0, 0.0, textureColor.b, textureColor.a);\n if (gl_FragColor.zw == vec2(0.0)) {\n discard;\n }\n } else {\n gl_FragColor = vec4(textureColor.b, textureColor.a, textureColor.b, textureColor.a);\n }\n // DSM noData values should not be included in heightMap because they produce ugly borders\n\t\treturn;\n\t} \n\tgl_FragColor = color;\n}\n"}),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.dsmAttributeLocation=t.getAttribLocation(this.program,"dsm_position"),this.useDSMUniformLocation=t.getUniformLocation(this.program,"use_dsm"),this.xyzUniformLocation=t.getUniformLocation(this.program,"xyz"),this.dimensionsUniformLocation=t.getUniformLocation(this.program,"dimensions"),this.heightMapUniformLocation=t.getUniformLocation(this.program,"height_map"),this.colorUniformLocation=t.getUniformLocation(this.program,"color"),this.positionBuffer=t.createBuffer(),this.dsmBuffer=t.createBuffer(),this.indexBuffer=t.createBuffer(),this.targetTexture=t.createTexture()}raster(t){const{features:e,upperLeftTile:r,mapZoom:o,width:n,height:a,imageData:s,dsmCoords:u,dsmSource:h,gl:l}=t,{x:c,y:f,z:d}=r;let m=0;l.useProgram(this.program),l.activeTexture(l.TEXTURE1);const _=l.createTexture();l.bindTexture(l.TEXTURE_2D,_),l.pixelStorei(l.UNPACK_ALIGNMENT,2),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.LUMINANCE_ALPHA,n,a,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,s),l.pixelStorei(l.UNPACK_ALIGNMENT,4);const x=n,g=a;l.activeTexture(l.TEXTURE0),l.bindTexture(l.TEXTURE_2D,this.targetTexture),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,x,g,0,l.RGBA,l.UNSIGNED_BYTE,null),o>15&&e.length>5?(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST)):(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.LINEAR)),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.viewport(0,0,x,g);const p=l.createFramebuffer();l.bindFramebuffer(l.FRAMEBUFFER,p);const E=l.COLOR_ATTACHMENT0;l.framebufferTexture2D(l.FRAMEBUFFER,E,l.TEXTURE_2D,this.targetTexture,0),l.disable(l.BLEND),l.bindBuffer(l.ARRAY_BUFFER,this.positionBuffer),l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,this.indexBuffer),l.clearColor(0,0,0,0),l.clear(l.COLOR_BUFFER_BIT);const T=256*c,v=256*f,y=new i(T,v);l.uniform3f(this.xyzUniformLocation,T,v,d),l.uniform2f(this.dimensionsUniformLocation,n,a),l.uniform1i(this.heightMapUniformLocation,1),l.uniform1i(this.useDSMUniformLocation,0);const R=new Float32Array([-1,-1,1,-1,-1,1,1,1]);if(l.enableVertexAttribArray(this.positionAttributeLocation),l.bufferData(l.ARRAY_BUFFER,R,l.STATIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.uniform4f(this.colorUniformLocation,0,0,0,0),l.drawArrays(l.TRIANGLE_STRIP,0,4),e.forEach((t=>{const{buildingHeight:e,aPosition:r,cuts:i,centroid:o,highlight:u}=t,h=Y({lng:o[0],lat:o[1]},d).subtract(y).floor();if(h.x<0||h.y<0||h.x>n||h.y>a)return;const c=256*s[h.y*n*2+2*h.x]+s[h.y*n*2+2*h.x+1]+5*e,f=Math.floor(c/256)/255,_=Math.floor(c%256)/255;m=Math.max(m,c/5),l.uniform4f(this.colorUniformLocation,f,_,f,_),l.bufferData(l.ARRAY_BUFFER,r,l.DYNAMIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.bufferData(l.ARRAY_BUFFER,r,l.DYNAMIC_DRAW),l.vertexAttribPointer(this.dsmAttributeLocation,2,l.FLOAT,!1,0,0),l.bufferData(l.ELEMENT_ARRAY_BUFFER,i,l.DYNAMIC_DRAW),l.drawElements(l.TRIANGLES,i.length,i.length>256?l.UNSIGNED_SHORT:l.UNSIGNED_BYTE,0)})),l.deleteTexture(_),0!==h.data.length){l.activeTexture(l.TEXTURE1);const t=l.createTexture();l.bindTexture(l.TEXTURE_2D,t),l.pixelStorei(l.UNPACK_ALIGNMENT,2),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.LUMINANCE_ALPHA,h.width,h.height,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,h.data),l.pixelStorei(l.UNPACK_ALIGNMENT,4);const e=[u[0],u[3],u[2],u[3],u[0],u[1],u[2],u[1]],r=new Float32Array(e);l.enableVertexAttribArray(this.positionAttributeLocation),l.bufferData(l.ARRAY_BUFFER,r,l.STATIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.enableVertexAttribArray(this.dsmAttributeLocation),l.bindBuffer(l.ARRAY_BUFFER,this.dsmBuffer),l.bufferData(l.ARRAY_BUFFER,new Float32Array([0,1,1,1,0,0,1,0]),l.STATIC_DRAW),l.vertexAttribPointer(this.dsmAttributeLocation,2,l.FLOAT,!1,0,0),l.uniform4f(this.colorUniformLocation,0,0,0,0),l.uniform1i(this.useDSMUniformLocation,1),l.colorMask(!1,!1,!0,!0),l.drawArrays(l.TRIANGLE_STRIP,0,4),l.deleteTexture(t)}return l.colorMask(!0,!0,!0,!0),l.deleteFramebuffer(p),{maxHeight:m,heightMapTex:this.targetTexture}}}const nt=t=>{const{tile:e,maxZoom:r,tileSize:i}=t;let{x:o,y:n,z:a}=e;if(a>r){const t=Math.pow(2,e.z-r);o=Math.floor(o/t),n=Math.floor(n/t),a=r}return{x:256===i?o:Math.floor(o/2),y:256===i?n:Math.floor(n/2),z:256===i?a:a-1}};class at{constructor(t){this.gl=t,this.program=it({vSrc:"\n attribute vec4 a_position;\n varying vec2 v_pos;\n void main() {\n v_pos = ((a_position + 1.0) * 0.5).xy;\n gl_Position = a_position;\n }\n",fSrc:"\n precision mediump float;\n varying vec2 v_pos;\n uniform sampler2D u_texture;\n void main() {\n gl_FragColor = texture2D(u_texture, v_pos);\n }\n",gl:t}),t.useProgram(this.program),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.positionBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(this.positionAttributeLocation),t.vertexAttribPointer(this.positionAttributeLocation,2,t.FLOAT,!1,0,0),this.tileTexture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.tileTexture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),this.outputTexture=t.createTexture(),this.framebuffer=t.createFramebuffer(),this.inProgress=[],this.finished=0}merge(t,e){return p(this,void 0,void 0,(function*(){const r=this.gl,{width:i,height:o,crossOrigin:n,getSourceUrl:a,getElevation:s,tileSize:u,tileLoaded:h,maxZoom:l}=e;if(r){const e=new Uint8ClampedArray(2*i*o);e.maxHeight=0,this.inProgress.forEach((t=>t.src="")),this.inProgress=[],this.finished=0;const c=new Set;t.forEach((t=>{c.add(a(nt({tile:t,maxZoom:l,tileSize:u})))}));const f=Array.from(c).map((o=>p(this,void 0,void 0,(function*(){return new Promise(((h,c)=>{const f=new Image;this.inProgress.push(f),f.onload=()=>{t.filter((t=>o===a(nt({tile:t,maxZoom:l,tileSize:u})))).forEach((t=>{let o=0,n=0;const a=514===u?1:0;let h=0,c=256,d=256;if(256!==u&&(o=t.x%2*256,n=t.y%2*256,c=256,d=256),t.z>l){const e=Math.pow(2,t.z-l);256!==u&&(o=Math.floor(t.x/e)%2*256,n=Math.floor(t.y/e)%2*256),o+=t.x%e/e*256,n+=t.y%e/e*256,c=256/e,d=256/e,h=514===u?1:0}r.useProgram(this.program),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.tileTexture),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,f),r.activeTexture(r.TEXTURE1),rt({gl:r,texture:this.outputTexture,imageData:null,format:r.RGBA,width:u,height:u,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST}),r.bindFramebuffer(r.FRAMEBUFFER,this.framebuffer),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,this.outputTexture,0);const m=r.checkFramebufferStatus(r.FRAMEBUFFER);m!==r.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+m),r.bindBuffer(r.ARRAY_BUFFER,this.positionBuffer),r.enableVertexAttribArray(this.positionAttributeLocation),r.vertexAttribPointer(this.positionAttributeLocation,2,r.FLOAT,!1,0,0),r.viewport(0,0,u,u),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4);const _=new Uint8Array(4*(c+h)*(d+h));r.readPixels(a+o,a+n,c+h,d+h,r.RGBA,r.UNSIGNED_BYTE,_),r.bindFramebuffer(r.FRAMEBUFFER,null);const x=new Uint8ClampedArray(131072);let g=new Array((c+h)*(d+h)),p=256/c;for(let t=0;t<_.length;t+=4){const r=s({r:_[t],g:_[t+1],b:_[t+2],a:_[t+3]});e.maxHeight=Math.max(r,e.maxHeight);const i=5*(r||0);g[t/4]=i}if(p>1&&514===u)for(g=function(t,e,r,i){const o=Math.floor(e*i),n=Math.floor(r*i),a=[];for(let s=0;s<n;s++)for(let n=0;n<o;n++){const o=n/i,u=s/i,h=Math.floor(o),l=Math.floor(u),c=Math.min(h+1,e-1),f=Math.min(l+1,r-1),d=o-h,m=u-l,_=l*e+c,x=f*e+h,g=f*e+c,p=t[l*e+h]*(1-d)*(1-m)+t[_]*d*(1-m)+t[x]*(1-d)*m+t[g]*d*m;a.push(p)}return function(t,e,r,i,o){if(i>=e||o>=r)return[];const n=e-i,a=r-o,s=[];for(let r=0;r<a;r++)for(let i=0;i<n;i++){const o=r*e+i;s.push(t[o])}return s}(a,Math.sqrt(a.length),Math.sqrt(a.length),i,i)}(g,c+1,d+1,p);p>1;)p/=2,d*=2,c*=2;for(let t=0;t<x.length;t+=2){const e=g[Math.floor(t/2/256/p)*c+Math.floor(t/2%256/p)],r=Math.floor(e/256),i=Math.floor(e%256);x[t]=r,x[t+1]=i}for(let r=0;r<256;r++)e.set(x.slice(256*r*2,256*(r+1)*2),2*(t.yOffset*i+r*i+t.xOffset))})),h(null)},f.onerror=t=>{if(f.src!==f.originalSource)return c("new tiles requested");h(null)},f.crossOrigin=n||null,f.src=o,f.originalSource=f.src})).then((()=>{this.finished++,h(this.finished,this.inProgress.length)}))}))));try{yield Promise.all(f)}catch(t){return console.log(`${f.length} requests aborted`,t),null}return this.inProgress=[],e}throw new Error("Could not get canvas context for merging tile images")}))}}class st extends class extends class{constructor(){this.events={}}on(t,e){return"object"!=typeof this.events[t]&&(this.events[t]=[]),this.events[t].push(e),()=>this.removeListener(t,e)}removeListener(t,e){if("object"!=typeof this.events[t])return;const r=this.events[t].indexOf(e);r>-1&&this.events[t].splice(r,1)}removeAllListeners(){Object.keys(this.events).forEach((t=>this.events[t].splice(0,this.events[t].length)))}emit(t,...e){"object"==typeof this.events[t]&&[...this.events[t]].forEach((t=>t.apply(this,e)))}once(t,e){const r=this.on(t,((...t)=>{r(),e.apply(this,t)}));return r}}{constructor(...t){super(),this.options={date:new Date,color:"000",opacity:.3,sunExposure:{enabled:!1,startDate:new Date,endDate:new Date,iterations:32},apiKey:"",terrainSource:{maxZoom:15,tileSize:256,_overzoom:15,getSourceUrl:t=>"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/7/17/45.png",getElevation:t=>{const{r:e,g:r,b:i}=t;return 256*e+r+i/256-32768}},dsmSource:{bounds:[{lat:0,lng:0},{lat:0,lng:0}],data:new Uint8ClampedArray,width:0,height:0,maxHeight:0},belowCanopy:!1,getFeatures:()=>Promise.resolve([]),getSize:()=>({width:Number.NaN,height:Number.NaN}),debug:t=>{}};const e=t[0];if(this.options=Object.assign(this.options,e),!this.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:this.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((t=>p(this,void 0,void 0,(function*(){if(200!==t.status)throw new Error(yield t.text())})))).catch((t=>p(this,void 0,void 0,(function*(){throw new Error(`Could not load ShadeMap API. Key: ${this.options.apiKey} Error: ${t}`)})))),this._canvas=document.createElement("canvas"),this._color=this._parseColor(this.options.color),this._reset=this._reset.bind(this),this._draw=this._draw.bind(this)}onRemove(){return this._map&&this._map.off("moveend",this._reset),this}setDate(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(J(this._compiledKernel,{date:this.options.date}),this._flush())):this.emit("idle"),this}_setDateForTimezone(t,e){let r=0;e&&(r=x(this.options.date)-x(this.options.date,e)),this.setDate(new Date(t.getTime()-r))}setColor(t){return this.options.color!==t&&(this.options.color=t,this._color=this._parseColor(this.options.color),this._compiledKernel&&(tt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setOpacity(t){return this.options.opacity!==t&&(this.options.opacity=t,this._compiledKernel&&(tt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setBelowCanopy(t){return this.options.belowCanopy=t,this._heightMap?this._draw(this._heightMap):this._reset(),this}setTerrainSource(t){return this.options.terrainSource=t,delete this._heightMap,this._reset(),this}setDSMSource(t){return this.options.dsmSource=t,delete this._heightMap,this._reset(),this}setSunExposure(t=!1,e){return p(this,void 0,void 0,(function*(){if(this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:t}),e){const{startDate:r=new Date,endDate:i=new Date,iterations:o=32}=e;this.options.sunExposure={enabled:t,startDate:r,endDate:i,iterations:o}}if(this._map&&this._compiledKernel&&this._heightMap){if(!1===t)J(this._compiledKernel,{date:this.options.date});else{const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!(t instanceof Date&&e instanceof Date))throw new Error("Start date or end date or both are missing");if(e.getTime()<t.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield Q(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._flush()}return this}))}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:i,height:o}=this._heightMap,n=e.min;return t.map((t=>{const e=Y(t,r);return[(e.x-n.x)/i,(e.y-n.y)/o]}))}return[]}_getBounds(t,e){const{width:r,height:o}=this.options.getSize();if(Number.isNaN(r)||Number.isNaN(o))return t.getBounds();const n=t.getCenter(),a=Y(n,e),s=K(new i(a.x-r/2,a.y-o/2),e),u=K(new i(a.x+r/2,a.y+o/2),e);return t.createBounds({nw:s,se:u})}_getDEMZoom(t){const e=Math.min(this.options.terrainSource._overzoom||this.options.terrainSource.maxZoom,t.getZoom());return Math.round(e)}_reset(){return p(this,void 0,void 0,(function*(){if(this.options.debug("_reset()"),this._map){const t=g(this._map);let e=this._getDEMZoom(t);try{this._bounds=this._getBounds(t,e)}catch(t){return console.error("Invalid bounds returned: ",t),this}try{if(!t.isLeaflet()&&this._map.getPitch()>45){yield new Promise((t=>{this._map.loaded()?t(!0):this._map.once("idle",(function(){t(!0)}))}));const r=this._map.style._sourceCaches["other:composite"].getVisibleCoordinates().reverse(),o=r.reduce(((t,e)=>Math.max(t,e.canonical.z)),Number.MIN_SAFE_INTEGER),n=r.filter((t=>t.canonical.z===o)).map((t=>t.canonical)),[a,s,u,h]=n.reduce(((t,e)=>[Math.min(t[0],e.x),Math.min(t[1],e.y),Math.max(t[2],e.x),Math.max(t[3],e.y)]),[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER]),l=K(new i(512*a,512*s),o+1),c=K(new i(512*(u+1),512*(h+1)),o+1);e=o+1,this._bounds=t.createBounds({nw:l,se:c})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield V({gl:this._gl,demZoom:e,bounds:this._bounds,terrainSource:this.options.terrainSource,dsmSource:this.options.dsmSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,tileLoaded:(t,e)=>this.emit("tileloaded",t,e),forceUpdate:!this._heightMap});this._heightMap=r,r.dirty&&(yield this._draw(r))}return this}))}_draw(t){return p(this,void 0,void 0,(function*(){if(this.options.debug("_draw()"),this._canvas&&this._compiledKernel&&this._map){if(et({kernel:this._compiledKernel,map:g(this._map),heightMap:t,color:this._color,belowCanopy:this.options.belowCanopy,opacity:this.options.opacity,now:this.options.date,maxZoom:this.options.terrainSource.maxZoom}),this.options.sunExposure.enabled){const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!0===(yield Q(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._bounds&&this._repositionCanvas(this._bounds)}return this}))}readPixel(t,e){const r=new Uint8Array(4);return this._gl&&this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r),r}readPixels(t,e,r,i){const o=new Uint8Array(r*i*4);return this._gl&&this._gl.readPixels(t,e,r,i,this._gl.RGBA,this._gl.UNSIGNED_BYTE,o),o}toGeoTiff(){const t=(t,e)=>{const r=this.readPixels(0,0,t,e),i=t*e*1,o=1*t,n=(e-1)*o,a=new Uint8Array(i),s=new Uint8Array(i);let u=0;const{startDate:h,endDate:l}=this.options.sunExposure;this.options.sunExposure.enabled&&h&&l&&(u=l.getTime()-h.getTime());for(let t=0;t<r.length;t+=4){let e;if(this.options.sunExposure.enabled){const i=r.subarray(t,t+3),o=_(i,.5,u)/1e3/60,n=Math.min(Math.floor(o/6),255);e=new Uint8Array([n])}else{e=r[t]+r[t+1]+r[t+2]===0?new Uint8Array([255]):new Uint8Array([0])}a.set(e,t/4*1)}if(this._map&&!g(this._map).isLeaflet())return a;for(let t=0;t<i;t+=o)s.set(a.subarray(t,t+o),n-t);return s};if(this._map&&this._heightMap){const e=this._heightMap.outputWidth,r=this._heightMap.outputHeight,i=t(e,r),o=g(this._map),{lat:n,lng:a}=o.getBounds().getNorthWest(),s=o.getBounds().getSouthEast(),u=[0,0,0,a,n,0],h=[(s.lng-a)/e,(n-s.lat)/r,0];return this.options.sunExposure.enabled,{data:i,metadata:{width:e,height:r,ModelTiepoint:u,ModelPixelScale:h,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}return null}_generateShadeProfile(t){if(this._compiledKernel){const e=this._lngLatToTextureCoords(t.locations);return((t,e)=>{const r=$({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=$({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{texCoords:e}))}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=x(t.startDate)-x(t.startDate,t.tzId),r=t.startDate.getTime()-e,i=(t.endDate.getTime()-e-r)/86400/1e3,o=1440,n=[],a=828e5,s=x(new Date(r),t.tzId);for(let e=0;e<i;e++){const i=x(new Date(r+86400*e*1e3+a),t.tzId)-s;n[e]=i}const u=[];for(let t=0;t<o;t++){const e=[];for(let o=0;o<i;o++){const i=r+86400*o*1e3+60*t*1e3;e.push(new Date(i+n[o]))}u.push(e)}const h=this._lngLatToTextureCoords([t.location])[0],l=((t,e)=>{const r=$({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=$({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateLocationShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{dates:u,texCoord:h}));return l.toArray=function(){const e=new Array;for(let r=0;r<i;r++){const n=[];for(let e=o-1;e>=0;e--){const o=e*i*4+4*r,a=this.slice(o,o+4);n.push(a.join("")===t.sunColor.join("")?1:0)}e.push(n)}return e},{data:l,width:i,height:o}}return{data:new Uint8Array,width:0,height:0}}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this.readPixel(t,e),{startDate:i,endDate:o}=this.options.sunExposure,n=o.getTime()-i.getTime(),a=_(r,.5,n);return Math.abs(a/1e3/3600)}return 0}_repositionCanvas(t){}_flush(){}flushSync(){this._gl&&this._gl.finish()}_parseColor(t){t=t.replace("#","");const e={r:0,g:0,b:0};return/^([0-9A-F]{3}){1,2}$/i.test(t)&&(3===t.length?(e.r=parseInt(t[0]+t[0],16),e.g=parseInt(t[1]+t[1],16),e.b=parseInt(t[2]+t[2],16)):6===t.length&&(e.r=parseInt(t[0]+t[1],16),e.g=parseInt(t[2]+t[3],16),e.b=parseInt(t[4]+t[5],16))),e}}{constructor(t){super(t),this.id="shademap-layer",this.type="custom",this.canvasSourceId="canvas-source",this.attributionSourceId="attribution-source",this.canvasLayerId="canvas-layer",this.attributionLayerId="attribution-layer",this._refreshing=0,this._raf=0,this.id=this.id+m(),this.canvasSourceId=this.canvasSourceId+m(),this.attributionSourceId=this.attributionSourceId+m(),this.canvasLayerId=this.canvasLayerId+m(),this.attributionLayerId=this.attributionLayerId+m(),this.options.terrainSource.tileSize>256&&(this.options.terrainSource.maxZoom=this.options.terrainSource.maxZoom+1),this._moveEndHandler=()=>{this._map&&this._reset()}}render(t,e){}addTo(t){return t.addLayer(this),this}onAdd(t){this._map=t,this._gl=this._map.painter.context.gl,this._framebuffer=this._gl.createFramebuffer();this._compiledKernel=function(t){const{context:e,setRenderBuffer:r}=t,i=e,o=it({gl:i,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 a_pos;attribute vec2 a_tex_pos;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;void main(void){gl_Position=vec4(a_pos,0,1);vTexCoordFull=(gl_Position*0.5+0.5).xy;vTexCoordCropped=a_tex_pos;}",fSrc:"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nprecision lowp int;precision lowp sampler2D;float atan2(float v1,float v2){if(v1==0.0||v2==0.0)return 0.0;return atan(v1,v2);}float _pow(float v1,float v2){if(v2==0.0)return 1.0;return pow(v1,v2);}float integerMod(float x,float y){float res=floor(mod(x,y));return res*(res>floor(y)-1.0 ? 0.0 : 1.0);}float divWithIntCheck(float x,float y){if(floor(x)==x&&floor(y)==y&&integerMod(x,y)==0.0){return float(int(x)/int(y));}return x/y;}float integerCorrectionModulo(float number,float divisor){if(number<0.0){number=abs(number);if(divisor<0.0){divisor=abs(divisor);}return-(number-(divisor*floor(divWithIntCheck(number,divisor))));}if(divisor<0.0){divisor=abs(divisor);}return number-(divisor*floor(divWithIntCheck(number,divisor)));}float getDEMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*255.0*256.0+result.g*255.0)/5000.0;}float getDSMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.b*255.0*256.0+result.a*255.0)/5000.0;}vec4 actualColor;void color(float r,float g,float b,float a){actualColor=vec4(r,g,b,a);}void color(float r,float g,float b){color(r,g,b,1.0);}void color(float r){color(r,r,r,1.0);}void color(vec4 color){actualColor=color;}const int LOOP_MAX=1000;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;uniform sampler2D user_a;uniform float user_width;uniform float user_height;uniform float user_maxHeight;uniform float user_zoom;uniform float user_topYCoord;uniform float user_ySize;uniform vec4 user_color;uniform vec4 u_sunColor;uniform float user_step;uniform float user_west;uniform float user_dLng;uniform float user_dec;uniform float user_Hi;uniform bool u_below_canopy;uniform sampler2D user_sunExposureTexture;uniform bool user_renderToSunExposureTexture;uniform bool user_outputSunExposure;uniform vec4 user_exposureDelta;uniform bool u_outputShadeProfile;uniform sampler2D u_decHiTexture;uniform sampler2D u_gpxTexture;uniform bool u_outputLocationShadeProfile;uniform vec2 u_shadeProfileLocation;float kernelResult;void kernel(){float sunDec=user_dec;float sunHi=user_Hi;vec4 shade_color=user_color;float maxHeight=user_maxHeight/1000.0;float user_x=vTexCoordCropped.x;float user_y=vTexCoordCropped.y;if(u_outputShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;vec4 gpx=texture2D(u_gpxTexture,vec2(vTexCoordFull.x,.5));user_x=gpx.x;user_y=gpx.y;}if(u_outputLocationShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;user_x=u_shadeProfileLocation.x;user_y=u_shadeProfileLocation.y;}float user_lit=1.0;float dsm_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(u_below_canopy==true){float dem_height=getDEMElevationFromSampler2D(user_a,user_x,user_y);if(dsm_height-dem_height>.002){user_lit=0.0;}}float user_z=dsm_height;float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=user_west+(user_dLng*user_x);float user_H=integerCorrectionModulo((sunHi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(sunDec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(sunDec))+((cos(user_lat)*cos(sunDec))*cos(user_H))));float user_zoom_factor=_pow(2.0,user_zoom);float user_kmPerPixel=divWithIntCheck(156.5430339296875,user_zoom_factor)*abs(cos(user_lat));float user_dx=((-sin(sun_azimuth)*cos(sun_altitude))*user_step)/user_width;float user_dy=((cos(sun_azimuth)*cos(sun_altitude))*user_step)/user_height;float user_dz=((sin(sun_altitude)*user_kmPerPixel)*user_step);float shadow_bias=0.0005;float user_curvature=0.0;float cur_height=0.0;float user_distance=0.0;float user_startX=user_x;float user_startY=user_y;user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;if((abs(1.0)<0.0)){kernelResult=0.0;return;}float minAngle=asin((earthRadiusInKm/(earthRadiusInKm+user_z)))-(user_PI/2.0);if(user_z<0.0||sun_altitude<minAngle){user_lit=0.0;}else{float xIter=ceil(user_dx<0.0 ? abs(user_x/user_dx):(1.0-user_x)/user_dx);float yIter=ceil(user_dy<0.0 ? abs(user_y/user_dy):(1.0-user_y)/user_dy);float zIter=ceil(user_dz<0.0 ? float(LOOP_MAX):(maxHeight-user_z)/user_dz);int iter=int(min(xIter,min(yIter,zIter)));float user_distance=(sqrt(pow(user_dx*user_width,2.0)+pow(user_dy*user_height,2.0))*user_kmPerPixel)/earthRadiusInKm;for(int safeI=0;safeI<LOOP_MAX;safeI++){if(safeI>iter){break;}cur_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(cur_height-user_z>shadow_bias){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;vec4 result=texture2D(user_a,vec2(user_x,user_y));iter=0;break;}}user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;}}if((user_lit==1.0)){if(u_outputLocationShadeProfile==true&&u_sunColor==shade_color){float timeInSun=pow(.7,pow(sin(sun_altitude),.678))*sin(sun_altitude)*(1.0/0.7);float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,1.0);}else{color(u_sunColor);}}else{color(shade_color);}if(user_renderToSunExposureTexture){vec4 aggregateColor=texture2D(user_sunExposureTexture,vec2(vTexCoordFull.x,vTexCoordFull.y));if((user_lit==1.0)){color(aggregateColor.r,0.0,0.0,1.0);}else{color(aggregateColor.r+user_exposureDelta.r,0.0,0.0,1.0);}if(user_outputSunExposure){float timeInSun=1.0-aggregateColor.r;float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,0.5);}}}void main(void){kernel();gl_FragColor=actualColor;}"});i.useProgram(o);const n=i.createBuffer(),a=i.getAttribLocation(o,"a_pos"),s=i.createBuffer(),u=i.getAttribLocation(o,"a_tex_pos"),h=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,h),i.bufferData(i.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),i.STATIC_DRAW);const l=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,l),i.bufferData(i.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),i.STATIC_DRAW);const c=i.getUniformLocation(o,"user_a");i.uniform1i(c,0);const f=i.getUniformLocation(o,"user_width"),m=i.getUniformLocation(o,"user_height"),_=i.getUniformLocation(o,"user_maxHeight"),x=i.getUniformLocation(o,"user_zoom"),g=i.getUniformLocation(o,"user_topYCoord"),E=i.getUniformLocation(o,"user_ySize"),T=i.getUniformLocation(o,"user_step"),v=i.getUniformLocation(o,"user_west"),y=i.getUniformLocation(o,"user_dLng"),R=i.getUniformLocation(o,"user_dec"),A=i.getUniformLocation(o,"user_Hi"),b=i.getUniformLocation(o,"user_color"),M=i.getUniformLocation(o,"user_xStart"),w=i.getUniformLocation(o,"user_yStart"),U=i.getUniformLocation(o,"user_xEnd"),F=i.getUniformLocation(o,"user_yEnd"),D=i.getUniformLocation(o,"u_below_canopy"),L=i.getUniformLocation(o,"user_sunExposureTexture"),S=i.getUniformLocation(o,"user_renderToSunExposureTexture"),P=i.getUniformLocation(o,"user_outputSunExposure"),C=i.getUniformLocation(o,"user_exposureDelta"),I=i.getUniformLocation(o,"u_outputShadeProfile"),B=i.getUniformLocation(o,"u_gpxTexture"),N=i.getUniformLocation(o,"u_decHiTexture"),O=i.getUniformLocation(o,"u_sunColor"),X=i.getUniformLocation(o,"u_outputLocationShadeProfile"),G=i.getUniformLocation(o,"u_shadeProfileLocation");let z=0,H=0,W=0,j=null;const Z=()=>{H&&W&&(i.useProgram(o),i.bindBuffer(i.ARRAY_BUFFER,n),i.enableVertexAttribArray(a),i.vertexAttribPointer(a,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,s),i.enableVertexAttribArray(u),i.vertexAttribPointer(u,2,i.FLOAT,!1,0,0),null!==j&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,j)),r(i,H,W),i.viewport(0,0,H,W),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4))};let Y=0;return{updateLocation:function(t){const{heightMapTex:e,width:r,height:a,maxHeight:u,heightMapZoom:h,topYCoord:l,ySize:c,colorVec:d,step:p,west:M,dLng:w,dec:U,Hi:F,cornerClipCoords:L,cornerTextureCoords:S,outputWidth:P,outputHeight:C,belowCanopy:I}=t;i.useProgram(o),H=P,W=C,j=e,i.bindBuffer(i.ARRAY_BUFFER,n),i.bufferData(i.ARRAY_BUFFER,new Float32Array(L),i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,s),i.bufferData(i.ARRAY_BUFFER,new Float32Array(S),i.STATIC_DRAW),i.uniform1f(f,r),i.uniform1f(m,a),i.uniform1f(_,u),i.uniform1f(x,h),i.uniform1f(g,l),i.uniform1f(E,c),i.uniform4fv(b,d),i.uniform1f(T,p),i.uniform1f(v,M),i.uniform1f(y,w),i.uniform1f(R,U),i.uniform1f(A,F),i.uniform1f(D,I?1:0),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(Z)},updateViewport:function(t){const{xStart:e,yStart:r,xEnd:n,yEnd:a}=t;i.useProgram(o),i.uniform1f(M,e),i.uniform1f(w,r),i.uniform1f(U,n),i.uniform1f(F,a),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(Z)},updateDate:t=>{const{dec:e,Hi:r}=t;i.useProgram(o),i.uniform1f(R,e),i.uniform1f(A,r),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(Z)},updateDateRange:t=>p(this,void 0,void 0,(function*(){const{startDate:e,endDate:r,iterations:h,emit:l}=t;i.useProgram(o);const c=Y=Date.now();i.uniform4fv(C,new Float32Array([1/h,0,0,0]));const f=Math.floor((r.getTime()-e.getTime())/h),m=H,_=W,x=i.createTexture();i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D,x),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,m,_,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);const g=i.createTexture();i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,g),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,m,_,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);const p=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,p);const E=i.COLOR_ATTACHMENT0;for(let t=0;t<h;t++){if(i.useProgram(o),l("tileloaded",t,h-1),c!==Y)return i.deleteFramebuffer(p),i.deleteTexture(x),i.deleteTexture(g),!0;yield new Promise(((r,h)=>{window.requestAnimationFrame((()=>{i.useProgram(o),i.uniform1i(L,1),i.uniform1i(S,1),null!==j&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,j));const h=t%2==0?g:x,l=t%2==0?x:g;i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D,h),i.bindFramebuffer(i.FRAMEBUFFER,p),i.framebufferTexture2D(i.FRAMEBUFFER,E,i.TEXTURE_2D,l,0);const c=i.checkFramebufferStatus(i.FRAMEBUFFER);c!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+c);const{dec:T,Hi:v}=d(new Date(e.getTime()+f*t));i.uniform1f(R,T),i.uniform1f(A,v),i.bindBuffer(i.ARRAY_BUFFER,n),i.enableVertexAttribArray(a),i.vertexAttribPointer(a,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,s),i.enableVertexAttribArray(u),i.vertexAttribPointer(u,2,i.FLOAT,!1,0,0),i.viewport(0,0,m,_),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4),r()}))}))}return i.deleteFramebuffer(p),yield new Promise(((t,e)=>{window.requestAnimationFrame((()=>{if(i.useProgram(o),c!==Y)return i.deleteTexture(x),i.deleteTexture(g),void t(!0);i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,(h-1)%2==0?x:g),i.uniform1i(L,2),i.uniform1i(P,1),i.uniform1i(S,1),Z(),i.uniform1i(S,0),i.uniform1i(P,0),i.uniform1i(L,0),i.deleteTexture(x),i.deleteTexture(g),t(!1)}))}))})),updateColor:t=>{const{colorVec:e}=t;i.useProgram(o),i.uniform4fv(b,e),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(Z)},generateShadeProfile:t=>{i.useProgram(o);const{dates:e,texCoords:r,shadeColor:n,sunColor:s}=t,c=r.length,f=e.length,m=i.getUniform(o,b);i.uniform4fv(b,n),i.uniform4fv(O,s),i.uniform1i(I,1);const _=i.createTexture();i.activeTexture(i.TEXTURE3),rt({gl:i,imageData:null,width:c,height:f,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,texture:_});const x=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,x),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,_,0);const g=i.checkFramebufferStatus(i.FRAMEBUFFER);g!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+g);const p=r.map((t=>[t[0],t[1],0,0])).flat(),E=i.createTexture();i.activeTexture(i.TEXTURE2),rt({gl:i,texture:E,imageData:new Float32Array(p),width:p.length/4,height:1,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,type:i.FLOAT}),i.uniform1i(B,2);const T=e.map((t=>{const{dec:e,Hi:r}=d(t);return[-e,r/10,0,0]})).flat(),v=i.createTexture();i.activeTexture(i.TEXTURE1),rt({gl:i,texture:v,imageData:new Float32Array(T),width:1,height:e.length,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,type:i.FLOAT}),i.uniform1i(N,1),null!==j&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,j)),i.bindBuffer(i.ARRAY_BUFFER,h),i.enableVertexAttribArray(a),i.vertexAttribPointer(a,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,l),i.enableVertexAttribArray(u),i.vertexAttribPointer(u,2,i.FLOAT,!1,0,0),i.viewport(0,0,c,f),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4);const y=new Uint8Array(c*f*4);return i.readPixels(0,0,c,f,i.RGBA,i.UNSIGNED_BYTE,y),i.deleteTexture(_),i.deleteTexture(v),i.deleteTexture(E),i.deleteFramebuffer(x),i.uniform1i(N,0),i.uniform1i(B,0),i.uniform1i(I,0),i.uniform4fv(b,m),i.uniform4fv(O,[0,0,0,0]),y},generateLocationShadeProfile:t=>{i.useProgram(o);const{dates:e,texCoord:r,shadeColor:n,sunColor:s}=t,c=e[0].length,f=e.length,m=i.getUniform(o,b);i.uniform4fv(b,n),i.uniform4fv(O,s),i.uniform1i(X,1),i.uniform2fv(G,[r[0],r[1]]);const _=i.createTexture();i.activeTexture(i.TEXTURE2),rt({gl:i,imageData:null,width:c,height:f,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,texture:_});const x=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,x),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,_,0);const g=i.checkFramebufferStatus(i.FRAMEBUFFER);g!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+g);const p=e.flat().map((t=>{const{dec:e,Hi:r}=d(t);return[-e,r/10,0,0]})).flat(),E=i.createTexture();i.activeTexture(i.TEXTURE1),rt({gl:i,texture:E,imageData:new Float32Array(p),width:c,height:f,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,internalFormat:i.RGBA32F,type:i.FLOAT}),i.uniform1i(N,1),null!==j&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,j)),i.uniform1i(S,0),i.bindBuffer(i.ARRAY_BUFFER,h),i.enableVertexAttribArray(a),i.vertexAttribPointer(a,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,l),i.enableVertexAttribArray(u),i.vertexAttribPointer(u,2,i.FLOAT,!1,0,0),i.viewport(0,0,c,f),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4);const T=new Uint8Array(c*f*4);return i.readPixels(0,0,c,f,i.RGBA,i.UNSIGNED_BYTE,T),i.deleteTexture(_),i.deleteTexture(E),i.deleteFramebuffer(x),i.uniform1i(N,0),i.uniform1i(X,0),i.uniform4fv(b,m),i.uniform4fv(O,[0,0,0,0]),T}}}({context:this._gl,setRenderBuffer:(e,r,i)=>{const o=t.getSource(this.canvasSourceId).texture;e.activeTexture(e.TEXTURE1),o.bind(e.LINEAR,e.CLAMP_TO_EDGE),o.size=[r,i],e.texImage2D(e.TEXTURE_2D,0,e.RGBA,r,i,0,e.RGBA,e.UNSIGNED_BYTE,null),e.bindFramebuffer(e.FRAMEBUFFER,this._framebuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o.texture,0),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA)}}),this._tileMerger=new at(this._gl),this._buildingRasterizer=new ot(this._gl),document.body.appendChild(this._canvas),this._canvas.style.display="none";const e=t.getBounds(),r=e.getNorthWest(),i=e.getNorthEast(),o=e.getSouthEast(),n=e.getSouthWest(),a=[[r.lng,r.lat],[i.lng,i.lat],[o.lng,o.lat],[n.lng,n.lat]];return t.addSource(this.canvasSourceId,{type:"canvas",canvas:this._canvas,coordinates:a,animate:!1}),t.addLayer({id:this.canvasLayerId,type:"raster",source:this.canvasSourceId,paint:{"raster-fade-duration":0}}),t.addSource(this.attributionSourceId,{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[-122.210598,47.769799]}},attribution:'<a href="https://shademap.app/about">© ShadeMap</a>'}),t.addLayer({id:this.attributionLayerId,type:"fill",source:this.attributionSourceId}),this._map.on("moveend",this._moveEndHandler),this._moveEndHandler(),this}onRemove(){return this._map&&(this._map.off("moveend",this._moveEndHandler),this._map.removeLayer(this.attributionLayerId),this._map.removeLayer(this.canvasLayerId),this._map.removeSource(this.attributionSourceId),this._map.removeSource(this.canvasSourceId)),this._gl&&this._framebuffer&&this._gl.deleteFramebuffer(this._framebuffer),document.body.removeChild(this._canvas),this.options.debug("onRemove called"),this}_getHeightMapCoords(t,e){if(this._map&&this.options.sunExposure.enabled&&this._bounds&&this._heightMap){const r=this._map.unproject([t,e]);if(r.toString()===this._map.unproject([t,e+1]).toString())return new i(-1,-1);const{visibleDEMPixelBounds:o,demZoom:n}=this._heightMap;return g(this._map).project(r,n).subtract(o.min)}return new i(-1,-1)}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this._getHeightMapCoords(t,e),i=this.readPixel(r.x,r.y),{startDate:o,endDate:n}=this.options.sunExposure,a=n.getTime()-o.getTime(),s=_(i,.5,a);return Math.abs(s/1e3/3600)}return 0}remove(){this._map&&this._map.removeLayer(this.id)}readPixel(t,e){const r=new Uint8Array(4);if(this._map&&this._gl&&this._framebuffer){const i=this._gl,o=this._map.getSource(this.canvasSourceId).texture;i.activeTexture(i.TEXTURE1),o.bind(i.LINEAR,i.CLAMP_TO_EDGE),i.bindFramebuffer(i.FRAMEBUFFER,this._framebuffer),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,o.texture,0),this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r)}return r}readPixels(t,e,r,i){console.log("Reading pix",t,e,r,i);const o=new Uint8Array(r*i*4);if(this._map&&this._gl&&this._framebuffer){const n=this._gl,a=this._map.getSource(this.canvasSourceId).texture;n.activeTexture(n.TEXTURE1),a.bind(n.LINEAR,n.CLAMP_TO_EDGE),n.bindFramebuffer(n.FRAMEBUFFER,this._framebuffer),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,a.texture,0),this._gl.readPixels(t,e,r,i,this._gl.RGBA,this._gl.UNSIGNED_BYTE,o)}return o}_flush(){if(this._map){this._map.getSource(this.canvasSourceId).fire({type:"data",dataType:"source",sourceDataType:"content"})}this.emit("idle")}_repositionCanvas(t){if(this._map){const e=this._map.getSource(this.canvasSourceId);if(e){const r=t.getNorthWest(),i=t.getNorthEast(),o=t.getSouthEast(),n=t.getSouthWest(),a=[[r.lng,r.lat],[i.lng,i.lat],[o.lng,o.lat],[n.lng,n.lat]];e.setCoordinates(a),this.emit("idle")}}return this}}export{st as default};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright Ted Piotrowski 2024
|
|
3
3
|
* Package: mapbox-gl-shadow-simulator
|
|
4
|
-
* Version: 0.
|
|
4
|
+
* Version: 0.54.0-unity
|
|
5
5
|
* For licensing visit: https://shademap.app/about/
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ShadeMap=e()}(this,(function(){"use strict";function t(t,e,r){var i=e[1],o=e[0],n=i-o;return t===i&&r?t:((t-o)%n+n)%n+o}function e(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}var r=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function i(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var o=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function n(t,e,o){return t instanceof i?t:r(t)?new i(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new i(t.x,t.y):new i(t,e,o)}function s(t,e){if(t)for(var r=e?[t,e]:t,i=0,o=r.length;i<o;i++)this.extend(r[i])}function a(t,e){return!t||t instanceof s?t:new s(t,e)}function u(t,e){if(t)for(var r=e?[t,e]:t,i=0,o=r.length;i<o;i++)this.extend(r[i])}function h(t,e){return t instanceof u?t:new u(t,e)}i.prototype={clone:function(){return new i(this.x,this.y)},add:function(t){return this.clone()._add(n(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(n(t))},_subtract:function(t){return this.x-=t.x,this.y-=t.y,this},divideBy:function(t){return this.clone()._divideBy(t)},_divideBy:function(t){return this.x/=t,this.y/=t,this},multiplyBy:function(t){return this.clone()._multiplyBy(t)},_multiplyBy:function(t){return this.x*=t,this.y*=t,this},scaleBy:function(t){return new i(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new i(this.x/t.x,this.y/t.y)},round:function(){return this.clone()._round()},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},floor:function(){return this.clone()._floor()},_floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.clone()._ceil()},_ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},trunc:function(){return this.clone()._trunc()},_trunc:function(){return this.x=o(this.x),this.y=o(this.y),this},distanceTo:function(t){var e=(t=n(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=n(t)).x===this.x&&t.y===this.y},contains:function(t){return t=n(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+e(this.x)+", "+e(this.y)+")"}},s.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof i||"number"==typeof t[0]||"x"in t)e=r=n(t);else if(e=(t=a(t)).min,r=t.max,!e||!r)return this;return this.min||this.max?(this.min.x=Math.min(e.x,this.min.x),this.max.x=Math.max(r.x,this.max.x),this.min.y=Math.min(e.y,this.min.y),this.max.y=Math.max(r.y,this.max.y)):(this.min=e.clone(),this.max=r.clone()),this},getCenter:function(t){return n((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return n(this.min.x,this.max.y)},getTopRight:function(){return n(this.max.x,this.min.y)},getTopLeft:function(){return this.min},getBottomRight:function(){return this.max},getSize:function(){return this.max.subtract(this.min)},contains:function(t){var e,r;return(t="number"==typeof t[0]||t instanceof i?n(t):a(t))instanceof s?(e=t.min,r=t.max):e=r=t,e.x>=this.min.x&&r.x<=this.max.x&&e.y>=this.min.y&&r.y<=this.max.y},intersects:function(t){t=a(t);var e=this.min,r=this.max,i=t.min,o=t.max,n=o.x>=e.x&&i.x<=r.x,s=o.y>=e.y&&i.y<=r.y;return n&&s},overlaps:function(t){t=a(t);var e=this.min,r=this.max,i=t.min,o=t.max,n=o.x>e.x&&i.x<r.x,s=o.y>e.y&&i.y<r.y;return n&&s},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,i=Math.abs(e.x-r.x)*t,o=Math.abs(e.y-r.y)*t;return a(n(e.x-i,e.y-o),n(r.x+i,r.y+o))},equals:function(t){return!!t&&(t=a(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},u.prototype={extend:function(t){var e,r,i=this._southWest,o=this._northEast;if(t instanceof c)e=t,r=t;else{if(!(t instanceof u))return t?this.extend(f(t)||h(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return i||o?(i.lat=Math.min(e.lat,i.lat),i.lng=Math.min(e.lng,i.lng),o.lat=Math.max(r.lat,o.lat),o.lng=Math.max(r.lng,o.lng)):(this._southWest=new c(e.lat,e.lng),this._northEast=new c(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,i=Math.abs(e.lat-r.lat)*t,o=Math.abs(e.lng-r.lng)*t;return new u(new c(e.lat-i,e.lng-o),new c(r.lat+i,r.lng+o))},getCenter:function(){return new c((this._southWest.lat+this._northEast.lat)/2,(this._southWest.lng+this._northEast.lng)/2)},getSouthWest:function(){return this._southWest},getNorthEast:function(){return this._northEast},getNorthWest:function(){return new c(this.getNorth(),this.getWest())},getSouthEast:function(){return new c(this.getSouth(),this.getEast())},getWest:function(){return this._southWest.lng},getSouth:function(){return this._southWest.lat},getEast:function(){return this._northEast.lng},getNorth:function(){return this._northEast.lat},contains:function(t){t="number"==typeof t[0]||t instanceof c||"lat"in t?f(t):h(t);var e,r,i=this._southWest,o=this._northEast;return t instanceof u?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=i.lat&&r.lat<=o.lat&&e.lng>=i.lng&&r.lng<=o.lng},intersects:function(t){t=h(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),o=t.getNorthEast(),n=o.lat>=e.lat&&i.lat<=r.lat,s=o.lng>=e.lng&&i.lng<=r.lng;return n&&s},overlaps:function(t){t=h(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),o=t.getNorthEast(),n=o.lat>e.lat&&i.lat<r.lat,s=o.lng>e.lng&&i.lng<r.lng;return n&&s},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=h(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var l=function(t){var e,r,i,o;for(r=1,i=arguments.length;r<i;r++)for(e in o=arguments[r])t[e]=o[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),i=this.scale(e);return this.transformation._transform(r,i)},pointToLatLng:function(t,e){var r=this.scale(e),i=this.transformation.untransform(t,r);return this.projection.unproject(i)},project:function(t){return this.projection.project(t)},unproject:function(t){return this.projection.unproject(t)},scale:function(t){return 256*Math.pow(2,t)},zoom:function(t){return Math.log(t/256)/Math.LN2},getProjectedBounds:function(t){if(this.infinite)return null;var e=this.projection.bounds,r=this.scale(t);return new s(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(e){var r=this.wrapLng?t(e.lng,this.wrapLng,!0):e.lng;return new c(this.wrapLat?t(e.lat,this.wrapLat,!0):e.lat,r,e.alt)},wrapLatLngBounds:function(t){var e=t.getCenter(),r=this.wrapLatLng(e),i=e.lat-r.lat,o=e.lng-r.lng;if(0===i&&0===o)return t;var n=t.getSouthWest(),s=t.getNorthEast();return new u(new c(n.lat-i,n.lng-o),new c(s.lat-i,s.lng-o))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,i=t.lat*r,o=e.lat*r,n=Math.sin((e.lat-t.lat)*r/2),s=Math.sin((e.lng-t.lng)*r/2),a=n*n+Math.cos(i)*Math.cos(o)*s*s,u=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return this.R*u}});function c(t,e,r){if(isNaN(t)||isNaN(e))throw new Error("Invalid LatLng object: ("+t+", "+e+")");this.lat=+t,this.lng=+e,void 0!==r&&(this.alt=+r)}function f(t,e,i){return t instanceof c?t:r(t)&&"object"!=typeof t[0]?3===t.length?new c(t[0],t[1],t[2]):2===t.length?new c(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new c(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new c(t,e,i)}c.prototype={equals:function(t,e){return!!t&&(t=f(t),Math.max(Math.abs(this.lat-t.lat),Math.abs(this.lng-t.lng))<=(void 0===e?1e-9:e))},toString:function(t){return"LatLng("+e(this.lat,t)+", "+e(this.lng,t)+")"},distanceTo:function(t){return l.distance(this,f(t))},wrap:function(){return l.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return h([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new c(this.lat,this.lng,this.alt)}};const d=256,m=.40909994067971484,_=t=>{const e=t.valueOf()/864e5-10957.5,r=6.240059966692059+.017201969994578018*e,i=r+.017453292519943295*(1.9148*Math.sin(r)+.02*Math.sin(2*r)+3e-4*Math.sin(3*r))+1.796593062783907+Math.PI,o=Math.atan2(Math.sin(i)*Math.cos(m),Math.cos(i));return{dec:Math.asin(Math.sin(m)*Math.sin(i)),Hi:(4.889714432387314+6.3003876824396166*e-o)%(2*Math.PI)+2*Math.PI}},g=()=>Math.floor(1e7*Math.random()),x=(t,e,r)=>{const i=1/e,o=Math.min(t[0]*i,255),n=Math.min(t[1]*i,255),s=Math.min(t[2]*i,255);let a=0;return o+n+s!==0&&(a=o>0?o/255*.5+.5:s>0?.5*(1-s/255):.5),a*r},p=(t=new Date,e)=>{const r=new Date(t.toLocaleString("en-US",{timeZone:"UTC"})),i=new Date(t.toLocaleString("en-US",e?{timeZone:e}:{}));return r.getTime()-i.getTime()};const E=t=>{const e=()=>!t.getPitch;return{project:(r,o)=>{if(e())return t.project(r,o);{const{lat:t,lng:e}=r;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*d)(e,o),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*d)(t,o))}},unproject:(r,i)=>{return e()?t.unproject(r,i):new c((o=r.y,n=i,s=Math.PI-2*Math.PI*o/d/Math.pow(2,n),180/Math.PI*Math.atan(.5*(Math.exp(s)-Math.exp(-s)))),function(t,e){return t/d/Math.pow(2,e)*360-180}(r.x,i));var o,n,s},screenUnproject:r=>e()?t.containerPointToLatLng(r):t.unproject(r),getZoom:()=>e()?t.getZoom():t.getZoom()+1,getCenter:()=>t.getCenter(),getBounds:()=>t.getBounds(),eachLayer:r=>{e()&&t.eachLayer(r)},getBearing:()=>e()?0:t.getBearing(),getPitch:()=>e()?0:t.getPitch(),rawMap:()=>t,isLeaflet:e,getPixelDimensions:()=>{const e=t.getContainer();return{width:e.clientWidth,height:e.clientHeight}},createBounds:t=>{const{nw:e,se:r}=t;return new u(e,r)}}};function T(t,e,r,i){return new(r||(r=Promise))((function(o,n){function s(t){try{u(i.next(t))}catch(t){n(t)}}function a(t){try{u(i.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((i=i.apply(t,e||[])).next())}))}const y=(t,e)=>{const{lat:r,lng:o}=t;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*d)(o,e),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*d)(r,e))},v=(t,e)=>{return new c((r=t.y,i=e,o=Math.PI-2*Math.PI*r/d/Math.pow(2,i),180/Math.PI*Math.atan(.5*(Math.exp(o)-Math.exp(-o)))),function(t,e){return t/d/Math.pow(2,e)*360-180}(t.x,e));var r,i,o},R=t=>{const{gl:e}=t,{texture:r,imageData:i=null,format:o=e.RGBA,width:n,height:s,filter:a=e.NEAREST,wrap:u=e.CLAMP_TO_EDGE,type:h=e.UNSIGNED_BYTE}=t;e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,a),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,a),e.texImage2D(e.TEXTURE_2D,0,o,n,s,0,o,h,i)};function A(t){const{gl:e,vSrc:r,fSrc:i}=t,o=e.createShader(e.VERTEX_SHADER);e.shaderSource(o,r),e.compileShader(o);const n=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,i),e.compileShader(n);const s=e.createProgram();return e.attachShader(s,o),e.attachShader(s,n),e.linkProgram(s),s}class b{constructor(t){this.gl=t,this.program=A({gl:t,vSrc:"\nuniform vec3 xyz;\nuniform vec2 dimensions;\nuniform bool use_dsm;\nattribute vec2 dsm_position;\nattribute vec2 a_position;\nfloat PI = 3.141592653589793;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\n\tvoid main() {\n\t\tif (use_dsm == true) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = dsm_position;\n v_use_dsm = 1.0;\n\t\t\treturn;\n\t\t}\n\t\tif (abs(a_position) == vec2(1,1)) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = a_position * 0.5 + 0.5;\n\t\t\treturn;\n\t\t}\n\t\tfloat x = ((a_position.x + 180.0) / 360.0 * pow(2.0, xyz.z)) * 256.0 - xyz.x;\n\t\tfloat y = (1.0 - (log(a_position.y) / PI)) / 2.0 * pow(2.0, xyz.z) * 256.0 - xyz.y;\n\t\tvec2 transformed = vec2(x, y);\n\t\tvec2 normalized = transformed / dimensions;\n\t\tvec2 final = normalized * 2.0 - 1.0;\n\t\tgl_Position = vec4(final, 0, 1);\n\t}\n",fSrc:"\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform vec4 color;\nuniform sampler2D height_map;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n if (v_use_dsm == 1.0) {\n\t \t gl_FragColor = vec4(0.0, 0.0, textureColor.b, textureColor.a);\n if (gl_FragColor.zw == vec2(0.0)) {\n discard;\n }\n } else {\n gl_FragColor = vec4(textureColor.b, textureColor.a, textureColor.b, textureColor.a);\n }\n // DSM noData values should not be included in heightMap because they produce ugly borders\n\t\treturn;\n\t} \n\tgl_FragColor = color;\n}\n"}),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.dsmAttributeLocation=t.getAttribLocation(this.program,"dsm_position"),this.useDSMUniformLocation=t.getUniformLocation(this.program,"use_dsm"),this.xyzUniformLocation=t.getUniformLocation(this.program,"xyz"),this.dimensionsUniformLocation=t.getUniformLocation(this.program,"dimensions"),this.heightMapUniformLocation=t.getUniformLocation(this.program,"height_map"),this.colorUniformLocation=t.getUniformLocation(this.program,"color"),this.positionBuffer=t.createBuffer(),this.dsmBuffer=t.createBuffer(),this.indexBuffer=t.createBuffer(),this.targetTexture=t.createTexture()}raster(t){const{features:e,upperLeftTile:r,mapZoom:o,width:n,height:s,imageData:a,dsmCoords:u,dsmSource:h,gl:l}=t,{x:c,y:f,z:m}=r;let _=0;l.useProgram(this.program),l.activeTexture(l.TEXTURE1);const g=l.createTexture();l.bindTexture(l.TEXTURE_2D,g),l.pixelStorei(l.UNPACK_ALIGNMENT,2),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.LUMINANCE_ALPHA,n,s,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,a);const x=n,p=s;l.activeTexture(l.TEXTURE0),l.bindTexture(l.TEXTURE_2D,this.targetTexture),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,x,p,0,l.RGBA,l.UNSIGNED_BYTE,null),o>15&&e.length>5?(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST)):(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.LINEAR)),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.viewport(0,0,x,p);const E=l.createFramebuffer();l.bindFramebuffer(l.FRAMEBUFFER,E);const T=l.COLOR_ATTACHMENT0;l.framebufferTexture2D(l.FRAMEBUFFER,T,l.TEXTURE_2D,this.targetTexture,0),l.disable(l.BLEND),l.bindBuffer(l.ARRAY_BUFFER,this.positionBuffer),l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,this.indexBuffer),l.clearColor(0,0,0,0),l.clear(l.COLOR_BUFFER_BIT);const v=c*d,R=f*d,A=new i(v,R);l.uniform3f(this.xyzUniformLocation,v,R,m),l.uniform2f(this.dimensionsUniformLocation,n,s),l.uniform1i(this.heightMapUniformLocation,1),l.uniform1i(this.useDSMUniformLocation,0);const b=new Float32Array([-1,-1,1,-1,-1,1,1,1]);if(l.enableVertexAttribArray(this.positionAttributeLocation),l.bufferData(l.ARRAY_BUFFER,b,l.STATIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.uniform4f(this.colorUniformLocation,0,0,0,0),l.drawArrays(l.TRIANGLE_STRIP,0,4),e.forEach((t=>{const{buildingHeight:e,aPosition:r,cuts:i,centroid:o,highlight:u}=t,h=y({lng:o[0],lat:o[1]},m).subtract(A).floor();if(h.x<0||h.y<0||h.x>n||h.y>s)return;const c=256*a[h.y*n*2+2*h.x]+a[h.y*n*2+2*h.x+1]+5*e,f=Math.floor(c/256)/255,d=Math.floor(c%256)/255;_=Math.max(_,c/5),l.uniform4f(this.colorUniformLocation,f,d,f,d),l.bufferData(l.ARRAY_BUFFER,r,l.DYNAMIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.bufferData(l.ARRAY_BUFFER,r,l.DYNAMIC_DRAW),l.vertexAttribPointer(this.dsmAttributeLocation,2,l.FLOAT,!1,0,0),l.bufferData(l.ELEMENT_ARRAY_BUFFER,i,l.DYNAMIC_DRAW),l.drawElements(l.TRIANGLES,i.length,i.length>256?l.UNSIGNED_SHORT:l.UNSIGNED_BYTE,0)})),l.deleteTexture(g),0!==h.data.length){l.activeTexture(l.TEXTURE1);const t=l.createTexture();l.bindTexture(l.TEXTURE_2D,t),l.pixelStorei(l.UNPACK_ALIGNMENT,2),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.LUMINANCE_ALPHA,h.width,h.height,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,h.data);const e=[u[0],u[3],u[2],u[3],u[0],u[1],u[2],u[1]],r=new Float32Array(e);l.enableVertexAttribArray(this.positionAttributeLocation),l.bufferData(l.ARRAY_BUFFER,r,l.STATIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.enableVertexAttribArray(this.dsmAttributeLocation),l.bindBuffer(l.ARRAY_BUFFER,this.dsmBuffer),l.bufferData(l.ARRAY_BUFFER,new Float32Array([0,1,1,1,0,0,1,0]),l.STATIC_DRAW),l.vertexAttribPointer(this.dsmAttributeLocation,2,l.FLOAT,!1,0,0),l.uniform4f(this.colorUniformLocation,0,0,0,0),l.uniform1i(this.useDSMUniformLocation,1),l.colorMask(!1,!1,!0,!0),l.drawArrays(l.TRIANGLE_STRIP,0,4),l.deleteTexture(t)}return l.colorMask(!0,!0,!0,!0),l.enable(l.BLEND),l.blendFunc(l.SRC_ALPHA,l.ONE_MINUS_SRC_ALPHA),l.deleteFramebuffer(E),_}}function M(t,e,r){r=r||2;var i,o,n,s,a,u,h,l=e&&e.length,c=l?e[0]*r:t.length,f=w(t,0,c,r,!0),d=[];if(!f||f.next===f.prev)return d;if(l&&(f=function(t,e,r,i){var o,n,s,a=[];for(o=0,n=e.length;o<n;o++)(s=w(t,e[o]*i,o<n-1?e[o+1]*i:t.length,i,!1))===s.next&&(s.steiner=!0),a.push(O(s));for(a.sort(C),o=0;o<a.length;o++)r=I(a[o],r);return r}(t,e,f,r)),t.length>80*r){i=n=t[0],o=s=t[1];for(var m=r;m<c;m+=r)(a=t[m])<i&&(i=a),(u=t[m+1])<o&&(o=u),a>n&&(n=a),u>s&&(s=u);h=0!==(h=Math.max(n-i,s-o))?32767/h:0}return D(f,d,r,i,o,h,0),d}function w(t,e,r,i,o){var n,s;if(o===$(t,e,r,i)>0)for(n=e;n<r;n+=i)s=k(n,t[n],t[n+1],s);else for(n=r-i;n>=e;n-=i)s=k(n,t[n],t[n+1],s);return s&&H(s,s.next)&&(q(s),s=s.next),s}function L(t,e){if(!t)return t;e||(e=t);var r,i=t;do{if(r=!1,i.steiner||!H(i,i.next)&&0!==G(i.prev,i,i.next))i=i.next;else{if(q(i),(i=e=i.prev)===i.next)break;r=!0}}while(r||i!==e);return e}function D(t,e,r,i,o,n,s){if(t){!s&&n&&function(t,e,r,i){var o=t;do{0===o.z&&(o.z=N(o.x,o.y,e,r,i)),o.prevZ=o.prev,o.nextZ=o.next,o=o.next}while(o!==t);o.prevZ.nextZ=null,o.prevZ=null,function(t){var e,r,i,o,n,s,a,u,h=1;do{for(r=t,t=null,n=null,s=0;r;){for(s++,i=r,a=0,e=0;e<h&&(a++,i=i.nextZ);e++);for(u=h;a>0||u>0&&i;)0!==a&&(0===u||!i||r.z<=i.z)?(o=r,r=r.nextZ,a--):(o=i,i=i.nextZ,u--),n?n.nextZ=o:t=o,o.prevZ=n,n=o;r=i}n.nextZ=null,h*=2}while(s>1)}(o)}(t,i,o,n);for(var a,u,h=t;t.prev!==t.next;)if(a=t.prev,u=t.next,n?F(t,i,o,n):U(t))e.push(a.i/r|0),e.push(t.i/r|0),e.push(u.i/r|0),q(t),t=u.next,h=u.next;else if((t=u)===h){s?1===s?D(t=S(L(t),e,r),e,r,i,o,n,2):2===s&&P(t,e,r,i,o,n):D(L(t),e,r,i,o,n,1);break}}}function U(t){var e=t.prev,r=t,i=t.next;if(G(e,r,i)>=0)return!1;for(var o=e.x,n=r.x,s=i.x,a=e.y,u=r.y,h=i.y,l=o<n?o<s?o:s:n<s?n:s,c=a<u?a<h?a:h:u<h?u:h,f=o>n?o>s?o:s:n>s?n:s,d=a>u?a>h?a:h:u>h?u:h,m=i.next;m!==e;){if(m.x>=l&&m.x<=f&&m.y>=c&&m.y<=d&&X(o,a,n,u,s,h,m.x,m.y)&&G(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function F(t,e,r,i){var o=t.prev,n=t,s=t.next;if(G(o,n,s)>=0)return!1;for(var a=o.x,u=n.x,h=s.x,l=o.y,c=n.y,f=s.y,d=a<u?a<h?a:h:u<h?u:h,m=l<c?l<f?l:f:c<f?c:f,_=a>u?a>h?a:h:u>h?u:h,g=l>c?l>f?l:f:c>f?c:f,x=N(d,m,e,r,i),p=N(_,g,e,r,i),E=t.prevZ,T=t.nextZ;E&&E.z>=x&&T&&T.z<=p;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=g&&E!==o&&E!==s&&X(a,l,u,c,h,f,E.x,E.y)&&G(E.prev,E,E.next)>=0)return!1;if(E=E.prevZ,T.x>=d&&T.x<=_&&T.y>=m&&T.y<=g&&T!==o&&T!==s&&X(a,l,u,c,h,f,T.x,T.y)&&G(T.prev,T,T.next)>=0)return!1;T=T.nextZ}for(;E&&E.z>=x;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=g&&E!==o&&E!==s&&X(a,l,u,c,h,f,E.x,E.y)&&G(E.prev,E,E.next)>=0)return!1;E=E.prevZ}for(;T&&T.z<=p;){if(T.x>=d&&T.x<=_&&T.y>=m&&T.y<=g&&T!==o&&T!==s&&X(a,l,u,c,h,f,T.x,T.y)&&G(T.prev,T,T.next)>=0)return!1;T=T.nextZ}return!0}function S(t,e,r){var i=t;do{var o=i.prev,n=i.next.next;!H(o,n)&&W(o,i,i.next,n)&&Y(o,n)&&Y(n,o)&&(e.push(o.i/r|0),e.push(i.i/r|0),e.push(n.i/r|0),q(i),q(i.next),i=t=n),i=i.next}while(i!==t);return L(i)}function P(t,e,r,i,o,n){var s=t;do{for(var a=s.next.next;a!==s.prev;){if(s.i!==a.i&&z(s,a)){var u=K(s,a);return s=L(s,s.next),u=L(u,u.next),D(s,e,r,i,o,n,0),void D(u,e,r,i,o,n,0)}a=a.next}s=s.next}while(s!==t)}function C(t,e){return t.x-e.x}function I(t,e){var r=function(t,e){var r,i=e,o=t.x,n=t.y,s=-1/0;do{if(n<=i.y&&n>=i.next.y&&i.next.y!==i.y){var a=i.x+(n-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(a<=o&&a>s&&(s=a,r=i.x<i.next.x?i:i.next,a===o))return r}i=i.next}while(i!==e);if(!r)return null;var u,h=r,l=r.x,c=r.y,f=1/0;i=r;do{o>=i.x&&i.x>=l&&o!==i.x&&X(n<c?o:s,n,l,c,n<c?s:o,n,i.x,i.y)&&(u=Math.abs(n-i.y)/(o-i.x),Y(i,t)&&(u<f||u===f&&(i.x>r.x||i.x===r.x&&B(r,i)))&&(r=i,f=u)),i=i.next}while(i!==h);return r}(t,e);if(!r)return e;var i=K(r,t);return L(i,i.next),L(r,r.next)}function B(t,e){return G(t.prev,t,e.prev)<0&&G(e.next,t,t.next)<0}function N(t,e,r,i,o){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*o|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*o|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function O(t){var e=t,r=t;do{(e.x<r.x||e.x===r.x&&e.y<r.y)&&(r=e),e=e.next}while(e!==t);return r}function X(t,e,r,i,o,n,s,a){return(o-s)*(e-a)>=(t-s)*(n-a)&&(t-s)*(i-a)>=(r-s)*(e-a)&&(r-s)*(n-a)>=(o-s)*(i-a)}function z(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==e.i&&r.next.i!==e.i&&W(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(Y(t,e)&&Y(e,t)&&function(t,e){var r=t,i=!1,o=(t.x+e.x)/2,n=(t.y+e.y)/2;do{r.y>n!=r.next.y>n&&r.next.y!==r.y&&o<(r.next.x-r.x)*(n-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next}while(r!==t);return i}(t,e)&&(G(t.prev,t,e.prev)||G(t,e.prev,e))||H(t,e)&&G(t.prev,t,t.next)>0&&G(e.prev,e,e.next)>0)}function G(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function H(t,e){return t.x===e.x&&t.y===e.y}function W(t,e,r,i){var o=Z(G(t,e,r)),n=Z(G(t,e,i)),s=Z(G(r,i,t)),a=Z(G(r,i,e));return o!==n&&s!==a||(!(0!==o||!j(t,r,e))||(!(0!==n||!j(t,i,e))||(!(0!==s||!j(r,t,i))||!(0!==a||!j(r,e,i)))))}function j(t,e,r){return e.x<=Math.max(t.x,r.x)&&e.x>=Math.min(t.x,r.x)&&e.y<=Math.max(t.y,r.y)&&e.y>=Math.min(t.y,r.y)}function Z(t){return t>0?1:t<0?-1:0}function Y(t,e){return G(t.prev,t,t.next)<0?G(t,e,t.next)>=0&&G(t,t.prev,e)>=0:G(t,e,t.prev)<0||G(t,t.next,e)<0}function K(t,e){var r=new V(t.i,t.x,t.y),i=new V(e.i,e.x,e.y),o=t.next,n=e.prev;return t.next=e,e.prev=t,r.next=o,o.prev=r,i.next=r,r.prev=i,n.next=i,i.prev=n,i}function k(t,e,r,i){var o=new V(t,e,r);return i?(o.next=i.next,o.prev=i,i.next.prev=o,i.next=o):(o.prev=o,o.next=o),o}function q(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function V(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function $(t,e,r,i){for(var o=0,n=e,s=r-i;n<r;n+=i)o+=(t[s]-t[n])*(t[n+1]+t[s+1]),s=n;return o}function J(t){t.filter((t=>"MultiPolygon"===t.geometry.type)).forEach((e=>{const{geometry:r,properties:i,type:o}=e;if("MultiPolygon"===r.type)for(let i=0;i<r.coordinates.length;i++)t.push(Object.assign(Object.assign({},e),{geometry:Object.assign(Object.assign({},r),{type:"Polygon",coordinates:r.coordinates[i]})}))}));return t.filter((t=>"Polygon"===t.geometry.type)).map((t=>{const{geometry:e,properties:r}=t,{vertices:i}=M.flatten(e.coordinates),o=new Float32Array(i.map(((t,e)=>{if(e%2==1){const e=t*Math.PI/180;return Math.tan(e)+1/Math.cos(e)}return t}))),n=M(i),s=n.length>256?new Uint16Array(n):new Uint8Array(n),a=function(t){const{height:e=0,levels:r=0,render_height:i=0}=t;if(r)return 3.04*r;return Math.max(e,i)}(r),u=r.highlight||!1;let h=0,l=0,c=0;for(let t=0;t<i.length;t+=2)h+=i[t],l+=i[t+1],c++;return{aPosition:o,cuts:s,buildingHeight:a,centroid:[h/c,l/c],highlight:u}}))}M.deviation=function(t,e,r,i){var o=e&&e.length,n=o?e[0]*r:t.length,s=Math.abs($(t,0,n,r));if(o)for(var a=0,u=e.length;a<u;a++){var h=e[a]*r,l=a<u-1?e[a+1]*r:t.length;s-=Math.abs($(t,h,l,r))}var c=0;for(a=0;a<i.length;a+=3){var f=i[a]*r,d=i[a+1]*r,m=i[a+2]*r;c+=Math.abs((t[f]-t[m])*(t[d+1]-t[f+1])-(t[f]-t[d])*(t[m+1]-t[f+1]))}return 0===s&&0===c?0:Math.abs((c-s)/s)},M.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},i=0,o=0;o<t.length;o++){for(var n=0;n<t[o].length;n++)for(var s=0;s<e;s++)r.vertices.push(t[o][n][s]);o>0&&(i+=t[o-1].length,r.holes.push(i))}return r};let Q,tt={width:0,height:0,imageData:new Uint8ClampedArray(0),visibleDEMPixelBounds:new s(new i(0,0),new i(0,0)),DEMPixelBounds:new s(new i(0,0),new i(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const et=t=>T(void 0,void 0,void 0,(function*(){const{demZoom:e,getFeatures:r,terrainSource:o,dsmSource:n,tileLoaded:a,gl:h,bounds:l,buildingRasterizer:c,tileMerger:f,forceUpdate:m=!1}=t,{getSourceUrl:_,getElevation:g,maxZoom:x,tileSize:p,_overzoom:E}=o,v=(R={getFeatures:r},T(void 0,void 0,void 0,(function*(){const{getFeatures:t}=R;try{return J(yield t())}catch(t){console.log("Error merging buildings",t)}return[]})));var R;try{const t=l,r=t.getNorthWest(),o=t.getSouthEast(),E=new s(y(r,e),y(o,e));let T=new i(E.min.x,E.min.y),R=E.max.x-E.min.x;const A=E.max.y-E.min.y,b=E.max.subtract(E.min);b.y>b.x&&(T.x-=d,R+=512);const M=(t=>{const{upperLeft:e,width:r,height:i}=t,o=e.divideBy(d).floor().multiplyBy(d),n=(Math.ceil(r/d)+1)*d,a=(Math.ceil(i/d)+1)*d,u=o.add([n,a]);return new s(o,u)})({upperLeft:T,width:R,height:A}),{x:w,y:L}=M.max.subtract(M.min),D=(t=>{t.sort(((t,e)=>t.y!==e.y?t.y-e.y:t.x-e.x));const e=t.reduce(((t,e)=>e.x<t.x?e:t)).x,r=t.reduce(((t,e)=>e.y<t.y?e:t)).y;return t.map((t=>{const i=Math.pow(2,t.z);return{x:(t.x%i+i)%i,y:(t.y%i+i)%i,z:t.z,xOffset:(t.x-e)*d,yOffset:(t.y-r)*d}}))})((t=>{const{upperLeft:e,width:r,height:i,zoom:o}=t,n=e.divideBy(d).floor(),s=n.x+r/d,a=Math.min(n.y+i/d,Math.pow(2,o)-1),u=[];for(var h=n.x;h<s;h++)for(var l=n.y;l<a;l++)u.push({x:h,y:l,z:o});return u})({upperLeft:M.min,width:w,height:L,zoom:e})),U=E.max.x-E.min.x,F=E.max.y-E.min.y,S=U,P=F,C=JSON.stringify(D);if(!m&&C===Q&&e<x)return tt=Object.assign(Object.assign({},tt),{outputWidth:S,outputHeight:P,visibleDEMPixelBounds:E,demZoom:e,dirty:!0}),tt;const I=yield f.merge(D,{maxZoom:x,width:w,height:L,crossOrigin:"Anonymous",getSourceUrl:_,getElevation:g,tileSize:p,tileLoaded:a});if(null===I)return tt=Object.assign(Object.assign({},tt),{visibleDEMPixelBounds:E,demZoom:e,dirty:!1}),tt;const B=new s(y(new u(n.bounds).getNorthWest(),e),y(new u(n.bounds).getSouthEast(),e)),N=B.min.subtract(M.min),O=B.max.subtract(M.min),X=[N.x/w,N.y/L,O.x/w,O.y/L].map((t=>2*t-1)),z=yield v,G=c.raster({upperLeftTile:D[0],width:w,height:L,mapZoom:e,features:z,imageData:I,gl:h,dsmSource:n,dsmCoords:X}),H=Math.max(Math.max(n.maxHeight,G),I.maxHeight);Q=C,tt={maxHeight:H,width:w,height:L,imageData:I,DEMPixelBounds:M,visibleDEMPixelBounds:E,raster:D,demZoom:e,dirty:!0,outputWidth:S,outputHeight:P}}catch(t){console.error("Could not decode height map",t)}return tt})),rt=t=>{const{tile:e,maxZoom:r,tileSize:i}=t;let{x:o,y:n,z:s}=e;if(s>r){const t=Math.pow(2,e.z-r);o=Math.floor(o/t),n=Math.floor(n/t),s=r}return{x:i===d?o:Math.floor(o/2),y:i===d?n:Math.floor(n/2),z:i===d?s:s-1}};class it{constructor(t){this.gl=t,this.program=A({vSrc:"\n attribute vec4 a_position;\n varying vec2 v_pos;\n void main() {\n v_pos = ((a_position + 1.0) * 0.5).xy;\n gl_Position = a_position;\n }\n",fSrc:"\n precision mediump float;\n varying vec2 v_pos;\n uniform sampler2D u_texture;\n void main() {\n gl_FragColor = texture2D(u_texture, v_pos);\n }\n",gl:t}),this.positionBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),t.enableVertexAttribArray(this.positionAttributeLocation),t.vertexAttribPointer(this.positionAttributeLocation,2,t.FLOAT,!1,0,0),this.tileTexture=t.createTexture(),this.gl.bindTexture(this.gl.TEXTURE_2D,this.tileTexture),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST),this.outputTexture=t.createTexture(),this.framebuffer=t.createFramebuffer(),this.inProgress=[],this.finished=0}merge(t,e){return T(this,void 0,void 0,(function*(){const{width:r,height:i,crossOrigin:o,getSourceUrl:n,getElevation:s,tileSize:a,tileLoaded:u,maxZoom:h}=e;if(this.gl){const e=new Uint8ClampedArray(2*r*i);e.maxHeight=0,this.inProgress.forEach((t=>t.src="")),this.inProgress=[],this.finished=0;const l=new Set;t.forEach((t=>{l.add(n(rt({tile:t,maxZoom:h,tileSize:a})))}));const c=Array.from(l).map((i=>T(this,void 0,void 0,(function*(){return new Promise(((u,l)=>{const c=new Image;this.inProgress.push(c),c.onload=()=>{t.filter((t=>i===n(rt({tile:t,maxZoom:h,tileSize:a})))).forEach((t=>{let i=0,o=0;const n=514===a?1:0;let u=0,l=d,f=d;if(a!==d&&(i=t.x%2*d,o=t.y%2*d,l=d,f=d),t.z>h){const e=Math.pow(2,t.z-h);a!==d&&(i=Math.floor(t.x/e)%2*d,o=Math.floor(t.y/e)%2*d),i+=d*(t.x%e/e),o+=d*(t.y%e/e),l=d/e,f=d/e,u=514===a?1:0}this.gl.useProgram(this.program),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,this.tileTexture),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,c),this.gl.activeTexture(this.gl.TEXTURE1),R({gl:this.gl,texture:this.outputTexture,imageData:null,format:this.gl.RGBA,width:a,height:a,wrap:this.gl.CLAMP_TO_EDGE,filter:this.gl.NEAREST}),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.framebuffer),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.outputTexture,0);const m=this.gl.checkFramebufferStatus(this.gl.FRAMEBUFFER);m!==this.gl.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+m),this.gl.viewport(0,0,a,a),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.positionAttributeLocation),this.gl.vertexAttribPointer(this.positionAttributeLocation,2,this.gl.FLOAT,!1,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.drawArrays(this.gl.TRIANGLE_STRIP,0,4);const _=new Uint8Array(4*(l+u)*(f+u));this.gl.readPixels(n+i,n+o,l+u,f+u,this.gl.RGBA,this.gl.UNSIGNED_BYTE,_),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null);const g=new Uint8ClampedArray(131072);let x=new Array((l+u)*(f+u)),p=d/l;for(let t=0;t<_.length;t+=4){const r=s({r:_[t],g:_[t+1],b:_[t+2],a:_[t+3]});e.maxHeight=Math.max(r,e.maxHeight);const i=5*(r||0);x[t/4]=i}if(p>1&&514===a)for(x=function(t,e,r,i){const o=Math.floor(e*i),n=Math.floor(r*i),s=[];for(let a=0;a<n;a++)for(let n=0;n<o;n++){const o=n/i,u=a/i,h=Math.floor(o),l=Math.floor(u),c=Math.min(h+1,e-1),f=Math.min(l+1,r-1),d=o-h,m=u-l,_=l*e+c,g=f*e+h,x=f*e+c,p=t[l*e+h]*(1-d)*(1-m)+t[_]*d*(1-m)+t[g]*(1-d)*m+t[x]*d*m;s.push(p)}return function(t,e,r,i,o){if(i>=e||o>=r)return[];const n=e-i,s=r-o,a=[];for(let r=0;r<s;r++)for(let i=0;i<n;i++){const o=r*e+i;a.push(t[o])}return a}(s,Math.sqrt(s.length),Math.sqrt(s.length),i,i)}(x,l+1,f+1,p);p>1;)p/=2,f*=2,l*=2;for(let t=0;t<g.length;t+=2){const e=x[Math.floor(t/2/d/p)*l+Math.floor(t/2%d/p)],r=Math.floor(e/256),i=Math.floor(e%256);g[t]=r,g[t+1]=i}for(let i=0;i<d;i++)e.set(g.slice(i*d*2,(i+1)*d*2),2*(t.yOffset*r+i*r+t.xOffset))})),u(null)},c.onerror=t=>{if(c.src!==c.originalSource)return l("new tiles requested");u(null)},c.crossOrigin=o||null,c.src=i,c.originalSource=c.src})).then((()=>{this.finished++,u(this.finished,this.inProgress.length)}))}))));try{yield Promise.all(c)}catch(t){return console.log(`${c.length} requests aborted`,t),null}return this.inProgress=[],e}throw new Error("Could not get canvas context for merging tile images")}))}}const ot=(t,e)=>{const{r:r,g:i,b:o}=t;return[r/255,i/255,o/255,e]},nt=(t,e)=>{const{date:r}=e,{dec:i,Hi:o}=_(r);t.updateDate({dec:i,Hi:o})},st=(t,e)=>T(void 0,void 0,void 0,(function*(){return yield t.updateDateRange(Object.assign({},e))})),at=(t,e)=>{const{color:r,opacity:i}=e,o=ot(r,i);t.updateColor({colorVec:o})};new u([0,0],[0,0]);const ut=t=>{const{kernel:e,map:r,heightMap:i,now:o,color:n,opacity:s,belowCanopy:a}=t;try{const{outputHeight:t,outputWidth:h,maxHeight:l,width:c,height:f,DEMPixelBounds:m,imageData:g,visibleDEMPixelBounds:x,demZoom:p}=i;if(0===c||0===f)return;const{min:E,max:T}=x;if(!E||!T)return;const{x:y,y:R}=T.subtract(E),A=m.min,b=r.getPixelDimensions(),M=r.screenUnproject([0,0]),w=r.screenUnproject([b.width,0]),L=r.screenUnproject([b.width,b.height]),D=r.screenUnproject([0,b.height]),U=[D,L,M,w].map((t=>r.project(t,p))),F=U.map((t=>[(t.x-A.x)/c,(t.y-A.y)/f])).flat(),S=U.map((t=>[(t.x-E.x)/y,(t.y-E.y)/R])).map((t=>[2*t[0]-1,-1*(2*t[1]-1)])).flat(),P=A.y/d/Math.pow(2,p),C=f/d/Math.pow(2,p),I=new u(v(m.getTopLeft(),p),v(m.getBottomRight(),p)),B=I.getWest(),N=Math.abs(I.getWest()-I.getEast());((t,e)=>{const{color:r,opacity:i,date:o}=e,n=ot(r,i),{dec:s,Hi:a}=_(o);t.updateLocation(Object.assign({dec:s,Hi:a,colorVec:n,step:1},e))})(e,{imageData:g,maxHeight:l,width:c,height:f,heightMapZoom:p,cornerTextureCoords:F,cornerClipCoords:S,topYCoord:P,ySize:C,west:B,dLng:N,date:o,color:n,opacity:s,outputHeight:t,outputWidth:h,belowCanopy:a})}catch(t){console.error("EXCEPTION",t)}};return class extends class extends class{constructor(){this.events={}}on(t,e){return"object"!=typeof this.events[t]&&(this.events[t]=[]),this.events[t].push(e),()=>this.removeListener(t,e)}removeListener(t,e){if("object"!=typeof this.events[t])return;const r=this.events[t].indexOf(e);r>-1&&this.events[t].splice(r,1)}removeAllListeners(){Object.keys(this.events).forEach((t=>this.events[t].splice(0,this.events[t].length)))}emit(t,...e){"object"==typeof this.events[t]&&[...this.events[t]].forEach((t=>t.apply(this,e)))}once(t,e){const r=this.on(t,((...t)=>{r(),e.apply(this,t)}));return r}}{constructor(...t){super(),this.options={date:new Date,color:"000",opacity:.3,sunExposure:{enabled:!1,startDate:new Date,endDate:new Date,iterations:32},apiKey:"",terrainSource:{maxZoom:15,tileSize:256,_overzoom:15,getSourceUrl:t=>"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/7/17/45.png",getElevation:t=>{const{r:e,g:r,b:i}=t;return 256*e+r+i/256-32768}},dsmSource:{bounds:[{lat:0,lng:0},{lat:0,lng:0}],data:new Uint8ClampedArray,width:0,height:0,maxHeight:0},belowCanopy:!1,getFeatures:()=>Promise.resolve([]),getSize:()=>({width:Number.NaN,height:Number.NaN}),debug:t=>{}};const e=t[0];if(this.options=Object.assign(this.options,e),!this.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:this.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((t=>T(this,void 0,void 0,(function*(){if(200!==t.status)throw new Error(yield t.text())})))).catch((t=>T(this,void 0,void 0,(function*(){throw new Error(`Could not load ShadeMap API. Key: ${this.options.apiKey} Error: ${t}`)}))));const r={preserveDrawingBuffer:!0,antialias:!1};this._canvas=document.createElement("canvas"),this._gl=this._canvas.getContext("webgl",r)||this._canvas.getContext("experimental-webgl",r),this._compiledKernel=function(t){const{context:e}=t,r=e,i=A({gl:r,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 a_pos;attribute vec2 a_tex_pos;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;void main(void){gl_Position=vec4(a_pos,0,1);vTexCoordFull=(gl_Position*0.5+0.5).xy;vTexCoordCropped=a_tex_pos;}",fSrc:"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nprecision lowp int;precision lowp sampler2D;float atan2(float v1,float v2){if(v1==0.0||v2==0.0)return 0.0;return atan(v1,v2);}float _pow(float v1,float v2){if(v2==0.0)return 1.0;return pow(v1,v2);}float integerMod(float x,float y){float res=floor(mod(x,y));return res*(res>floor(y)-1.0 ? 0.0 : 1.0);}float divWithIntCheck(float x,float y){if(floor(x)==x&&floor(y)==y&&integerMod(x,y)==0.0){return float(int(x)/int(y));}return x/y;}float integerCorrectionModulo(float number,float divisor){if(number<0.0){number=abs(number);if(divisor<0.0){divisor=abs(divisor);}return-(number-(divisor*floor(divWithIntCheck(number,divisor))));}if(divisor<0.0){divisor=abs(divisor);}return number-(divisor*floor(divWithIntCheck(number,divisor)));}float getDEMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*255.0*256.0+result.g*255.0)/5000.0;}float getDSMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.b*255.0*256.0+result.a*255.0)/5000.0;}vec4 actualColor;void color(float r,float g,float b,float a){actualColor=vec4(r,g,b,a);}void color(float r,float g,float b){color(r,g,b,1.0);}void color(float r){color(r,r,r,1.0);}void color(vec4 color){actualColor=color;}const int LOOP_MAX=1000;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;uniform sampler2D user_a;uniform float user_width;uniform float user_height;uniform float user_maxHeight;uniform float user_zoom;uniform float user_topYCoord;uniform float user_ySize;uniform vec4 user_color;uniform vec4 u_sunColor;uniform float user_step;uniform float user_west;uniform float user_dLng;uniform float user_dec;uniform float user_Hi;uniform bool u_below_canopy;uniform sampler2D user_sunExposureTexture;uniform bool user_renderToSunExposureTexture;uniform bool user_outputSunExposure;uniform vec4 user_exposureDelta;uniform bool u_outputShadeProfile;uniform sampler2D u_decHiTexture;uniform sampler2D u_gpxTexture;uniform bool u_outputLocationShadeProfile;uniform vec2 u_shadeProfileLocation;float kernelResult;void kernel(){float sunDec=user_dec;float sunHi=user_Hi;vec4 shade_color=user_color;float maxHeight=user_maxHeight/1000.0;float user_x=vTexCoordCropped.x;float user_y=vTexCoordCropped.y;if(u_outputShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;vec4 gpx=texture2D(u_gpxTexture,vec2(vTexCoordFull.x,.5));user_x=gpx.x;user_y=gpx.y;}if(u_outputLocationShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;user_x=u_shadeProfileLocation.x;user_y=u_shadeProfileLocation.y;}float user_lit=1.0;float dsm_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(u_below_canopy==true){float dem_height=getDEMElevationFromSampler2D(user_a,user_x,user_y);if(dsm_height-dem_height>.002){user_lit=0.0;}}float user_z=dsm_height;float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=user_west+(user_dLng*user_x);float user_H=integerCorrectionModulo((sunHi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(sunDec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(sunDec))+((cos(user_lat)*cos(sunDec))*cos(user_H))));float user_zoom_factor=_pow(2.0,user_zoom);float user_kmPerPixel=divWithIntCheck(156.5430339296875,user_zoom_factor)*abs(cos(user_lat));float user_dx=((-sin(sun_azimuth)*cos(sun_altitude))*user_step)/user_width;float user_dy=((cos(sun_azimuth)*cos(sun_altitude))*user_step)/user_height;float user_dz=((sin(sun_altitude)*user_kmPerPixel)*user_step);float shadow_bias=0.0005;float user_curvature=0.0;float cur_height=0.0;float user_distance=0.0;float user_startX=user_x;float user_startY=user_y;user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;if((abs(1.0)<0.0)){kernelResult=0.0;return;}float minAngle=asin((earthRadiusInKm/(earthRadiusInKm+user_z)))-(user_PI/2.0);if(user_z<0.0||sun_altitude<minAngle){user_lit=0.0;}else{float xIter=ceil(user_dx<0.0 ? abs(user_x/user_dx):(1.0-user_x)/user_dx);float yIter=ceil(user_dy<0.0 ? abs(user_y/user_dy):(1.0-user_y)/user_dy);float zIter=ceil(user_dz<0.0 ? float(LOOP_MAX):(maxHeight-user_z)/user_dz);int iter=int(min(xIter,min(yIter,zIter)));float user_distance=(sqrt(pow(user_dx*user_width,2.0)+pow(user_dy*user_height,2.0))*user_kmPerPixel)/earthRadiusInKm;for(int safeI=0;safeI<LOOP_MAX;safeI++){if(safeI>iter){break;}cur_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(cur_height-user_z>shadow_bias){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;vec4 result=texture2D(user_a,vec2(user_x,user_y));iter=0;break;}}user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;}}if((user_lit==1.0)){if(u_outputLocationShadeProfile==true&&u_sunColor==shade_color){float timeInSun=pow(.7,pow(sin(sun_altitude),.678))*sin(sun_altitude)*(1.0/0.7);float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,1.0);}else{color(u_sunColor);}}else{color(shade_color);}if(user_renderToSunExposureTexture){vec4 aggregateColor=texture2D(user_sunExposureTexture,vec2(vTexCoordFull.x,vTexCoordFull.y));if((user_lit==1.0)){color(aggregateColor.r,0.0,0.0,1.0);}else{color(aggregateColor.r+user_exposureDelta.r,0.0,0.0,1.0);}if(user_outputSunExposure){float timeInSun=1.0-aggregateColor.r;float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,0.5);}}}void main(void){kernel();gl_FragColor=actualColor;}"});r.useProgram(i);const o=r.createBuffer(),n=r.getAttribLocation(i,"a_pos"),s=r.createBuffer(),a=r.getAttribLocation(i,"a_tex_pos"),u=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,u),r.bufferData(r.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),r.STATIC_DRAW),r.enable(r.BLEND),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA);const h=r.getUniformLocation(i,"user_a");r.uniform1i(h,0);const l=r.getUniformLocation(i,"user_width"),c=r.getUniformLocation(i,"user_height"),f=r.getUniformLocation(i,"user_maxHeight"),d=r.getUniformLocation(i,"user_zoom"),m=r.getUniformLocation(i,"user_topYCoord"),g=r.getUniformLocation(i,"user_ySize"),x=r.getUniformLocation(i,"user_step"),p=r.getUniformLocation(i,"user_west"),E=r.getUniformLocation(i,"user_dLng"),y=r.getUniformLocation(i,"user_dec"),v=r.getUniformLocation(i,"user_Hi"),b=r.getUniformLocation(i,"user_color"),M=r.getUniformLocation(i,"user_xStart"),w=r.getUniformLocation(i,"user_yStart"),L=r.getUniformLocation(i,"user_xEnd"),D=r.getUniformLocation(i,"user_yEnd"),U=r.getUniformLocation(i,"u_below_canopy"),F=r.getUniformLocation(i,"user_sunExposureTexture"),S=r.getUniformLocation(i,"user_renderToSunExposureTexture"),P=r.getUniformLocation(i,"user_outputSunExposure"),C=r.getUniformLocation(i,"user_exposureDelta"),I=r.getUniformLocation(i,"u_outputShadeProfile"),B=r.getUniformLocation(i,"u_gpxTexture"),N=r.getUniformLocation(i,"u_decHiTexture"),O=r.getUniformLocation(i,"u_sunColor"),X=r.getUniformLocation(i,"u_outputLocationShadeProfile"),z=r.getUniformLocation(i,"u_shadeProfileLocation");let G=0,H=0,W=0;const j=()=>{H&&W&&(r.useProgram(i),r.bindBuffer(r.ARRAY_BUFFER,o),r.enableVertexAttribArray(n),r.bindBuffer(r.ARRAY_BUFFER,s),r.enableVertexAttribArray(a),r.bindFramebuffer(r.FRAMEBUFFER,null),r.viewport(0,0,H,W),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4))};let Z=0;return{updateLocation:function(t){const{width:e,height:u,maxHeight:h,heightMapZoom:_,topYCoord:T,ySize:R,colorVec:A,step:M,west:w,dLng:L,dec:D,Hi:F,cornerClipCoords:S,cornerTextureCoords:P,outputWidth:C,outputHeight:I,belowCanopy:B}=t;r.useProgram(i),H=C,W=I,r.canvas.width=H,r.canvas.height=W,r.bindBuffer(r.ARRAY_BUFFER,o),r.bufferData(r.ARRAY_BUFFER,new Float32Array(S),r.STATIC_DRAW),r.enableVertexAttribArray(n),r.vertexAttribPointer(n,2,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,s),r.bufferData(r.ARRAY_BUFFER,new Float32Array(P),r.STATIC_DRAW),r.enableVertexAttribArray(a),r.vertexAttribPointer(a,2,r.FLOAT,!1,0,0),r.uniform1f(l,e),r.uniform1f(c,u),r.uniform1f(f,h),r.uniform1f(d,_),r.uniform1f(m,T),r.uniform1f(g,R),r.uniform4fv(b,A),r.uniform1f(x,M),r.uniform1f(p,w),r.uniform1f(E,L),r.uniform1f(y,D),r.uniform1f(v,F),r.uniform1f(U,B?1:0),window.cancelAnimationFrame(G),G=window.requestAnimationFrame(j)},updateViewport:function(t){const{xStart:e,yStart:o,xEnd:n,yEnd:s}=t;r.useProgram(i),r.uniform1f(M,e),r.uniform1f(w,o),r.uniform1f(L,n),r.uniform1f(D,s),window.cancelAnimationFrame(G),G=window.requestAnimationFrame(j)},updateDate:t=>{const{dec:e,Hi:o}=t;r.useProgram(i),r.uniform1f(y,e),r.uniform1f(v,o),window.cancelAnimationFrame(G),G=window.requestAnimationFrame(j)},updateDateRange:t=>T(this,void 0,void 0,(function*(){const{startDate:e,endDate:o,iterations:n,emit:s}=t;r.useProgram(i);const a=Z=Date.now();r.uniform4fv(C,new Float32Array([1/n,0,0,0]));const u=Math.floor((o.getTime()-e.getTime())/n),h=H,l=W,c=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,c),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,h,l,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR);const f=r.createTexture();r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,f),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,h,l,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR);const d=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,d);const m=r.COLOR_ATTACHMENT0;r.uniform1i(F,1);for(let t=0;t<n;t++){if(r.useProgram(i),s("tileloaded",t,n-1),a!==Z)return r.deleteFramebuffer(d),r.deleteTexture(c),r.deleteTexture(f),!0;yield new Promise(((o,n)=>{window.requestAnimationFrame((()=>{r.useProgram(i),r.uniform1i(S,1);const n=t%2==0?f:c,s=t%2==0?c:f;r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,n),r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,s),r.bindFramebuffer(r.FRAMEBUFFER,d),r.framebufferTexture2D(r.FRAMEBUFFER,m,r.TEXTURE_2D,s,0);const a=r.checkFramebufferStatus(r.FRAMEBUFFER);a!==r.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+a);const{dec:g,Hi:x}=_(new Date(e.getTime()+u*t));r.uniform1f(y,g),r.uniform1f(v,x),r.viewport(0,0,h,l),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4),o()}))}))}return yield new Promise(((t,e)=>{window.requestAnimationFrame((()=>{if(r.useProgram(i),a!==Z)return r.deleteFramebuffer(d),r.deleteTexture(c),r.deleteTexture(f),void t(!0);r.uniform1i(F,2),r.uniform1i(P,1),j(),r.uniform1i(S,0),r.uniform1i(P,0),r.uniform1i(F,0),r.deleteFramebuffer(d),r.deleteTexture(c),r.deleteTexture(f),t(!1)}))}))})),updateColor:t=>{const{colorVec:e}=t;r.useProgram(i),r.uniform4fv(b,e),window.cancelAnimationFrame(G),G=window.requestAnimationFrame(j)},generateShadeProfile:t=>{if(r.useProgram(i),null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");const{dates:e,texCoords:o,shadeColor:s,sunColor:a}=t,h=o.length,l=e.length,c=r.getUniform(i,b);r.uniform4fv(b,s),r.uniform4fv(O,a),r.uniform1i(I,1);const f=r.createTexture();r.activeTexture(r.TEXTURE3),R({gl:r,imageData:null,width:h,height:l,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST,format:r.RGBA,texture:f});const d=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,d),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,f,0);const m=r.checkFramebufferStatus(r.FRAMEBUFFER);m!==r.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+m);const g=o.map((t=>[t[0],t[1],0,0])).flat(),x=r.createTexture();r.activeTexture(r.TEXTURE2),R({gl:r,texture:x,imageData:new Float32Array(g),width:g.length/4,height:1,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST,format:r.RGBA,type:r.FLOAT}),r.uniform1i(B,2);const p=e.map((t=>{const{dec:e,Hi:r}=_(t);return[-e,r/10,0,0]})).flat(),E=r.createTexture();r.activeTexture(r.TEXTURE1),R({gl:r,texture:E,imageData:new Float32Array(p),width:1,height:e.length,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST,format:r.RGBA,type:r.FLOAT}),r.uniform1i(N,1),r.viewport(0,0,h,l),r.clear(r.COLOR_BUFFER_BIT),r.bindBuffer(r.ARRAY_BUFFER,u),r.enableVertexAttribArray(n),r.drawArrays(r.TRIANGLE_STRIP,0,4);const T=new Uint8Array(h*l*4);return r.readPixels(0,0,h,l,r.RGBA,r.UNSIGNED_BYTE,T),r.deleteTexture(f),r.deleteTexture(E),r.deleteTexture(x),r.deleteFramebuffer(d),r.uniform1i(N,0),r.uniform1i(B,0),r.uniform1i(I,0),r.uniform4fv(b,c),r.uniform4fv(O,[0,0,0,0]),T},generateLocationShadeProfile:t=>{if(r.useProgram(i),null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");const{dates:e,texCoord:o,shadeColor:s,sunColor:a}=t,h=e[0].length,l=e.length,c=r.getUniform(i,b);r.uniform4fv(b,s),r.uniform4fv(O,a),r.uniform1i(X,1),r.uniform2fv(z,[o[0],o[1]]);const f=r.createTexture();r.activeTexture(r.TEXTURE2),R({gl:r,imageData:null,width:h,height:l,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST,format:r.RGBA,texture:f});const d=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,d),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,f,0);const m=r.checkFramebufferStatus(r.FRAMEBUFFER);m!==r.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+m);const g=e.flat().map((t=>{const{dec:e,Hi:r}=_(t);return[-e,r/10,0,0]})).flat(),x=r.createTexture();r.activeTexture(r.TEXTURE1),R({gl:r,texture:x,imageData:new Float32Array(g),width:h,height:l,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST,format:r.RGBA,type:r.FLOAT}),r.uniform1i(N,1),r.viewport(0,0,h,l),r.clear(r.COLOR_BUFFER_BIT),r.bindBuffer(r.ARRAY_BUFFER,u),r.enableVertexAttribArray(n),r.drawArrays(r.TRIANGLE_STRIP,0,4);const p=new Uint8Array(h*l*4);return r.readPixels(0,0,h,l,r.RGBA,r.UNSIGNED_BYTE,p),r.deleteTexture(f),r.deleteTexture(x),r.deleteFramebuffer(d),r.uniform1i(N,0),r.uniform1i(X,0),r.uniform4fv(b,c),r.uniform4fv(O,[0,0,0,0]),p}}}({context:this._gl}),this._color=this._parseColor(this.options.color),this._buildingRasterizer=new b(this._gl),this._tileMerger=new it(this._gl),this._reset=this._reset.bind(this),this._draw=this._draw.bind(this)}onRemove(){return this._map&&this._map.off("moveend",this._reset),this}setDate(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(nt(this._compiledKernel,{date:this.options.date}),this._flush())):this.emit("idle"),this}_setDateForTimezone(t,e){let r=0;e&&(r=p(this.options.date)-p(this.options.date,e)),this.setDate(new Date(t.getTime()-r))}setColor(t){return this.options.color!==t&&(this.options.color=t,this._color=this._parseColor(this.options.color),this._compiledKernel&&(at(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setOpacity(t){return this.options.opacity!==t&&(this.options.opacity=t,this._compiledKernel&&(at(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setBelowCanopy(t){return this.options.belowCanopy=t,this._heightMap?this._draw(this._heightMap):this._reset(),this}setTerrainSource(t){return this.options.terrainSource=t,delete this._heightMap,this._reset(),this}setDSMSource(t){return this.options.dsmSource=t,delete this._heightMap,this._reset(),this}setSunExposure(t=!1,e){return T(this,void 0,void 0,(function*(){if(this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:t}),e){const{startDate:r=new Date,endDate:i=new Date,iterations:o=32}=e;this.options.sunExposure={enabled:t,startDate:r,endDate:i,iterations:o}}if(this._map&&this._compiledKernel&&this._heightMap){if(!1===t)nt(this._compiledKernel,{date:this.options.date});else{const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!(t instanceof Date&&e instanceof Date))throw new Error("Start date or end date or both are missing");if(e.getTime()<t.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield st(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._flush()}return this}))}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:i,height:o}=this._heightMap,n=e.min;return t.map((t=>{const e=y(t,r);return[(e.x-n.x)/i,(e.y-n.y)/o]}))}return[]}_getBounds(t,e){const{width:r,height:o}=this.options.getSize();if(Number.isNaN(r)||Number.isNaN(o))return t.getBounds();const n=t.getCenter(),s=y(n,e),a=v(new i(s.x-r/2,s.y-o/2),e),u=v(new i(s.x+r/2,s.y+o/2),e);return t.createBounds({nw:a,se:u})}_getDEMZoom(t){const e=Math.min(this.options.terrainSource._overzoom||this.options.terrainSource.maxZoom,t.getZoom());return Math.round(e)}_reset(){return T(this,void 0,void 0,(function*(){if(this.options.debug("_reset()"),this._map){const t=E(this._map);let e=this._getDEMZoom(t);try{this._bounds=this._getBounds(t,e)}catch(t){return console.error("Invalid bounds returned: ",t),this}try{if(!t.isLeaflet()&&this._map.getPitch()>45){yield new Promise((t=>{this._map.loaded()?t(!0):this._map.once("idle",(function(){t(!0)}))}));const r=this._map.style._sourceCaches["other:composite"].getVisibleCoordinates().reverse(),o=r.reduce(((t,e)=>Math.max(t,e.canonical.z)),Number.MIN_SAFE_INTEGER),n=r.filter((t=>t.canonical.z===o)).map((t=>t.canonical)),[s,a,u,h]=n.reduce(((t,e)=>[Math.min(t[0],e.x),Math.min(t[1],e.y),Math.max(t[2],e.x),Math.max(t[3],e.y)]),[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER]),l=v(new i(512*s,512*a),o+1),c=v(new i(512*(u+1),512*(h+1)),o+1);e=o+1,this._bounds=t.createBounds({nw:l,se:c})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield et({gl:this._gl,demZoom:e,bounds:this._bounds,terrainSource:this.options.terrainSource,dsmSource:this.options.dsmSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,tileLoaded:(t,e)=>this.emit("tileloaded",t,e),forceUpdate:!this._heightMap});this._heightMap=r,r.dirty&&(yield this._draw(r))}return this}))}_draw(t){return T(this,void 0,void 0,(function*(){if(this.options.debug("_draw()"),this._canvas&&this._compiledKernel&&this._map){if(ut({kernel:this._compiledKernel,map:E(this._map),heightMap:t,color:this._color,belowCanopy:this.options.belowCanopy,opacity:this.options.opacity,now:this.options.date,maxZoom:this.options.terrainSource.maxZoom}),this.options.sunExposure.enabled){const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!0===(yield st(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._bounds&&this._repositionCanvas(this._bounds)}return this}))}readPixel(t,e){const r=new Uint8Array(4);return this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r),r}toGeoTiff(){const t=(t,e,r,i)=>{const o=new Uint8Array(r*i*4);this._gl.readPixels(t,e,r,i,this._gl.RGBA,this._gl.UNSIGNED_BYTE,o);const n=r*i*1,s=1*r,a=(i-1)*s,u=new Uint8Array(n),h=new Uint8Array(n);let l=0;const{startDate:c,endDate:f}=this.options.sunExposure;this.options.sunExposure.enabled&&c&&f&&(l=f.getTime()-c.getTime());for(let t=0;t<o.length;t+=4){let e;if(this.options.sunExposure.enabled){const r=o.subarray(t,t+3),i=x(r,.5,l)/1e3/60,n=Math.min(Math.floor(i/6),255);e=new Uint8Array([n])}else{e=o[t]+o[t+1]+o[t+2]===0?new Uint8Array([255]):new Uint8Array([0])}u.set(e,t/4*1)}for(let t=0;t<n;t+=s)h.set(u.subarray(t,t+s),a-t);return h};if(this._map){const e=this._canvas.width,r=this._canvas.height,i=t(0,0,e,r),o=E(this._map),{lat:n,lng:s}=o.getBounds().getNorthWest(),a=o.getBounds().getSouthEast(),u=[0,0,0,s,n,0],h=[(a.lng-s)/e,(n-a.lat)/r,0];return this.options.sunExposure.enabled,{data:i,metadata:{width:e,height:r,ModelTiepoint:u,ModelPixelScale:h,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}return null}_generateShadeProfile(t){if(this._compiledKernel){const e=this._lngLatToTextureCoords(t.locations);return((t,e)=>{const r=ot({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=ot({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{texCoords:e}))}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=p(t.startDate)-p(t.startDate,t.tzId),r=t.startDate.getTime()-e,i=(t.endDate.getTime()-e-r)/86400/1e3,o=1440,n=[],s=828e5,a=p(new Date(r),t.tzId);for(let e=0;e<i;e++){const i=p(new Date(r+86400*e*1e3+s),t.tzId)-a;n[e]=i}const u=[];for(let t=0;t<o;t++){const e=[];for(let o=0;o<i;o++){const i=r+86400*o*1e3+60*t*1e3;e.push(new Date(i+n[o]))}u.push(e)}const h=this._lngLatToTextureCoords([t.location])[0],l=((t,e)=>{const r=ot({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=ot({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateLocationShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{dates:u,texCoord:h}));return l.toArray=function(){const e=new Array;for(let r=0;r<i;r++){const n=[];for(let e=o-1;e>=0;e--){const o=e*i*4+4*r,s=this.slice(o,o+4);n.push(s.join("")===t.sunColor.join("")?1:0)}e.push(n)}return e},{data:l,width:i,height:o}}return{data:new Uint8Array,width:0,height:0}}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this.readPixel(t,e),{startDate:i,endDate:o}=this.options.sunExposure,n=o.getTime()-i.getTime(),s=x(r,.5,n);return Math.abs(s/1e3/3600)}return 0}_repositionCanvas(t){}_flush(){}flushSync(){this._gl.finish()}_parseColor(t){t=t.replace("#","");const e={r:0,g:0,b:0};return/^([0-9A-F]{3}){1,2}$/i.test(t)&&(3===t.length?(e.r=parseInt(t[0]+t[0],16),e.g=parseInt(t[1]+t[1],16),e.b=parseInt(t[2]+t[2],16)):6===t.length&&(e.r=parseInt(t[0]+t[1],16),e.g=parseInt(t[2]+t[3],16),e.b=parseInt(t[4]+t[5],16))),e}}{constructor(t){super(t),this.id="shademap-layer",this.type="custom",this.canvasSourceId="canvas-source",this.attributionSourceId="attribution-source",this.canvasLayerId="canvas-layer",this.attributionLayerId="attribution-layer",this._refreshing=0,this._raf=0,this.id=this.id+g(),this.canvasSourceId=this.canvasSourceId+g(),this.attributionSourceId=this.attributionSourceId+g(),this.canvasLayerId=this.canvasLayerId+g(),this.attributionLayerId=this.attributionLayerId+g(),this.options.terrainSource.tileSize>256&&(this.options.terrainSource.maxZoom=this.options.terrainSource.maxZoom+1),this._moveEndHandler=()=>this._map&&this._reset()}render(t,e){}addTo(t){return t.addLayer(this),this}onAdd(t){this._map=t,document.body.appendChild(this._canvas),this._canvas.style.display="none";const e=t.getBounds(),r=e.getNorthWest(),i=e.getNorthEast(),o=e.getSouthEast(),n=e.getSouthWest(),s=[[r.lng,r.lat],[i.lng,i.lat],[o.lng,o.lat],[n.lng,n.lat]];t.addSource(this.canvasSourceId,{type:"canvas",canvas:this._canvas,coordinates:s,animate:!1}),t.addLayer({id:this.canvasLayerId,type:"raster",source:this.canvasSourceId,paint:{"raster-fade-duration":0}}),t.addSource(this.attributionSourceId,{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[-122.210598,47.769799]}},attribution:'<a href="https://shademap.app/about">© ShadeMap</a>'}),t.addLayer({id:this.attributionLayerId,type:"fill",source:this.attributionSourceId});const a=t.getSource(this.canvasSourceId),u=()=>{this._refreshing>0&&(a.texture.update(this._canvas,{premultiply:!0}),a.fire({type:"data",dataType:"source",sourceDataType:"content"}),this._refreshing--,this.options.debug("repaint"),1===this._refreshing&&this.emit("idle")),this._raf=requestAnimationFrame(u)};return this._raf=requestAnimationFrame(u),this._map.on("moveend",this._moveEndHandler),this._moveEndHandler(),this}onRemove(){return this._map&&(this._map.off("moveend",this._moveEndHandler),this._map.removeLayer(this.attributionLayerId),this._map.removeLayer(this.canvasLayerId),this._map.removeSource(this.attributionSourceId),this._map.removeSource(this.canvasSourceId)),cancelAnimationFrame(this._raf),document.body.removeChild(this._canvas),this.options.debug("onRemove called"),this}_getHeightMapCoords(t,e){if(this._map&&this.options.sunExposure.enabled&&this._bounds&&this._heightMap){const r=this._map.unproject([t,e]);if(r.toString()===this._map.unproject([t,e+1]).toString())return new i(-1,-1);const{visibleDEMPixelBounds:o,demZoom:n}=this._heightMap,s=E(this._map).project(r,n).subtract(o.min);return s.y=o.max.y-o.min.y-s.y,s}return new i(-1,-1)}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this._getHeightMapCoords(t,e),i=this.readPixel(r.x,r.y),{startDate:o,endDate:n}=this.options.sunExposure,s=n.getTime()-o.getTime(),a=x(i,.5,s);return Math.abs(a/1e3/3600)}return 0}remove(){this._map&&this._map.removeLayer(this.id)}_flush(){this._refreshing=2}_repositionCanvas(t){if(this._map){const e=this._map.getSource(this.canvasSourceId);if(e){const r=t.getNorthWest(),i=t.getNorthEast(),o=t.getSouthEast(),n=t.getSouthWest(),s=[[r.lng,r.lat],[i.lng,i.lat],[o.lng,o.lat],[n.lng,n.lat]];window.requestAnimationFrame((()=>{e.texture.update(this._canvas,{premultiply:!0}),e.setCoordinates(s),this.emit("idle")}))}}return this}}}));
|
|
8
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ShadeMap=e()}(this,(function(){"use strict";function t(t,e,r){var i=e[1],o=e[0],n=i-o;return t===i&&r?t:((t-o)%n+n)%n+o}function e(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}var r=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function i(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var o=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function n(t,e,o){return t instanceof i?t:r(t)?new i(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new i(t.x,t.y):new i(t,e,o)}function a(t,e){if(t)for(var r=e?[t,e]:t,i=0,o=r.length;i<o;i++)this.extend(r[i])}function s(t,e){return!t||t instanceof a?t:new a(t,e)}function u(t,e){if(t)for(var r=e?[t,e]:t,i=0,o=r.length;i<o;i++)this.extend(r[i])}function h(t,e){return t instanceof u?t:new u(t,e)}i.prototype={clone:function(){return new i(this.x,this.y)},add:function(t){return this.clone()._add(n(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(n(t))},_subtract:function(t){return this.x-=t.x,this.y-=t.y,this},divideBy:function(t){return this.clone()._divideBy(t)},_divideBy:function(t){return this.x/=t,this.y/=t,this},multiplyBy:function(t){return this.clone()._multiplyBy(t)},_multiplyBy:function(t){return this.x*=t,this.y*=t,this},scaleBy:function(t){return new i(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new i(this.x/t.x,this.y/t.y)},round:function(){return this.clone()._round()},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},floor:function(){return this.clone()._floor()},_floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.clone()._ceil()},_ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},trunc:function(){return this.clone()._trunc()},_trunc:function(){return this.x=o(this.x),this.y=o(this.y),this},distanceTo:function(t){var e=(t=n(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=n(t)).x===this.x&&t.y===this.y},contains:function(t){return t=n(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+e(this.x)+", "+e(this.y)+")"}},a.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof i||"number"==typeof t[0]||"x"in t)e=r=n(t);else if(e=(t=s(t)).min,r=t.max,!e||!r)return this;return this.min||this.max?(this.min.x=Math.min(e.x,this.min.x),this.max.x=Math.max(r.x,this.max.x),this.min.y=Math.min(e.y,this.min.y),this.max.y=Math.max(r.y,this.max.y)):(this.min=e.clone(),this.max=r.clone()),this},getCenter:function(t){return n((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return n(this.min.x,this.max.y)},getTopRight:function(){return n(this.max.x,this.min.y)},getTopLeft:function(){return this.min},getBottomRight:function(){return this.max},getSize:function(){return this.max.subtract(this.min)},contains:function(t){var e,r;return(t="number"==typeof t[0]||t instanceof i?n(t):s(t))instanceof a?(e=t.min,r=t.max):e=r=t,e.x>=this.min.x&&r.x<=this.max.x&&e.y>=this.min.y&&r.y<=this.max.y},intersects:function(t){t=s(t);var e=this.min,r=this.max,i=t.min,o=t.max,n=o.x>=e.x&&i.x<=r.x,a=o.y>=e.y&&i.y<=r.y;return n&&a},overlaps:function(t){t=s(t);var e=this.min,r=this.max,i=t.min,o=t.max,n=o.x>e.x&&i.x<r.x,a=o.y>e.y&&i.y<r.y;return n&&a},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,i=Math.abs(e.x-r.x)*t,o=Math.abs(e.y-r.y)*t;return s(n(e.x-i,e.y-o),n(r.x+i,r.y+o))},equals:function(t){return!!t&&(t=s(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},u.prototype={extend:function(t){var e,r,i=this._southWest,o=this._northEast;if(t instanceof c)e=t,r=t;else{if(!(t instanceof u))return t?this.extend(f(t)||h(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return i||o?(i.lat=Math.min(e.lat,i.lat),i.lng=Math.min(e.lng,i.lng),o.lat=Math.max(r.lat,o.lat),o.lng=Math.max(r.lng,o.lng)):(this._southWest=new c(e.lat,e.lng),this._northEast=new c(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,i=Math.abs(e.lat-r.lat)*t,o=Math.abs(e.lng-r.lng)*t;return new u(new c(e.lat-i,e.lng-o),new c(r.lat+i,r.lng+o))},getCenter:function(){return new c((this._southWest.lat+this._northEast.lat)/2,(this._southWest.lng+this._northEast.lng)/2)},getSouthWest:function(){return this._southWest},getNorthEast:function(){return this._northEast},getNorthWest:function(){return new c(this.getNorth(),this.getWest())},getSouthEast:function(){return new c(this.getSouth(),this.getEast())},getWest:function(){return this._southWest.lng},getSouth:function(){return this._southWest.lat},getEast:function(){return this._northEast.lng},getNorth:function(){return this._northEast.lat},contains:function(t){t="number"==typeof t[0]||t instanceof c||"lat"in t?f(t):h(t);var e,r,i=this._southWest,o=this._northEast;return t instanceof u?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=i.lat&&r.lat<=o.lat&&e.lng>=i.lng&&r.lng<=o.lng},intersects:function(t){t=h(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),o=t.getNorthEast(),n=o.lat>=e.lat&&i.lat<=r.lat,a=o.lng>=e.lng&&i.lng<=r.lng;return n&&a},overlaps:function(t){t=h(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),o=t.getNorthEast(),n=o.lat>e.lat&&i.lat<r.lat,a=o.lng>e.lng&&i.lng<r.lng;return n&&a},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=h(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var l=function(t){var e,r,i,o;for(r=1,i=arguments.length;r<i;r++)for(e in o=arguments[r])t[e]=o[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),i=this.scale(e);return this.transformation._transform(r,i)},pointToLatLng:function(t,e){var r=this.scale(e),i=this.transformation.untransform(t,r);return this.projection.unproject(i)},project:function(t){return this.projection.project(t)},unproject:function(t){return this.projection.unproject(t)},scale:function(t){return 256*Math.pow(2,t)},zoom:function(t){return Math.log(t/256)/Math.LN2},getProjectedBounds:function(t){if(this.infinite)return null;var e=this.projection.bounds,r=this.scale(t);return new a(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(e){var r=this.wrapLng?t(e.lng,this.wrapLng,!0):e.lng;return new c(this.wrapLat?t(e.lat,this.wrapLat,!0):e.lat,r,e.alt)},wrapLatLngBounds:function(t){var e=t.getCenter(),r=this.wrapLatLng(e),i=e.lat-r.lat,o=e.lng-r.lng;if(0===i&&0===o)return t;var n=t.getSouthWest(),a=t.getNorthEast();return new u(new c(n.lat-i,n.lng-o),new c(a.lat-i,a.lng-o))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,i=t.lat*r,o=e.lat*r,n=Math.sin((e.lat-t.lat)*r/2),a=Math.sin((e.lng-t.lng)*r/2),s=n*n+Math.cos(i)*Math.cos(o)*a*a,u=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s));return this.R*u}});function c(t,e,r){if(isNaN(t)||isNaN(e))throw new Error("Invalid LatLng object: ("+t+", "+e+")");this.lat=+t,this.lng=+e,void 0!==r&&(this.alt=+r)}function f(t,e,i){return t instanceof c?t:r(t)&&"object"!=typeof t[0]?3===t.length?new c(t[0],t[1],t[2]):2===t.length?new c(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new c(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new c(t,e,i)}c.prototype={equals:function(t,e){return!!t&&(t=f(t),Math.max(Math.abs(this.lat-t.lat),Math.abs(this.lng-t.lng))<=(void 0===e?1e-9:e))},toString:function(t){return"LatLng("+e(this.lat,t)+", "+e(this.lng,t)+")"},distanceTo:function(t){return l.distance(this,f(t))},wrap:function(){return l.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return h([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new c(this.lat,this.lng,this.alt)}};const d=256,m=.40909994067971484,_=t=>{const e=t.valueOf()/864e5-10957.5,r=6.240059966692059+.017201969994578018*e,i=r+.017453292519943295*(1.9148*Math.sin(r)+.02*Math.sin(2*r)+3e-4*Math.sin(3*r))+1.796593062783907+Math.PI,o=Math.atan2(Math.sin(i)*Math.cos(m),Math.cos(i));return{dec:Math.asin(Math.sin(m)*Math.sin(i)),Hi:(4.889714432387314+6.3003876824396166*e-o)%(2*Math.PI)+2*Math.PI}},x=()=>Math.floor(1e7*Math.random()),g=(t,e,r)=>{const i=1/e,o=Math.min(t[0]*i,255),n=Math.min(t[1]*i,255),a=Math.min(t[2]*i,255);let s=0;return o+n+a!==0&&(s=o>0?o/255*.5+.5:a>0?.5*(1-a/255):.5),s*r},p=(t=new Date,e)=>{const r=new Date(t.toLocaleString("en-US",{timeZone:"UTC"})),i=new Date(t.toLocaleString("en-US",e?{timeZone:e}:{}));return r.getTime()-i.getTime()};const E=t=>{const e=()=>!t.getPitch;return{project:(r,o)=>{if(e())return t.project(r,o);{const{lat:t,lng:e}=r;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*d)(e,o),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*d)(t,o))}},unproject:(r,i)=>{return e()?t.unproject(r,i):new c((o=r.y,n=i,a=Math.PI-2*Math.PI*o/d/Math.pow(2,n),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/d/Math.pow(2,e)*360-180}(r.x,i));var o,n,a},screenUnproject:r=>e()?t.containerPointToLatLng(r):t.unproject(r),getZoom:()=>e()?t.getZoom():t.getZoom()+1,getCenter:()=>t.getCenter(),getBounds:()=>t.getBounds(),eachLayer:r=>{e()&&t.eachLayer(r)},getBearing:()=>e()?0:t.getBearing(),getPitch:()=>e()?0:t.getPitch(),rawMap:()=>t,isLeaflet:e,getPixelDimensions:()=>{const e=t.getContainer();return{width:e.clientWidth,height:e.clientHeight}},createBounds:t=>{const{nw:e,se:r}=t;return new u(e,r)}}};function T(t,e,r,i){return new(r||(r=Promise))((function(o,n){function a(t){try{u(i.next(t))}catch(t){n(t)}}function s(t){try{u(i.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((i=i.apply(t,e||[])).next())}))}function y(t,e,r){r=r||2;var i,o,n,a,s,u,h,l=e&&e.length,c=l?e[0]*r:t.length,f=v(t,0,c,r,!0),d=[];if(!f||f.next===f.prev)return d;if(l&&(f=function(t,e,r,i){var o,n,a,s=[];for(o=0,n=e.length;o<n;o++)(a=v(t,e[o]*i,o<n-1?e[o+1]*i:t.length,i,!1))===a.next&&(a.steiner=!0),s.push(P(a));for(s.sort(F),o=0;o<s.length;o++)r=D(s[o],r);return r}(t,e,f,r)),t.length>80*r){i=n=t[0],o=a=t[1];for(var m=r;m<c;m+=r)(s=t[m])<i&&(i=s),(u=t[m+1])<o&&(o=u),s>n&&(n=s),u>a&&(a=u);h=0!==(h=Math.max(n-i,a-o))?32767/h:0}return A(f,d,r,i,o,h,0),d}function v(t,e,r,i,o){var n,a;if(o===Y(t,e,r,i)>0)for(n=e;n<r;n+=i)a=W(n,t[n],t[n+1],a);else for(n=r-i;n>=e;n-=i)a=W(n,t[n],t[n+1],a);return a&&N(a,a.next)&&(j(a),a=a.next),a}function R(t,e){if(!t)return t;e||(e=t);var r,i=t;do{if(r=!1,i.steiner||!N(i,i.next)&&0!==B(i.prev,i,i.next))i=i.next;else{if(j(i),(i=e=i.prev)===i.next)break;r=!0}}while(r||i!==e);return e}function A(t,e,r,i,o,n,a){if(t){!a&&n&&function(t,e,r,i){var o=t;do{0===o.z&&(o.z=S(o.x,o.y,e,r,i)),o.prevZ=o.prev,o.nextZ=o.next,o=o.next}while(o!==t);o.prevZ.nextZ=null,o.prevZ=null,function(t){var e,r,i,o,n,a,s,u,h=1;do{for(r=t,t=null,n=null,a=0;r;){for(a++,i=r,s=0,e=0;e<h&&(s++,i=i.nextZ);e++);for(u=h;s>0||u>0&&i;)0!==s&&(0===u||!i||r.z<=i.z)?(o=r,r=r.nextZ,s--):(o=i,i=i.nextZ,u--),n?n.nextZ=o:t=o,o.prevZ=n,n=o;r=i}n.nextZ=null,h*=2}while(a>1)}(o)}(t,i,o,n);for(var s,u,h=t;t.prev!==t.next;)if(s=t.prev,u=t.next,n?M(t,i,o,n):b(t))e.push(s.i/r|0),e.push(t.i/r|0),e.push(u.i/r|0),j(t),t=u.next,h=u.next;else if((t=u)===h){a?1===a?A(t=w(R(t),e,r),e,r,i,o,n,2):2===a&&U(t,e,r,i,o,n):A(R(t),e,r,i,o,n,1);break}}}function b(t){var e=t.prev,r=t,i=t.next;if(B(e,r,i)>=0)return!1;for(var o=e.x,n=r.x,a=i.x,s=e.y,u=r.y,h=i.y,l=o<n?o<a?o:a:n<a?n:a,c=s<u?s<h?s:h:u<h?u:h,f=o>n?o>a?o:a:n>a?n:a,d=s>u?s>h?s:h:u>h?u:h,m=i.next;m!==e;){if(m.x>=l&&m.x<=f&&m.y>=c&&m.y<=d&&C(o,s,n,u,a,h,m.x,m.y)&&B(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function M(t,e,r,i){var o=t.prev,n=t,a=t.next;if(B(o,n,a)>=0)return!1;for(var s=o.x,u=n.x,h=a.x,l=o.y,c=n.y,f=a.y,d=s<u?s<h?s:h:u<h?u:h,m=l<c?l<f?l:f:c<f?c:f,_=s>u?s>h?s:h:u>h?u:h,x=l>c?l>f?l:f:c>f?c:f,g=S(d,m,e,r,i),p=S(_,x,e,r,i),E=t.prevZ,T=t.nextZ;E&&E.z>=g&&T&&T.z<=p;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=x&&E!==o&&E!==a&&C(s,l,u,c,h,f,E.x,E.y)&&B(E.prev,E,E.next)>=0)return!1;if(E=E.prevZ,T.x>=d&&T.x<=_&&T.y>=m&&T.y<=x&&T!==o&&T!==a&&C(s,l,u,c,h,f,T.x,T.y)&&B(T.prev,T,T.next)>=0)return!1;T=T.nextZ}for(;E&&E.z>=g;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=x&&E!==o&&E!==a&&C(s,l,u,c,h,f,E.x,E.y)&&B(E.prev,E,E.next)>=0)return!1;E=E.prevZ}for(;T&&T.z<=p;){if(T.x>=d&&T.x<=_&&T.y>=m&&T.y<=x&&T!==o&&T!==a&&C(s,l,u,c,h,f,T.x,T.y)&&B(T.prev,T,T.next)>=0)return!1;T=T.nextZ}return!0}function w(t,e,r){var i=t;do{var o=i.prev,n=i.next.next;!N(o,n)&&O(o,i,i.next,n)&&z(o,n)&&z(n,o)&&(e.push(o.i/r|0),e.push(i.i/r|0),e.push(n.i/r|0),j(i),j(i.next),i=t=n),i=i.next}while(i!==t);return R(i)}function U(t,e,r,i,o,n){var a=t;do{for(var s=a.next.next;s!==a.prev;){if(a.i!==s.i&&I(a,s)){var u=H(a,s);return a=R(a,a.next),u=R(u,u.next),A(a,e,r,i,o,n,0),void A(u,e,r,i,o,n,0)}s=s.next}a=a.next}while(a!==t)}function F(t,e){return t.x-e.x}function D(t,e){var r=function(t,e){var r,i=e,o=t.x,n=t.y,a=-1/0;do{if(n<=i.y&&n>=i.next.y&&i.next.y!==i.y){var s=i.x+(n-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(s<=o&&s>a&&(a=s,r=i.x<i.next.x?i:i.next,s===o))return r}i=i.next}while(i!==e);if(!r)return null;var u,h=r,l=r.x,c=r.y,f=1/0;i=r;do{o>=i.x&&i.x>=l&&o!==i.x&&C(n<c?o:a,n,l,c,n<c?a:o,n,i.x,i.y)&&(u=Math.abs(n-i.y)/(o-i.x),z(i,t)&&(u<f||u===f&&(i.x>r.x||i.x===r.x&&L(r,i)))&&(r=i,f=u)),i=i.next}while(i!==h);return r}(t,e);if(!r)return e;var i=H(r,t);return R(i,i.next),R(r,r.next)}function L(t,e){return B(t.prev,t,e.prev)<0&&B(e.next,t,t.next)<0}function S(t,e,r,i,o){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*o|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*o|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function P(t){var e=t,r=t;do{(e.x<r.x||e.x===r.x&&e.y<r.y)&&(r=e),e=e.next}while(e!==t);return r}function C(t,e,r,i,o,n,a,s){return(o-a)*(e-s)>=(t-a)*(n-s)&&(t-a)*(i-s)>=(r-a)*(e-s)&&(r-a)*(n-s)>=(o-a)*(i-s)}function I(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==e.i&&r.next.i!==e.i&&O(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(z(t,e)&&z(e,t)&&function(t,e){var r=t,i=!1,o=(t.x+e.x)/2,n=(t.y+e.y)/2;do{r.y>n!=r.next.y>n&&r.next.y!==r.y&&o<(r.next.x-r.x)*(n-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next}while(r!==t);return i}(t,e)&&(B(t.prev,t,e.prev)||B(t,e.prev,e))||N(t,e)&&B(t.prev,t,t.next)>0&&B(e.prev,e,e.next)>0)}function B(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function N(t,e){return t.x===e.x&&t.y===e.y}function O(t,e,r,i){var o=G(B(t,e,r)),n=G(B(t,e,i)),a=G(B(r,i,t)),s=G(B(r,i,e));return o!==n&&a!==s||(!(0!==o||!X(t,r,e))||(!(0!==n||!X(t,i,e))||(!(0!==a||!X(r,t,i))||!(0!==s||!X(r,e,i)))))}function X(t,e,r){return e.x<=Math.max(t.x,r.x)&&e.x>=Math.min(t.x,r.x)&&e.y<=Math.max(t.y,r.y)&&e.y>=Math.min(t.y,r.y)}function G(t){return t>0?1:t<0?-1:0}function z(t,e){return B(t.prev,t,t.next)<0?B(t,e,t.next)>=0&&B(t,t.prev,e)>=0:B(t,e,t.prev)<0||B(t,t.next,e)<0}function H(t,e){var r=new Z(t.i,t.x,t.y),i=new Z(e.i,e.x,e.y),o=t.next,n=e.prev;return t.next=e,e.prev=t,r.next=o,o.prev=r,i.next=r,r.prev=i,n.next=i,i.prev=n,i}function W(t,e,r,i){var o=new Z(t,e,r);return i?(o.next=i.next,o.prev=i,i.next.prev=o,i.next=o):(o.prev=o,o.next=o),o}function j(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Z(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function Y(t,e,r,i){for(var o=0,n=e,a=r-i;n<r;n+=i)o+=(t[a]-t[n])*(t[n+1]+t[a+1]),a=n;return o}function K(t){t.filter((t=>"MultiPolygon"===t.geometry.type)).forEach((e=>{const{geometry:r,properties:i,type:o}=e;if("MultiPolygon"===r.type)for(let i=0;i<r.coordinates.length;i++)t.push(Object.assign(Object.assign({},e),{geometry:Object.assign(Object.assign({},r),{type:"Polygon",coordinates:r.coordinates[i]})}))}));return t.filter((t=>"Polygon"===t.geometry.type)).map((t=>{const{geometry:e,properties:r}=t,{vertices:i}=y.flatten(e.coordinates),o=new Float32Array(i.map(((t,e)=>{if(e%2==1){const e=t*Math.PI/180;return Math.tan(e)+1/Math.cos(e)}return t}))),n=y(i),a=n.length>256?new Uint16Array(n):new Uint8Array(n),s=function(t){const{height:e=0,levels:r=0,render_height:i=0}=t;if(r)return 3.04*r;return Math.max(e,i)}(r),u=r.highlight||!1;let h=0,l=0,c=0;for(let t=0;t<i.length;t+=2)h+=i[t],l+=i[t+1],c++;return{aPosition:o,cuts:a,buildingHeight:s,centroid:[h/c,l/c],highlight:u}}))}y.deviation=function(t,e,r,i){var o=e&&e.length,n=o?e[0]*r:t.length,a=Math.abs(Y(t,0,n,r));if(o)for(var s=0,u=e.length;s<u;s++){var h=e[s]*r,l=s<u-1?e[s+1]*r:t.length;a-=Math.abs(Y(t,h,l,r))}var c=0;for(s=0;s<i.length;s+=3){var f=i[s]*r,d=i[s+1]*r,m=i[s+2]*r;c+=Math.abs((t[f]-t[m])*(t[d+1]-t[f+1])-(t[f]-t[d])*(t[m+1]-t[f+1]))}return 0===a&&0===c?0:Math.abs((c-a)/a)},y.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},i=0,o=0;o<t.length;o++){for(var n=0;n<t[o].length;n++)for(var a=0;a<e;a++)r.vertices.push(t[o][n][a]);o>0&&(i+=t[o-1].length,r.holes.push(i))}return r};const k=(t,e)=>{const{lat:r,lng:o}=t;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*d)(o,e),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*d)(r,e))},q=(t,e)=>{return new c((r=t.y,i=e,o=Math.PI-2*Math.PI*r/d/Math.pow(2,i),180/Math.PI*Math.atan(.5*(Math.exp(o)-Math.exp(-o)))),function(t,e){return t/d/Math.pow(2,e)*360-180}(t.x,e));var r,i,o};let V,$={heightMapTex:null,width:0,height:0,visibleDEMPixelBounds:new a(new i(0,0),new i(0,0)),DEMPixelBounds:new a(new i(0,0),new i(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const J=t=>T(void 0,void 0,void 0,(function*(){const{demZoom:e,getFeatures:r,terrainSource:o,dsmSource:n,tileLoaded:s,gl:h,bounds:l,buildingRasterizer:c,tileMerger:f,forceUpdate:m=!1}=t,{getSourceUrl:_,getElevation:x,maxZoom:g,tileSize:p,_overzoom:E}=o,y=(v={getFeatures:r},T(void 0,void 0,void 0,(function*(){const{getFeatures:t}=v;try{return K(yield t())}catch(t){console.log("Error merging buildings",t)}return[]})));var v;try{const t=l,r=t.getNorthWest(),o=t.getSouthEast(),E=new a(k(r,e),k(o,e));let T=new i(E.min.x,E.min.y),v=E.max.x-E.min.x;const R=E.max.y-E.min.y,A=E.max.subtract(E.min);A.y>A.x&&(T.x-=d,v+=512);const b=(t=>{const{upperLeft:e,width:r,height:i}=t,o=e.divideBy(d).floor().multiplyBy(d),n=(Math.ceil(r/d)+1)*d,s=(Math.ceil(i/d)+1)*d,u=o.add([n,s]);return new a(o,u)})({upperLeft:T,width:v,height:R}),{x:M,y:w}=b.max.subtract(b.min),U=(t=>{t.sort(((t,e)=>t.y!==e.y?t.y-e.y:t.x-e.x));const e=t.reduce(((t,e)=>e.x<t.x?e:t)).x,r=t.reduce(((t,e)=>e.y<t.y?e:t)).y;return t.map((t=>{const i=Math.pow(2,t.z);return{x:(t.x%i+i)%i,y:(t.y%i+i)%i,z:t.z,xOffset:(t.x-e)*d,yOffset:(t.y-r)*d}}))})((t=>{const{upperLeft:e,width:r,height:i,zoom:o}=t,n=e.divideBy(d).floor(),a=n.x+r/d,s=Math.min(n.y+i/d,Math.pow(2,o)-1),u=[];for(var h=n.x;h<a;h++)for(var l=n.y;l<s;l++)u.push({x:h,y:l,z:o});return u})({upperLeft:b.min,width:M,height:w,zoom:e})),F=E.max.x-E.min.x,D=E.max.y-E.min.y,L=Math.round(F),S=Math.round(D),P=JSON.stringify(U);if(!m&&P===V&&e<g)return $=Object.assign(Object.assign({},$),{outputWidth:L,outputHeight:S,visibleDEMPixelBounds:E,demZoom:e,dirty:!0}),$;const C=yield f.merge(U,{maxZoom:g,width:M,height:w,crossOrigin:"Anonymous",getSourceUrl:_,getElevation:x,tileSize:p,tileLoaded:s});if(null===C)return $=Object.assign(Object.assign({},$),{visibleDEMPixelBounds:E,demZoom:e,dirty:!1}),$;const I=new a(k(new u(n.bounds).getNorthWest(),e),k(new u(n.bounds).getSouthEast(),e)),B=I.min.subtract(b.min),N=I.max.subtract(b.min),O=[B.x/M,B.y/w,N.x/M,N.y/w].map((t=>2*t-1)),X=yield y,{maxHeight:G,heightMapTex:z}=c.raster({upperLeftTile:U[0],width:M,height:w,mapZoom:e,features:X,imageData:C,gl:h,dsmSource:n,dsmCoords:O}),H=Math.max(Math.max(n.maxHeight,G),C.maxHeight);V=P,$={heightMapTex:z,maxHeight:H,width:M,height:w,DEMPixelBounds:b,visibleDEMPixelBounds:E,raster:U,demZoom:e,dirty:!0,outputWidth:L,outputHeight:S}}catch(t){console.error("Could not decode height map",t)}return $})),Q=(t,e)=>{const{r:r,g:i,b:o}=t;return[r/255,i/255,o/255,e]},tt=(t,e)=>{const{date:r}=e,{dec:i,Hi:o}=_(r);t.updateDate({dec:i,Hi:o})},et=(t,e)=>T(void 0,void 0,void 0,(function*(){return yield t.updateDateRange(Object.assign({},e))})),rt=(t,e)=>{const{color:r,opacity:i}=e,o=Q(r,i);t.updateColor({colorVec:o})};new u([0,0],[0,0]);const it=t=>{const{kernel:e,map:r,heightMap:i,now:o,color:n,opacity:a,belowCanopy:s}=t;try{const{heightMapTex:t,outputHeight:h,outputWidth:l,maxHeight:c,width:f,height:m,DEMPixelBounds:x,visibleDEMPixelBounds:g,demZoom:p}=i;if(0===f||0===m)return;const{min:E,max:T}=g;if(!E||!T)return;const{x:y,y:v}=T.subtract(E),R=x.min,A=r.getPixelDimensions(),b=r.screenUnproject([0,0]),M=r.screenUnproject([A.width,0]),w=r.screenUnproject([A.width,A.height]),U=r.screenUnproject([0,A.height]),F=[U,w,b,M].map((t=>r.project(t,p))),D=F.map((t=>[(t.x-R.x)/f,(t.y-R.y)/m])).flat(),L=F.map((t=>[(t.x-E.x)/y,(t.y-E.y)/v])).map((t=>[2*t[0]-1,(2*t[1]-1)*(r.isLeaflet()?-1:1)])).flat(),S=R.y/d/Math.pow(2,p),P=m/d/Math.pow(2,p),C=new u(q(x.getTopLeft(),p),q(x.getBottomRight(),p)),I=C.getWest(),B=Math.abs(C.getWest()-C.getEast());((t,e)=>{const{color:r,opacity:i,date:o}=e,n=Q(r,i),{dec:a,Hi:s}=_(o);t.updateLocation(Object.assign({dec:a,Hi:s,colorVec:n,step:1},e))})(e,{heightMapTex:t,maxHeight:c,width:f,height:m,heightMapZoom:p,cornerTextureCoords:D,cornerClipCoords:L,topYCoord:S,ySize:P,west:I,dLng:B,date:o,color:n,opacity:a,outputHeight:h,outputWidth:l,belowCanopy:s})}catch(t){console.error("EXCEPTION",t)}};const ot=t=>{const{gl:e}=t,{texture:r,imageData:i=null,format:o=e.RGBA,width:n,height:a,filter:s=e.NEAREST,wrap:u=e.CLAMP_TO_EDGE,type:h=e.UNSIGNED_BYTE,internalFormat:l=o}=t;e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,s),e.texImage2D(e.TEXTURE_2D,0,l,n,a,0,o,h,i)};function nt(t){const{gl:e,vSrc:r,fSrc:i}=t,o=e.createShader(e.VERTEX_SHADER);e.shaderSource(o,r),e.compileShader(o);const n=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,i),e.compileShader(n);const a=e.createProgram();return e.attachShader(a,o),e.attachShader(a,n),e.linkProgram(a),a}class at{constructor(t){this.gl=t,this.program=nt({gl:t,vSrc:"\nuniform vec3 xyz;\nuniform vec2 dimensions;\nuniform bool use_dsm;\nattribute vec2 dsm_position;\nattribute vec2 a_position;\nfloat PI = 3.141592653589793;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\n\tvoid main() {\n\t\tif (use_dsm == true) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = dsm_position;\n v_use_dsm = 1.0;\n\t\t\treturn;\n\t\t}\n\t\tif (abs(a_position) == vec2(1,1)) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = a_position * 0.5 + 0.5;\n\t\t\treturn;\n\t\t}\n\t\tfloat x = ((a_position.x + 180.0) / 360.0 * pow(2.0, xyz.z)) * 256.0 - xyz.x;\n\t\tfloat y = (1.0 - (log(a_position.y) / PI)) / 2.0 * pow(2.0, xyz.z) * 256.0 - xyz.y;\n\t\tvec2 transformed = vec2(x, y);\n\t\tvec2 normalized = transformed / dimensions;\n\t\tvec2 final = normalized * 2.0 - 1.0;\n\t\tgl_Position = vec4(final, 0, 1);\n\t}\n",fSrc:"\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform vec4 color;\nuniform sampler2D height_map;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n if (v_use_dsm == 1.0) {\n\t \t gl_FragColor = vec4(0.0, 0.0, textureColor.b, textureColor.a);\n if (gl_FragColor.zw == vec2(0.0)) {\n discard;\n }\n } else {\n gl_FragColor = vec4(textureColor.b, textureColor.a, textureColor.b, textureColor.a);\n }\n // DSM noData values should not be included in heightMap because they produce ugly borders\n\t\treturn;\n\t} \n\tgl_FragColor = color;\n}\n"}),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.dsmAttributeLocation=t.getAttribLocation(this.program,"dsm_position"),this.useDSMUniformLocation=t.getUniformLocation(this.program,"use_dsm"),this.xyzUniformLocation=t.getUniformLocation(this.program,"xyz"),this.dimensionsUniformLocation=t.getUniformLocation(this.program,"dimensions"),this.heightMapUniformLocation=t.getUniformLocation(this.program,"height_map"),this.colorUniformLocation=t.getUniformLocation(this.program,"color"),this.positionBuffer=t.createBuffer(),this.dsmBuffer=t.createBuffer(),this.indexBuffer=t.createBuffer(),this.targetTexture=t.createTexture()}raster(t){const{features:e,upperLeftTile:r,mapZoom:o,width:n,height:a,imageData:s,dsmCoords:u,dsmSource:h,gl:l}=t,{x:c,y:f,z:m}=r;let _=0;l.useProgram(this.program),l.activeTexture(l.TEXTURE1);const x=l.createTexture();l.bindTexture(l.TEXTURE_2D,x),l.pixelStorei(l.UNPACK_ALIGNMENT,2),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.LUMINANCE_ALPHA,n,a,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,s),l.pixelStorei(l.UNPACK_ALIGNMENT,4);const g=n,p=a;l.activeTexture(l.TEXTURE0),l.bindTexture(l.TEXTURE_2D,this.targetTexture),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,g,p,0,l.RGBA,l.UNSIGNED_BYTE,null),o>15&&e.length>5?(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST)):(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.LINEAR)),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.viewport(0,0,g,p);const E=l.createFramebuffer();l.bindFramebuffer(l.FRAMEBUFFER,E);const T=l.COLOR_ATTACHMENT0;l.framebufferTexture2D(l.FRAMEBUFFER,T,l.TEXTURE_2D,this.targetTexture,0),l.disable(l.BLEND),l.bindBuffer(l.ARRAY_BUFFER,this.positionBuffer),l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,this.indexBuffer),l.clearColor(0,0,0,0),l.clear(l.COLOR_BUFFER_BIT);const y=c*d,v=f*d,R=new i(y,v);l.uniform3f(this.xyzUniformLocation,y,v,m),l.uniform2f(this.dimensionsUniformLocation,n,a),l.uniform1i(this.heightMapUniformLocation,1),l.uniform1i(this.useDSMUniformLocation,0);const A=new Float32Array([-1,-1,1,-1,-1,1,1,1]);if(l.enableVertexAttribArray(this.positionAttributeLocation),l.bufferData(l.ARRAY_BUFFER,A,l.STATIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.uniform4f(this.colorUniformLocation,0,0,0,0),l.drawArrays(l.TRIANGLE_STRIP,0,4),e.forEach((t=>{const{buildingHeight:e,aPosition:r,cuts:i,centroid:o,highlight:u}=t,h=k({lng:o[0],lat:o[1]},m).subtract(R).floor();if(h.x<0||h.y<0||h.x>n||h.y>a)return;const c=256*s[h.y*n*2+2*h.x]+s[h.y*n*2+2*h.x+1]+5*e,f=Math.floor(c/256)/255,d=Math.floor(c%256)/255;_=Math.max(_,c/5),l.uniform4f(this.colorUniformLocation,f,d,f,d),l.bufferData(l.ARRAY_BUFFER,r,l.DYNAMIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.bufferData(l.ARRAY_BUFFER,r,l.DYNAMIC_DRAW),l.vertexAttribPointer(this.dsmAttributeLocation,2,l.FLOAT,!1,0,0),l.bufferData(l.ELEMENT_ARRAY_BUFFER,i,l.DYNAMIC_DRAW),l.drawElements(l.TRIANGLES,i.length,i.length>256?l.UNSIGNED_SHORT:l.UNSIGNED_BYTE,0)})),l.deleteTexture(x),0!==h.data.length){l.activeTexture(l.TEXTURE1);const t=l.createTexture();l.bindTexture(l.TEXTURE_2D,t),l.pixelStorei(l.UNPACK_ALIGNMENT,2),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.LUMINANCE_ALPHA,h.width,h.height,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,h.data),l.pixelStorei(l.UNPACK_ALIGNMENT,4);const e=[u[0],u[3],u[2],u[3],u[0],u[1],u[2],u[1]],r=new Float32Array(e);l.enableVertexAttribArray(this.positionAttributeLocation),l.bufferData(l.ARRAY_BUFFER,r,l.STATIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.enableVertexAttribArray(this.dsmAttributeLocation),l.bindBuffer(l.ARRAY_BUFFER,this.dsmBuffer),l.bufferData(l.ARRAY_BUFFER,new Float32Array([0,1,1,1,0,0,1,0]),l.STATIC_DRAW),l.vertexAttribPointer(this.dsmAttributeLocation,2,l.FLOAT,!1,0,0),l.uniform4f(this.colorUniformLocation,0,0,0,0),l.uniform1i(this.useDSMUniformLocation,1),l.colorMask(!1,!1,!0,!0),l.drawArrays(l.TRIANGLE_STRIP,0,4),l.deleteTexture(t)}return l.colorMask(!0,!0,!0,!0),l.deleteFramebuffer(E),{maxHeight:_,heightMapTex:this.targetTexture}}}const st=t=>{const{tile:e,maxZoom:r,tileSize:i}=t;let{x:o,y:n,z:a}=e;if(a>r){const t=Math.pow(2,e.z-r);o=Math.floor(o/t),n=Math.floor(n/t),a=r}return{x:i===d?o:Math.floor(o/2),y:i===d?n:Math.floor(n/2),z:i===d?a:a-1}};class ut{constructor(t){this.gl=t,this.program=nt({vSrc:"\n attribute vec4 a_position;\n varying vec2 v_pos;\n void main() {\n v_pos = ((a_position + 1.0) * 0.5).xy;\n gl_Position = a_position;\n }\n",fSrc:"\n precision mediump float;\n varying vec2 v_pos;\n uniform sampler2D u_texture;\n void main() {\n gl_FragColor = texture2D(u_texture, v_pos);\n }\n",gl:t}),t.useProgram(this.program),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.positionBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(this.positionAttributeLocation),t.vertexAttribPointer(this.positionAttributeLocation,2,t.FLOAT,!1,0,0),this.tileTexture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.tileTexture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),this.outputTexture=t.createTexture(),this.framebuffer=t.createFramebuffer(),this.inProgress=[],this.finished=0}merge(t,e){return T(this,void 0,void 0,(function*(){const r=this.gl,{width:i,height:o,crossOrigin:n,getSourceUrl:a,getElevation:s,tileSize:u,tileLoaded:h,maxZoom:l}=e;if(r){const e=new Uint8ClampedArray(2*i*o);e.maxHeight=0,this.inProgress.forEach((t=>t.src="")),this.inProgress=[],this.finished=0;const c=new Set;t.forEach((t=>{c.add(a(st({tile:t,maxZoom:l,tileSize:u})))}));const f=Array.from(c).map((o=>T(this,void 0,void 0,(function*(){return new Promise(((h,c)=>{const f=new Image;this.inProgress.push(f),f.onload=()=>{t.filter((t=>o===a(st({tile:t,maxZoom:l,tileSize:u})))).forEach((t=>{let o=0,n=0;const a=514===u?1:0;let h=0,c=d,m=d;if(u!==d&&(o=t.x%2*d,n=t.y%2*d,c=d,m=d),t.z>l){const e=Math.pow(2,t.z-l);u!==d&&(o=Math.floor(t.x/e)%2*d,n=Math.floor(t.y/e)%2*d),o+=d*(t.x%e/e),n+=d*(t.y%e/e),c=d/e,m=d/e,h=514===u?1:0}r.useProgram(this.program),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.tileTexture),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,f),r.activeTexture(r.TEXTURE1),ot({gl:r,texture:this.outputTexture,imageData:null,format:r.RGBA,width:u,height:u,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST}),r.bindFramebuffer(r.FRAMEBUFFER,this.framebuffer),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,this.outputTexture,0);const _=r.checkFramebufferStatus(r.FRAMEBUFFER);_!==r.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+_),r.bindBuffer(r.ARRAY_BUFFER,this.positionBuffer),r.enableVertexAttribArray(this.positionAttributeLocation),r.vertexAttribPointer(this.positionAttributeLocation,2,r.FLOAT,!1,0,0),r.viewport(0,0,u,u),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4);const x=new Uint8Array(4*(c+h)*(m+h));r.readPixels(a+o,a+n,c+h,m+h,r.RGBA,r.UNSIGNED_BYTE,x),r.bindFramebuffer(r.FRAMEBUFFER,null);const g=new Uint8ClampedArray(131072);let p=new Array((c+h)*(m+h)),E=d/c;for(let t=0;t<x.length;t+=4){const r=s({r:x[t],g:x[t+1],b:x[t+2],a:x[t+3]});e.maxHeight=Math.max(r,e.maxHeight);const i=5*(r||0);p[t/4]=i}if(E>1&&514===u)for(p=function(t,e,r,i){const o=Math.floor(e*i),n=Math.floor(r*i),a=[];for(let s=0;s<n;s++)for(let n=0;n<o;n++){const o=n/i,u=s/i,h=Math.floor(o),l=Math.floor(u),c=Math.min(h+1,e-1),f=Math.min(l+1,r-1),d=o-h,m=u-l,_=l*e+c,x=f*e+h,g=f*e+c,p=t[l*e+h]*(1-d)*(1-m)+t[_]*d*(1-m)+t[x]*(1-d)*m+t[g]*d*m;a.push(p)}return function(t,e,r,i,o){if(i>=e||o>=r)return[];const n=e-i,a=r-o,s=[];for(let r=0;r<a;r++)for(let i=0;i<n;i++){const o=r*e+i;s.push(t[o])}return s}(a,Math.sqrt(a.length),Math.sqrt(a.length),i,i)}(p,c+1,m+1,E);E>1;)E/=2,m*=2,c*=2;for(let t=0;t<g.length;t+=2){const e=p[Math.floor(t/2/d/E)*c+Math.floor(t/2%d/E)],r=Math.floor(e/256),i=Math.floor(e%256);g[t]=r,g[t+1]=i}for(let r=0;r<d;r++)e.set(g.slice(r*d*2,(r+1)*d*2),2*(t.yOffset*i+r*i+t.xOffset))})),h(null)},f.onerror=t=>{if(f.src!==f.originalSource)return c("new tiles requested");h(null)},f.crossOrigin=n||null,f.src=o,f.originalSource=f.src})).then((()=>{this.finished++,h(this.finished,this.inProgress.length)}))}))));try{yield Promise.all(f)}catch(t){return console.log(`${f.length} requests aborted`,t),null}return this.inProgress=[],e}throw new Error("Could not get canvas context for merging tile images")}))}}return class extends class extends class{constructor(){this.events={}}on(t,e){return"object"!=typeof this.events[t]&&(this.events[t]=[]),this.events[t].push(e),()=>this.removeListener(t,e)}removeListener(t,e){if("object"!=typeof this.events[t])return;const r=this.events[t].indexOf(e);r>-1&&this.events[t].splice(r,1)}removeAllListeners(){Object.keys(this.events).forEach((t=>this.events[t].splice(0,this.events[t].length)))}emit(t,...e){"object"==typeof this.events[t]&&[...this.events[t]].forEach((t=>t.apply(this,e)))}once(t,e){const r=this.on(t,((...t)=>{r(),e.apply(this,t)}));return r}}{constructor(...t){super(),this.options={date:new Date,color:"000",opacity:.3,sunExposure:{enabled:!1,startDate:new Date,endDate:new Date,iterations:32},apiKey:"",terrainSource:{maxZoom:15,tileSize:256,_overzoom:15,getSourceUrl:t=>"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/7/17/45.png",getElevation:t=>{const{r:e,g:r,b:i}=t;return 256*e+r+i/256-32768}},dsmSource:{bounds:[{lat:0,lng:0},{lat:0,lng:0}],data:new Uint8ClampedArray,width:0,height:0,maxHeight:0},belowCanopy:!1,getFeatures:()=>Promise.resolve([]),getSize:()=>({width:Number.NaN,height:Number.NaN}),debug:t=>{}};const e=t[0];if(this.options=Object.assign(this.options,e),!this.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:this.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((t=>T(this,void 0,void 0,(function*(){if(200!==t.status)throw new Error(yield t.text())})))).catch((t=>T(this,void 0,void 0,(function*(){throw new Error(`Could not load ShadeMap API. Key: ${this.options.apiKey} Error: ${t}`)})))),this._canvas=document.createElement("canvas"),this._color=this._parseColor(this.options.color),this._reset=this._reset.bind(this),this._draw=this._draw.bind(this)}onRemove(){return this._map&&this._map.off("moveend",this._reset),this}setDate(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(tt(this._compiledKernel,{date:this.options.date}),this._flush())):this.emit("idle"),this}_setDateForTimezone(t,e){let r=0;e&&(r=p(this.options.date)-p(this.options.date,e)),this.setDate(new Date(t.getTime()-r))}setColor(t){return this.options.color!==t&&(this.options.color=t,this._color=this._parseColor(this.options.color),this._compiledKernel&&(rt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setOpacity(t){return this.options.opacity!==t&&(this.options.opacity=t,this._compiledKernel&&(rt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setBelowCanopy(t){return this.options.belowCanopy=t,this._heightMap?this._draw(this._heightMap):this._reset(),this}setTerrainSource(t){return this.options.terrainSource=t,delete this._heightMap,this._reset(),this}setDSMSource(t){return this.options.dsmSource=t,delete this._heightMap,this._reset(),this}setSunExposure(t=!1,e){return T(this,void 0,void 0,(function*(){if(this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:t}),e){const{startDate:r=new Date,endDate:i=new Date,iterations:o=32}=e;this.options.sunExposure={enabled:t,startDate:r,endDate:i,iterations:o}}if(this._map&&this._compiledKernel&&this._heightMap){if(!1===t)tt(this._compiledKernel,{date:this.options.date});else{const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!(t instanceof Date&&e instanceof Date))throw new Error("Start date or end date or both are missing");if(e.getTime()<t.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield et(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._flush()}return this}))}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:i,height:o}=this._heightMap,n=e.min;return t.map((t=>{const e=k(t,r);return[(e.x-n.x)/i,(e.y-n.y)/o]}))}return[]}_getBounds(t,e){const{width:r,height:o}=this.options.getSize();if(Number.isNaN(r)||Number.isNaN(o))return t.getBounds();const n=t.getCenter(),a=k(n,e),s=q(new i(a.x-r/2,a.y-o/2),e),u=q(new i(a.x+r/2,a.y+o/2),e);return t.createBounds({nw:s,se:u})}_getDEMZoom(t){const e=Math.min(this.options.terrainSource._overzoom||this.options.terrainSource.maxZoom,t.getZoom());return Math.round(e)}_reset(){return T(this,void 0,void 0,(function*(){if(this.options.debug("_reset()"),this._map){const t=E(this._map);let e=this._getDEMZoom(t);try{this._bounds=this._getBounds(t,e)}catch(t){return console.error("Invalid bounds returned: ",t),this}try{if(!t.isLeaflet()&&this._map.getPitch()>45){yield new Promise((t=>{this._map.loaded()?t(!0):this._map.once("idle",(function(){t(!0)}))}));const r=this._map.style._sourceCaches["other:composite"].getVisibleCoordinates().reverse(),o=r.reduce(((t,e)=>Math.max(t,e.canonical.z)),Number.MIN_SAFE_INTEGER),n=r.filter((t=>t.canonical.z===o)).map((t=>t.canonical)),[a,s,u,h]=n.reduce(((t,e)=>[Math.min(t[0],e.x),Math.min(t[1],e.y),Math.max(t[2],e.x),Math.max(t[3],e.y)]),[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER]),l=q(new i(512*a,512*s),o+1),c=q(new i(512*(u+1),512*(h+1)),o+1);e=o+1,this._bounds=t.createBounds({nw:l,se:c})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield J({gl:this._gl,demZoom:e,bounds:this._bounds,terrainSource:this.options.terrainSource,dsmSource:this.options.dsmSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,tileLoaded:(t,e)=>this.emit("tileloaded",t,e),forceUpdate:!this._heightMap});this._heightMap=r,r.dirty&&(yield this._draw(r))}return this}))}_draw(t){return T(this,void 0,void 0,(function*(){if(this.options.debug("_draw()"),this._canvas&&this._compiledKernel&&this._map){if(it({kernel:this._compiledKernel,map:E(this._map),heightMap:t,color:this._color,belowCanopy:this.options.belowCanopy,opacity:this.options.opacity,now:this.options.date,maxZoom:this.options.terrainSource.maxZoom}),this.options.sunExposure.enabled){const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!0===(yield et(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._bounds&&this._repositionCanvas(this._bounds)}return this}))}readPixel(t,e){const r=new Uint8Array(4);return this._gl&&this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r),r}readPixels(t,e,r,i){const o=new Uint8Array(r*i*4);return this._gl&&this._gl.readPixels(t,e,r,i,this._gl.RGBA,this._gl.UNSIGNED_BYTE,o),o}toGeoTiff(){const t=(t,e)=>{const r=this.readPixels(0,0,t,e),i=t*e*1,o=1*t,n=(e-1)*o,a=new Uint8Array(i),s=new Uint8Array(i);let u=0;const{startDate:h,endDate:l}=this.options.sunExposure;this.options.sunExposure.enabled&&h&&l&&(u=l.getTime()-h.getTime());for(let t=0;t<r.length;t+=4){let e;if(this.options.sunExposure.enabled){const i=r.subarray(t,t+3),o=g(i,.5,u)/1e3/60,n=Math.min(Math.floor(o/6),255);e=new Uint8Array([n])}else{e=r[t]+r[t+1]+r[t+2]===0?new Uint8Array([255]):new Uint8Array([0])}a.set(e,t/4*1)}if(this._map&&!E(this._map).isLeaflet())return a;for(let t=0;t<i;t+=o)s.set(a.subarray(t,t+o),n-t);return s};if(this._map&&this._heightMap){const e=this._heightMap.outputWidth,r=this._heightMap.outputHeight,i=t(e,r),o=E(this._map),{lat:n,lng:a}=o.getBounds().getNorthWest(),s=o.getBounds().getSouthEast(),u=[0,0,0,a,n,0],h=[(s.lng-a)/e,(n-s.lat)/r,0];return this.options.sunExposure.enabled,{data:i,metadata:{width:e,height:r,ModelTiepoint:u,ModelPixelScale:h,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}return null}_generateShadeProfile(t){if(this._compiledKernel){const e=this._lngLatToTextureCoords(t.locations);return((t,e)=>{const r=Q({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=Q({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{texCoords:e}))}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=p(t.startDate)-p(t.startDate,t.tzId),r=t.startDate.getTime()-e,i=(t.endDate.getTime()-e-r)/86400/1e3,o=1440,n=[],a=828e5,s=p(new Date(r),t.tzId);for(let e=0;e<i;e++){const i=p(new Date(r+86400*e*1e3+a),t.tzId)-s;n[e]=i}const u=[];for(let t=0;t<o;t++){const e=[];for(let o=0;o<i;o++){const i=r+86400*o*1e3+60*t*1e3;e.push(new Date(i+n[o]))}u.push(e)}const h=this._lngLatToTextureCoords([t.location])[0],l=((t,e)=>{const r=Q({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=Q({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateLocationShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{dates:u,texCoord:h}));return l.toArray=function(){const e=new Array;for(let r=0;r<i;r++){const n=[];for(let e=o-1;e>=0;e--){const o=e*i*4+4*r,a=this.slice(o,o+4);n.push(a.join("")===t.sunColor.join("")?1:0)}e.push(n)}return e},{data:l,width:i,height:o}}return{data:new Uint8Array,width:0,height:0}}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this.readPixel(t,e),{startDate:i,endDate:o}=this.options.sunExposure,n=o.getTime()-i.getTime(),a=g(r,.5,n);return Math.abs(a/1e3/3600)}return 0}_repositionCanvas(t){}_flush(){}flushSync(){this._gl&&this._gl.finish()}_parseColor(t){t=t.replace("#","");const e={r:0,g:0,b:0};return/^([0-9A-F]{3}){1,2}$/i.test(t)&&(3===t.length?(e.r=parseInt(t[0]+t[0],16),e.g=parseInt(t[1]+t[1],16),e.b=parseInt(t[2]+t[2],16)):6===t.length&&(e.r=parseInt(t[0]+t[1],16),e.g=parseInt(t[2]+t[3],16),e.b=parseInt(t[4]+t[5],16))),e}}{constructor(t){super(t),this.id="shademap-layer",this.type="custom",this.canvasSourceId="canvas-source",this.attributionSourceId="attribution-source",this.canvasLayerId="canvas-layer",this.attributionLayerId="attribution-layer",this._refreshing=0,this._raf=0,this.id=this.id+x(),this.canvasSourceId=this.canvasSourceId+x(),this.attributionSourceId=this.attributionSourceId+x(),this.canvasLayerId=this.canvasLayerId+x(),this.attributionLayerId=this.attributionLayerId+x(),this.options.terrainSource.tileSize>256&&(this.options.terrainSource.maxZoom=this.options.terrainSource.maxZoom+1),this._moveEndHandler=()=>{this._map&&this._reset()}}render(t,e){}addTo(t){return t.addLayer(this),this}onAdd(t){this._map=t,this._gl=this._map.painter.context.gl,this._framebuffer=this._gl.createFramebuffer();this._compiledKernel=function(t){const{context:e,setRenderBuffer:r}=t,i=e,o=nt({gl:i,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 a_pos;attribute vec2 a_tex_pos;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;void main(void){gl_Position=vec4(a_pos,0,1);vTexCoordFull=(gl_Position*0.5+0.5).xy;vTexCoordCropped=a_tex_pos;}",fSrc:"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nprecision lowp int;precision lowp sampler2D;float atan2(float v1,float v2){if(v1==0.0||v2==0.0)return 0.0;return atan(v1,v2);}float _pow(float v1,float v2){if(v2==0.0)return 1.0;return pow(v1,v2);}float integerMod(float x,float y){float res=floor(mod(x,y));return res*(res>floor(y)-1.0 ? 0.0 : 1.0);}float divWithIntCheck(float x,float y){if(floor(x)==x&&floor(y)==y&&integerMod(x,y)==0.0){return float(int(x)/int(y));}return x/y;}float integerCorrectionModulo(float number,float divisor){if(number<0.0){number=abs(number);if(divisor<0.0){divisor=abs(divisor);}return-(number-(divisor*floor(divWithIntCheck(number,divisor))));}if(divisor<0.0){divisor=abs(divisor);}return number-(divisor*floor(divWithIntCheck(number,divisor)));}float getDEMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*255.0*256.0+result.g*255.0)/5000.0;}float getDSMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.b*255.0*256.0+result.a*255.0)/5000.0;}vec4 actualColor;void color(float r,float g,float b,float a){actualColor=vec4(r,g,b,a);}void color(float r,float g,float b){color(r,g,b,1.0);}void color(float r){color(r,r,r,1.0);}void color(vec4 color){actualColor=color;}const int LOOP_MAX=1000;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;uniform sampler2D user_a;uniform float user_width;uniform float user_height;uniform float user_maxHeight;uniform float user_zoom;uniform float user_topYCoord;uniform float user_ySize;uniform vec4 user_color;uniform vec4 u_sunColor;uniform float user_step;uniform float user_west;uniform float user_dLng;uniform float user_dec;uniform float user_Hi;uniform bool u_below_canopy;uniform sampler2D user_sunExposureTexture;uniform bool user_renderToSunExposureTexture;uniform bool user_outputSunExposure;uniform vec4 user_exposureDelta;uniform bool u_outputShadeProfile;uniform sampler2D u_decHiTexture;uniform sampler2D u_gpxTexture;uniform bool u_outputLocationShadeProfile;uniform vec2 u_shadeProfileLocation;float kernelResult;void kernel(){float sunDec=user_dec;float sunHi=user_Hi;vec4 shade_color=user_color;float maxHeight=user_maxHeight/1000.0;float user_x=vTexCoordCropped.x;float user_y=vTexCoordCropped.y;if(u_outputShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;vec4 gpx=texture2D(u_gpxTexture,vec2(vTexCoordFull.x,.5));user_x=gpx.x;user_y=gpx.y;}if(u_outputLocationShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;user_x=u_shadeProfileLocation.x;user_y=u_shadeProfileLocation.y;}float user_lit=1.0;float dsm_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(u_below_canopy==true){float dem_height=getDEMElevationFromSampler2D(user_a,user_x,user_y);if(dsm_height-dem_height>.002){user_lit=0.0;}}float user_z=dsm_height;float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=user_west+(user_dLng*user_x);float user_H=integerCorrectionModulo((sunHi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(sunDec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(sunDec))+((cos(user_lat)*cos(sunDec))*cos(user_H))));float user_zoom_factor=_pow(2.0,user_zoom);float user_kmPerPixel=divWithIntCheck(156.5430339296875,user_zoom_factor)*abs(cos(user_lat));float user_dx=((-sin(sun_azimuth)*cos(sun_altitude))*user_step)/user_width;float user_dy=((cos(sun_azimuth)*cos(sun_altitude))*user_step)/user_height;float user_dz=((sin(sun_altitude)*user_kmPerPixel)*user_step);float shadow_bias=0.0005;float user_curvature=0.0;float cur_height=0.0;float user_distance=0.0;float user_startX=user_x;float user_startY=user_y;user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;if((abs(1.0)<0.0)){kernelResult=0.0;return;}float minAngle=asin((earthRadiusInKm/(earthRadiusInKm+user_z)))-(user_PI/2.0);if(user_z<0.0||sun_altitude<minAngle){user_lit=0.0;}else{float xIter=ceil(user_dx<0.0 ? abs(user_x/user_dx):(1.0-user_x)/user_dx);float yIter=ceil(user_dy<0.0 ? abs(user_y/user_dy):(1.0-user_y)/user_dy);float zIter=ceil(user_dz<0.0 ? float(LOOP_MAX):(maxHeight-user_z)/user_dz);int iter=int(min(xIter,min(yIter,zIter)));float user_distance=(sqrt(pow(user_dx*user_width,2.0)+pow(user_dy*user_height,2.0))*user_kmPerPixel)/earthRadiusInKm;for(int safeI=0;safeI<LOOP_MAX;safeI++){if(safeI>iter){break;}cur_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(cur_height-user_z>shadow_bias){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;vec4 result=texture2D(user_a,vec2(user_x,user_y));iter=0;break;}}user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;}}if((user_lit==1.0)){if(u_outputLocationShadeProfile==true&&u_sunColor==shade_color){float timeInSun=pow(.7,pow(sin(sun_altitude),.678))*sin(sun_altitude)*(1.0/0.7);float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,1.0);}else{color(u_sunColor);}}else{color(shade_color);}if(user_renderToSunExposureTexture){vec4 aggregateColor=texture2D(user_sunExposureTexture,vec2(vTexCoordFull.x,vTexCoordFull.y));if((user_lit==1.0)){color(aggregateColor.r,0.0,0.0,1.0);}else{color(aggregateColor.r+user_exposureDelta.r,0.0,0.0,1.0);}if(user_outputSunExposure){float timeInSun=1.0-aggregateColor.r;float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,0.5);}}}void main(void){kernel();gl_FragColor=actualColor;}"});i.useProgram(o);const n=i.createBuffer(),a=i.getAttribLocation(o,"a_pos"),s=i.createBuffer(),u=i.getAttribLocation(o,"a_tex_pos"),h=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,h),i.bufferData(i.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),i.STATIC_DRAW);const l=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,l),i.bufferData(i.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),i.STATIC_DRAW);const c=i.getUniformLocation(o,"user_a");i.uniform1i(c,0);const f=i.getUniformLocation(o,"user_width"),d=i.getUniformLocation(o,"user_height"),m=i.getUniformLocation(o,"user_maxHeight"),x=i.getUniformLocation(o,"user_zoom"),g=i.getUniformLocation(o,"user_topYCoord"),p=i.getUniformLocation(o,"user_ySize"),E=i.getUniformLocation(o,"user_step"),y=i.getUniformLocation(o,"user_west"),v=i.getUniformLocation(o,"user_dLng"),R=i.getUniformLocation(o,"user_dec"),A=i.getUniformLocation(o,"user_Hi"),b=i.getUniformLocation(o,"user_color"),M=i.getUniformLocation(o,"user_xStart"),w=i.getUniformLocation(o,"user_yStart"),U=i.getUniformLocation(o,"user_xEnd"),F=i.getUniformLocation(o,"user_yEnd"),D=i.getUniformLocation(o,"u_below_canopy"),L=i.getUniformLocation(o,"user_sunExposureTexture"),S=i.getUniformLocation(o,"user_renderToSunExposureTexture"),P=i.getUniformLocation(o,"user_outputSunExposure"),C=i.getUniformLocation(o,"user_exposureDelta"),I=i.getUniformLocation(o,"u_outputShadeProfile"),B=i.getUniformLocation(o,"u_gpxTexture"),N=i.getUniformLocation(o,"u_decHiTexture"),O=i.getUniformLocation(o,"u_sunColor"),X=i.getUniformLocation(o,"u_outputLocationShadeProfile"),G=i.getUniformLocation(o,"u_shadeProfileLocation");let z=0,H=0,W=0,j=null;const Z=()=>{H&&W&&(i.useProgram(o),i.bindBuffer(i.ARRAY_BUFFER,n),i.enableVertexAttribArray(a),i.vertexAttribPointer(a,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,s),i.enableVertexAttribArray(u),i.vertexAttribPointer(u,2,i.FLOAT,!1,0,0),null!==j&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,j)),r(i,H,W),i.viewport(0,0,H,W),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4))};let Y=0;return{updateLocation:function(t){const{heightMapTex:e,width:r,height:a,maxHeight:u,heightMapZoom:h,topYCoord:l,ySize:c,colorVec:_,step:T,west:M,dLng:w,dec:U,Hi:F,cornerClipCoords:L,cornerTextureCoords:S,outputWidth:P,outputHeight:C,belowCanopy:I}=t;i.useProgram(o),H=P,W=C,j=e,i.bindBuffer(i.ARRAY_BUFFER,n),i.bufferData(i.ARRAY_BUFFER,new Float32Array(L),i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,s),i.bufferData(i.ARRAY_BUFFER,new Float32Array(S),i.STATIC_DRAW),i.uniform1f(f,r),i.uniform1f(d,a),i.uniform1f(m,u),i.uniform1f(x,h),i.uniform1f(g,l),i.uniform1f(p,c),i.uniform4fv(b,_),i.uniform1f(E,T),i.uniform1f(y,M),i.uniform1f(v,w),i.uniform1f(R,U),i.uniform1f(A,F),i.uniform1f(D,I?1:0),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(Z)},updateViewport:function(t){const{xStart:e,yStart:r,xEnd:n,yEnd:a}=t;i.useProgram(o),i.uniform1f(M,e),i.uniform1f(w,r),i.uniform1f(U,n),i.uniform1f(F,a),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(Z)},updateDate:t=>{const{dec:e,Hi:r}=t;i.useProgram(o),i.uniform1f(R,e),i.uniform1f(A,r),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(Z)},updateDateRange:t=>T(this,void 0,void 0,(function*(){const{startDate:e,endDate:r,iterations:h,emit:l}=t;i.useProgram(o);const c=Y=Date.now();i.uniform4fv(C,new Float32Array([1/h,0,0,0]));const f=Math.floor((r.getTime()-e.getTime())/h),d=H,m=W,x=i.createTexture();i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D,x),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,d,m,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);const g=i.createTexture();i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,g),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,d,m,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);const p=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,p);const E=i.COLOR_ATTACHMENT0;for(let t=0;t<h;t++){if(i.useProgram(o),l("tileloaded",t,h-1),c!==Y)return i.deleteFramebuffer(p),i.deleteTexture(x),i.deleteTexture(g),!0;yield new Promise(((r,h)=>{window.requestAnimationFrame((()=>{i.useProgram(o),i.uniform1i(L,1),i.uniform1i(S,1),null!==j&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,j));const h=t%2==0?g:x,l=t%2==0?x:g;i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D,h),i.bindFramebuffer(i.FRAMEBUFFER,p),i.framebufferTexture2D(i.FRAMEBUFFER,E,i.TEXTURE_2D,l,0);const c=i.checkFramebufferStatus(i.FRAMEBUFFER);c!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+c);const{dec:T,Hi:y}=_(new Date(e.getTime()+f*t));i.uniform1f(R,T),i.uniform1f(A,y),i.bindBuffer(i.ARRAY_BUFFER,n),i.enableVertexAttribArray(a),i.vertexAttribPointer(a,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,s),i.enableVertexAttribArray(u),i.vertexAttribPointer(u,2,i.FLOAT,!1,0,0),i.viewport(0,0,d,m),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4),r()}))}))}return i.deleteFramebuffer(p),yield new Promise(((t,e)=>{window.requestAnimationFrame((()=>{if(i.useProgram(o),c!==Y)return i.deleteTexture(x),i.deleteTexture(g),void t(!0);i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,(h-1)%2==0?x:g),i.uniform1i(L,2),i.uniform1i(P,1),i.uniform1i(S,1),Z(),i.uniform1i(S,0),i.uniform1i(P,0),i.uniform1i(L,0),i.deleteTexture(x),i.deleteTexture(g),t(!1)}))}))})),updateColor:t=>{const{colorVec:e}=t;i.useProgram(o),i.uniform4fv(b,e),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(Z)},generateShadeProfile:t=>{i.useProgram(o);const{dates:e,texCoords:r,shadeColor:n,sunColor:s}=t,c=r.length,f=e.length,d=i.getUniform(o,b);i.uniform4fv(b,n),i.uniform4fv(O,s),i.uniform1i(I,1);const m=i.createTexture();i.activeTexture(i.TEXTURE3),ot({gl:i,imageData:null,width:c,height:f,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,texture:m});const x=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,x),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,m,0);const g=i.checkFramebufferStatus(i.FRAMEBUFFER);g!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+g);const p=r.map((t=>[t[0],t[1],0,0])).flat(),E=i.createTexture();i.activeTexture(i.TEXTURE2),ot({gl:i,texture:E,imageData:new Float32Array(p),width:p.length/4,height:1,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,type:i.FLOAT}),i.uniform1i(B,2);const T=e.map((t=>{const{dec:e,Hi:r}=_(t);return[-e,r/10,0,0]})).flat(),y=i.createTexture();i.activeTexture(i.TEXTURE1),ot({gl:i,texture:y,imageData:new Float32Array(T),width:1,height:e.length,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,type:i.FLOAT}),i.uniform1i(N,1),null!==j&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,j)),i.bindBuffer(i.ARRAY_BUFFER,h),i.enableVertexAttribArray(a),i.vertexAttribPointer(a,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,l),i.enableVertexAttribArray(u),i.vertexAttribPointer(u,2,i.FLOAT,!1,0,0),i.viewport(0,0,c,f),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4);const v=new Uint8Array(c*f*4);return i.readPixels(0,0,c,f,i.RGBA,i.UNSIGNED_BYTE,v),i.deleteTexture(m),i.deleteTexture(y),i.deleteTexture(E),i.deleteFramebuffer(x),i.uniform1i(N,0),i.uniform1i(B,0),i.uniform1i(I,0),i.uniform4fv(b,d),i.uniform4fv(O,[0,0,0,0]),v},generateLocationShadeProfile:t=>{i.useProgram(o);const{dates:e,texCoord:r,shadeColor:n,sunColor:s}=t,c=e[0].length,f=e.length,d=i.getUniform(o,b);i.uniform4fv(b,n),i.uniform4fv(O,s),i.uniform1i(X,1),i.uniform2fv(G,[r[0],r[1]]);const m=i.createTexture();i.activeTexture(i.TEXTURE2),ot({gl:i,imageData:null,width:c,height:f,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,texture:m});const x=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,x),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,m,0);const g=i.checkFramebufferStatus(i.FRAMEBUFFER);g!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+g);const p=e.flat().map((t=>{const{dec:e,Hi:r}=_(t);return[-e,r/10,0,0]})).flat(),E=i.createTexture();i.activeTexture(i.TEXTURE1),ot({gl:i,texture:E,imageData:new Float32Array(p),width:c,height:f,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,internalFormat:i.RGBA32F,type:i.FLOAT}),i.uniform1i(N,1),null!==j&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,j)),i.uniform1i(S,0),i.bindBuffer(i.ARRAY_BUFFER,h),i.enableVertexAttribArray(a),i.vertexAttribPointer(a,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,l),i.enableVertexAttribArray(u),i.vertexAttribPointer(u,2,i.FLOAT,!1,0,0),i.viewport(0,0,c,f),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4);const T=new Uint8Array(c*f*4);return i.readPixels(0,0,c,f,i.RGBA,i.UNSIGNED_BYTE,T),i.deleteTexture(m),i.deleteTexture(E),i.deleteFramebuffer(x),i.uniform1i(N,0),i.uniform1i(X,0),i.uniform4fv(b,d),i.uniform4fv(O,[0,0,0,0]),T}}}({context:this._gl,setRenderBuffer:(e,r,i)=>{const o=t.getSource(this.canvasSourceId).texture;e.activeTexture(e.TEXTURE1),o.bind(e.LINEAR,e.CLAMP_TO_EDGE),o.size=[r,i],e.texImage2D(e.TEXTURE_2D,0,e.RGBA,r,i,0,e.RGBA,e.UNSIGNED_BYTE,null),e.bindFramebuffer(e.FRAMEBUFFER,this._framebuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o.texture,0),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA)}}),this._tileMerger=new ut(this._gl),this._buildingRasterizer=new at(this._gl),document.body.appendChild(this._canvas),this._canvas.style.display="none";const e=t.getBounds(),r=e.getNorthWest(),i=e.getNorthEast(),o=e.getSouthEast(),n=e.getSouthWest(),a=[[r.lng,r.lat],[i.lng,i.lat],[o.lng,o.lat],[n.lng,n.lat]];return t.addSource(this.canvasSourceId,{type:"canvas",canvas:this._canvas,coordinates:a,animate:!1}),t.addLayer({id:this.canvasLayerId,type:"raster",source:this.canvasSourceId,paint:{"raster-fade-duration":0}}),t.addSource(this.attributionSourceId,{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[-122.210598,47.769799]}},attribution:'<a href="https://shademap.app/about">© ShadeMap</a>'}),t.addLayer({id:this.attributionLayerId,type:"fill",source:this.attributionSourceId}),this._map.on("moveend",this._moveEndHandler),this._moveEndHandler(),this}onRemove(){return this._map&&(this._map.off("moveend",this._moveEndHandler),this._map.removeLayer(this.attributionLayerId),this._map.removeLayer(this.canvasLayerId),this._map.removeSource(this.attributionSourceId),this._map.removeSource(this.canvasSourceId)),this._gl&&this._framebuffer&&this._gl.deleteFramebuffer(this._framebuffer),document.body.removeChild(this._canvas),this.options.debug("onRemove called"),this}_getHeightMapCoords(t,e){if(this._map&&this.options.sunExposure.enabled&&this._bounds&&this._heightMap){const r=this._map.unproject([t,e]);if(r.toString()===this._map.unproject([t,e+1]).toString())return new i(-1,-1);const{visibleDEMPixelBounds:o,demZoom:n}=this._heightMap;return E(this._map).project(r,n).subtract(o.min)}return new i(-1,-1)}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this._getHeightMapCoords(t,e),i=this.readPixel(r.x,r.y),{startDate:o,endDate:n}=this.options.sunExposure,a=n.getTime()-o.getTime(),s=g(i,.5,a);return Math.abs(s/1e3/3600)}return 0}remove(){this._map&&this._map.removeLayer(this.id)}readPixel(t,e){const r=new Uint8Array(4);if(this._map&&this._gl&&this._framebuffer){const i=this._gl,o=this._map.getSource(this.canvasSourceId).texture;i.activeTexture(i.TEXTURE1),o.bind(i.LINEAR,i.CLAMP_TO_EDGE),i.bindFramebuffer(i.FRAMEBUFFER,this._framebuffer),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,o.texture,0),this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r)}return r}readPixels(t,e,r,i){console.log("Reading pix",t,e,r,i);const o=new Uint8Array(r*i*4);if(this._map&&this._gl&&this._framebuffer){const n=this._gl,a=this._map.getSource(this.canvasSourceId).texture;n.activeTexture(n.TEXTURE1),a.bind(n.LINEAR,n.CLAMP_TO_EDGE),n.bindFramebuffer(n.FRAMEBUFFER,this._framebuffer),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,a.texture,0),this._gl.readPixels(t,e,r,i,this._gl.RGBA,this._gl.UNSIGNED_BYTE,o)}return o}_flush(){if(this._map){this._map.getSource(this.canvasSourceId).fire({type:"data",dataType:"source",sourceDataType:"content"})}this.emit("idle")}_repositionCanvas(t){if(this._map){const e=this._map.getSource(this.canvasSourceId);if(e){const r=t.getNorthWest(),i=t.getNorthEast(),o=t.getSouthEast(),n=t.getSouthWest(),a=[[r.lng,r.lat],[i.lng,i.lat],[o.lng,o.lat],[n.lng,n.lat]];e.setCoordinates(a),this.emit("idle")}}return this}}}));
|
|
@@ -11,13 +11,13 @@ import { Color } from "./types/color";
|
|
|
11
11
|
import { DSMSource, SunExposureOptions, TerrainSource } from "./types/shadeMapOptions";
|
|
12
12
|
export declare class ShadeMap extends EventEmitter {
|
|
13
13
|
_canvas: HTMLCanvasElement;
|
|
14
|
-
_gl
|
|
14
|
+
_gl?: WebGLRenderingContext;
|
|
15
15
|
_map?: Map | LeafletMap;
|
|
16
16
|
_compiledKernel?: CompiledKernel;
|
|
17
17
|
_color: Color;
|
|
18
18
|
_bounds?: LatLngBounds;
|
|
19
|
-
_buildingRasterizer
|
|
20
|
-
_tileMerger
|
|
19
|
+
_buildingRasterizer?: BuildingRasterizer;
|
|
20
|
+
_tileMerger?: TileMerger;
|
|
21
21
|
_heightMap?: HeightMap;
|
|
22
22
|
options: {
|
|
23
23
|
date: Date;
|
|
@@ -80,6 +80,7 @@ export declare class ShadeMap extends EventEmitter {
|
|
|
80
80
|
_reset(): Promise<this>;
|
|
81
81
|
_draw(heightMap: HeightMap): Promise<this>;
|
|
82
82
|
readPixel(x: number, y: number): Uint8Array;
|
|
83
|
+
readPixels(x: number, y: number, width: number, height: number): Uint8Array;
|
|
83
84
|
toGeoTiff(): {
|
|
84
85
|
data: Uint8Array;
|
|
85
86
|
metadata: {
|
|
@@ -13,6 +13,7 @@ export default class extends ShadeMap {
|
|
|
13
13
|
_refreshing: number;
|
|
14
14
|
_raf: number;
|
|
15
15
|
_moveEndHandler: () => void;
|
|
16
|
+
_framebuffer?: WebGLFramebuffer;
|
|
16
17
|
constructor(options: ShadeMapOptions);
|
|
17
18
|
render(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
18
19
|
addTo(map: Map): this;
|
|
@@ -21,6 +22,8 @@ export default class extends ShadeMap {
|
|
|
21
22
|
_getHeightMapCoords(x: number, y: number): any;
|
|
22
23
|
getHoursOfSun(x: number, y: number): number;
|
|
23
24
|
remove(): void;
|
|
25
|
+
readPixel(x: number, y: number): Uint8Array;
|
|
26
|
+
readPixels(x: number, y: number, width: number, height: number): Uint8Array;
|
|
24
27
|
_flush(): void;
|
|
25
28
|
_repositionCanvas(bounds: LatLngBounds): this;
|
|
26
29
|
}
|
|
@@ -32,6 +32,9 @@ export declare class BuildingRasterizer {
|
|
|
32
32
|
indexBuffer: WebGLBuffer;
|
|
33
33
|
targetTexture: WebGLTexture;
|
|
34
34
|
constructor(gl: WebGLRenderingContext);
|
|
35
|
-
raster(args: BuildingRasterGLArgs):
|
|
35
|
+
raster(args: BuildingRasterGLArgs): {
|
|
36
|
+
maxHeight: number;
|
|
37
|
+
heightMapTex: WebGLTexture;
|
|
38
|
+
};
|
|
36
39
|
}
|
|
37
40
|
export {};
|
|
@@ -17,9 +17,9 @@ interface HeightMapParams {
|
|
|
17
17
|
forceUpdate: boolean;
|
|
18
18
|
}
|
|
19
19
|
export interface HeightMap {
|
|
20
|
+
heightMapTex: WebGLTexture | null;
|
|
20
21
|
width: number;
|
|
21
22
|
height: number;
|
|
22
|
-
imageData: Uint8ClampedArray;
|
|
23
23
|
maxHeight: number;
|
|
24
24
|
visibleDEMPixelBounds: ValidBounds;
|
|
25
25
|
DEMPixelBounds: ValidBounds;
|
|
@@ -4,6 +4,7 @@ interface CompileProgramArgs {
|
|
|
4
4
|
fSrc: string;
|
|
5
5
|
}
|
|
6
6
|
interface UpdateLocationArgs {
|
|
7
|
+
heightMapTex: WebGLTexture | null;
|
|
7
8
|
width: number;
|
|
8
9
|
height: number;
|
|
9
10
|
maxHeight: number;
|
|
@@ -63,6 +64,7 @@ export interface CompiledKernel {
|
|
|
63
64
|
export declare function compileProgram(args: CompileProgramArgs): WebGLProgram;
|
|
64
65
|
interface Settings {
|
|
65
66
|
context: WebGLRenderingContext;
|
|
67
|
+
setRenderBuffer: (gl: WebGLRenderingContext, viewportWidth: number, viewportHeight: number) => void;
|
|
66
68
|
}
|
|
67
69
|
declare function kernel(settings: Settings): CompiledKernel;
|
|
68
70
|
export default kernel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mapbox-gl-shadow-simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.0-unity",
|
|
4
4
|
"description": "Display terrain and structure shadows cast by the sun in a custom style layer",
|
|
5
5
|
"main": "dist/mapbox-gl-shadow-simulator.umd.min.js",
|
|
6
6
|
"browser": "dist/mapbox-gl-shadow-simulator.umd.min.js",
|