leaflet-shadow-simulator 0.56.1 → 0.57.0

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.
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Copyright Ted Piotrowski 2024
3
3
  * Package: leaflet-shadow-simulator
4
- * Version: 0.56.1
4
+ * Version: 0.57.0
5
5
  * For licensing visit: https://shademap.app/about/
6
6
  */
7
7
 
8
- import{ImageOverlay as t,DomUtil as e,Util as r}from"leaflet";class i extends t{constructor(t,e,r={}){super("",e,r),this._url=t}_initImage(){const t="CANVAS"===this._url.tagName,i=this._image=t?this._url:e.create("canvas");return e.addClass(i,"leaflet-image-layer"),this._zoomAnimated&&e.addClass(i,"leaflet-zoom-animated"),this.options.className&&e.addClass(i,this.options.className),i.onselectstart=r.falseFn,i.onmousemove=r.falseFn,this}setBounds(t){return this._bounds=t,this._map&&this._reset(),this}}function n(t,e,r,i){return new(r||(r=Promise))((function(n,o){function a(t){try{u(i.next(t))}catch(t){o(t)}}function s(t){try{u(i.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((i=i.apply(t,e||[])).next())}))}function o(t,e,r){r=r||2;var i,n,o,s,h,l,c,f=e&&e.length,_=f?e[0]*r:t.length,x=a(t,0,_,r,!0),p=[];if(!x||x.next===x.prev)return p;if(f&&(x=function(t,e,r,i){var n,o,s,u=[];for(n=0,o=e.length;n<o;n++)(s=a(t,e[n]*i,n<o-1?e[n+1]*i:t.length,i,!1))===s.next&&(s.steiner=!0),u.push(g(s));for(u.sort(m),n=0;n<u.length;n++)r=d(u[n],r);return r}(t,e,x,r)),t.length>80*r){i=o=t[0],n=s=t[1];for(var E=r;E<_;E+=r)(h=t[E])<i&&(i=h),(l=t[E+1])<n&&(n=l),h>o&&(o=h),l>s&&(s=l);c=0!==(c=Math.max(o-i,s-n))?32767/c:0}return u(x,p,r,i,n,c,0),p}function a(t,e,r,i,n){var o,a;if(n===D(t,e,r,i)>0)for(o=e;o<r;o+=i)a=w(o,t[o],t[o+1],a);else for(o=r-i;o>=e;o-=i)a=w(o,t[o],t[o+1],a);return a&&v(a,a.next)&&(F(a),a=a.next),a}function s(t,e){if(!t)return t;e||(e=t);var r,i=t;do{if(r=!1,i.steiner||!v(i,i.next)&&0!==T(i.prev,i,i.next))i=i.next;else{if(F(i),(i=e=i.prev)===i.next)break;r=!0}}while(r||i!==e);return e}function u(t,e,r,i,n,o,a){if(t){!a&&o&&function(t,e,r,i){var n=t;do{0===n.z&&(n.z=x(n.x,n.y,e,r,i)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next}while(n!==t);n.prevZ.nextZ=null,n.prevZ=null,function(t){var e,r,i,n,o,a,s,u,h=1;do{for(r=t,t=null,o=null,a=0;r;){for(a++,i=r,s=0,e=0;e<h&&(s++,i=i.nextZ);e++);for(u=h;s>0||u>0&&i;)0!==s&&(0===u||!i||r.z<=i.z)?(n=r,r=r.nextZ,s--):(n=i,i=i.nextZ,u--),o?o.nextZ=n:t=n,n.prevZ=o,o=n;r=i}o.nextZ=null,h*=2}while(a>1)}(n)}(t,i,n,o);for(var m,d,_=t;t.prev!==t.next;)if(m=t.prev,d=t.next,o?l(t,i,n,o):h(t))e.push(m.i/r|0),e.push(t.i/r|0),e.push(d.i/r|0),F(t),t=d.next,_=d.next;else if((t=d)===_){a?1===a?u(t=c(s(t),e,r),e,r,i,n,o,2):2===a&&f(t,e,r,i,n,o):u(s(t),e,r,i,n,o,1);break}}}function h(t){var e=t.prev,r=t,i=t.next;if(T(e,r,i)>=0)return!1;for(var n=e.x,o=r.x,a=i.x,s=e.y,u=r.y,h=i.y,l=n<o?n<a?n:a:o<a?o:a,c=s<u?s<h?s:h:u<h?u:h,f=n>o?n>a?n:a:o>a?o:a,m=s>u?s>h?s:h:u>h?u:h,d=i.next;d!==e;){if(d.x>=l&&d.x<=f&&d.y>=c&&d.y<=m&&p(n,s,o,u,a,h,d.x,d.y)&&T(d.prev,d,d.next)>=0)return!1;d=d.next}return!0}function l(t,e,r,i){var n=t.prev,o=t,a=t.next;if(T(n,o,a)>=0)return!1;for(var s=n.x,u=o.x,h=a.x,l=n.y,c=o.y,f=a.y,m=s<u?s<h?s:h:u<h?u:h,d=l<c?l<f?l:f:c<f?c:f,_=s>u?s>h?s:h:u>h?u:h,g=l>c?l>f?l:f:c>f?c:f,E=x(m,d,e,r,i),v=x(_,g,e,r,i),y=t.prevZ,A=t.nextZ;y&&y.z>=E&&A&&A.z<=v;){if(y.x>=m&&y.x<=_&&y.y>=d&&y.y<=g&&y!==n&&y!==a&&p(s,l,u,c,h,f,y.x,y.y)&&T(y.prev,y,y.next)>=0)return!1;if(y=y.prevZ,A.x>=m&&A.x<=_&&A.y>=d&&A.y<=g&&A!==n&&A!==a&&p(s,l,u,c,h,f,A.x,A.y)&&T(A.prev,A,A.next)>=0)return!1;A=A.nextZ}for(;y&&y.z>=E;){if(y.x>=m&&y.x<=_&&y.y>=d&&y.y<=g&&y!==n&&y!==a&&p(s,l,u,c,h,f,y.x,y.y)&&T(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;A&&A.z<=v;){if(A.x>=m&&A.x<=_&&A.y>=d&&A.y<=g&&A!==n&&A!==a&&p(s,l,u,c,h,f,A.x,A.y)&&T(A.prev,A,A.next)>=0)return!1;A=A.nextZ}return!0}function c(t,e,r){var i=t;do{var n=i.prev,o=i.next.next;!v(n,o)&&y(n,i,i.next,o)&&b(n,o)&&b(o,n)&&(e.push(n.i/r|0),e.push(i.i/r|0),e.push(o.i/r|0),F(i),F(i.next),i=t=o),i=i.next}while(i!==t);return s(i)}function f(t,e,r,i,n,o){var a=t;do{for(var h=a.next.next;h!==a.prev;){if(a.i!==h.i&&E(a,h)){var l=M(a,h);return a=s(a,a.next),l=s(l,l.next),u(a,e,r,i,n,o,0),void u(l,e,r,i,n,o,0)}h=h.next}a=a.next}while(a!==t)}function m(t,e){return t.x-e.x}function d(t,e){var r=function(t,e){var r,i=e,n=t.x,o=t.y,a=-1/0;do{if(o<=i.y&&o>=i.next.y&&i.next.y!==i.y){var s=i.x+(o-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(s<=n&&s>a&&(a=s,r=i.x<i.next.x?i:i.next,s===n))return r}i=i.next}while(i!==e);if(!r)return null;var u,h=r,l=r.x,c=r.y,f=1/0;i=r;do{n>=i.x&&i.x>=l&&n!==i.x&&p(o<c?n:a,o,l,c,o<c?a:n,o,i.x,i.y)&&(u=Math.abs(o-i.y)/(n-i.x),b(i,t)&&(u<f||u===f&&(i.x>r.x||i.x===r.x&&_(r,i)))&&(r=i,f=u)),i=i.next}while(i!==h);return r}(t,e);if(!r)return e;var i=M(r,t);return s(i,i.next),s(r,r.next)}function _(t,e){return T(t.prev,t,e.prev)<0&&T(e.next,t,t.next)<0}function x(t,e,r,i,n){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*n|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*n|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function g(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 p(t,e,r,i,n,o,a,s){return(n-a)*(e-s)>=(t-a)*(o-s)&&(t-a)*(i-s)>=(r-a)*(e-s)&&(r-a)*(o-s)>=(n-a)*(i-s)}function E(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&&y(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(b(t,e)&&b(e,t)&&function(t,e){var r=t,i=!1,n=(t.x+e.x)/2,o=(t.y+e.y)/2;do{r.y>o!=r.next.y>o&&r.next.y!==r.y&&n<(r.next.x-r.x)*(o-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next}while(r!==t);return i}(t,e)&&(T(t.prev,t,e.prev)||T(t,e.prev,e))||v(t,e)&&T(t.prev,t,t.next)>0&&T(e.prev,e,e.next)>0)}function T(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function v(t,e){return t.x===e.x&&t.y===e.y}function y(t,e,r,i){var n=R(T(t,e,r)),o=R(T(t,e,i)),a=R(T(r,i,t)),s=R(T(r,i,e));return n!==o&&a!==s||(!(0!==n||!A(t,r,e))||(!(0!==o||!A(t,i,e))||(!(0!==a||!A(r,t,i))||!(0!==s||!A(r,e,i)))))}function A(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 R(t){return t>0?1:t<0?-1:0}function b(t,e){return T(t.prev,t,t.next)<0?T(t,e,t.next)>=0&&T(t,t.prev,e)>=0:T(t,e,t.prev)<0||T(t,t.next,e)<0}function M(t,e){var r=new U(t.i,t.x,t.y),i=new U(e.i,e.x,e.y),n=t.next,o=e.prev;return t.next=e,e.prev=t,r.next=n,n.prev=r,i.next=r,r.prev=i,o.next=i,i.prev=o,i}function w(t,e,r,i){var n=new U(t,e,r);return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function F(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 U(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 D(t,e,r,i){for(var n=0,o=e,a=r-i;o<r;o+=i)n+=(t[a]-t[o])*(t[o+1]+t[a+1]),a=o;return n}function L(t,e,r){var i=e[1],n=e[0],o=i-n;return t===i&&r?t:((t-n)%o+o)%o+n}function P(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}o.deviation=function(t,e,r,i){var n=e&&e.length,o=n?e[0]*r:t.length,a=Math.abs(D(t,0,o,r));if(n)for(var s=0,u=e.length;s<u;s++){var h=e[s]*r,l=s<u-1?e[s+1]*r:t.length;a-=Math.abs(D(t,h,l,r))}var c=0;for(s=0;s<i.length;s+=3){var f=i[s]*r,m=i[s+1]*r,d=i[s+2]*r;c+=Math.abs((t[f]-t[d])*(t[m+1]-t[f+1])-(t[f]-t[m])*(t[d+1]-t[f+1]))}return 0===a&&0===c?0:Math.abs((c-a)/a)},o.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},i=0,n=0;n<t.length;n++){for(var o=0;o<t[n].length;o++)for(var a=0;a<e;a++)r.vertices.push(t[n][o][a]);n>0&&(i+=t[n-1].length,r.holes.push(i))}return r};var C=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function S(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var B=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function I(t,e,r){return t instanceof S?t:C(t)?new S(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new S(t.x,t.y):new S(t,e,r)}function N(t,e){if(t)for(var r=e?[t,e]:t,i=0,n=r.length;i<n;i++)this.extend(r[i])}function O(t,e){return!t||t instanceof N?t:new N(t,e)}function X(t,e){if(t)for(var r=e?[t,e]:t,i=0,n=r.length;i<n;i++)this.extend(r[i])}function z(t,e){return t instanceof X?t:new X(t,e)}S.prototype={clone:function(){return new S(this.x,this.y)},add:function(t){return this.clone()._add(I(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(I(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 S(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new S(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=B(this.x),this.y=B(this.y),this},distanceTo:function(t){var e=(t=I(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=I(t)).x===this.x&&t.y===this.y},contains:function(t){return t=I(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+P(this.x)+", "+P(this.y)+")"}},N.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof S||"number"==typeof t[0]||"x"in t)e=r=I(t);else if(e=(t=O(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 I((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return I(this.min.x,this.max.y)},getTopRight:function(){return I(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 S?I(t):O(t))instanceof N?(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=O(t);var e=this.min,r=this.max,i=t.min,n=t.max,o=n.x>=e.x&&i.x<=r.x,a=n.y>=e.y&&i.y<=r.y;return o&&a},overlaps:function(t){t=O(t);var e=this.min,r=this.max,i=t.min,n=t.max,o=n.x>e.x&&i.x<r.x,a=n.y>e.y&&i.y<r.y;return o&&a},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,i=Math.abs(e.x-r.x)*t,n=Math.abs(e.y-r.y)*t;return O(I(e.x-i,e.y-n),I(r.x+i,r.y+n))},equals:function(t){return!!t&&(t=O(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},X.prototype={extend:function(t){var e,r,i=this._southWest,n=this._northEast;if(t instanceof H)e=t,r=t;else{if(!(t instanceof X))return t?this.extend(W(t)||z(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return i||n?(i.lat=Math.min(e.lat,i.lat),i.lng=Math.min(e.lng,i.lng),n.lat=Math.max(r.lat,n.lat),n.lng=Math.max(r.lng,n.lng)):(this._southWest=new H(e.lat,e.lng),this._northEast=new H(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,i=Math.abs(e.lat-r.lat)*t,n=Math.abs(e.lng-r.lng)*t;return new X(new H(e.lat-i,e.lng-n),new H(r.lat+i,r.lng+n))},getCenter:function(){return new H((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 H(this.getNorth(),this.getWest())},getSouthEast:function(){return new H(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 H||"lat"in t?W(t):z(t);var e,r,i=this._southWest,n=this._northEast;return t instanceof X?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=i.lat&&r.lat<=n.lat&&e.lng>=i.lng&&r.lng<=n.lng},intersects:function(t){t=z(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),n=t.getNorthEast(),o=n.lat>=e.lat&&i.lat<=r.lat,a=n.lng>=e.lng&&i.lng<=r.lng;return o&&a},overlaps:function(t){t=z(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),n=t.getNorthEast(),o=n.lat>e.lat&&i.lat<r.lat,a=n.lng>e.lng&&i.lng<r.lng;return o&&a},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=z(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var G=function(t){var e,r,i,n;for(r=1,i=arguments.length;r<i;r++)for(e in n=arguments[r])t[e]=n[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),i=this.scale(e);return this.transformation._transform(r,i)},pointToLatLng:function(t,e){var r=this.scale(e),i=this.transformation.untransform(t,r);return this.projection.unproject(i)},project:function(t){return this.projection.project(t)},unproject:function(t){return this.projection.unproject(t)},scale:function(t){return 256*Math.pow(2,t)},zoom:function(t){return Math.log(t/256)/Math.LN2},getProjectedBounds:function(t){if(this.infinite)return null;var e=this.projection.bounds,r=this.scale(t);return new N(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(t){var e=this.wrapLng?L(t.lng,this.wrapLng,!0):t.lng;return new H(this.wrapLat?L(t.lat,this.wrapLat,!0):t.lat,e,t.alt)},wrapLatLngBounds:function(t){var e=t.getCenter(),r=this.wrapLatLng(e),i=e.lat-r.lat,n=e.lng-r.lng;if(0===i&&0===n)return t;var o=t.getSouthWest(),a=t.getNorthEast();return new X(new H(o.lat-i,o.lng-n),new H(a.lat-i,a.lng-n))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,i=t.lat*r,n=e.lat*r,o=Math.sin((e.lat-t.lat)*r/2),a=Math.sin((e.lng-t.lng)*r/2),s=o*o+Math.cos(i)*Math.cos(n)*a*a,u=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s));return this.R*u}});function H(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 W(t,e,r){return t instanceof H?t:C(t)&&"object"!=typeof t[0]?3===t.length?new H(t[0],t[1],t[2]):2===t.length?new H(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new H(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new H(t,e,r)}H.prototype={equals:function(t,e){return!!t&&(t=W(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("+P(this.lat,t)+", "+P(this.lng,t)+")"},distanceTo:function(t){return G.distance(this,W(t))},wrap:function(){return G.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return z([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new H(this.lat,this.lng,this.alt)}};const j=t=>{const e=t.valueOf();return Z(e)},Z=t=>{const e=t/864e5-10957.5,r=6.240059966692059+.017201969994578018*e,i=r+.017453292519943295*(1.9148*Math.sin(r)+.02*Math.sin(2*r)+3e-4*Math.sin(3*r))+1.796593062783907+Math.PI,n=Math.atan2(Math.sin(i)*Math.cos(.40909994067971484),Math.cos(i));return{dec:Math.asin(Math.sin(.40909994067971484)*Math.sin(i)),Hi:(4.889714432387314+6.3003876824396166*e-n)%(2*Math.PI)+2*Math.PI}},Y=(t,e,r)=>{const i=1/e,n=Math.min(t[0]*i,255),o=Math.min(t[1]*i,255),a=Math.min(t[2]*i,255);let s=0;return n+o+a!==0&&(s=n>0?n/255*.5+.5:a>0?.5*(1-a/255):.5),s*r},K=(t=new Date,e)=>{const r=new Date(t.toLocaleString("en-US",{timeZone:"UTC"})),i=new Date(t.toLocaleString("en-US",e?{timeZone:e}:{}));return r.getTime()-i.getTime()};function k(t){t.filter((t=>"MultiPolygon"===t.geometry.type)).forEach((e=>{const{geometry:r,properties:i,type:n}=e;if("MultiPolygon"===r.type)for(let i=0;i<r.coordinates.length;i++)t.push(Object.assign(Object.assign({},e),{geometry:Object.assign(Object.assign({},r),{type:"Polygon",coordinates:r.coordinates[i]})}))}));return t.filter((t=>"Polygon"===t.geometry.type)).map((t=>{const{geometry:e,properties:r}=t,{vertices:i}=o.flatten(e.coordinates),n=new Float32Array(i.map(((t,e)=>{return e%2==1?(r=t,(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+r*Math.PI/360)))/360):(180+t)/360;var r}))),a=o(n),s=a.length>256?new Uint16Array(a):new Uint8Array(a),u=function(t){const{height:e=0,levels:r=0,render_height:i=0}=t;if(r)return 3.04*r;return Math.max(e,i)}(r),h=r.highlight||!1;let l=0,c=0,f=0;for(let t=0;t<n.length;t+=2)l+=n[t],c+=n[t+1],f++;return{aPosition:n,cuts:s,buildingHeight:u,centroid:[l/f,c/f],highlight:h}}))}const V=(t,e)=>{const{lat:r,lng:i}=t;return new S(((t,e)=>(t+180)/360*Math.pow(2,e)*256)(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)*256)(r,e))},q=(t,e)=>{return new H((r=t.y,i=e,n=Math.PI-2*Math.PI*r/256/Math.pow(2,i),180/Math.PI*Math.atan(.5*(Math.exp(n)-Math.exp(-n)))),function(t,e){return t/256/Math.pow(2,e)*360-180}(t.x,e));var r,i,n};let $,J={heightMapTex:null,width:0,height:0,visibleDEMPixelBounds:new N(new S(0,0),new S(0,0)),DEMPixelBounds:new N(new S(0,0),new S(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const Q=t=>n(void 0,void 0,void 0,(function*(){const{demZoom:e,getFeatures:r,terrainSource:i,dsmSource:o,tileLoaded:a,gl:s,bounds:u,buildingRasterizer:h,tileMerger:l,forceUpdate:c=!1}=t,{getSourceUrl:f,getElevation:m,maxZoom:d,tileSize:_,_overzoom:x}=i,g=(p={getFeatures:r},n(void 0,void 0,void 0,(function*(){const{getFeatures:t}=p;try{return k(yield t())}catch(t){console.log("Error merging buildings",t)}return[]})));var p;try{const t=u,r=t.getNorthWest(),i=t.getSouthEast(),n=new N(V(r,e),V(i,e));let x=new S(n.min.x,n.min.y),p=n.max.x-n.min.x;const E=n.max.y-n.min.y,T=n.max.subtract(n.min);T.y>T.x&&(x.x-=256,p+=512);const v=(t=>{const{upperLeft:e,width:r,height:i}=t,n=e.divideBy(256).floor().multiplyBy(256),o=256*(Math.ceil(r/256)+1),a=256*(Math.ceil(i/256)+1),s=n.add([o,a]);return new N(n,s)})({upperLeft:x,width:p,height:E}),{x:y,y:A}=v.max.subtract(v.min),R=(t=>{t.sort(((t,e)=>t.y!==e.y?t.y-e.y:t.x-e.x));const e=t.reduce(((t,e)=>e.x<t.x?e:t)).x,r=t.reduce(((t,e)=>e.y<t.y?e:t)).y;return t.map((t=>{const i=Math.pow(2,t.z);return{x:(t.x%i+i)%i,y:(t.y%i+i)%i,z:t.z,xOffset:256*(t.x-e),yOffset:256*(t.y-r)}}))})((t=>{const{upperLeft:e,width:r,height:i,zoom:n}=t,o=e.divideBy(256).floor(),a=o.x+r/256,s=Math.min(o.y+i/256,Math.pow(2,n)-1),u=[];for(var h=o.x;h<a;h++)for(var l=o.y;l<s;l++)u.push({x:h,y:l,z:n});return u})({upperLeft:v.min,width:y,height:A,zoom:e})),b=n.max.x-n.min.x,M=n.max.y-n.min.y,w=Math.round(b),F=Math.round(M),U=JSON.stringify(R);if(!c&&U===$&&e<d)return J=Object.assign(Object.assign({},J),{outputWidth:w,outputHeight:F,visibleDEMPixelBounds:n,demZoom:e,dirty:!0}),J;const D=yield l.merge(R,{maxZoom:d,width:y,height:A,crossOrigin:"Anonymous",getSourceUrl:f,getElevation:m,tileSize:_,tileLoaded:a});if(null===D)return J=Object.assign(Object.assign({},J),{visibleDEMPixelBounds:n,demZoom:e,dirty:!1}),J;const L=new N(V(new X(o.bounds).getNorthWest(),e),V(new X(o.bounds).getSouthEast(),e)),P=L.min.subtract(v.min),C=L.max.subtract(v.min),B=[P.x/y,P.y/A,C.x/y,C.y/A].map((t=>2*t-1)),I=yield g,{maxHeight:O,heightMapTex:z}=h.raster({upperLeftTile:R[0],width:y,height:A,mapZoom:e,features:I,imageData:D,gl:s,dsmSource:o,dsmCoords:B}),G=Math.max(Math.max(o.maxHeight,O),D.maxHeight);$=U,J={heightMapTex:z,maxHeight:G,width:y,height:A,DEMPixelBounds:v,visibleDEMPixelBounds:n,raster:R,demZoom:e,dirty:!0,outputWidth:w,outputHeight:F}}catch(t){console.error("Could not decode height map",t)}return J})),tt=(t,e)=>{const{r:r,g:i,b:n}=t;return[r/255,i/255,n/255,e]},et=(t,e)=>{const{date:r}=e,{dec:i,Hi:n}=j(r);t.updateDate({dec:i,Hi:n})},rt=(t,e)=>n(void 0,void 0,void 0,(function*(){return yield t.updateDateRange(Object.assign({},e))})),it=(t,e)=>{const{color:r,opacity:i}=e,n=tt(r,i);t.updateColor({colorVec:n})},nt=t=>{const{kernel:e,map:r,heightMap:i,now:n,color:o,opacity:a,belowCanopy:s,skipRender:u}=t;try{const{heightMapTex:t,outputHeight:h,outputWidth:l,maxHeight:c,width:f,height:m,DEMPixelBounds:d,visibleDEMPixelBounds:_,demZoom:x}=i;if(0===f||0===m)return;const{min:g,max:p}=_;if(!g||!p)return;const{x:E,y:T}=p.subtract(g),v=d.min,y=r.getPixelDimensions(),A=r.screenUnproject([0,0]),R=r.screenUnproject([y.width,0]),b=r.screenUnproject([y.width,y.height]),M=r.screenUnproject([0,y.height]),w=[M,b,A,R].map((t=>r.project(t,x))),F=w.map((t=>[(t.x-v.x)/f,(t.y-v.y)/m])).flat(),U=w.map((t=>[(t.x-g.x)/E,(t.y-g.y)/T])).map((t=>[2*t[0]-1,(2*t[1]-1)*(r.isLeaflet()?-1:1)])).flat(),D=v.y/256/Math.pow(2,x),L=m/256/Math.pow(2,x),P=new X(q(d.getTopLeft(),x),q(d.getBottomRight(),x)),C=P.getWest(),S=Math.abs(P.getWest()-P.getEast());((t,e)=>{const{color:r,opacity:i,date:n}=e,o=tt(r,i),{dec:a,Hi:s}=j(n);t.updateHeightMap(Object.assign({dec:a,Hi:s,colorVec:o,step:1},e))})(e,{heightMapTex:t,maxHeight:c,width:f,height:m,heightMapZoom:x,cornerTextureCoords:F,cornerClipCoords:U,topYCoord:D,ySize:L,west:C,dLng:S,date:n,color:o,opacity:a,outputHeight:h,outputWidth:l,belowCanopy:s,skipRender:u})}catch(t){console.error("EXCEPTION",t)}};const ot=t=>{const e=()=>!t.getPitch;return{project:(r,i)=>{if(e())return t.project(r,i);{const{lat:t,lng:e}=r;return new S(((t,e)=>(t+180)/360*Math.pow(2,e)*256)(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)*256)(t,i))}},unproject:(r,i)=>{return e()?t.unproject(r,i):new H((n=r.y,o=i,a=Math.PI-2*Math.PI*n/256/Math.pow(2,o),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/256/Math.pow(2,e)*360-180}(r.x,i));var n,o,a},screenUnproject:r=>e()?t.containerPointToLatLng(r):t.unproject(r),getZoom:()=>e()?t.getZoom():t.getZoom()+1,getCenter:()=>t.getCenter(),getBounds:()=>t.getBounds(),eachLayer:r=>{e()&&t.eachLayer(r)},getBearing:()=>e()?0:t.getBearing(),getPitch:()=>e()?0:t.getPitch(),rawMap:()=>t,isLeaflet:e,getPixelDimensions:()=>{const e=t.getContainer();return{width:e.clientWidth,height:e.clientHeight}},createBounds:t=>{const{nw:e,se:r}=t;return new X(e,r)}}};const at=t=>{const{gl:e}=t,{texture:r,imageData:i=null,format:n=e.RGBA,width:o,height:a,filter:s=e.NEAREST,wrap:u=e.CLAMP_TO_EDGE,type:h=e.UNSIGNED_BYTE,internalFormat:l=n}=t;e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,s),e.texImage2D(e.TEXTURE_2D,0,l,o,a,0,n,h,i)};function st(t){const{gl:e,vSrc:r,fSrc:i}=t,n=e.createShader(e.VERTEX_SHADER);e.shaderSource(n,r),e.compileShader(n);const o=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(o,i),e.compileShader(o);const a=e.createProgram();return e.attachShader(a,n),e.attachShader(a,o),e.linkProgram(a),a}class ut{constructor(t){this.gl=t,this.program=st({gl:t,vSrc:"\nuniform vec3 xyz;\nuniform vec2 dimensions;\nuniform bool use_dsm;\nattribute vec2 dsm_position;\nattribute vec2 a_position;\nfloat PI = 3.141592653589793;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\n\tvoid main() {\n\t\tif (use_dsm == true) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = dsm_position;\n v_use_dsm = 1.0;\n\t\t\treturn;\n\t\t}\n\t\tif (abs(a_position) == vec2(1,1)) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = a_position * 0.5 + 0.5;\n\t\t\treturn;\n\t\t}\n\t\tfloat x = a_position.x - xyz.x;\n\t\tfloat y = a_position.y - xyz.y;\n\t\tvec2 transformed = vec2(x, y);\n\t\tvec2 normalized = transformed / dimensions;\n\t\tvec2 final = normalized * 2.0 - 1.0;\n\t\tgl_Position = vec4(final, 0, 1);\n\t}\n",fSrc:"\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform vec4 color;\nuniform sampler2D height_map;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n if (v_use_dsm == 1.0) {\n\t \t gl_FragColor = vec4(0.0, 0.0, textureColor.b, textureColor.a);\n if (gl_FragColor.zw == vec2(0.0)) {\n discard;\n }\n } else {\n gl_FragColor = vec4(textureColor.b, textureColor.a, textureColor.b, textureColor.a);\n }\n // DSM noData values should not be included in heightMap because they produce ugly borders\n\t\treturn;\n\t} \n\tgl_FragColor = color;\n}\n"}),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.dsmAttributeLocation=t.getAttribLocation(this.program,"dsm_position"),this.useDSMUniformLocation=t.getUniformLocation(this.program,"use_dsm"),this.xyzUniformLocation=t.getUniformLocation(this.program,"xyz"),this.dimensionsUniformLocation=t.getUniformLocation(this.program,"dimensions"),this.heightMapUniformLocation=t.getUniformLocation(this.program,"height_map"),this.colorUniformLocation=t.getUniformLocation(this.program,"color"),this.positionBuffer=t.createBuffer(),this.dsmBuffer=t.createBuffer(),this.indexBuffer=t.createBuffer(),this.targetTexture=t.createTexture()}raster(t){const{features:e,upperLeftTile:r,mapZoom:i,width:n,height:o,imageData:a,dsmCoords:s,dsmSource:u,gl:h}=t,{x:l,y:c,z:f}=r;let m=0;h.useProgram(this.program),h.activeTexture(h.TEXTURE1);const d=h.createTexture();h.bindTexture(h.TEXTURE_2D,d),h.pixelStorei(h.UNPACK_ALIGNMENT,2),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,h.NEAREST),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,h.NEAREST),h.texImage2D(h.TEXTURE_2D,0,h.LUMINANCE_ALPHA,n,o,0,h.LUMINANCE_ALPHA,h.UNSIGNED_BYTE,a),h.pixelStorei(h.UNPACK_ALIGNMENT,4);const _=n,x=o;h.activeTexture(h.TEXTURE0),h.bindTexture(h.TEXTURE_2D,this.targetTexture),h.texImage2D(h.TEXTURE_2D,0,h.RGBA,_,x,0,h.RGBA,h.UNSIGNED_BYTE,null),i>15&&e.length>5?(h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,h.NEAREST),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,h.NEAREST)):(h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,h.LINEAR),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,h.LINEAR)),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE),h.viewport(0,0,_,x);const g=h.createFramebuffer();h.bindFramebuffer(h.FRAMEBUFFER,g);const p=h.COLOR_ATTACHMENT0;h.framebufferTexture2D(h.FRAMEBUFFER,p,h.TEXTURE_2D,this.targetTexture,0),h.disable(h.BLEND),h.bindBuffer(h.ARRAY_BUFFER,this.positionBuffer),h.bindBuffer(h.ELEMENT_ARRAY_BUFFER,this.indexBuffer),h.clearColor(0,0,0,0),h.clear(h.COLOR_BUFFER_BIT);const E=l/Math.pow(2,f),T=c/Math.pow(2,f),v=new S(E,T),y=n/256/Math.pow(2,f),A=o/256/Math.pow(2,f);h.uniform3f(this.xyzUniformLocation,E,T,f),h.uniform2f(this.dimensionsUniformLocation,y,A),h.uniform1i(this.heightMapUniformLocation,1),h.uniform1i(this.useDSMUniformLocation,0);const R=new Float32Array([-1,-1,1,-1,-1,1,1,1]);if(h.enableVertexAttribArray(this.positionAttributeLocation),h.bufferData(h.ARRAY_BUFFER,R,h.STATIC_DRAW),h.vertexAttribPointer(this.positionAttributeLocation,2,h.FLOAT,!1,0,0),h.uniform4f(this.colorUniformLocation,0,0,0,0),h.drawArrays(h.TRIANGLE_STRIP,0,4),e.forEach((t=>{const{buildingHeight:e,aPosition:r,cuts:i,centroid:s,highlight:u}=t,l=new S(s[0],s[1]).subtract(v).unscaleBy(new S(y,A)).scaleBy(new S(n,o)).floor();if(l.x<0||l.y<0||l.x>n||l.y>o)return;const c=256*a[l.y*n*2+2*l.x]+a[l.y*n*2+2*l.x+1]+5*e,f=Math.floor(c/256)/255,d=Math.floor(c%256)/255;m=Math.max(m,c/5),h.uniform4f(this.colorUniformLocation,f,d,f,d),h.bufferData(h.ARRAY_BUFFER,r,h.DYNAMIC_DRAW),h.vertexAttribPointer(this.positionAttributeLocation,2,h.FLOAT,!1,0,0),h.bufferData(h.ARRAY_BUFFER,r,h.DYNAMIC_DRAW),h.vertexAttribPointer(this.dsmAttributeLocation,2,h.FLOAT,!1,0,0),h.bufferData(h.ELEMENT_ARRAY_BUFFER,i,h.DYNAMIC_DRAW),h.drawElements(h.TRIANGLES,i.length,i.length>256?h.UNSIGNED_SHORT:h.UNSIGNED_BYTE,0)})),h.deleteTexture(d),0!==u.data.length){h.activeTexture(h.TEXTURE1);const t=h.createTexture();h.bindTexture(h.TEXTURE_2D,t),h.pixelStorei(h.UNPACK_ALIGNMENT,2),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,h.NEAREST),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,h.NEAREST),h.texImage2D(h.TEXTURE_2D,0,h.LUMINANCE_ALPHA,u.width,u.height,0,h.LUMINANCE_ALPHA,h.UNSIGNED_BYTE,u.data),h.pixelStorei(h.UNPACK_ALIGNMENT,4);const e=[s[0],s[3],s[2],s[3],s[0],s[1],s[2],s[1]],r=new Float32Array(e);h.enableVertexAttribArray(this.positionAttributeLocation),h.bufferData(h.ARRAY_BUFFER,r,h.STATIC_DRAW),h.vertexAttribPointer(this.positionAttributeLocation,2,h.FLOAT,!1,0,0),h.enableVertexAttribArray(this.dsmAttributeLocation),h.bindBuffer(h.ARRAY_BUFFER,this.dsmBuffer),h.bufferData(h.ARRAY_BUFFER,new Float32Array([0,1,1,1,0,0,1,0]),h.STATIC_DRAW),h.vertexAttribPointer(this.dsmAttributeLocation,2,h.FLOAT,!1,0,0),h.uniform4f(this.colorUniformLocation,0,0,0,0),h.uniform1i(this.useDSMUniformLocation,1),h.colorMask(!1,!1,!0,!0),h.drawArrays(h.TRIANGLE_STRIP,0,4),h.deleteTexture(t)}return h.colorMask(!0,!0,!0,!0),h.deleteFramebuffer(g),{maxHeight:m,heightMapTex:this.targetTexture}}}const ht=t=>{const{tile:e,maxZoom:r,tileSize:i}=t;let{x:n,y:o,z:a}=e;if(a>r){const t=Math.pow(2,e.z-r);n=Math.floor(n/t),o=Math.floor(o/t),a=r}return{x:256===i?n:Math.floor(n/2),y:256===i?o:Math.floor(o/2),z:256===i?a:a-1}};class lt{constructor(t){this.gl=t,this.program=st({vSrc:"\n attribute vec4 a_position;\n varying vec2 v_pos;\n void main() {\n v_pos = ((a_position + 1.0) * 0.5).xy;\n gl_Position = a_position;\n }\n",fSrc:"\n precision mediump float;\n varying vec2 v_pos;\n uniform sampler2D u_texture;\n void main() {\n gl_FragColor = texture2D(u_texture, v_pos);\n }\n",gl:t}),t.useProgram(this.program),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.positionBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(this.positionAttributeLocation),t.vertexAttribPointer(this.positionAttributeLocation,2,t.FLOAT,!1,0,0),this.tileTexture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.tileTexture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),this.outputTexture=t.createTexture(),this.framebuffer=t.createFramebuffer(),this.inProgress=[],this.finished=0}merge(t,e){return n(this,void 0,void 0,(function*(){const r=this.gl,{width:i,height:o,crossOrigin:a,getSourceUrl:s,getElevation:u,tileSize:h,tileLoaded:l,maxZoom:c}=e;if(r){const e=new Uint8ClampedArray(2*i*o);e.maxHeight=0,this.inProgress.forEach((t=>t.src="")),this.inProgress=[],this.finished=0;const f=new Set;t.forEach((t=>{f.add(s(ht({tile:t,maxZoom:c,tileSize:h})))}));const m=Array.from(f).map((o=>n(this,void 0,void 0,(function*(){return new Promise(((n,l)=>{const f=new Image;this.inProgress.push(f),f.onload=()=>{t.filter((t=>o===s(ht({tile:t,maxZoom:c,tileSize:h})))).forEach((t=>{let n=0,o=0;const a=514===h?1:0;let s=0,l=256,m=256;if(256!==h&&(n=t.x%2*256,o=t.y%2*256,l=256,m=256),t.z>c){const e=Math.pow(2,t.z-c);256!==h&&(n=Math.floor(t.x/e)%2*256,o=Math.floor(t.y/e)%2*256),n+=t.x%e/e*256,o+=t.y%e/e*256,l=256/e,m=256/e,s=514===h?1:0}r.useProgram(this.program),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.tileTexture),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,f),r.activeTexture(r.TEXTURE1),at({gl:r,texture:this.outputTexture,imageData:null,format:r.RGBA,width:h,height:h,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST}),r.bindFramebuffer(r.FRAMEBUFFER,this.framebuffer),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,this.outputTexture,0);const d=r.checkFramebufferStatus(r.FRAMEBUFFER);d!==r.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+d),r.bindBuffer(r.ARRAY_BUFFER,this.positionBuffer),r.enableVertexAttribArray(this.positionAttributeLocation),r.vertexAttribPointer(this.positionAttributeLocation,2,r.FLOAT,!1,0,0),r.viewport(0,0,h,h),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4);const _=new Uint8Array(4*(l+s)*(m+s));r.readPixels(a+n,a+o,l+s,m+s,r.RGBA,r.UNSIGNED_BYTE,_),r.bindFramebuffer(r.FRAMEBUFFER,null);const x=new Uint8ClampedArray(131072);let g=new Array((l+s)*(m+s)),p=256/l;for(let t=0;t<_.length;t+=4){const r=u({r:_[t],g:_[t+1],b:_[t+2],a:_[t+3]});e.maxHeight=Math.max(r,e.maxHeight);const i=5*(r||0);g[t/4]=i}if(p>1&&514===h)for(g=function(t,e,r,i){const n=Math.floor(e*i),o=Math.floor(r*i),a=[];for(let s=0;s<o;s++)for(let o=0;o<n;o++){const n=o/i,u=s/i,h=Math.floor(n),l=Math.floor(u),c=Math.min(h+1,e-1),f=Math.min(l+1,r-1),m=n-h,d=u-l,_=l*e+c,x=f*e+h,g=f*e+c,p=t[l*e+h]*(1-m)*(1-d)+t[_]*m*(1-d)+t[x]*(1-m)*d+t[g]*m*d;a.push(p)}return function(t,e,r,i,n){if(i>=e||n>=r)return[];const o=e-i,a=r-n,s=[];for(let r=0;r<a;r++)for(let i=0;i<o;i++){const n=r*e+i;s.push(t[n])}return s}(a,Math.sqrt(a.length),Math.sqrt(a.length),i,i)}(g,l+1,m+1,p);p>1;)p/=2,m*=2,l*=2;for(let t=0;t<x.length;t+=2){const e=g[Math.floor(t/2/256/p)*l+Math.floor(t/2%256/p)],r=Math.floor(e/256),i=Math.floor(e%256);x[t]=r,x[t+1]=i}for(let r=0;r<256;r++)e.set(x.slice(256*r*2,256*(r+1)*2),2*(t.yOffset*i+r*i+t.xOffset))})),n(null)},f.onerror=t=>{if(f.src!==f.originalSource)return l("new tiles requested");n(null)},f.crossOrigin=a||null,f.src=o,f.originalSource=f.src})).then((()=>{this.finished++,l(this.finished,this.inProgress.length)}))}))));try{yield Promise.all(m)}catch(t){return console.log(`${m.length} requests aborted`,t),null}return this.inProgress=[],e}throw new Error("Could not get canvas context for merging tile images")}))}}class ct extends class extends class{constructor(){this.events={}}on(t,e){return"object"!=typeof this.events[t]&&(this.events[t]=[]),this.events[t].push(e),()=>this.removeListener(t,e)}removeListener(t,e){if("object"!=typeof this.events[t])return;const r=this.events[t].indexOf(e);r>-1&&this.events[t].splice(r,1)}removeAllListeners(){Object.keys(this.events).forEach((t=>this.events[t].splice(0,this.events[t].length)))}emit(t,...e){"object"==typeof this.events[t]&&[...this.events[t]].forEach((t=>t.apply(this,e)))}once(t,e){const r=this.on(t,((...t)=>{r(),e.apply(this,t)}));return r}}{constructor(...t){super(),this.options={date:new Date,color:"000",opacity:.3,sunExposure:{enabled:!1,startDate:new Date,endDate:new Date,iterations:32},apiKey:"",terrainSource:{maxZoom:15,tileSize:256,_overzoom:15,getSourceUrl:t=>"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/7/17/45.png",getElevation:t=>{const{r:e,g:r,b:i}=t;return 256*e+r+i/256-32768}},dsmSource:{bounds:[{lat:0,lng:0},{lat:0,lng:0}],data:new Uint8ClampedArray,width:0,height:0,maxHeight:0},belowCanopy:!1,getFeatures:()=>Promise.resolve([]),getSize:()=>({width:Number.NaN,height:Number.NaN}),debug:t=>{}};const e=t[0];if(this.options=Object.assign(this.options,e),!this.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:this.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((t=>n(this,void 0,void 0,(function*(){if(200!==t.status)throw new Error(yield t.text())})))).catch((t=>n(this,void 0,void 0,(function*(){throw new Error(`Could not load ShadeMap API. Key: ${this.options.apiKey} Error: ${t}`)})))),this._canvas=document.createElement("canvas"),this._color=this._parseColor(this.options.color),this._reset=this._reset.bind(this),this._draw=this._draw.bind(this)}onRemove(){return this._map&&this._map.off("moveend",this._reset),this}setDate(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(et(this._compiledKernel,{date:this.options.date}),this._heightMap&&this._flush())):this.emit("idle"),this}_setDateForTimezone(t,e){let r=0;e&&(r=K(this.options.date)-K(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&&(it(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&&(it(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setBelowCanopy(t){return this.options.belowCanopy=t,this._heightMap?this._draw(this._heightMap):this._reset(),this}setTerrainSource(t){return this.options.terrainSource=t,delete this._heightMap,this._reset(),this}setDSMSource(t){return this.options.dsmSource=t,delete this._heightMap,this._reset(),this}setSunExposure(t=!1,e){return n(this,void 0,void 0,(function*(){if(this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:t}),e){const{startDate:r=new Date,endDate:i=new Date,iterations:n=32}=e;this.options.sunExposure={enabled:t,startDate:r,endDate:i,iterations:n}}if(this._map&&this._compiledKernel&&this._heightMap){if(!1===t)et(this._compiledKernel,{date:this.options.date});else{const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!(t instanceof Date&&e instanceof Date))throw new Error("Start date or end date or both are missing");if(e.getTime()<t.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield rt(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._flush()}return this}))}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:i,height:n}=this._heightMap,o=e.min;return t.map((t=>{const e=V(t,r);return[(e.x-o.x)/i,(e.y-o.y)/n]}))}return[]}_getBounds(t,e){const{width:r,height:i}=this.options.getSize();if(Number.isNaN(r)||Number.isNaN(i))return t.getBounds();const n=t.getCenter(),o=V(n,e),a=q(new S(o.x-r/2,o.y-i/2),e),s=q(new S(o.x+r/2,o.y+i/2),e);return t.createBounds({nw:a,se:s})}_getDEMZoom(t){const e=Math.min(this.options.terrainSource._overzoom||this.options.terrainSource.maxZoom,t.getZoom());return Math.round(e)}_reset(){return n(this,void 0,void 0,(function*(){if(this.options.debug("_reset()"),this._map){const t=ot(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),n=r.filter((t=>t.canonical.z===i)).map((t=>t.canonical)),[o,a,s,u]=n.reduce(((t,e)=>[Math.min(t[0],e.x),Math.min(t[1],e.y),Math.max(t[2],e.x),Math.max(t[3],e.y)]),[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER]),h=q(new S(512*o,512*a),i+1),l=q(new S(512*(s+1),512*(u+1)),i+1);e=i+1,this._bounds=t.createBounds({nw:h,se:l})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield Q({gl:this._gl,demZoom:e,bounds:this._bounds,terrainSource:this.options.terrainSource,dsmSource:this.options.dsmSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,tileLoaded:(t,e)=>this.emit("tileloaded",t,e),forceUpdate:!this._heightMap});this._heightMap=r,r.dirty&&(yield this._draw(r))}return this}))}_draw(t){return n(this,void 0,void 0,(function*(){if(this.options.debug("_draw()"),this._canvas&&this._compiledKernel&&this._map){if(nt({kernel:this._compiledKernel,map:ot(this._map),heightMap:t,color:this._color,belowCanopy:this.options.belowCanopy,opacity:this.options.opacity,now:this.options.date,maxZoom:this.options.terrainSource.maxZoom,skipRender:this.options.sunExposure.enabled}),this.options.sunExposure.enabled){const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!0===(yield rt(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._bounds&&this._repositionCanvas(this._bounds)}return this}))}readPixel(t,e){const r=new Uint8Array(4);return this._gl&&this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r),r}readPixels(t,e,r,i){const n=new Uint8Array(r*i*4);return this._gl&&this._gl.readPixels(t,e,r,i,this._gl.RGBA,this._gl.UNSIGNED_BYTE,n),n}toGeoTiff(){const t=(t,e)=>{const r=this.readPixels(0,0,t,e),i=t*e*1,n=1*t,o=(e-1)*n,a=new Uint8Array(i),s=new Uint8Array(i);let u=0;const{startDate:h,endDate:l}=this.options.sunExposure;this.options.sunExposure.enabled&&h&&l&&(u=l.getTime()-h.getTime());for(let t=0;t<r.length;t+=4){let e;if(this.options.sunExposure.enabled){const i=r.subarray(t,t+3),n=Y(i,.5,u)/1e3/60,o=Math.min(Math.floor(n/6),255);e=new Uint8Array([o])}else{e=r[t]+r[t+1]+r[t+2]===0?new Uint8Array([255]):new Uint8Array([0])}a.set(e,t/4*1)}if(this._map&&!ot(this._map).isLeaflet())return a;for(let t=0;t<i;t+=n)s.set(a.subarray(t,t+n),o-t);return s};if(this._map&&this._heightMap){const e=this._heightMap.outputWidth,r=this._heightMap.outputHeight,i=t(e,r),n=ot(this._map),{lat:o,lng:a}=n.getBounds().getNorthWest(),s=n.getBounds().getSouthEast(),u=[0,0,0,a,o,0],h=[(s.lng-a)/e,(o-s.lat)/r,0];return this.options.sunExposure.enabled,{data:i,metadata:{width:e,height:r,ModelTiepoint:u,ModelPixelScale:h,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}return null}_generateShadeProfile(t){if(this._compiledKernel){const e=this._lngLatToTextureCoords(t.locations);return((t,e)=>{const r=tt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=tt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{texCoords:e}))}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=K(t.startDate)-K(t.startDate,t.tzId),r=t.startDate.getTime()-e,i=t.endDate.getTime()-e,n=this._lngLatToTextureCoords([t.location])[0],{output:o,outputWidth:a,outputHeight:s}=((t,e)=>{const r=tt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=tt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateLocationShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{startTime:r,endTime:i,texCoord:n}));return o.toArray=function(){const e=new Array;for(let r=0;r<a;r++){const i=[];for(let e=s-1;e>=0;e--){const n=e*a*4+4*r,o=this.slice(n,n+4);i.push(o.join("")===t.sunColor.join("")?1:0)}e.push(i)}return e},{data:o,width:a,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:i,endDate:n}=this.options.sunExposure,o=n.getTime()-i.getTime(),a=Y(r,.5,o);return Math.abs(a/1e3/3600)}return 0}_repositionCanvas(t){}_flush(){}flushSync(){this._gl&&this._gl.finish()}_parseColor(t){t=t.replace("#","");const e={r:0,g:0,b:0};return/^([0-9A-F]{3}){1,2}$/i.test(t)&&(3===t.length?(e.r=parseInt(t[0]+t[0],16),e.g=parseInt(t[1]+t[1],16),e.b=parseInt(t[2]+t[2],16)):6===t.length&&(e.r=parseInt(t[0]+t[1],16),e.g=parseInt(t[2]+t[3],16),e.b=parseInt(t[4]+t[5],16))),e}}{constructor(t){super(t);const e={preserveDrawingBuffer:!0,antialias:!1};this._gl=this._canvas.getContext("webgl",e)||this._canvas.getContext("experimental-webgl",e),this._canvas.width=window.innerWidth,this._canvas.height=window.innerHeight,this._compiledKernel=function(t){const{context:e,setRenderBuffer:r}=t,i=e,o=st({gl:i,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 a_pos;attribute vec2 a_tex_pos;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;void main(void){gl_Position=vec4(a_pos,0,1);vTexCoordFull=(gl_Position*0.5+0.5).xy;vTexCoordCropped=a_tex_pos;}",fSrc:"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nprecision lowp int;precision lowp sampler2D;float atan2(float v1,float v2){if(v1==0.0||v2==0.0)return 0.0;return atan(v1,v2);}float _pow(float v1,float v2){if(v2==0.0)return 1.0;return pow(v1,v2);}float integerMod(float x,float y){float res=floor(mod(x,y));return res*(res>floor(y)-1.0 ? 0.0 : 1.0);}float divWithIntCheck(float x,float y){if(floor(x)==x&&floor(y)==y&&integerMod(x,y)==0.0){return float(int(x)/int(y));}return x/y;}float integerCorrectionModulo(float number,float divisor){if(number<0.0){number=abs(number);if(divisor<0.0){divisor=abs(divisor);}return-(number-(divisor*floor(divWithIntCheck(number,divisor))));}if(divisor<0.0){divisor=abs(divisor);}return number-(divisor*floor(divWithIntCheck(number,divisor)));}float getDEMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*255.0*256.0+result.g*255.0)/5000.0;}float getDSMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.b*255.0*256.0+result.a*255.0)/5000.0;}vec4 actualColor;void color(float r,float g,float b,float a){actualColor=vec4(r,g,b,a);}void color(float r,float g,float b){color(r,g,b,1.0);}void color(float r){color(r,r,r,1.0);}void color(vec4 color){actualColor=color;}const int LOOP_MAX=1000;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;uniform sampler2D user_a;uniform float user_width;uniform float user_height;uniform float user_maxHeight;uniform float user_zoom;uniform float user_topYCoord;uniform float user_ySize;uniform vec4 user_color;uniform vec4 u_sunColor;uniform float user_step;uniform float user_west;uniform float user_dLng;uniform float user_dec;uniform float user_Hi;uniform bool u_below_canopy;uniform sampler2D user_sunExposureTexture;uniform bool user_outputSunExposure;uniform bool u_outputShadeProfile;uniform sampler2D u_decHiTexture;uniform sampler2D u_gpxTexture;uniform bool u_outputLocationShadeProfile;uniform vec2 u_shadeProfileLocation;float kernelResult;void kernel(){float sunDec=user_dec;float sunHi=user_Hi;vec4 shade_color=user_color;float maxHeight=user_maxHeight/1000.0;float user_x=vTexCoordCropped.x;float user_y=vTexCoordCropped.y;if(u_outputShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;vec4 gpx=texture2D(u_gpxTexture,vec2(vTexCoordFull.x,.5));user_x=gpx.x;user_y=gpx.y;}if(u_outputLocationShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;user_x=u_shadeProfileLocation.x;user_y=u_shadeProfileLocation.y;}float user_lit=1.0;float dsm_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(u_below_canopy==true){float dem_height=getDEMElevationFromSampler2D(user_a,user_x,user_y);if(dsm_height-dem_height>.002){user_lit=0.0;}}float user_z=dsm_height;float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=user_west+(user_dLng*user_x);float user_H=integerCorrectionModulo((sunHi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(sunDec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(sunDec))+((cos(user_lat)*cos(sunDec))*cos(user_H))));float user_zoom_factor=_pow(2.0,user_zoom);float user_kmPerPixel=divWithIntCheck(156.5430339296875,user_zoom_factor)*abs(cos(user_lat));float user_dx=((-sin(sun_azimuth)*cos(sun_altitude))*user_step)/user_width;float user_dy=((cos(sun_azimuth)*cos(sun_altitude))*user_step)/user_height;float user_dz=((sin(sun_altitude)*user_kmPerPixel)*user_step);float shadow_bias=0.0005;float user_curvature=0.0;float cur_height=0.0;float user_distance=0.0;float user_startX=user_x;float user_startY=user_y;user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;if((abs(1.0)<0.0)){kernelResult=0.0;return;}float minAngle=asin((earthRadiusInKm/(earthRadiusInKm+user_z)))-(user_PI/2.0);if(user_z<0.0||sun_altitude<minAngle){user_lit=0.0;}else{float xIter=ceil(user_dx<0.0 ? abs(user_x/user_dx):(1.0-user_x)/user_dx);float yIter=ceil(user_dy<0.0 ? abs(user_y/user_dy):(1.0-user_y)/user_dy);float zIter=ceil(user_dz<0.0 ? float(LOOP_MAX):(maxHeight-user_z)/user_dz);int iter=int(min(xIter,min(yIter,zIter)));float user_distance=(sqrt(pow(user_dx*user_width,2.0)+pow(user_dy*user_height,2.0))*user_kmPerPixel)/earthRadiusInKm;for(int safeI=0;safeI<LOOP_MAX;safeI++){if(safeI>iter){break;}cur_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(cur_height-user_z>shadow_bias){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;vec4 result=texture2D(user_a,vec2(user_x,user_y));iter=0;break;}}user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;}}if((user_lit==1.0)){if(u_outputLocationShadeProfile==true&&u_sunColor==shade_color){float timeInSun=pow(.7,pow(sin(sun_altitude),.678))*sin(sun_altitude)*(1.0/0.7);float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,1.0);}else{color(u_sunColor);}}else{color(shade_color);}if(user_outputSunExposure){vec4 aggregateColor=texture2D(user_sunExposureTexture,vec2(vTexCoordFull.x,vTexCoordFull.y));float timeInSun=1.0-aggregateColor.r;float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,0.5);}}void main(void){kernel();gl_FragColor=actualColor;}"});i.useProgram(o);const a=i.createBuffer(),s=i.getAttribLocation(o,"a_pos"),u=i.createBuffer(),h=i.getAttribLocation(o,"a_tex_pos"),l=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,l),i.bufferData(i.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),i.STATIC_DRAW);const c=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,c),i.bufferData(i.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),i.STATIC_DRAW);const f=i.getUniformLocation(o,"user_a");i.uniform1i(f,0);const m=i.getUniformLocation(o,"user_width"),d=i.getUniformLocation(o,"user_height"),_=i.getUniformLocation(o,"user_maxHeight"),x=i.getUniformLocation(o,"user_zoom"),g=i.getUniformLocation(o,"user_topYCoord"),p=i.getUniformLocation(o,"user_ySize"),E=i.getUniformLocation(o,"user_step"),T=i.getUniformLocation(o,"user_west"),v=i.getUniformLocation(o,"user_dLng"),y=i.getUniformLocation(o,"user_dec"),A=i.getUniformLocation(o,"user_Hi"),R=i.getUniformLocation(o,"user_color"),b=i.getUniformLocation(o,"u_below_canopy"),M=i.getUniformLocation(o,"user_sunExposureTexture"),w=i.getUniformLocation(o,"user_outputSunExposure"),F=i.getUniformLocation(o,"u_outputShadeProfile"),U=i.getUniformLocation(o,"u_gpxTexture"),D=i.getUniformLocation(o,"u_decHiTexture"),L=i.getUniformLocation(o,"u_sunColor"),P=i.getUniformLocation(o,"u_outputLocationShadeProfile"),C=i.getUniformLocation(o,"u_shadeProfileLocation"),S=i.createTexture();let B=0,I=0,N=0,O=null;const X=()=>{I&&N&&(i.useProgram(o),i.bindBuffer(i.ARRAY_BUFFER,a),i.enableVertexAttribArray(s),i.vertexAttribPointer(s,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,u),i.enableVertexAttribArray(h),i.vertexAttribPointer(h,2,i.FLOAT,!1,0,0),null!==O&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,O)),r(i,I,N),i.viewport(0,0,I,N),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4))};let z=0,G=0,H=0,W="";const Y=t=>{const e=(t.endTime-t.startTime)/86400/1e3,r=1440;if(i.activeTexture(i.TEXTURE3),i.uniform1i(D,3),t.startTime!==G||t.endTime!==H||t.tzId!==W){G=t.startTime,H=t.endTime,W=t.tzId;const n=[],o=828e5,a=K(new Date(G),W);for(let t=0;t<e;t++){const e=K(new Date(G+86400*t*1e3+o),W)-a;n[t]=e}const s=new Float32Array(r*e*2);for(let t=0;t<r;t++)for(let r=0;r<e;r++){const i=G+86400*r*1e3+60*t*1e3,{dec:o,Hi:a}=Z(i+n[r]);s[2*(t*e+r)]=-o,s[2*(t*e+r)+1]=a/10}at({gl:i,texture:S,imageData:s,width:e,height:r,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RG,internalFormat:i.RG32F,type:i.FLOAT})}else i.bindTexture(i.TEXTURE_2D,S);return{outputWidth:e,outputHeight:r}};return{updateHeightMap:function(t){const{heightMapTex:e,width:r,height:n,maxHeight:s,heightMapZoom:h,topYCoord:l,ySize:c,colorVec:f,step:M,west:w,dLng:F,dec:U,Hi:D,cornerClipCoords:L,cornerTextureCoords:P,outputWidth:C,outputHeight:S,belowCanopy:z,skipRender:G}=t;i.useProgram(o),I=C,N=S,O=e,i.bindBuffer(i.ARRAY_BUFFER,a),i.bufferData(i.ARRAY_BUFFER,new Float32Array(L),i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,u),i.bufferData(i.ARRAY_BUFFER,new Float32Array(P),i.STATIC_DRAW),i.uniform1f(m,r),i.uniform1f(d,n),i.uniform1f(_,s),i.uniform1f(x,h),i.uniform1f(g,l),i.uniform1f(p,c),i.uniform4fv(R,f),i.uniform1f(E,M),i.uniform1f(T,w),i.uniform1f(v,F),i.uniform1f(y,U),i.uniform1f(A,D),i.uniform1f(b,z?1:0),G||(window.cancelAnimationFrame(B),B=window.requestAnimationFrame(X))},updateDate:t=>{const{dec:e,Hi:r}=t;i.useProgram(o),i.uniform1f(y,e),i.uniform1f(A,r),window.cancelAnimationFrame(B),B=window.requestAnimationFrame(X)},updateDateRange:t=>n(this,void 0,void 0,(function*(){const{startDate:e,endDate:r,iterations:n,emit:l}=t;i.useProgram(o);const c=z=Date.now(),f=Math.floor((r.getTime()-e.getTime())/n),m=i.getUniform(o,R),d=I,_=N,x=i.createTexture();i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,x),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,d,_,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);const g=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,g);const p=i.COLOR_ATTACHMENT0;i.framebufferTexture2D(i.FRAMEBUFFER,p,i.TEXTURE_2D,x,0);for(let t=0;t<n;t++){if(i.useProgram(o),l("tileloaded",t,n-1),c!==z)return i.deleteFramebuffer(g),i.deleteTexture(x),i.uniform4fv(R,m),!0;yield new Promise(((r,l)=>{window.requestAnimationFrame((()=>{i.useProgram(o),null!==O&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,O)),i.bindFramebuffer(i.FRAMEBUFFER,g);const l=i.checkFramebufferStatus(i.FRAMEBUFFER);l!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+l);const{dec:c,Hi:m}=j(new Date(e.getTime()+f*t));i.uniform1f(y,c),i.uniform1f(A,m),i.uniform4fv(R,[1/n,0,0,1]),i.bindBuffer(i.ARRAY_BUFFER,a),i.enableVertexAttribArray(s),i.vertexAttribPointer(s,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,u),i.enableVertexAttribArray(h),i.vertexAttribPointer(h,2,i.FLOAT,!1,0,0),i.viewport(0,0,d,_),i.enable(i.BLEND),i.blendFunc(i.ONE,i.ONE),i.drawArrays(i.TRIANGLE_STRIP,0,4),r()}))}))}return i.deleteFramebuffer(g),yield new Promise(((t,e)=>{window.requestAnimationFrame((()=>{if(i.useProgram(o),c!==z)return i.deleteTexture(x),i.uniform4fv(R,m),void t(!0);i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,x),i.uniform1i(M,2),i.uniform1i(w,1),X(),i.uniform1i(w,0),i.uniform1i(M,0),i.deleteTexture(x),i.uniform4fv(R,m),t(!1)}))}))})),updateColor:t=>{const{colorVec:e}=t;i.useProgram(o),i.uniform4fv(R,e),window.cancelAnimationFrame(B),B=window.requestAnimationFrame(X)},generateShadeProfile:t=>{i.useProgram(o);const{dates:e,texCoords:r,shadeColor:n,sunColor:a}=t,u=r.length,f=e.length,m=i.getUniform(o,R);i.uniform4fv(R,n),i.uniform4fv(L,a),i.uniform1i(F,1);const d=i.createTexture();i.activeTexture(i.TEXTURE3),at({gl:i,imageData:null,width:u,height:f,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,texture:d});const _=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,_),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,d,0);const x=i.checkFramebufferStatus(i.FRAMEBUFFER);x!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+x);const g=r.map((t=>[t[0],t[1]])).flat(),p=i.createTexture();i.activeTexture(i.TEXTURE2),at({gl:i,texture:p,imageData:new Float32Array(g),width:g.length/2,height:1,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RG,internalFormat:i.RG32F,type:i.FLOAT}),i.uniform1i(U,2);const E=e.map((t=>{const{dec:e,Hi:r}=j(t);return[-e,r/10]})).flat(),T=i.createTexture();i.activeTexture(i.TEXTURE1),at({gl:i,texture:T,imageData:new Float32Array(E),width:1,height:e.length,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RG,internalFormat:i.RG32F,type:i.FLOAT}),i.uniform1i(D,1),null!==O&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,O)),i.bindBuffer(i.ARRAY_BUFFER,l),i.enableVertexAttribArray(s),i.vertexAttribPointer(s,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,c),i.enableVertexAttribArray(h),i.vertexAttribPointer(h,2,i.FLOAT,!1,0,0),i.viewport(0,0,u,f),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4);const v=new Uint8Array(u*f*4);return i.readPixels(0,0,u,f,i.RGBA,i.UNSIGNED_BYTE,v),i.deleteTexture(d),i.deleteTexture(T),i.deleteTexture(p),i.deleteFramebuffer(_),i.uniform1i(D,0),i.uniform1i(U,0),i.uniform1i(F,0),i.uniform4fv(R,m),i.uniform4fv(L,[0,0,0,0]),v},generateLocationShadeProfile:t=>{i.useProgram(o);const{startTime:e,endTime:r,tzId:n,texCoord:a,shadeColor:u,sunColor:f}=t,m=i.getUniform(o,R),{outputWidth:d,outputHeight:_}=Y({startTime:e,endTime:r,tzId:n});i.uniform4fv(R,u),i.uniform4fv(L,f),i.uniform1i(P,1),i.uniform2fv(C,[a[0],a[1]]);const x=i.createTexture();i.activeTexture(i.TEXTURE2),at({gl:i,imageData:null,width:d,height:_,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,texture:x});const g=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,g),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,x,0);const p=i.checkFramebufferStatus(i.FRAMEBUFFER);p!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+p),null!==O&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,O)),i.bindBuffer(i.ARRAY_BUFFER,l),i.enableVertexAttribArray(s),i.vertexAttribPointer(s,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,c),i.enableVertexAttribArray(h),i.vertexAttribPointer(h,2,i.FLOAT,!1,0,0),i.viewport(0,0,d,_),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4);const E=new Uint8Array(d*_*4);return i.readPixels(0,0,d,_,i.RGBA,i.UNSIGNED_BYTE,E),i.deleteTexture(x),i.deleteFramebuffer(g),i.uniform1i(D,0),i.uniform1i(P,0),i.uniform4fv(R,m),i.uniform4fv(L,[0,0,0,0]),{output:E,outputWidth:d,outputHeight:_}}}}({context:this._gl,setRenderBuffer:t=>{t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.bindFramebuffer(t.FRAMEBUFFER,null)}}),this._buildingRasterizer=new ut(this._gl),this._tileMerger=new lt(this._gl)}addTo(t){return this.onAdd(t)}onAdd(t){if(this._map=t,!this._canvasOverlay&&this._canvas){const t=this._map.getBounds();this._canvasOverlay=function(...t){return new i(...t)}(this._canvas,t),this._canvasOverlay.addTo(this._map)}return this._map.on("moveend",this._reset),this._map.attributionControl.addAttribution('<a href="https://shademap.app/about">&copy; ShadeMap</a>'),this._reset(),this}_repositionCanvas(t){if(this._canvasOverlay&&this._canvasOverlay.setBounds(t),this._map){const{x:t,y:e}=this._map.getSize();this._canvas.width=t,this._canvas.height=e}this._flush()}_flush(){this.emit("idle")}}void 0!==window.L&&(window.L.shadeMap=(...t)=>new ct(...t));export{ct as default};
8
+ import{ImageOverlay as t,DomUtil as e,Util as r}from"leaflet";class o extends t{constructor(t,e,r={}){super("",e,r),this._url=t}_initImage(){const t="CANVAS"===this._url.tagName,o=this._image=t?this._url:e.create("canvas");return e.addClass(o,"leaflet-image-layer"),this._zoomAnimated&&e.addClass(o,"leaflet-zoom-animated"),this.options.className&&e.addClass(o,this.options.className),o.onselectstart=r.falseFn,o.onmousemove=r.falseFn,this}setBounds(t){return this._bounds=t,this._map&&this._reset(),this}}function n(t,e,r,o){return new(r||(r=Promise))((function(n,i){function a(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((o=o.apply(t,e||[])).next())}))}function i(t,e,r){r=r||2;var o,n,i,s,l,h,c,f=e&&e.length,_=f?e[0]*r:t.length,x=a(t,0,_,r,!0),p=[];if(!x||x.next===x.prev)return p;if(f&&(x=function(t,e,r,o){var n,i,s,u=[];for(n=0,i=e.length;n<i;n++)(s=a(t,e[n]*o,n<i-1?e[n+1]*o:t.length,o,!1))===s.next&&(s.steiner=!0),u.push(g(s));for(u.sort(d),n=0;n<u.length;n++)r=m(u[n],r);return r}(t,e,x,r)),t.length>80*r){o=i=t[0],n=s=t[1];for(var E=r;E<_;E+=r)(l=t[E])<o&&(o=l),(h=t[E+1])<n&&(n=h),l>i&&(i=l),h>s&&(s=h);c=0!==(c=Math.max(i-o,s-n))?32767/c:0}return u(x,p,r,o,n,c,0),p}function a(t,e,r,o,n){var i,a;if(n===U(t,e,r,o)>0)for(i=e;i<r;i+=o)a=w(i,t[i],t[i+1],a);else for(i=r-o;i>=e;i-=o)a=w(i,t[i],t[i+1],a);return a&&T(a,a.next)&&(F(a),a=a.next),a}function s(t,e){if(!t)return t;e||(e=t);var r,o=t;do{if(r=!1,o.steiner||!T(o,o.next)&&0!==v(o.prev,o,o.next))o=o.next;else{if(F(o),(o=e=o.prev)===o.next)break;r=!0}}while(r||o!==e);return e}function u(t,e,r,o,n,i,a){if(t){!a&&i&&function(t,e,r,o){var n=t;do{0===n.z&&(n.z=x(n.x,n.y,e,r,o)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next}while(n!==t);n.prevZ.nextZ=null,n.prevZ=null,function(t){var e,r,o,n,i,a,s,u,l=1;do{for(r=t,t=null,i=null,a=0;r;){for(a++,o=r,s=0,e=0;e<l&&(s++,o=o.nextZ);e++);for(u=l;s>0||u>0&&o;)0!==s&&(0===u||!o||r.z<=o.z)?(n=r,r=r.nextZ,s--):(n=o,o=o.nextZ,u--),i?i.nextZ=n:t=n,n.prevZ=i,i=n;r=o}i.nextZ=null,l*=2}while(a>1)}(n)}(t,o,n,i);for(var d,m,_=t;t.prev!==t.next;)if(d=t.prev,m=t.next,i?h(t,o,n,i):l(t))e.push(d.i/r|0),e.push(t.i/r|0),e.push(m.i/r|0),F(t),t=m.next,_=m.next;else if((t=m)===_){a?1===a?u(t=c(s(t),e,r),e,r,o,n,i,2):2===a&&f(t,e,r,o,n,i):u(s(t),e,r,o,n,i,1);break}}}function l(t){var e=t.prev,r=t,o=t.next;if(v(e,r,o)>=0)return!1;for(var n=e.x,i=r.x,a=o.x,s=e.y,u=r.y,l=o.y,h=n<i?n<a?n:a:i<a?i:a,c=s<u?s<l?s:l:u<l?u:l,f=n>i?n>a?n:a:i>a?i:a,d=s>u?s>l?s:l:u>l?u:l,m=o.next;m!==e;){if(m.x>=h&&m.x<=f&&m.y>=c&&m.y<=d&&p(n,s,i,u,a,l,m.x,m.y)&&v(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function h(t,e,r,o){var n=t.prev,i=t,a=t.next;if(v(n,i,a)>=0)return!1;for(var s=n.x,u=i.x,l=a.x,h=n.y,c=i.y,f=a.y,d=s<u?s<l?s:l:u<l?u:l,m=h<c?h<f?h:f:c<f?c:f,_=s>u?s>l?s:l:u>l?u:l,g=h>c?h>f?h:f:c>f?c:f,E=x(d,m,e,r,o),T=x(_,g,e,r,o),y=t.prevZ,b=t.nextZ;y&&y.z>=E&&b&&b.z<=T;){if(y.x>=d&&y.x<=_&&y.y>=m&&y.y<=g&&y!==n&&y!==a&&p(s,h,u,c,l,f,y.x,y.y)&&v(y.prev,y,y.next)>=0)return!1;if(y=y.prevZ,b.x>=d&&b.x<=_&&b.y>=m&&b.y<=g&&b!==n&&b!==a&&p(s,h,u,c,l,f,b.x,b.y)&&v(b.prev,b,b.next)>=0)return!1;b=b.nextZ}for(;y&&y.z>=E;){if(y.x>=d&&y.x<=_&&y.y>=m&&y.y<=g&&y!==n&&y!==a&&p(s,h,u,c,l,f,y.x,y.y)&&v(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;b&&b.z<=T;){if(b.x>=d&&b.x<=_&&b.y>=m&&b.y<=g&&b!==n&&b!==a&&p(s,h,u,c,l,f,b.x,b.y)&&v(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function c(t,e,r){var o=t;do{var n=o.prev,i=o.next.next;!T(n,i)&&y(n,o,o.next,i)&&R(n,i)&&R(i,n)&&(e.push(n.i/r|0),e.push(o.i/r|0),e.push(i.i/r|0),F(o),F(o.next),o=t=i),o=o.next}while(o!==t);return s(o)}function f(t,e,r,o,n,i){var a=t;do{for(var l=a.next.next;l!==a.prev;){if(a.i!==l.i&&E(a,l)){var h=M(a,l);return a=s(a,a.next),h=s(h,h.next),u(a,e,r,o,n,i,0),void u(h,e,r,o,n,i,0)}l=l.next}a=a.next}while(a!==t)}function d(t,e){return t.x-e.x}function m(t,e){var r=function(t,e){var r,o=e,n=t.x,i=t.y,a=-1/0;do{if(i<=o.y&&i>=o.next.y&&o.next.y!==o.y){var s=o.x+(i-o.y)*(o.next.x-o.x)/(o.next.y-o.y);if(s<=n&&s>a&&(a=s,r=o.x<o.next.x?o:o.next,s===n))return r}o=o.next}while(o!==e);if(!r)return null;var u,l=r,h=r.x,c=r.y,f=1/0;o=r;do{n>=o.x&&o.x>=h&&n!==o.x&&p(i<c?n:a,i,h,c,i<c?a:n,i,o.x,o.y)&&(u=Math.abs(i-o.y)/(n-o.x),R(o,t)&&(u<f||u===f&&(o.x>r.x||o.x===r.x&&_(r,o)))&&(r=o,f=u)),o=o.next}while(o!==l);return r}(t,e);if(!r)return e;var o=M(r,t);return s(o,o.next),s(r,r.next)}function _(t,e){return v(t.prev,t,e.prev)<0&&v(e.next,t,t.next)<0}function x(t,e,r,o,n){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*n|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-o)*n|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function g(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 p(t,e,r,o,n,i,a,s){return(n-a)*(e-s)>=(t-a)*(i-s)&&(t-a)*(o-s)>=(r-a)*(e-s)&&(r-a)*(i-s)>=(n-a)*(o-s)}function E(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&&y(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(R(t,e)&&R(e,t)&&function(t,e){var r=t,o=!1,n=(t.x+e.x)/2,i=(t.y+e.y)/2;do{r.y>i!=r.next.y>i&&r.next.y!==r.y&&n<(r.next.x-r.x)*(i-r.y)/(r.next.y-r.y)+r.x&&(o=!o),r=r.next}while(r!==t);return o}(t,e)&&(v(t.prev,t,e.prev)||v(t,e.prev,e))||T(t,e)&&v(t.prev,t,t.next)>0&&v(e.prev,e,e.next)>0)}function v(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function T(t,e){return t.x===e.x&&t.y===e.y}function y(t,e,r,o){var n=A(v(t,e,r)),i=A(v(t,e,o)),a=A(v(r,o,t)),s=A(v(r,o,e));return n!==i&&a!==s||(!(0!==n||!b(t,r,e))||(!(0!==i||!b(t,o,e))||(!(0!==a||!b(r,t,o))||!(0!==s||!b(r,e,o)))))}function b(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 A(t){return t>0?1:t<0?-1:0}function R(t,e){return v(t.prev,t,t.next)<0?v(t,e,t.next)>=0&&v(t,t.prev,e)>=0:v(t,e,t.prev)<0||v(t,t.next,e)<0}function M(t,e){var r=new L(t.i,t.x,t.y),o=new L(e.i,e.x,e.y),n=t.next,i=e.prev;return t.next=e,e.prev=t,r.next=n,n.prev=r,o.next=r,r.prev=o,i.next=o,o.prev=i,o}function w(t,e,r,o){var n=new L(t,e,r);return o?(n.next=o.next,n.prev=o,o.next.prev=n,o.next=n):(n.prev=n,n.next=n),n}function F(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 L(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 U(t,e,r,o){for(var n=0,i=e,a=r-o;i<r;i+=o)n+=(t[a]-t[i])*(t[i+1]+t[a+1]),a=i;return n}function D(t,e,r){var o=e[1],n=e[0],i=o-n;return t===o&&r?t:((t-n)%i+i)%i+n}function P(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}i.deviation=function(t,e,r,o){var n=e&&e.length,i=n?e[0]*r:t.length,a=Math.abs(U(t,0,i,r));if(n)for(var s=0,u=e.length;s<u;s++){var l=e[s]*r,h=s<u-1?e[s+1]*r:t.length;a-=Math.abs(U(t,l,h,r))}var c=0;for(s=0;s<o.length;s+=3){var f=o[s]*r,d=o[s+1]*r,m=o[s+2]*r;c+=Math.abs((t[f]-t[m])*(t[d+1]-t[f+1])-(t[f]-t[d])*(t[m+1]-t[f+1]))}return 0===a&&0===c?0:Math.abs((c-a)/a)},i.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},o=0,n=0;n<t.length;n++){for(var i=0;i<t[n].length;i++)for(var a=0;a<e;a++)r.vertices.push(t[n][i][a]);n>0&&(o+=t[n-1].length,r.holes.push(o))}return r};var S=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function C(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var B=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function I(t,e,r){return t instanceof C?t:S(t)?new C(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new C(t.x,t.y):new C(t,e,r)}function N(t,e){if(t)for(var r=e?[t,e]:t,o=0,n=r.length;o<n;o++)this.extend(r[o])}function O(t,e){return!t||t instanceof N?t:new N(t,e)}function z(t,e){if(t)for(var r=e?[t,e]:t,o=0,n=r.length;o<n;o++)this.extend(r[o])}function X(t,e){return t instanceof z?t:new z(t,e)}C.prototype={clone:function(){return new C(this.x,this.y)},add:function(t){return this.clone()._add(I(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(I(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 C(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new C(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=B(this.x),this.y=B(this.y),this},distanceTo:function(t){var e=(t=I(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=I(t)).x===this.x&&t.y===this.y},contains:function(t){return t=I(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+P(this.x)+", "+P(this.y)+")"}},N.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof C||"number"==typeof t[0]||"x"in t)e=r=I(t);else if(e=(t=O(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 I((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return I(this.min.x,this.max.y)},getTopRight:function(){return I(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 C?I(t):O(t))instanceof N?(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=O(t);var e=this.min,r=this.max,o=t.min,n=t.max,i=n.x>=e.x&&o.x<=r.x,a=n.y>=e.y&&o.y<=r.y;return i&&a},overlaps:function(t){t=O(t);var e=this.min,r=this.max,o=t.min,n=t.max,i=n.x>e.x&&o.x<r.x,a=n.y>e.y&&o.y<r.y;return i&&a},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,o=Math.abs(e.x-r.x)*t,n=Math.abs(e.y-r.y)*t;return O(I(e.x-o,e.y-n),I(r.x+o,r.y+n))},equals:function(t){return!!t&&(t=O(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},z.prototype={extend:function(t){var e,r,o=this._southWest,n=this._northEast;if(t instanceof H)e=t,r=t;else{if(!(t instanceof z))return t?this.extend(W(t)||X(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return o||n?(o.lat=Math.min(e.lat,o.lat),o.lng=Math.min(e.lng,o.lng),n.lat=Math.max(r.lat,n.lat),n.lng=Math.max(r.lng,n.lng)):(this._southWest=new H(e.lat,e.lng),this._northEast=new H(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,o=Math.abs(e.lat-r.lat)*t,n=Math.abs(e.lng-r.lng)*t;return new z(new H(e.lat-o,e.lng-n),new H(r.lat+o,r.lng+n))},getCenter:function(){return new H((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 H(this.getNorth(),this.getWest())},getSouthEast:function(){return new H(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 H||"lat"in t?W(t):X(t);var e,r,o=this._southWest,n=this._northEast;return t instanceof z?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=o.lat&&r.lat<=n.lat&&e.lng>=o.lng&&r.lng<=n.lng},intersects:function(t){t=X(t);var e=this._southWest,r=this._northEast,o=t.getSouthWest(),n=t.getNorthEast(),i=n.lat>=e.lat&&o.lat<=r.lat,a=n.lng>=e.lng&&o.lng<=r.lng;return i&&a},overlaps:function(t){t=X(t);var e=this._southWest,r=this._northEast,o=t.getSouthWest(),n=t.getNorthEast(),i=n.lat>e.lat&&o.lat<r.lat,a=n.lng>e.lng&&o.lng<r.lng;return i&&a},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=X(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var G=function(t){var e,r,o,n;for(r=1,o=arguments.length;r<o;r++)for(e in n=arguments[r])t[e]=n[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),o=this.scale(e);return this.transformation._transform(r,o)},pointToLatLng:function(t,e){var r=this.scale(e),o=this.transformation.untransform(t,r);return this.projection.unproject(o)},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 N(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(t){var e=this.wrapLng?D(t.lng,this.wrapLng,!0):t.lng;return new H(this.wrapLat?D(t.lat,this.wrapLat,!0):t.lat,e,t.alt)},wrapLatLngBounds:function(t){var e=t.getCenter(),r=this.wrapLatLng(e),o=e.lat-r.lat,n=e.lng-r.lng;if(0===o&&0===n)return t;var i=t.getSouthWest(),a=t.getNorthEast();return new z(new H(i.lat-o,i.lng-n),new H(a.lat-o,a.lng-n))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,o=t.lat*r,n=e.lat*r,i=Math.sin((e.lat-t.lat)*r/2),a=Math.sin((e.lng-t.lng)*r/2),s=i*i+Math.cos(o)*Math.cos(n)*a*a,u=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s));return this.R*u}});function H(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 W(t,e,r){return t instanceof H?t:S(t)&&"object"!=typeof t[0]?3===t.length?new H(t[0],t[1],t[2]):2===t.length?new H(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new H(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new H(t,e,r)}H.prototype={equals:function(t,e){return!!t&&(t=W(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("+P(this.lat,t)+", "+P(this.lng,t)+")"},distanceTo:function(t){return G.distance(this,W(t))},wrap:function(){return G.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return X([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new H(this.lat,this.lng,this.alt)}};const j=t=>{const e=t.valueOf();return Z(e)},Z=t=>{const e=t/864e5-10957.5,r=6.240059966692059+.017201969994578018*e,o=r+.017453292519943295*(1.9148*Math.sin(r)+.02*Math.sin(2*r)+3e-4*Math.sin(3*r))+1.796593062783907+Math.PI,n=Math.atan2(Math.sin(o)*Math.cos(.40909994067971484),Math.cos(o));return{dec:Math.asin(Math.sin(.40909994067971484)*Math.sin(o)),Hi:(4.889714432387314+6.3003876824396166*e-n)%(2*Math.PI)+2*Math.PI}},Y=(t,e,r)=>{const o=1/e,n=Math.min(t[0]*o,255),i=Math.min(t[1]*o,255),a=Math.min(t[2]*o,255);let s=0;return n+i+a!==0&&(s=n>0?n/255*.5+.5:a>0?.5*(1-a/255):.5),s*r},K=(t=new Date,e)=>{const r=new Date(t.toLocaleString("en-US",{timeZone:"UTC"})),o=new Date(t.toLocaleString("en-US",e?{timeZone:e}:{}));return r.getTime()-o.getTime()};function k(t){t.filter((t=>"MultiPolygon"===t.geometry.type)).forEach((e=>{const{geometry:r,properties:o,type:n}=e;if("MultiPolygon"===r.type)for(let o=0;o<r.coordinates.length;o++)t.push(Object.assign(Object.assign({},e),{geometry:Object.assign(Object.assign({},r),{type:"Polygon",coordinates:r.coordinates[o]})}))}));return t.filter((t=>"Polygon"===t.geometry.type)).map((t=>{const{geometry:e,properties:r}=t,{vertices:o}=i.flatten(e.coordinates),n=new Float32Array(o.map(((t,e)=>{return e%2==1?(r=t,(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+r*Math.PI/360)))/360):(180+t)/360;var r}))),a=i(n),s=a.length>256?new Uint16Array(a):new Uint8Array(a),u=function(t){const{height:e=0,levels:r=0,render_height:o=0}=t;if(r)return 3.04*r;return Math.max(e,o)}(r),l=r.highlight||!1;let h=0,c=0,f=0;for(let t=0;t<n.length;t+=2)h+=n[t],c+=n[t+1],f++;return{aPosition:n,cuts:s,buildingHeight:u,centroid:[h/f,c/f],highlight:l}}))}const V=(t,e)=>{const{lat:r,lng:o}=t;return new C(((t,e)=>(t+180)/360*Math.pow(2,e)*256)(o,e),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*256)(r,e))},q=(t,e)=>{return new H((r=t.y,o=e,n=Math.PI-2*Math.PI*r/256/Math.pow(2,o),180/Math.PI*Math.atan(.5*(Math.exp(n)-Math.exp(-n)))),function(t,e){return t/256/Math.pow(2,e)*360-180}(t.x,e));var r,o,n};let $,J={heightMapTex:null,width:0,height:0,visibleDEMPixelBounds:new N(new C(0,0),new C(0,0)),DEMPixelBounds:new N(new C(0,0),new C(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const Q=t=>n(void 0,void 0,void 0,(function*(){const{demZoom:e,getFeatures:r,terrainSource:o,dsmSource:i,tileLoaded:a,gl:s,bounds:u,buildingRasterizer:l,tileMerger:h,forceUpdate:c=!1}=t,{getSourceUrl:f,getElevation:d,maxZoom:m,tileSize:_,_overzoom:x}=o,g=(p={getFeatures:r},n(void 0,void 0,void 0,(function*(){const{getFeatures:t}=p;try{return k(yield t())}catch(t){console.log("Error merging buildings",t)}return[]})));var p;try{const t=u,r=t.getNorthWest(),o=t.getSouthEast(),n=new N(V(r,e),V(o,e));let x=new C(n.min.x,n.min.y),p=n.max.x-n.min.x;const E=n.max.y-n.min.y,v=n.max.subtract(n.min);v.y>v.x&&(x.x-=256,p+=512);const T=(t=>{const{upperLeft:e,width:r,height:o}=t,n=e.divideBy(256).floor().multiplyBy(256),i=256*(Math.ceil(r/256)+1),a=256*(Math.ceil(o/256)+1),s=n.add([i,a]);return new N(n,s)})({upperLeft:x,width:p,height:E}),{x:y,y:b}=T.max.subtract(T.min),A=(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 o=Math.pow(2,t.z);return{x:(t.x%o+o)%o,y:(t.y%o+o)%o,z:t.z,xOffset:256*(t.x-e),yOffset:256*(t.y-r)}}))})((t=>{const{upperLeft:e,width:r,height:o,zoom:n}=t,i=e.divideBy(256).floor(),a=i.x+r/256,s=Math.min(i.y+o/256,Math.pow(2,n)-1),u=[];for(var l=i.x;l<a;l++)for(var h=i.y;h<s;h++)u.push({x:l,y:h,z:n});return u})({upperLeft:T.min,width:y,height:b,zoom:e})),R=n.max.x-n.min.x,M=n.max.y-n.min.y,w=Math.round(R),F=Math.round(M),L=JSON.stringify(A);if(!c&&L===$&&e<m)return J=Object.assign(Object.assign({},J),{outputWidth:w,outputHeight:F,visibleDEMPixelBounds:n,demZoom:e,dirty:!0}),J;const U=yield h.merge(A,{maxZoom:m,width:y,height:b,crossOrigin:"Anonymous",getSourceUrl:f,getElevation:d,tileSize:_,tileLoaded:a});if(null===U)return J=Object.assign(Object.assign({},J),{visibleDEMPixelBounds:n,demZoom:e,dirty:!1}),J;const D=new N(V(new z(i.bounds).getNorthWest(),e),V(new z(i.bounds).getSouthEast(),e)),P=D.min.subtract(T.min),S=D.max.subtract(T.min),B=[P.x/y,P.y/b,S.x/y,S.y/b].map((t=>2*t-1)),I=yield g,{maxHeight:O,heightMapTex:X}=l.raster({upperLeftTile:A[0],width:y,height:b,mapZoom:e,features:I,imageData:U,gl:s,dsmSource:i,dsmCoords:B}),G=Math.max(i.maxHeight,U.maxHeight+O);$=L,J={heightMapTex:X,maxHeight:G,width:y,height:b,DEMPixelBounds:T,visibleDEMPixelBounds:n,raster:A,demZoom:e,dirty:!0,outputWidth:w,outputHeight:F}}catch(t){console.error("Could not decode height map",t)}return J})),tt=(t,e)=>{const{r:r,g:o,b:n}=t;return[r/255,o/255,n/255,e]},et=(t,e)=>{const{date:r}=e,{dec:o,Hi:n}=j(r);t.updateDate({dec:o,Hi:n})},rt=(t,e)=>n(void 0,void 0,void 0,(function*(){return yield t.updateDateRange(Object.assign({},e))})),ot=(t,e)=>{const{color:r,opacity:o}=e,n=tt(r,o);t.updateColor({colorVec:n})},nt=t=>{const{kernel:e,map:r,heightMap:o,now:n,color:i,opacity:a,belowCanopy:s,skipRender:u}=t;try{const{heightMapTex:t,outputHeight:l,outputWidth:h,maxHeight:c,width:f,height:d,DEMPixelBounds:m,visibleDEMPixelBounds:_,demZoom:x}=o;if(0===f||0===d)return;const{min:g,max:p}=_;if(!g||!p)return;const{x:E,y:v}=p.subtract(g),T=m.min,y=r.getPixelDimensions(),b=r.screenUnproject([0,0]),A=r.screenUnproject([y.width,0]),R=r.screenUnproject([y.width,y.height]),M=r.screenUnproject([0,y.height]),w=[M,R,b,A].map((t=>r.project(t,x))),F=w.map((t=>[(t.x-T.x)/f,(t.y-T.y)/d])).flat(),L=w.map((t=>[(t.x-g.x)/E,(t.y-g.y)/v])).map((t=>[2*t[0]-1,(2*t[1]-1)*(r.isLeaflet()?-1:1)])).flat(),U=T.y/256/Math.pow(2,x),D=d/256/Math.pow(2,x),P=new z(q(m.getTopLeft(),x),q(m.getBottomRight(),x)),S=P.getWest(),C=Math.abs(P.getWest()-P.getEast());((t,e)=>{const{color:r,opacity:o,date:n}=e,i=tt(r,o),{dec:a,Hi:s}=j(n);t.updateHeightMap(Object.assign({dec:a,Hi:s,colorVec:i,step:1},e))})(e,{heightMapTex:t,maxHeight:c,width:f,height:d,heightMapZoom:x,cornerTextureCoords:F,cornerClipCoords:L,topYCoord:U,ySize:D,west:S,dLng:C,date:n,color:i,opacity:a,outputHeight:l,outputWidth:h,belowCanopy:s,skipRender:u})}catch(t){console.error("EXCEPTION",t)}};const it=t=>{const e=()=>!t.getPitch;return{project:(r,o)=>{if(e())return t.project(r,o);{const{lat:t,lng:e}=r;return new C(((t,e)=>(t+180)/360*Math.pow(2,e)*256)(e,o),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*256)(t,o))}},unproject:(r,o)=>{return e()?t.unproject(r,o):new H((n=r.y,i=o,a=Math.PI-2*Math.PI*n/256/Math.pow(2,i),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/256/Math.pow(2,e)*360-180}(r.x,o));var n,i,a},screenUnproject:r=>e()?t.containerPointToLatLng(r):t.unproject(r),getZoom:()=>e()?t.getZoom():t.getZoom()+1,getCenter:()=>t.getCenter(),getBounds:()=>t.getBounds(),eachLayer:r=>{e()&&t.eachLayer(r)},getBearing:()=>e()?0:t.getBearing(),getPitch:()=>e()?0:t.getPitch(),rawMap:()=>t,isLeaflet:e,getPixelDimensions:()=>{const e=t.getContainer();return{width:e.clientWidth,height:e.clientHeight}},createBounds:t=>{const{nw:e,se:r}=t;return new z(e,r)}}};const at=t=>{const{gl:e}=t,{texture:r,imageData:o=null,format:n=e.RGBA,width:i,height:a,filter:s=e.NEAREST,wrap:u=e.CLAMP_TO_EDGE,type:l=e.UNSIGNED_BYTE,internalFormat:h=n}=t;e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,s),e.texImage2D(e.TEXTURE_2D,0,h,i,a,0,n,l,o)};function st(t){const{gl:e,vSrc:r,fSrc:o}=t,n=e.createShader(e.VERTEX_SHADER);e.shaderSource(n,r),e.compileShader(n);const i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(i,o),e.compileShader(i);const a=e.createProgram();return e.attachShader(a,n),e.attachShader(a,i),e.linkProgram(a),a}class ut{constructor(t){this.gl=t,this.program=st({gl:t,vSrc:"\nuniform vec3 xyz;\nuniform vec2 dimensions;\nuniform bool use_dsm;\nuniform vec2 u_centroid;\nuniform sampler2D height_map;\nattribute vec2 dsm_position;\nattribute vec2 a_position;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\nvarying vec4 v_elevation;\n\n\tvoid main() {\n\t\tif (use_dsm == true) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = dsm_position;\n v_use_dsm = 1.0;\n\t\t\treturn;\n\t\t}\n\t\tif (abs(a_position) == vec2(1,1)) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = a_position * 0.5 + 0.5;\n\t\t\treturn;\n\t\t}\n\t\tfloat x = a_position.x - xyz.x;\n\t\tfloat y = a_position.y - 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 v_elevation = texture2D(height_map, vec2(u_centroid.x, u_centroid.y));\n\t\tgl_Position = vec4(final, 0, 1);\n\t}\n",fSrc:"\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform vec4 color;\nuniform sampler2D height_map;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\nvarying vec4 v_elevation;\n\nvec4 addElevation(vec4 color, vec4 toAdd) {\n float ground = (color.b * 255.0 * 255.0 + color.a * 255.0);\n float building = (toAdd.r * 255.0 * 255.0 + toAdd.g * 255.0);\n float elevation = ground + building;\n float r = floor(elevation / 255.0) / 255.0;\n float g = floor(mod(elevation, 255.0)) / 255.0;\n return vec4(r, g, r, g);\n}\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n if (v_use_dsm == 1.0) {\n\t \t gl_FragColor = vec4(0.0, 0.0, textureColor.b, textureColor.a);\n if (gl_FragColor.zw == vec2(0.0)) {\n discard;\n }\n } else {\n gl_FragColor = vec4(textureColor.b, textureColor.a, textureColor.b, textureColor.a);\n }\n // DSM noData values should not be included in heightMap because they produce ugly borders\n\t\treturn;\n\t} \n vec4 final = addElevation(v_elevation, color);\n\tgl_FragColor = final;\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.centroidUniformLocation=t.getUniformLocation(this.program,"u_centroid"),this.colorUniformLocation=t.getUniformLocation(this.program,"color"),this.positionBuffer=t.createBuffer(),this.dsmBuffer=t.createBuffer(),this.indexBuffer=t.createBuffer(),this.targetTexture=t.createTexture()}raster(t){const{features:e,upperLeftTile:r,mapZoom:o,width:n,height:i,imageData:a,dsmCoords:s,dsmSource:u,gl:l}=t,{x:h,y:c,z:f}=r;let d=0;l.useProgram(this.program),l.activeTexture(l.TEXTURE1),l.bindTexture(l.TEXTURE_2D,a);const m=n,_=i;l.activeTexture(l.TEXTURE0),l.bindTexture(l.TEXTURE_2D,this.targetTexture),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,m,_,0,l.RGBA,l.UNSIGNED_BYTE,null),o>15&&e.length>5?(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST)):(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.LINEAR)),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.viewport(0,0,m,_);const x=l.createFramebuffer();l.bindFramebuffer(l.FRAMEBUFFER,x);const g=l.COLOR_ATTACHMENT0;l.framebufferTexture2D(l.FRAMEBUFFER,g,l.TEXTURE_2D,this.targetTexture,0),l.disable(l.BLEND),l.bindBuffer(l.ARRAY_BUFFER,this.positionBuffer),l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,this.indexBuffer),l.clearColor(0,0,0,0),l.clear(l.COLOR_BUFFER_BIT);const p=h/Math.pow(2,f),E=c/Math.pow(2,f),v=new C(p,E),T=n/256/Math.pow(2,f),y=i/256/Math.pow(2,f);l.uniform3f(this.xyzUniformLocation,p,E,f),l.uniform2f(this.dimensionsUniformLocation,T,y),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:o,centroid:a,highlight:s}=t,u=new C(a[0],a[1]).subtract(v).unscaleBy(new C(T,y)).scaleBy(new C(n,i)).floor();if(u.x<0||u.y<0||u.x>n||u.y>i)return;const h=u.x/n,c=u.y/i,f=5*e,m=Math.floor(f/255)/255,_=Math.floor(f%255)/255;d=Math.max(d,e),l.uniform2f(this.centroidUniformLocation,h,c),l.uniform4f(this.colorUniformLocation,m,_,m,_),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,o,l.DYNAMIC_DRAW),l.drawElements(l.TRIANGLES,o.length,o.length>256?l.UNSIGNED_SHORT:l.UNSIGNED_BYTE,0)})),0!==u.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,u.width,u.height,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,u.data),l.pixelStorei(l.UNPACK_ALIGNMENT,4);const e=[s[0],s[3],s[2],s[3],s[0],s[1],s[2],s[1]],r=new Float32Array(e);l.enableVertexAttribArray(this.positionAttributeLocation),l.bufferData(l.ARRAY_BUFFER,r,l.STATIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.enableVertexAttribArray(this.dsmAttributeLocation),l.bindBuffer(l.ARRAY_BUFFER,this.dsmBuffer),l.bufferData(l.ARRAY_BUFFER,new Float32Array([0,1,1,1,0,0,1,0]),l.STATIC_DRAW),l.vertexAttribPointer(this.dsmAttributeLocation,2,l.FLOAT,!1,0,0),l.uniform4f(this.colorUniformLocation,0,0,0,0),l.uniform1i(this.useDSMUniformLocation,1),l.colorMask(!1,!1,!0,!0),l.drawArrays(l.TRIANGLE_STRIP,0,4),l.deleteTexture(t)}return l.colorMask(!0,!0,!0,!0),l.deleteFramebuffer(x),{maxHeight:d,heightMapTex:this.targetTexture}}}const lt=t=>{const{tile:e,maxZoom:r,tileSize:o}=t;let{x:n,y:i,z:a}=e;if(a>r){const t=Math.pow(2,e.z-r);n=Math.floor(n/t),i=Math.floor(i/t),a=r}return{x:256===o?n:Math.floor(n/2),y:256===o?i:Math.floor(i/2),z:256===o?a:a-1}};class ht{constructor(t){this.gl=t,this.program=st({vSrc:"\n attribute vec4 a_tex_position;\n attribute vec4 a_tile_position;\n varying vec2 v_tex_pos;\n void main() {\n v_tex_pos = a_tex_position.xy;\n gl_Position = a_tile_position;\n }\n ",fSrc:"\n precision mediump float;\n uniform sampler2D u_texture;\n uniform float u_encoding;\n uniform float u_tile_size;\n varying vec2 v_tex_pos;\n\n float getElevationTerrarium(vec4 color) {\n float decoded = color.r * 255.0 * 256.0 + color.g * 255.0 + color.b * 255.0 / 256.0 - 32768.0;\n return decoded;\n }\n\n float getElevationMapbox(vec4 color) {\n float decoded = -10000.0 + (color.r * 255.0 * 256.0 * 256.0 + color.g * 255.0 * 256.0 + color.b * 255.0) * .1;\n return decoded;\n }\n\n float getElevationSwitzerland(vec4 color) {\n float decoded = ((color.r * 255.0 * 256.0 + color.g * 255.0) / pow(2.0, 16.0)) * 4808.0;\n return decoded;\n }\n\n float getElevation(vec4 color, float encoding) {\n float decoded;\n if (encoding == 1.0) {\n decoded = getElevationMapbox(color);\n } else if (encoding == 2.0) {\n decoded = getElevationSwitzerland(color);\n } else {\n decoded = getElevationTerrarium(color);\n }\n float scaled = decoded * 5.0;\n float elevation = max(scaled, 0.0);\n return elevation;\n }\n\n float textureSampleLinear(sampler2D sampler, vec2 texCoord) {\n vec2 texelSize = vec2(1.0 / u_tile_size, 1.0 / u_tile_size);\n \n // Calculate interpolation weights based on texCoord fract (fractional part)\n vec2 uv = fract(texCoord * u_tile_size);\n \n // Sample four nearest texels\n vec4 bottomLeft = texture2D(sampler, texCoord);\n vec4 bottomRight = texture2D(sampler, texCoord + vec2(texelSize.x, 0.0));\n vec4 topLeft = texture2D(sampler, texCoord + vec2(0.0, texelSize.y));\n vec4 topRight = texture2D(sampler, texCoord + texelSize);\n\n float bottomLeftEl = getElevation(bottomLeft, u_encoding);\n float bottomRightEl = getElevation(bottomRight, u_encoding);\n float topLeftEl = getElevation(topLeft, u_encoding);\n float topRightEl = getElevation(topRight, u_encoding);\n \n // Interpolate between bottom and top rows\n float bottom = mix(bottomLeftEl, bottomRightEl, uv.x);\n float top = mix(topLeftEl, topRightEl, uv.x);\n \n // Interpolate final color\n return mix(bottom, top, uv.y);\n }\n\n void main() {\n float elevation = textureSampleLinear(u_texture, v_tex_pos);\n float r = floor(elevation / 255.0) / 255.0;\n float g = floor(mod(elevation, 255.0)) / 255.0;\n gl_FragColor = vec4(0, 0, r, g);\n\n // vec4 color = texture2D(u_texture, v_tex_pos);\n // float elevation = getElevation(color, u_encoding);\n // float r = floor(elevation / 255.0) / 255.0;\n // float g = floor(mod(elevation, 255.0)) / 255.0;\n // gl_FragColor = vec4(0, 0, r, g);\n // gl_FragColor = color;\n }\n ",gl:t}),t.useProgram(this.program),this.texPositionAttributeLocation=t.getAttribLocation(this.program,"a_tex_position"),this.tilePositionAttributeLocation=t.getAttribLocation(this.program,"a_tile_position"),this.encodingUniformLocation=t.getUniformLocation(this.program,"u_encoding"),this.tileSizeUniformLocation=t.getUniformLocation(this.program,"u_tile_size"),this.texPositionBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.texPositionBuffer),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(this.texPositionAttributeLocation),t.vertexAttribPointer(this.texPositionAttributeLocation,2,t.FLOAT,!1,0,0),this.tilePositionBuffer=t.createBuffer(),this.tileTexture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.tileTexture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),this.outputTexture=t.createTexture(),this.framebuffer=t.createFramebuffer(),this.inProgress=[],this.finished=0}merge(t,e){return n(this,void 0,void 0,(function*(){const r=this.gl;let o=0;const{width:i,height:a,crossOrigin:s,getSourceUrl:u,getElevation:l,tileSize:h,tileLoaded:c,maxZoom:f}=e;if(r){this.inProgress.forEach((t=>t.src="")),this.inProgress=[],this.finished=0;const e=new Set;t.forEach((t=>{e.add(u(lt({tile:t,maxZoom:f,tileSize:h})))})),r.useProgram(this.program);let d=0;-32768===l({r:0,g:0,b:0,a:0})&&(d=0),-1e4===l({r:0,g:0,b:0,a:0})&&(d=1),4808===l({r:256,g:0,b:0,a:0})&&(d=2),r.uniform1f(this.encodingUniformLocation,d),at({gl:r,texture:this.outputTexture,imageData:null,format:r.RGBA,width:i,height:a,wrap:r.CLAMP_TO_EDGE,filter:r.NEAREST}),r.bindFramebuffer(r.FRAMEBUFFER,this.framebuffer),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,this.outputTexture,0);const m=r.checkFramebufferStatus(r.FRAMEBUFFER);m!==r.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+m),r.clear(r.COLOR_BUFFER_BIT);const _=Array.from(e).map((e=>n(this,void 0,void 0,(function*(){return new Promise(((n,l)=>{const c=new Image;this.inProgress.push(c),c.onload=()=>{r.useProgram(this.program),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.tileTexture),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,c),r.bindFramebuffer(r.FRAMEBUFFER,this.framebuffer);const s=t.filter((t=>e===u(lt({tile:t,maxZoom:f,tileSize:h})))),l=s.reduce(((t,e)=>Math.min(t,e.xOffset)),1/0),d=s.reduce(((t,e)=>Math.min(t,e.yOffset)),1/0),m=s.reduce(((t,e)=>Math.max(t,e.xOffset)),0),_=s.reduce(((t,e)=>Math.max(t,e.yOffset)),0),x=s.reduce(((t,e)=>Math.min(t,e.x)),1/0),g=s.reduce(((t,e)=>Math.min(t,e.y)),1/0),p=s.reduce(((t,e)=>Math.max(t,e.x)),0),E=s.reduce(((t,e)=>Math.max(t,e.y)),0),v=s[0].z,T=l/i,y=d/a,b=(m+256)/i,A=(_+256)/a,R=[T,y,b,y,T,A,b,A].map((t=>2*t-1));r.bindBuffer(r.ARRAY_BUFFER,this.tilePositionBuffer),r.bufferData(r.ARRAY_BUFFER,new Float32Array(R),r.STATIC_DRAW),r.enableVertexAttribArray(this.tilePositionAttributeLocation),r.vertexAttribPointer(this.tilePositionAttributeLocation,2,r.FLOAT,!1,0,0);let M=[0,0,1,0,0,1,1,1];const w=Math.pow(2,Math.max(0,v-f)+(256!==h?1:0)),F=514===h?1/h:0,L=1/w,U=x%w/w,D=g%w/w,P=p%w/w,S=E%w/w;M=[U,D,P+L,D,U,S+L,P+L,S+L].map((t=>t*(514===h?512/514:1)+F)),r.bindBuffer(r.ARRAY_BUFFER,this.texPositionBuffer),r.bufferData(r.ARRAY_BUFFER,new Float32Array(M),r.STATIC_DRAW),r.enableVertexAttribArray(this.texPositionAttributeLocation),r.vertexAttribPointer(this.texPositionAttributeLocation,2,r.FLOAT,!1,0,0),r.uniform1f(this.tileSizeUniformLocation,h),r.viewport(0,0,i,a),r.disable(r.BLEND),r.drawArrays(r.TRIANGLE_STRIP,0,4);const C=Math.floor(T*i),B=Math.floor(y*a),I=Math.ceil((b-T)*i),N=Math.ceil((A-y)*a),O=new Uint8Array(4*I*N);r.readPixels(C,B,I,N,r.RGBA,r.UNSIGNED_BYTE,O);for(let t=0;t<O.length;t+=4){const e=(256*O[t+2]+O[t+3])/5;o=Math.max(e,o)}n(null)},c.onerror=t=>{if(c.src!==c.originalSource)return l("new tiles requested");n(null)},c.crossOrigin=s||null,c.src=e,c.originalSource=c.src})).then((()=>{this.finished++,c(this.finished,this.inProgress.length)}))}))));try{yield Promise.all(_)}catch(t){return console.log(`${_.length} requests aborted`,t),null}return this.inProgress=[],this.outputTexture.maxHeight=o,this.outputTexture}throw new Error("Could not get canvas context for merging tile images")}))}}class ct 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:o}=t;return 256*e+r+o/256-32768}},dsmSource:{bounds:[{lat:0,lng:0},{lat:0,lng:0}],data:new Uint8ClampedArray,width:0,height:0,maxHeight:0},belowCanopy:!1,getFeatures:()=>Promise.resolve([]),getSize:()=>({width:Number.NaN,height:Number.NaN}),debug:t=>{}};const e=t[0];if(this.options=Object.assign(this.options,e),!this.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:this.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((t=>n(this,void 0,void 0,(function*(){if(200!==t.status)throw new Error(yield t.text())})))).catch((t=>n(this,void 0,void 0,(function*(){throw new Error(`Could not load ShadeMap API. Key: ${this.options.apiKey} Error: ${t}`)})))),this._canvas=document.createElement("canvas"),this._color=this._parseColor(this.options.color),this._reset=this._reset.bind(this),this._draw=this._draw.bind(this)}onRemove(){return this._map&&this._map.off("moveend",this._reset),this}setDate(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(et(this._compiledKernel,{date:this.options.date}),this._heightMap&&this._flush())):this.emit("idle"),this}_setDateForTimezone(t,e){let r=0;e&&(r=K(this.options.date)-K(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&&(ot(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&&(ot(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setBelowCanopy(t){return this.options.belowCanopy=t,this._heightMap?this._draw(this._heightMap):this._reset(),this}setTerrainSource(t){return this.options.terrainSource=t,delete this._heightMap,this._reset(),this}setDSMSource(t){return this.options.dsmSource=t,delete this._heightMap,this._reset(),this}setSunExposure(t=!1,e){return n(this,void 0,void 0,(function*(){if(this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:t}),e){const{startDate:r=new Date,endDate:o=new Date,iterations:n=32}=e;this.options.sunExposure={enabled:t,startDate:r,endDate:o,iterations:n}}if(this._map&&this._compiledKernel&&this._heightMap){if(!1===t)et(this._compiledKernel,{date:this.options.date});else{const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!(t instanceof Date&&e instanceof Date))throw new Error("Start date or end date or both are missing");if(e.getTime()<t.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield rt(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._flush()}return this}))}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:o,height:n}=this._heightMap,i=e.min;return t.map((t=>{const e=V(t,r);return[(e.x-i.x)/o,(e.y-i.y)/n]}))}return[]}_getBounds(t,e){const{width:r,height:o}=this.options.getSize();if(Number.isNaN(r)||Number.isNaN(o))return t.getBounds();const n=t.getCenter(),i=V(n,e),a=q(new C(i.x-r/2,i.y-o/2),e),s=q(new C(i.x+r/2,i.y+o/2),e);return t.createBounds({nw:a,se:s})}_getDEMZoom(t){const e=Math.min(this.options.terrainSource._overzoom||this.options.terrainSource.maxZoom,t.getZoom());return Math.round(e)}_reset(){return n(this,void 0,void 0,(function*(){if(this.options.debug("_reset()"),this._map){const t=it(this._map);let e=this._getDEMZoom(t);try{this._bounds=this._getBounds(t,e)}catch(t){return console.error("Invalid bounds returned: ",t),this}try{if(!t.isLeaflet()&&this._map.getPitch()>45){yield new Promise((t=>{this._map.loaded()?t(!0):this._map.once("idle",(function(){t(!0)}))}));const r=this._map.style._sourceCaches["other:composite"].getVisibleCoordinates().reverse(),o=r.reduce(((t,e)=>Math.max(t,e.canonical.z)),Number.MIN_SAFE_INTEGER),n=r.filter((t=>t.canonical.z===o)).map((t=>t.canonical)),[i,a,s,u]=n.reduce(((t,e)=>[Math.min(t[0],e.x),Math.min(t[1],e.y),Math.max(t[2],e.x),Math.max(t[3],e.y)]),[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER]),l=q(new C(512*i,512*a),o+1),h=q(new C(512*(s+1),512*(u+1)),o+1);e=o+1,this._bounds=t.createBounds({nw:l,se:h})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield Q({gl:this._gl,demZoom:e,bounds:this._bounds,terrainSource:this.options.terrainSource,dsmSource:this.options.dsmSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,tileLoaded:(t,e)=>this.emit("tileloaded",t,e),forceUpdate:!this._heightMap});this._heightMap=r,r.dirty&&(yield this._draw(r))}return this}))}_draw(t){return n(this,void 0,void 0,(function*(){if(this.options.debug("_draw()"),this._canvas&&this._compiledKernel&&this._map){if(nt({kernel:this._compiledKernel,map:it(this._map),heightMap:t,color:this._color,belowCanopy:this.options.belowCanopy,opacity:this.options.opacity,now:this.options.date,maxZoom:this.options.terrainSource.maxZoom,skipRender:this.options.sunExposure.enabled}),this.options.sunExposure.enabled){const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!0===(yield rt(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._bounds&&this._repositionCanvas(this._bounds)}return this}))}readPixel(t,e){const r=new Uint8Array(4);return this._gl&&this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r),r}readPixels(t,e,r,o){const n=new Uint8Array(r*o*4);return this._gl&&this._gl.readPixels(t,e,r,o,this._gl.RGBA,this._gl.UNSIGNED_BYTE,n),n}toGeoTiff(){const t=(t,e)=>{const r=this.readPixels(0,0,t,e),o=t*e*1,n=1*t,i=(e-1)*n,a=new Uint8Array(o),s=new Uint8Array(o);let u=0;const{startDate:l,endDate:h}=this.options.sunExposure;this.options.sunExposure.enabled&&l&&h&&(u=h.getTime()-l.getTime());for(let t=0;t<r.length;t+=4){let e;if(this.options.sunExposure.enabled){const o=r.subarray(t,t+3),n=Y(o,.5,u)/1e3/60,i=Math.min(Math.floor(n/6),255);e=new Uint8Array([i])}else{e=r[t]+r[t+1]+r[t+2]===0?new Uint8Array([255]):new Uint8Array([0])}a.set(e,t/4*1)}if(this._map&&!it(this._map).isLeaflet())return a;for(let t=0;t<o;t+=n)s.set(a.subarray(t,t+n),i-t);return s};if(this._map&&this._heightMap){const e=this._heightMap.outputWidth,r=this._heightMap.outputHeight,o=t(e,r),n=it(this._map),{lat:i,lng:a}=n.getBounds().getNorthWest(),s=n.getBounds().getSouthEast(),u=[0,0,0,a,i,0],l=[(s.lng-a)/e,(i-s.lat)/r,0];return this.options.sunExposure.enabled,{data:o,metadata:{width:e,height:r,ModelTiepoint:u,ModelPixelScale:l,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}return null}_generateShadeProfile(t){if(this._compiledKernel){const e=this._lngLatToTextureCoords(t.locations);return((t,e)=>{const r=tt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),o=tt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:o}))})(this._compiledKernel,Object.assign(Object.assign({},t),{texCoords:e}))}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=K(t.startDate)-K(t.startDate,t.tzId),r=t.startDate.getTime()-e,o=t.endDate.getTime()-e,n=this._lngLatToTextureCoords([t.location])[0],{output:i,outputWidth:a,outputHeight:s}=((t,e)=>{const r=tt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),o=tt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateLocationShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:o}))})(this._compiledKernel,Object.assign(Object.assign({},t),{startTime:r,endTime:o,texCoord:n}));return i.toArray=function(){const e=new Array;for(let r=0;r<a;r++){const o=[];for(let e=s-1;e>=0;e--){const n=e*a*4+4*r,i=this.slice(n,n+4);o.push(i.join("")===t.sunColor.join("")?1:0)}e.push(o)}return e},{data:i,width:a,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:o,endDate:n}=this.options.sunExposure,i=n.getTime()-o.getTime(),a=Y(r,.5,i);return Math.abs(a/1e3/3600)}return 0}_repositionCanvas(t){}_flush(){}flushSync(){this._gl&&this._gl.finish()}_parseColor(t){t=t.replace("#","");const e={r:0,g:0,b:0};return/^([0-9A-F]{3}){1,2}$/i.test(t)&&(3===t.length?(e.r=parseInt(t[0]+t[0],16),e.g=parseInt(t[1]+t[1],16),e.b=parseInt(t[2]+t[2],16)):6===t.length&&(e.r=parseInt(t[0]+t[1],16),e.g=parseInt(t[2]+t[3],16),e.b=parseInt(t[4]+t[5],16))),e}}{constructor(t){super(t);const e={preserveDrawingBuffer:!0,antialias:!1};this._gl=this._canvas.getContext("webgl",e)||this._canvas.getContext("experimental-webgl",e),this._canvas.width=window.innerWidth,this._canvas.height=window.innerHeight,this._compiledKernel=function(t){const{context:e,setRenderBuffer:r}=t,o=e,i=st({gl:o,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 a_pos;attribute vec2 a_tex_pos;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;void main(void){gl_Position=vec4(a_pos,0,1);vTexCoordFull=(gl_Position*0.5+0.5).xy;vTexCoordCropped=a_tex_pos;}",fSrc:"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nprecision lowp int;precision lowp sampler2D;float atan2(float v1,float v2){if(v1==0.0||v2==0.0)return 0.0;return atan(v1,v2);}float _pow(float v1,float v2){if(v2==0.0)return 1.0;return pow(v1,v2);}float integerMod(float x,float y){float res=floor(mod(x,y));return res*(res>floor(y)-1.0 ? 0.0 : 1.0);}float divWithIntCheck(float x,float y){if(floor(x)==x&&floor(y)==y&&integerMod(x,y)==0.0){return float(int(x)/int(y));}return x/y;}float integerCorrectionModulo(float number,float divisor){if(number<0.0){number=abs(number);if(divisor<0.0){divisor=abs(divisor);}return-(number-(divisor*floor(divWithIntCheck(number,divisor))));}if(divisor<0.0){divisor=abs(divisor);}return number-(divisor*floor(divWithIntCheck(number,divisor)));}float getDEMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*255.0*256.0+result.g*255.0)/5000.0;}float getDSMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.b*255.0*256.0+result.a*255.0)/5000.0;}vec4 actualColor;void color(float r,float g,float b,float a){actualColor=vec4(r,g,b,a);}void color(float r,float g,float b){color(r,g,b,1.0);}void color(float r){color(r,r,r,1.0);}void color(vec4 color){actualColor=color;}const int LOOP_MAX=1000;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;uniform sampler2D user_a;uniform float user_width;uniform float user_height;uniform float user_maxHeight;uniform float user_zoom;uniform float user_topYCoord;uniform float user_ySize;uniform vec4 user_color;uniform vec4 u_sunColor;uniform float user_step;uniform float user_west;uniform float user_dLng;uniform float user_dec;uniform float user_Hi;uniform bool u_below_canopy;uniform sampler2D user_sunExposureTexture;uniform bool user_outputSunExposure;uniform bool u_outputShadeProfile;uniform sampler2D u_decHiTexture;uniform sampler2D u_gpxTexture;uniform bool u_outputLocationShadeProfile;uniform vec2 u_shadeProfileLocation;float kernelResult;void kernel(){float sunDec=user_dec;float sunHi=user_Hi;vec4 shade_color=user_color;float maxHeight=user_maxHeight/1000.0;float user_x=vTexCoordCropped.x;float user_y=vTexCoordCropped.y;if(u_outputShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;vec4 gpx=texture2D(u_gpxTexture,vec2(vTexCoordFull.x,.5));user_x=gpx.x;user_y=gpx.y;}if(u_outputLocationShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;user_x=u_shadeProfileLocation.x;user_y=u_shadeProfileLocation.y;}float user_lit=1.0;float dsm_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(u_below_canopy==true){float dem_height=getDEMElevationFromSampler2D(user_a,user_x,user_y);if(dsm_height-dem_height>.002){user_lit=0.0;}}float user_z=dsm_height;float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=user_west+(user_dLng*user_x);float user_H=integerCorrectionModulo((sunHi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(sunDec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(sunDec))+((cos(user_lat)*cos(sunDec))*cos(user_H))));float user_zoom_factor=_pow(2.0,user_zoom);float user_kmPerPixel=divWithIntCheck(156.5430339296875,user_zoom_factor)*abs(cos(user_lat));float user_dx=((-sin(sun_azimuth)*cos(sun_altitude))*user_step)/user_width;float user_dy=((cos(sun_azimuth)*cos(sun_altitude))*user_step)/user_height;float user_dz=((sin(sun_altitude)*user_kmPerPixel)*user_step);float shadow_bias=0.0005;float user_curvature=0.0;float cur_height=0.0;float user_distance=0.0;float user_startX=user_x;float user_startY=user_y;user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;if((abs(1.0)<0.0)){kernelResult=0.0;return;}float minAngle=asin((earthRadiusInKm/(earthRadiusInKm+user_z)))-(user_PI/2.0);if(user_z<0.0||sun_altitude<minAngle){user_lit=0.0;}else{float xIter=ceil(user_dx<0.0 ? abs(user_x/user_dx):(1.0-user_x)/user_dx);float yIter=ceil(user_dy<0.0 ? abs(user_y/user_dy):(1.0-user_y)/user_dy);float zIter=ceil(user_dz<0.0 ? float(LOOP_MAX):(maxHeight-user_z)/user_dz);int iter=int(min(xIter,min(yIter,zIter)));float user_distance=(sqrt(pow(user_dx*user_width,2.0)+pow(user_dy*user_height,2.0))*user_kmPerPixel)/earthRadiusInKm;for(int safeI=0;safeI<LOOP_MAX;safeI++){if(safeI>iter){break;}cur_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(cur_height-user_z>shadow_bias){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;vec4 result=texture2D(user_a,vec2(user_x,user_y));iter=0;break;}}user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;}}if((user_lit==1.0)){if(u_outputLocationShadeProfile==true&&u_sunColor==shade_color){float timeInSun=pow(.7,pow(sin(sun_altitude),.678))*sin(sun_altitude)*(1.0/0.7);float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,1.0);}else{color(u_sunColor);}}else{color(shade_color);}if(user_outputSunExposure){vec4 aggregateColor=texture2D(user_sunExposureTexture,vec2(vTexCoordFull.x,vTexCoordFull.y));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;}"});o.useProgram(i);const a=o.createBuffer(),s=o.getAttribLocation(i,"a_pos"),u=o.createBuffer(),l=o.getAttribLocation(i,"a_tex_pos"),h=o.createBuffer();o.bindBuffer(o.ARRAY_BUFFER,h),o.bufferData(o.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),o.STATIC_DRAW);const c=o.createBuffer();o.bindBuffer(o.ARRAY_BUFFER,c),o.bufferData(o.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),o.STATIC_DRAW);const f=o.getUniformLocation(i,"user_a");o.uniform1i(f,0);const d=o.getUniformLocation(i,"user_width"),m=o.getUniformLocation(i,"user_height"),_=o.getUniformLocation(i,"user_maxHeight"),x=o.getUniformLocation(i,"user_zoom"),g=o.getUniformLocation(i,"user_topYCoord"),p=o.getUniformLocation(i,"user_ySize"),E=o.getUniformLocation(i,"user_step"),v=o.getUniformLocation(i,"user_west"),T=o.getUniformLocation(i,"user_dLng"),y=o.getUniformLocation(i,"user_dec"),b=o.getUniformLocation(i,"user_Hi"),A=o.getUniformLocation(i,"user_color"),R=o.getUniformLocation(i,"u_below_canopy"),M=o.getUniformLocation(i,"user_sunExposureTexture"),w=o.getUniformLocation(i,"user_outputSunExposure"),F=o.getUniformLocation(i,"u_outputShadeProfile"),L=o.getUniformLocation(i,"u_gpxTexture"),U=o.getUniformLocation(i,"u_decHiTexture"),D=o.getUniformLocation(i,"u_sunColor"),P=o.getUniformLocation(i,"u_outputLocationShadeProfile"),S=o.getUniformLocation(i,"u_shadeProfileLocation"),C=o.createTexture();let B=0,I=0,N=0,O=null;const z=()=>{I&&N&&(o.useProgram(i),o.bindBuffer(o.ARRAY_BUFFER,a),o.enableVertexAttribArray(s),o.vertexAttribPointer(s,2,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,u),o.enableVertexAttribArray(l),o.vertexAttribPointer(l,2,o.FLOAT,!1,0,0),null!==O&&(o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,O)),r(o,I,N),o.viewport(0,0,I,N),o.clear(o.COLOR_BUFFER_BIT),o.drawArrays(o.TRIANGLE_STRIP,0,4))};let X=0,G=0,H=0,W="";const Y=t=>{const e=(t.endTime-t.startTime)/86400/1e3,r=1440;if(o.activeTexture(o.TEXTURE3),o.uniform1i(U,3),t.startTime!==G||t.endTime!==H||t.tzId!==W){G=t.startTime,H=t.endTime,W=t.tzId;const n=[],i=828e5,a=K(new Date(G),W);for(let t=0;t<e;t++){const e=K(new Date(G+86400*t*1e3+i),W)-a;n[t]=e}const s=new Float32Array(r*e*2);for(let t=0;t<r;t++)for(let r=0;r<e;r++){const o=G+86400*r*1e3+60*t*1e3,{dec:i,Hi:a}=Z(o+n[r]);s[2*(t*e+r)]=-i,s[2*(t*e+r)+1]=a/10}at({gl:o,texture:C,imageData:s,width:e,height:r,wrap:o.CLAMP_TO_EDGE,filter:o.NEAREST,format:o.RG,internalFormat:o.RG32F,type:o.FLOAT})}else o.bindTexture(o.TEXTURE_2D,C);return{outputWidth:e,outputHeight:r}};return{updateHeightMap:function(t){const{heightMapTex:e,width:r,height:n,maxHeight:s,heightMapZoom:l,topYCoord:h,ySize:c,colorVec:f,step:M,west:w,dLng:F,dec:L,Hi:U,cornerClipCoords:D,cornerTextureCoords:P,outputWidth:S,outputHeight:C,belowCanopy:X,skipRender:G}=t;o.useProgram(i),I=S,N=C,O=e,o.bindBuffer(o.ARRAY_BUFFER,a),o.bufferData(o.ARRAY_BUFFER,new Float32Array(D),o.STATIC_DRAW),o.bindBuffer(o.ARRAY_BUFFER,u),o.bufferData(o.ARRAY_BUFFER,new Float32Array(P),o.STATIC_DRAW),o.uniform1f(d,r),o.uniform1f(m,n),o.uniform1f(_,s),o.uniform1f(x,l),o.uniform1f(g,h),o.uniform1f(p,c),o.uniform4fv(A,f),o.uniform1f(E,M),o.uniform1f(v,w),o.uniform1f(T,F),o.uniform1f(y,L),o.uniform1f(b,U),o.uniform1f(R,X?1:0),G||(window.cancelAnimationFrame(B),B=window.requestAnimationFrame(z))},updateDate:t=>{const{dec:e,Hi:r}=t;o.useProgram(i),o.uniform1f(y,e),o.uniform1f(b,r),window.cancelAnimationFrame(B),B=window.requestAnimationFrame(z)},updateDateRange:t=>n(this,void 0,void 0,(function*(){const{startDate:e,endDate:r,iterations:n,emit:h}=t;o.useProgram(i);const c=X=Date.now(),f=Math.floor((r.getTime()-e.getTime())/n),d=o.getUniform(i,A),m=I,_=N,x=o.createTexture();o.activeTexture(o.TEXTURE2),o.bindTexture(o.TEXTURE_2D,x),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,m,_,0,o.RGBA,o.UNSIGNED_BYTE,null),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.NEAREST),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.NEAREST);const g=o.createFramebuffer();o.bindFramebuffer(o.FRAMEBUFFER,g);const p=o.COLOR_ATTACHMENT0;o.framebufferTexture2D(o.FRAMEBUFFER,p,o.TEXTURE_2D,x,0);for(let t=0;t<n;t++){if(o.useProgram(i),h("tileloaded",t,n-1),c!==X)return o.deleteFramebuffer(g),o.deleteTexture(x),o.uniform4fv(A,d),!0;yield new Promise(((r,h)=>{window.requestAnimationFrame((()=>{o.useProgram(i),null!==O&&(o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,O)),o.bindFramebuffer(o.FRAMEBUFFER,g);const h=o.checkFramebufferStatus(o.FRAMEBUFFER);h!==o.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+h);const{dec:c,Hi:d}=j(new Date(e.getTime()+f*t));o.uniform1f(y,c),o.uniform1f(b,d),o.uniform4fv(A,[1/n,0,0,1]),o.bindBuffer(o.ARRAY_BUFFER,a),o.enableVertexAttribArray(s),o.vertexAttribPointer(s,2,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,u),o.enableVertexAttribArray(l),o.vertexAttribPointer(l,2,o.FLOAT,!1,0,0),o.viewport(0,0,m,_),o.enable(o.BLEND),o.blendFunc(o.ONE,o.ONE),o.drawArrays(o.TRIANGLE_STRIP,0,4),r()}))}))}return o.deleteFramebuffer(g),yield new Promise(((t,e)=>{window.requestAnimationFrame((()=>{if(o.useProgram(i),c!==X)return o.deleteTexture(x),o.uniform4fv(A,d),void t(!0);o.activeTexture(o.TEXTURE2),o.bindTexture(o.TEXTURE_2D,x),o.uniform1i(M,2),o.uniform1i(w,1),z(),o.uniform1i(w,0),o.uniform1i(M,0),o.deleteTexture(x),o.uniform4fv(A,d),t(!1)}))}))})),updateColor:t=>{const{colorVec:e}=t;o.useProgram(i),o.uniform4fv(A,e),window.cancelAnimationFrame(B),B=window.requestAnimationFrame(z)},generateShadeProfile:t=>{o.useProgram(i);const{dates:e,texCoords:r,shadeColor:n,sunColor:a}=t,u=r.length,f=e.length,d=o.getUniform(i,A);o.uniform4fv(A,n),o.uniform4fv(D,a),o.uniform1i(F,1);const m=o.createTexture();o.activeTexture(o.TEXTURE3),at({gl:o,imageData:null,width:u,height:f,wrap:o.CLAMP_TO_EDGE,filter:o.NEAREST,format:o.RGBA,texture:m});const _=o.createFramebuffer();o.bindFramebuffer(o.FRAMEBUFFER,_),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,m,0);const x=o.checkFramebufferStatus(o.FRAMEBUFFER);x!==o.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+x);const g=r.map((t=>[t[0],t[1]])).flat(),p=o.createTexture();o.activeTexture(o.TEXTURE2),at({gl:o,texture:p,imageData:new Float32Array(g),width:g.length/2,height:1,wrap:o.CLAMP_TO_EDGE,filter:o.NEAREST,format:o.RG,internalFormat:o.RG32F,type:o.FLOAT}),o.uniform1i(L,2);const E=e.map((t=>{const{dec:e,Hi:r}=j(t);return[-e,r/10]})).flat(),v=o.createTexture();o.activeTexture(o.TEXTURE1),at({gl:o,texture:v,imageData:new Float32Array(E),width:1,height:e.length,wrap:o.CLAMP_TO_EDGE,filter:o.NEAREST,format:o.RG,internalFormat:o.RG32F,type:o.FLOAT}),o.uniform1i(U,1),null!==O&&(o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,O)),o.bindBuffer(o.ARRAY_BUFFER,h),o.enableVertexAttribArray(s),o.vertexAttribPointer(s,2,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,c),o.enableVertexAttribArray(l),o.vertexAttribPointer(l,2,o.FLOAT,!1,0,0),o.viewport(0,0,u,f),o.clear(o.COLOR_BUFFER_BIT),o.drawArrays(o.TRIANGLE_STRIP,0,4);const T=new Uint8Array(u*f*4);return o.readPixels(0,0,u,f,o.RGBA,o.UNSIGNED_BYTE,T),o.deleteTexture(m),o.deleteTexture(v),o.deleteTexture(p),o.deleteFramebuffer(_),o.uniform1i(U,0),o.uniform1i(L,0),o.uniform1i(F,0),o.uniform4fv(A,d),o.uniform4fv(D,[0,0,0,0]),T},generateLocationShadeProfile:t=>{o.useProgram(i);const{startTime:e,endTime:r,tzId:n,texCoord:a,shadeColor:u,sunColor:f}=t,d=o.getUniform(i,A),{outputWidth:m,outputHeight:_}=Y({startTime:e,endTime:r,tzId:n});o.uniform4fv(A,u),o.uniform4fv(D,f),o.uniform1i(P,1),o.uniform2fv(S,[a[0],a[1]]);const x=o.createTexture();o.activeTexture(o.TEXTURE2),at({gl:o,imageData:null,width:m,height:_,wrap:o.CLAMP_TO_EDGE,filter:o.NEAREST,format:o.RGBA,texture:x});const g=o.createFramebuffer();o.bindFramebuffer(o.FRAMEBUFFER,g),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,x,0);const p=o.checkFramebufferStatus(o.FRAMEBUFFER);p!==o.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+p),null!==O&&(o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,O)),o.bindBuffer(o.ARRAY_BUFFER,h),o.enableVertexAttribArray(s),o.vertexAttribPointer(s,2,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,c),o.enableVertexAttribArray(l),o.vertexAttribPointer(l,2,o.FLOAT,!1,0,0),o.viewport(0,0,m,_),o.clear(o.COLOR_BUFFER_BIT),o.drawArrays(o.TRIANGLE_STRIP,0,4);const E=new Uint8Array(m*_*4);return o.readPixels(0,0,m,_,o.RGBA,o.UNSIGNED_BYTE,E),o.deleteTexture(x),o.deleteFramebuffer(g),o.uniform1i(U,0),o.uniform1i(P,0),o.uniform4fv(A,d),o.uniform4fv(D,[0,0,0,0]),{output:E,outputWidth:m,outputHeight:_}}}}({context:this._gl,setRenderBuffer:t=>{t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.bindFramebuffer(t.FRAMEBUFFER,null)}}),this._buildingRasterizer=new ut(this._gl),this._tileMerger=new ht(this._gl)}addTo(t){return this.onAdd(t)}onAdd(t){if(this._map=t,!this._canvasOverlay&&this._canvas){const t=this._map.getBounds();this._canvasOverlay=function(...t){return new o(...t)}(this._canvas,t),this._canvasOverlay.addTo(this._map)}return this._map.on("moveend",this._reset),this._map.attributionControl.addAttribution('<a href="https://shademap.app/about">&copy; ShadeMap</a>'),this._reset(),this}_repositionCanvas(t){if(this._canvasOverlay&&this._canvasOverlay.setBounds(t),this._map){const{x:t,y:e}=this._map.getSize();this._canvas.width=t,this._canvas.height=e}this._flush()}_flush(){this.emit("idle")}}void 0!==window.L&&(window.L.shadeMap=(...t)=>new ct(...t));export{ct as default};
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Copyright Ted Piotrowski 2024
3
3
  * Package: leaflet-shadow-simulator
4
- * Version: 0.56.1
4
+ * Version: 0.57.0
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(require("leaflet")):"function"==typeof define&&define.amd?define(["leaflet"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).ShadeMap=e(t.L)}(this,(function(t){"use strict";class e extends t.ImageOverlay{constructor(t,e,r={}){super("",e,r),this._url=t}_initImage(){const e="CANVAS"===this._url.tagName,r=this._image=e?this._url:t.DomUtil.create("canvas");return t.DomUtil.addClass(r,"leaflet-image-layer"),this._zoomAnimated&&t.DomUtil.addClass(r,"leaflet-zoom-animated"),this.options.className&&t.DomUtil.addClass(r,this.options.className),r.onselectstart=t.Util.falseFn,r.onmousemove=t.Util.falseFn,this}setBounds(t){return this._bounds=t,this._map&&this._reset(),this}}function r(t,e,r,i){return new(r||(r=Promise))((function(n,o){function a(t){try{u(i.next(t))}catch(t){o(t)}}function s(t){try{u(i.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((i=i.apply(t,e||[])).next())}))}function i(t,e,r){r=r||2;var i,o,s,u,h,l,d,m=e&&e.length,x=m?e[0]*r:t.length,g=n(t,0,x,r,!0),p=[];if(!g||g.next===g.prev)return p;if(m&&(g=function(t,e,r,i){var o,a,s,u=[];for(o=0,a=e.length;o<a;o++)(s=n(t,e[o]*i,o<a-1?e[o+1]*i:t.length,i,!1))===s.next&&(s.steiner=!0),u.push(_(s));for(u.sort(c),o=0;o<u.length;o++)r=f(u[o],r);return r}(t,e,g,r)),t.length>80*r){i=s=t[0],o=u=t[1];for(var E=r;E<x;E+=r)(h=t[E])<i&&(i=h),(l=t[E+1])<o&&(o=l),h>s&&(s=h),l>u&&(u=l);d=0!==(d=Math.max(s-i,u-o))?32767/d:0}return a(g,p,r,i,o,d,0),p}function n(t,e,r,i,n){var o,a;if(n===F(t,e,r,i)>0)for(o=e;o<r;o+=i)a=b(o,t[o],t[o+1],a);else for(o=r-i;o>=e;o-=i)a=b(o,t[o],t[o+1],a);return a&&E(a,a.next)&&(M(a),a=a.next),a}function o(t,e){if(!t)return t;e||(e=t);var r,i=t;do{if(r=!1,i.steiner||!E(i,i.next)&&0!==p(i.prev,i,i.next))i=i.next;else{if(M(i),(i=e=i.prev)===i.next)break;r=!0}}while(r||i!==e);return e}function a(t,e,r,i,n,c,f){if(t){!f&&c&&function(t,e,r,i){var n=t;do{0===n.z&&(n.z=m(n.x,n.y,e,r,i)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next}while(n!==t);n.prevZ.nextZ=null,n.prevZ=null,function(t){var e,r,i,n,o,a,s,u,h=1;do{for(r=t,t=null,o=null,a=0;r;){for(a++,i=r,s=0,e=0;e<h&&(s++,i=i.nextZ);e++);for(u=h;s>0||u>0&&i;)0!==s&&(0===u||!i||r.z<=i.z)?(n=r,r=r.nextZ,s--):(n=i,i=i.nextZ,u--),o?o.nextZ=n:t=n,n.prevZ=o,o=n;r=i}o.nextZ=null,h*=2}while(a>1)}(n)}(t,i,n,c);for(var d,_,x=t;t.prev!==t.next;)if(d=t.prev,_=t.next,c?u(t,i,n,c):s(t))e.push(d.i/r|0),e.push(t.i/r|0),e.push(_.i/r|0),M(t),t=_.next,x=_.next;else if((t=_)===x){f?1===f?a(t=h(o(t),e,r),e,r,i,n,c,2):2===f&&l(t,e,r,i,n,c):a(o(t),e,r,i,n,c,1);break}}}function s(t){var e=t.prev,r=t,i=t.next;if(p(e,r,i)>=0)return!1;for(var n=e.x,o=r.x,a=i.x,s=e.y,u=r.y,h=i.y,l=n<o?n<a?n:a:o<a?o:a,c=s<u?s<h?s:h:u<h?u:h,f=n>o?n>a?n:a:o>a?o:a,d=s>u?s>h?s:h:u>h?u:h,m=i.next;m!==e;){if(m.x>=l&&m.x<=f&&m.y>=c&&m.y<=d&&x(n,s,o,u,a,h,m.x,m.y)&&p(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function u(t,e,r,i){var n=t.prev,o=t,a=t.next;if(p(n,o,a)>=0)return!1;for(var s=n.x,u=o.x,h=a.x,l=n.y,c=o.y,f=a.y,d=s<u?s<h?s:h:u<h?u:h,_=l<c?l<f?l:f:c<f?c:f,g=s>u?s>h?s:h:u>h?u:h,E=l>c?l>f?l:f:c>f?c:f,T=m(d,_,e,r,i),v=m(g,E,e,r,i),y=t.prevZ,A=t.nextZ;y&&y.z>=T&&A&&A.z<=v;){if(y.x>=d&&y.x<=g&&y.y>=_&&y.y<=E&&y!==n&&y!==a&&x(s,l,u,c,h,f,y.x,y.y)&&p(y.prev,y,y.next)>=0)return!1;if(y=y.prevZ,A.x>=d&&A.x<=g&&A.y>=_&&A.y<=E&&A!==n&&A!==a&&x(s,l,u,c,h,f,A.x,A.y)&&p(A.prev,A,A.next)>=0)return!1;A=A.nextZ}for(;y&&y.z>=T;){if(y.x>=d&&y.x<=g&&y.y>=_&&y.y<=E&&y!==n&&y!==a&&x(s,l,u,c,h,f,y.x,y.y)&&p(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;A&&A.z<=v;){if(A.x>=d&&A.x<=g&&A.y>=_&&A.y<=E&&A!==n&&A!==a&&x(s,l,u,c,h,f,A.x,A.y)&&p(A.prev,A,A.next)>=0)return!1;A=A.nextZ}return!0}function h(t,e,r){var i=t;do{var n=i.prev,a=i.next.next;!E(n,a)&&T(n,i,i.next,a)&&A(n,a)&&A(a,n)&&(e.push(n.i/r|0),e.push(i.i/r|0),e.push(a.i/r|0),M(i),M(i.next),i=t=a),i=i.next}while(i!==t);return o(i)}function l(t,e,r,i,n,s){var u=t;do{for(var h=u.next.next;h!==u.prev;){if(u.i!==h.i&&g(u,h)){var l=R(u,h);return u=o(u,u.next),l=o(l,l.next),a(u,e,r,i,n,s,0),void a(l,e,r,i,n,s,0)}h=h.next}u=u.next}while(u!==t)}function c(t,e){return t.x-e.x}function f(t,e){var r=function(t,e){var r,i=e,n=t.x,o=t.y,a=-1/0;do{if(o<=i.y&&o>=i.next.y&&i.next.y!==i.y){var s=i.x+(o-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(s<=n&&s>a&&(a=s,r=i.x<i.next.x?i:i.next,s===n))return r}i=i.next}while(i!==e);if(!r)return null;var u,h=r,l=r.x,c=r.y,f=1/0;i=r;do{n>=i.x&&i.x>=l&&n!==i.x&&x(o<c?n:a,o,l,c,o<c?a:n,o,i.x,i.y)&&(u=Math.abs(o-i.y)/(n-i.x),A(i,t)&&(u<f||u===f&&(i.x>r.x||i.x===r.x&&d(r,i)))&&(r=i,f=u)),i=i.next}while(i!==h);return r}(t,e);if(!r)return e;var i=R(r,t);return o(i,i.next),o(r,r.next)}function d(t,e){return p(t.prev,t,e.prev)<0&&p(e.next,t,t.next)<0}function m(t,e,r,i,n){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*n|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*n|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function _(t){var e=t,r=t;do{(e.x<r.x||e.x===r.x&&e.y<r.y)&&(r=e),e=e.next}while(e!==t);return r}function x(t,e,r,i,n,o,a,s){return(n-a)*(e-s)>=(t-a)*(o-s)&&(t-a)*(i-s)>=(r-a)*(e-s)&&(r-a)*(o-s)>=(n-a)*(i-s)}function g(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&&T(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(A(t,e)&&A(e,t)&&function(t,e){var r=t,i=!1,n=(t.x+e.x)/2,o=(t.y+e.y)/2;do{r.y>o!=r.next.y>o&&r.next.y!==r.y&&n<(r.next.x-r.x)*(o-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next}while(r!==t);return i}(t,e)&&(p(t.prev,t,e.prev)||p(t,e.prev,e))||E(t,e)&&p(t.prev,t,t.next)>0&&p(e.prev,e,e.next)>0)}function p(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function E(t,e){return t.x===e.x&&t.y===e.y}function T(t,e,r,i){var n=y(p(t,e,r)),o=y(p(t,e,i)),a=y(p(r,i,t)),s=y(p(r,i,e));return n!==o&&a!==s||(!(0!==n||!v(t,r,e))||(!(0!==o||!v(t,i,e))||(!(0!==a||!v(r,t,i))||!(0!==s||!v(r,e,i)))))}function v(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 y(t){return t>0?1:t<0?-1:0}function A(t,e){return p(t.prev,t,t.next)<0?p(t,e,t.next)>=0&&p(t,t.prev,e)>=0:p(t,e,t.prev)<0||p(t,t.next,e)<0}function R(t,e){var r=new w(t.i,t.x,t.y),i=new w(e.i,e.x,e.y),n=t.next,o=e.prev;return t.next=e,e.prev=t,r.next=n,n.prev=r,i.next=r,r.prev=i,o.next=i,i.prev=o,i}function b(t,e,r,i){var n=new w(t,e,r);return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function M(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function w(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function F(t,e,r,i){for(var n=0,o=e,a=r-i;o<r;o+=i)n+=(t[a]-t[o])*(t[o+1]+t[a+1]),a=o;return n}function U(t,e,r){var i=e[1],n=e[0],o=i-n;return t===i&&r?t:((t-n)%o+o)%o+n}function D(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}i.deviation=function(t,e,r,i){var n=e&&e.length,o=n?e[0]*r:t.length,a=Math.abs(F(t,0,o,r));if(n)for(var s=0,u=e.length;s<u;s++){var h=e[s]*r,l=s<u-1?e[s+1]*r:t.length;a-=Math.abs(F(t,h,l,r))}var c=0;for(s=0;s<i.length;s+=3){var f=i[s]*r,d=i[s+1]*r,m=i[s+2]*r;c+=Math.abs((t[f]-t[m])*(t[d+1]-t[f+1])-(t[f]-t[d])*(t[m+1]-t[f+1]))}return 0===a&&0===c?0:Math.abs((c-a)/a)},i.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},i=0,n=0;n<t.length;n++){for(var o=0;o<t[n].length;o++)for(var a=0;a<e;a++)r.vertices.push(t[n][o][a]);n>0&&(i+=t[n-1].length,r.holes.push(i))}return r};var L=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function P(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var S=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function C(t,e,r){return t instanceof P?t:L(t)?new P(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new P(t.x,t.y):new P(t,e,r)}function B(t,e){if(t)for(var r=e?[t,e]:t,i=0,n=r.length;i<n;i++)this.extend(r[i])}function I(t,e){return!t||t instanceof B?t:new B(t,e)}function N(t,e){if(t)for(var r=e?[t,e]:t,i=0,n=r.length;i<n;i++)this.extend(r[i])}function O(t,e){return t instanceof N?t:new N(t,e)}P.prototype={clone:function(){return new P(this.x,this.y)},add:function(t){return this.clone()._add(C(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(C(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 P(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new P(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=S(this.x),this.y=S(this.y),this},distanceTo:function(t){var e=(t=C(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=C(t)).x===this.x&&t.y===this.y},contains:function(t){return t=C(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+D(this.x)+", "+D(this.y)+")"}},B.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof P||"number"==typeof t[0]||"x"in t)e=r=C(t);else if(e=(t=I(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 C((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return C(this.min.x,this.max.y)},getTopRight:function(){return C(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 P?C(t):I(t))instanceof B?(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=I(t);var e=this.min,r=this.max,i=t.min,n=t.max,o=n.x>=e.x&&i.x<=r.x,a=n.y>=e.y&&i.y<=r.y;return o&&a},overlaps:function(t){t=I(t);var e=this.min,r=this.max,i=t.min,n=t.max,o=n.x>e.x&&i.x<r.x,a=n.y>e.y&&i.y<r.y;return o&&a},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,i=Math.abs(e.x-r.x)*t,n=Math.abs(e.y-r.y)*t;return I(C(e.x-i,e.y-n),C(r.x+i,r.y+n))},equals:function(t){return!!t&&(t=I(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},N.prototype={extend:function(t){var e,r,i=this._southWest,n=this._northEast;if(t instanceof z)e=t,r=t;else{if(!(t instanceof N))return t?this.extend(G(t)||O(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return i||n?(i.lat=Math.min(e.lat,i.lat),i.lng=Math.min(e.lng,i.lng),n.lat=Math.max(r.lat,n.lat),n.lng=Math.max(r.lng,n.lng)):(this._southWest=new z(e.lat,e.lng),this._northEast=new z(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,i=Math.abs(e.lat-r.lat)*t,n=Math.abs(e.lng-r.lng)*t;return new N(new z(e.lat-i,e.lng-n),new z(r.lat+i,r.lng+n))},getCenter:function(){return new z((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 z(this.getNorth(),this.getWest())},getSouthEast:function(){return new z(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 z||"lat"in t?G(t):O(t);var e,r,i=this._southWest,n=this._northEast;return t instanceof N?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=i.lat&&r.lat<=n.lat&&e.lng>=i.lng&&r.lng<=n.lng},intersects:function(t){t=O(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),n=t.getNorthEast(),o=n.lat>=e.lat&&i.lat<=r.lat,a=n.lng>=e.lng&&i.lng<=r.lng;return o&&a},overlaps:function(t){t=O(t);var e=this._southWest,r=this._northEast,i=t.getSouthWest(),n=t.getNorthEast(),o=n.lat>e.lat&&i.lat<r.lat,a=n.lng>e.lng&&i.lng<r.lng;return o&&a},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=O(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var X=function(t){var e,r,i,n;for(r=1,i=arguments.length;r<i;r++)for(e in n=arguments[r])t[e]=n[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),i=this.scale(e);return this.transformation._transform(r,i)},pointToLatLng:function(t,e){var r=this.scale(e),i=this.transformation.untransform(t,r);return this.projection.unproject(i)},project:function(t){return this.projection.project(t)},unproject:function(t){return this.projection.unproject(t)},scale:function(t){return 256*Math.pow(2,t)},zoom:function(t){return Math.log(t/256)/Math.LN2},getProjectedBounds:function(t){if(this.infinite)return null;var e=this.projection.bounds,r=this.scale(t);return new B(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(t){var e=this.wrapLng?U(t.lng,this.wrapLng,!0):t.lng;return new z(this.wrapLat?U(t.lat,this.wrapLat,!0):t.lat,e,t.alt)},wrapLatLngBounds:function(t){var e=t.getCenter(),r=this.wrapLatLng(e),i=e.lat-r.lat,n=e.lng-r.lng;if(0===i&&0===n)return t;var o=t.getSouthWest(),a=t.getNorthEast();return new N(new z(o.lat-i,o.lng-n),new z(a.lat-i,a.lng-n))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,i=t.lat*r,n=e.lat*r,o=Math.sin((e.lat-t.lat)*r/2),a=Math.sin((e.lng-t.lng)*r/2),s=o*o+Math.cos(i)*Math.cos(n)*a*a,u=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s));return this.R*u}});function z(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 G(t,e,r){return t instanceof z?t:L(t)&&"object"!=typeof t[0]?3===t.length?new z(t[0],t[1],t[2]):2===t.length?new z(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new z(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new z(t,e,r)}z.prototype={equals:function(t,e){return!!t&&(t=G(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("+D(this.lat,t)+", "+D(this.lng,t)+")"},distanceTo:function(t){return X.distance(this,G(t))},wrap:function(){return X.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return O([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new z(this.lat,this.lng,this.alt)}};const H=256,W=.40909994067971484,j=t=>{const e=t.valueOf();return Z(e)},Z=t=>{const e=t/864e5-10957.5,r=6.240059966692059+.017201969994578018*e,i=r+.017453292519943295*(1.9148*Math.sin(r)+.02*Math.sin(2*r)+3e-4*Math.sin(3*r))+1.796593062783907+Math.PI,n=Math.atan2(Math.sin(i)*Math.cos(W),Math.cos(i));return{dec:Math.asin(Math.sin(W)*Math.sin(i)),Hi:(4.889714432387314+6.3003876824396166*e-n)%(2*Math.PI)+2*Math.PI}},Y=(t,e,r)=>{const i=1/e,n=Math.min(t[0]*i,255),o=Math.min(t[1]*i,255),a=Math.min(t[2]*i,255);let s=0;return n+o+a!==0&&(s=n>0?n/255*.5+.5:a>0?.5*(1-a/255):.5),s*r},K=(t=new Date,e)=>{const r=new Date(t.toLocaleString("en-US",{timeZone:"UTC"})),i=new Date(t.toLocaleString("en-US",e?{timeZone:e}:{}));return r.getTime()-i.getTime()};function k(t){t.filter((t=>"MultiPolygon"===t.geometry.type)).forEach((e=>{const{geometry:r,properties:i,type:n}=e;if("MultiPolygon"===r.type)for(let i=0;i<r.coordinates.length;i++)t.push(Object.assign(Object.assign({},e),{geometry:Object.assign(Object.assign({},r),{type:"Polygon",coordinates:r.coordinates[i]})}))}));return t.filter((t=>"Polygon"===t.geometry.type)).map((t=>{const{geometry:e,properties:r}=t,{vertices:n}=i.flatten(e.coordinates),o=new Float32Array(n.map(((t,e)=>{return e%2==1?(r=t,(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+r*Math.PI/360)))/360):(180+t)/360;var r}))),a=i(o),s=a.length>256?new Uint16Array(a):new Uint8Array(a),u=function(t){const{height:e=0,levels:r=0,render_height:i=0}=t;if(r)return 3.04*r;return Math.max(e,i)}(r),h=r.highlight||!1;let l=0,c=0,f=0;for(let t=0;t<o.length;t+=2)l+=o[t],c+=o[t+1],f++;return{aPosition:o,cuts:s,buildingHeight:u,centroid:[l/f,c/f],highlight:h}}))}const q=(t,e)=>{const{lat:r,lng:i}=t;return new P(((t,e)=>(t+180)/360*Math.pow(2,e)*H)(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)*H)(r,e))},V=(t,e)=>{return new z((r=t.y,i=e,n=Math.PI-2*Math.PI*r/H/Math.pow(2,i),180/Math.PI*Math.atan(.5*(Math.exp(n)-Math.exp(-n)))),function(t,e){return t/H/Math.pow(2,e)*360-180}(t.x,e));var r,i,n};let $,J={heightMapTex:null,width:0,height:0,visibleDEMPixelBounds:new B(new P(0,0),new P(0,0)),DEMPixelBounds:new B(new P(0,0),new P(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const Q=t=>r(void 0,void 0,void 0,(function*(){const{demZoom:e,getFeatures:i,terrainSource:n,dsmSource:o,tileLoaded:a,gl:s,bounds:u,buildingRasterizer:h,tileMerger:l,forceUpdate:c=!1}=t,{getSourceUrl:f,getElevation:d,maxZoom:m,tileSize:_,_overzoom:x}=n,g=(p={getFeatures:i},r(void 0,void 0,void 0,(function*(){const{getFeatures:t}=p;try{return k(yield t())}catch(t){console.log("Error merging buildings",t)}return[]})));var p;try{const t=u,r=t.getNorthWest(),i=t.getSouthEast(),n=new B(q(r,e),q(i,e));let x=new P(n.min.x,n.min.y),p=n.max.x-n.min.x;const E=n.max.y-n.min.y,T=n.max.subtract(n.min);T.y>T.x&&(x.x-=H,p+=512);const v=(t=>{const{upperLeft:e,width:r,height:i}=t,n=e.divideBy(H).floor().multiplyBy(H),o=(Math.ceil(r/H)+1)*H,a=(Math.ceil(i/H)+1)*H,s=n.add([o,a]);return new B(n,s)})({upperLeft:x,width:p,height:E}),{x:y,y:A}=v.max.subtract(v.min),R=(t=>{t.sort(((t,e)=>t.y!==e.y?t.y-e.y:t.x-e.x));const e=t.reduce(((t,e)=>e.x<t.x?e:t)).x,r=t.reduce(((t,e)=>e.y<t.y?e:t)).y;return t.map((t=>{const i=Math.pow(2,t.z);return{x:(t.x%i+i)%i,y:(t.y%i+i)%i,z:t.z,xOffset:(t.x-e)*H,yOffset:(t.y-r)*H}}))})((t=>{const{upperLeft:e,width:r,height:i,zoom:n}=t,o=e.divideBy(H).floor(),a=o.x+r/H,s=Math.min(o.y+i/H,Math.pow(2,n)-1),u=[];for(var h=o.x;h<a;h++)for(var l=o.y;l<s;l++)u.push({x:h,y:l,z:n});return u})({upperLeft:v.min,width:y,height:A,zoom:e})),b=n.max.x-n.min.x,M=n.max.y-n.min.y,w=Math.round(b),F=Math.round(M),U=JSON.stringify(R);if(!c&&U===$&&e<m)return J=Object.assign(Object.assign({},J),{outputWidth:w,outputHeight:F,visibleDEMPixelBounds:n,demZoom:e,dirty:!0}),J;const D=yield l.merge(R,{maxZoom:m,width:y,height:A,crossOrigin:"Anonymous",getSourceUrl:f,getElevation:d,tileSize:_,tileLoaded:a});if(null===D)return J=Object.assign(Object.assign({},J),{visibleDEMPixelBounds:n,demZoom:e,dirty:!1}),J;const L=new B(q(new N(o.bounds).getNorthWest(),e),q(new N(o.bounds).getSouthEast(),e)),S=L.min.subtract(v.min),C=L.max.subtract(v.min),I=[S.x/y,S.y/A,C.x/y,C.y/A].map((t=>2*t-1)),O=yield g,{maxHeight:X,heightMapTex:z}=h.raster({upperLeftTile:R[0],width:y,height:A,mapZoom:e,features:O,imageData:D,gl:s,dsmSource:o,dsmCoords:I}),G=Math.max(Math.max(o.maxHeight,X),D.maxHeight);$=U,J={heightMapTex:z,maxHeight:G,width:y,height:A,DEMPixelBounds:v,visibleDEMPixelBounds:n,raster:R,demZoom:e,dirty:!0,outputWidth:w,outputHeight:F}}catch(t){console.error("Could not decode height map",t)}return J})),tt=(t,e)=>{const{r:r,g:i,b:n}=t;return[r/255,i/255,n/255,e]},et=(t,e)=>{const{date:r}=e,{dec:i,Hi:n}=j(r);t.updateDate({dec:i,Hi:n})},rt=(t,e)=>r(void 0,void 0,void 0,(function*(){return yield t.updateDateRange(Object.assign({},e))})),it=(t,e)=>{const{color:r,opacity:i}=e,n=tt(r,i);t.updateColor({colorVec:n})},nt=t=>{const{kernel:e,map:r,heightMap:i,now:n,color:o,opacity:a,belowCanopy:s,skipRender:u}=t;try{const{heightMapTex:t,outputHeight:h,outputWidth:l,maxHeight:c,width:f,height:d,DEMPixelBounds:m,visibleDEMPixelBounds:_,demZoom:x}=i;if(0===f||0===d)return;const{min:g,max:p}=_;if(!g||!p)return;const{x:E,y:T}=p.subtract(g),v=m.min,y=r.getPixelDimensions(),A=r.screenUnproject([0,0]),R=r.screenUnproject([y.width,0]),b=r.screenUnproject([y.width,y.height]),M=r.screenUnproject([0,y.height]),w=[M,b,A,R].map((t=>r.project(t,x))),F=w.map((t=>[(t.x-v.x)/f,(t.y-v.y)/d])).flat(),U=w.map((t=>[(t.x-g.x)/E,(t.y-g.y)/T])).map((t=>[2*t[0]-1,(2*t[1]-1)*(r.isLeaflet()?-1:1)])).flat(),D=v.y/H/Math.pow(2,x),L=d/H/Math.pow(2,x),P=new N(V(m.getTopLeft(),x),V(m.getBottomRight(),x)),S=P.getWest(),C=Math.abs(P.getWest()-P.getEast());((t,e)=>{const{color:r,opacity:i,date:n}=e,o=tt(r,i),{dec:a,Hi:s}=j(n);t.updateHeightMap(Object.assign({dec:a,Hi:s,colorVec:o,step:1},e))})(e,{heightMapTex:t,maxHeight:c,width:f,height:d,heightMapZoom:x,cornerTextureCoords:F,cornerClipCoords:U,topYCoord:D,ySize:L,west:S,dLng:C,date:n,color:o,opacity:a,outputHeight:h,outputWidth:l,belowCanopy:s,skipRender:u})}catch(t){console.error("EXCEPTION",t)}};const ot=t=>{const e=()=>!t.getPitch;return{project:(r,i)=>{if(e())return t.project(r,i);{const{lat:t,lng:e}=r;return new P(((t,e)=>(t+180)/360*Math.pow(2,e)*H)(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)*H)(t,i))}},unproject:(r,i)=>{return e()?t.unproject(r,i):new z((n=r.y,o=i,a=Math.PI-2*Math.PI*n/H/Math.pow(2,o),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/H/Math.pow(2,e)*360-180}(r.x,i));var n,o,a},screenUnproject:r=>e()?t.containerPointToLatLng(r):t.unproject(r),getZoom:()=>e()?t.getZoom():t.getZoom()+1,getCenter:()=>t.getCenter(),getBounds:()=>t.getBounds(),eachLayer:r=>{e()&&t.eachLayer(r)},getBearing:()=>e()?0:t.getBearing(),getPitch:()=>e()?0:t.getPitch(),rawMap:()=>t,isLeaflet:e,getPixelDimensions:()=>{const e=t.getContainer();return{width:e.clientWidth,height:e.clientHeight}},createBounds:t=>{const{nw:e,se:r}=t;return new N(e,r)}}};const at=t=>{const{gl:e}=t,{texture:r,imageData:i=null,format:n=e.RGBA,width:o,height:a,filter:s=e.NEAREST,wrap:u=e.CLAMP_TO_EDGE,type:h=e.UNSIGNED_BYTE,internalFormat:l=n}=t;e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,s),e.texImage2D(e.TEXTURE_2D,0,l,o,a,0,n,h,i)};function st(t){const{gl:e,vSrc:r,fSrc:i}=t,n=e.createShader(e.VERTEX_SHADER);e.shaderSource(n,r),e.compileShader(n);const o=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(o,i),e.compileShader(o);const a=e.createProgram();return e.attachShader(a,n),e.attachShader(a,o),e.linkProgram(a),a}class ut{constructor(t){this.gl=t,this.program=st({gl:t,vSrc:"\nuniform vec3 xyz;\nuniform vec2 dimensions;\nuniform bool use_dsm;\nattribute vec2 dsm_position;\nattribute vec2 a_position;\nfloat PI = 3.141592653589793;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\n\tvoid main() {\n\t\tif (use_dsm == true) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = dsm_position;\n v_use_dsm = 1.0;\n\t\t\treturn;\n\t\t}\n\t\tif (abs(a_position) == vec2(1,1)) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = a_position * 0.5 + 0.5;\n\t\t\treturn;\n\t\t}\n\t\tfloat x = a_position.x - xyz.x;\n\t\tfloat y = a_position.y - xyz.y;\n\t\tvec2 transformed = vec2(x, y);\n\t\tvec2 normalized = transformed / dimensions;\n\t\tvec2 final = normalized * 2.0 - 1.0;\n\t\tgl_Position = vec4(final, 0, 1);\n\t}\n",fSrc:"\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform vec4 color;\nuniform sampler2D height_map;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n if (v_use_dsm == 1.0) {\n\t \t gl_FragColor = vec4(0.0, 0.0, textureColor.b, textureColor.a);\n if (gl_FragColor.zw == vec2(0.0)) {\n discard;\n }\n } else {\n gl_FragColor = vec4(textureColor.b, textureColor.a, textureColor.b, textureColor.a);\n }\n // DSM noData values should not be included in heightMap because they produce ugly borders\n\t\treturn;\n\t} \n\tgl_FragColor = color;\n}\n"}),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.dsmAttributeLocation=t.getAttribLocation(this.program,"dsm_position"),this.useDSMUniformLocation=t.getUniformLocation(this.program,"use_dsm"),this.xyzUniformLocation=t.getUniformLocation(this.program,"xyz"),this.dimensionsUniformLocation=t.getUniformLocation(this.program,"dimensions"),this.heightMapUniformLocation=t.getUniformLocation(this.program,"height_map"),this.colorUniformLocation=t.getUniformLocation(this.program,"color"),this.positionBuffer=t.createBuffer(),this.dsmBuffer=t.createBuffer(),this.indexBuffer=t.createBuffer(),this.targetTexture=t.createTexture()}raster(t){const{features:e,upperLeftTile:r,mapZoom:i,width:n,height:o,imageData:a,dsmCoords:s,dsmSource:u,gl:h}=t,{x:l,y:c,z:f}=r;let d=0;h.useProgram(this.program),h.activeTexture(h.TEXTURE1);const m=h.createTexture();h.bindTexture(h.TEXTURE_2D,m),h.pixelStorei(h.UNPACK_ALIGNMENT,2),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,h.NEAREST),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,h.NEAREST),h.texImage2D(h.TEXTURE_2D,0,h.LUMINANCE_ALPHA,n,o,0,h.LUMINANCE_ALPHA,h.UNSIGNED_BYTE,a),h.pixelStorei(h.UNPACK_ALIGNMENT,4);const _=n,x=o;h.activeTexture(h.TEXTURE0),h.bindTexture(h.TEXTURE_2D,this.targetTexture),h.texImage2D(h.TEXTURE_2D,0,h.RGBA,_,x,0,h.RGBA,h.UNSIGNED_BYTE,null),i>15&&e.length>5?(h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,h.NEAREST),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,h.NEAREST)):(h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,h.LINEAR),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,h.LINEAR)),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE),h.viewport(0,0,_,x);const g=h.createFramebuffer();h.bindFramebuffer(h.FRAMEBUFFER,g);const p=h.COLOR_ATTACHMENT0;h.framebufferTexture2D(h.FRAMEBUFFER,p,h.TEXTURE_2D,this.targetTexture,0),h.disable(h.BLEND),h.bindBuffer(h.ARRAY_BUFFER,this.positionBuffer),h.bindBuffer(h.ELEMENT_ARRAY_BUFFER,this.indexBuffer),h.clearColor(0,0,0,0),h.clear(h.COLOR_BUFFER_BIT);const E=l/Math.pow(2,f),T=c/Math.pow(2,f),v=new P(E,T),y=n/H/Math.pow(2,f),A=o/H/Math.pow(2,f);h.uniform3f(this.xyzUniformLocation,E,T,f),h.uniform2f(this.dimensionsUniformLocation,y,A),h.uniform1i(this.heightMapUniformLocation,1),h.uniform1i(this.useDSMUniformLocation,0);const R=new Float32Array([-1,-1,1,-1,-1,1,1,1]);if(h.enableVertexAttribArray(this.positionAttributeLocation),h.bufferData(h.ARRAY_BUFFER,R,h.STATIC_DRAW),h.vertexAttribPointer(this.positionAttributeLocation,2,h.FLOAT,!1,0,0),h.uniform4f(this.colorUniformLocation,0,0,0,0),h.drawArrays(h.TRIANGLE_STRIP,0,4),e.forEach((t=>{const{buildingHeight:e,aPosition:r,cuts:i,centroid:s,highlight:u}=t,l=new P(s[0],s[1]).subtract(v).unscaleBy(new P(y,A)).scaleBy(new P(n,o)).floor();if(l.x<0||l.y<0||l.x>n||l.y>o)return;const c=256*a[l.y*n*2+2*l.x]+a[l.y*n*2+2*l.x+1]+5*e,f=Math.floor(c/256)/255,m=Math.floor(c%256)/255;d=Math.max(d,c/5),h.uniform4f(this.colorUniformLocation,f,m,f,m),h.bufferData(h.ARRAY_BUFFER,r,h.DYNAMIC_DRAW),h.vertexAttribPointer(this.positionAttributeLocation,2,h.FLOAT,!1,0,0),h.bufferData(h.ARRAY_BUFFER,r,h.DYNAMIC_DRAW),h.vertexAttribPointer(this.dsmAttributeLocation,2,h.FLOAT,!1,0,0),h.bufferData(h.ELEMENT_ARRAY_BUFFER,i,h.DYNAMIC_DRAW),h.drawElements(h.TRIANGLES,i.length,i.length>256?h.UNSIGNED_SHORT:h.UNSIGNED_BYTE,0)})),h.deleteTexture(m),0!==u.data.length){h.activeTexture(h.TEXTURE1);const t=h.createTexture();h.bindTexture(h.TEXTURE_2D,t),h.pixelStorei(h.UNPACK_ALIGNMENT,2),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,h.NEAREST),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,h.NEAREST),h.texImage2D(h.TEXTURE_2D,0,h.LUMINANCE_ALPHA,u.width,u.height,0,h.LUMINANCE_ALPHA,h.UNSIGNED_BYTE,u.data),h.pixelStorei(h.UNPACK_ALIGNMENT,4);const e=[s[0],s[3],s[2],s[3],s[0],s[1],s[2],s[1]],r=new Float32Array(e);h.enableVertexAttribArray(this.positionAttributeLocation),h.bufferData(h.ARRAY_BUFFER,r,h.STATIC_DRAW),h.vertexAttribPointer(this.positionAttributeLocation,2,h.FLOAT,!1,0,0),h.enableVertexAttribArray(this.dsmAttributeLocation),h.bindBuffer(h.ARRAY_BUFFER,this.dsmBuffer),h.bufferData(h.ARRAY_BUFFER,new Float32Array([0,1,1,1,0,0,1,0]),h.STATIC_DRAW),h.vertexAttribPointer(this.dsmAttributeLocation,2,h.FLOAT,!1,0,0),h.uniform4f(this.colorUniformLocation,0,0,0,0),h.uniform1i(this.useDSMUniformLocation,1),h.colorMask(!1,!1,!0,!0),h.drawArrays(h.TRIANGLE_STRIP,0,4),h.deleteTexture(t)}return h.colorMask(!0,!0,!0,!0),h.deleteFramebuffer(g),{maxHeight:d,heightMapTex:this.targetTexture}}}const ht=t=>{const{tile:e,maxZoom:r,tileSize:i}=t;let{x:n,y:o,z:a}=e;if(a>r){const t=Math.pow(2,e.z-r);n=Math.floor(n/t),o=Math.floor(o/t),a=r}return{x:i===H?n:Math.floor(n/2),y:i===H?o:Math.floor(o/2),z:i===H?a:a-1}};class lt{constructor(t){this.gl=t,this.program=st({vSrc:"\n attribute vec4 a_position;\n varying vec2 v_pos;\n void main() {\n v_pos = ((a_position + 1.0) * 0.5).xy;\n gl_Position = a_position;\n }\n",fSrc:"\n precision mediump float;\n varying vec2 v_pos;\n uniform sampler2D u_texture;\n void main() {\n gl_FragColor = texture2D(u_texture, v_pos);\n }\n",gl:t}),t.useProgram(this.program),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.positionBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(this.positionAttributeLocation),t.vertexAttribPointer(this.positionAttributeLocation,2,t.FLOAT,!1,0,0),this.tileTexture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.tileTexture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),this.outputTexture=t.createTexture(),this.framebuffer=t.createFramebuffer(),this.inProgress=[],this.finished=0}merge(t,e){return r(this,void 0,void 0,(function*(){const i=this.gl,{width:n,height:o,crossOrigin:a,getSourceUrl:s,getElevation:u,tileSize:h,tileLoaded:l,maxZoom:c}=e;if(i){const e=new Uint8ClampedArray(2*n*o);e.maxHeight=0,this.inProgress.forEach((t=>t.src="")),this.inProgress=[],this.finished=0;const f=new Set;t.forEach((t=>{f.add(s(ht({tile:t,maxZoom:c,tileSize:h})))}));const d=Array.from(f).map((o=>r(this,void 0,void 0,(function*(){return new Promise(((r,l)=>{const f=new Image;this.inProgress.push(f),f.onload=()=>{t.filter((t=>o===s(ht({tile:t,maxZoom:c,tileSize:h})))).forEach((t=>{let r=0,o=0;const a=514===h?1:0;let s=0,l=H,d=H;if(h!==H&&(r=t.x%2*H,o=t.y%2*H,l=H,d=H),t.z>c){const e=Math.pow(2,t.z-c);h!==H&&(r=Math.floor(t.x/e)%2*H,o=Math.floor(t.y/e)%2*H),r+=H*(t.x%e/e),o+=H*(t.y%e/e),l=H/e,d=H/e,s=514===h?1:0}i.useProgram(this.program),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.tileTexture),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,f),i.activeTexture(i.TEXTURE1),at({gl:i,texture:this.outputTexture,imageData:null,format:i.RGBA,width:h,height:h,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST}),i.bindFramebuffer(i.FRAMEBUFFER,this.framebuffer),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,this.outputTexture,0);const m=i.checkFramebufferStatus(i.FRAMEBUFFER);m!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+m),i.bindBuffer(i.ARRAY_BUFFER,this.positionBuffer),i.enableVertexAttribArray(this.positionAttributeLocation),i.vertexAttribPointer(this.positionAttributeLocation,2,i.FLOAT,!1,0,0),i.viewport(0,0,h,h),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4);const _=new Uint8Array(4*(l+s)*(d+s));i.readPixels(a+r,a+o,l+s,d+s,i.RGBA,i.UNSIGNED_BYTE,_),i.bindFramebuffer(i.FRAMEBUFFER,null);const x=new Uint8ClampedArray(131072);let g=new Array((l+s)*(d+s)),p=H/l;for(let t=0;t<_.length;t+=4){const r=u({r:_[t],g:_[t+1],b:_[t+2],a:_[t+3]});e.maxHeight=Math.max(r,e.maxHeight);const i=5*(r||0);g[t/4]=i}if(p>1&&514===h)for(g=function(t,e,r,i){const n=Math.floor(e*i),o=Math.floor(r*i),a=[];for(let s=0;s<o;s++)for(let o=0;o<n;o++){const n=o/i,u=s/i,h=Math.floor(n),l=Math.floor(u),c=Math.min(h+1,e-1),f=Math.min(l+1,r-1),d=n-h,m=u-l,_=l*e+c,x=f*e+h,g=f*e+c,p=t[l*e+h]*(1-d)*(1-m)+t[_]*d*(1-m)+t[x]*(1-d)*m+t[g]*d*m;a.push(p)}return function(t,e,r,i,n){if(i>=e||n>=r)return[];const o=e-i,a=r-n,s=[];for(let r=0;r<a;r++)for(let i=0;i<o;i++){const n=r*e+i;s.push(t[n])}return s}(a,Math.sqrt(a.length),Math.sqrt(a.length),i,i)}(g,l+1,d+1,p);p>1;)p/=2,d*=2,l*=2;for(let t=0;t<x.length;t+=2){const e=g[Math.floor(t/2/H/p)*l+Math.floor(t/2%H/p)],r=Math.floor(e/256),i=Math.floor(e%256);x[t]=r,x[t+1]=i}for(let r=0;r<H;r++)e.set(x.slice(r*H*2,(r+1)*H*2),2*(t.yOffset*n+r*n+t.xOffset))})),r(null)},f.onerror=t=>{if(f.src!==f.originalSource)return l("new tiles requested");r(null)},f.crossOrigin=a||null,f.src=o,f.originalSource=f.src})).then((()=>{this.finished++,l(this.finished,this.inProgress.length)}))}))));try{yield Promise.all(d)}catch(t){return console.log(`${d.length} requests aborted`,t),null}return this.inProgress=[],e}throw new Error("Could not get canvas context for merging tile images")}))}}class ct extends class extends class{constructor(){this.events={}}on(t,e){return"object"!=typeof this.events[t]&&(this.events[t]=[]),this.events[t].push(e),()=>this.removeListener(t,e)}removeListener(t,e){if("object"!=typeof this.events[t])return;const r=this.events[t].indexOf(e);r>-1&&this.events[t].splice(r,1)}removeAllListeners(){Object.keys(this.events).forEach((t=>this.events[t].splice(0,this.events[t].length)))}emit(t,...e){"object"==typeof this.events[t]&&[...this.events[t]].forEach((t=>t.apply(this,e)))}once(t,e){const r=this.on(t,((...t)=>{r(),e.apply(this,t)}));return r}}{constructor(...t){super(),this.options={date:new Date,color:"000",opacity:.3,sunExposure:{enabled:!1,startDate:new Date,endDate:new Date,iterations:32},apiKey:"",terrainSource:{maxZoom:15,tileSize:256,_overzoom:15,getSourceUrl:t=>"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/7/17/45.png",getElevation:t=>{const{r:e,g:r,b:i}=t;return 256*e+r+i/256-32768}},dsmSource:{bounds:[{lat:0,lng:0},{lat:0,lng:0}],data:new Uint8ClampedArray,width:0,height:0,maxHeight:0},belowCanopy:!1,getFeatures:()=>Promise.resolve([]),getSize:()=>({width:Number.NaN,height:Number.NaN}),debug:t=>{}};const e=t[0];if(this.options=Object.assign(this.options,e),!this.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:this.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((t=>r(this,void 0,void 0,(function*(){if(200!==t.status)throw new Error(yield t.text())})))).catch((t=>r(this,void 0,void 0,(function*(){throw new Error(`Could not load ShadeMap API. Key: ${this.options.apiKey} Error: ${t}`)})))),this._canvas=document.createElement("canvas"),this._color=this._parseColor(this.options.color),this._reset=this._reset.bind(this),this._draw=this._draw.bind(this)}onRemove(){return this._map&&this._map.off("moveend",this._reset),this}setDate(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(et(this._compiledKernel,{date:this.options.date}),this._heightMap&&this._flush())):this.emit("idle"),this}_setDateForTimezone(t,e){let r=0;e&&(r=K(this.options.date)-K(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&&(it(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&&(it(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setBelowCanopy(t){return this.options.belowCanopy=t,this._heightMap?this._draw(this._heightMap):this._reset(),this}setTerrainSource(t){return this.options.terrainSource=t,delete this._heightMap,this._reset(),this}setDSMSource(t){return this.options.dsmSource=t,delete this._heightMap,this._reset(),this}setSunExposure(t=!1,e){return r(this,void 0,void 0,(function*(){if(this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:t}),e){const{startDate:r=new Date,endDate:i=new Date,iterations:n=32}=e;this.options.sunExposure={enabled:t,startDate:r,endDate:i,iterations:n}}if(this._map&&this._compiledKernel&&this._heightMap){if(!1===t)et(this._compiledKernel,{date:this.options.date});else{const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!(t instanceof Date&&e instanceof Date))throw new Error("Start date or end date or both are missing");if(e.getTime()<t.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield rt(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._flush()}return this}))}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:i,height:n}=this._heightMap,o=e.min;return t.map((t=>{const e=q(t,r);return[(e.x-o.x)/i,(e.y-o.y)/n]}))}return[]}_getBounds(t,e){const{width:r,height:i}=this.options.getSize();if(Number.isNaN(r)||Number.isNaN(i))return t.getBounds();const n=t.getCenter(),o=q(n,e),a=V(new P(o.x-r/2,o.y-i/2),e),s=V(new P(o.x+r/2,o.y+i/2),e);return t.createBounds({nw:a,se:s})}_getDEMZoom(t){const e=Math.min(this.options.terrainSource._overzoom||this.options.terrainSource.maxZoom,t.getZoom());return Math.round(e)}_reset(){return r(this,void 0,void 0,(function*(){if(this.options.debug("_reset()"),this._map){const t=ot(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),n=r.filter((t=>t.canonical.z===i)).map((t=>t.canonical)),[o,a,s,u]=n.reduce(((t,e)=>[Math.min(t[0],e.x),Math.min(t[1],e.y),Math.max(t[2],e.x),Math.max(t[3],e.y)]),[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER]),h=V(new P(512*o,512*a),i+1),l=V(new P(512*(s+1),512*(u+1)),i+1);e=i+1,this._bounds=t.createBounds({nw:h,se:l})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield Q({gl:this._gl,demZoom:e,bounds:this._bounds,terrainSource:this.options.terrainSource,dsmSource:this.options.dsmSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,tileLoaded:(t,e)=>this.emit("tileloaded",t,e),forceUpdate:!this._heightMap});this._heightMap=r,r.dirty&&(yield this._draw(r))}return this}))}_draw(t){return r(this,void 0,void 0,(function*(){if(this.options.debug("_draw()"),this._canvas&&this._compiledKernel&&this._map){if(nt({kernel:this._compiledKernel,map:ot(this._map),heightMap:t,color:this._color,belowCanopy:this.options.belowCanopy,opacity:this.options.opacity,now:this.options.date,maxZoom:this.options.terrainSource.maxZoom,skipRender:this.options.sunExposure.enabled}),this.options.sunExposure.enabled){const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!0===(yield rt(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._bounds&&this._repositionCanvas(this._bounds)}return this}))}readPixel(t,e){const r=new Uint8Array(4);return this._gl&&this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r),r}readPixels(t,e,r,i){const n=new Uint8Array(r*i*4);return this._gl&&this._gl.readPixels(t,e,r,i,this._gl.RGBA,this._gl.UNSIGNED_BYTE,n),n}toGeoTiff(){const t=(t,e)=>{const r=this.readPixels(0,0,t,e),i=t*e*1,n=1*t,o=(e-1)*n,a=new Uint8Array(i),s=new Uint8Array(i);let u=0;const{startDate:h,endDate:l}=this.options.sunExposure;this.options.sunExposure.enabled&&h&&l&&(u=l.getTime()-h.getTime());for(let t=0;t<r.length;t+=4){let e;if(this.options.sunExposure.enabled){const i=r.subarray(t,t+3),n=Y(i,.5,u)/1e3/60,o=Math.min(Math.floor(n/6),255);e=new Uint8Array([o])}else{e=r[t]+r[t+1]+r[t+2]===0?new Uint8Array([255]):new Uint8Array([0])}a.set(e,t/4*1)}if(this._map&&!ot(this._map).isLeaflet())return a;for(let t=0;t<i;t+=n)s.set(a.subarray(t,t+n),o-t);return s};if(this._map&&this._heightMap){const e=this._heightMap.outputWidth,r=this._heightMap.outputHeight,i=t(e,r),n=ot(this._map),{lat:o,lng:a}=n.getBounds().getNorthWest(),s=n.getBounds().getSouthEast(),u=[0,0,0,a,o,0],h=[(s.lng-a)/e,(o-s.lat)/r,0];return this.options.sunExposure.enabled,{data:i,metadata:{width:e,height:r,ModelTiepoint:u,ModelPixelScale:h,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}return null}_generateShadeProfile(t){if(this._compiledKernel){const e=this._lngLatToTextureCoords(t.locations);return((t,e)=>{const r=tt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=tt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{texCoords:e}))}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=K(t.startDate)-K(t.startDate,t.tzId),r=t.startDate.getTime()-e,i=t.endDate.getTime()-e,n=this._lngLatToTextureCoords([t.location])[0],{output:o,outputWidth:a,outputHeight:s}=((t,e)=>{const r=tt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=tt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateLocationShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:i}))})(this._compiledKernel,Object.assign(Object.assign({},t),{startTime:r,endTime:i,texCoord:n}));return o.toArray=function(){const e=new Array;for(let r=0;r<a;r++){const i=[];for(let e=s-1;e>=0;e--){const n=e*a*4+4*r,o=this.slice(n,n+4);i.push(o.join("")===t.sunColor.join("")?1:0)}e.push(i)}return e},{data:o,width:a,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:i,endDate:n}=this.options.sunExposure,o=n.getTime()-i.getTime(),a=Y(r,.5,o);return Math.abs(a/1e3/3600)}return 0}_repositionCanvas(t){}_flush(){}flushSync(){this._gl&&this._gl.finish()}_parseColor(t){t=t.replace("#","");const e={r:0,g:0,b:0};return/^([0-9A-F]{3}){1,2}$/i.test(t)&&(3===t.length?(e.r=parseInt(t[0]+t[0],16),e.g=parseInt(t[1]+t[1],16),e.b=parseInt(t[2]+t[2],16)):6===t.length&&(e.r=parseInt(t[0]+t[1],16),e.g=parseInt(t[2]+t[3],16),e.b=parseInt(t[4]+t[5],16))),e}}{constructor(t){super(t);const e={preserveDrawingBuffer:!0,antialias:!1};this._gl=this._canvas.getContext("webgl",e)||this._canvas.getContext("experimental-webgl",e),this._canvas.width=window.innerWidth,this._canvas.height=window.innerHeight,this._compiledKernel=function(t){const{context:e,setRenderBuffer:i}=t,n=e,o=st({gl:n,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 a_pos;attribute vec2 a_tex_pos;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;void main(void){gl_Position=vec4(a_pos,0,1);vTexCoordFull=(gl_Position*0.5+0.5).xy;vTexCoordCropped=a_tex_pos;}",fSrc:"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nprecision lowp int;precision lowp sampler2D;float atan2(float v1,float v2){if(v1==0.0||v2==0.0)return 0.0;return atan(v1,v2);}float _pow(float v1,float v2){if(v2==0.0)return 1.0;return pow(v1,v2);}float integerMod(float x,float y){float res=floor(mod(x,y));return res*(res>floor(y)-1.0 ? 0.0 : 1.0);}float divWithIntCheck(float x,float y){if(floor(x)==x&&floor(y)==y&&integerMod(x,y)==0.0){return float(int(x)/int(y));}return x/y;}float integerCorrectionModulo(float number,float divisor){if(number<0.0){number=abs(number);if(divisor<0.0){divisor=abs(divisor);}return-(number-(divisor*floor(divWithIntCheck(number,divisor))));}if(divisor<0.0){divisor=abs(divisor);}return number-(divisor*floor(divWithIntCheck(number,divisor)));}float getDEMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*255.0*256.0+result.g*255.0)/5000.0;}float getDSMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.b*255.0*256.0+result.a*255.0)/5000.0;}vec4 actualColor;void color(float r,float g,float b,float a){actualColor=vec4(r,g,b,a);}void color(float r,float g,float b){color(r,g,b,1.0);}void color(float r){color(r,r,r,1.0);}void color(vec4 color){actualColor=color;}const int LOOP_MAX=1000;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;uniform sampler2D user_a;uniform float user_width;uniform float user_height;uniform float user_maxHeight;uniform float user_zoom;uniform float user_topYCoord;uniform float user_ySize;uniform vec4 user_color;uniform vec4 u_sunColor;uniform float user_step;uniform float user_west;uniform float user_dLng;uniform float user_dec;uniform float user_Hi;uniform bool u_below_canopy;uniform sampler2D user_sunExposureTexture;uniform bool user_outputSunExposure;uniform bool u_outputShadeProfile;uniform sampler2D u_decHiTexture;uniform sampler2D u_gpxTexture;uniform bool u_outputLocationShadeProfile;uniform vec2 u_shadeProfileLocation;float kernelResult;void kernel(){float sunDec=user_dec;float sunHi=user_Hi;vec4 shade_color=user_color;float maxHeight=user_maxHeight/1000.0;float user_x=vTexCoordCropped.x;float user_y=vTexCoordCropped.y;if(u_outputShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;vec4 gpx=texture2D(u_gpxTexture,vec2(vTexCoordFull.x,.5));user_x=gpx.x;user_y=gpx.y;}if(u_outputLocationShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;user_x=u_shadeProfileLocation.x;user_y=u_shadeProfileLocation.y;}float user_lit=1.0;float dsm_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(u_below_canopy==true){float dem_height=getDEMElevationFromSampler2D(user_a,user_x,user_y);if(dsm_height-dem_height>.002){user_lit=0.0;}}float user_z=dsm_height;float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=user_west+(user_dLng*user_x);float user_H=integerCorrectionModulo((sunHi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(sunDec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(sunDec))+((cos(user_lat)*cos(sunDec))*cos(user_H))));float user_zoom_factor=_pow(2.0,user_zoom);float user_kmPerPixel=divWithIntCheck(156.5430339296875,user_zoom_factor)*abs(cos(user_lat));float user_dx=((-sin(sun_azimuth)*cos(sun_altitude))*user_step)/user_width;float user_dy=((cos(sun_azimuth)*cos(sun_altitude))*user_step)/user_height;float user_dz=((sin(sun_altitude)*user_kmPerPixel)*user_step);float shadow_bias=0.0005;float user_curvature=0.0;float cur_height=0.0;float user_distance=0.0;float user_startX=user_x;float user_startY=user_y;user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;if((abs(1.0)<0.0)){kernelResult=0.0;return;}float minAngle=asin((earthRadiusInKm/(earthRadiusInKm+user_z)))-(user_PI/2.0);if(user_z<0.0||sun_altitude<minAngle){user_lit=0.0;}else{float xIter=ceil(user_dx<0.0 ? abs(user_x/user_dx):(1.0-user_x)/user_dx);float yIter=ceil(user_dy<0.0 ? abs(user_y/user_dy):(1.0-user_y)/user_dy);float zIter=ceil(user_dz<0.0 ? float(LOOP_MAX):(maxHeight-user_z)/user_dz);int iter=int(min(xIter,min(yIter,zIter)));float user_distance=(sqrt(pow(user_dx*user_width,2.0)+pow(user_dy*user_height,2.0))*user_kmPerPixel)/earthRadiusInKm;for(int safeI=0;safeI<LOOP_MAX;safeI++){if(safeI>iter){break;}cur_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(cur_height-user_z>shadow_bias){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;vec4 result=texture2D(user_a,vec2(user_x,user_y));iter=0;break;}}user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;}}if((user_lit==1.0)){if(u_outputLocationShadeProfile==true&&u_sunColor==shade_color){float timeInSun=pow(.7,pow(sin(sun_altitude),.678))*sin(sun_altitude)*(1.0/0.7);float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,1.0);}else{color(u_sunColor);}}else{color(shade_color);}if(user_outputSunExposure){vec4 aggregateColor=texture2D(user_sunExposureTexture,vec2(vTexCoordFull.x,vTexCoordFull.y));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;}"});n.useProgram(o);const a=n.createBuffer(),s=n.getAttribLocation(o,"a_pos"),u=n.createBuffer(),h=n.getAttribLocation(o,"a_tex_pos"),l=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,l),n.bufferData(n.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);const c=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,c),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),n.STATIC_DRAW);const f=n.getUniformLocation(o,"user_a");n.uniform1i(f,0);const d=n.getUniformLocation(o,"user_width"),m=n.getUniformLocation(o,"user_height"),_=n.getUniformLocation(o,"user_maxHeight"),x=n.getUniformLocation(o,"user_zoom"),g=n.getUniformLocation(o,"user_topYCoord"),p=n.getUniformLocation(o,"user_ySize"),E=n.getUniformLocation(o,"user_step"),T=n.getUniformLocation(o,"user_west"),v=n.getUniformLocation(o,"user_dLng"),y=n.getUniformLocation(o,"user_dec"),A=n.getUniformLocation(o,"user_Hi"),R=n.getUniformLocation(o,"user_color"),b=n.getUniformLocation(o,"u_below_canopy"),M=n.getUniformLocation(o,"user_sunExposureTexture"),w=n.getUniformLocation(o,"user_outputSunExposure"),F=n.getUniformLocation(o,"u_outputShadeProfile"),U=n.getUniformLocation(o,"u_gpxTexture"),D=n.getUniformLocation(o,"u_decHiTexture"),L=n.getUniformLocation(o,"u_sunColor"),P=n.getUniformLocation(o,"u_outputLocationShadeProfile"),S=n.getUniformLocation(o,"u_shadeProfileLocation"),C=n.createTexture();let B=0,I=0,N=0,O=null;const X=()=>{I&&N&&(n.useProgram(o),n.bindBuffer(n.ARRAY_BUFFER,a),n.enableVertexAttribArray(s),n.vertexAttribPointer(s,2,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,u),n.enableVertexAttribArray(h),n.vertexAttribPointer(h,2,n.FLOAT,!1,0,0),null!==O&&(n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,O)),i(n,I,N),n.viewport(0,0,I,N),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLE_STRIP,0,4))};let z=0,G=0,H=0,W="";const Y=t=>{const e=(t.endTime-t.startTime)/86400/1e3,r=1440;if(n.activeTexture(n.TEXTURE3),n.uniform1i(D,3),t.startTime!==G||t.endTime!==H||t.tzId!==W){G=t.startTime,H=t.endTime,W=t.tzId;const i=[],o=828e5,a=K(new Date(G),W);for(let t=0;t<e;t++){const e=K(new Date(G+86400*t*1e3+o),W)-a;i[t]=e}const s=new Float32Array(r*e*2);for(let t=0;t<r;t++)for(let r=0;r<e;r++){const n=G+86400*r*1e3+60*t*1e3,{dec:o,Hi:a}=Z(n+i[r]);s[2*(t*e+r)]=-o,s[2*(t*e+r)+1]=a/10}at({gl:n,texture:C,imageData:s,width:e,height:r,wrap:n.CLAMP_TO_EDGE,filter:n.NEAREST,format:n.RG,internalFormat:n.RG32F,type:n.FLOAT})}else n.bindTexture(n.TEXTURE_2D,C);return{outputWidth:e,outputHeight:r}};return{updateHeightMap:function(t){const{heightMapTex:e,width:r,height:i,maxHeight:s,heightMapZoom:h,topYCoord:l,ySize:c,colorVec:f,step:M,west:w,dLng:F,dec:U,Hi:D,cornerClipCoords:L,cornerTextureCoords:P,outputWidth:S,outputHeight:C,belowCanopy:z,skipRender:G}=t;n.useProgram(o),I=S,N=C,O=e,n.bindBuffer(n.ARRAY_BUFFER,a),n.bufferData(n.ARRAY_BUFFER,new Float32Array(L),n.STATIC_DRAW),n.bindBuffer(n.ARRAY_BUFFER,u),n.bufferData(n.ARRAY_BUFFER,new Float32Array(P),n.STATIC_DRAW),n.uniform1f(d,r),n.uniform1f(m,i),n.uniform1f(_,s),n.uniform1f(x,h),n.uniform1f(g,l),n.uniform1f(p,c),n.uniform4fv(R,f),n.uniform1f(E,M),n.uniform1f(T,w),n.uniform1f(v,F),n.uniform1f(y,U),n.uniform1f(A,D),n.uniform1f(b,z?1:0),G||(window.cancelAnimationFrame(B),B=window.requestAnimationFrame(X))},updateDate:t=>{const{dec:e,Hi:r}=t;n.useProgram(o),n.uniform1f(y,e),n.uniform1f(A,r),window.cancelAnimationFrame(B),B=window.requestAnimationFrame(X)},updateDateRange:t=>r(this,void 0,void 0,(function*(){const{startDate:e,endDate:r,iterations:i,emit:l}=t;n.useProgram(o);const c=z=Date.now(),f=Math.floor((r.getTime()-e.getTime())/i),d=n.getUniform(o,R),m=I,_=N,x=n.createTexture();n.activeTexture(n.TEXTURE2),n.bindTexture(n.TEXTURE_2D,x),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,m,_,0,n.RGBA,n.UNSIGNED_BYTE,null),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST);const g=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,g);const p=n.COLOR_ATTACHMENT0;n.framebufferTexture2D(n.FRAMEBUFFER,p,n.TEXTURE_2D,x,0);for(let t=0;t<i;t++){if(n.useProgram(o),l("tileloaded",t,i-1),c!==z)return n.deleteFramebuffer(g),n.deleteTexture(x),n.uniform4fv(R,d),!0;yield new Promise(((r,l)=>{window.requestAnimationFrame((()=>{n.useProgram(o),null!==O&&(n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,O)),n.bindFramebuffer(n.FRAMEBUFFER,g);const l=n.checkFramebufferStatus(n.FRAMEBUFFER);l!==n.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+l);const{dec:c,Hi:d}=j(new Date(e.getTime()+f*t));n.uniform1f(y,c),n.uniform1f(A,d),n.uniform4fv(R,[1/i,0,0,1]),n.bindBuffer(n.ARRAY_BUFFER,a),n.enableVertexAttribArray(s),n.vertexAttribPointer(s,2,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,u),n.enableVertexAttribArray(h),n.vertexAttribPointer(h,2,n.FLOAT,!1,0,0),n.viewport(0,0,m,_),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE),n.drawArrays(n.TRIANGLE_STRIP,0,4),r()}))}))}return n.deleteFramebuffer(g),yield new Promise(((t,e)=>{window.requestAnimationFrame((()=>{if(n.useProgram(o),c!==z)return n.deleteTexture(x),n.uniform4fv(R,d),void t(!0);n.activeTexture(n.TEXTURE2),n.bindTexture(n.TEXTURE_2D,x),n.uniform1i(M,2),n.uniform1i(w,1),X(),n.uniform1i(w,0),n.uniform1i(M,0),n.deleteTexture(x),n.uniform4fv(R,d),t(!1)}))}))})),updateColor:t=>{const{colorVec:e}=t;n.useProgram(o),n.uniform4fv(R,e),window.cancelAnimationFrame(B),B=window.requestAnimationFrame(X)},generateShadeProfile:t=>{n.useProgram(o);const{dates:e,texCoords:r,shadeColor:i,sunColor:a}=t,u=r.length,f=e.length,d=n.getUniform(o,R);n.uniform4fv(R,i),n.uniform4fv(L,a),n.uniform1i(F,1);const m=n.createTexture();n.activeTexture(n.TEXTURE3),at({gl:n,imageData:null,width:u,height:f,wrap:n.CLAMP_TO_EDGE,filter:n.NEAREST,format:n.RGBA,texture:m});const _=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,_),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,m,0);const x=n.checkFramebufferStatus(n.FRAMEBUFFER);x!==n.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+x);const g=r.map((t=>[t[0],t[1]])).flat(),p=n.createTexture();n.activeTexture(n.TEXTURE2),at({gl:n,texture:p,imageData:new Float32Array(g),width:g.length/2,height:1,wrap:n.CLAMP_TO_EDGE,filter:n.NEAREST,format:n.RG,internalFormat:n.RG32F,type:n.FLOAT}),n.uniform1i(U,2);const E=e.map((t=>{const{dec:e,Hi:r}=j(t);return[-e,r/10]})).flat(),T=n.createTexture();n.activeTexture(n.TEXTURE1),at({gl:n,texture:T,imageData:new Float32Array(E),width:1,height:e.length,wrap:n.CLAMP_TO_EDGE,filter:n.NEAREST,format:n.RG,internalFormat:n.RG32F,type:n.FLOAT}),n.uniform1i(D,1),null!==O&&(n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,O)),n.bindBuffer(n.ARRAY_BUFFER,l),n.enableVertexAttribArray(s),n.vertexAttribPointer(s,2,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,c),n.enableVertexAttribArray(h),n.vertexAttribPointer(h,2,n.FLOAT,!1,0,0),n.viewport(0,0,u,f),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLE_STRIP,0,4);const v=new Uint8Array(u*f*4);return n.readPixels(0,0,u,f,n.RGBA,n.UNSIGNED_BYTE,v),n.deleteTexture(m),n.deleteTexture(T),n.deleteTexture(p),n.deleteFramebuffer(_),n.uniform1i(D,0),n.uniform1i(U,0),n.uniform1i(F,0),n.uniform4fv(R,d),n.uniform4fv(L,[0,0,0,0]),v},generateLocationShadeProfile:t=>{n.useProgram(o);const{startTime:e,endTime:r,tzId:i,texCoord:a,shadeColor:u,sunColor:f}=t,d=n.getUniform(o,R),{outputWidth:m,outputHeight:_}=Y({startTime:e,endTime:r,tzId:i});n.uniform4fv(R,u),n.uniform4fv(L,f),n.uniform1i(P,1),n.uniform2fv(S,[a[0],a[1]]);const x=n.createTexture();n.activeTexture(n.TEXTURE2),at({gl:n,imageData:null,width:m,height:_,wrap:n.CLAMP_TO_EDGE,filter:n.NEAREST,format:n.RGBA,texture:x});const g=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,g),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,x,0);const p=n.checkFramebufferStatus(n.FRAMEBUFFER);p!==n.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+p),null!==O&&(n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,O)),n.bindBuffer(n.ARRAY_BUFFER,l),n.enableVertexAttribArray(s),n.vertexAttribPointer(s,2,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,c),n.enableVertexAttribArray(h),n.vertexAttribPointer(h,2,n.FLOAT,!1,0,0),n.viewport(0,0,m,_),n.clear(n.COLOR_BUFFER_BIT),n.drawArrays(n.TRIANGLE_STRIP,0,4);const E=new Uint8Array(m*_*4);return n.readPixels(0,0,m,_,n.RGBA,n.UNSIGNED_BYTE,E),n.deleteTexture(x),n.deleteFramebuffer(g),n.uniform1i(D,0),n.uniform1i(P,0),n.uniform4fv(R,d),n.uniform4fv(L,[0,0,0,0]),{output:E,outputWidth:m,outputHeight:_}}}}({context:this._gl,setRenderBuffer:t=>{t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.bindFramebuffer(t.FRAMEBUFFER,null)}}),this._buildingRasterizer=new ut(this._gl),this._tileMerger=new lt(this._gl)}addTo(t){return this.onAdd(t)}onAdd(t){if(this._map=t,!this._canvasOverlay&&this._canvas){const t=this._map.getBounds();this._canvasOverlay=function(...t){return new e(...t)}(this._canvas,t),this._canvasOverlay.addTo(this._map)}return this._map.on("moveend",this._reset),this._map.attributionControl.addAttribution('<a href="https://shademap.app/about">&copy; ShadeMap</a>'),this._reset(),this}_repositionCanvas(t){if(this._canvasOverlay&&this._canvasOverlay.setBounds(t),this._map){const{x:t,y:e}=this._map.getSize();this._canvas.width=t,this._canvas.height=e}this._flush()}_flush(){this.emit("idle")}}return void 0!==window.L&&(window.L.shadeMap=(...t)=>new ct(...t)),ct}));
8
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("leaflet")):"function"==typeof define&&define.amd?define(["leaflet"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).ShadeMap=e(t.L)}(this,(function(t){"use strict";class e extends t.ImageOverlay{constructor(t,e,r={}){super("",e,r),this._url=t}_initImage(){const e="CANVAS"===this._url.tagName,r=this._image=e?this._url:t.DomUtil.create("canvas");return t.DomUtil.addClass(r,"leaflet-image-layer"),this._zoomAnimated&&t.DomUtil.addClass(r,"leaflet-zoom-animated"),this.options.className&&t.DomUtil.addClass(r,this.options.className),r.onselectstart=t.Util.falseFn,r.onmousemove=t.Util.falseFn,this}setBounds(t){return this._bounds=t,this._map&&this._reset(),this}}function r(t,e,r,o){return new(r||(r=Promise))((function(i,n){function a(t){try{u(o.next(t))}catch(t){n(t)}}function s(t){try{u(o.throw(t))}catch(t){n(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(a,s)}u((o=o.apply(t,e||[])).next())}))}function o(t,e,r){r=r||2;var o,n,s,u,l,h,d,m=e&&e.length,x=m?e[0]*r:t.length,g=i(t,0,x,r,!0),p=[];if(!g||g.next===g.prev)return p;if(m&&(g=function(t,e,r,o){var n,a,s,u=[];for(n=0,a=e.length;n<a;n++)(s=i(t,e[n]*o,n<a-1?e[n+1]*o:t.length,o,!1))===s.next&&(s.steiner=!0),u.push(_(s));for(u.sort(c),n=0;n<u.length;n++)r=f(u[n],r);return r}(t,e,g,r)),t.length>80*r){o=s=t[0],n=u=t[1];for(var E=r;E<x;E+=r)(l=t[E])<o&&(o=l),(h=t[E+1])<n&&(n=h),l>s&&(s=l),h>u&&(u=h);d=0!==(d=Math.max(s-o,u-n))?32767/d:0}return a(g,p,r,o,n,d,0),p}function i(t,e,r,o,i){var n,a;if(i===F(t,e,r,o)>0)for(n=e;n<r;n+=o)a=R(n,t[n],t[n+1],a);else for(n=r-o;n>=e;n-=o)a=R(n,t[n],t[n+1],a);return a&&E(a,a.next)&&(M(a),a=a.next),a}function n(t,e){if(!t)return t;e||(e=t);var r,o=t;do{if(r=!1,o.steiner||!E(o,o.next)&&0!==p(o.prev,o,o.next))o=o.next;else{if(M(o),(o=e=o.prev)===o.next)break;r=!0}}while(r||o!==e);return e}function a(t,e,r,o,i,c,f){if(t){!f&&c&&function(t,e,r,o){var i=t;do{0===i.z&&(i.z=m(i.x,i.y,e,r,o)),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,o,i,n,a,s,u,l=1;do{for(r=t,t=null,n=null,a=0;r;){for(a++,o=r,s=0,e=0;e<l&&(s++,o=o.nextZ);e++);for(u=l;s>0||u>0&&o;)0!==s&&(0===u||!o||r.z<=o.z)?(i=r,r=r.nextZ,s--):(i=o,o=o.nextZ,u--),n?n.nextZ=i:t=i,i.prevZ=n,n=i;r=o}n.nextZ=null,l*=2}while(a>1)}(i)}(t,o,i,c);for(var d,_,x=t;t.prev!==t.next;)if(d=t.prev,_=t.next,c?u(t,o,i,c):s(t))e.push(d.i/r|0),e.push(t.i/r|0),e.push(_.i/r|0),M(t),t=_.next,x=_.next;else if((t=_)===x){f?1===f?a(t=l(n(t),e,r),e,r,o,i,c,2):2===f&&h(t,e,r,o,i,c):a(n(t),e,r,o,i,c,1);break}}}function s(t){var e=t.prev,r=t,o=t.next;if(p(e,r,o)>=0)return!1;for(var i=e.x,n=r.x,a=o.x,s=e.y,u=r.y,l=o.y,h=i<n?i<a?i:a:n<a?n:a,c=s<u?s<l?s:l:u<l?u:l,f=i>n?i>a?i:a:n>a?n:a,d=s>u?s>l?s:l:u>l?u:l,m=o.next;m!==e;){if(m.x>=h&&m.x<=f&&m.y>=c&&m.y<=d&&x(i,s,n,u,a,l,m.x,m.y)&&p(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function u(t,e,r,o){var i=t.prev,n=t,a=t.next;if(p(i,n,a)>=0)return!1;for(var s=i.x,u=n.x,l=a.x,h=i.y,c=n.y,f=a.y,d=s<u?s<l?s:l:u<l?u:l,_=h<c?h<f?h:f:c<f?c:f,g=s>u?s>l?s:l:u>l?u:l,E=h>c?h>f?h:f:c>f?c:f,v=m(d,_,e,r,o),T=m(g,E,e,r,o),y=t.prevZ,b=t.nextZ;y&&y.z>=v&&b&&b.z<=T;){if(y.x>=d&&y.x<=g&&y.y>=_&&y.y<=E&&y!==i&&y!==a&&x(s,h,u,c,l,f,y.x,y.y)&&p(y.prev,y,y.next)>=0)return!1;if(y=y.prevZ,b.x>=d&&b.x<=g&&b.y>=_&&b.y<=E&&b!==i&&b!==a&&x(s,h,u,c,l,f,b.x,b.y)&&p(b.prev,b,b.next)>=0)return!1;b=b.nextZ}for(;y&&y.z>=v;){if(y.x>=d&&y.x<=g&&y.y>=_&&y.y<=E&&y!==i&&y!==a&&x(s,h,u,c,l,f,y.x,y.y)&&p(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;b&&b.z<=T;){if(b.x>=d&&b.x<=g&&b.y>=_&&b.y<=E&&b!==i&&b!==a&&x(s,h,u,c,l,f,b.x,b.y)&&p(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function l(t,e,r){var o=t;do{var i=o.prev,a=o.next.next;!E(i,a)&&v(i,o,o.next,a)&&b(i,a)&&b(a,i)&&(e.push(i.i/r|0),e.push(o.i/r|0),e.push(a.i/r|0),M(o),M(o.next),o=t=a),o=o.next}while(o!==t);return n(o)}function h(t,e,r,o,i,s){var u=t;do{for(var l=u.next.next;l!==u.prev;){if(u.i!==l.i&&g(u,l)){var h=A(u,l);return u=n(u,u.next),h=n(h,h.next),a(u,e,r,o,i,s,0),void a(h,e,r,o,i,s,0)}l=l.next}u=u.next}while(u!==t)}function c(t,e){return t.x-e.x}function f(t,e){var r=function(t,e){var r,o=e,i=t.x,n=t.y,a=-1/0;do{if(n<=o.y&&n>=o.next.y&&o.next.y!==o.y){var s=o.x+(n-o.y)*(o.next.x-o.x)/(o.next.y-o.y);if(s<=i&&s>a&&(a=s,r=o.x<o.next.x?o:o.next,s===i))return r}o=o.next}while(o!==e);if(!r)return null;var u,l=r,h=r.x,c=r.y,f=1/0;o=r;do{i>=o.x&&o.x>=h&&i!==o.x&&x(n<c?i:a,n,h,c,n<c?a:i,n,o.x,o.y)&&(u=Math.abs(n-o.y)/(i-o.x),b(o,t)&&(u<f||u===f&&(o.x>r.x||o.x===r.x&&d(r,o)))&&(r=o,f=u)),o=o.next}while(o!==l);return r}(t,e);if(!r)return e;var o=A(r,t);return n(o,o.next),n(r,r.next)}function d(t,e){return p(t.prev,t,e.prev)<0&&p(e.next,t,t.next)<0}function m(t,e,r,o,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-o)*i|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function _(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,o,i,n,a,s){return(i-a)*(e-s)>=(t-a)*(n-s)&&(t-a)*(o-s)>=(r-a)*(e-s)&&(r-a)*(n-s)>=(i-a)*(o-s)}function g(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&&v(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(b(t,e)&&b(e,t)&&function(t,e){var r=t,o=!1,i=(t.x+e.x)/2,n=(t.y+e.y)/2;do{r.y>n!=r.next.y>n&&r.next.y!==r.y&&i<(r.next.x-r.x)*(n-r.y)/(r.next.y-r.y)+r.x&&(o=!o),r=r.next}while(r!==t);return o}(t,e)&&(p(t.prev,t,e.prev)||p(t,e.prev,e))||E(t,e)&&p(t.prev,t,t.next)>0&&p(e.prev,e,e.next)>0)}function p(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function E(t,e){return t.x===e.x&&t.y===e.y}function v(t,e,r,o){var i=y(p(t,e,r)),n=y(p(t,e,o)),a=y(p(r,o,t)),s=y(p(r,o,e));return i!==n&&a!==s||(!(0!==i||!T(t,r,e))||(!(0!==n||!T(t,o,e))||(!(0!==a||!T(r,t,o))||!(0!==s||!T(r,e,o)))))}function T(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 y(t){return t>0?1:t<0?-1:0}function b(t,e){return p(t.prev,t,t.next)<0?p(t,e,t.next)>=0&&p(t,t.prev,e)>=0:p(t,e,t.prev)<0||p(t,t.next,e)<0}function A(t,e){var r=new w(t.i,t.x,t.y),o=new w(e.i,e.x,e.y),i=t.next,n=e.prev;return t.next=e,e.prev=t,r.next=i,i.prev=r,o.next=r,r.prev=o,n.next=o,o.prev=n,o}function R(t,e,r,o){var i=new w(t,e,r);return o?(i.next=o.next,i.prev=o,o.next.prev=i,o.next=i):(i.prev=i,i.next=i),i}function M(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function w(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function F(t,e,r,o){for(var i=0,n=e,a=r-o;n<r;n+=o)i+=(t[a]-t[n])*(t[n+1]+t[a+1]),a=n;return i}function U(t,e,r){var o=e[1],i=e[0],n=o-i;return t===o&&r?t:((t-i)%n+n)%n+i}function L(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}o.deviation=function(t,e,r,o){var i=e&&e.length,n=i?e[0]*r:t.length,a=Math.abs(F(t,0,n,r));if(i)for(var s=0,u=e.length;s<u;s++){var l=e[s]*r,h=s<u-1?e[s+1]*r:t.length;a-=Math.abs(F(t,l,h,r))}var c=0;for(s=0;s<o.length;s+=3){var f=o[s]*r,d=o[s+1]*r,m=o[s+2]*r;c+=Math.abs((t[f]-t[m])*(t[d+1]-t[f+1])-(t[f]-t[d])*(t[m+1]-t[f+1]))}return 0===a&&0===c?0:Math.abs((c-a)/a)},o.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},o=0,i=0;i<t.length;i++){for(var n=0;n<t[i].length;n++)for(var a=0;a<e;a++)r.vertices.push(t[i][n][a]);i>0&&(o+=t[i-1].length,r.holes.push(o))}return r};var D=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function P(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var S=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function C(t,e,r){return t instanceof P?t:D(t)?new P(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new P(t.x,t.y):new P(t,e,r)}function B(t,e){if(t)for(var r=e?[t,e]:t,o=0,i=r.length;o<i;o++)this.extend(r[o])}function I(t,e){return!t||t instanceof B?t:new B(t,e)}function N(t,e){if(t)for(var r=e?[t,e]:t,o=0,i=r.length;o<i;o++)this.extend(r[o])}function O(t,e){return t instanceof N?t:new N(t,e)}P.prototype={clone:function(){return new P(this.x,this.y)},add:function(t){return this.clone()._add(C(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(C(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 P(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new P(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=S(this.x),this.y=S(this.y),this},distanceTo:function(t){var e=(t=C(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=C(t)).x===this.x&&t.y===this.y},contains:function(t){return t=C(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+L(this.x)+", "+L(this.y)+")"}},B.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof P||"number"==typeof t[0]||"x"in t)e=r=C(t);else if(e=(t=I(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 C((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return C(this.min.x,this.max.y)},getTopRight:function(){return C(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 P?C(t):I(t))instanceof B?(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=I(t);var e=this.min,r=this.max,o=t.min,i=t.max,n=i.x>=e.x&&o.x<=r.x,a=i.y>=e.y&&o.y<=r.y;return n&&a},overlaps:function(t){t=I(t);var e=this.min,r=this.max,o=t.min,i=t.max,n=i.x>e.x&&o.x<r.x,a=i.y>e.y&&o.y<r.y;return n&&a},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,o=Math.abs(e.x-r.x)*t,i=Math.abs(e.y-r.y)*t;return I(C(e.x-o,e.y-i),C(r.x+o,r.y+i))},equals:function(t){return!!t&&(t=I(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},N.prototype={extend:function(t){var e,r,o=this._southWest,i=this._northEast;if(t instanceof X)e=t,r=t;else{if(!(t instanceof N))return t?this.extend(G(t)||O(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return o||i?(o.lat=Math.min(e.lat,o.lat),o.lng=Math.min(e.lng,o.lng),i.lat=Math.max(r.lat,i.lat),i.lng=Math.max(r.lng,i.lng)):(this._southWest=new X(e.lat,e.lng),this._northEast=new X(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,o=Math.abs(e.lat-r.lat)*t,i=Math.abs(e.lng-r.lng)*t;return new N(new X(e.lat-o,e.lng-i),new X(r.lat+o,r.lng+i))},getCenter:function(){return new X((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 X(this.getNorth(),this.getWest())},getSouthEast:function(){return new X(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 X||"lat"in t?G(t):O(t);var e,r,o=this._southWest,i=this._northEast;return t instanceof N?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=o.lat&&r.lat<=i.lat&&e.lng>=o.lng&&r.lng<=i.lng},intersects:function(t){t=O(t);var e=this._southWest,r=this._northEast,o=t.getSouthWest(),i=t.getNorthEast(),n=i.lat>=e.lat&&o.lat<=r.lat,a=i.lng>=e.lng&&o.lng<=r.lng;return n&&a},overlaps:function(t){t=O(t);var e=this._southWest,r=this._northEast,o=t.getSouthWest(),i=t.getNorthEast(),n=i.lat>e.lat&&o.lat<r.lat,a=i.lng>e.lng&&o.lng<r.lng;return n&&a},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=O(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var z=function(t){var e,r,o,i;for(r=1,o=arguments.length;r<o;r++)for(e in i=arguments[r])t[e]=i[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),o=this.scale(e);return this.transformation._transform(r,o)},pointToLatLng:function(t,e){var r=this.scale(e),o=this.transformation.untransform(t,r);return this.projection.unproject(o)},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 B(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(t){var e=this.wrapLng?U(t.lng,this.wrapLng,!0):t.lng;return new X(this.wrapLat?U(t.lat,this.wrapLat,!0):t.lat,e,t.alt)},wrapLatLngBounds:function(t){var e=t.getCenter(),r=this.wrapLatLng(e),o=e.lat-r.lat,i=e.lng-r.lng;if(0===o&&0===i)return t;var n=t.getSouthWest(),a=t.getNorthEast();return new N(new X(n.lat-o,n.lng-i),new X(a.lat-o,a.lng-i))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,o=t.lat*r,i=e.lat*r,n=Math.sin((e.lat-t.lat)*r/2),a=Math.sin((e.lng-t.lng)*r/2),s=n*n+Math.cos(o)*Math.cos(i)*a*a,u=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s));return this.R*u}});function X(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 G(t,e,r){return t instanceof X?t:D(t)&&"object"!=typeof t[0]?3===t.length?new X(t[0],t[1],t[2]):2===t.length?new X(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new X(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new X(t,e,r)}X.prototype={equals:function(t,e){return!!t&&(t=G(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("+L(this.lat,t)+", "+L(this.lng,t)+")"},distanceTo:function(t){return z.distance(this,G(t))},wrap:function(){return z.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return O([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new X(this.lat,this.lng,this.alt)}};const H=256,W=.40909994067971484,j=t=>{const e=t.valueOf();return Z(e)},Z=t=>{const e=t/864e5-10957.5,r=6.240059966692059+.017201969994578018*e,o=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(o)*Math.cos(W),Math.cos(o));return{dec:Math.asin(Math.sin(W)*Math.sin(o)),Hi:(4.889714432387314+6.3003876824396166*e-i)%(2*Math.PI)+2*Math.PI}},Y=(t,e,r)=>{const o=1/e,i=Math.min(t[0]*o,255),n=Math.min(t[1]*o,255),a=Math.min(t[2]*o,255);let s=0;return i+n+a!==0&&(s=i>0?i/255*.5+.5:a>0?.5*(1-a/255):.5),s*r},K=(t=new Date,e)=>{const r=new Date(t.toLocaleString("en-US",{timeZone:"UTC"})),o=new Date(t.toLocaleString("en-US",e?{timeZone:e}:{}));return r.getTime()-o.getTime()};function k(t){t.filter((t=>"MultiPolygon"===t.geometry.type)).forEach((e=>{const{geometry:r,properties:o,type:i}=e;if("MultiPolygon"===r.type)for(let o=0;o<r.coordinates.length;o++)t.push(Object.assign(Object.assign({},e),{geometry:Object.assign(Object.assign({},r),{type:"Polygon",coordinates:r.coordinates[o]})}))}));return t.filter((t=>"Polygon"===t.geometry.type)).map((t=>{const{geometry:e,properties:r}=t,{vertices:i}=o.flatten(e.coordinates),n=new Float32Array(i.map(((t,e)=>{return e%2==1?(r=t,(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+r*Math.PI/360)))/360):(180+t)/360;var r}))),a=o(n),s=a.length>256?new Uint16Array(a):new Uint8Array(a),u=function(t){const{height:e=0,levels:r=0,render_height:o=0}=t;if(r)return 3.04*r;return Math.max(e,o)}(r),l=r.highlight||!1;let h=0,c=0,f=0;for(let t=0;t<n.length;t+=2)h+=n[t],c+=n[t+1],f++;return{aPosition:n,cuts:s,buildingHeight:u,centroid:[h/f,c/f],highlight:l}}))}const V=(t,e)=>{const{lat:r,lng:o}=t;return new P(((t,e)=>(t+180)/360*Math.pow(2,e)*H)(o,e),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*H)(r,e))},q=(t,e)=>{return new X((r=t.y,o=e,i=Math.PI-2*Math.PI*r/H/Math.pow(2,o),180/Math.PI*Math.atan(.5*(Math.exp(i)-Math.exp(-i)))),function(t,e){return t/H/Math.pow(2,e)*360-180}(t.x,e));var r,o,i};let $,J={heightMapTex:null,width:0,height:0,visibleDEMPixelBounds:new B(new P(0,0),new P(0,0)),DEMPixelBounds:new B(new P(0,0),new P(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const Q=t=>r(void 0,void 0,void 0,(function*(){const{demZoom:e,getFeatures:o,terrainSource:i,dsmSource:n,tileLoaded:a,gl:s,bounds:u,buildingRasterizer:l,tileMerger:h,forceUpdate:c=!1}=t,{getSourceUrl:f,getElevation:d,maxZoom:m,tileSize:_,_overzoom:x}=i,g=(p={getFeatures:o},r(void 0,void 0,void 0,(function*(){const{getFeatures:t}=p;try{return k(yield t())}catch(t){console.log("Error merging buildings",t)}return[]})));var p;try{const t=u,r=t.getNorthWest(),o=t.getSouthEast(),i=new B(V(r,e),V(o,e));let x=new P(i.min.x,i.min.y),p=i.max.x-i.min.x;const E=i.max.y-i.min.y,v=i.max.subtract(i.min);v.y>v.x&&(x.x-=H,p+=512);const T=(t=>{const{upperLeft:e,width:r,height:o}=t,i=e.divideBy(H).floor().multiplyBy(H),n=(Math.ceil(r/H)+1)*H,a=(Math.ceil(o/H)+1)*H,s=i.add([n,a]);return new B(i,s)})({upperLeft:x,width:p,height:E}),{x:y,y:b}=T.max.subtract(T.min),A=(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 o=Math.pow(2,t.z);return{x:(t.x%o+o)%o,y:(t.y%o+o)%o,z:t.z,xOffset:(t.x-e)*H,yOffset:(t.y-r)*H}}))})((t=>{const{upperLeft:e,width:r,height:o,zoom:i}=t,n=e.divideBy(H).floor(),a=n.x+r/H,s=Math.min(n.y+o/H,Math.pow(2,i)-1),u=[];for(var l=n.x;l<a;l++)for(var h=n.y;h<s;h++)u.push({x:l,y:h,z:i});return u})({upperLeft:T.min,width:y,height:b,zoom:e})),R=i.max.x-i.min.x,M=i.max.y-i.min.y,w=Math.round(R),F=Math.round(M),U=JSON.stringify(A);if(!c&&U===$&&e<m)return J=Object.assign(Object.assign({},J),{outputWidth:w,outputHeight:F,visibleDEMPixelBounds:i,demZoom:e,dirty:!0}),J;const L=yield h.merge(A,{maxZoom:m,width:y,height:b,crossOrigin:"Anonymous",getSourceUrl:f,getElevation:d,tileSize:_,tileLoaded:a});if(null===L)return J=Object.assign(Object.assign({},J),{visibleDEMPixelBounds:i,demZoom:e,dirty:!1}),J;const D=new B(V(new N(n.bounds).getNorthWest(),e),V(new N(n.bounds).getSouthEast(),e)),S=D.min.subtract(T.min),C=D.max.subtract(T.min),I=[S.x/y,S.y/b,C.x/y,C.y/b].map((t=>2*t-1)),O=yield g,{maxHeight:z,heightMapTex:X}=l.raster({upperLeftTile:A[0],width:y,height:b,mapZoom:e,features:O,imageData:L,gl:s,dsmSource:n,dsmCoords:I}),G=Math.max(n.maxHeight,L.maxHeight+z);$=U,J={heightMapTex:X,maxHeight:G,width:y,height:b,DEMPixelBounds:T,visibleDEMPixelBounds:i,raster:A,demZoom:e,dirty:!0,outputWidth:w,outputHeight:F}}catch(t){console.error("Could not decode height map",t)}return J})),tt=(t,e)=>{const{r:r,g:o,b:i}=t;return[r/255,o/255,i/255,e]},et=(t,e)=>{const{date:r}=e,{dec:o,Hi:i}=j(r);t.updateDate({dec:o,Hi:i})},rt=(t,e)=>r(void 0,void 0,void 0,(function*(){return yield t.updateDateRange(Object.assign({},e))})),ot=(t,e)=>{const{color:r,opacity:o}=e,i=tt(r,o);t.updateColor({colorVec:i})},it=t=>{const{kernel:e,map:r,heightMap:o,now:i,color:n,opacity:a,belowCanopy:s,skipRender:u}=t;try{const{heightMapTex:t,outputHeight:l,outputWidth:h,maxHeight:c,width:f,height:d,DEMPixelBounds:m,visibleDEMPixelBounds:_,demZoom:x}=o;if(0===f||0===d)return;const{min:g,max:p}=_;if(!g||!p)return;const{x:E,y:v}=p.subtract(g),T=m.min,y=r.getPixelDimensions(),b=r.screenUnproject([0,0]),A=r.screenUnproject([y.width,0]),R=r.screenUnproject([y.width,y.height]),M=r.screenUnproject([0,y.height]),w=[M,R,b,A].map((t=>r.project(t,x))),F=w.map((t=>[(t.x-T.x)/f,(t.y-T.y)/d])).flat(),U=w.map((t=>[(t.x-g.x)/E,(t.y-g.y)/v])).map((t=>[2*t[0]-1,(2*t[1]-1)*(r.isLeaflet()?-1:1)])).flat(),L=T.y/H/Math.pow(2,x),D=d/H/Math.pow(2,x),P=new N(q(m.getTopLeft(),x),q(m.getBottomRight(),x)),S=P.getWest(),C=Math.abs(P.getWest()-P.getEast());((t,e)=>{const{color:r,opacity:o,date:i}=e,n=tt(r,o),{dec:a,Hi:s}=j(i);t.updateHeightMap(Object.assign({dec:a,Hi:s,colorVec:n,step:1},e))})(e,{heightMapTex:t,maxHeight:c,width:f,height:d,heightMapZoom:x,cornerTextureCoords:F,cornerClipCoords:U,topYCoord:L,ySize:D,west:S,dLng:C,date:i,color:n,opacity:a,outputHeight:l,outputWidth:h,belowCanopy:s,skipRender:u})}catch(t){console.error("EXCEPTION",t)}};const nt=t=>{const e=()=>!t.getPitch;return{project:(r,o)=>{if(e())return t.project(r,o);{const{lat:t,lng:e}=r;return new P(((t,e)=>(t+180)/360*Math.pow(2,e)*H)(e,o),((t,e)=>(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*H)(t,o))}},unproject:(r,o)=>{return e()?t.unproject(r,o):new X((i=r.y,n=o,a=Math.PI-2*Math.PI*i/H/Math.pow(2,n),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/H/Math.pow(2,e)*360-180}(r.x,o));var i,n,a},screenUnproject:r=>e()?t.containerPointToLatLng(r):t.unproject(r),getZoom:()=>e()?t.getZoom():t.getZoom()+1,getCenter:()=>t.getCenter(),getBounds:()=>t.getBounds(),eachLayer:r=>{e()&&t.eachLayer(r)},getBearing:()=>e()?0:t.getBearing(),getPitch:()=>e()?0:t.getPitch(),rawMap:()=>t,isLeaflet:e,getPixelDimensions:()=>{const e=t.getContainer();return{width:e.clientWidth,height:e.clientHeight}},createBounds:t=>{const{nw:e,se:r}=t;return new N(e,r)}}};const at=t=>{const{gl:e}=t,{texture:r,imageData:o=null,format:i=e.RGBA,width:n,height:a,filter:s=e.NEAREST,wrap:u=e.CLAMP_TO_EDGE,type:l=e.UNSIGNED_BYTE,internalFormat:h=i}=t;e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,s),e.texImage2D(e.TEXTURE_2D,0,h,n,a,0,i,l,o)};function st(t){const{gl:e,vSrc:r,fSrc:o}=t,i=e.createShader(e.VERTEX_SHADER);e.shaderSource(i,r),e.compileShader(i);const n=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,o),e.compileShader(n);const a=e.createProgram();return e.attachShader(a,i),e.attachShader(a,n),e.linkProgram(a),a}class ut{constructor(t){this.gl=t,this.program=st({gl:t,vSrc:"\nuniform vec3 xyz;\nuniform vec2 dimensions;\nuniform bool use_dsm;\nuniform vec2 u_centroid;\nuniform sampler2D height_map;\nattribute vec2 dsm_position;\nattribute vec2 a_position;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\nvarying vec4 v_elevation;\n\n\tvoid main() {\n\t\tif (use_dsm == true) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = dsm_position;\n v_use_dsm = 1.0;\n\t\t\treturn;\n\t\t}\n\t\tif (abs(a_position) == vec2(1,1)) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = a_position * 0.5 + 0.5;\n\t\t\treturn;\n\t\t}\n\t\tfloat x = a_position.x - xyz.x;\n\t\tfloat y = a_position.y - 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 v_elevation = texture2D(height_map, vec2(u_centroid.x, u_centroid.y));\n\t\tgl_Position = vec4(final, 0, 1);\n\t}\n",fSrc:"\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform vec4 color;\nuniform sampler2D height_map;\nvarying vec2 vCoord;\nvarying float v_use_dsm;\nvarying vec4 v_elevation;\n\nvec4 addElevation(vec4 color, vec4 toAdd) {\n float ground = (color.b * 255.0 * 255.0 + color.a * 255.0);\n float building = (toAdd.r * 255.0 * 255.0 + toAdd.g * 255.0);\n float elevation = ground + building;\n float r = floor(elevation / 255.0) / 255.0;\n float g = floor(mod(elevation, 255.0)) / 255.0;\n return vec4(r, g, r, g);\n}\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n if (v_use_dsm == 1.0) {\n\t \t gl_FragColor = vec4(0.0, 0.0, textureColor.b, textureColor.a);\n if (gl_FragColor.zw == vec2(0.0)) {\n discard;\n }\n } else {\n gl_FragColor = vec4(textureColor.b, textureColor.a, textureColor.b, textureColor.a);\n }\n // DSM noData values should not be included in heightMap because they produce ugly borders\n\t\treturn;\n\t} \n vec4 final = addElevation(v_elevation, color);\n\tgl_FragColor = final;\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.centroidUniformLocation=t.getUniformLocation(this.program,"u_centroid"),this.colorUniformLocation=t.getUniformLocation(this.program,"color"),this.positionBuffer=t.createBuffer(),this.dsmBuffer=t.createBuffer(),this.indexBuffer=t.createBuffer(),this.targetTexture=t.createTexture()}raster(t){const{features:e,upperLeftTile:r,mapZoom:o,width:i,height:n,imageData:a,dsmCoords:s,dsmSource:u,gl:l}=t,{x:h,y:c,z:f}=r;let d=0;l.useProgram(this.program),l.activeTexture(l.TEXTURE1),l.bindTexture(l.TEXTURE_2D,a);const m=i,_=n;l.activeTexture(l.TEXTURE0),l.bindTexture(l.TEXTURE_2D,this.targetTexture),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,m,_,0,l.RGBA,l.UNSIGNED_BYTE,null),o>15&&e.length>5?(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST)):(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.LINEAR)),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.viewport(0,0,m,_);const x=l.createFramebuffer();l.bindFramebuffer(l.FRAMEBUFFER,x);const g=l.COLOR_ATTACHMENT0;l.framebufferTexture2D(l.FRAMEBUFFER,g,l.TEXTURE_2D,this.targetTexture,0),l.disable(l.BLEND),l.bindBuffer(l.ARRAY_BUFFER,this.positionBuffer),l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,this.indexBuffer),l.clearColor(0,0,0,0),l.clear(l.COLOR_BUFFER_BIT);const p=h/Math.pow(2,f),E=c/Math.pow(2,f),v=new P(p,E),T=i/H/Math.pow(2,f),y=n/H/Math.pow(2,f);l.uniform3f(this.xyzUniformLocation,p,E,f),l.uniform2f(this.dimensionsUniformLocation,T,y),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:o,centroid:a,highlight:s}=t,u=new P(a[0],a[1]).subtract(v).unscaleBy(new P(T,y)).scaleBy(new P(i,n)).floor();if(u.x<0||u.y<0||u.x>i||u.y>n)return;const h=u.x/i,c=u.y/n,f=5*e,m=Math.floor(f/255)/255,_=Math.floor(f%255)/255;d=Math.max(d,e),l.uniform2f(this.centroidUniformLocation,h,c),l.uniform4f(this.colorUniformLocation,m,_,m,_),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,o,l.DYNAMIC_DRAW),l.drawElements(l.TRIANGLES,o.length,o.length>256?l.UNSIGNED_SHORT:l.UNSIGNED_BYTE,0)})),0!==u.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,u.width,u.height,0,l.LUMINANCE_ALPHA,l.UNSIGNED_BYTE,u.data),l.pixelStorei(l.UNPACK_ALIGNMENT,4);const e=[s[0],s[3],s[2],s[3],s[0],s[1],s[2],s[1]],r=new Float32Array(e);l.enableVertexAttribArray(this.positionAttributeLocation),l.bufferData(l.ARRAY_BUFFER,r,l.STATIC_DRAW),l.vertexAttribPointer(this.positionAttributeLocation,2,l.FLOAT,!1,0,0),l.enableVertexAttribArray(this.dsmAttributeLocation),l.bindBuffer(l.ARRAY_BUFFER,this.dsmBuffer),l.bufferData(l.ARRAY_BUFFER,new Float32Array([0,1,1,1,0,0,1,0]),l.STATIC_DRAW),l.vertexAttribPointer(this.dsmAttributeLocation,2,l.FLOAT,!1,0,0),l.uniform4f(this.colorUniformLocation,0,0,0,0),l.uniform1i(this.useDSMUniformLocation,1),l.colorMask(!1,!1,!0,!0),l.drawArrays(l.TRIANGLE_STRIP,0,4),l.deleteTexture(t)}return l.colorMask(!0,!0,!0,!0),l.deleteFramebuffer(x),{maxHeight:d,heightMapTex:this.targetTexture}}}const lt=t=>{const{tile:e,maxZoom:r,tileSize:o}=t;let{x:i,y:n,z:a}=e;if(a>r){const t=Math.pow(2,e.z-r);i=Math.floor(i/t),n=Math.floor(n/t),a=r}return{x:o===H?i:Math.floor(i/2),y:o===H?n:Math.floor(n/2),z:o===H?a:a-1}};class ht{constructor(t){this.gl=t,this.program=st({vSrc:"\n attribute vec4 a_tex_position;\n attribute vec4 a_tile_position;\n varying vec2 v_tex_pos;\n void main() {\n v_tex_pos = a_tex_position.xy;\n gl_Position = a_tile_position;\n }\n ",fSrc:"\n precision mediump float;\n uniform sampler2D u_texture;\n uniform float u_encoding;\n uniform float u_tile_size;\n varying vec2 v_tex_pos;\n\n float getElevationTerrarium(vec4 color) {\n float decoded = color.r * 255.0 * 256.0 + color.g * 255.0 + color.b * 255.0 / 256.0 - 32768.0;\n return decoded;\n }\n\n float getElevationMapbox(vec4 color) {\n float decoded = -10000.0 + (color.r * 255.0 * 256.0 * 256.0 + color.g * 255.0 * 256.0 + color.b * 255.0) * .1;\n return decoded;\n }\n\n float getElevationSwitzerland(vec4 color) {\n float decoded = ((color.r * 255.0 * 256.0 + color.g * 255.0) / pow(2.0, 16.0)) * 4808.0;\n return decoded;\n }\n\n float getElevation(vec4 color, float encoding) {\n float decoded;\n if (encoding == 1.0) {\n decoded = getElevationMapbox(color);\n } else if (encoding == 2.0) {\n decoded = getElevationSwitzerland(color);\n } else {\n decoded = getElevationTerrarium(color);\n }\n float scaled = decoded * 5.0;\n float elevation = max(scaled, 0.0);\n return elevation;\n }\n\n float textureSampleLinear(sampler2D sampler, vec2 texCoord) {\n vec2 texelSize = vec2(1.0 / u_tile_size, 1.0 / u_tile_size);\n \n // Calculate interpolation weights based on texCoord fract (fractional part)\n vec2 uv = fract(texCoord * u_tile_size);\n \n // Sample four nearest texels\n vec4 bottomLeft = texture2D(sampler, texCoord);\n vec4 bottomRight = texture2D(sampler, texCoord + vec2(texelSize.x, 0.0));\n vec4 topLeft = texture2D(sampler, texCoord + vec2(0.0, texelSize.y));\n vec4 topRight = texture2D(sampler, texCoord + texelSize);\n\n float bottomLeftEl = getElevation(bottomLeft, u_encoding);\n float bottomRightEl = getElevation(bottomRight, u_encoding);\n float topLeftEl = getElevation(topLeft, u_encoding);\n float topRightEl = getElevation(topRight, u_encoding);\n \n // Interpolate between bottom and top rows\n float bottom = mix(bottomLeftEl, bottomRightEl, uv.x);\n float top = mix(topLeftEl, topRightEl, uv.x);\n \n // Interpolate final color\n return mix(bottom, top, uv.y);\n }\n\n void main() {\n float elevation = textureSampleLinear(u_texture, v_tex_pos);\n float r = floor(elevation / 255.0) / 255.0;\n float g = floor(mod(elevation, 255.0)) / 255.0;\n gl_FragColor = vec4(0, 0, r, g);\n\n // vec4 color = texture2D(u_texture, v_tex_pos);\n // float elevation = getElevation(color, u_encoding);\n // float r = floor(elevation / 255.0) / 255.0;\n // float g = floor(mod(elevation, 255.0)) / 255.0;\n // gl_FragColor = vec4(0, 0, r, g);\n // gl_FragColor = color;\n }\n ",gl:t}),t.useProgram(this.program),this.texPositionAttributeLocation=t.getAttribLocation(this.program,"a_tex_position"),this.tilePositionAttributeLocation=t.getAttribLocation(this.program,"a_tile_position"),this.encodingUniformLocation=t.getUniformLocation(this.program,"u_encoding"),this.tileSizeUniformLocation=t.getUniformLocation(this.program,"u_tile_size"),this.texPositionBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.texPositionBuffer),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(this.texPositionAttributeLocation),t.vertexAttribPointer(this.texPositionAttributeLocation,2,t.FLOAT,!1,0,0),this.tilePositionBuffer=t.createBuffer(),this.tileTexture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.tileTexture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),this.outputTexture=t.createTexture(),this.framebuffer=t.createFramebuffer(),this.inProgress=[],this.finished=0}merge(t,e){return r(this,void 0,void 0,(function*(){const o=this.gl;let i=0;const{width:n,height:a,crossOrigin:s,getSourceUrl:u,getElevation:l,tileSize:h,tileLoaded:c,maxZoom:f}=e;if(o){this.inProgress.forEach((t=>t.src="")),this.inProgress=[],this.finished=0;const e=new Set;t.forEach((t=>{e.add(u(lt({tile:t,maxZoom:f,tileSize:h})))})),o.useProgram(this.program);let d=0;-32768===l({r:0,g:0,b:0,a:0})&&(d=0),-1e4===l({r:0,g:0,b:0,a:0})&&(d=1),4808===l({r:256,g:0,b:0,a:0})&&(d=2),o.uniform1f(this.encodingUniformLocation,d),at({gl:o,texture:this.outputTexture,imageData:null,format:o.RGBA,width:n,height:a,wrap:o.CLAMP_TO_EDGE,filter:o.NEAREST}),o.bindFramebuffer(o.FRAMEBUFFER,this.framebuffer),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,this.outputTexture,0);const m=o.checkFramebufferStatus(o.FRAMEBUFFER);m!==o.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+m),o.clear(o.COLOR_BUFFER_BIT);const _=Array.from(e).map((e=>r(this,void 0,void 0,(function*(){return new Promise(((r,l)=>{const c=new Image;this.inProgress.push(c),c.onload=()=>{o.useProgram(this.program),o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,this.tileTexture),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,c),o.bindFramebuffer(o.FRAMEBUFFER,this.framebuffer);const s=t.filter((t=>e===u(lt({tile:t,maxZoom:f,tileSize:h})))),l=s.reduce(((t,e)=>Math.min(t,e.xOffset)),1/0),d=s.reduce(((t,e)=>Math.min(t,e.yOffset)),1/0),m=s.reduce(((t,e)=>Math.max(t,e.xOffset)),0),_=s.reduce(((t,e)=>Math.max(t,e.yOffset)),0),x=s.reduce(((t,e)=>Math.min(t,e.x)),1/0),g=s.reduce(((t,e)=>Math.min(t,e.y)),1/0),p=s.reduce(((t,e)=>Math.max(t,e.x)),0),E=s.reduce(((t,e)=>Math.max(t,e.y)),0),v=s[0].z,T=l/n,y=d/a,b=(m+H)/n,A=(_+H)/a,R=[T,y,b,y,T,A,b,A].map((t=>2*t-1));o.bindBuffer(o.ARRAY_BUFFER,this.tilePositionBuffer),o.bufferData(o.ARRAY_BUFFER,new Float32Array(R),o.STATIC_DRAW),o.enableVertexAttribArray(this.tilePositionAttributeLocation),o.vertexAttribPointer(this.tilePositionAttributeLocation,2,o.FLOAT,!1,0,0);let M=[0,0,1,0,0,1,1,1];const w=Math.pow(2,Math.max(0,v-f)+(h!==H?1:0)),F=514===h?1/h:0,U=1/w,L=x%w/w,D=g%w/w,P=p%w/w,S=E%w/w;M=[L,D,P+U,D,L,S+U,P+U,S+U].map((t=>t*(514===h?512/514:1)+F)),o.bindBuffer(o.ARRAY_BUFFER,this.texPositionBuffer),o.bufferData(o.ARRAY_BUFFER,new Float32Array(M),o.STATIC_DRAW),o.enableVertexAttribArray(this.texPositionAttributeLocation),o.vertexAttribPointer(this.texPositionAttributeLocation,2,o.FLOAT,!1,0,0),o.uniform1f(this.tileSizeUniformLocation,h),o.viewport(0,0,n,a),o.disable(o.BLEND),o.drawArrays(o.TRIANGLE_STRIP,0,4);const C=Math.floor(T*n),B=Math.floor(y*a),I=Math.ceil((b-T)*n),N=Math.ceil((A-y)*a),O=new Uint8Array(4*I*N);o.readPixels(C,B,I,N,o.RGBA,o.UNSIGNED_BYTE,O);for(let t=0;t<O.length;t+=4){const e=(256*O[t+2]+O[t+3])/5;i=Math.max(e,i)}r(null)},c.onerror=t=>{if(c.src!==c.originalSource)return l("new tiles requested");r(null)},c.crossOrigin=s||null,c.src=e,c.originalSource=c.src})).then((()=>{this.finished++,c(this.finished,this.inProgress.length)}))}))));try{yield Promise.all(_)}catch(t){return console.log(`${_.length} requests aborted`,t),null}return this.inProgress=[],this.outputTexture.maxHeight=i,this.outputTexture}throw new Error("Could not get canvas context for merging tile images")}))}}class ct 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:o}=t;return 256*e+r+o/256-32768}},dsmSource:{bounds:[{lat:0,lng:0},{lat:0,lng:0}],data:new Uint8ClampedArray,width:0,height:0,maxHeight:0},belowCanopy:!1,getFeatures:()=>Promise.resolve([]),getSize:()=>({width:Number.NaN,height:Number.NaN}),debug:t=>{}};const e=t[0];if(this.options=Object.assign(this.options,e),!this.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:this.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((t=>r(this,void 0,void 0,(function*(){if(200!==t.status)throw new Error(yield t.text())})))).catch((t=>r(this,void 0,void 0,(function*(){throw new Error(`Could not load ShadeMap API. Key: ${this.options.apiKey} Error: ${t}`)})))),this._canvas=document.createElement("canvas"),this._color=this._parseColor(this.options.color),this._reset=this._reset.bind(this),this._draw=this._draw.bind(this)}onRemove(){return this._map&&this._map.off("moveend",this._reset),this}setDate(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(et(this._compiledKernel,{date:this.options.date}),this._heightMap&&this._flush())):this.emit("idle"),this}_setDateForTimezone(t,e){let r=0;e&&(r=K(this.options.date)-K(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&&(ot(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&&(ot(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this}setBelowCanopy(t){return this.options.belowCanopy=t,this._heightMap?this._draw(this._heightMap):this._reset(),this}setTerrainSource(t){return this.options.terrainSource=t,delete this._heightMap,this._reset(),this}setDSMSource(t){return this.options.dsmSource=t,delete this._heightMap,this._reset(),this}setSunExposure(t=!1,e){return r(this,void 0,void 0,(function*(){if(this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:t}),e){const{startDate:r=new Date,endDate:o=new Date,iterations:i=32}=e;this.options.sunExposure={enabled:t,startDate:r,endDate:o,iterations:i}}if(this._map&&this._compiledKernel&&this._heightMap){if(!1===t)et(this._compiledKernel,{date:this.options.date});else{const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!(t instanceof Date&&e instanceof Date))throw new Error("Start date or end date or both are missing");if(e.getTime()<t.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield rt(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._flush()}return this}))}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:o,height:i}=this._heightMap,n=e.min;return t.map((t=>{const e=V(t,r);return[(e.x-n.x)/o,(e.y-n.y)/i]}))}return[]}_getBounds(t,e){const{width:r,height:o}=this.options.getSize();if(Number.isNaN(r)||Number.isNaN(o))return t.getBounds();const i=t.getCenter(),n=V(i,e),a=q(new P(n.x-r/2,n.y-o/2),e),s=q(new P(n.x+r/2,n.y+o/2),e);return t.createBounds({nw:a,se:s})}_getDEMZoom(t){const e=Math.min(this.options.terrainSource._overzoom||this.options.terrainSource.maxZoom,t.getZoom());return Math.round(e)}_reset(){return r(this,void 0,void 0,(function*(){if(this.options.debug("_reset()"),this._map){const t=nt(this._map);let e=this._getDEMZoom(t);try{this._bounds=this._getBounds(t,e)}catch(t){return console.error("Invalid bounds returned: ",t),this}try{if(!t.isLeaflet()&&this._map.getPitch()>45){yield new Promise((t=>{this._map.loaded()?t(!0):this._map.once("idle",(function(){t(!0)}))}));const r=this._map.style._sourceCaches["other:composite"].getVisibleCoordinates().reverse(),o=r.reduce(((t,e)=>Math.max(t,e.canonical.z)),Number.MIN_SAFE_INTEGER),i=r.filter((t=>t.canonical.z===o)).map((t=>t.canonical)),[n,a,s,u]=i.reduce(((t,e)=>[Math.min(t[0],e.x),Math.min(t[1],e.y),Math.max(t[2],e.x),Math.max(t[3],e.y)]),[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER]),l=q(new P(512*n,512*a),o+1),h=q(new P(512*(s+1),512*(u+1)),o+1);e=o+1,this._bounds=t.createBounds({nw:l,se:h})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield Q({gl:this._gl,demZoom:e,bounds:this._bounds,terrainSource:this.options.terrainSource,dsmSource:this.options.dsmSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,tileLoaded:(t,e)=>this.emit("tileloaded",t,e),forceUpdate:!this._heightMap});this._heightMap=r,r.dirty&&(yield this._draw(r))}return this}))}_draw(t){return r(this,void 0,void 0,(function*(){if(this.options.debug("_draw()"),this._canvas&&this._compiledKernel&&this._map){if(it({kernel:this._compiledKernel,map:nt(this._map),heightMap:t,color:this._color,belowCanopy:this.options.belowCanopy,opacity:this.options.opacity,now:this.options.date,maxZoom:this.options.terrainSource.maxZoom,skipRender:this.options.sunExposure.enabled}),this.options.sunExposure.enabled){const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!0===(yield rt(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._bounds&&this._repositionCanvas(this._bounds)}return this}))}readPixel(t,e){const r=new Uint8Array(4);return this._gl&&this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r),r}readPixels(t,e,r,o){const i=new Uint8Array(r*o*4);return this._gl&&this._gl.readPixels(t,e,r,o,this._gl.RGBA,this._gl.UNSIGNED_BYTE,i),i}toGeoTiff(){const t=(t,e)=>{const r=this.readPixels(0,0,t,e),o=t*e*1,i=1*t,n=(e-1)*i,a=new Uint8Array(o),s=new Uint8Array(o);let u=0;const{startDate:l,endDate:h}=this.options.sunExposure;this.options.sunExposure.enabled&&l&&h&&(u=h.getTime()-l.getTime());for(let t=0;t<r.length;t+=4){let e;if(this.options.sunExposure.enabled){const o=r.subarray(t,t+3),i=Y(o,.5,u)/1e3/60,n=Math.min(Math.floor(i/6),255);e=new Uint8Array([n])}else{e=r[t]+r[t+1]+r[t+2]===0?new Uint8Array([255]):new Uint8Array([0])}a.set(e,t/4*1)}if(this._map&&!nt(this._map).isLeaflet())return a;for(let t=0;t<o;t+=i)s.set(a.subarray(t,t+i),n-t);return s};if(this._map&&this._heightMap){const e=this._heightMap.outputWidth,r=this._heightMap.outputHeight,o=t(e,r),i=nt(this._map),{lat:n,lng:a}=i.getBounds().getNorthWest(),s=i.getBounds().getSouthEast(),u=[0,0,0,a,n,0],l=[(s.lng-a)/e,(n-s.lat)/r,0];return this.options.sunExposure.enabled,{data:o,metadata:{width:e,height:r,ModelTiepoint:u,ModelPixelScale:l,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}return null}_generateShadeProfile(t){if(this._compiledKernel){const e=this._lngLatToTextureCoords(t.locations);return((t,e)=>{const r=tt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),o=tt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:o}))})(this._compiledKernel,Object.assign(Object.assign({},t),{texCoords:e}))}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=K(t.startDate)-K(t.startDate,t.tzId),r=t.startDate.getTime()-e,o=t.endDate.getTime()-e,i=this._lngLatToTextureCoords([t.location])[0],{output:n,outputWidth:a,outputHeight:s}=((t,e)=>{const r=tt({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),o=tt({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateLocationShadeProfile(Object.assign(Object.assign({},e),{sunColor:r,shadeColor:o}))})(this._compiledKernel,Object.assign(Object.assign({},t),{startTime:r,endTime:o,texCoord:i}));return n.toArray=function(){const e=new Array;for(let r=0;r<a;r++){const o=[];for(let e=s-1;e>=0;e--){const i=e*a*4+4*r,n=this.slice(i,i+4);o.push(n.join("")===t.sunColor.join("")?1:0)}e.push(o)}return e},{data:n,width:a,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:o,endDate:i}=this.options.sunExposure,n=i.getTime()-o.getTime(),a=Y(r,.5,n);return Math.abs(a/1e3/3600)}return 0}_repositionCanvas(t){}_flush(){}flushSync(){this._gl&&this._gl.finish()}_parseColor(t){t=t.replace("#","");const e={r:0,g:0,b:0};return/^([0-9A-F]{3}){1,2}$/i.test(t)&&(3===t.length?(e.r=parseInt(t[0]+t[0],16),e.g=parseInt(t[1]+t[1],16),e.b=parseInt(t[2]+t[2],16)):6===t.length&&(e.r=parseInt(t[0]+t[1],16),e.g=parseInt(t[2]+t[3],16),e.b=parseInt(t[4]+t[5],16))),e}}{constructor(t){super(t);const e={preserveDrawingBuffer:!0,antialias:!1};this._gl=this._canvas.getContext("webgl",e)||this._canvas.getContext("experimental-webgl",e),this._canvas.width=window.innerWidth,this._canvas.height=window.innerHeight,this._compiledKernel=function(t){const{context:e,setRenderBuffer:o}=t,i=e,n=st({gl:i,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 a_pos;attribute vec2 a_tex_pos;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;void main(void){gl_Position=vec4(a_pos,0,1);vTexCoordFull=(gl_Position*0.5+0.5).xy;vTexCoordCropped=a_tex_pos;}",fSrc:"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nprecision lowp int;precision lowp sampler2D;float atan2(float v1,float v2){if(v1==0.0||v2==0.0)return 0.0;return atan(v1,v2);}float _pow(float v1,float v2){if(v2==0.0)return 1.0;return pow(v1,v2);}float integerMod(float x,float y){float res=floor(mod(x,y));return res*(res>floor(y)-1.0 ? 0.0 : 1.0);}float divWithIntCheck(float x,float y){if(floor(x)==x&&floor(y)==y&&integerMod(x,y)==0.0){return float(int(x)/int(y));}return x/y;}float integerCorrectionModulo(float number,float divisor){if(number<0.0){number=abs(number);if(divisor<0.0){divisor=abs(divisor);}return-(number-(divisor*floor(divWithIntCheck(number,divisor))));}if(divisor<0.0){divisor=abs(divisor);}return number-(divisor*floor(divWithIntCheck(number,divisor)));}float getDEMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*255.0*256.0+result.g*255.0)/5000.0;}float getDSMElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.b*255.0*256.0+result.a*255.0)/5000.0;}vec4 actualColor;void color(float r,float g,float b,float a){actualColor=vec4(r,g,b,a);}void color(float r,float g,float b){color(r,g,b,1.0);}void color(float r){color(r,r,r,1.0);}void color(vec4 color){actualColor=color;}const int LOOP_MAX=1000;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;uniform sampler2D user_a;uniform float user_width;uniform float user_height;uniform float user_maxHeight;uniform float user_zoom;uniform float user_topYCoord;uniform float user_ySize;uniform vec4 user_color;uniform vec4 u_sunColor;uniform float user_step;uniform float user_west;uniform float user_dLng;uniform float user_dec;uniform float user_Hi;uniform bool u_below_canopy;uniform sampler2D user_sunExposureTexture;uniform bool user_outputSunExposure;uniform bool u_outputShadeProfile;uniform sampler2D u_decHiTexture;uniform sampler2D u_gpxTexture;uniform bool u_outputLocationShadeProfile;uniform vec2 u_shadeProfileLocation;float kernelResult;void kernel(){float sunDec=user_dec;float sunHi=user_Hi;vec4 shade_color=user_color;float maxHeight=user_maxHeight/1000.0;float user_x=vTexCoordCropped.x;float user_y=vTexCoordCropped.y;if(u_outputShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;vec4 gpx=texture2D(u_gpxTexture,vec2(vTexCoordFull.x,.5));user_x=gpx.x;user_y=gpx.y;}if(u_outputLocationShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;user_x=u_shadeProfileLocation.x;user_y=u_shadeProfileLocation.y;}float user_lit=1.0;float dsm_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(u_below_canopy==true){float dem_height=getDEMElevationFromSampler2D(user_a,user_x,user_y);if(dsm_height-dem_height>.002){user_lit=0.0;}}float user_z=dsm_height;float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=user_west+(user_dLng*user_x);float user_H=integerCorrectionModulo((sunHi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(sunDec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(sunDec))+((cos(user_lat)*cos(sunDec))*cos(user_H))));float user_zoom_factor=_pow(2.0,user_zoom);float user_kmPerPixel=divWithIntCheck(156.5430339296875,user_zoom_factor)*abs(cos(user_lat));float user_dx=((-sin(sun_azimuth)*cos(sun_altitude))*user_step)/user_width;float user_dy=((cos(sun_azimuth)*cos(sun_altitude))*user_step)/user_height;float user_dz=((sin(sun_altitude)*user_kmPerPixel)*user_step);float shadow_bias=0.0005;float user_curvature=0.0;float cur_height=0.0;float user_distance=0.0;float user_startX=user_x;float user_startY=user_y;user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;if((abs(1.0)<0.0)){kernelResult=0.0;return;}float minAngle=asin((earthRadiusInKm/(earthRadiusInKm+user_z)))-(user_PI/2.0);if(user_z<0.0||sun_altitude<minAngle){user_lit=0.0;}else{float xIter=ceil(user_dx<0.0 ? abs(user_x/user_dx):(1.0-user_x)/user_dx);float yIter=ceil(user_dy<0.0 ? abs(user_y/user_dy):(1.0-user_y)/user_dy);float zIter=ceil(user_dz<0.0 ? float(LOOP_MAX):(maxHeight-user_z)/user_dz);int iter=int(min(xIter,min(yIter,zIter)));float user_distance=(sqrt(pow(user_dx*user_width,2.0)+pow(user_dy*user_height,2.0))*user_kmPerPixel)/earthRadiusInKm;for(int safeI=0;safeI<LOOP_MAX;safeI++){if(safeI>iter){break;}cur_height=getDSMElevationFromSampler2D(user_a,user_x,user_y);if(cur_height-user_z>shadow_bias){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;vec4 result=texture2D(user_a,vec2(user_x,user_y));iter=0;break;}}user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;}}if((user_lit==1.0)){if(u_outputLocationShadeProfile==true&&u_sunColor==shade_color){float timeInSun=pow(.7,pow(sin(sun_altitude),.678))*sin(sun_altitude)*(1.0/0.7);float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,1.0);}else{color(u_sunColor);}}else{color(shade_color);}if(user_outputSunExposure){vec4 aggregateColor=texture2D(user_sunExposureTexture,vec2(vTexCoordFull.x,vTexCoordFull.y));float timeInSun=1.0-aggregateColor.r;float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,0.5);}}void main(void){kernel();gl_FragColor=actualColor;}"});i.useProgram(n);const a=i.createBuffer(),s=i.getAttribLocation(n,"a_pos"),u=i.createBuffer(),l=i.getAttribLocation(n,"a_tex_pos"),h=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,h),i.bufferData(i.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),i.STATIC_DRAW);const c=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,c),i.bufferData(i.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),i.STATIC_DRAW);const f=i.getUniformLocation(n,"user_a");i.uniform1i(f,0);const d=i.getUniformLocation(n,"user_width"),m=i.getUniformLocation(n,"user_height"),_=i.getUniformLocation(n,"user_maxHeight"),x=i.getUniformLocation(n,"user_zoom"),g=i.getUniformLocation(n,"user_topYCoord"),p=i.getUniformLocation(n,"user_ySize"),E=i.getUniformLocation(n,"user_step"),v=i.getUniformLocation(n,"user_west"),T=i.getUniformLocation(n,"user_dLng"),y=i.getUniformLocation(n,"user_dec"),b=i.getUniformLocation(n,"user_Hi"),A=i.getUniformLocation(n,"user_color"),R=i.getUniformLocation(n,"u_below_canopy"),M=i.getUniformLocation(n,"user_sunExposureTexture"),w=i.getUniformLocation(n,"user_outputSunExposure"),F=i.getUniformLocation(n,"u_outputShadeProfile"),U=i.getUniformLocation(n,"u_gpxTexture"),L=i.getUniformLocation(n,"u_decHiTexture"),D=i.getUniformLocation(n,"u_sunColor"),P=i.getUniformLocation(n,"u_outputLocationShadeProfile"),S=i.getUniformLocation(n,"u_shadeProfileLocation"),C=i.createTexture();let B=0,I=0,N=0,O=null;const z=()=>{I&&N&&(i.useProgram(n),i.bindBuffer(i.ARRAY_BUFFER,a),i.enableVertexAttribArray(s),i.vertexAttribPointer(s,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,u),i.enableVertexAttribArray(l),i.vertexAttribPointer(l,2,i.FLOAT,!1,0,0),null!==O&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,O)),o(i,I,N),i.viewport(0,0,I,N),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4))};let X=0,G=0,H=0,W="";const Y=t=>{const e=(t.endTime-t.startTime)/86400/1e3,r=1440;if(i.activeTexture(i.TEXTURE3),i.uniform1i(L,3),t.startTime!==G||t.endTime!==H||t.tzId!==W){G=t.startTime,H=t.endTime,W=t.tzId;const o=[],n=828e5,a=K(new Date(G),W);for(let t=0;t<e;t++){const e=K(new Date(G+86400*t*1e3+n),W)-a;o[t]=e}const s=new Float32Array(r*e*2);for(let t=0;t<r;t++)for(let r=0;r<e;r++){const i=G+86400*r*1e3+60*t*1e3,{dec:n,Hi:a}=Z(i+o[r]);s[2*(t*e+r)]=-n,s[2*(t*e+r)+1]=a/10}at({gl:i,texture:C,imageData:s,width:e,height:r,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RG,internalFormat:i.RG32F,type:i.FLOAT})}else i.bindTexture(i.TEXTURE_2D,C);return{outputWidth:e,outputHeight:r}};return{updateHeightMap:function(t){const{heightMapTex:e,width:r,height:o,maxHeight:s,heightMapZoom:l,topYCoord:h,ySize:c,colorVec:f,step:M,west:w,dLng:F,dec:U,Hi:L,cornerClipCoords:D,cornerTextureCoords:P,outputWidth:S,outputHeight:C,belowCanopy:X,skipRender:G}=t;i.useProgram(n),I=S,N=C,O=e,i.bindBuffer(i.ARRAY_BUFFER,a),i.bufferData(i.ARRAY_BUFFER,new Float32Array(D),i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,u),i.bufferData(i.ARRAY_BUFFER,new Float32Array(P),i.STATIC_DRAW),i.uniform1f(d,r),i.uniform1f(m,o),i.uniform1f(_,s),i.uniform1f(x,l),i.uniform1f(g,h),i.uniform1f(p,c),i.uniform4fv(A,f),i.uniform1f(E,M),i.uniform1f(v,w),i.uniform1f(T,F),i.uniform1f(y,U),i.uniform1f(b,L),i.uniform1f(R,X?1:0),G||(window.cancelAnimationFrame(B),B=window.requestAnimationFrame(z))},updateDate:t=>{const{dec:e,Hi:r}=t;i.useProgram(n),i.uniform1f(y,e),i.uniform1f(b,r),window.cancelAnimationFrame(B),B=window.requestAnimationFrame(z)},updateDateRange:t=>r(this,void 0,void 0,(function*(){const{startDate:e,endDate:r,iterations:o,emit:h}=t;i.useProgram(n);const c=X=Date.now(),f=Math.floor((r.getTime()-e.getTime())/o),d=i.getUniform(n,A),m=I,_=N,x=i.createTexture();i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,x),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,m,_,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);const g=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,g);const p=i.COLOR_ATTACHMENT0;i.framebufferTexture2D(i.FRAMEBUFFER,p,i.TEXTURE_2D,x,0);for(let t=0;t<o;t++){if(i.useProgram(n),h("tileloaded",t,o-1),c!==X)return i.deleteFramebuffer(g),i.deleteTexture(x),i.uniform4fv(A,d),!0;yield new Promise(((r,h)=>{window.requestAnimationFrame((()=>{i.useProgram(n),null!==O&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,O)),i.bindFramebuffer(i.FRAMEBUFFER,g);const h=i.checkFramebufferStatus(i.FRAMEBUFFER);h!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+h);const{dec:c,Hi:d}=j(new Date(e.getTime()+f*t));i.uniform1f(y,c),i.uniform1f(b,d),i.uniform4fv(A,[1/o,0,0,1]),i.bindBuffer(i.ARRAY_BUFFER,a),i.enableVertexAttribArray(s),i.vertexAttribPointer(s,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,u),i.enableVertexAttribArray(l),i.vertexAttribPointer(l,2,i.FLOAT,!1,0,0),i.viewport(0,0,m,_),i.enable(i.BLEND),i.blendFunc(i.ONE,i.ONE),i.drawArrays(i.TRIANGLE_STRIP,0,4),r()}))}))}return i.deleteFramebuffer(g),yield new Promise(((t,e)=>{window.requestAnimationFrame((()=>{if(i.useProgram(n),c!==X)return i.deleteTexture(x),i.uniform4fv(A,d),void t(!0);i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,x),i.uniform1i(M,2),i.uniform1i(w,1),z(),i.uniform1i(w,0),i.uniform1i(M,0),i.deleteTexture(x),i.uniform4fv(A,d),t(!1)}))}))})),updateColor:t=>{const{colorVec:e}=t;i.useProgram(n),i.uniform4fv(A,e),window.cancelAnimationFrame(B),B=window.requestAnimationFrame(z)},generateShadeProfile:t=>{i.useProgram(n);const{dates:e,texCoords:r,shadeColor:o,sunColor:a}=t,u=r.length,f=e.length,d=i.getUniform(n,A);i.uniform4fv(A,o),i.uniform4fv(D,a),i.uniform1i(F,1);const m=i.createTexture();i.activeTexture(i.TEXTURE3),at({gl:i,imageData:null,width:u,height:f,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,texture:m});const _=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,_),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,m,0);const x=i.checkFramebufferStatus(i.FRAMEBUFFER);x!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+x);const g=r.map((t=>[t[0],t[1]])).flat(),p=i.createTexture();i.activeTexture(i.TEXTURE2),at({gl:i,texture:p,imageData:new Float32Array(g),width:g.length/2,height:1,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RG,internalFormat:i.RG32F,type:i.FLOAT}),i.uniform1i(U,2);const E=e.map((t=>{const{dec:e,Hi:r}=j(t);return[-e,r/10]})).flat(),v=i.createTexture();i.activeTexture(i.TEXTURE1),at({gl:i,texture:v,imageData:new Float32Array(E),width:1,height:e.length,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RG,internalFormat:i.RG32F,type:i.FLOAT}),i.uniform1i(L,1),null!==O&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,O)),i.bindBuffer(i.ARRAY_BUFFER,h),i.enableVertexAttribArray(s),i.vertexAttribPointer(s,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,c),i.enableVertexAttribArray(l),i.vertexAttribPointer(l,2,i.FLOAT,!1,0,0),i.viewport(0,0,u,f),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4);const T=new Uint8Array(u*f*4);return i.readPixels(0,0,u,f,i.RGBA,i.UNSIGNED_BYTE,T),i.deleteTexture(m),i.deleteTexture(v),i.deleteTexture(p),i.deleteFramebuffer(_),i.uniform1i(L,0),i.uniform1i(U,0),i.uniform1i(F,0),i.uniform4fv(A,d),i.uniform4fv(D,[0,0,0,0]),T},generateLocationShadeProfile:t=>{i.useProgram(n);const{startTime:e,endTime:r,tzId:o,texCoord:a,shadeColor:u,sunColor:f}=t,d=i.getUniform(n,A),{outputWidth:m,outputHeight:_}=Y({startTime:e,endTime:r,tzId:o});i.uniform4fv(A,u),i.uniform4fv(D,f),i.uniform1i(P,1),i.uniform2fv(S,[a[0],a[1]]);const x=i.createTexture();i.activeTexture(i.TEXTURE2),at({gl:i,imageData:null,width:m,height:_,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,texture:x});const g=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,g),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,x,0);const p=i.checkFramebufferStatus(i.FRAMEBUFFER);p!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+p),null!==O&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,O)),i.bindBuffer(i.ARRAY_BUFFER,h),i.enableVertexAttribArray(s),i.vertexAttribPointer(s,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,c),i.enableVertexAttribArray(l),i.vertexAttribPointer(l,2,i.FLOAT,!1,0,0),i.viewport(0,0,m,_),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4);const E=new Uint8Array(m*_*4);return i.readPixels(0,0,m,_,i.RGBA,i.UNSIGNED_BYTE,E),i.deleteTexture(x),i.deleteFramebuffer(g),i.uniform1i(L,0),i.uniform1i(P,0),i.uniform4fv(A,d),i.uniform4fv(D,[0,0,0,0]),{output:E,outputWidth:m,outputHeight:_}}}}({context:this._gl,setRenderBuffer:t=>{t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.bindFramebuffer(t.FRAMEBUFFER,null)}}),this._buildingRasterizer=new ut(this._gl),this._tileMerger=new ht(this._gl)}addTo(t){return this.onAdd(t)}onAdd(t){if(this._map=t,!this._canvasOverlay&&this._canvas){const t=this._map.getBounds();this._canvasOverlay=function(...t){return new e(...t)}(this._canvas,t),this._canvasOverlay.addTo(this._map)}return this._map.on("moveend",this._reset),this._map.attributionControl.addAttribution('<a href="https://shademap.app/about">&copy; ShadeMap</a>'),this._reset(),this}_repositionCanvas(t){if(this._canvasOverlay&&this._canvasOverlay.setBounds(t),this._map){const{x:t,y:e}=this._map.getSize();this._canvas.width=t,this._canvas.height=e}this._flush()}_flush(){this.emit("idle")}}return void 0!==window.L&&(window.L.shadeMap=(...t)=>new ct(...t)),ct}));
@@ -11,13 +11,13 @@ import { Color } from "./types/color";
11
11
  import { DSMSource, SunExposureOptions, TerrainSource } from "./types/shadeMapOptions";
12
12
  export declare class ShadeMap extends EventEmitter {
13
13
  _canvas: HTMLCanvasElement;
14
- _gl: WebGLRenderingContext;
14
+ _gl?: WebGLRenderingContext;
15
15
  _map?: Map | LeafletMap;
16
16
  _compiledKernel?: CompiledKernel;
17
17
  _color: Color;
18
18
  _bounds?: LatLngBounds;
19
- _buildingRasterizer: BuildingRasterizer;
20
- _tileMerger: TileMerger;
19
+ _buildingRasterizer?: BuildingRasterizer;
20
+ _tileMerger?: TileMerger;
21
21
  _heightMap?: HeightMap;
22
22
  options: {
23
23
  date: Date;
@@ -56,12 +56,6 @@ export declare class ShadeMap extends EventEmitter {
56
56
  height: number;
57
57
  maxHeight: number;
58
58
  };
59
- cowHeight: number;
60
- geometry: {
61
- enabled: boolean;
62
- type: string;
63
- coordinates: number[][][];
64
- };
65
59
  belowCanopy: boolean;
66
60
  getFeatures: () => Promise<MapboxGeoJSONFeature[]>;
67
61
  getSize: () => {
@@ -72,14 +66,9 @@ export declare class ShadeMap extends EventEmitter {
72
66
  };
73
67
  constructor(...args: any[]);
74
68
  onRemove(): this;
75
- setGeometry(enabled: boolean, geometry?: {
76
- type: string;
77
- coordinates: number[][][];
78
- }): void;
79
69
  setDate(date: Date): this;
80
70
  _setDateForTimezone(date: Date, tzId?: string): void;
81
71
  setColor(color: string): this;
82
- setCowHeight(height: number): this;
83
72
  setOpacity(opacity: number): this;
84
73
  setBelowCanopy(belowCanopy: boolean): this;
85
74
  setTerrainSource(terrainSource: TerrainSource): this;
@@ -91,6 +80,7 @@ export declare class ShadeMap extends EventEmitter {
91
80
  _reset(): Promise<this>;
92
81
  _draw(heightMap: HeightMap): Promise<this>;
93
82
  readPixel(x: number, y: number): Uint8Array;
83
+ readPixels(x: number, y: number, width: number, height: number): Uint8Array;
94
84
  toGeoTiff(): {
95
85
  data: Uint8Array;
96
86
  metadata: {
@@ -102,12 +92,6 @@ export declare class ShadeMap extends EventEmitter {
102
92
  GeogCitationGeoKey: string;
103
93
  };
104
94
  } | null;
105
- _calculateArea(params: {
106
- dates: Date[];
107
- geometry: {
108
- coordinates: [number, number][][];
109
- };
110
- }): import("./types/area").ShadeArea[];
111
95
  _generateShadeProfile(params: {
112
96
  locations: LatLngLiteral[];
113
97
  dates: Date[];
@@ -11,4 +11,7 @@ declare class ShadeMapLeaflet extends ShadeMap {
11
11
  _repositionCanvas(bounds: LatLngBounds): void;
12
12
  _flush(): void;
13
13
  }
14
+ declare module "leaflet" {
15
+ function shadeMap(options: ShadeMapOptions): ShadeMapLeaflet;
16
+ }
14
17
  export default ShadeMapLeaflet;
@@ -13,6 +13,7 @@ export default class extends ShadeMap {
13
13
  _refreshing: number;
14
14
  _raf: number;
15
15
  _moveEndHandler: () => void;
16
+ _framebuffer?: WebGLFramebuffer;
16
17
  constructor(options: ShadeMapOptions);
17
18
  render(gl: WebGLRenderingContext, matrix: number[]): void;
18
19
  addTo(map: Map): this;
@@ -21,6 +22,8 @@ export default class extends ShadeMap {
21
22
  _getHeightMapCoords(x: number, y: number): any;
22
23
  getHoursOfSun(x: number, y: number): number;
23
24
  remove(): void;
25
+ readPixel(x: number, y: number): Uint8Array;
26
+ readPixels(x: number, y: number, width: number, height: number): Uint8Array;
24
27
  _flush(): void;
25
28
  _repositionCanvas(bounds: LatLngBounds): this;
26
29
  }
@@ -10,7 +10,7 @@ interface BuildingRasterGLArgs {
10
10
  highlight: boolean;
11
11
  }[];
12
12
  mapZoom: number;
13
- imageData: Uint8ClampedArray;
13
+ imageData: WebGLTexture;
14
14
  width: number;
15
15
  height: number;
16
16
  dsmSource: DSMSource;
@@ -26,12 +26,16 @@ export declare class BuildingRasterizer {
26
26
  xyzUniformLocation: WebGLUniformLocation;
27
27
  dimensionsUniformLocation: WebGLUniformLocation;
28
28
  heightMapUniformLocation: WebGLUniformLocation;
29
+ centroidUniformLocation: WebGLUniformLocation;
29
30
  colorUniformLocation: WebGLUniformLocation;
30
31
  positionBuffer: WebGLBuffer;
31
32
  dsmBuffer: WebGLBuffer;
32
33
  indexBuffer: WebGLBuffer;
33
34
  targetTexture: WebGLTexture;
34
35
  constructor(gl: WebGLRenderingContext);
35
- raster(args: BuildingRasterGLArgs): number;
36
+ raster(args: BuildingRasterGLArgs): {
37
+ maxHeight: number;
38
+ heightMapTex: WebGLTexture;
39
+ };
36
40
  }
37
41
  export {};
@@ -31,13 +31,19 @@ interface MergeImageOptions {
31
31
  }
32
32
  export declare class TileMerger {
33
33
  gl: WebGLRenderingContext;
34
- texture: WebGLTexture;
34
+ tileTexture: WebGLTexture;
35
+ outputTexture: WebGLTexture;
35
36
  program: WebGLProgram;
36
- positionAttributeLocation: number;
37
- positionBuffer: WebGLBuffer;
37
+ texPositionAttributeLocation: number;
38
+ tilePositionAttributeLocation: number;
39
+ encodingUniformLocation: WebGLUniformLocation;
40
+ tileSizeUniformLocation: WebGLUniformLocation;
41
+ texPositionBuffer: WebGLBuffer;
42
+ tilePositionBuffer: WebGLBuffer;
43
+ framebuffer: WebGLFramebuffer;
38
44
  inProgress: HTMLImageElement[];
39
45
  finished: number;
40
46
  constructor(gl: WebGLRenderingContext);
41
- merge(tiles: XYZRaster[], options: MergeImageOptions): Promise<Uint8ClampedArray | null>;
47
+ merge(tiles: XYZRaster[], options: MergeImageOptions): Promise<WebGLTexture | null>;
42
48
  }
43
49
  export {};
@@ -0,0 +1,47 @@
1
+ import { XYZRaster } from "./image";
2
+ /**
3
+ * Notes:
4
+ *
5
+ * The responsibility of this code is to download map tiles and stitch
6
+ * them together into a bitmap
7
+ *
8
+ * The code can be aborted if a new set of tiles is requested
9
+ * The code works with 256x256 and 512x512 tiles
10
+ * Zoom can exceed a tileset's maximum value by cropping and scaling to the appropriate size
11
+ * Some tiles are virtual, they do not correspond to a physical image but are a subset of a physical image
12
+ */
13
+ interface MergeImageOptions {
14
+ getSourceUrl: (params: {
15
+ x: number;
16
+ y: number;
17
+ z: number;
18
+ }) => string;
19
+ getElevation: (params: {
20
+ r: number;
21
+ g: number;
22
+ b: number;
23
+ a: number;
24
+ }) => number;
25
+ width: number;
26
+ height: number;
27
+ crossOrigin?: string;
28
+ tileSize: number;
29
+ maxZoom: number;
30
+ tileLoaded: (loadedTiles: number, totalTiles: number) => void;
31
+ }
32
+ export declare class TileMergerGPU {
33
+ gl: WebGLRenderingContext;
34
+ tileTexture: WebGLTexture;
35
+ outputTexture: WebGLTexture;
36
+ program: WebGLProgram;
37
+ texPositionAttributeLocation: number;
38
+ tilePositionAttributeLocation: number;
39
+ texPositionBuffer: WebGLBuffer;
40
+ tilePositionBuffer: WebGLBuffer;
41
+ framebuffer: WebGLFramebuffer;
42
+ inProgress: HTMLImageElement[];
43
+ finished: number;
44
+ constructor(gl: WebGLRenderingContext);
45
+ merge(tiles: XYZRaster[], options: MergeImageOptions): Promise<Uint8ClampedArray | null>;
46
+ }
47
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { MapboxGeoJSONFeature } from "mapbox-gl";
2
2
  import { BuildingRasterizer } from "../buildings/BuildingRasterizer";
3
+ import { XYZRaster } from "../lib/image";
3
4
  import { TileMerger } from "./TileMerger";
4
5
  import { LatLngBounds, ValidBounds } from "../map/geometryLeaflet";
5
6
  import { DSMSource, TerrainSource } from "../types/shadeMapOptions";
@@ -16,17 +17,17 @@ interface HeightMapParams {
16
17
  forceUpdate: boolean;
17
18
  }
18
19
  export interface HeightMap {
20
+ heightMapTex: WebGLTexture | null;
19
21
  width: number;
20
22
  height: number;
21
- imageData: Uint8ClampedArray;
22
23
  maxHeight: number;
23
24
  visibleDEMPixelBounds: ValidBounds;
24
25
  DEMPixelBounds: ValidBounds;
26
+ raster: XYZRaster[];
25
27
  demZoom: number;
26
28
  dirty: boolean;
27
29
  outputWidth: number;
28
30
  outputHeight: number;
29
- kmPerPixel: number;
30
31
  }
31
32
  export declare const getHeightMap: (params: HeightMapParams) => Promise<HeightMap>;
32
33
  export {};
@@ -1,4 +1,3 @@
1
- import { LatLng } from "leaflet";
2
1
  import { Point, ValidBounds } from "../map/geometryLeaflet";
3
2
  export declare const pad: (x: number) => string | number;
4
3
  export interface XYZ {
@@ -23,28 +22,12 @@ export declare const getDeclination: (date: Date) => {
23
22
  dec: number;
24
23
  Hi: number;
25
24
  };
25
+ export declare const getDeclinationMs: (ms: number) => {
26
+ dec: number;
27
+ Hi: number;
28
+ };
26
29
  export declare const randomId: () => number;
27
30
  export declare const timeInTheSunMs: (exposureLayerColor: Uint8Array, exposureLayerOpacity: number, totalTimeIntervalInMs: number) => number;
28
31
  export declare const UTCOffsetByTimeZone: (date?: Date, timeZone?: string | undefined) => number;
29
- export declare function findBounds(lngLatPairs: [number, number][]): {
30
- minLat: number;
31
- maxLat: number;
32
- minLng: number;
33
- maxLng: number;
34
- };
35
- export declare function findMercBounds(lngLatPairs: [number, number][]): {
36
- minX: number;
37
- maxX: number;
38
- minY: number;
39
- maxY: number;
40
- };
41
- export declare function mercatorFromLngLat(coords: {
42
- lng: number;
43
- lat: number;
44
- }): {
45
- x: number;
46
- y: number;
47
- };
48
32
  export declare function mercatorXfromLng(lng: number): number;
49
33
  export declare function mercatorYfromLat(lat: number): number;
50
- export declare function tesselate(coordinates: number[][][]): LatLng[];
@@ -2,7 +2,6 @@ import { UMap } from "../map/umap";
2
2
  import { CompiledKernel } from "../shader/kernel";
3
3
  import { Color } from "../types/color";
4
4
  import { HeightMap } from "./heightMap";
5
- import { Geometry } from "../types/shadeMapOptions";
6
5
  interface DrawShadowParams {
7
6
  kernel: CompiledKernel;
8
7
  map: UMap;
@@ -12,7 +11,7 @@ interface DrawShadowParams {
12
11
  opacity: number;
13
12
  maxZoom: number;
14
13
  belowCanopy: boolean;
15
- geometry?: Geometry;
14
+ skipRender: boolean;
16
15
  }
17
16
  export declare const drawShadow: (params: DrawShadowParams) => void;
18
17
  export {};
@@ -0,0 +1,13 @@
1
+ export interface BindTextureOptions {
2
+ gl: WebGLRenderingContext;
3
+ texture: WebGLTexture;
4
+ imageData?: Uint8ClampedArray | Float32Array | null;
5
+ width: number;
6
+ height: number;
7
+ filter?: number;
8
+ wrap?: number;
9
+ format?: number;
10
+ type?: number;
11
+ internalFormat?: number;
12
+ }
13
+ export declare const bindTexture: (options: BindTextureOptions) => void;
@@ -1,18 +1,10 @@
1
1
  import { Color } from "../types/color";
2
- import { DSMSource } from "../types/shadeMapOptions";
3
2
  import { Shadow3DData } from "../types/shadow3DData";
4
3
  import { CompiledKernel } from "./kernel";
5
4
  export declare const updateHeightMapGPU: (compiledKernel: CompiledKernel, shadow3DData: Shadow3DData) => void;
6
5
  export declare const updateDateGPU: (compiledKernel: CompiledKernel, params: {
7
6
  date: Date;
8
7
  }) => void;
9
- export declare const calculateArea: (compiledKernel: CompiledKernel, params: {
10
- dates: Date[];
11
- dsm: DSMSource;
12
- geometry: {
13
- coordinates: [number, number][][];
14
- };
15
- }) => import("../types/area").ShadeArea[];
16
8
  export declare const generateShadeProfile: (compiledKernel: CompiledKernel, params: {
17
9
  texCoords: number[][];
18
10
  dates: Date[];
@@ -20,11 +12,17 @@ export declare const generateShadeProfile: (compiledKernel: CompiledKernel, para
20
12
  shadeColor: number[];
21
13
  }) => Uint8Array;
22
14
  export declare const generateLocationShadeProfile: (compiledKernel: CompiledKernel, params: {
15
+ startTime: number;
16
+ endTime: number;
17
+ tzId: string;
23
18
  texCoord: number[];
24
- dates: Date[][];
25
19
  sunColor: number[];
26
20
  shadeColor: number[];
27
- }) => Uint8Array;
21
+ }) => {
22
+ output: Uint8Array;
23
+ outputWidth: number;
24
+ outputHeight: number;
25
+ };
28
26
  export declare const updateDateRangeGPU: (compiledKernel: CompiledKernel, params: {
29
27
  startDate: Date;
30
28
  endDate: Date;
@@ -35,4 +33,3 @@ export declare const updateColorGPU: (compiledKernel: CompiledKernel, params: {
35
33
  color: Color;
36
34
  opacity: number;
37
35
  }) => void;
38
- export declare const updateCowHeightGPU: (compiledKernel: CompiledKernel, cowHeight: number) => void;
@@ -1,11 +1,10 @@
1
- import { DSMSource } from "../types/shadeMapOptions";
2
- import { ShadeArea } from "../types/area";
3
1
  interface CompileProgramArgs {
4
2
  gl: WebGLRenderingContext;
5
3
  vSrc: string;
6
4
  fSrc: string;
7
5
  }
8
- interface UpdateLocationArgs {
6
+ interface UpdateHeightMapArgs {
7
+ heightMapTex: WebGLTexture | null;
9
8
  width: number;
10
9
  height: number;
11
10
  maxHeight: number;
@@ -23,13 +22,7 @@ interface UpdateLocationArgs {
23
22
  outputWidth: number;
24
23
  outputHeight: number;
25
24
  belowCanopy: boolean;
26
- kmPerPixel: number;
27
- }
28
- interface UpdateViewportArgs {
29
- xStart: number;
30
- yStart: number;
31
- xEnd: number;
32
- yEnd: number;
25
+ skipRender: boolean;
33
26
  }
34
27
  interface UpdateDateArgs {
35
28
  dec: number;
@@ -44,36 +37,36 @@ interface UpdateDateRangeArgs {
44
37
  interface UpdateColorArgs {
45
38
  colorVec: number[];
46
39
  }
40
+ interface ShadeProfileArgs {
41
+ texCoords: number[][];
42
+ dates: Date[];
43
+ sunColor: number[];
44
+ shadeColor: number[];
45
+ }
46
+ interface LocationShadeProfileArgs {
47
+ startTime: number;
48
+ endTime: number;
49
+ tzId: string;
50
+ texCoord: number[];
51
+ sunColor: number[];
52
+ shadeColor: number[];
53
+ }
47
54
  export interface CompiledKernel {
48
- updateLocation: (args: UpdateLocationArgs) => void;
49
- updateViewport: (args: UpdateViewportArgs) => void;
55
+ updateHeightMap: (args: UpdateHeightMapArgs) => void;
50
56
  updateDate: (args: UpdateDateArgs) => void;
51
57
  updateDateRange: (args: UpdateDateRangeArgs) => Promise<boolean>;
52
58
  updateColor: (args: UpdateColorArgs) => void;
53
- updateCowHeight: (cowHeight: number) => void;
54
- generateShadeProfile: (args: {
55
- texCoords: number[][];
56
- dates: Date[];
57
- sunColor: number[];
58
- shadeColor: number[];
59
- }) => Uint8Array;
60
- generateLocationShadeProfile: (args: {
61
- texCoord: number[];
62
- dates: Date[][];
63
- sunColor: number[];
64
- shadeColor: number[];
65
- }) => Uint8Array;
66
- calculateArea: (args: {
67
- dates: Date[];
68
- dsm: DSMSource;
69
- geometry: {
70
- coordinates: [number, number][][];
71
- };
72
- }) => ShadeArea[];
59
+ generateShadeProfile: (args: ShadeProfileArgs) => Uint8Array;
60
+ generateLocationShadeProfile: (args: LocationShadeProfileArgs) => {
61
+ output: Uint8Array;
62
+ outputWidth: number;
63
+ outputHeight: number;
64
+ };
73
65
  }
74
66
  export declare function compileProgram(args: CompileProgramArgs): WebGLProgram;
75
67
  interface Settings {
76
68
  context: WebGLRenderingContext;
69
+ setRenderBuffer: (gl: WebGLRenderingContext, viewportWidth: number, viewportHeight: number) => void;
77
70
  }
78
71
  declare function kernel(settings: Settings): CompiledKernel;
79
72
  export default kernel;
@@ -32,11 +32,6 @@ export interface SunExposureOptions {
32
32
  export interface SunExposure extends SunExposureOptions {
33
33
  enabled: boolean;
34
34
  }
35
- export interface Geometry {
36
- enabled: boolean;
37
- type: string;
38
- coordinates: number[][][];
39
- }
40
35
  export interface ShadeMapOptions {
41
36
  date?: Date;
42
37
  color?: string;
@@ -45,7 +40,6 @@ export interface ShadeMapOptions {
45
40
  sunExposure?: SunExposure;
46
41
  terrainSource?: TerrainSource;
47
42
  dsmSource?: DSMSource;
48
- geometry?: Geometry;
49
43
  getFeatures?: () => Promise<MapboxGeoJSONFeature[]>;
50
44
  apiKey: string;
51
45
  debug?: (msg: string) => void;
@@ -1,6 +1,6 @@
1
1
  import { Color } from "./color";
2
2
  export interface Shadow3DData {
3
- imageData: Uint8ClampedArray;
3
+ heightMapTex: WebGLTexture | null;
4
4
  maxHeight: number;
5
5
  width: number;
6
6
  height: number;
@@ -17,5 +17,5 @@ export interface Shadow3DData {
17
17
  outputWidth: number;
18
18
  outputHeight: number;
19
19
  belowCanopy: boolean;
20
- kmPerPixel: number;
20
+ skipRender: boolean;
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leaflet-shadow-simulator",
3
- "version": "0.56.1",
3
+ "version": "0.57.0",
4
4
  "description": "Display terrain and structure shadows cast by the sun in a custom Leaflet layer",
5
5
  "main": "dist/leaflet-shadow-simulator.umd.min.js",
6
6
  "browser": "dist/leaflet-shadow-simulator.umd.min.js",