mapbox-gl-shadow-simulator 0.45.2 → 0.46.1
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/examples/maplibre.html +35 -5
- package/package.json +1 -1
- package/dist/shademap/leaflet-shademap/dist/ShadeMap.d.ts +0 -119
- package/dist/shademap/leaflet-shademap/dist/ShadeMapLeaflet.d.ts +0 -14
- package/dist/shademap/leaflet-shademap/dist/ShadeMapMapbox.d.ts +0 -26
- package/dist/shademap/leaflet-shademap/dist/buildings/BuildingRasterizer.d.ts +0 -37
- package/dist/shademap/leaflet-shademap/dist/buildings/fetch-buildings.d.ts +0 -12
- package/dist/shademap/leaflet-shademap/dist/buildings/normalize-buildings.d.ts +0 -8
- package/dist/shademap/leaflet-shademap/dist/components/CanvasOverlay.d.ts +0 -11
- package/dist/shademap/leaflet-shademap/dist/index.d.ts +0 -7
- package/dist/shademap/leaflet-shademap/dist/lib/EventEmitter.d.ts +0 -10
- package/dist/shademap/leaflet-shademap/dist/lib/TileMerger.d.ts +0 -40
- package/dist/shademap/leaflet-shademap/dist/lib/heightMap.d.ts +0 -33
- package/dist/shademap/leaflet-shademap/dist/lib/helpers.d.ts +0 -27
- package/dist/shademap/leaflet-shademap/dist/lib/image.d.ts +0 -13
- package/dist/shademap/leaflet-shademap/dist/lib/projection.d.ts +0 -3
- package/dist/shademap/leaflet-shademap/dist/lib/shadowMap.d.ts +0 -15
- package/dist/shademap/leaflet-shademap/dist/map/geometryLeaflet.d.ts +0 -11
- package/dist/shademap/leaflet-shademap/dist/map/umap.d.ts +0 -26
- package/dist/shademap/leaflet-shademap/dist/shader/gpu.d.ts +0 -29
- package/dist/shademap/leaflet-shademap/dist/shader/kernel.d.ts +0 -67
- package/dist/shademap/leaflet-shademap/dist/types/color.d.ts +0 -5
- package/dist/shademap/leaflet-shademap/dist/types/constants.d.ts +0 -3
- package/dist/shademap/leaflet-shademap/dist/types/quality.d.ts +0 -5
- package/dist/shademap/leaflet-shademap/dist/types/shadeMapOptions.d.ts +0 -46
- package/dist/shademap/leaflet-shademap/dist/types/shadow3DData.d.ts +0 -19
|
@@ -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.46.1
|
|
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 n=e[1],i=e[0],o=n-i;return t===n&&r?t:((t-i)%o+o)%o+i}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 n(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var i=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function o(t,e,i){return t instanceof n?t:r(t)?new n(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new n(t.x,t.y):new n(t,e,i)}function s(t,e){if(t)for(var r=e?[t,e]:t,n=0,i=r.length;n<i;n++)this.extend(r[n])}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,n=0,i=r.length;n<i;n++)this.extend(r[n])}function h(t,e){return t instanceof u?t:new u(t,e)}n.prototype={clone:function(){return new n(this.x,this.y)},add:function(t){return this.clone()._add(o(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(o(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 n(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new n(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=i(this.x),this.y=i(this.y),this},distanceTo:function(t){var e=(t=o(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=o(t)).x===this.x&&t.y===this.y},contains:function(t){return t=o(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 n||"number"==typeof t[0]||"x"in t)e=r=o(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 o((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return o(this.min.x,this.max.y)},getTopRight:function(){return o(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 n?o(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,n=t.min,i=t.max,o=i.x>=e.x&&n.x<=r.x,s=i.y>=e.y&&n.y<=r.y;return o&&s},overlaps:function(t){t=a(t);var e=this.min,r=this.max,n=t.min,i=t.max,o=i.x>e.x&&n.x<r.x,s=i.y>e.y&&n.y<r.y;return o&&s},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,n=Math.abs(e.x-r.x)*t,i=Math.abs(e.y-r.y)*t;return a(o(e.x-n,e.y-i),o(r.x+n,r.y+i))},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,n=this._southWest,i=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 n||i?(n.lat=Math.min(e.lat,n.lat),n.lng=Math.min(e.lng,n.lng),i.lat=Math.max(r.lat,i.lat),i.lng=Math.max(r.lng,i.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,n=Math.abs(e.lat-r.lat)*t,i=Math.abs(e.lng-r.lng)*t;return new u(new c(e.lat-n,e.lng-i),new c(r.lat+n,r.lng+i))},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,n=this._southWest,i=this._northEast;return t instanceof u?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=n.lat&&r.lat<=i.lat&&e.lng>=n.lng&&r.lng<=i.lng},intersects:function(t){t=h(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),i=t.getNorthEast(),o=i.lat>=e.lat&&n.lat<=r.lat,s=i.lng>=e.lng&&n.lng<=r.lng;return o&&s},overlaps:function(t){t=h(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),i=t.getNorthEast(),o=i.lat>e.lat&&n.lat<r.lat,s=i.lng>e.lng&&n.lng<r.lng;return o&&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,n,i;for(r=1,n=arguments.length;r<n;r++)for(e in i=arguments[r])t[e]=i[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),n=this.scale(e);return this.transformation._transform(r,n)},pointToLatLng:function(t,e){var r=this.scale(e),n=this.transformation.untransform(t,r);return this.projection.unproject(n)},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),n=e.lat-r.lat,i=e.lng-r.lng;if(0===n&&0===i)return t;var o=t.getSouthWest(),s=t.getNorthEast();return new u(new c(o.lat-n,o.lng-i),new c(s.lat-n,s.lng-i))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,n=t.lat*r,i=e.lat*r,o=Math.sin((e.lat-t.lat)*r/2),s=Math.sin((e.lng-t.lng)*r/2),a=o*o+Math.cos(n)*Math.cos(i)*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,n){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,n)}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,n=r+.017453292519943295*(1.9148*Math.sin(r)+.02*Math.sin(2*r)+3e-4*Math.sin(3*r))+1.796593062783907+Math.PI,i=Math.atan2(Math.sin(n)*Math.cos(m),Math.cos(n));return{dec:Math.asin(Math.sin(m)*Math.sin(n)),Hi:(4.889714432387314+6.3003876824396166*e-i)%(2*Math.PI)+2*Math.PI}},x=()=>Math.floor(1e7*Math.random()),g=(t,e,r)=>{const n=1/e,i=Math.min(t[0]*n,255),o=Math.min(t[1]*n,255),s=Math.min(t[2]*n,255);let a=0;return i+o+s!==0&&(a=i>0?i/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"})),n=new Date(t.toLocaleString("en-US",e?{timeZone:e}:{}));return r.getTime()-n.getTime()};const E=t=>{const e=()=>!t.getPitch;return{project:(r,i)=>{if(e())return t.project(r,i);{const{lat:t,lng:e}=r;return new n(((t,e)=>(t+180)/360*Math.pow(2,e)*d)(e,i),((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,i))}},unproject:(r,n)=>{return e()?t.unproject(r,n):new c((i=r.y,o=n,s=Math.PI-2*Math.PI*i/d/Math.pow(2,o),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,n));var i,o,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,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}const v=(t,e)=>{const{lat:r,lng:i}=t;return new n(((t,e)=>(t+180)/360*Math.pow(2,e)*d)(i,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))},y=(t,e)=>{return new c((r=t.y,n=e,i=Math.PI-2*Math.PI*r/d/Math.pow(2,n),180/Math.PI*Math.atan(.5*(Math.exp(i)-Math.exp(-i)))),function(t,e){return t/d/Math.pow(2,e)*360-180}(t.x,e));var r,n,i};function R(t){const{gl:e,vSrc:r,fSrc:n}=t,i=e.createShader(e.VERTEX_SHADER);e.shaderSource(i,r),e.compileShader(i);const o=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(o,n),e.compileShader(o);const s=e.createProgram();return e.attachShader(s,i),e.attachShader(s,o),e.linkProgram(s),s}class A{constructor(t){this.gl=t,this.program=R({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;\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\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;\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n\t \tgl_FragColor = vec4(textureColor.b, textureColor.a, 0, 1.0);\n // DSM noData values should not be included in heightMap because they produce ugly borders\n if (gl_FragColor.xy == vec2(0.0)) {\n discard;\n }\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:i,width:o,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 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,o,s,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,a);const g=o,p=s;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),i>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.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,R=f*d,A=new n(y,R);l.uniform3f(this.xyzUniformLocation,y,R,m),l.uniform2f(this.dimensionsUniformLocation,o,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:n,centroid:i,highlight:u}=t,h=v({lng:i[0],lat:i[1]},m).subtract(A).floor();if(h.x<0||h.y<0||h.x>o||h.y>s)return;const c=256*a[h.y*o*2+2*h.x]+a[h.y*o*2+2*h.x+1]+5*e,f=Math.floor(c/256)/256,d=Math.floor(c%256)/256;_=Math.max(_,c/5),l.uniform4f(this.colorUniformLocation,f,d,u?1:0,1),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,n,l.DYNAMIC_DRAW),l.drawElements(l.TRIANGLES,n.length,n.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);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.drawArrays(l.TRIANGLE_STRIP,0,4),l.deleteTexture(t)}return l.deleteFramebuffer(E),_}}function b(t,e,r){r=r||2;var n,i,o,s,a,u,h,l=e&&e.length,c=l?e[0]*r:t.length,f=M(t,0,c,r,!0),d=[];if(!f||f.next===f.prev)return d;if(l&&(f=function(t,e,r,n){var i,o,s,a=[];for(i=0,o=e.length;i<o;i++)(s=M(t,e[i]*n,i<o-1?e[i+1]*n:t.length,n,!1))===s.next&&(s.steiner=!0),a.push(B(s));for(a.sort(I),i=0;i<a.length;i++)r=C(a[i],r);return r}(t,e,f,r)),t.length>80*r){n=o=t[0],i=s=t[1];for(var m=r;m<c;m+=r)(a=t[m])<n&&(n=a),(u=t[m+1])<i&&(i=u),a>o&&(o=a),u>s&&(s=u);h=0!==(h=Math.max(o-n,s-i))?32767/h:0}return L(f,d,r,n,i,h,0),d}function M(t,e,r,n,i){var o,s;if(i===V(t,e,r,n)>0)for(o=e;o<r;o+=n)s=K(o,t[o],t[o+1],s);else for(o=r-n;o>=e;o-=n)s=K(o,t[o],t[o+1],s);return s&&G(s,s.next)&&(q(s),s=s.next),s}function w(t,e){if(!t)return t;e||(e=t);var r,n=t;do{if(r=!1,n.steiner||!G(n,n.next)&&0!==z(n.prev,n,n.next))n=n.next;else{if(q(n),(n=e=n.prev)===n.next)break;r=!0}}while(r||n!==e);return e}function L(t,e,r,n,i,o,s){if(t){!s&&o&&function(t,e,r,n){var i=t;do{0===i.z&&(i.z=N(i.x,i.y,e,r,n)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next}while(i!==t);i.prevZ.nextZ=null,i.prevZ=null,function(t){var e,r,n,i,o,s,a,u,h=1;do{for(r=t,t=null,o=null,s=0;r;){for(s++,n=r,a=0,e=0;e<h&&(a++,n=n.nextZ);e++);for(u=h;a>0||u>0&&n;)0!==a&&(0===u||!n||r.z<=n.z)?(i=r,r=r.nextZ,a--):(i=n,n=n.nextZ,u--),o?o.nextZ=i:t=i,i.prevZ=o,o=i;r=n}o.nextZ=null,h*=2}while(s>1)}(i)}(t,n,i,o);for(var a,u,h=t;t.prev!==t.next;)if(a=t.prev,u=t.next,o?S(t,n,i,o):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?L(t=D(w(t),e,r),e,r,n,i,o,2):2===s&&P(t,e,r,n,i,o):L(w(t),e,r,n,i,o,1);break}}}function U(t){var e=t.prev,r=t,n=t.next;if(z(e,r,n)>=0)return!1;for(var i=e.x,o=r.x,s=n.x,a=e.y,u=r.y,h=n.y,l=i<o?i<s?i:s:o<s?o:s,c=a<u?a<h?a:h:u<h?u:h,f=i>o?i>s?i:s:o>s?o:s,d=a>u?a>h?a:h:u>h?u:h,m=n.next;m!==e;){if(m.x>=l&&m.x<=f&&m.y>=c&&m.y<=d&&X(i,a,o,u,s,h,m.x,m.y)&&z(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function S(t,e,r,n){var i=t.prev,o=t,s=t.next;if(z(i,o,s)>=0)return!1;for(var a=i.x,u=o.x,h=s.x,l=i.y,c=o.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,x=l>c?l>f?l:f:c>f?c:f,g=N(d,m,e,r,n),p=N(_,x,e,r,n),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!==i&&E!==s&&X(a,l,u,c,h,f,E.x,E.y)&&z(E.prev,E,E.next)>=0)return!1;if(E=E.prevZ,T.x>=d&&T.x<=_&&T.y>=m&&T.y<=x&&T!==i&&T!==s&&X(a,l,u,c,h,f,T.x,T.y)&&z(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!==i&&E!==s&&X(a,l,u,c,h,f,E.x,E.y)&&z(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!==i&&T!==s&&X(a,l,u,c,h,f,T.x,T.y)&&z(T.prev,T,T.next)>=0)return!1;T=T.nextZ}return!0}function D(t,e,r){var n=t;do{var i=n.prev,o=n.next.next;!G(i,o)&&H(i,n,n.next,o)&&Z(i,o)&&Z(o,i)&&(e.push(i.i/r|0),e.push(n.i/r|0),e.push(o.i/r|0),q(n),q(n.next),n=t=o),n=n.next}while(n!==t);return w(n)}function P(t,e,r,n,i,o){var s=t;do{for(var a=s.next.next;a!==s.prev;){if(s.i!==a.i&&O(s,a)){var u=Y(s,a);return s=w(s,s.next),u=w(u,u.next),L(s,e,r,n,i,o,0),void L(u,e,r,n,i,o,0)}a=a.next}s=s.next}while(s!==t)}function I(t,e){return t.x-e.x}function C(t,e){var r=function(t,e){var r,n=e,i=t.x,o=t.y,s=-1/0;do{if(o<=n.y&&o>=n.next.y&&n.next.y!==n.y){var a=n.x+(o-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(a<=i&&a>s&&(s=a,r=n.x<n.next.x?n:n.next,a===i))return r}n=n.next}while(n!==e);if(!r)return null;var u,h=r,l=r.x,c=r.y,f=1/0;n=r;do{i>=n.x&&n.x>=l&&i!==n.x&&X(o<c?i:s,o,l,c,o<c?s:i,o,n.x,n.y)&&(u=Math.abs(o-n.y)/(i-n.x),Z(n,t)&&(u<f||u===f&&(n.x>r.x||n.x===r.x&&F(r,n)))&&(r=n,f=u)),n=n.next}while(n!==h);return r}(t,e);if(!r)return e;var n=Y(r,t);return w(n,n.next),w(r,r.next)}function F(t,e){return z(t.prev,t,e.prev)<0&&z(e.next,t,t.next)<0}function N(t,e,r,n,i){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*i|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-n)*i|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 X(t,e,r,n,i,o,s,a){return(i-s)*(e-a)>=(t-s)*(o-a)&&(t-s)*(n-a)>=(r-s)*(e-a)&&(r-s)*(o-a)>=(i-s)*(n-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&&H(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,n=!1,i=(t.x+e.x)/2,o=(t.y+e.y)/2;do{r.y>o!=r.next.y>o&&r.next.y!==r.y&&i<(r.next.x-r.x)*(o-r.y)/(r.next.y-r.y)+r.x&&(n=!n),r=r.next}while(r!==t);return n}(t,e)&&(z(t.prev,t,e.prev)||z(t,e.prev,e))||G(t,e)&&z(t.prev,t,t.next)>0&&z(e.prev,e,e.next)>0)}function z(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function G(t,e){return t.x===e.x&&t.y===e.y}function H(t,e,r,n){var i=j(z(t,e,r)),o=j(z(t,e,n)),s=j(z(r,n,t)),a=j(z(r,n,e));return i!==o&&s!==a||(!(0!==i||!W(t,r,e))||(!(0!==o||!W(t,n,e))||(!(0!==s||!W(r,t,n))||!(0!==a||!W(r,e,n)))))}function W(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 j(t){return t>0?1:t<0?-1:0}function Z(t,e){return z(t.prev,t,t.next)<0?z(t,e,t.next)>=0&&z(t,t.prev,e)>=0:z(t,e,t.prev)<0||z(t,t.next,e)<0}function Y(t,e){var r=new k(t.i,t.x,t.y),n=new k(e.i,e.x,e.y),i=t.next,o=e.prev;return t.next=e,e.prev=t,r.next=i,i.prev=r,n.next=r,r.prev=n,o.next=n,n.prev=o,n}function K(t,e,r,n){var i=new k(t,e,r);return n?(i.next=n.next,i.prev=n,n.next.prev=i,n.next=i):(i.prev=i,i.next=i),i}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 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 V(t,e,r,n){for(var i=0,o=e,s=r-n;o<r;o+=n)i+=(t[s]-t[o])*(t[o+1]+t[s+1]),s=o;return i}function $(t){t.filter((t=>"MultiPolygon"===t.geometry.type)).forEach((e=>{const{geometry:r,properties:n,type:i}=e;if("MultiPolygon"===r.type)for(let n=0;n<r.coordinates.length;n++)t.push(Object.assign(Object.assign({},e),{geometry:Object.assign(Object.assign({},r),{type:"Polygon",coordinates:r.coordinates[n]})}))}));return t.filter((t=>"Polygon"===t.geometry.type)).map((t=>{const{geometry:e,properties:r}=t,{vertices:n}=b.flatten(e.coordinates),i=new Float32Array(n.map(((t,e)=>{if(e%2==1){const e=t*Math.PI/180;return Math.tan(e)+1/Math.cos(e)}return t}))),o=b(n),s=o.length>256?new Uint16Array(o):new Uint8Array(o),a=function(t){const{height:e=0,levels:r=0,render_height:n=0}=t;if(r)return 3.04*r;return Math.max(e,n)}(r),u=r.highlight||!1;let h=0,l=0,c=0;for(let t=0;t<n.length;t+=2)h+=n[t],l+=n[t+1],c++;return{aPosition:i,cuts:s,buildingHeight:a,centroid:[h/c,l/c],highlight:u}}))}b.deviation=function(t,e,r,n){var i=e&&e.length,o=i?e[0]*r:t.length,s=Math.abs(V(t,0,o,r));if(i)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(V(t,h,l,r))}var c=0;for(a=0;a<n.length;a+=3){var f=n[a]*r,d=n[a+1]*r,m=n[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)},b.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},n=0,i=0;i<t.length;i++){for(var o=0;o<t[i].length;o++)for(var s=0;s<e;s++)r.vertices.push(t[i][o][s]);i>0&&(n+=t[i-1].length,r.holes.push(n))}return r};let J,Q={width:0,height:0,imageData:new Uint8ClampedArray(0),visibleDEMPixelBounds:new s(new n(0,0),new n(0,0)),DEMPixelBounds:new s(new n(0,0),new n(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const tt=t=>T(void 0,void 0,void 0,(function*(){const{demZoom:e,getFeatures:r,terrainSource:i,dsmSource:o,tileLoaded:a,gl:h,bounds:l,buildingRasterizer:c,tileMerger:f,forceUpdate:m=!1}=t,{getSourceUrl:_,getElevation:x,maxZoom:g,tileSize:p,_overzoom:E}=i,y=(R={getFeatures:r},T(void 0,void 0,void 0,(function*(){const{getFeatures:t}=R;try{return $(yield t())}catch(t){console.log("Error merging buildings",t)}return[]})));var R;try{const t=l,r=t.getNorthWest(),i=t.getSouthEast(),E=new s(v(r,e),v(i,e));let T=new n(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:n}=t,i=e.divideBy(d).floor().multiplyBy(d),o=(Math.ceil(r/d)+1)*d,a=(Math.ceil(n/d)+1)*d,u=i.add([o,a]);return new s(i,u)})({upperLeft:T,width:R,height:A}),{x:w,y:L}=M.max.subtract(M.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 n=Math.pow(2,t.z);return{x:(t.x%n+n)%n,y:(t.y%n+n)%n,z:t.z,xOffset:(t.x-e)*d,yOffset:(t.y-r)*d}}))})((t=>{const{upperLeft:e,width:r,height:n,zoom:i}=t,o=e.divideBy(d).floor(),s=o.x+r/d,a=Math.min(o.y+n/d,Math.pow(2,i)-1),u=[];for(var h=o.x;h<s;h++)for(var l=o.y;l<a;l++)u.push({x:h,y:l,z:i});return u})({upperLeft:M.min,width:w,height:L,zoom:e})),S=E.max.x-E.min.x,D=E.max.y-E.min.y,P=S,I=D,C=JSON.stringify(U);if(!m&&C===J&&e<g)return Q=Object.assign(Object.assign({},Q),{outputWidth:P,outputHeight:I,visibleDEMPixelBounds:E,demZoom:e,dirty:!0}),Q;const F=yield f.merge(U,{maxZoom:g,width:w,height:L,crossOrigin:"Anonymous",getSourceUrl:_,getElevation:x,tileSize:p,tileLoaded:a});if(null===F)return Q=Object.assign(Object.assign({},Q),{visibleDEMPixelBounds:E,demZoom:e,dirty:!1}),Q;const N=new s(v(new u(o.bounds).getNorthWest(),e),v(new u(o.bounds).getSouthEast(),e)),B=N.min.subtract(M.min),X=N.max.subtract(M.min),O=[B.x/w,B.y/L,X.x/w,X.y/L].map((t=>2*t-1)),z=yield y,G=c.raster({upperLeftTile:U[0],width:w,height:L,mapZoom:e,features:z,imageData:F,gl:h,dsmSource:o,dsmCoords:O}),H=Math.max(Math.max(o.maxHeight,G),F.maxHeight);J=C,Q={maxHeight:H,width:w,height:L,imageData:F,DEMPixelBounds:M,visibleDEMPixelBounds:E,raster:U,demZoom:e,dirty:!0,outputWidth:P,outputHeight:I}}catch(t){console.error("Could not decode height map",t)}return Q})),et=t=>{const{tile:e,maxZoom:r,tileSize:n}=t;let{x:i,y:o,z:s}=e;if(s>r){const t=Math.pow(2,e.z-r);i=Math.floor(i/t),o=Math.floor(o/t),s=r}return{x:n===d?i:Math.floor(i/2),y:n===d?o:Math.floor(o/2),z:n===d?s:s-1}};class rt{constructor(){this.canvas=document.createElement("canvas"),this.canvas.width=d,this.canvas.height=d,this.ctx=this.canvas.getContext("2d",{antialias:!1,alpha:!1,willReadFrequently:!0}),null!==this.ctx&&(this.ctx.imageSmoothingEnabled=!1),this.inProgress=[],this.finished=0}merge(t,e){return T(this,void 0,void 0,(function*(){const{width:r,height:n,crossOrigin:i,getSourceUrl:o,getElevation:s,tileSize:a,tileLoaded:u,maxZoom:h}=e;if(this.ctx){const e=new Uint8ClampedArray(2*r*n);e.maxHeight=0,this.inProgress.forEach((t=>t.src="")),this.inProgress=[],this.finished=0;const l=new Set;t.forEach((t=>{l.add(o(et({tile:t,maxZoom:h,tileSize:a})))}));const c=Array.from(l).map((n=>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=>n===o(et({tile:t,maxZoom:h,tileSize:a})))).forEach((t=>{let n=0,i=0;const o=514===a?1:0;let u=0,l=d,f=d;if(a!==d&&(n=t.x%2*d,i=t.y%2*d,l=d,f=d),t.z>h){const e=Math.pow(2,t.z-h);a!==d&&(n=Math.floor(t.x/e)%2*d,i=Math.floor(t.y/e)%2*d),n+=d*(t.x%e/e),i+=d*(t.y%e/e),l=d/e,f=d/e,u=514===a?1:0}this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.drawImage(c,o+n,o+i,l+u,f+u,0,0,l+u,f+u);const m=this.ctx.getImageData(0,0,l+u,f+u).data,_=new Uint8ClampedArray(131072);let x=new Array((l+u)*(f+u)),g=d/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 n=5*(r||0);x[t/4]=n}if(g>1&&514===a)for(x=function(t,e,r,n){const i=Math.floor(e*n),o=Math.floor(r*n),s=[];for(let a=0;a<o;a++)for(let o=0;o<i;o++){const i=o/n,u=a/n,h=Math.floor(i),l=Math.floor(u),c=Math.min(h+1,e-1),f=Math.min(l+1,r-1),d=i-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;s.push(p)}return function(t,e,r,n,i){if(n>=e||i>=r)return[];const o=e-n,s=r-i,a=[];for(let r=0;r<s;r++)for(let n=0;n<o;n++){const i=r*e+n;a.push(t[i])}return a}(s,Math.sqrt(s.length),Math.sqrt(s.length),n,n)}(x,l+1,f+1,g);g>1;)g/=2,f*=2,l*=2;for(let t=0;t<_.length;t+=2){const e=x[Math.floor(t/2/d/g)*l+Math.floor(t/2%d/g)],r=Math.floor(e/256),n=Math.floor(e%256);_[t]=r,_[t+1]=n}for(let n=0;n<d;n++)e.set(_.slice(n*d*2,(n+1)*d*2),2*(t.yOffset*r+n*r+t.xOffset))})),u(null)},c.onerror=t=>{if(c.src!==c.originalSource)return l("new tiles requested");u(null)},c.crossOrigin=i||null,c.src=n,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 nt=(t,e)=>{const{r:r,g:n,b:i}=t;return[r/255,n/255,i/255,e]},it=(t,e)=>{const{date:r}=e,{dec:n,Hi:i}=_(r);t.updateDate({dec:n,Hi:i})},ot=(t,e)=>T(void 0,void 0,void 0,(function*(){return yield t.updateDateRange(Object.assign({},e))})),st=(t,e)=>{const{color:r,opacity:n}=e,i=nt(r,n);t.updateColor({colorVec:i})};new u([0,0],[0,0]);const at=t=>{const{kernel:e,map:r,heightMap:n,now:i,color:o,opacity:s}=t;try{const{outputHeight:t,outputWidth:a,maxHeight:h,width:l,height:c,DEMPixelBounds:f,imageData:m,visibleDEMPixelBounds:x,demZoom:g}=n;if(0===l||0===c)return;const{min:p,max:E}=x;if(!p||!E)return;const{x:T,y:v}=E.subtract(p),R=f.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]),U=[L,w,b,M].map((t=>r.project(t,g))),S=U.map((t=>[(t.x-R.x)/l,(t.y-R.y)/c])).flat(),D=U.map((t=>[(t.x-p.x)/T,(t.y-p.y)/v])).map((t=>[2*t[0]-1,-1*(2*t[1]-1)])).flat(),P=R.y/d/Math.pow(2,g),I=c/d/Math.pow(2,g),C=new u(y(f.getTopLeft(),g),y(f.getBottomRight(),g)),F=C.getWest(),N=Math.abs(C.getWest()-C.getEast());((t,e)=>{const{color:r,opacity:n,date:i}=e,o=nt(r,n),{dec:s,Hi:a}=_(i);t.updateLocation(Object.assign({dec:s,Hi:a,colorVec:o,step:1},e))})(e,{imageData:m,maxHeight:h,width:l,height:c,heightMapZoom:g,cornerTextureCoords:S,cornerClipCoords:D,topYCoord:P,ySize:I,west:F,dLng:N,date:i,color:o,opacity:s,outputHeight:t,outputWidth: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:n}=t;return 256*e+r+n/256-32768}},dsmSource:{bounds:[{lat:0,lng:0},{lat:0,lng:0}],data:new Uint8ClampedArray,width:0,height:0,maxHeight:0},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,n=R({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 getElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*256.0*256.0+result.g*256.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 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_z=getElevationFromSampler2D(user_a,user_x,user_y);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_lit=1.0;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=getElevationFromSampler2D(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));if(result.z==1.0){shade_color=vec4(.92941,.4375,.078125,.85);}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(n);const i=r.createBuffer(),o=r.getAttribLocation(n,"a_pos"),s=r.createBuffer(),a=r.getAttribLocation(n,"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(n,"user_a");r.uniform1i(h,0);const l=r.getUniformLocation(n,"user_width"),c=r.getUniformLocation(n,"user_height"),f=r.getUniformLocation(n,"user_maxHeight"),d=r.getUniformLocation(n,"user_zoom"),m=r.getUniformLocation(n,"user_topYCoord"),x=r.getUniformLocation(n,"user_ySize"),g=r.getUniformLocation(n,"user_step"),p=r.getUniformLocation(n,"user_west"),E=r.getUniformLocation(n,"user_dLng"),v=r.getUniformLocation(n,"user_dec"),y=r.getUniformLocation(n,"user_Hi"),A=r.getUniformLocation(n,"user_color"),b=r.getUniformLocation(n,"user_xStart"),M=r.getUniformLocation(n,"user_yStart"),w=r.getUniformLocation(n,"user_xEnd"),L=r.getUniformLocation(n,"user_yEnd"),U=r.getUniformLocation(n,"user_sunExposureTexture");r.uniform1i(U,2);const S=r.getUniformLocation(n,"user_renderToSunExposureTexture"),D=r.getUniformLocation(n,"user_outputSunExposure"),P=r.getUniformLocation(n,"user_exposureDelta"),I=r.getUniformLocation(n,"u_outputShadeProfile"),C=r.getUniformLocation(n,"u_gpxTexture"),F=r.getUniformLocation(n,"u_decHiTexture"),N=r.getUniformLocation(n,"u_sunColor"),B=r.getUniformLocation(n,"u_outputLocationShadeProfile"),X=r.getUniformLocation(n,"u_shadeProfileLocation"),O=()=>{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:b,step:M,west:w,dLng:L,dec:U,Hi:S,cornerClipCoords:D,cornerTextureCoords:P,outputWidth:I,outputHeight:C}=t;r.useProgram(n),r.canvas.width=I,r.canvas.height=C,r.viewport(0,0,I,C),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindBuffer(r.ARRAY_BUFFER,i),r.bufferData(r.ARRAY_BUFFER,new Float32Array(D),r.STATIC_DRAW),r.enableVertexAttribArray(o),r.vertexAttribPointer(o,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(x,R),r.uniform4fv(A,b),r.uniform1f(g,M),r.uniform1f(p,w),r.uniform1f(E,L),r.uniform1f(v,U),r.uniform1f(y,S),window.requestAnimationFrame(O)},updateViewport:function(t){const{xStart:e,yStart:n,xEnd:i,yEnd:o}=t;r.uniform1f(b,e),r.uniform1f(M,n),r.uniform1f(w,i),r.uniform1f(L,o),window.requestAnimationFrame(O)},updateDate:t=>{const{dec:e,Hi:n}=t;r.uniform1f(v,e),r.uniform1f(y,n),window.requestAnimationFrame(O)},updateDateRange:t=>T(this,void 0,void 0,(function*(){const{startDate:e,endDate:n,iterations:i,emit:o}=t,s=z=Date.now();r.uniform4fv(P,new Float32Array([1/i,0,0,0]));const a=Math.floor((n.getTime()-e.getTime())/i),u=r.canvas.width,h=r.canvas.height,l=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,l),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,u,h,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 c=r.createTexture();r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,c),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,u,h,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),r.uniform1i(S,1);const f=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,f);const d=r.COLOR_ATTACHMENT0;r.viewport(0,0,u,h);for(let t=0;t<i;t++){if(o("tileloaded",t,i-1),s!==z)return!0;yield new Promise(((n,i)=>{window.requestAnimationFrame((()=>{t%2==0?(r.uniform1i(U,2),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,l),r.framebufferTexture2D(r.FRAMEBUFFER,d,r.TEXTURE_2D,l,0)):(r.uniform1i(U,1),r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,c),r.framebufferTexture2D(r.FRAMEBUFFER,d,r.TEXTURE_2D,c,0));const{dec:i,Hi:o}=_(new Date(e.getTime()+a*t));r.uniform1f(v,i),r.uniform1f(y,o),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4),n()}))}))}return yield new Promise(((t,e)=>{window.requestAnimationFrame((()=>{s!==z&&t(!0),r.bindFramebuffer(r.FRAMEBUFFER,null),r.uniform1i(U,i%2==0?2:1),r.uniform1i(D,1),O(),r.uniform1i(S,0),r.uniform1i(D,0),r.deleteFramebuffer(f),r.deleteTexture(l),r.deleteTexture(c),t(!1)}))}))})),updateColor:t=>{const{colorVec:e}=t;r.uniform4fv(A,e),window.requestAnimationFrame(O)},generateShadeProfile:t=>{if(null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");const{dates:e,texCoords:s,shadeColor:a,sunColor:h}=t,l=s.length,c=e.length,f=r.getParameter(r.VIEWPORT),d=r.getUniform(n,A);r.uniform4fv(A,a),r.uniform4fv(N,h),r.uniform1i(I,1);const m=r.createTexture();r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,m);const x=s.map((t=>[t[0],t[1],0,0])).flat();r.texImage2D(r.TEXTURE_2D,0,r.RGBA,x.length/4,1,0,r.RGBA,r.FLOAT,new Float32Array(x)),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.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.uniform1i(C,2);const g=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,g);const p=e.map((t=>{const{dec:e,Hi:r}=_(t);return[-e,r/10,0,0]})).flat();r.texImage2D(r.TEXTURE_2D,0,r.RGBA,1,e.length,0,r.RGBA,r.FLOAT,new Float32Array(p)),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.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.uniform1i(F,1),r.viewport(0,0,l,c),r.clear(r.COLOR_BUFFER_BIT),r.bindBuffer(r.ARRAY_BUFFER,u),r.enableVertexAttribArray(o),r.vertexAttribPointer(o,2,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.bindBuffer(r.ARRAY_BUFFER,i),r.vertexAttribPointer(o,2,r.FLOAT,!1,0,0);const E=new Uint8Array(l*c*4);return r.readPixels(0,0,l,c,r.RGBA,r.UNSIGNED_BYTE,E),r.deleteTexture(g),r.deleteTexture(m),r.uniform1i(F,0),r.uniform1i(C,0),r.uniform1i(I,0),r.viewport(f[0],f[1],f[2],f[3]),r.uniform4fv(A,d),r.uniform4fv(N,[0,0,0,0]),E},generateLocationShadeProfile:t=>{if(null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");const{dates:e,texCoord:s,shadeColor:a,sunColor:h}=t,l=e[0].length,c=e.length,f=r.getParameter(r.VIEWPORT),d=r.getUniform(n,A);r.uniform4fv(A,a),r.uniform4fv(N,h),r.uniform1i(B,1),r.uniform2fv(X,[s[0],s[1]]);const m=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,m);const x=e.flat().map((t=>{const{dec:e,Hi:r}=_(t);return[-e,r/10,0,0]})).flat();r.texImage2D(r.TEXTURE_2D,0,r.RGBA,l,c,0,r.RGBA,r.FLOAT,new Float32Array(x)),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.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.uniform1i(F,1),r.viewport(0,0,l,c),r.clear(r.COLOR_BUFFER_BIT),r.bindBuffer(r.ARRAY_BUFFER,u),r.enableVertexAttribArray(o),r.vertexAttribPointer(o,2,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.bindBuffer(r.ARRAY_BUFFER,i),r.vertexAttribPointer(o,2,r.FLOAT,!1,0,0);const g=new Uint8Array(l*c*4);return r.readPixels(0,0,l,c,r.RGBA,r.UNSIGNED_BYTE,g),r.deleteTexture(m),r.uniform1i(F,0),r.uniform1i(B,0),r.viewport(f[0],f[1],f[2],f[3]),r.uniform4fv(A,d),r.uniform4fv(N,[0,0,0,0]),g}}}({context:this._gl}),this._color=this._parseColor(this.options.color),this._buildingRasterizer=new A(this._gl),this._tileMerger=new rt,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=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&&(st(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&&(st(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),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._map&&this._compiledKernel){if(!1===t)this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:t}),it(this._compiledKernel,{date:this.options.date});else{const{startDate:r,endDate:n,iterations:i=32}=e;if(this.options.sunExposure={enabled:t,startDate:r,endDate:n,iterations:i},!(r instanceof Date&&n instanceof Date))throw new Error("Start date or end date or both are missing");if(n.getTime()<r.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield ot(this._compiledKernel,{startDate:r,endDate:n,iterations:i,emit:this.emit.bind(this)})))return this}this._flush()}return this}))}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:n,height:i}=this._heightMap,o=e.min;return t.map((t=>{const e=v(t,r);return[(e.x-o.x)/n,(e.y-o.y)/i]}))}return[]}_getBounds(t,e){const{width:r,height:i}=this.options.getSize();if(Number.isNaN(r)||Number.isNaN(i))return t.getBounds();const o=t.getCenter(),s=v(o,e),a=y(new n(s.x-r/2,s.y-i/2),e),u=y(new n(s.x+r/2,s.y+i/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(),i=r.reduce(((t,e)=>Math.max(t,e.canonical.z)),Number.MIN_SAFE_INTEGER),o=r.filter((t=>t.canonical.z===i)).map((t=>t.canonical)),[s,a,u,h]=o.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=y(new n(512*s,512*a),i+1),c=y(new n(512*(u+1),512*(h+1)),i+1);e=i+1,this._bounds=t.createBounds({nw:l,se:c})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield tt({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(at({kernel:this._compiledKernel,map:E(this._map),heightMap:t,color:this._color,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,n)=>{const i=new Uint8Array(r*n*4);this._gl.readPixels(t,e,r,n,this._gl.RGBA,this._gl.UNSIGNED_BYTE,i);const o=r*n*1,s=1*r,a=(n-1)*s,u=new Uint8Array(o),h=new Uint8Array(o);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<i.length;t+=4){let e;if(this.options.sunExposure.enabled){const r=i.subarray(t,t+3),n=g(r,.5,l)/1e3/60,o=Math.min(Math.floor(n/6),255);e=new Uint8Array([o])}else{e=i[t]+i[t+1]+i[t+2]===0?new Uint8Array([255]):new Uint8Array([0])}u.set(e,t/4*1)}for(let t=0;t<o;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,n=t(0,0,e,r),i=E(this._map),{lat:o,lng:s}=i.getBounds().getNorthWest(),a=i.getBounds().getSouthEast(),u=[0,0,0,s,o,0],h=[(a.lng-s)/e,(o-a.lat)/r,0];return this.options.sunExposure.enabled,{data:n,metadata:{width:e,height:r,ModelTiepoint:u,ModelPixelScale:h,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}return null}_generateShadeProfile(t){if(this._compiledKernel){const e=this._canvas.width,r=this._canvas.height;this._canvas.width=t.locations.length,this._canvas.height=t.dates.length;const n=this._lngLatToTextureCoords(t.locations),i=((t,e)=>{const r=nt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),n=nt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:n}))})(this._compiledKernel,Object.assign(Object.assign({},t),{texCoords:n}));return this._canvas.width=e,this._canvas.height=r,i}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=this._canvas.width,r=this._canvas.height,n=p(t.startDate)-p(t.startDate,t.tzId),i=t.startDate.getTime()-n,o=(t.endDate.getTime()-n-i)/86400/1e3,s=1440;this._canvas.width=o,this._canvas.height=s;const a=[],u=828e5,h=p(new Date(i),t.tzId);for(let e=0;e<o;e++){const r=p(new Date(i+86400*e*1e3+u),t.tzId)-h;a[e]=r}const l=[];for(let t=0;t<s;t++){const e=[];for(let r=0;r<o;r++){const n=i+86400*r*1e3+60*t*1e3;e.push(new Date(n+a[r]))}l.push(e)}const c=this._lngLatToTextureCoords([t.location])[0],f=((t,e)=>{const r=nt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),n=nt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateLocationShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:n}))})(this._compiledKernel,Object.assign(Object.assign({},t),{dates:l,texCoord:c}));return this._canvas.width=e,this._canvas.height=r,f.toArray=function(){const e=new Array;for(let r=0;r<o;r++){const n=[];for(let e=s-1;e>=0;e--){const i=e*o*4+4*r,s=this.slice(i,i+4);n.push(s.join("")===t.sunColor.join("")?1:0)}e.push(n)}return e},{data:f,width:o,height:s}}return{data:new Uint8Array,width:0,height:0}}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this.readPixel(t,e),{startDate:n,endDate:i}=this.options.sunExposure,o=i.getTime()-n.getTime(),s=g(r,.5,o);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+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,document.body.appendChild(this._canvas),this._canvas.style.display="none";const e=t.getBounds(),r=e.getNorthWest(),n=e.getNorthEast(),i=e.getSouthEast(),o=e.getSouthWest(),s=[[r.lng,r.lat],[n.lng,n.lat],[i.lng,i.lat],[o.lng,o.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 n(-1,-1);const{visibleDEMPixelBounds:i,demZoom:o}=this._heightMap,s=E(this._map).project(r,o).subtract(i.min);return s.y=i.max.y-i.min.y-s.y,s}return new n(-1,-1)}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this._getHeightMapCoords(t,e),n=this.readPixel(r.x,r.y),{startDate:i,endDate:o}=this.options.sunExposure,s=o.getTime()-i.getTime(),a=g(n,.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(),n=t.getNorthEast(),i=t.getSouthEast(),o=t.getSouthWest(),s=[[r.lng,r.lat],[n.lng,n.lat],[i.lng,i.lat],[o.lng,o.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 n=e[1],i=e[0],o=n-i;return t===n&&r?t:((t-i)%o+o)%o+i}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 n(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var i=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function o(t,e,i){return t instanceof n?t:r(t)?new n(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new n(t.x,t.y):new n(t,e,i)}function s(t,e){if(t)for(var r=e?[t,e]:t,n=0,i=r.length;n<i;n++)this.extend(r[n])}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,n=0,i=r.length;n<i;n++)this.extend(r[n])}function h(t,e){return t instanceof u?t:new u(t,e)}n.prototype={clone:function(){return new n(this.x,this.y)},add:function(t){return this.clone()._add(o(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(o(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 n(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new n(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=i(this.x),this.y=i(this.y),this},distanceTo:function(t){var e=(t=o(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=o(t)).x===this.x&&t.y===this.y},contains:function(t){return t=o(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 n||"number"==typeof t[0]||"x"in t)e=r=o(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 o((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return o(this.min.x,this.max.y)},getTopRight:function(){return o(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 n?o(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,n=t.min,i=t.max,o=i.x>=e.x&&n.x<=r.x,s=i.y>=e.y&&n.y<=r.y;return o&&s},overlaps:function(t){t=a(t);var e=this.min,r=this.max,n=t.min,i=t.max,o=i.x>e.x&&n.x<r.x,s=i.y>e.y&&n.y<r.y;return o&&s},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,n=Math.abs(e.x-r.x)*t,i=Math.abs(e.y-r.y)*t;return a(o(e.x-n,e.y-i),o(r.x+n,r.y+i))},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,n=this._southWest,i=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 n||i?(n.lat=Math.min(e.lat,n.lat),n.lng=Math.min(e.lng,n.lng),i.lat=Math.max(r.lat,i.lat),i.lng=Math.max(r.lng,i.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,n=Math.abs(e.lat-r.lat)*t,i=Math.abs(e.lng-r.lng)*t;return new u(new c(e.lat-n,e.lng-i),new c(r.lat+n,r.lng+i))},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,n=this._southWest,i=this._northEast;return t instanceof u?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=n.lat&&r.lat<=i.lat&&e.lng>=n.lng&&r.lng<=i.lng},intersects:function(t){t=h(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),i=t.getNorthEast(),o=i.lat>=e.lat&&n.lat<=r.lat,s=i.lng>=e.lng&&n.lng<=r.lng;return o&&s},overlaps:function(t){t=h(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),i=t.getNorthEast(),o=i.lat>e.lat&&n.lat<r.lat,s=i.lng>e.lng&&n.lng<r.lng;return o&&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,n,i;for(r=1,n=arguments.length;r<n;r++)for(e in i=arguments[r])t[e]=i[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),n=this.scale(e);return this.transformation._transform(r,n)},pointToLatLng:function(t,e){var r=this.scale(e),n=this.transformation.untransform(t,r);return this.projection.unproject(n)},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),n=e.lat-r.lat,i=e.lng-r.lng;if(0===n&&0===i)return t;var o=t.getSouthWest(),s=t.getNorthEast();return new u(new c(o.lat-n,o.lng-i),new c(s.lat-n,s.lng-i))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,n=t.lat*r,i=e.lat*r,o=Math.sin((e.lat-t.lat)*r/2),s=Math.sin((e.lng-t.lng)*r/2),a=o*o+Math.cos(n)*Math.cos(i)*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,n){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,n)}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,n=r+.017453292519943295*(1.9148*Math.sin(r)+.02*Math.sin(2*r)+3e-4*Math.sin(3*r))+1.796593062783907+Math.PI,i=Math.atan2(Math.sin(n)*Math.cos(m),Math.cos(n));return{dec:Math.asin(Math.sin(m)*Math.sin(n)),Hi:(4.889714432387314+6.3003876824396166*e-i)%(2*Math.PI)+2*Math.PI}},x=()=>Math.floor(1e7*Math.random()),g=(t,e,r)=>{const n=1/e,i=Math.min(t[0]*n,255),o=Math.min(t[1]*n,255),s=Math.min(t[2]*n,255);let a=0;return i+o+s!==0&&(a=i>0?i/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"})),n=new Date(t.toLocaleString("en-US",e?{timeZone:e}:{}));return r.getTime()-n.getTime()};const E=t=>{const e=()=>!t.getPitch;return{project:(r,i)=>{if(e())return t.project(r,i);{const{lat:t,lng:e}=r;return new n(((t,e)=>(t+180)/360*Math.pow(2,e)*d)(e,i),((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,i))}},unproject:(r,n)=>{return e()?t.unproject(r,n):new c((i=r.y,o=n,s=Math.PI-2*Math.PI*i/d/Math.pow(2,o),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,n));var i,o,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,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}const v=(t,e)=>{const{lat:r,lng:i}=t;return new n(((t,e)=>(t+180)/360*Math.pow(2,e)*d)(i,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))},y=(t,e)=>{return new c((r=t.y,n=e,i=Math.PI-2*Math.PI*r/d/Math.pow(2,n),180/Math.PI*Math.atan(.5*(Math.exp(i)-Math.exp(-i)))),function(t,e){return t/d/Math.pow(2,e)*360-180}(t.x,e));var r,n,i};function R(t){const{gl:e,vSrc:r,fSrc:n}=t,i=e.createShader(e.VERTEX_SHADER);e.shaderSource(i,r),e.compileShader(i);const o=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(o,n),e.compileShader(o);const s=e.createProgram();return e.attachShader(s,i),e.attachShader(s,o),e.linkProgram(s),s}class A{constructor(t){this.gl=t,this.program=R({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;\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\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;\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n\t \tgl_FragColor = vec4(textureColor.b, textureColor.a, 0, 1.0);\n // DSM noData values should not be included in heightMap because they produce ugly borders\n if (gl_FragColor.xy == vec2(0.0)) {\n discard;\n }\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:i,width:o,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 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,o,s,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,a);const g=o,p=s;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),i>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.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,R=f*d,A=new n(y,R);l.uniform3f(this.xyzUniformLocation,y,R,m),l.uniform2f(this.dimensionsUniformLocation,o,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:n,centroid:i,highlight:u}=t,h=v({lng:i[0],lat:i[1]},m).subtract(A).floor();if(h.x<0||h.y<0||h.x>o||h.y>s)return;const c=256*a[h.y*o*2+2*h.x]+a[h.y*o*2+2*h.x+1]+5*e,f=Math.floor(c/256)/256,d=Math.floor(c%256)/256;_=Math.max(_,c/5),l.uniform4f(this.colorUniformLocation,f,d,u?1:0,1),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,n,l.DYNAMIC_DRAW),l.drawElements(l.TRIANGLES,n.length,n.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);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.drawArrays(l.TRIANGLE_STRIP,0,4),l.deleteTexture(t)}return l.deleteFramebuffer(E),_}}function b(t,e,r){r=r||2;var n,i,o,s,a,u,h,l=e&&e.length,c=l?e[0]*r:t.length,f=M(t,0,c,r,!0),d=[];if(!f||f.next===f.prev)return d;if(l&&(f=function(t,e,r,n){var i,o,s,a=[];for(i=0,o=e.length;i<o;i++)(s=M(t,e[i]*n,i<o-1?e[i+1]*n:t.length,n,!1))===s.next&&(s.steiner=!0),a.push(B(s));for(a.sort(I),i=0;i<a.length;i++)r=C(a[i],r);return r}(t,e,f,r)),t.length>80*r){n=o=t[0],i=s=t[1];for(var m=r;m<c;m+=r)(a=t[m])<n&&(n=a),(u=t[m+1])<i&&(i=u),a>o&&(o=a),u>s&&(s=u);h=0!==(h=Math.max(o-n,s-i))?32767/h:0}return L(f,d,r,n,i,h,0),d}function M(t,e,r,n,i){var o,s;if(i===V(t,e,r,n)>0)for(o=e;o<r;o+=n)s=K(o,t[o],t[o+1],s);else for(o=r-n;o>=e;o-=n)s=K(o,t[o],t[o+1],s);return s&&G(s,s.next)&&(q(s),s=s.next),s}function w(t,e){if(!t)return t;e||(e=t);var r,n=t;do{if(r=!1,n.steiner||!G(n,n.next)&&0!==z(n.prev,n,n.next))n=n.next;else{if(q(n),(n=e=n.prev)===n.next)break;r=!0}}while(r||n!==e);return e}function L(t,e,r,n,i,o,s){if(t){!s&&o&&function(t,e,r,n){var i=t;do{0===i.z&&(i.z=N(i.x,i.y,e,r,n)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next}while(i!==t);i.prevZ.nextZ=null,i.prevZ=null,function(t){var e,r,n,i,o,s,a,u,h=1;do{for(r=t,t=null,o=null,s=0;r;){for(s++,n=r,a=0,e=0;e<h&&(a++,n=n.nextZ);e++);for(u=h;a>0||u>0&&n;)0!==a&&(0===u||!n||r.z<=n.z)?(i=r,r=r.nextZ,a--):(i=n,n=n.nextZ,u--),o?o.nextZ=i:t=i,i.prevZ=o,o=i;r=n}o.nextZ=null,h*=2}while(s>1)}(i)}(t,n,i,o);for(var a,u,h=t;t.prev!==t.next;)if(a=t.prev,u=t.next,o?S(t,n,i,o):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?L(t=D(w(t),e,r),e,r,n,i,o,2):2===s&&P(t,e,r,n,i,o):L(w(t),e,r,n,i,o,1);break}}}function U(t){var e=t.prev,r=t,n=t.next;if(z(e,r,n)>=0)return!1;for(var i=e.x,o=r.x,s=n.x,a=e.y,u=r.y,h=n.y,l=i<o?i<s?i:s:o<s?o:s,c=a<u?a<h?a:h:u<h?u:h,f=i>o?i>s?i:s:o>s?o:s,d=a>u?a>h?a:h:u>h?u:h,m=n.next;m!==e;){if(m.x>=l&&m.x<=f&&m.y>=c&&m.y<=d&&X(i,a,o,u,s,h,m.x,m.y)&&z(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function S(t,e,r,n){var i=t.prev,o=t,s=t.next;if(z(i,o,s)>=0)return!1;for(var a=i.x,u=o.x,h=s.x,l=i.y,c=o.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,x=l>c?l>f?l:f:c>f?c:f,g=N(d,m,e,r,n),p=N(_,x,e,r,n),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!==i&&E!==s&&X(a,l,u,c,h,f,E.x,E.y)&&z(E.prev,E,E.next)>=0)return!1;if(E=E.prevZ,T.x>=d&&T.x<=_&&T.y>=m&&T.y<=x&&T!==i&&T!==s&&X(a,l,u,c,h,f,T.x,T.y)&&z(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!==i&&E!==s&&X(a,l,u,c,h,f,E.x,E.y)&&z(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!==i&&T!==s&&X(a,l,u,c,h,f,T.x,T.y)&&z(T.prev,T,T.next)>=0)return!1;T=T.nextZ}return!0}function D(t,e,r){var n=t;do{var i=n.prev,o=n.next.next;!G(i,o)&&H(i,n,n.next,o)&&Z(i,o)&&Z(o,i)&&(e.push(i.i/r|0),e.push(n.i/r|0),e.push(o.i/r|0),q(n),q(n.next),n=t=o),n=n.next}while(n!==t);return w(n)}function P(t,e,r,n,i,o){var s=t;do{for(var a=s.next.next;a!==s.prev;){if(s.i!==a.i&&O(s,a)){var u=Y(s,a);return s=w(s,s.next),u=w(u,u.next),L(s,e,r,n,i,o,0),void L(u,e,r,n,i,o,0)}a=a.next}s=s.next}while(s!==t)}function I(t,e){return t.x-e.x}function C(t,e){var r=function(t,e){var r,n=e,i=t.x,o=t.y,s=-1/0;do{if(o<=n.y&&o>=n.next.y&&n.next.y!==n.y){var a=n.x+(o-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(a<=i&&a>s&&(s=a,r=n.x<n.next.x?n:n.next,a===i))return r}n=n.next}while(n!==e);if(!r)return null;var u,h=r,l=r.x,c=r.y,f=1/0;n=r;do{i>=n.x&&n.x>=l&&i!==n.x&&X(o<c?i:s,o,l,c,o<c?s:i,o,n.x,n.y)&&(u=Math.abs(o-n.y)/(i-n.x),Z(n,t)&&(u<f||u===f&&(n.x>r.x||n.x===r.x&&F(r,n)))&&(r=n,f=u)),n=n.next}while(n!==h);return r}(t,e);if(!r)return e;var n=Y(r,t);return w(n,n.next),w(r,r.next)}function F(t,e){return z(t.prev,t,e.prev)<0&&z(e.next,t,t.next)<0}function N(t,e,r,n,i){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*i|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-n)*i|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 X(t,e,r,n,i,o,s,a){return(i-s)*(e-a)>=(t-s)*(o-a)&&(t-s)*(n-a)>=(r-s)*(e-a)&&(r-s)*(o-a)>=(i-s)*(n-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&&H(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,n=!1,i=(t.x+e.x)/2,o=(t.y+e.y)/2;do{r.y>o!=r.next.y>o&&r.next.y!==r.y&&i<(r.next.x-r.x)*(o-r.y)/(r.next.y-r.y)+r.x&&(n=!n),r=r.next}while(r!==t);return n}(t,e)&&(z(t.prev,t,e.prev)||z(t,e.prev,e))||G(t,e)&&z(t.prev,t,t.next)>0&&z(e.prev,e,e.next)>0)}function z(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function G(t,e){return t.x===e.x&&t.y===e.y}function H(t,e,r,n){var i=j(z(t,e,r)),o=j(z(t,e,n)),s=j(z(r,n,t)),a=j(z(r,n,e));return i!==o&&s!==a||(!(0!==i||!W(t,r,e))||(!(0!==o||!W(t,n,e))||(!(0!==s||!W(r,t,n))||!(0!==a||!W(r,e,n)))))}function W(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 j(t){return t>0?1:t<0?-1:0}function Z(t,e){return z(t.prev,t,t.next)<0?z(t,e,t.next)>=0&&z(t,t.prev,e)>=0:z(t,e,t.prev)<0||z(t,t.next,e)<0}function Y(t,e){var r=new k(t.i,t.x,t.y),n=new k(e.i,e.x,e.y),i=t.next,o=e.prev;return t.next=e,e.prev=t,r.next=i,i.prev=r,n.next=r,r.prev=n,o.next=n,n.prev=o,n}function K(t,e,r,n){var i=new k(t,e,r);return n?(i.next=n.next,i.prev=n,n.next.prev=i,n.next=i):(i.prev=i,i.next=i),i}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 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 V(t,e,r,n){for(var i=0,o=e,s=r-n;o<r;o+=n)i+=(t[s]-t[o])*(t[o+1]+t[s+1]),s=o;return i}function $(t){t.filter((t=>"MultiPolygon"===t.geometry.type)).forEach((e=>{const{geometry:r,properties:n,type:i}=e;if("MultiPolygon"===r.type)for(let n=0;n<r.coordinates.length;n++)t.push(Object.assign(Object.assign({},e),{geometry:Object.assign(Object.assign({},r),{type:"Polygon",coordinates:r.coordinates[n]})}))}));return t.filter((t=>"Polygon"===t.geometry.type)).map((t=>{const{geometry:e,properties:r}=t,{vertices:n}=b.flatten(e.coordinates),i=new Float32Array(n.map(((t,e)=>{if(e%2==1){const e=t*Math.PI/180;return Math.tan(e)+1/Math.cos(e)}return t}))),o=b(n),s=o.length>256?new Uint16Array(o):new Uint8Array(o),a=function(t){const{height:e=0,levels:r=0,render_height:n=0}=t;if(r)return 3.04*r;return Math.max(e,n)}(r),u=r.highlight||!1;let h=0,l=0,c=0;for(let t=0;t<n.length;t+=2)h+=n[t],l+=n[t+1],c++;return{aPosition:i,cuts:s,buildingHeight:a,centroid:[h/c,l/c],highlight:u}}))}b.deviation=function(t,e,r,n){var i=e&&e.length,o=i?e[0]*r:t.length,s=Math.abs(V(t,0,o,r));if(i)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(V(t,h,l,r))}var c=0;for(a=0;a<n.length;a+=3){var f=n[a]*r,d=n[a+1]*r,m=n[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)},b.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},n=0,i=0;i<t.length;i++){for(var o=0;o<t[i].length;o++)for(var s=0;s<e;s++)r.vertices.push(t[i][o][s]);i>0&&(n+=t[i-1].length,r.holes.push(n))}return r};let J,Q={width:0,height:0,imageData:new Uint8ClampedArray(0),visibleDEMPixelBounds:new s(new n(0,0),new n(0,0)),DEMPixelBounds:new s(new n(0,0),new n(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const tt=t=>T(void 0,void 0,void 0,(function*(){const{demZoom:e,getFeatures:r,terrainSource:i,dsmSource:o,tileLoaded:a,gl:h,bounds:l,buildingRasterizer:c,tileMerger:f,forceUpdate:m=!1}=t,{getSourceUrl:_,getElevation:x,maxZoom:g,tileSize:p,_overzoom:E}=i,y=(R={getFeatures:r},T(void 0,void 0,void 0,(function*(){const{getFeatures:t}=R;try{return $(yield t())}catch(t){console.log("Error merging buildings",t)}return[]})));var R;try{const t=l,r=t.getNorthWest(),i=t.getSouthEast(),E=new s(v(r,e),v(i,e));let T=new n(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:n}=t,i=e.divideBy(d).floor().multiplyBy(d),o=(Math.ceil(r/d)+1)*d,a=(Math.ceil(n/d)+1)*d,u=i.add([o,a]);return new s(i,u)})({upperLeft:T,width:R,height:A}),{x:w,y:L}=M.max.subtract(M.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 n=Math.pow(2,t.z);return{x:(t.x%n+n)%n,y:(t.y%n+n)%n,z:t.z,xOffset:(t.x-e)*d,yOffset:(t.y-r)*d}}))})((t=>{const{upperLeft:e,width:r,height:n,zoom:i}=t,o=e.divideBy(d).floor(),s=o.x+r/d,a=Math.min(o.y+n/d,Math.pow(2,i)-1),u=[];for(var h=o.x;h<s;h++)for(var l=o.y;l<a;l++)u.push({x:h,y:l,z:i});return u})({upperLeft:M.min,width:w,height:L,zoom:e})),S=E.max.x-E.min.x,D=E.max.y-E.min.y,P=S,I=D,C=JSON.stringify(U);if(!m&&C===J&&e<g)return Q=Object.assign(Object.assign({},Q),{outputWidth:P,outputHeight:I,visibleDEMPixelBounds:E,demZoom:e,dirty:!0}),Q;const F=yield f.merge(U,{maxZoom:g,width:w,height:L,crossOrigin:"Anonymous",getSourceUrl:_,getElevation:x,tileSize:p,tileLoaded:a});if(null===F)return Q=Object.assign(Object.assign({},Q),{visibleDEMPixelBounds:E,demZoom:e,dirty:!1}),Q;const N=new s(v(new u(o.bounds).getNorthWest(),e),v(new u(o.bounds).getSouthEast(),e)),B=N.min.subtract(M.min),X=N.max.subtract(M.min),O=[B.x/w,B.y/L,X.x/w,X.y/L].map((t=>2*t-1)),z=yield y,G=c.raster({upperLeftTile:U[0],width:w,height:L,mapZoom:e,features:z,imageData:F,gl:h,dsmSource:o,dsmCoords:O}),H=Math.max(Math.max(o.maxHeight,G),F.maxHeight);J=C,Q={maxHeight:H,width:w,height:L,imageData:F,DEMPixelBounds:M,visibleDEMPixelBounds:E,raster:U,demZoom:e,dirty:!0,outputWidth:P,outputHeight:I}}catch(t){console.error("Could not decode height map",t)}return Q})),et=t=>{const{tile:e,maxZoom:r,tileSize:n}=t;let{x:i,y:o,z:s}=e;if(s>r){const t=Math.pow(2,e.z-r);i=Math.floor(i/t),o=Math.floor(o/t),s=r}return{x:n===d?i:Math.floor(i/2),y:n===d?o:Math.floor(o/2),z:n===d?s:s-1}};class rt{constructor(){this.canvas=document.createElement("canvas"),this.canvas.width=d,this.canvas.height=d,this.ctx=this.canvas.getContext("2d",{antialias:!1,alpha:!1,willReadFrequently:!0}),null!==this.ctx&&(this.ctx.imageSmoothingEnabled=!1),this.inProgress=[],this.finished=0}merge(t,e){return T(this,void 0,void 0,(function*(){const{width:r,height:n,crossOrigin:i,getSourceUrl:o,getElevation:s,tileSize:a,tileLoaded:u,maxZoom:h}=e;if(this.ctx){const e=new Uint8ClampedArray(2*r*n);e.maxHeight=0,this.inProgress.forEach((t=>t.src="")),this.inProgress=[],this.finished=0;const l=new Set;t.forEach((t=>{l.add(o(et({tile:t,maxZoom:h,tileSize:a})))}));const c=Array.from(l).map((n=>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=>n===o(et({tile:t,maxZoom:h,tileSize:a})))).forEach((t=>{let n=0,i=0;const o=514===a?1:0;let u=0,l=d,f=d;if(a!==d&&(n=t.x%2*d,i=t.y%2*d,l=d,f=d),t.z>h){const e=Math.pow(2,t.z-h);a!==d&&(n=Math.floor(t.x/e)%2*d,i=Math.floor(t.y/e)%2*d),n+=d*(t.x%e/e),i+=d*(t.y%e/e),l=d/e,f=d/e,u=514===a?1:0}this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.drawImage(c,o+n,o+i,l+u,f+u,0,0,l+u,f+u);const m=this.ctx.getImageData(0,0,l+u,f+u).data,_=new Uint8ClampedArray(131072);let x=new Array((l+u)*(f+u)),g=d/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 n=5*(r||0);x[t/4]=n}if(g>1&&514===a)for(x=function(t,e,r,n){const i=Math.floor(e*n),o=Math.floor(r*n),s=[];for(let a=0;a<o;a++)for(let o=0;o<i;o++){const i=o/n,u=a/n,h=Math.floor(i),l=Math.floor(u),c=Math.min(h+1,e-1),f=Math.min(l+1,r-1),d=i-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;s.push(p)}return function(t,e,r,n,i){if(n>=e||i>=r)return[];const o=e-n,s=r-i,a=[];for(let r=0;r<s;r++)for(let n=0;n<o;n++){const i=r*e+n;a.push(t[i])}return a}(s,Math.sqrt(s.length),Math.sqrt(s.length),n,n)}(x,l+1,f+1,g);g>1;)g/=2,f*=2,l*=2;for(let t=0;t<_.length;t+=2){const e=x[Math.floor(t/2/d/g)*l+Math.floor(t/2%d/g)],r=Math.floor(e/256),n=Math.floor(e%256);_[t]=r,_[t+1]=n}for(let n=0;n<d;n++)e.set(_.slice(n*d*2,(n+1)*d*2),2*(t.yOffset*r+n*r+t.xOffset))})),u(null)},c.onerror=t=>{if(c.src!==c.originalSource)return l("new tiles requested");u(null)},c.crossOrigin=i||null,c.src=n,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 nt=(t,e)=>{const{r:r,g:n,b:i}=t;return[r/255,n/255,i/255,e]},it=(t,e)=>{const{date:r}=e,{dec:n,Hi:i}=_(r);t.updateDate({dec:n,Hi:i})},ot=(t,e)=>T(void 0,void 0,void 0,(function*(){return yield t.updateDateRange(Object.assign({},e))})),st=(t,e)=>{const{color:r,opacity:n}=e,i=nt(r,n);t.updateColor({colorVec:i})};new u([0,0],[0,0]);const at=t=>{const{kernel:e,map:r,heightMap:n,now:i,color:o,opacity:s}=t;try{const{outputHeight:t,outputWidth:a,maxHeight:h,width:l,height:c,DEMPixelBounds:f,imageData:m,visibleDEMPixelBounds:x,demZoom:g}=n;if(0===l||0===c)return;const{min:p,max:E}=x;if(!p||!E)return;const{x:T,y:v}=E.subtract(p),R=f.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]),U=[L,w,b,M].map((t=>r.project(t,g))),S=U.map((t=>[(t.x-R.x)/l,(t.y-R.y)/c])).flat(),D=U.map((t=>[(t.x-p.x)/T,(t.y-p.y)/v])).map((t=>[2*t[0]-1,-1*(2*t[1]-1)])).flat(),P=R.y/d/Math.pow(2,g),I=c/d/Math.pow(2,g),C=new u(y(f.getTopLeft(),g),y(f.getBottomRight(),g)),F=C.getWest(),N=Math.abs(C.getWest()-C.getEast());((t,e)=>{const{color:r,opacity:n,date:i}=e,o=nt(r,n),{dec:s,Hi:a}=_(i);t.updateLocation(Object.assign({dec:s,Hi:a,colorVec:o,step:1},e))})(e,{imageData:m,maxHeight:h,width:l,height:c,heightMapZoom:g,cornerTextureCoords:S,cornerClipCoords:D,topYCoord:P,ySize:I,west:F,dLng:N,date:i,color:o,opacity:s,outputHeight:t,outputWidth: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:n}=t;return 256*e+r+n/256-32768}},dsmSource:{bounds:[{lat:0,lng:0},{lat:0,lng:0}],data:new Uint8ClampedArray,width:0,height:0,maxHeight:0},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,n=R({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 getElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*256.0*256.0+result.g*256.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 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_z=getElevationFromSampler2D(user_a,user_x,user_y);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_lit=1.0;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=getElevationFromSampler2D(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));if(result.z==1.0){shade_color=vec4(.92941,.4375,.078125,user_color.a*1.31);}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(n);const i=r.createBuffer(),o=r.getAttribLocation(n,"a_pos"),s=r.createBuffer(),a=r.getAttribLocation(n,"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(n,"user_a");r.uniform1i(h,0);const l=r.getUniformLocation(n,"user_width"),c=r.getUniformLocation(n,"user_height"),f=r.getUniformLocation(n,"user_maxHeight"),d=r.getUniformLocation(n,"user_zoom"),m=r.getUniformLocation(n,"user_topYCoord"),x=r.getUniformLocation(n,"user_ySize"),g=r.getUniformLocation(n,"user_step"),p=r.getUniformLocation(n,"user_west"),E=r.getUniformLocation(n,"user_dLng"),v=r.getUniformLocation(n,"user_dec"),y=r.getUniformLocation(n,"user_Hi"),A=r.getUniformLocation(n,"user_color"),b=r.getUniformLocation(n,"user_xStart"),M=r.getUniformLocation(n,"user_yStart"),w=r.getUniformLocation(n,"user_xEnd"),L=r.getUniformLocation(n,"user_yEnd"),U=r.getUniformLocation(n,"user_sunExposureTexture");r.uniform1i(U,2);const S=r.getUniformLocation(n,"user_renderToSunExposureTexture"),D=r.getUniformLocation(n,"user_outputSunExposure"),P=r.getUniformLocation(n,"user_exposureDelta"),I=r.getUniformLocation(n,"u_outputShadeProfile"),C=r.getUniformLocation(n,"u_gpxTexture"),F=r.getUniformLocation(n,"u_decHiTexture"),N=r.getUniformLocation(n,"u_sunColor"),B=r.getUniformLocation(n,"u_outputLocationShadeProfile"),X=r.getUniformLocation(n,"u_shadeProfileLocation"),O=()=>{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:b,step:M,west:w,dLng:L,dec:U,Hi:S,cornerClipCoords:D,cornerTextureCoords:P,outputWidth:I,outputHeight:C}=t;r.useProgram(n),r.canvas.width=I,r.canvas.height=C,r.viewport(0,0,I,C),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindBuffer(r.ARRAY_BUFFER,i),r.bufferData(r.ARRAY_BUFFER,new Float32Array(D),r.STATIC_DRAW),r.enableVertexAttribArray(o),r.vertexAttribPointer(o,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(x,R),r.uniform4fv(A,b),r.uniform1f(g,M),r.uniform1f(p,w),r.uniform1f(E,L),r.uniform1f(v,U),r.uniform1f(y,S),window.requestAnimationFrame(O)},updateViewport:function(t){const{xStart:e,yStart:n,xEnd:i,yEnd:o}=t;r.uniform1f(b,e),r.uniform1f(M,n),r.uniform1f(w,i),r.uniform1f(L,o),window.requestAnimationFrame(O)},updateDate:t=>{const{dec:e,Hi:n}=t;r.uniform1f(v,e),r.uniform1f(y,n),window.requestAnimationFrame(O)},updateDateRange:t=>T(this,void 0,void 0,(function*(){const{startDate:e,endDate:n,iterations:i,emit:o}=t,s=z=Date.now();r.uniform4fv(P,new Float32Array([1/i,0,0,0]));const a=Math.floor((n.getTime()-e.getTime())/i),u=r.canvas.width,h=r.canvas.height,l=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,l),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,u,h,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 c=r.createTexture();r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,c),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,u,h,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),r.uniform1i(S,1);const f=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,f);const d=r.COLOR_ATTACHMENT0;r.viewport(0,0,u,h);for(let t=0;t<i;t++){if(o("tileloaded",t,i-1),s!==z)return!0;yield new Promise(((n,i)=>{window.requestAnimationFrame((()=>{t%2==0?(r.uniform1i(U,2),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,l),r.framebufferTexture2D(r.FRAMEBUFFER,d,r.TEXTURE_2D,l,0)):(r.uniform1i(U,1),r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,c),r.framebufferTexture2D(r.FRAMEBUFFER,d,r.TEXTURE_2D,c,0));const{dec:i,Hi:o}=_(new Date(e.getTime()+a*t));r.uniform1f(v,i),r.uniform1f(y,o),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4),n()}))}))}return yield new Promise(((t,e)=>{window.requestAnimationFrame((()=>{s!==z&&t(!0),r.bindFramebuffer(r.FRAMEBUFFER,null),r.uniform1i(U,i%2==0?2:1),r.uniform1i(D,1),O(),r.uniform1i(S,0),r.uniform1i(D,0),r.deleteFramebuffer(f),r.deleteTexture(l),r.deleteTexture(c),t(!1)}))}))})),updateColor:t=>{const{colorVec:e}=t;r.uniform4fv(A,e),window.requestAnimationFrame(O)},generateShadeProfile:t=>{if(null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");const{dates:e,texCoords:s,shadeColor:a,sunColor:h}=t,l=s.length,c=e.length,f=r.getParameter(r.VIEWPORT),d=r.getUniform(n,A);r.uniform4fv(A,a),r.uniform4fv(N,h),r.uniform1i(I,1);const m=r.createTexture();r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,m);const x=s.map((t=>[t[0],t[1],0,0])).flat();r.texImage2D(r.TEXTURE_2D,0,r.RGBA,x.length/4,1,0,r.RGBA,r.FLOAT,new Float32Array(x)),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.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.uniform1i(C,2);const g=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,g);const p=e.map((t=>{const{dec:e,Hi:r}=_(t);return[-e,r/10,0,0]})).flat();r.texImage2D(r.TEXTURE_2D,0,r.RGBA,1,e.length,0,r.RGBA,r.FLOAT,new Float32Array(p)),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.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.uniform1i(F,1),r.viewport(0,0,l,c),r.clear(r.COLOR_BUFFER_BIT),r.bindBuffer(r.ARRAY_BUFFER,u),r.enableVertexAttribArray(o),r.vertexAttribPointer(o,2,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.bindBuffer(r.ARRAY_BUFFER,i),r.vertexAttribPointer(o,2,r.FLOAT,!1,0,0);const E=new Uint8Array(l*c*4);return r.readPixels(0,0,l,c,r.RGBA,r.UNSIGNED_BYTE,E),r.deleteTexture(g),r.deleteTexture(m),r.uniform1i(F,0),r.uniform1i(C,0),r.uniform1i(I,0),r.viewport(f[0],f[1],f[2],f[3]),r.uniform4fv(A,d),r.uniform4fv(N,[0,0,0,0]),E},generateLocationShadeProfile:t=>{if(null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");const{dates:e,texCoord:s,shadeColor:a,sunColor:h}=t,l=e[0].length,c=e.length,f=r.getParameter(r.VIEWPORT),d=r.getUniform(n,A);r.uniform4fv(A,a),r.uniform4fv(N,h),r.uniform1i(B,1),r.uniform2fv(X,[s[0],s[1]]);const m=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,m);const x=e.flat().map((t=>{const{dec:e,Hi:r}=_(t);return[-e,r/10,0,0]})).flat();r.texImage2D(r.TEXTURE_2D,0,r.RGBA,l,c,0,r.RGBA,r.FLOAT,new Float32Array(x)),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.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.uniform1i(F,1),r.viewport(0,0,l,c),r.clear(r.COLOR_BUFFER_BIT),r.bindBuffer(r.ARRAY_BUFFER,u),r.enableVertexAttribArray(o),r.vertexAttribPointer(o,2,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.bindBuffer(r.ARRAY_BUFFER,i),r.vertexAttribPointer(o,2,r.FLOAT,!1,0,0);const g=new Uint8Array(l*c*4);return r.readPixels(0,0,l,c,r.RGBA,r.UNSIGNED_BYTE,g),r.deleteTexture(m),r.uniform1i(F,0),r.uniform1i(B,0),r.viewport(f[0],f[1],f[2],f[3]),r.uniform4fv(A,d),r.uniform4fv(N,[0,0,0,0]),g}}}({context:this._gl}),this._color=this._parseColor(this.options.color),this._buildingRasterizer=new A(this._gl),this._tileMerger=new rt,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=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&&(st(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&&(st(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),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._map&&this._compiledKernel){if(!1===t)this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:t}),it(this._compiledKernel,{date:this.options.date});else{const{startDate:r,endDate:n,iterations:i=32}=e;if(this.options.sunExposure={enabled:t,startDate:r,endDate:n,iterations:i},!(r instanceof Date&&n instanceof Date))throw new Error("Start date or end date or both are missing");if(n.getTime()<r.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield ot(this._compiledKernel,{startDate:r,endDate:n,iterations:i,emit:this.emit.bind(this)})))return this}this._flush()}return this}))}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:n,height:i}=this._heightMap,o=e.min;return t.map((t=>{const e=v(t,r);return[(e.x-o.x)/n,(e.y-o.y)/i]}))}return[]}_getBounds(t,e){const{width:r,height:i}=this.options.getSize();if(Number.isNaN(r)||Number.isNaN(i))return t.getBounds();const o=t.getCenter(),s=v(o,e),a=y(new n(s.x-r/2,s.y-i/2),e),u=y(new n(s.x+r/2,s.y+i/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(),i=r.reduce(((t,e)=>Math.max(t,e.canonical.z)),Number.MIN_SAFE_INTEGER),o=r.filter((t=>t.canonical.z===i)).map((t=>t.canonical)),[s,a,u,h]=o.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=y(new n(512*s,512*a),i+1),c=y(new n(512*(u+1),512*(h+1)),i+1);e=i+1,this._bounds=t.createBounds({nw:l,se:c})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield tt({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(at({kernel:this._compiledKernel,map:E(this._map),heightMap:t,color:this._color,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,n)=>{const i=new Uint8Array(r*n*4);this._gl.readPixels(t,e,r,n,this._gl.RGBA,this._gl.UNSIGNED_BYTE,i);const o=r*n*1,s=1*r,a=(n-1)*s,u=new Uint8Array(o),h=new Uint8Array(o);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<i.length;t+=4){let e;if(this.options.sunExposure.enabled){const r=i.subarray(t,t+3),n=g(r,.5,l)/1e3/60,o=Math.min(Math.floor(n/6),255);e=new Uint8Array([o])}else{e=i[t]+i[t+1]+i[t+2]===0?new Uint8Array([255]):new Uint8Array([0])}u.set(e,t/4*1)}for(let t=0;t<o;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,n=t(0,0,e,r),i=E(this._map),{lat:o,lng:s}=i.getBounds().getNorthWest(),a=i.getBounds().getSouthEast(),u=[0,0,0,s,o,0],h=[(a.lng-s)/e,(o-a.lat)/r,0];return this.options.sunExposure.enabled,{data:n,metadata:{width:e,height:r,ModelTiepoint:u,ModelPixelScale:h,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}return null}_generateShadeProfile(t){if(this._compiledKernel){const e=this._canvas.width,r=this._canvas.height;this._canvas.width=t.locations.length,this._canvas.height=t.dates.length;const n=this._lngLatToTextureCoords(t.locations),i=((t,e)=>{const r=nt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),n=nt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:n}))})(this._compiledKernel,Object.assign(Object.assign({},t),{texCoords:n}));return this._canvas.width=e,this._canvas.height=r,i}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=this._canvas.width,r=this._canvas.height,n=p(t.startDate)-p(t.startDate,t.tzId),i=t.startDate.getTime()-n,o=(t.endDate.getTime()-n-i)/86400/1e3,s=1440;this._canvas.width=o,this._canvas.height=s;const a=[],u=828e5,h=p(new Date(i),t.tzId);for(let e=0;e<o;e++){const r=p(new Date(i+86400*e*1e3+u),t.tzId)-h;a[e]=r}const l=[];for(let t=0;t<s;t++){const e=[];for(let r=0;r<o;r++){const n=i+86400*r*1e3+60*t*1e3;e.push(new Date(n+a[r]))}l.push(e)}const c=this._lngLatToTextureCoords([t.location])[0],f=((t,e)=>{const r=nt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),n=nt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateLocationShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:n}))})(this._compiledKernel,Object.assign(Object.assign({},t),{dates:l,texCoord:c}));return this._canvas.width=e,this._canvas.height=r,f.toArray=function(){const e=new Array;for(let r=0;r<o;r++){const n=[];for(let e=s-1;e>=0;e--){const i=e*o*4+4*r,s=this.slice(i,i+4);n.push(s.join("")===t.sunColor.join("")?1:0)}e.push(n)}return e},{data:f,width:o,height:s}}return{data:new Uint8Array,width:0,height:0}}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this.readPixel(t,e),{startDate:n,endDate:i}=this.options.sunExposure,o=i.getTime()-n.getTime(),s=g(r,.5,o);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+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,document.body.appendChild(this._canvas),this._canvas.style.display="none";const e=t.getBounds(),r=e.getNorthWest(),n=e.getNorthEast(),i=e.getSouthEast(),o=e.getSouthWest(),s=[[r.lng,r.lat],[n.lng,n.lat],[i.lng,i.lat],[o.lng,o.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 n(-1,-1);const{visibleDEMPixelBounds:i,demZoom:o}=this._heightMap,s=E(this._map).project(r,o).subtract(i.min);return s.y=i.max.y-i.min.y-s.y,s}return new n(-1,-1)}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this._getHeightMapCoords(t,e),n=this.readPixel(r.x,r.y),{startDate:i,endDate:o}=this.options.sunExposure,s=o.getTime()-i.getTime(),a=g(n,.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(),n=t.getNorthEast(),i=t.getSouthEast(),o=t.getSouthWest(),s=[[r.lng,r.lat],[n.lng,n.lat],[i.lng,i.lat],[o.lng,o.lat]];window.requestAnimationFrame((()=>{e.texture.update(this._canvas,{premultiply:!0}),e.setCoordinates(s),this.emit("idle")}))}}return this}}}));
|
package/examples/maplibre.html
CHANGED
|
@@ -99,10 +99,6 @@
|
|
|
99
99
|
let now = new Date((SunCalc.getTimes(new Date(), 47.694878957368815, -122.18578164139899).sunrise).getTime() + 60 * 60 * 1000);
|
|
100
100
|
let shadeMap;
|
|
101
101
|
map.on('load', () => {
|
|
102
|
-
map.addSource('composite', {
|
|
103
|
-
type: 'vector',
|
|
104
|
-
tiles: []
|
|
105
|
-
})
|
|
106
102
|
shadeMap = new ShadeMap({
|
|
107
103
|
apiKey: "eyJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InRwcGlvdHJvd3NraUBzaGFkZW1hcC5hcHAiLCJjcmVhdGVkIjoxNjYyNDkzMDY2Nzk0LCJpYXQiOjE2NjI0OTMwNjZ9.ovCrLTYsdKFTF6TW3DuODxCaAtGQ3qhcmqj3DWcol5g",
|
|
108
104
|
date: now,
|
|
@@ -150,6 +146,40 @@
|
|
|
150
146
|
loaderEl.innerText = `Loading: ${(loadedTiles / totalTiles * 100).toFixed(0)}%`;
|
|
151
147
|
});
|
|
152
148
|
});
|
|
149
|
+
|
|
150
|
+
async function addExtrusion() {
|
|
151
|
+
try {
|
|
152
|
+
if (map.getZoom() > 15) {
|
|
153
|
+
const bounds = map.getBounds();
|
|
154
|
+
const north = bounds.getNorth();
|
|
155
|
+
const south = bounds.getSouth();
|
|
156
|
+
const east = bounds.getEast();
|
|
157
|
+
const west = bounds.getWest();
|
|
158
|
+
const query = `https://overpass-api.de/api/interpreter?data=%2F*%0AThis%20has%20been%20generated%20by%20the%20overpass-turbo%20wizard.%0AThe%20original%20search%20was%3A%0A%E2%80%9Cbuilding%E2%80%9D%0A*%2F%0A%5Bout%3Ajson%5D%5Btimeout%3A25%5D%3B%0A%2F%2F%20gather%20results%0A%28%0A%20%20%2F%2F%20query%20part%20for%3A%20%E2%80%9Cbuilding%E2%80%9D%0A%20%20way%5B%22building%22%5D%28${south}%2C${west}%2C${north}%2C${east}%29%3B%0A%29%3B%0A%2F%2F%20print%20results%0Aout%20body%3B%0A%3E%3B%0Aout%20skel%20qt%3B`;
|
|
159
|
+
const response = await fetch(query)
|
|
160
|
+
const json = await response.json();
|
|
161
|
+
const geojson = osmtogeojson(json);
|
|
162
|
+
// If no building height, default to one storey of 3 meters
|
|
163
|
+
geojson.features.forEach(feature => {
|
|
164
|
+
if (!feature.properties) {
|
|
165
|
+
feature.properties = {};
|
|
166
|
+
}
|
|
167
|
+
if (!feature.properties.height) {
|
|
168
|
+
feature.properties.height = 3;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
map.addSource('buildings3d', {
|
|
172
|
+
type: 'geojson',
|
|
173
|
+
data: geojson
|
|
174
|
+
});
|
|
175
|
+
map.addLayer('')
|
|
176
|
+
}
|
|
177
|
+
} catch (e) {
|
|
178
|
+
console.error(e);
|
|
179
|
+
}
|
|
180
|
+
return [];
|
|
181
|
+
|
|
182
|
+
}
|
|
153
183
|
/* End ShadeMap setup */
|
|
154
184
|
|
|
155
185
|
/* Controls setup */
|
|
@@ -221,4 +251,4 @@
|
|
|
221
251
|
</script>
|
|
222
252
|
</body>
|
|
223
253
|
|
|
224
|
-
</html>
|
|
254
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mapbox-gl-shadow-simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.1",
|
|
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",
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { LatLngLiteral, Map as LeafletMap } from "leaflet";
|
|
2
|
-
import { Map, MapboxGeoJSONFeature } from "mapbox-gl";
|
|
3
|
-
import { BuildingRasterizer } from "./buildings/BuildingRasterizer";
|
|
4
|
-
import { EventEmitter } from "./lib/EventEmitter";
|
|
5
|
-
import { HeightMap } from "./lib/heightMap";
|
|
6
|
-
import { TileMerger } from "./lib/TileMerger";
|
|
7
|
-
import { LatLngBounds } from "./map/geometryLeaflet";
|
|
8
|
-
import { UMap } from "./map/umap";
|
|
9
|
-
import { CompiledKernel } from "./shader/kernel";
|
|
10
|
-
import { Color } from "./types/color";
|
|
11
|
-
import { DSMSource, SunExposureOptions, TerrainSource } from "./types/shadeMapOptions";
|
|
12
|
-
export declare class ShadeMap extends EventEmitter {
|
|
13
|
-
_canvas: HTMLCanvasElement;
|
|
14
|
-
_gl: WebGLRenderingContext;
|
|
15
|
-
_map?: Map | LeafletMap;
|
|
16
|
-
_compiledKernel?: CompiledKernel;
|
|
17
|
-
_color: Color;
|
|
18
|
-
_bounds?: LatLngBounds;
|
|
19
|
-
_buildingRasterizer: BuildingRasterizer;
|
|
20
|
-
_tileMerger: TileMerger;
|
|
21
|
-
_heightMap?: HeightMap;
|
|
22
|
-
options: {
|
|
23
|
-
date: Date;
|
|
24
|
-
color: string;
|
|
25
|
-
opacity: number;
|
|
26
|
-
sunExposure: {
|
|
27
|
-
enabled: boolean;
|
|
28
|
-
startDate: Date;
|
|
29
|
-
endDate: Date;
|
|
30
|
-
iterations: number;
|
|
31
|
-
};
|
|
32
|
-
apiKey: string;
|
|
33
|
-
terrainSource: {
|
|
34
|
-
maxZoom: number;
|
|
35
|
-
tileSize: number;
|
|
36
|
-
_overzoom: number;
|
|
37
|
-
getSourceUrl: (params: {
|
|
38
|
-
x: number;
|
|
39
|
-
y: number;
|
|
40
|
-
z: number;
|
|
41
|
-
}) => string;
|
|
42
|
-
getElevation: (params: {
|
|
43
|
-
r: number;
|
|
44
|
-
g: number;
|
|
45
|
-
b: number;
|
|
46
|
-
a: number;
|
|
47
|
-
}) => number;
|
|
48
|
-
};
|
|
49
|
-
dsmSource: {
|
|
50
|
-
bounds: {
|
|
51
|
-
lat: number;
|
|
52
|
-
lng: number;
|
|
53
|
-
}[];
|
|
54
|
-
data: Uint8ClampedArray;
|
|
55
|
-
width: number;
|
|
56
|
-
height: number;
|
|
57
|
-
maxHeight: number;
|
|
58
|
-
};
|
|
59
|
-
getFeatures: () => Promise<MapboxGeoJSONFeature[]>;
|
|
60
|
-
getSize: () => {
|
|
61
|
-
width: number;
|
|
62
|
-
height: number;
|
|
63
|
-
};
|
|
64
|
-
debug: (msg: string) => void;
|
|
65
|
-
};
|
|
66
|
-
constructor(...args: any[]);
|
|
67
|
-
onRemove(): this;
|
|
68
|
-
setDate(date: Date): this;
|
|
69
|
-
_setDateForTimezone(date: Date, tzId?: string): void;
|
|
70
|
-
setColor(color: string): this;
|
|
71
|
-
setOpacity(opacity: number): this;
|
|
72
|
-
setTerrainSource(terrainSource: TerrainSource): this;
|
|
73
|
-
setDSMSource(dsmSource: DSMSource): this;
|
|
74
|
-
setSunExposure(enabled?: boolean, options?: SunExposureOptions): Promise<this>;
|
|
75
|
-
_lngLatToTextureCoords(lngLat: LatLngLiteral[]): number[][];
|
|
76
|
-
_getBounds(map: UMap, demZoom: number): any;
|
|
77
|
-
_getDEMZoom(map: UMap): number;
|
|
78
|
-
_reset(): Promise<this>;
|
|
79
|
-
_draw(heightMap: HeightMap): Promise<this>;
|
|
80
|
-
readPixel(x: number, y: number): Uint8Array;
|
|
81
|
-
toGeoTiff(): {
|
|
82
|
-
data: Uint8Array;
|
|
83
|
-
metadata: {
|
|
84
|
-
width: number;
|
|
85
|
-
height: number;
|
|
86
|
-
ModelTiepoint: any[];
|
|
87
|
-
ModelPixelScale: number[];
|
|
88
|
-
GeographicTypeGeoKey: number;
|
|
89
|
-
GeogCitationGeoKey: string;
|
|
90
|
-
};
|
|
91
|
-
} | null;
|
|
92
|
-
_generateShadeProfile(params: {
|
|
93
|
-
locations: LatLngLiteral[];
|
|
94
|
-
dates: Date[];
|
|
95
|
-
sunColor: number[];
|
|
96
|
-
shadeColor: number[];
|
|
97
|
-
}): Uint8Array;
|
|
98
|
-
_generateLocationShadeProfile(params: {
|
|
99
|
-
location: LatLngLiteral;
|
|
100
|
-
startDate: Date;
|
|
101
|
-
endDate: Date;
|
|
102
|
-
sunColor: number[];
|
|
103
|
-
shadeColor: number[];
|
|
104
|
-
tzId: string;
|
|
105
|
-
}): {
|
|
106
|
-
data: Uint8Array;
|
|
107
|
-
width: number;
|
|
108
|
-
height: number;
|
|
109
|
-
};
|
|
110
|
-
getHoursOfSun(x: number, y: number): number;
|
|
111
|
-
_repositionCanvas(bounds: LatLngBounds): void;
|
|
112
|
-
_flush(): void;
|
|
113
|
-
flushSync(): void;
|
|
114
|
-
_parseColor(color: string): {
|
|
115
|
-
r: number;
|
|
116
|
-
g: number;
|
|
117
|
-
b: number;
|
|
118
|
-
};
|
|
119
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Map } from "leaflet";
|
|
2
|
-
import { CanvasOverlay } from "./components/CanvasOverlay";
|
|
3
|
-
import { LatLngBounds } from "./map/geometryLeaflet";
|
|
4
|
-
import { ShadeMap } from "./ShadeMap";
|
|
5
|
-
import { ShadeMapOptions } from "./types/shadeMapOptions";
|
|
6
|
-
declare class ShadeMapLeaflet extends ShadeMap {
|
|
7
|
-
_canvasOverlay?: CanvasOverlay;
|
|
8
|
-
constructor(options: ShadeMapOptions);
|
|
9
|
-
addTo(map: Map): this;
|
|
10
|
-
onAdd(map: Map): this;
|
|
11
|
-
_repositionCanvas(bounds: LatLngBounds): void;
|
|
12
|
-
_flush(): void;
|
|
13
|
-
}
|
|
14
|
-
export default ShadeMapLeaflet;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Map } from "mapbox-gl";
|
|
2
|
-
import { LatLngBounds } from "./map/geometryLeaflet";
|
|
3
|
-
import { ShadeMap } from "./ShadeMap";
|
|
4
|
-
import { ShadeMapOptions } from "./types/shadeMapOptions";
|
|
5
|
-
export default class extends ShadeMap {
|
|
6
|
-
id: string;
|
|
7
|
-
type: string;
|
|
8
|
-
canvasSourceId: string;
|
|
9
|
-
attributionSourceId: string;
|
|
10
|
-
canvasLayerId: string;
|
|
11
|
-
attributionLayerId: string;
|
|
12
|
-
_map?: Map;
|
|
13
|
-
_refreshing: number;
|
|
14
|
-
_raf: number;
|
|
15
|
-
_moveEndHandler: () => void;
|
|
16
|
-
constructor(options: ShadeMapOptions);
|
|
17
|
-
render(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
18
|
-
addTo(map: Map): this;
|
|
19
|
-
onAdd(map: Map): this;
|
|
20
|
-
onRemove(): this;
|
|
21
|
-
_getHeightMapCoords(x: number, y: number): any;
|
|
22
|
-
getHoursOfSun(x: number, y: number): number;
|
|
23
|
-
remove(): void;
|
|
24
|
-
_flush(): void;
|
|
25
|
-
_repositionCanvas(bounds: LatLngBounds): this;
|
|
26
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { XYZ } from "../lib/helpers";
|
|
2
|
-
import { DSMSource } from "../types/shadeMapOptions";
|
|
3
|
-
interface BuildingRasterGLArgs {
|
|
4
|
-
upperLeftTile: XYZ;
|
|
5
|
-
features: {
|
|
6
|
-
aPosition: Float32Array;
|
|
7
|
-
cuts: Uint16Array | Uint8Array;
|
|
8
|
-
buildingHeight: number;
|
|
9
|
-
centroid: number[];
|
|
10
|
-
highlight: boolean;
|
|
11
|
-
}[];
|
|
12
|
-
mapZoom: number;
|
|
13
|
-
imageData: Uint8ClampedArray;
|
|
14
|
-
width: number;
|
|
15
|
-
height: number;
|
|
16
|
-
dsmSource: DSMSource;
|
|
17
|
-
dsmCoords: number[];
|
|
18
|
-
gl: WebGLRenderingContext;
|
|
19
|
-
}
|
|
20
|
-
export declare class BuildingRasterizer {
|
|
21
|
-
gl: WebGLRenderingContext;
|
|
22
|
-
program: WebGLProgram;
|
|
23
|
-
positionAttributeLocation: number;
|
|
24
|
-
dsmAttributeLocation: number;
|
|
25
|
-
useDSMUniformLocation: WebGLUniformLocation;
|
|
26
|
-
xyzUniformLocation: WebGLUniformLocation;
|
|
27
|
-
dimensionsUniformLocation: WebGLUniformLocation;
|
|
28
|
-
heightMapUniformLocation: WebGLUniformLocation;
|
|
29
|
-
colorUniformLocation: WebGLUniformLocation;
|
|
30
|
-
positionBuffer: WebGLBuffer;
|
|
31
|
-
dsmBuffer: WebGLBuffer;
|
|
32
|
-
indexBuffer: WebGLBuffer;
|
|
33
|
-
targetTexture: WebGLTexture;
|
|
34
|
-
constructor(gl: WebGLRenderingContext);
|
|
35
|
-
raster(args: BuildingRasterGLArgs): number;
|
|
36
|
-
}
|
|
37
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { MapboxGeoJSONFeature } from "mapbox-gl";
|
|
2
|
-
interface FetchBuildingsArgs {
|
|
3
|
-
getFeatures: () => Promise<MapboxGeoJSONFeature[]>;
|
|
4
|
-
}
|
|
5
|
-
export declare const fetchBuildings: (args: FetchBuildingsArgs) => Promise<{
|
|
6
|
-
aPosition: Float32Array;
|
|
7
|
-
cuts: Uint8Array | Uint16Array;
|
|
8
|
-
buildingHeight: number;
|
|
9
|
-
centroid: number[];
|
|
10
|
-
highlight: any;
|
|
11
|
-
}[]>;
|
|
12
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ImageOverlay, ImageOverlayOptions, LatLngBounds, LatLngBoundsExpression } from "leaflet";
|
|
2
|
-
export declare class CanvasOverlay extends ImageOverlay {
|
|
3
|
-
_url: HTMLCanvasElement;
|
|
4
|
-
_image?: HTMLCanvasElement;
|
|
5
|
-
_zoomAnimated?: boolean;
|
|
6
|
-
_bounds?: LatLngBounds;
|
|
7
|
-
constructor(canvas: HTMLCanvasElement, bounds: LatLngBoundsExpression, options?: ImageOverlayOptions);
|
|
8
|
-
_initImage(): this;
|
|
9
|
-
setBounds(bounds: LatLngBounds): this;
|
|
10
|
-
}
|
|
11
|
-
export declare function canvasOverlay(...args: ConstructorParameters<typeof CanvasOverlay>): CanvasOverlay;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import "leaflet";
|
|
2
|
-
import ShadeMapLeaflet from "./ShadeMapLeaflet";
|
|
3
|
-
import { ShadeMapOptions } from "./types/shadeMapOptions";
|
|
4
|
-
declare module "leaflet" {
|
|
5
|
-
function shadeMap(options: ShadeMapOptions): ShadeMapLeaflet;
|
|
6
|
-
}
|
|
7
|
-
export { ShadeMapLeaflet as default, ShadeMapOptions };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare type Listener = (...args: any[]) => void;
|
|
2
|
-
export declare class EventEmitter {
|
|
3
|
-
private readonly events;
|
|
4
|
-
on(event: string, listener: Listener): () => void;
|
|
5
|
-
removeListener(event: string, listener: Listener): void;
|
|
6
|
-
removeAllListeners(): void;
|
|
7
|
-
emit(event: string, ...args: any[]): void;
|
|
8
|
-
once(event: string, listener: Listener): () => void;
|
|
9
|
-
}
|
|
10
|
-
export {};
|