mapbox-gl-shadow-simulator 0.63.0 → 0.64.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.
- package/README.md +1 -1
- package/dist/mapbox-gl-shadow-simulator.esm.js +2 -2
- package/dist/mapbox-gl-shadow-simulator.umd.min.js +2 -2
- package/examples/map.html +2 -2
- package/examples/maplibre.html +3 -3
- package/examples/markers-maplibre.html +3 -3
- package/examples/markers.html +2 -2
- package/package.json +1 -1
- package/dist/leaflet-shademap/leaflet-shademap/dist/ShadeMap.d.ts +0 -129
- package/dist/leaflet-shademap/leaflet-shademap/dist/ShadeMapLeaflet.d.ts +0 -16
- package/dist/leaflet-shademap/leaflet-shademap/dist/ShadeMapMapbox.d.ts +0 -31
- package/dist/leaflet-shademap/leaflet-shademap/dist/buildings/BuildingRasterizer.d.ts +0 -44
- package/dist/leaflet-shademap/leaflet-shademap/dist/buildings/fetch-buildings.d.ts +0 -12
- package/dist/leaflet-shademap/leaflet-shademap/dist/buildings/normalize-buildings.d.ts +0 -8
- package/dist/leaflet-shademap/leaflet-shademap/dist/components/CanvasOverlay.d.ts +0 -11
- package/dist/leaflet-shademap/leaflet-shademap/dist/index.d.ts +0 -7
- package/dist/leaflet-shademap/leaflet-shademap/dist/lib/EventEmitter.d.ts +0 -10
- package/dist/leaflet-shademap/leaflet-shademap/dist/lib/TileMerger.d.ts +0 -48
- package/dist/leaflet-shademap/leaflet-shademap/dist/lib/heightMap.d.ts +0 -35
- package/dist/leaflet-shademap/leaflet-shademap/dist/lib/helpers.d.ts +0 -33
- package/dist/leaflet-shademap/leaflet-shademap/dist/lib/image.d.ts +0 -13
- package/dist/leaflet-shademap/leaflet-shademap/dist/lib/projection.d.ts +0 -3
- package/dist/leaflet-shademap/leaflet-shademap/dist/lib/shadowMap.d.ts +0 -17
- package/dist/leaflet-shademap/leaflet-shademap/dist/lib/webgl.d.ts +0 -13
- package/dist/leaflet-shademap/leaflet-shademap/dist/map/geometryLeaflet.d.ts +0 -11
- package/dist/leaflet-shademap/leaflet-shademap/dist/map/umap.d.ts +0 -26
- package/dist/leaflet-shademap/leaflet-shademap/dist/shader/gpu.d.ts +0 -37
- package/dist/leaflet-shademap/leaflet-shademap/dist/shader/kernel.d.ts +0 -74
- package/dist/leaflet-shademap/leaflet-shademap/dist/types/color.d.ts +0 -5
- package/dist/leaflet-shademap/leaflet-shademap/dist/types/constants.d.ts +0 -3
- package/dist/leaflet-shademap/leaflet-shademap/dist/types/quality.d.ts +0 -5
- package/dist/leaflet-shademap/leaflet-shademap/dist/types/shadeMapOptions.d.ts +0 -47
- package/dist/leaflet-shademap/leaflet-shademap/dist/types/shadow3DData.d.ts +0 -21
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright Ted Piotrowski 2025
|
|
3
3
|
* Package: mapbox-gl-shadow-simulator
|
|
4
|
-
* Version: 0.
|
|
4
|
+
* Version: 0.64.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():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ShadeMap=e()}(this,function(){"use strict";function t(t,e,r,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 e(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 r(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function i(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var n=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function a(t,e,r){return t instanceof i?t:o(t)?new i(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new i(t.x,t.y):new i(t,e,r)}function s(t,e){if(t)for(var r=e?[t,e]:t,o=0,i=r.length;o<i;o++)this.extend(r[o])}function u(t,e){return!t||t instanceof s?t:new s(t,e)}function l(t,e){if(t)for(var r=e?[t,e]:t,o=0,i=r.length;o<i;o++)this.extend(r[o])}function h(t,e){return t instanceof l?t:new l(t,e)}i.prototype={clone:function(){return new i(this.x,this.y)},add:function(t){return this.clone()._add(a(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(a(t))},_subtract:function(t){return this.x-=t.x,this.y-=t.y,this},divideBy:function(t){return this.clone()._divideBy(t)},_divideBy:function(t){return this.x/=t,this.y/=t,this},multiplyBy:function(t){return this.clone()._multiplyBy(t)},_multiplyBy:function(t){return this.x*=t,this.y*=t,this},scaleBy:function(t){return new i(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new i(this.x/t.x,this.y/t.y)},round:function(){return this.clone()._round()},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},floor:function(){return this.clone()._floor()},_floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.clone()._ceil()},_ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},trunc:function(){return this.clone()._trunc()},_trunc:function(){return this.x=n(this.x),this.y=n(this.y),this},distanceTo:function(t){var e=(t=a(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=a(t)).x===this.x&&t.y===this.y},contains:function(t){return t=a(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+r(this.x)+", "+r(this.y)+")"}},s.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof i||"number"==typeof t[0]||"x"in t)e=r=a(t);else if(e=(t=u(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 a((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return a(this.min.x,this.max.y)},getTopRight:function(){return a(this.max.x,this.min.y)},getTopLeft:function(){return this.min},getBottomRight:function(){return this.max},getSize:function(){return this.max.subtract(this.min)},contains:function(t){var e,r;return(t="number"==typeof t[0]||t instanceof i?a(t):u(t))instanceof s?(e=t.min,r=t.max):e=r=t,e.x>=this.min.x&&r.x<=this.max.x&&e.y>=this.min.y&&r.y<=this.max.y},intersects:function(t){t=u(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=u(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 u(a(e.x-o,e.y-i),a(r.x+o,r.y+i))},equals:function(t){return!!t&&(t=u(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},l.prototype={extend:function(t){var e,r,o=this._southWest,i=this._northEast;if(t instanceof f)e=t,r=t;else{if(!(t instanceof l))return t?this.extend(d(t)||h(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 f(e.lat,e.lng),this._northEast=new f(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 l(new f(e.lat-o,e.lng-i),new f(r.lat+o,r.lng+i))},getCenter:function(){return new f((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 f(this.getNorth(),this.getWest())},getSouthEast:function(){return new f(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 f||"lat"in t?d(t):h(t);var e,r,o=this._southWest,i=this._northEast;return t instanceof l?(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=h(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=h(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=h(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var c=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 s(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(t){var r=this.wrapLng?e(t.lng,this.wrapLng,!0):t.lng;return new f(this.wrapLat?e(t.lat,this.wrapLat,!0):t.lat,r,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 l(new f(n.lat-o,n.lng-i),new f(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 f(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 d(t,e,r){return t instanceof f?t:o(t)&&"object"!=typeof t[0]?3===t.length?new f(t[0],t[1],t[2]):2===t.length?new f(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new f(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new f(t,e,r)}f.prototype={equals:function(t,e){return!!t&&(t=d(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("+r(this.lat,t)+", "+r(this.lng,t)+")"},distanceTo:function(t){return c.distance(this,d(t))},wrap:function(){return c.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return h([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new f(this.lat,this.lng,this.alt)}};const m=256,_=.40909994067971484,g=t=>{const e=t.valueOf();return p(e)},p=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(_),Math.cos(o));return{dec:Math.asin(Math.sin(_)*Math.sin(o)),Hi:(4.889714432387314+6.3003876824396166*e-i)%(2*Math.PI)+2*Math.PI}},x=()=>Math.floor(1e7*Math.random()),E=(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},v=(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()};const T=t=>{const e=()=>!t.getPitch;return{project:(r,o)=>{if(e())return t.project(r,o);{const{lat:t,lng:e}=r;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*m)(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)*m)(t,o))}},unproject:(r,o)=>{return e()?t.unproject(r,o):new f((i=r.y,n=o,a=Math.PI-2*Math.PI*i/m/Math.pow(2,n),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/m/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 l(e,r)}}};class y{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}}function A(t,e,r){r=r||2;var o,i,n,a,s,u,l,h=e&&e.length,c=h?e[0]*r:t.length,f=b(t,0,c,r,!0),d=[];if(!f||f.next===f.prev)return d;if(h&&(f=function(t,e,r,o){var i,n,a,s=[];for(i=0,n=e.length;i<n;i++)(a=b(t,e[i]*o,i<n-1?e[i+1]*o:t.length,o,!1))===a.next&&(a.steiner=!0),s.push(I(a));for(s.sort(D),i=0;i<s.length;i++)r=S(s[i],r);return r}(t,e,f,r)),t.length>80*r){o=n=t[0],i=a=t[1];for(var m=r;m<c;m+=r)(s=t[m])<o&&(o=s),(u=t[m+1])<i&&(i=u),s>n&&(n=s),u>a&&(a=u);l=0!==(l=Math.max(n-o,a-i))?32767/l:0}return M(f,d,r,o,i,l,0),d}function b(t,e,r,o,i){var n,a;if(i===k(t,e,r,o)>0)for(n=e;n<r;n+=o)a=Y(n,t[n],t[n+1],a);else for(n=r-o;n>=e;n-=o)a=Y(n,t[n],t[n+1],a);return a&&z(a,a.next)&&(Z(a),a=a.next),a}function R(t,e){if(!t)return t;e||(e=t);var r,o=t;do{if(r=!1,o.steiner||!z(o,o.next)&&0!==O(o.prev,o,o.next))o=o.next;else{if(Z(o),(o=e=o.prev)===o.next)break;r=!0}}while(r||o!==e);return e}function M(t,e,r,o,i,n,a){if(t){!a&&n&&function(t,e,r,o){var i=t;do{0===i.z&&(i.z=C(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,n);for(var s,u,l=t;t.prev!==t.next;)if(s=t.prev,u=t.next,n?F(t,o,i,n):w(t))e.push(s.i/r|0),e.push(t.i/r|0),e.push(u.i/r|0),Z(t),t=u.next,l=u.next;else if((t=u)===l){a?1===a?M(t=L(R(t),e,r),e,r,o,i,n,2):2===a&&U(t,e,r,o,i,n):M(R(t),e,r,o,i,n,1);break}}}function w(t){var e=t.prev,r=t,o=t.next;if(O(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&&B(i,s,n,u,a,l,m.x,m.y)&&O(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function F(t,e,r,o){var i=t.prev,n=t,a=t.next;if(O(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,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,p=C(d,m,e,r,o),x=C(_,g,e,r,o),E=t.prevZ,v=t.nextZ;E&&E.z>=p&&v&&v.z<=x;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=g&&E!==i&&E!==a&&B(s,h,u,c,l,f,E.x,E.y)&&O(E.prev,E,E.next)>=0)return!1;if(E=E.prevZ,v.x>=d&&v.x<=_&&v.y>=m&&v.y<=g&&v!==i&&v!==a&&B(s,h,u,c,l,f,v.x,v.y)&&O(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;E&&E.z>=p;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=g&&E!==i&&E!==a&&B(s,h,u,c,l,f,E.x,E.y)&&O(E.prev,E,E.next)>=0)return!1;E=E.prevZ}for(;v&&v.z<=x;){if(v.x>=d&&v.x<=_&&v.y>=m&&v.y<=g&&v!==i&&v!==a&&B(s,h,u,c,l,f,v.x,v.y)&&O(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function L(t,e,r){var o=t;do{var i=o.prev,n=o.next.next;!z(i,n)&&X(i,o,o.next,n)&&W(i,n)&&W(n,i)&&(e.push(i.i/r|0),e.push(o.i/r|0),e.push(n.i/r|0),Z(o),Z(o.next),o=t=n),o=o.next}while(o!==t);return R(o)}function U(t,e,r,o,i,n){var a=t;do{for(var s=a.next.next;s!==a.prev;){if(a.i!==s.i&&N(a,s)){var u=j(a,s);return a=R(a,a.next),u=R(u,u.next),M(a,e,r,o,i,n,0),void M(u,e,r,o,i,n,0)}s=s.next}a=a.next}while(a!==t)}function D(t,e){return t.x-e.x}function S(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&&B(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),W(o,t)&&(u<f||u===f&&(o.x>r.x||o.x===r.x&&P(r,o)))&&(r=o,f=u)),o=o.next}while(o!==l);return r}(t,e);if(!r)return e;var o=j(r,t);return R(o,o.next),R(r,r.next)}function P(t,e){return O(t.prev,t,e.prev)<0&&O(e.next,t,t.next)<0}function C(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 I(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 B(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 N(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&&X(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(W(t,e)&&W(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)&&(O(t.prev,t,e.prev)||O(t,e.prev,e))||z(t,e)&&O(t.prev,t,t.next)>0&&O(e.prev,e,e.next)>0)}function O(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function z(t,e){return t.x===e.x&&t.y===e.y}function X(t,e,r,o){var i=H(O(t,e,r)),n=H(O(t,e,o)),a=H(O(r,o,t)),s=H(O(r,o,e));return i!==n&&a!==s||(!(0!==i||!G(t,r,e))||(!(0!==n||!G(t,o,e))||(!(0!==a||!G(r,t,o))||!(0!==s||!G(r,e,o)))))}function G(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 H(t){return t>0?1:t<0?-1:0}function W(t,e){return O(t.prev,t,t.next)<0?O(t,e,t.next)>=0&&O(t,t.prev,e)>=0:O(t,e,t.prev)<0||O(t,t.next,e)<0}function j(t,e){var r=new K(t.i,t.x,t.y),o=new K(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 Y(t,e,r,o){var i=new K(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 Z(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function K(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function k(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 V(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,o=A.flatten(e.coordinates),i=new Float32Array(o.vertices.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})),n=A(o.vertices,o.holes,o.dimensions),a=n.length>256?new Uint16Array(n):new Uint8Array(n),s=function(t){const{height:e=0,levels:r=0,render_height:o=0}=t;if(r)return 3.04*r;return o||e}(r),u=r.highlight||!1;let l=0,h=0,c=0;for(let t=0;t<i.length;t+=2)l+=i[t],h+=i[t+1],c++;return{aPosition:i,cuts:a,buildingHeight:s,centroid:[l/c,h/c],highlight:u}})}A.deviation=function(t,e,r,o){var i=e&&e.length,n=i?e[0]*r:t.length,a=Math.abs(k(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(k(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)},A.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};const q=(t,e)=>{const{lat:r,lng:o}=t;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*m)(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)*m)(r,e))},$=(t,e)=>{return new f((r=t.y,o=e,i=Math.PI-2*Math.PI*r/m/Math.pow(2,o),180/Math.PI*Math.atan(.5*(Math.exp(i)-Math.exp(-i)))),function(t,e){return t/m/Math.pow(2,e)*360-180}(t.x,e));var r,o,i};let J,Q={heightMapTex:null,width:0,height:0,visibleDEMPixelBounds:new s(new i(0,0),new i(0,0)),DEMPixelBounds:new s(new i(0,0),new i(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const tt=e=>t(void 0,void 0,void 0,function*(){const{demZoom:r,getFeatures:o,terrainSource:n,canopySource:a,dsmSource:u,tileLoaded:h,gl:c,bounds:f,buildingRasterizer:d,tileMerger:_,canopyMerger:g,forceUpdate:p=!1}=e,{getSourceUrl:x,getElevation:E,maxZoom:v,tileSize:T,_overzoom:y}=n,A=(b={getFeatures:o},t(void 0,void 0,void 0,function*(){const{getFeatures:t}=b;try{return V(yield t())}catch(t){console.log("Error merging buildings",t)}return[]}));var b;try{const t=f,e=t.getNorthWest(),o=t.getSouthEast(),n=new s(q(e,r),q(o,r));let y=new i(n.min.x,n.min.y),b=n.max.x-n.min.x;const R=n.max.y-n.min.y,M=n.max.subtract(n.min);M.y>M.x&&(y.x-=m,b+=512);const w=(t=>{const{upperLeft:e,width:r,height:o}=t,i=e.divideBy(m).floor().multiplyBy(m),n=(Math.ceil(r/m)+1)*m,a=(Math.ceil(o/m)+1)*m,u=i.add([n,a]);return new s(i,u)})({upperLeft:y,width:b,height:R}),{x:F,y:L}=w.max.subtract(w.min),U=(t=>{const{upperLeft:e,width:r,height:o,zoom:i}=t,n=e.divideBy(m).floor(),a=n.x+r/m,s=Math.min(n.y+o/m,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:w.min,width:F,height:L,zoom:r}),D=(t=>{t.sort((t,e)=>t.y!==e.y?t.y-e.y:t.x-e.x);const e=t.reduce((t,e)=>e.x<t.x?e:t).x,r=t.reduce((t,e)=>e.y<t.y?e:t).y;return t.map(t=>{const 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)*m,yOffset:(t.y-r)*m}})})(U),S=n.max.x-n.min.x,P=n.max.y-n.min.y,C=Math.round(S),I=Math.round(P),B=JSON.stringify(D);if(!p&&B===J&&r<v)return Q=Object.assign(Object.assign({},Q),{outputWidth:C,outputHeight:I,visibleDEMPixelBounds:n,demZoom:r,dirty:!0}),Q;const N=[_.merge(D,{maxZoom:v,width:F,height:L,crossOrigin:"Anonymous",getSourceUrl:x,getElevation:E,tileSize:T,tileLoaded:h})];if(void 0!==a){const t=g.merge(D,{maxZoom:a.maxZoom,width:F,height:L,crossOrigin:"Anonymous",getSourceUrl:a.getSourceUrl,getElevation:a.getElevation,tileSize:a.tileSize,tileLoaded:h});N.push(t)}else N.push(new Promise(t=>{const e=c.createTexture();c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,e),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,1,1,0,c.RGBA,c.UNSIGNED_BYTE,new Uint8ClampedArray([0,0,0,0])),t(e)}));const[O,z]=yield Promise.all(N);if(null===O||null===z)return Q=Object.assign(Object.assign({},Q),{visibleDEMPixelBounds:n,demZoom:r,dirty:!1}),Q;const X=new s(q(new l(u.bounds).getNorthWest(),r),q(new l(u.bounds).getSouthEast(),r)),G=X.min.subtract(w.min),H=X.max.subtract(w.min),W=[G.x/F,G.y/L,H.x/F,H.y/L].map(t=>2*t-1),j=yield A,{maxHeight:Y,heightMapTex:Z}=d.raster({upperLeftTile:D[0],width:F,height:L,mapZoom:r,features:j,imageData:O,gl:c,dsmSource:u,dsmCoords:W,canopyData:z}),K=Math.max(u.maxHeight,O.maxHeight+Y);J=B,Q={heightMapTex:Z,maxHeight:K,width:F,height:L,DEMPixelBounds:w,visibleDEMPixelBounds:n,raster:D,demZoom:r,dirty:!0,outputWidth:C,outputHeight:I}}catch(t){console.error("Could not decode height map",t)}return Q}),et=(t,e)=>{const{r:r,g:o,b:i}=t;return[r/255,o/255,i/255,e]},rt=(t,e)=>{const{date:r}=e,{dec:o,Hi:i}=g(r);t.updateDate({dec:o,Hi:i})},ot=(e,r)=>t(void 0,void 0,void 0,function*(){return yield e.updateDateRange(Object.assign({},r))}),it=(t,e)=>{const{color:r,opacity:o}=e,i=et(r,o);t.updateColor({colorVec:i})},nt=t=>{const{kernel:e,map:r,heightMap:o,now:i,color:n,opacity:a,belowCanopy:s,skipRender:u}=t;try{const{heightMapTex:t,outputHeight:h,outputWidth:c,maxHeight:f,width:d,height:_,DEMPixelBounds:p,visibleDEMPixelBounds:x,demZoom:E}=o;if(0===d||0===_)return;const{min:v,max:T}=x;if(!v||!T)return;const{x:y,y:A}=T.subtract(v),b=p.min,R=r.getPixelDimensions(),M=r.screenUnproject([0,0]),w=r.screenUnproject([R.width,0]),F=r.screenUnproject([R.width,R.height]),L=r.screenUnproject([0,R.height]),U=[L,F,M,w].map(t=>r.project(t,E)),D=U.map(t=>[(t.x-b.x)/d,(t.y-b.y)/_]).flat(),S=U.map(t=>[(t.x-v.x)/y,(t.y-v.y)/A]).map(t=>[2*t[0]-1,(2*t[1]-1)*(r.isLeaflet()?-1:1)]).flat(),P=b.y/m/Math.pow(2,E),C=_/m/Math.pow(2,E),I=new l($(p.getTopLeft(),E),$(p.getBottomRight(),E)),B=I.getWest(),N=Math.abs(I.getWest()-I.getEast());((t,e)=>{const{color:r,opacity:o,date:i}=e,n=et(r,o),{dec:a,Hi:s}=g(i);t.updateHeightMap(Object.assign({dec:a,Hi:s,colorVec:n,step:1},e))})(e,{heightMapTex:t,maxHeight:f,width:d,height:_,heightMapZoom:E,cornerTextureCoords:D,cornerClipCoords:S,topYCoord:P,ySize:C,west:B,dLng:N,date:i,color:n,opacity:a,outputHeight:h,outputWidth:c,belowCanopy:s,skipRender:u})}catch(t){console.error("EXCEPTION",t)}};class at extends y{constructor(...e){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}},canopySource:void 0,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 r=e[0];if(this.options=Object.assign(this.options,r),!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(e=>t(this,void 0,void 0,function*(){if(200!==e.status)throw new Error(yield e.text())})).catch(e=>t(this,void 0,void 0,function*(){throw new Error(`Could not load ShadeMap API. Key: ${this.options.apiKey} Error: ${e}`)})),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&&(rt(this._compiledKernel,{date:this.options.date}),this._heightMap&&this._flush())):this._flush(),this}_setDateForTimezone(t,e){let r=0;e&&(r=v(this.options.date)-v(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}setCanopySource(t){return this.options.canopySource=t,delete this._heightMap,this._reset(),this}setDSMSource(t){return this.options.dsmSource=t,delete this._heightMap,this._reset(),this}setSunExposure(e=!1,r){return t(this,void 0,void 0,function*(){if(this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:e}),r){const{startDate:t=new Date,endDate:o=new Date,iterations:i=32}=r;this.options.sunExposure={enabled:e,startDate:t,endDate:o,iterations:i}}if(this._map&&this._compiledKernel&&this._heightMap){if(!1===e)rt(this._compiledKernel,{date:this.options.date});else{const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!(t instanceof Date&&e instanceof Date))throw new Error("Start date or end date or both are missing");if(e.getTime()<t.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield ot(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._flush()}return this})}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:o,height:i}=this._heightMap,n=e.min;return t.map(t=>{const e=q(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 n=t.getCenter(),a=q(n,e),s=$(new i(a.x-r/2,a.y-o/2),e),u=$(new i(a.x+r/2,a.y+o/2),e);return t.createBounds({nw:s,se:u})}_getDEMZoom(t){const e=Math.min(this.options.terrainSource._overzoom||this.options.terrainSource.maxZoom,t.getZoom());return Math.round(e)}_reset(){return t(this,void 0,void 0,function*(){if(this.options.debug("_reset()"),this._map){const t=T(this._map);let e=this._getDEMZoom(t);try{this._bounds=this._getBounds(t,e)}catch(t){return console.error("Invalid bounds returned: ",t),this}try{if(!t.isLeaflet()&&this._map.getPitch()>45){yield new Promise(t=>{this._map.loaded()?t(!0):this._map.once("idle",function(){t(!0)})});const r=this._map.style._sourceCaches["other:composite"].getVisibleCoordinates().reverse(),o=r.reduce((t,e)=>Math.max(t,e.canonical.z),Number.MIN_SAFE_INTEGER),n=r.filter(t=>t.canonical.z===o).map(t=>t.canonical),[a,s,u,l]=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=$(new i(512*a,512*s),o+1),c=$(new i(512*(u+1),512*(l+1)),o+1);e=o+1,this._bounds=t.createBounds({nw:h,se:c})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield tt({gl:this._gl,demZoom:e,bounds:this._bounds,terrainSource:this.options.terrainSource,canopySource:this.options.canopySource,dsmSource:this.options.dsmSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,canopyMerger:this._canopyMerger,tileLoaded:(t,e)=>this.emit("tileloaded",t,e),forceUpdate:!this._heightMap});this._heightMap=r,r.dirty&&(yield this._draw(r))}return this})}_draw(e){return t(this,void 0,void 0,function*(){if(this.options.debug("_draw()"),this._canvas&&this._compiledKernel&&this._map){if(nt({kernel:this._compiledKernel,map:T(this._map),heightMap:e,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 ot(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._bounds&&this._repositionCanvas(this._bounds)}return this})}readPixel(t,e){const r=new Uint8Array(4),o=window.innerHeight-e;return this._gl&&this._gl.readPixels(t,o,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}isPositionInSun(e,r){return t(this,void 0,void 0,function*(){const t=this.readPixel(e,r);return 0===t[0]&&0===t[1]&&0===t[2]&&0===t[3]})}isPositionInShade(e,r){return t(this,void 0,void 0,function*(){return!(yield this.isPositionInSun(e,r))})}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=E(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&&!T(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=T(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),r=((t,e)=>{const r=et({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),o=et({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 r}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=v(t.startDate)-v(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=et({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),o=et({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=E(r,.5,n);return Math.abs(a/1e3/3600)}return 0}_repositionCanvas(t){}_flush(){window.requestAnimationFrame(()=>this.emit("idle"))}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}}const st=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 ut(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 lt{constructor(t){this.gl=t,this.program=ut({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 vCoord = normalized;\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;\nuniform bool is_negative;\nuniform sampler2D canopy_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) * (is_negative ? -1.0 : 1.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(1,1,1,1)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n\t \tvec4 canopyColor = texture2D(canopy_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 float upper = textureColor.r + canopyColor.r;\n float combined = textureColor.g + canopyColor.g;\n if (combined > 1.0) {\n combined = combined - floor(combined);\n upper += 1.0 / 255.0;\n }\n gl_FragColor = vec4(textureColor.r, textureColor.g, upper, combined);\n }\n // DSM noData values should not be included in heightMap because they produce ugly borders\n\t\treturn;\n }\n if (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n gl_FragColor = vec4(textureColor.r, textureColor.g, textureColor.r, textureColor.g);\n return;\n }\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.isNegative=t.getUniformLocation(this.program,"is_negative"),this.xyzUniformLocation=t.getUniformLocation(this.program,"xyz"),this.dimensionsUniformLocation=t.getUniformLocation(this.program,"dimensions"),this.heightMapUniformLocation=t.getUniformLocation(this.program,"height_map"),this.canopyMapUniformLocation=t.getUniformLocation(this.program,"canopy_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:a,imageData:s,dsmCoords:u,dsmSource:l,canopyData:h,gl:c}=t,{x:f,y:d,z:_}=r;let g=0;c.useProgram(this.program),c.activeTexture(c.TEXTURE1),c.bindTexture(c.TEXTURE_2D,s),c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,h);const p=n,x=a;c.activeTexture(c.TEXTURE0),c.bindTexture(c.TEXTURE_2D,this.targetTexture),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,p,x,0,c.RGBA,c.UNSIGNED_BYTE,null),o>15&&e.length>5?(c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST)):(c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.LINEAR),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.LINEAR)),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),c.viewport(0,0,p,x);const E=c.createFramebuffer();c.bindFramebuffer(c.FRAMEBUFFER,E);const v=c.COLOR_ATTACHMENT0;c.framebufferTexture2D(c.FRAMEBUFFER,v,c.TEXTURE_2D,this.targetTexture,0),c.disable(c.BLEND),c.bindBuffer(c.ARRAY_BUFFER,this.positionBuffer),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,this.indexBuffer),c.clearColor(0,0,0,0),c.clear(c.COLOR_BUFFER_BIT);const T=f/Math.pow(2,_),y=d/Math.pow(2,_),A=new i(T,y),b=n/m/Math.pow(2,_),R=a/m/Math.pow(2,_);c.uniform3f(this.xyzUniformLocation,T,y,_),c.uniform2f(this.dimensionsUniformLocation,b,R),c.uniform1i(this.heightMapUniformLocation,1),c.uniform1i(this.canopyMapUniformLocation,2),c.uniform1i(this.useDSMUniformLocation,0);const M=new Float32Array([-1,-1,1,-1,-1,1,1,1]);if(c.enableVertexAttribArray(this.positionAttributeLocation),c.bufferData(c.ARRAY_BUFFER,M,c.STATIC_DRAW),c.vertexAttribPointer(this.positionAttributeLocation,2,c.FLOAT,!1,0,0),c.uniform4f(this.colorUniformLocation,1,1,1,1),c.drawArrays(c.TRIANGLE_STRIP,0,4),e.filter(t=>!t.highlight).forEach(t=>{const{buildingHeight:e,aPosition:r,cuts:o,centroid:s,highlight:u}=t,l=new i(s[0],s[1]).subtract(A).unscaleBy(new i(b,R)).scaleBy(new i(n,a)).floor();if(l.x<0||l.y<0||l.x>n||l.y>a)return;const h=l.x/n,f=l.y/a,d=5*Math.abs(e),m=Math.floor(d/255)/255,_=Math.floor(d%255)/255;g=Math.max(g,e),c.uniform2f(this.centroidUniformLocation,h,f),c.uniform1i(this.isNegative,e<0?1:0),c.uniform4f(this.colorUniformLocation,m,_,m,_),c.bufferData(c.ARRAY_BUFFER,r,c.DYNAMIC_DRAW),c.vertexAttribPointer(this.positionAttributeLocation,2,c.FLOAT,!1,0,0),c.bufferData(c.ARRAY_BUFFER,r,c.DYNAMIC_DRAW),c.vertexAttribPointer(this.dsmAttributeLocation,2,c.FLOAT,!1,0,0),c.bufferData(c.ELEMENT_ARRAY_BUFFER,o,c.DYNAMIC_DRAW),c.drawElements(c.TRIANGLES,o.length,o.length>256?c.UNSIGNED_SHORT:c.UNSIGNED_BYTE,0)}),0!==l.data.length){c.activeTexture(c.TEXTURE1);const t=c.createTexture();c.bindTexture(c.TEXTURE_2D,t),c.pixelStorei(c.UNPACK_ALIGNMENT,2),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST),c.texImage2D(c.TEXTURE_2D,0,c.LUMINANCE_ALPHA,l.width,l.height,0,c.LUMINANCE_ALPHA,c.UNSIGNED_BYTE,l.data),c.pixelStorei(c.UNPACK_ALIGNMENT,4);const e=[u[0],u[3],u[2],u[3],u[0],u[1],u[2],u[1]],r=new Float32Array(e);c.enableVertexAttribArray(this.positionAttributeLocation),c.bufferData(c.ARRAY_BUFFER,r,c.STATIC_DRAW),c.vertexAttribPointer(this.positionAttributeLocation,2,c.FLOAT,!1,0,0),c.enableVertexAttribArray(this.dsmAttributeLocation),c.bindBuffer(c.ARRAY_BUFFER,this.dsmBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array([0,1,1,1,0,0,1,0]),c.STATIC_DRAW),c.vertexAttribPointer(this.dsmAttributeLocation,2,c.FLOAT,!1,0,0),c.uniform4f(this.colorUniformLocation,1,1,1,1),c.uniform1i(this.useDSMUniformLocation,1),c.colorMask(!1,!1,!0,!0),c.drawArrays(c.TRIANGLE_STRIP,0,4),c.deleteTexture(t)}return c.colorMask(!0,!0,!0,!0),c.activeTexture(c.TEXTURE1),c.bindTexture(c.TEXTURE_2D,s),c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,h),c.uniform1i(this.useDSMUniformLocation,0),e.filter(t=>t.highlight).forEach(t=>{const{buildingHeight:e,aPosition:r,cuts:o,centroid:s,highlight:u}=t,l=new i(s[0],s[1]).subtract(A).unscaleBy(new i(b,R)).scaleBy(new i(n,a)).floor();if(l.x<0||l.y<0||l.x>n||l.y>a)return;const h=l.x/n,f=l.y/a,d=5*e,m=Math.floor(d/255)/255,_=Math.floor(d%255)/255;g=Math.max(g,e),c.uniform2f(this.centroidUniformLocation,h,f),c.uniform4f(this.colorUniformLocation,m,_,m,_),c.bufferData(c.ARRAY_BUFFER,r,c.DYNAMIC_DRAW),c.vertexAttribPointer(this.positionAttributeLocation,2,c.FLOAT,!1,0,0),c.bufferData(c.ARRAY_BUFFER,r,c.DYNAMIC_DRAW),c.vertexAttribPointer(this.dsmAttributeLocation,2,c.FLOAT,!1,0,0),c.bufferData(c.ELEMENT_ARRAY_BUFFER,o,c.DYNAMIC_DRAW),c.drawElements(c.TRIANGLES,o.length,o.length>256?c.UNSIGNED_SHORT:c.UNSIGNED_BYTE,0)}),c.deleteFramebuffer(E),{maxHeight:g,heightMapTex:this.targetTexture}}}const ht=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===m?i:Math.floor(i/2),y:o===m?n:Math.floor(n/2),z:o===m?a:a-1}};class ct{constructor(t){this.gl=t,this.program=ut({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 #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n #else\n precision mediump float;\n #endif\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 getElevationCanopy(vec4 color) {\n float closestDistance = 1000.0;\n int closestColor = 100;\n const int colorCount = 26;\n vec3 colorArray[colorCount];\n\n colorArray[0] = vec3(51.0 / 255.0, 0, 66.0 / 255.0);\n colorArray[1] = vec3(51.0 / 255.0, 16.0/255.0, 86.0 / 255.0);\n colorArray[2] = vec3(51.0 / 255.0, 24.0/255.0, 86.0 / 255.0);\n colorArray[3] = vec3(51.0 / 255.0, 24.0/255.0, 98.0 / 255.0);\n colorArray[4] = vec3(51.0 / 255.0, 37.0/255.0, 108.0 / 255.0);\n colorArray[5] = vec3(48.0 / 255.0, 47.0/255.0, 114.0 / 255.0);\n colorArray[6] = vec3(44.0 / 255.0, 57.0/255.0, 116.0 / 255.0);\n colorArray[7] = vec3(42.0 / 255.0, 68.0/255.0, 117.0 / 255.0);\n colorArray[8] = vec3(39.0 / 255.0, 79.0/255.0, 120.0 / 255.0);\n colorArray[9] = vec3(37.0 / 255.0, 89.0/255.0, 123.0 / 255.0);\n colorArray[10] = vec3(34.0 / 255.0, 100.0/255.0, 120.0 / 255.0);\n colorArray[11] = vec3(34.0 / 255.0, 110.0/255.0, 121.0 / 255.0);\n colorArray[12] = vec3(30.0 / 255.0, 120.0/255.0, 120.0 / 255.0);\n colorArray[13] = vec3(32.0 / 255.0, 132.0/255.0, 117.0 / 255.0);\n colorArray[14] = vec3(36.0 / 255.0, 141.0/255.0, 112.0 / 255.0);\n colorArray[15] = vec3(40.0 / 255.0, 152.0/255.0, 108.0 / 255.0);\n colorArray[16] = vec3(44.0 / 255.0, 161.0/255.0, 101.0 / 255.0);\n colorArray[17] = vec3(52.0 / 255.0, 173.0/255.0, 95.0 / 255.0);\n colorArray[18] = vec3(69.0 / 255.0, 182.0/255.0, 84.0 / 255.0);\n colorArray[19] = vec3(88.0 / 255.0, 191.0/255.0, 72.0 / 255.0);\n colorArray[20] = vec3(109.0 / 255.0, 201.0/255.0, 61.0 / 255.0);\n colorArray[21] = vec3(130.0 / 255.0, 209.0/255.0, 51.0 / 255.0);\n colorArray[22] = vec3(158.0 / 255.0, 213.0/255.0, 45.0 / 255.0);\n colorArray[23] = vec3(189.0 / 255.0, 218.0/255.0, 40.0 / 255.0);\n colorArray[24] = vec3(219.0 / 255.0, 224.0/255.0, 36.0 / 255.0);\n colorArray[25] = vec3(252.0 / 255.0, 228.0/255.0, 30.0 / 255.0);\n\n for (int i = 0; i < colorCount; i++) {\n float distance = sqrt(pow(color.x - colorArray[i].x, 2.0) + pow(color.y - colorArray[i].y, 2.0) + pow(color.z - colorArray[i].z, 2.0));\n if (distance < closestDistance) {\n closestDistance = distance;\n closestColor = i;\n }\n }\n if (closestColor < 3) {\n closestColor = 0;\n }\n\n return float(closestColor);\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 if (encoding == 3.0) {\n decoded = getElevationCanopy(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(r, g, 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.inProgress=[],this.finished=0}merge(e,r){return t(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}=r;if(o){this.inProgress.forEach(t=>t.src=""),this.inProgress=[],this.finished=0;const r=new Set;e.forEach(t=>{r.add(u(ht({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),0===l({r:51,g:0,b:66,a:0})&&(d=3),o.uniform1f(this.encodingUniformLocation,d),st({gl:o,texture:this.outputTexture,imageData:null,format:o.RGBA,width:n,height:a,wrap:o.CLAMP_TO_EDGE,filter:o.NEAREST});const _=o.createFramebuffer();o.bindFramebuffer(o.FRAMEBUFFER,_),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,this.outputTexture,0);const g=o.checkFramebufferStatus(o.FRAMEBUFFER);g!==o.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+g),o.clear(o.COLOR_BUFFER_BIT);const p=Array.from(r).map(r=>t(this,void 0,void 0,function*(){return new Promise((t,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,_);const s=e.filter(t=>r===u(ht({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),g=s.reduce((t,e)=>Math.max(t,e.xOffset),0),p=s.reduce((t,e)=>Math.max(t,e.yOffset),0),x=s.reduce((t,e)=>Math.min(t,e.x),1/0),E=s.reduce((t,e)=>Math.min(t,e.y),1/0),v=s.reduce((t,e)=>Math.max(t,e.x),0),T=s.reduce((t,e)=>Math.max(t,e.y),0),y=s[0].z,A=l/n,b=d/a,R=(g+m)/n,M=(p+m)/a,w=[A,b,R,b,A,M,R,M].map(t=>2*t-1);o.bindBuffer(o.ARRAY_BUFFER,this.tilePositionBuffer),o.bufferData(o.ARRAY_BUFFER,new Float32Array(w),o.STATIC_DRAW),o.enableVertexAttribArray(this.tilePositionAttributeLocation),o.vertexAttribPointer(this.tilePositionAttributeLocation,2,o.FLOAT,!1,0,0);let F=[0,0,1,0,0,1,1,1];const L=Math.pow(2,Math.max(0,y-f)+(h!==m?1:0)),U=514===h?1/h:0,D=1/L,S=x%L/L,P=E%L/L,C=v%L/L,I=T%L/L;F=[S,P,C+D,P,S,I+D,C+D,I+D].map(t=>t*(514===h?512/514:1)+U),o.bindBuffer(o.ARRAY_BUFFER,this.texPositionBuffer),o.bufferData(o.ARRAY_BUFFER,new Float32Array(F),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 B=Math.floor(A*n),N=Math.floor(b*a),O=Math.ceil((R-A)*n),z=Math.ceil((M-b)*a),X=new Uint8Array(4*O*z);o.readPixels(B,N,O,z,o.RGBA,o.UNSIGNED_BYTE,X);for(let t=0;t<X.length;t+=4){const e=(256*X[t+2]+X[t+3])/5;i=Math.max(e,i)}t(null)},c.onerror=e=>{if(c.src!==c.originalSource)return l("new tiles requested");t(null)},c.crossOrigin=s||null,c.src=r,c.originalSource=c.src}).then(()=>{this.finished++,c(this.finished,this.inProgress.length)})}));try{yield Promise.all(p)}catch(t){return console.log(`${p.length} requests aborted`,t),null}return this.inProgress=[],this.outputTexture.maxHeight=i,o.deleteFramebuffer(_),this.outputTexture}throw new Error("Could not get canvas context for merging tile images")})}}return class extends at{constructor(t){super(t),this.id="shademap-layer",this.type="custom",this.canvasSourceId="canvas-source",this.attributionSourceId="attribution-source",this.canvasLayerId="canvas-layer",this.attributionLayerId="attribution-layer",this._refreshing=0,this._raf=0,this.id=this.id+x(),this.canvasSourceId=this.canvasSourceId+x(),this.attributionSourceId=this.attributionSourceId+x(),this.canvasLayerId=this.canvasLayerId+x(),this.attributionLayerId=this.attributionLayerId+x(),this.options.terrainSource.tileSize>256&&(this.options.terrainSource.maxZoom=this.options.terrainSource.maxZoom+1),this._moveEndHandler=()=>{this._map&&this._reset()}}render(t,e){}addTo(t){return t.addLayer(this),this}onAdd(e){this._map=e,this._gl=this._map.painter.context.gl,this._framebuffer=this._gl.createFramebuffer();this._compiledKernel=function(e){const{context:r,setRenderBuffer:o}=e,i=r,n=ut({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 vec2 u_panel_orientation;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 panel_altitude=sun_altitude;float panel_azimuth=sun_azimuth;if(u_panel_orientation.x!=-1.0&&u_panel_orientation.y!=-1.0){panel_altitude=u_panel_orientation.x;panel_azimuth=u_panel_orientation.y;}float px=cos(panel_altitude)*cos(panel_azimuth);float py=cos(panel_altitude)*sin(panel_azimuth);float pz=sin(panel_altitude);float sx=cos(sun_altitude)*cos(sun_azimuth);float sy=cos(sun_altitude)*sin(sun_azimuth);float sz=sin(sun_altitude);float timeInSun=pow(.7,pow(sin(sun_altitude),.678))*sin(sun_altitude)*(1.0/0.7);float intensity_on_panel=max(dot(vec3(px,py,pz),vec3(sx,sy,sz)),0.0)*timeInSun;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,intensity_on_panel/h),mix(green,red,(intensity_on_panel-h)/(1.0-h)),step(h,intensity_on_panel));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"),E=i.getUniformLocation(n,"user_topYCoord"),T=i.getUniformLocation(n,"user_ySize"),y=i.getUniformLocation(n,"user_step"),A=i.getUniformLocation(n,"user_west"),b=i.getUniformLocation(n,"user_dLng"),R=i.getUniformLocation(n,"user_dec"),M=i.getUniformLocation(n,"user_Hi"),w=i.getUniformLocation(n,"user_color"),F=i.getUniformLocation(n,"u_below_canopy"),L=i.getUniformLocation(n,"u_panel_orientation"),U=i.getUniformLocation(n,"user_sunExposureTexture"),D=i.getUniformLocation(n,"user_outputSunExposure"),S=i.getUniformLocation(n,"u_outputShadeProfile"),P=i.getUniformLocation(n,"u_gpxTexture"),C=i.getUniformLocation(n,"u_decHiTexture"),I=i.getUniformLocation(n,"u_sunColor"),B=i.getUniformLocation(n,"u_outputLocationShadeProfile"),N=i.getUniformLocation(n,"u_shadeProfileLocation"),O=i.createTexture();let z=0,X=0,G=0,H=null;const W=()=>{X&&G&&(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!==H&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,H)),o(i,X,G),i.viewport(0,0,X,G),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4))};let j=0,Y=0,Z=0,K="";const k=t=>{const e=(t.endTime-t.startTime)/86400/1e3,r=1440;if(i.activeTexture(i.TEXTURE3),i.uniform1i(C,3),t.startTime!==Y||t.endTime!==Z||t.tzId!==K){Y=t.startTime,Z=t.endTime,K=t.tzId;const o=[],n=828e5,a=v(new Date(Y),K);for(let t=0;t<e;t++){const e=v(new Date(Y+86400*t*1e3+n),K)-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=Y+86400*r*1e3+60*t*1e3,{dec:n,Hi:a}=p(i+o[r]);s[2*(t*e+r)]=-n,s[2*(t*e+r)+1]=a/10}st({gl:i,texture:O,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,O);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:g,west:p,dLng:v,dec:L,Hi:U,cornerClipCoords:D,cornerTextureCoords:S,outputWidth:P,outputHeight:C,belowCanopy:I,skipRender:B}=t;i.useProgram(n),X=P,G=C,H=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(S),i.STATIC_DRAW),i.uniform1f(d,r),i.uniform1f(m,o),i.uniform1f(_,s),i.uniform1f(x,l),i.uniform1f(E,h),i.uniform1f(T,c),i.uniform4fv(w,f),i.uniform1f(y,g),i.uniform1f(A,p),i.uniform1f(b,v),i.uniform1f(R,L),i.uniform1f(M,U),i.uniform1f(F,I?1:0),B||(window.cancelAnimationFrame(z),z=window.requestAnimationFrame(W))},updateDate:t=>{const{dec:e,Hi:r}=t;i.useProgram(n),i.uniform1f(R,e),i.uniform1f(M,r),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(W)},updateDateRange:e=>t(this,void 0,void 0,function*(){const{startDate:t,endDate:r,iterations:o,emit:h}=e;i.useProgram(n);const c=j=Date.now(),f=Math.floor((r.getTime()-t.getTime())/o),d=i.getUniform(n,w),m=X,_=G,p=i.createTexture();i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,p),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 x=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,x);const E=i.COLOR_ATTACHMENT0;i.framebufferTexture2D(i.FRAMEBUFFER,E,i.TEXTURE_2D,p,0);for(let e=0;e<o;e++){if(i.useProgram(n),h("tileloaded",e,o-1),c!==j)return i.deleteFramebuffer(x),i.deleteTexture(p),i.uniform4fv(w,d),!0;yield new Promise((r,h)=>{window.requestAnimationFrame(()=>{i.useProgram(n),null!==H&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,H)),i.bindFramebuffer(i.FRAMEBUFFER,x);const h=i.checkFramebufferStatus(i.FRAMEBUFFER);h!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+h);const{dec:c,Hi:d}=g(new Date(t.getTime()+f*e));i.uniform1f(R,c),i.uniform1f(M,d),i.uniform4fv(w,[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(x),yield new Promise((t,e)=>{window.requestAnimationFrame(()=>{if(i.useProgram(n),c!==j)return i.deleteTexture(p),i.uniform4fv(w,d),void t(!0);i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,p),i.uniform1i(U,2),i.uniform1i(D,1),W(),i.uniform1i(D,0),i.uniform1i(U,0),i.deleteTexture(p),i.uniform4fv(w,d),t(!1)})})}),updateColor:t=>{const{colorVec:e}=t;i.useProgram(n),i.uniform4fv(w,e),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(W)},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,w);i.uniform4fv(w,o),i.uniform4fv(I,a),i.uniform1i(S,1);const m=i.createTexture();i.activeTexture(i.TEXTURE3),st({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 p=i.checkFramebufferStatus(i.FRAMEBUFFER);p!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+p);const x=r.map(t=>[t[0],t[1]]).flat(),E=i.createTexture();i.activeTexture(i.TEXTURE2),st({gl:i,texture:E,imageData:new Float32Array(x),width:x.length/2,height:1,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RG,internalFormat:i.RG32F,type:i.FLOAT}),i.uniform1i(P,2);const v=e.map(t=>{const{dec:e,Hi:r}=g(t);return[-e,r/10]}).flat(),T=i.createTexture();i.activeTexture(i.TEXTURE1),st({gl:i,texture:T,imageData:new Float32Array(v),width:1,height:e.length,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RG,internalFormat:i.RG32F,type:i.FLOAT}),i.uniform1i(C,1),null!==H&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,H)),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 y=new Uint8Array(u*f*4);return i.readPixels(0,0,u,f,i.RGBA,i.UNSIGNED_BYTE,y),i.deleteTexture(m),i.deleteTexture(T),i.deleteTexture(E),i.deleteFramebuffer(_),i.uniform1i(C,0),i.uniform1i(P,0),i.uniform1i(S,0),i.uniform4fv(w,d),i.uniform4fv(I,[0,0,0,0]),y},generateLocationShadeProfile:t=>{i.useProgram(n);const{startTime:e,endTime:r,tzId:o,texCoord:a,shadeColor:u,sunColor:f,panelAltitude:d,panelAzimuth:m}=t,_=i.getUniform(n,w),{outputWidth:g,outputHeight:p}=k({startTime:e,endTime:r,tzId:o});i.uniform4fv(w,u),i.uniform4fv(I,f),i.uniform1i(B,1),i.uniform2fv(N,[a[0],a[1]]),i.uniform2fv(L,[d,m]);const x=i.createTexture();i.activeTexture(i.TEXTURE2),st({gl:i,imageData:null,width:g,height:p,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,texture:x});const E=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,E),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,x,0);const v=i.checkFramebufferStatus(i.FRAMEBUFFER);v!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+v),null!==H&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,H)),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,g,p),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4);const T=new Uint8Array(g*p*4);return i.readPixels(0,0,g,p,i.RGBA,i.UNSIGNED_BYTE,T),i.deleteTexture(x),i.deleteFramebuffer(E),i.uniform1i(C,0),i.uniform1i(B,0),i.uniform4fv(w,_),i.uniform4fv(I,[0,0,0,0]),{output:T,outputWidth:g,outputHeight:p}}}}({context:this._gl,setRenderBuffer:(t,r,o)=>{const i=e.getSource(this.canvasSourceId).texture;t.activeTexture(t.TEXTURE1),i.bind(t.LINEAR,t.CLAMP_TO_EDGE),i.size=[r,o],t.texImage2D(t.TEXTURE_2D,0,t.RGBA,r,o,0,t.RGBA,t.UNSIGNED_BYTE,null),t.bindFramebuffer(t.FRAMEBUFFER,this._framebuffer),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,i.texture,0),t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA)}}),this._tileMerger=new ct(this._gl),this._canopyMerger=new ct(this._gl),this._buildingRasterizer=new lt(this._gl),document.body.appendChild(this._canvas),this._canvas.style.display="none";const r=e.getBounds(),o=r.getNorthWest(),i=r.getNorthEast(),n=r.getSouthEast(),a=r.getSouthWest(),s=[[o.lng,o.lat],[i.lng,i.lat],[n.lng,n.lat],[a.lng,a.lat]];return e.addSource(this.canvasSourceId,{type:"canvas",canvas:this._canvas,coordinates:s,animate:!1}),e.addLayer({id:this.canvasLayerId,type:"raster",source:this.canvasSourceId,paint:{"raster-fade-duration":0}}),e.addSource(this.attributionSourceId,{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[-122.210598,47.769799]}},attribution:'<a href="https://shademap.app/about">© ShadeMap</a>'}),e.addLayer({id:this.attributionLayerId,type:"fill",source:this.attributionSourceId}),this._map.on("moveend",this._moveEndHandler),this._moveEndHandler(),this}onRemove(){return this._map&&(this._map.off("moveend",this._moveEndHandler),this._map.removeLayer(this.attributionLayerId),this._map.removeLayer(this.canvasLayerId),this._map.removeSource(this.attributionSourceId),this._map.removeSource(this.canvasSourceId)),this._gl&&this._framebuffer&&this._gl.deleteFramebuffer(this._framebuffer),document.body.removeChild(this._canvas),this.options.debug("onRemove called"),this}_getHeightMapCoords(t,e){if(this._map&&this._bounds&&this._heightMap){const r=this._map.unproject([t,e]);if(r.toString()===this._map.unproject([t,e+1]).toString())return new i(-1,-1);const{visibleDEMPixelBounds:o,demZoom:n}=this._heightMap;return T(this._map).project(r,n).subtract(o.min)}return new i(-1,-1)}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this._getHeightMapCoords(t,e),o=this.readPixel(r.x,r.y),{startDate:i,endDate:n}=this.options.sunExposure,a=n.getTime()-i.getTime(),s=E(o,.5,a);return Math.abs(s/1e3/3600)}return 0}remove(){this._map&&this._map.removeLayer(this.id)}readPixel(t,e){const r=new Uint8Array(4);if(this._map&&this._gl&&this._framebuffer){const o=this._gl,i=this._map.getSource(this.canvasSourceId).texture;o.activeTexture(o.TEXTURE1),i.bind(o.LINEAR,o.CLAMP_TO_EDGE),o.bindFramebuffer(o.FRAMEBUFFER,this._framebuffer),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,i.texture,0),this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r)}return r}readPixels(t,e,r,o){const i=new Uint8Array(r*o*4);if(this._map&&this._gl&&this._framebuffer){const n=this._gl,a=this._map.getSource(this.canvasSourceId).texture;n.activeTexture(n.TEXTURE1),a.bind(n.LINEAR,n.CLAMP_TO_EDGE),n.bindFramebuffer(n.FRAMEBUFFER,this._framebuffer),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,a.texture,0),this._gl.readPixels(t,e,r,o,this._gl.RGBA,this._gl.UNSIGNED_BYTE,i)}return i}isPositionInSun(e,r){const o=Object.create(null,{isPositionInSun:{get:()=>super.isPositionInSun}});return t(this,void 0,void 0,function*(){const t=this._getHeightMapCoords(e,r);return o.isPositionInSun.call(this,t.x,t.y)})}isPositionInShade(e,r){return t(this,void 0,void 0,function*(){return!(yield this.isPositionInSun(e,r))})}_flush(){if(this._map){this._map.getSource(this.canvasSourceId).fire({type:"data",dataType:"source",sourceDataType:"content"})}super._flush()}_repositionCanvas(t){if(this._map){const e=this._map.getSource(this.canvasSourceId);if(e){const r=t.getNorthWest(),o=t.getNorthEast(),i=t.getSouthEast(),n=t.getSouthWest(),a=[[r.lng,r.lat],[o.lng,o.lat],[i.lng,i.lat],[n.lng,n.lat]];e.setCoordinates(a),super._flush()}}return this}}});
|
|
8
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ShadeMap=e()}(this,function(){"use strict";function t(t,e,r,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 e(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 r(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function i(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var n=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function a(t,e,r){return t instanceof i?t:o(t)?new i(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new i(t.x,t.y):new i(t,e,r)}function s(t,e){if(t)for(var r=e?[t,e]:t,o=0,i=r.length;o<i;o++)this.extend(r[o])}function u(t,e){return!t||t instanceof s?t:new s(t,e)}function l(t,e){if(t)for(var r=e?[t,e]:t,o=0,i=r.length;o<i;o++)this.extend(r[o])}function h(t,e){return t instanceof l?t:new l(t,e)}i.prototype={clone:function(){return new i(this.x,this.y)},add:function(t){return this.clone()._add(a(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(a(t))},_subtract:function(t){return this.x-=t.x,this.y-=t.y,this},divideBy:function(t){return this.clone()._divideBy(t)},_divideBy:function(t){return this.x/=t,this.y/=t,this},multiplyBy:function(t){return this.clone()._multiplyBy(t)},_multiplyBy:function(t){return this.x*=t,this.y*=t,this},scaleBy:function(t){return new i(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new i(this.x/t.x,this.y/t.y)},round:function(){return this.clone()._round()},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},floor:function(){return this.clone()._floor()},_floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.clone()._ceil()},_ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},trunc:function(){return this.clone()._trunc()},_trunc:function(){return this.x=n(this.x),this.y=n(this.y),this},distanceTo:function(t){var e=(t=a(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=a(t)).x===this.x&&t.y===this.y},contains:function(t){return t=a(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+r(this.x)+", "+r(this.y)+")"}},s.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof i||"number"==typeof t[0]||"x"in t)e=r=a(t);else if(e=(t=u(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 a((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return a(this.min.x,this.max.y)},getTopRight:function(){return a(this.max.x,this.min.y)},getTopLeft:function(){return this.min},getBottomRight:function(){return this.max},getSize:function(){return this.max.subtract(this.min)},contains:function(t){var e,r;return(t="number"==typeof t[0]||t instanceof i?a(t):u(t))instanceof s?(e=t.min,r=t.max):e=r=t,e.x>=this.min.x&&r.x<=this.max.x&&e.y>=this.min.y&&r.y<=this.max.y},intersects:function(t){t=u(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=u(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 u(a(e.x-o,e.y-i),a(r.x+o,r.y+i))},equals:function(t){return!!t&&(t=u(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},l.prototype={extend:function(t){var e,r,o=this._southWest,i=this._northEast;if(t instanceof f)e=t,r=t;else{if(!(t instanceof l))return t?this.extend(d(t)||h(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 f(e.lat,e.lng),this._northEast=new f(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 l(new f(e.lat-o,e.lng-i),new f(r.lat+o,r.lng+i))},getCenter:function(){return new f((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 f(this.getNorth(),this.getWest())},getSouthEast:function(){return new f(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 f||"lat"in t?d(t):h(t);var e,r,o=this._southWest,i=this._northEast;return t instanceof l?(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=h(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=h(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=h(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var c=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 s(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(t){var r=this.wrapLng?e(t.lng,this.wrapLng,!0):t.lng;return new f(this.wrapLat?e(t.lat,this.wrapLat,!0):t.lat,r,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 l(new f(n.lat-o,n.lng-i),new f(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 f(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 d(t,e,r){return t instanceof f?t:o(t)&&"object"!=typeof t[0]?3===t.length?new f(t[0],t[1],t[2]):2===t.length?new f(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new f(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new f(t,e,r)}f.prototype={equals:function(t,e){return!!t&&(t=d(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("+r(this.lat,t)+", "+r(this.lng,t)+")"},distanceTo:function(t){return c.distance(this,d(t))},wrap:function(){return c.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return h([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new f(this.lat,this.lng,this.alt)}};const m=256,_=.40909994067971484,g=t=>{const e=t.valueOf();return p(e)},p=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(_),Math.cos(o));return{dec:Math.asin(Math.sin(_)*Math.sin(o)),Hi:(4.889714432387314+6.3003876824396166*e-i)%(2*Math.PI)+2*Math.PI}},x=()=>Math.floor(1e7*Math.random()),E=(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},v=(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()};const T=t=>{const e=()=>!t.getPitch;return{project:(r,o)=>{if(e())return t.project(r,o);{const{lat:t,lng:e}=r;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*m)(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)*m)(t,o))}},unproject:(r,o)=>{return e()?t.unproject(r,o):new f((i=r.y,n=o,a=Math.PI-2*Math.PI*i/m/Math.pow(2,n),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/m/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 l(e,r)}}};class y{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}}function A(t,e,r){r=r||2;var o,i,n,a,s,u,l,h=e&&e.length,c=h?e[0]*r:t.length,f=b(t,0,c,r,!0),d=[];if(!f||f.next===f.prev)return d;if(h&&(f=function(t,e,r,o){var i,n,a,s=[];for(i=0,n=e.length;i<n;i++)(a=b(t,e[i]*o,i<n-1?e[i+1]*o:t.length,o,!1))===a.next&&(a.steiner=!0),s.push(I(a));for(s.sort(D),i=0;i<s.length;i++)r=S(s[i],r);return r}(t,e,f,r)),t.length>80*r){o=n=t[0],i=a=t[1];for(var m=r;m<c;m+=r)(s=t[m])<o&&(o=s),(u=t[m+1])<i&&(i=u),s>n&&(n=s),u>a&&(a=u);l=0!==(l=Math.max(n-o,a-i))?32767/l:0}return M(f,d,r,o,i,l,0),d}function b(t,e,r,o,i){var n,a;if(i===k(t,e,r,o)>0)for(n=e;n<r;n+=o)a=Z(n,t[n],t[n+1],a);else for(n=r-o;n>=e;n-=o)a=Z(n,t[n],t[n+1],a);return a&&z(a,a.next)&&(Y(a),a=a.next),a}function R(t,e){if(!t)return t;e||(e=t);var r,o=t;do{if(r=!1,o.steiner||!z(o,o.next)&&0!==O(o.prev,o,o.next))o=o.next;else{if(Y(o),(o=e=o.prev)===o.next)break;r=!0}}while(r||o!==e);return e}function M(t,e,r,o,i,n,a){if(t){!a&&n&&function(t,e,r,o){var i=t;do{0===i.z&&(i.z=C(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,n);for(var s,u,l=t;t.prev!==t.next;)if(s=t.prev,u=t.next,n?F(t,o,i,n):w(t))e.push(s.i/r|0),e.push(t.i/r|0),e.push(u.i/r|0),Y(t),t=u.next,l=u.next;else if((t=u)===l){a?1===a?M(t=L(R(t),e,r),e,r,o,i,n,2):2===a&&U(t,e,r,o,i,n):M(R(t),e,r,o,i,n,1);break}}}function w(t){var e=t.prev,r=t,o=t.next;if(O(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&&B(i,s,n,u,a,l,m.x,m.y)&&O(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function F(t,e,r,o){var i=t.prev,n=t,a=t.next;if(O(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,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,p=C(d,m,e,r,o),x=C(_,g,e,r,o),E=t.prevZ,v=t.nextZ;E&&E.z>=p&&v&&v.z<=x;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=g&&E!==i&&E!==a&&B(s,h,u,c,l,f,E.x,E.y)&&O(E.prev,E,E.next)>=0)return!1;if(E=E.prevZ,v.x>=d&&v.x<=_&&v.y>=m&&v.y<=g&&v!==i&&v!==a&&B(s,h,u,c,l,f,v.x,v.y)&&O(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;E&&E.z>=p;){if(E.x>=d&&E.x<=_&&E.y>=m&&E.y<=g&&E!==i&&E!==a&&B(s,h,u,c,l,f,E.x,E.y)&&O(E.prev,E,E.next)>=0)return!1;E=E.prevZ}for(;v&&v.z<=x;){if(v.x>=d&&v.x<=_&&v.y>=m&&v.y<=g&&v!==i&&v!==a&&B(s,h,u,c,l,f,v.x,v.y)&&O(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function L(t,e,r){var o=t;do{var i=o.prev,n=o.next.next;!z(i,n)&&X(i,o,o.next,n)&&W(i,n)&&W(n,i)&&(e.push(i.i/r|0),e.push(o.i/r|0),e.push(n.i/r|0),Y(o),Y(o.next),o=t=n),o=o.next}while(o!==t);return R(o)}function U(t,e,r,o,i,n){var a=t;do{for(var s=a.next.next;s!==a.prev;){if(a.i!==s.i&&N(a,s)){var u=j(a,s);return a=R(a,a.next),u=R(u,u.next),M(a,e,r,o,i,n,0),void M(u,e,r,o,i,n,0)}s=s.next}a=a.next}while(a!==t)}function D(t,e){return t.x-e.x}function S(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&&B(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),W(o,t)&&(u<f||u===f&&(o.x>r.x||o.x===r.x&&P(r,o)))&&(r=o,f=u)),o=o.next}while(o!==l);return r}(t,e);if(!r)return e;var o=j(r,t);return R(o,o.next),R(r,r.next)}function P(t,e){return O(t.prev,t,e.prev)<0&&O(e.next,t,t.next)<0}function C(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 I(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 B(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 N(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&&X(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(W(t,e)&&W(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)&&(O(t.prev,t,e.prev)||O(t,e.prev,e))||z(t,e)&&O(t.prev,t,t.next)>0&&O(e.prev,e,e.next)>0)}function O(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function z(t,e){return t.x===e.x&&t.y===e.y}function X(t,e,r,o){var i=H(O(t,e,r)),n=H(O(t,e,o)),a=H(O(r,o,t)),s=H(O(r,o,e));return i!==n&&a!==s||(!(0!==i||!G(t,r,e))||(!(0!==n||!G(t,o,e))||(!(0!==a||!G(r,t,o))||!(0!==s||!G(r,e,o)))))}function G(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 H(t){return t>0?1:t<0?-1:0}function W(t,e){return O(t.prev,t,t.next)<0?O(t,e,t.next)>=0&&O(t,t.prev,e)>=0:O(t,e,t.prev)<0||O(t,t.next,e)<0}function j(t,e){var r=new K(t.i,t.x,t.y),o=new K(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 Z(t,e,r,o){var i=new K(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 Y(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function K(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function k(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 V(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,o=A.flatten(e.coordinates),i=new Float32Array(o.vertices.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})),n=A(o.vertices,o.holes,o.dimensions),a=n.length>256?new Uint16Array(n):new Uint8Array(n),s=function(t){const{height:e=0,levels:r=0,render_height:o=0}=t;if(r)return 3.04*r;return o||e}(r),u=r.highlight||!1;let l=0,h=0,c=0;for(let t=0;t<i.length;t+=2)l+=i[t],h+=i[t+1],c++;return{aPosition:i,cuts:a,buildingHeight:s,centroid:[l/c,h/c],highlight:u}})}A.deviation=function(t,e,r,o){var i=e&&e.length,n=i?e[0]*r:t.length,a=Math.abs(k(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(k(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)},A.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};const q=(t,e)=>{const{lat:r,lng:o}=t;return new i(((t,e)=>(t+180)/360*Math.pow(2,e)*m)(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)*m)(r,e))},$=(t,e)=>{return new f((r=t.y,o=e,i=Math.PI-2*Math.PI*r/m/Math.pow(2,o),180/Math.PI*Math.atan(.5*(Math.exp(i)-Math.exp(-i)))),function(t,e){return t/m/Math.pow(2,e)*360-180}(t.x,e));var r,o,i};let J,Q={heightMapTex:null,width:0,height:0,visibleDEMPixelBounds:new s(new i(0,0),new i(0,0)),DEMPixelBounds:new s(new i(0,0),new i(0,0)),maxHeight:8848,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0};const tt=e=>t(void 0,void 0,void 0,function*(){const{demZoom:r,getFeatures:o,terrainSource:n,canopySource:a,dsmSource:u,tileLoaded:h,gl:c,bounds:f,buildingRasterizer:d,tileMerger:_,canopyMerger:g,forceUpdate:p=!1}=e,{getSourceUrl:x,getElevation:E,maxZoom:v,tileSize:T,_overzoom:y}=n,A=(b={getFeatures:o},t(void 0,void 0,void 0,function*(){const{getFeatures:t}=b;try{return V(yield t())}catch(t){console.log("Error merging buildings",t)}return[]}));var b;try{const t=f,e=t.getNorthWest(),o=t.getSouthEast(),n=new s(q(e,r),q(o,r));let y=new i(n.min.x,n.min.y),b=n.max.x-n.min.x;const R=n.max.y-n.min.y,M=n.max.subtract(n.min);M.y>M.x&&(y.x-=m,b+=512);const w=(t=>{const{upperLeft:e,width:r,height:o}=t,i=e.divideBy(m).floor().multiplyBy(m),n=(Math.ceil(r/m)+1)*m,a=(Math.ceil(o/m)+1)*m,u=i.add([n,a]);return new s(i,u)})({upperLeft:y,width:b,height:R}),{x:F,y:L}=w.max.subtract(w.min),U=(t=>{const{upperLeft:e,width:r,height:o,zoom:i}=t,n=e.divideBy(m).floor(),a=n.x+r/m,s=Math.min(n.y+o/m,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:w.min,width:F,height:L,zoom:r}),D=(t=>{t.sort((t,e)=>t.y!==e.y?t.y-e.y:t.x-e.x);const e=t.reduce((t,e)=>e.x<t.x?e:t).x,r=t.reduce((t,e)=>e.y<t.y?e:t).y;return t.map(t=>{const 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)*m,yOffset:(t.y-r)*m}})})(U),S=n.max.x-n.min.x,P=n.max.y-n.min.y,C=Math.round(S),I=Math.round(P),B=JSON.stringify(D);if(!p&&B===J&&r<v)return Q=Object.assign(Object.assign({},Q),{outputWidth:C,outputHeight:I,visibleDEMPixelBounds:n,demZoom:r,dirty:!0}),Q;const N=[_.merge(D,{maxZoom:v,width:F,height:L,crossOrigin:"Anonymous",getSourceUrl:x,getElevation:E,tileSize:T,tileLoaded:h})];if(void 0!==a){const t=g.merge(D,{maxZoom:a.maxZoom,width:F,height:L,crossOrigin:"Anonymous",getSourceUrl:a.getSourceUrl,getElevation:a.getElevation,tileSize:a.tileSize,tileLoaded:h});N.push(t)}else N.push(new Promise(t=>{const e=c.createTexture();c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,e),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,1,1,0,c.RGBA,c.UNSIGNED_BYTE,new Uint8ClampedArray([0,0,0,0])),t(e)}));const[O,z]=yield Promise.all(N);if(null===O||null===z)return Q=Object.assign(Object.assign({},Q),{visibleDEMPixelBounds:n,demZoom:r,dirty:!1}),Q;const X=new s(q(new l(u.bounds).getNorthWest(),r),q(new l(u.bounds).getSouthEast(),r)),G=X.min.subtract(w.min),H=X.max.subtract(w.min),W=[G.x/F,G.y/L,H.x/F,H.y/L].map(t=>2*t-1),j=yield A,{maxHeight:Z,heightMapTex:Y}=d.raster({upperLeftTile:D[0],width:F,height:L,mapZoom:r,features:j,imageData:O,gl:c,dsmSource:u,dsmCoords:W,canopyData:z}),K=Math.max(u.maxHeight,O.maxHeight+Z);J=B,Q={heightMapTex:Y,maxHeight:K,width:F,height:L,DEMPixelBounds:w,visibleDEMPixelBounds:n,raster:D,demZoom:r,dirty:!0,outputWidth:C,outputHeight:I}}catch(t){console.error("Could not decode height map",t)}return Q}),et=(t,e)=>{const{r:r,g:o,b:i}=t;return[r/255,o/255,i/255,e]},rt=(t,e)=>{const{date:r}=e,{dec:o,Hi:i}=g(r);t.updateDate({dec:o,Hi:i})},ot=(e,r)=>t(void 0,void 0,void 0,function*(){return yield e.updateDateRange(Object.assign({},r))}),it=(t,e)=>{const{color:r,opacity:o}=e,i=et(r,o);t.updateColor({colorVec:i})},nt=t=>{const{kernel:e,map:r,heightMap:o,now:i,color:n,opacity:a,belowCanopy:s,skipRender:u}=t;try{const{heightMapTex:t,outputHeight:h,outputWidth:c,maxHeight:f,width:d,height:_,DEMPixelBounds:p,visibleDEMPixelBounds:x,demZoom:E}=o;if(0===d||0===_)return;const{min:v,max:T}=x;if(!v||!T)return;const{x:y,y:A}=T.subtract(v),b=p.min,R=r.getPixelDimensions(),M=r.screenUnproject([0,0]),w=r.screenUnproject([R.width,0]),F=r.screenUnproject([R.width,R.height]),L=r.screenUnproject([0,R.height]),U=[L,F,M,w].map(t=>r.project(t,E)),D=U.map(t=>[(t.x-b.x)/d,(t.y-b.y)/_]).flat(),S=U.map(t=>[(t.x-v.x)/y,(t.y-v.y)/A]).map(t=>[2*t[0]-1,(2*t[1]-1)*(r.isLeaflet()?-1:1)]).flat(),P=b.y/m/Math.pow(2,E),C=_/m/Math.pow(2,E),I=new l($(p.getTopLeft(),E),$(p.getBottomRight(),E)),B=I.getWest(),N=Math.abs(I.getWest()-I.getEast());((t,e)=>{const{color:r,opacity:o,date:i}=e,n=et(r,o),{dec:a,Hi:s}=g(i);t.updateHeightMap(Object.assign({dec:a,Hi:s,colorVec:n,step:1},e))})(e,{heightMapTex:t,maxHeight:f,width:d,height:_,heightMapZoom:E,cornerTextureCoords:D,cornerClipCoords:S,topYCoord:P,ySize:C,west:B,dLng:N,date:i,color:n,opacity:a,outputHeight:h,outputWidth:c,belowCanopy:s,skipRender:u})}catch(t){console.error("EXCEPTION",t)}};class at extends y{constructor(...e){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}},canopySource:void 0,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 r=e[0];if(this.options=Object.assign(this.options,r),!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(e=>t(this,void 0,void 0,function*(){if(200!==e.status)throw new Error(yield e.text())})).catch(e=>t(this,void 0,void 0,function*(){throw new Error(`Could not load ShadeMap API. Key: ${this.options.apiKey} Error: ${e}`)})),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&&(rt(this._compiledKernel,{date:this.options.date}),this._heightMap&&this._flush())):this._flush(),this}_setDateForTimezone(t,e){let r=0;e&&(r=v(this.options.date)-v(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}setCanopySource(t){return this.options.canopySource=t,delete this._heightMap,this._reset(),this}setDSMSource(t){return this.options.dsmSource=t,delete this._heightMap,this._reset(),this}setSunExposure(e=!1,r){return t(this,void 0,void 0,function*(){if(this.options.sunExposure=Object.assign(Object.assign({},this.options.sunExposure),{enabled:e}),r){const{startDate:t=new Date,endDate:o=new Date,iterations:i=32}=r;this.options.sunExposure={enabled:e,startDate:t,endDate:o,iterations:i}}if(this._map&&this._compiledKernel&&this._heightMap){if(!1===e)rt(this._compiledKernel,{date:this.options.date});else{const{startDate:t,endDate:e,iterations:r}=this.options.sunExposure;if(!(t instanceof Date&&e instanceof Date))throw new Error("Start date or end date or both are missing");if(e.getTime()<t.getTime())throw new Error("End date must come after the start date to calculate sun exposure");if(!0===(yield ot(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._flush()}return this})}_lngLatToTextureCoords(t){if(this._heightMap){const{DEMPixelBounds:e,demZoom:r,width:o,height:i}=this._heightMap,n=e.min;return t.map(t=>{const e=q(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 n=t.getCenter(),a=q(n,e),s=$(new i(a.x-r/2,a.y-o/2),e),u=$(new i(a.x+r/2,a.y+o/2),e);return t.createBounds({nw:s,se:u})}_getDEMZoom(t){const e=Math.min(this.options.terrainSource._overzoom||this.options.terrainSource.maxZoom,t.getZoom());return Math.round(e)}_reset(){return t(this,void 0,void 0,function*(){if(this.options.debug("_reset()"),this._map){const t=T(this._map);let e=this._getDEMZoom(t);try{this._bounds=this._getBounds(t,e)}catch(t){return console.error("Invalid bounds returned: ",t),this}try{if(!t.isLeaflet()&&this._map.getPitch()>45){yield new Promise(t=>{this._map.loaded()?t(!0):this._map.once("idle",function(){t(!0)})});const r=this._map.style._sourceCaches["other:composite"].getVisibleCoordinates().reverse(),o=r.reduce((t,e)=>Math.max(t,e.canonical.z),Number.MIN_SAFE_INTEGER),n=r.filter(t=>t.canonical.z===o).map(t=>t.canonical),[a,s,u,l]=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=$(new i(512*a,512*s),o+1),c=$(new i(512*(u+1),512*(l+1)),o+1);e=o+1,this._bounds=t.createBounds({nw:h,se:c})}}catch(t){console.log("Mapbox tile optimization failed",t)}const r=yield tt({gl:this._gl,demZoom:e,bounds:this._bounds,terrainSource:this.options.terrainSource,canopySource:this.options.canopySource,dsmSource:this.options.dsmSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,canopyMerger:this._canopyMerger,tileLoaded:(t,e)=>this.emit("tileloaded",t,e),forceUpdate:!this._heightMap});this._heightMap=r,r.dirty&&(yield this._draw(r))}return this})}_draw(e){return t(this,void 0,void 0,function*(){if(this.options.debug("_draw()"),this._canvas&&this._compiledKernel&&this._map){if(nt({kernel:this._compiledKernel,map:T(this._map),heightMap:e,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 ot(this._compiledKernel,{startDate:t,endDate:e,iterations:r,emit:this.emit.bind(this)})))return this}this._bounds&&this._repositionCanvas(this._bounds)}return this})}readPixel(t,e){const r=new Uint8Array(4),o=window.innerHeight-e;return this._gl&&this._gl.readPixels(t,o,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}isPositionInSun(e,r){return t(this,void 0,void 0,function*(){const t=this.readPixel(e,r);return 0===t[0]&&0===t[1]&&0===t[2]&&0===t[3]})}isPositionInShade(e,r){return t(this,void 0,void 0,function*(){return!(yield this.isPositionInSun(e,r))})}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=E(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&&!T(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=T(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),r=((t,e)=>{const r=et({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),o=et({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 r}return new Uint8Array}_generateLocationShadeProfile(t){if(this._compiledKernel){const e=v(t.startDate)-v(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=et({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),o=et({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=E(r,.5,n);return Math.abs(a/1e3/3600)}return 0}_repositionCanvas(t){}_flush(){window.requestAnimationFrame(()=>this.emit("idle"))}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}}const st=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 ut(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 lt{constructor(t){this.gl=t,this.program=ut({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 vCoord = normalized;\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;\nuniform bool is_negative;\nuniform sampler2D canopy_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) * (is_negative ? -1.0 : 1.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(1,1,1,1)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n\t \tvec4 canopyColor = texture2D(canopy_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 float upper = textureColor.r + canopyColor.r;\n float combined = textureColor.g + canopyColor.g;\n if (combined > 1.0) {\n combined = combined - floor(combined);\n upper += 1.0 / 255.0;\n }\n gl_FragColor = vec4(textureColor.r, textureColor.g, upper, combined);\n }\n // DSM noData values should not be included in heightMap because they produce ugly borders\n\t\treturn;\n }\n if (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n gl_FragColor = vec4(textureColor.r, textureColor.g, textureColor.r, textureColor.g);\n return;\n }\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.isNegative=t.getUniformLocation(this.program,"is_negative"),this.xyzUniformLocation=t.getUniformLocation(this.program,"xyz"),this.dimensionsUniformLocation=t.getUniformLocation(this.program,"dimensions"),this.heightMapUniformLocation=t.getUniformLocation(this.program,"height_map"),this.canopyMapUniformLocation=t.getUniformLocation(this.program,"canopy_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:a,imageData:s,dsmCoords:u,dsmSource:l,canopyData:h,gl:c}=t,{x:f,y:d,z:_}=r;let g=0;c.useProgram(this.program),c.activeTexture(c.TEXTURE1),c.bindTexture(c.TEXTURE_2D,s),c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,h);const p=n,x=a;c.activeTexture(c.TEXTURE0),c.bindTexture(c.TEXTURE_2D,this.targetTexture),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,p,x,0,c.RGBA,c.UNSIGNED_BYTE,null),o>15&&e.length>5?(c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST)):(c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.LINEAR),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.LINEAR)),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),c.viewport(0,0,p,x);const E=c.createFramebuffer();c.bindFramebuffer(c.FRAMEBUFFER,E);const v=c.COLOR_ATTACHMENT0;c.framebufferTexture2D(c.FRAMEBUFFER,v,c.TEXTURE_2D,this.targetTexture,0),c.disable(c.BLEND),c.bindBuffer(c.ARRAY_BUFFER,this.positionBuffer),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,this.indexBuffer),c.clearColor(0,0,0,0),c.clear(c.COLOR_BUFFER_BIT);const T=f/Math.pow(2,_),y=d/Math.pow(2,_),A=new i(T,y),b=n/m/Math.pow(2,_),R=a/m/Math.pow(2,_);c.uniform3f(this.xyzUniformLocation,T,y,_),c.uniform2f(this.dimensionsUniformLocation,b,R),c.uniform1i(this.heightMapUniformLocation,1),c.uniform1i(this.canopyMapUniformLocation,2),c.uniform1i(this.useDSMUniformLocation,0);const M=new Float32Array([-1,-1,1,-1,-1,1,1,1]);if(c.enableVertexAttribArray(this.positionAttributeLocation),c.bufferData(c.ARRAY_BUFFER,M,c.STATIC_DRAW),c.vertexAttribPointer(this.positionAttributeLocation,2,c.FLOAT,!1,0,0),c.uniform4f(this.colorUniformLocation,1,1,1,1),c.drawArrays(c.TRIANGLE_STRIP,0,4),e.filter(t=>!t.highlight).forEach(t=>{const{buildingHeight:e,aPosition:r,cuts:o,centroid:s,highlight:u}=t,l=new i(s[0],s[1]).subtract(A).unscaleBy(new i(b,R)).scaleBy(new i(n,a)).floor();if(l.x<0||l.y<0||l.x>n||l.y>a)return;const h=l.x/n,f=l.y/a,d=5*Math.abs(e),m=Math.floor(d/255)/255,_=Math.floor(d%255)/255;g=Math.max(g,e),c.uniform2f(this.centroidUniformLocation,h,f),c.uniform1i(this.isNegative,e<0?1:0),c.uniform4f(this.colorUniformLocation,m,_,m,_),c.bufferData(c.ARRAY_BUFFER,r,c.DYNAMIC_DRAW),c.vertexAttribPointer(this.positionAttributeLocation,2,c.FLOAT,!1,0,0),c.bufferData(c.ARRAY_BUFFER,r,c.DYNAMIC_DRAW),c.vertexAttribPointer(this.dsmAttributeLocation,2,c.FLOAT,!1,0,0),c.bufferData(c.ELEMENT_ARRAY_BUFFER,o,c.DYNAMIC_DRAW),c.drawElements(c.TRIANGLES,o.length,o.length>256?c.UNSIGNED_SHORT:c.UNSIGNED_BYTE,0)}),0!==l.data.length){c.activeTexture(c.TEXTURE1);const t=c.createTexture();c.bindTexture(c.TEXTURE_2D,t),c.pixelStorei(c.UNPACK_ALIGNMENT,2),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST),c.texImage2D(c.TEXTURE_2D,0,c.LUMINANCE_ALPHA,l.width,l.height,0,c.LUMINANCE_ALPHA,c.UNSIGNED_BYTE,l.data),c.pixelStorei(c.UNPACK_ALIGNMENT,4);const e=[u[0],u[3],u[2],u[3],u[0],u[1],u[2],u[1]],r=new Float32Array(e);c.enableVertexAttribArray(this.positionAttributeLocation),c.bufferData(c.ARRAY_BUFFER,r,c.STATIC_DRAW),c.vertexAttribPointer(this.positionAttributeLocation,2,c.FLOAT,!1,0,0),c.enableVertexAttribArray(this.dsmAttributeLocation),c.bindBuffer(c.ARRAY_BUFFER,this.dsmBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array([0,1,1,1,0,0,1,0]),c.STATIC_DRAW),c.vertexAttribPointer(this.dsmAttributeLocation,2,c.FLOAT,!1,0,0),c.uniform4f(this.colorUniformLocation,1,1,1,1),c.uniform1i(this.useDSMUniformLocation,1),c.colorMask(!1,!1,!0,!0),c.drawArrays(c.TRIANGLE_STRIP,0,4),c.deleteTexture(t)}return c.colorMask(!0,!0,!0,!0),c.activeTexture(c.TEXTURE1),c.bindTexture(c.TEXTURE_2D,s),c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,h),c.uniform1i(this.useDSMUniformLocation,0),e.filter(t=>t.highlight).forEach(t=>{const{buildingHeight:e,aPosition:r,cuts:o,centroid:s,highlight:u}=t,l=new i(s[0],s[1]).subtract(A).unscaleBy(new i(b,R)).scaleBy(new i(n,a)).floor();if(l.x<0||l.y<0||l.x>n||l.y>a)return;const h=l.x/n,f=l.y/a,d=5*e,m=Math.floor(d/255)/255,_=Math.floor(d%255)/255;g=Math.max(g,e),c.uniform2f(this.centroidUniformLocation,h,f),c.uniform4f(this.colorUniformLocation,m,_,m,_),c.bufferData(c.ARRAY_BUFFER,r,c.DYNAMIC_DRAW),c.vertexAttribPointer(this.positionAttributeLocation,2,c.FLOAT,!1,0,0),c.bufferData(c.ARRAY_BUFFER,r,c.DYNAMIC_DRAW),c.vertexAttribPointer(this.dsmAttributeLocation,2,c.FLOAT,!1,0,0),c.bufferData(c.ELEMENT_ARRAY_BUFFER,o,c.DYNAMIC_DRAW),c.drawElements(c.TRIANGLES,o.length,o.length>256?c.UNSIGNED_SHORT:c.UNSIGNED_BYTE,0)}),c.deleteFramebuffer(E),{maxHeight:g,heightMapTex:this.targetTexture}}}const ht=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===m?i:Math.floor(i/2),y:o===m?n:Math.floor(n/2),z:o===m?a:a-1}};class ct{constructor(t){this.gl=t,this.program=ut({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 #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n #else\n precision mediump float;\n #endif\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 getElevationCanopy(vec4 color) {\n float closestDistance = 1000.0;\n int closestColor = 100;\n const int colorCount = 26;\n vec3 colorArray[colorCount];\n\n colorArray[0] = vec3(51.0 / 255.0, 0, 66.0 / 255.0);\n colorArray[1] = vec3(51.0 / 255.0, 16.0/255.0, 86.0 / 255.0);\n colorArray[2] = vec3(51.0 / 255.0, 24.0/255.0, 86.0 / 255.0);\n colorArray[3] = vec3(51.0 / 255.0, 24.0/255.0, 98.0 / 255.0);\n colorArray[4] = vec3(51.0 / 255.0, 37.0/255.0, 108.0 / 255.0);\n colorArray[5] = vec3(48.0 / 255.0, 47.0/255.0, 114.0 / 255.0);\n colorArray[6] = vec3(44.0 / 255.0, 57.0/255.0, 116.0 / 255.0);\n colorArray[7] = vec3(42.0 / 255.0, 68.0/255.0, 117.0 / 255.0);\n colorArray[8] = vec3(39.0 / 255.0, 79.0/255.0, 120.0 / 255.0);\n colorArray[9] = vec3(37.0 / 255.0, 89.0/255.0, 123.0 / 255.0);\n colorArray[10] = vec3(34.0 / 255.0, 100.0/255.0, 120.0 / 255.0);\n colorArray[11] = vec3(34.0 / 255.0, 110.0/255.0, 121.0 / 255.0);\n colorArray[12] = vec3(30.0 / 255.0, 120.0/255.0, 120.0 / 255.0);\n colorArray[13] = vec3(32.0 / 255.0, 132.0/255.0, 117.0 / 255.0);\n colorArray[14] = vec3(36.0 / 255.0, 141.0/255.0, 112.0 / 255.0);\n colorArray[15] = vec3(40.0 / 255.0, 152.0/255.0, 108.0 / 255.0);\n colorArray[16] = vec3(44.0 / 255.0, 161.0/255.0, 101.0 / 255.0);\n colorArray[17] = vec3(52.0 / 255.0, 173.0/255.0, 95.0 / 255.0);\n colorArray[18] = vec3(69.0 / 255.0, 182.0/255.0, 84.0 / 255.0);\n colorArray[19] = vec3(88.0 / 255.0, 191.0/255.0, 72.0 / 255.0);\n colorArray[20] = vec3(109.0 / 255.0, 201.0/255.0, 61.0 / 255.0);\n colorArray[21] = vec3(130.0 / 255.0, 209.0/255.0, 51.0 / 255.0);\n colorArray[22] = vec3(158.0 / 255.0, 213.0/255.0, 45.0 / 255.0);\n colorArray[23] = vec3(189.0 / 255.0, 218.0/255.0, 40.0 / 255.0);\n colorArray[24] = vec3(219.0 / 255.0, 224.0/255.0, 36.0 / 255.0);\n colorArray[25] = vec3(252.0 / 255.0, 228.0/255.0, 30.0 / 255.0);\n\n for (int i = 0; i < colorCount; i++) {\n float distance = sqrt(pow(color.x - colorArray[i].x, 2.0) + pow(color.y - colorArray[i].y, 2.0) + pow(color.z - colorArray[i].z, 2.0));\n if (distance < closestDistance) {\n closestDistance = distance;\n closestColor = i;\n }\n }\n if (closestColor < 3) {\n closestColor = 0;\n }\n\n return float(closestColor);\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 if (encoding == 3.0) {\n decoded = getElevationCanopy(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(r, g, 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.inProgress=[],this.finished=0}merge(e,r){return t(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}=r;if(o){this.inProgress.forEach(t=>t.src=""),this.inProgress=[],this.finished=0;const r=new Set;e.forEach(t=>{r.add(u(ht({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),0===l({r:51,g:0,b:66,a:0})&&(d=3),o.uniform1f(this.encodingUniformLocation,d),st({gl:o,texture:this.outputTexture,imageData:null,format:o.RGBA,width:n,height:a,wrap:o.CLAMP_TO_EDGE,filter:o.NEAREST});const _=o.createFramebuffer();o.bindFramebuffer(o.FRAMEBUFFER,_),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,this.outputTexture,0);const g=o.checkFramebufferStatus(o.FRAMEBUFFER);g!==o.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+g),o.clear(o.COLOR_BUFFER_BIT);const p=Array.from(r).map(r=>t(this,void 0,void 0,function*(){return new Promise((t,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,_);const s=e.filter(t=>r===u(ht({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),g=s.reduce((t,e)=>Math.max(t,e.xOffset),0),p=s.reduce((t,e)=>Math.max(t,e.yOffset),0),x=s.reduce((t,e)=>Math.min(t,e.x),1/0),E=s.reduce((t,e)=>Math.min(t,e.y),1/0),v=s.reduce((t,e)=>Math.max(t,e.x),0),T=s.reduce((t,e)=>Math.max(t,e.y),0),y=s[0].z,A=l/n,b=d/a,R=(g+m)/n,M=(p+m)/a,w=[A,b,R,b,A,M,R,M].map(t=>2*t-1);o.bindBuffer(o.ARRAY_BUFFER,this.tilePositionBuffer),o.bufferData(o.ARRAY_BUFFER,new Float32Array(w),o.STATIC_DRAW),o.enableVertexAttribArray(this.tilePositionAttributeLocation),o.vertexAttribPointer(this.tilePositionAttributeLocation,2,o.FLOAT,!1,0,0);let F=[0,0,1,0,0,1,1,1];const L=Math.pow(2,Math.max(0,y-f)+(h!==m?1:0)),U=514===h?1/h:0,D=1/L,S=x%L/L,P=E%L/L,C=v%L/L,I=T%L/L;F=[S,P,C+D,P,S,I+D,C+D,I+D].map(t=>t*(514===h?512/514:1)+U),o.bindBuffer(o.ARRAY_BUFFER,this.texPositionBuffer),o.bufferData(o.ARRAY_BUFFER,new Float32Array(F),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 B=Math.floor(A*n),N=Math.floor(b*a),O=Math.ceil((R-A)*n),z=Math.ceil((M-b)*a),X=new Uint8Array(4*O*z);o.readPixels(B,N,O,z,o.RGBA,o.UNSIGNED_BYTE,X);for(let t=0;t<X.length;t+=4){const e=(256*X[t+2]+X[t+3])/5;i=Math.max(e,i)}t(null)},c.onerror=e=>{if(c.src!==c.originalSource)return l("new tiles requested");t(null)},c.crossOrigin=s||null,c.src=r,c.originalSource=c.src}).then(()=>{this.finished++,c(this.finished,this.inProgress.length)})}));try{yield Promise.all(p)}catch(t){return console.log(`${p.length} requests aborted`,t),null}return this.inProgress=[],this.outputTexture.maxHeight=i,o.deleteFramebuffer(_),this.outputTexture}throw new Error("Could not get canvas context for merging tile images")})}}return class extends at{constructor(t){super(t),this.id="shademap-layer",this.type="custom",this.canvasSourceId="canvas-source",this.attributionSourceId="attribution-source",this.canvasLayerId="canvas-layer",this.attributionLayerId="attribution-layer",this._refreshing=0,this._raf=0,this.id=this.id+x(),this.canvasSourceId=this.canvasSourceId+x(),this.attributionSourceId=this.attributionSourceId+x(),this.canvasLayerId=this.canvasLayerId+x(),this.attributionLayerId=this.attributionLayerId+x(),this.options.terrainSource.tileSize>256&&(this.options.terrainSource.maxZoom=this.options.terrainSource.maxZoom+1),this._moveEndHandler=()=>{this._map&&this._reset()}}render(t,e){}addTo(t){return t.addLayer(this),this}onAdd(e){this._map=e,this._gl=this._map.painter.context.gl,this._framebuffer=this._gl.createFramebuffer();this._compiledKernel=function(e){const{context:r,setRenderBuffer:o}=e,i=r,n=ut({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 vec2 u_panel_orientation;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 panel_altitude=sun_altitude;float panel_azimuth=sun_azimuth;if(u_panel_orientation.x!=-1.0&&u_panel_orientation.y!=-1.0){panel_altitude=u_panel_orientation.x;panel_azimuth=u_panel_orientation.y;}float px=cos(panel_altitude)*cos(panel_azimuth);float py=cos(panel_altitude)*sin(panel_azimuth);float pz=sin(panel_altitude);float sx=cos(sun_altitude)*cos(sun_azimuth);float sy=cos(sun_altitude)*sin(sun_azimuth);float sz=sin(sun_altitude);float timeInSun=pow(.7,pow(sin(sun_altitude),.678))*sin(sun_altitude)*(1.0/0.7);float intensity_on_panel=max(dot(vec3(px,py,pz),vec3(sx,sy,sz)),0.0)*timeInSun;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,intensity_on_panel/h),mix(green,red,(intensity_on_panel-h)/(1.0-h)),step(h,intensity_on_panel));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"),E=i.getUniformLocation(n,"user_topYCoord"),T=i.getUniformLocation(n,"user_ySize"),y=i.getUniformLocation(n,"user_step"),A=i.getUniformLocation(n,"user_west"),b=i.getUniformLocation(n,"user_dLng"),R=i.getUniformLocation(n,"user_dec"),M=i.getUniformLocation(n,"user_Hi"),w=i.getUniformLocation(n,"user_color"),F=i.getUniformLocation(n,"u_below_canopy"),L=i.getUniformLocation(n,"u_panel_orientation"),U=i.getUniformLocation(n,"user_sunExposureTexture"),D=i.getUniformLocation(n,"user_outputSunExposure"),S=i.getUniformLocation(n,"u_outputShadeProfile"),P=i.getUniformLocation(n,"u_gpxTexture"),C=i.getUniformLocation(n,"u_decHiTexture"),I=i.getUniformLocation(n,"u_sunColor"),B=i.getUniformLocation(n,"u_outputLocationShadeProfile"),N=i.getUniformLocation(n,"u_shadeProfileLocation"),O=i.createTexture();let z=0,X=0,G=0,H=null;const W=()=>{X&&G&&(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!==H&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,H)),o(i,X,G),i.viewport(0,0,X,G),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4))};let j=0,Z=0,Y=0,K="";const k=t=>{const e=(t.endTime-t.startTime)/86400/1e3,r=1440;if(i.activeTexture(i.TEXTURE3),i.uniform1i(C,3),t.startTime!==Z||t.endTime!==Y||t.tzId!==K){Z=t.startTime,Y=t.endTime,K=t.tzId;const o=[],n=828e5,a=v(new Date(Z),K);for(let t=0;t<e;t++){const e=v(new Date(Z+86400*t*1e3+n),K)-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=Z+86400*r*1e3+60*t*1e3,{dec:n,Hi:a}=p(i+o[r]);s[2*(t*e+r)]=-n,s[2*(t*e+r)+1]=a/10}st({gl:i,texture:O,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,O);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:g,west:p,dLng:v,dec:L,Hi:U,cornerClipCoords:D,cornerTextureCoords:S,outputWidth:P,outputHeight:C,belowCanopy:I,skipRender:B}=t;i.useProgram(n),X=P,G=C,H=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(S),i.STATIC_DRAW),i.uniform1f(d,r),i.uniform1f(m,o),i.uniform1f(_,s),i.uniform1f(x,l),i.uniform1f(E,h),i.uniform1f(T,c),i.uniform4fv(w,f),i.uniform1f(y,g),i.uniform1f(A,p),i.uniform1f(b,v),i.uniform1f(R,L),i.uniform1f(M,U),i.uniform1f(F,I?1:0),B||(window.cancelAnimationFrame(z),z=window.requestAnimationFrame(W))},updateDate:t=>{const{dec:e,Hi:r}=t;i.useProgram(n),i.uniform1f(R,e),i.uniform1f(M,r),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(W)},updateDateRange:e=>t(this,void 0,void 0,function*(){const{startDate:t,endDate:r,iterations:o,emit:h}=e;i.useProgram(n);const c=j=Date.now(),f=Math.floor((r.getTime()-t.getTime())/o),d=i.getUniform(n,w),m=X,_=G,p=i.createTexture();i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,p),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 x=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,x);const E=i.COLOR_ATTACHMENT0;i.framebufferTexture2D(i.FRAMEBUFFER,E,i.TEXTURE_2D,p,0);for(let e=0;e<o;e++){if(i.useProgram(n),h("tileloaded",e,o-1),c!==j)return i.deleteFramebuffer(x),i.deleteTexture(p),i.uniform4fv(w,d),!0;yield new Promise((r,h)=>{window.requestAnimationFrame(()=>{i.useProgram(n),null!==H&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,H)),i.bindFramebuffer(i.FRAMEBUFFER,x);const h=i.checkFramebufferStatus(i.FRAMEBUFFER);h!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+h);const{dec:c,Hi:d}=g(new Date(t.getTime()+f*e));i.uniform1f(R,c),i.uniform1f(M,d),i.uniform4fv(w,[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(x),yield new Promise((t,e)=>{window.requestAnimationFrame(()=>{if(i.useProgram(n),c!==j)return i.deleteTexture(p),i.uniform4fv(w,d),void t(!0);i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,p),i.uniform1i(U,2),i.uniform1i(D,1),W(),i.uniform1i(D,0),i.uniform1i(U,0),i.deleteTexture(p),i.uniform4fv(w,d),t(!1)})})}),updateColor:t=>{const{colorVec:e}=t;i.useProgram(n),i.uniform4fv(w,e),window.cancelAnimationFrame(z),z=window.requestAnimationFrame(W)},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,w);i.uniform4fv(w,o),i.uniform4fv(I,a),i.uniform1i(S,1);const m=i.createTexture();i.activeTexture(i.TEXTURE3),st({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 p=i.checkFramebufferStatus(i.FRAMEBUFFER);p!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+p);const x=r.map(t=>[t[0],t[1]]).flat(),E=i.createTexture();i.activeTexture(i.TEXTURE2),st({gl:i,texture:E,imageData:new Float32Array(x),width:x.length/2,height:1,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RG,internalFormat:i.RG32F,type:i.FLOAT}),i.uniform1i(P,2);const v=e.map(t=>{const{dec:e,Hi:r}=g(t);return[-e,r/10]}).flat(),T=i.createTexture();i.activeTexture(i.TEXTURE1),st({gl:i,texture:T,imageData:new Float32Array(v),width:1,height:e.length,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RG,internalFormat:i.RG32F,type:i.FLOAT}),i.uniform1i(C,1),null!==H&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,H)),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 y=new Uint8Array(u*f*4);return i.readPixels(0,0,u,f,i.RGBA,i.UNSIGNED_BYTE,y),i.deleteTexture(m),i.deleteTexture(T),i.deleteTexture(E),i.deleteFramebuffer(_),i.uniform1i(C,0),i.uniform1i(P,0),i.uniform1i(S,0),i.uniform4fv(w,d),i.uniform4fv(I,[0,0,0,0]),y},generateLocationShadeProfile:t=>{i.useProgram(n);const{startTime:e,endTime:r,tzId:o,texCoord:a,shadeColor:u,sunColor:f,panelAltitude:d,panelAzimuth:m}=t,_=i.getUniform(n,w),{outputWidth:g,outputHeight:p}=k({startTime:e,endTime:r,tzId:o});i.uniform4fv(w,u),i.uniform4fv(I,f),i.uniform1i(B,1),i.uniform2fv(N,[a[0],a[1]]),i.uniform2fv(L,[d,m]);const x=i.createTexture();i.activeTexture(i.TEXTURE2),st({gl:i,imageData:null,width:g,height:p,wrap:i.CLAMP_TO_EDGE,filter:i.NEAREST,format:i.RGBA,texture:x});const E=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,E),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,x,0);const v=i.checkFramebufferStatus(i.FRAMEBUFFER);v!==i.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete: "+v),null!==H&&(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,H)),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,g,p),i.clear(i.COLOR_BUFFER_BIT),i.drawArrays(i.TRIANGLE_STRIP,0,4);const T=new Uint8Array(g*p*4);return i.readPixels(0,0,g,p,i.RGBA,i.UNSIGNED_BYTE,T),i.deleteTexture(x),i.deleteFramebuffer(E),i.uniform1i(C,0),i.uniform1i(B,0),i.uniform4fv(w,_),i.uniform4fv(I,[0,0,0,0]),{output:T,outputWidth:g,outputHeight:p}}}}({context:this._gl,setRenderBuffer:(t,r,o)=>{const i=e.getSource(this.canvasSourceId).texture;t.activeTexture(t.TEXTURE1),i.update({width:r,height:o}),t.bindFramebuffer(t.FRAMEBUFFER,this._framebuffer),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,i.texture,0),t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),this._map&&this._map.triggerRepaint&&this._map.triggerRepaint()}}),this._tileMerger=new ct(this._gl),this._canopyMerger=new ct(this._gl),this._buildingRasterizer=new lt(this._gl),document.body.appendChild(this._canvas),this._canvas.style.display="none";const r=e.getBounds(),o=r.getNorthWest(),i=r.getNorthEast(),n=r.getSouthEast(),a=r.getSouthWest(),s=[[o.lng,o.lat],[i.lng,i.lat],[n.lng,n.lat],[a.lng,a.lat]];return e.addSource(this.canvasSourceId,{type:"canvas",canvas:this._canvas,coordinates:s,animate:!1}),e.addLayer({id:this.canvasLayerId,type:"raster",source:this.canvasSourceId,paint:{"raster-fade-duration":0}}),e.addSource(this.attributionSourceId,{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[-122.210598,47.769799]}},attribution:'<a href="https://shademap.app/about">© ShadeMap</a>'}),e.addLayer({id:this.attributionLayerId,type:"fill",source:this.attributionSourceId}),this._map.on("moveend",this._moveEndHandler),this._moveEndHandler(),this}onRemove(){return this._map&&(this._map.off("moveend",this._moveEndHandler),this._map.removeLayer(this.attributionLayerId),this._map.removeLayer(this.canvasLayerId),this._map.removeSource(this.attributionSourceId),this._map.removeSource(this.canvasSourceId)),this._gl&&this._framebuffer&&this._gl.deleteFramebuffer(this._framebuffer),document.body.removeChild(this._canvas),this.options.debug("onRemove called"),this}_getHeightMapCoords(t,e){if(this._map&&this._bounds&&this._heightMap){const r=this._map.unproject([t,e]);if(r.toString()===this._map.unproject([t,e+1]).toString())return new i(-1,-1);const{visibleDEMPixelBounds:o,demZoom:n}=this._heightMap;return T(this._map).project(r,n).subtract(o.min)}return new i(-1,-1)}getHoursOfSun(t,e){if(this.options.sunExposure.enabled){const r=this._getHeightMapCoords(t,e),o=this.readPixel(r.x,r.y),{startDate:i,endDate:n}=this.options.sunExposure,a=n.getTime()-i.getTime(),s=E(o,.5,a);return Math.abs(s/1e3/3600)}return 0}remove(){this._map&&this._map.removeLayer(this.id)}readPixel(t,e){const r=new Uint8Array(4);if(this._map&&this._gl&&this._framebuffer){const o=this._gl,i=this._map.getSource(this.canvasSourceId).texture;o.activeTexture(o.TEXTURE1),i.bind(o.LINEAR,o.CLAMP_TO_EDGE),o.bindFramebuffer(o.FRAMEBUFFER,this._framebuffer),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,i.texture,0),this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r)}return r}readPixels(t,e,r,o){const i=new Uint8Array(r*o*4);if(this._map&&this._gl&&this._framebuffer){const n=this._gl,a=this._map.getSource(this.canvasSourceId).texture;n.activeTexture(n.TEXTURE1),a.bind(n.LINEAR,n.CLAMP_TO_EDGE),n.bindFramebuffer(n.FRAMEBUFFER,this._framebuffer),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,a.texture,0),this._gl.readPixels(t,e,r,o,this._gl.RGBA,this._gl.UNSIGNED_BYTE,i)}return i}isPositionInSun(e,r){const o=Object.create(null,{isPositionInSun:{get:()=>super.isPositionInSun}});return t(this,void 0,void 0,function*(){const t=this._getHeightMapCoords(e,r);return o.isPositionInSun.call(this,t.x,t.y)})}isPositionInShade(e,r){return t(this,void 0,void 0,function*(){return!(yield this.isPositionInSun(e,r))})}_flush(){if(this._map){this._map.getSource(this.canvasSourceId).fire({type:"data",dataType:"source",sourceDataType:"content"})}super._flush()}_repositionCanvas(t){if(this._map){const e=this._map.getSource(this.canvasSourceId);if(e){const r=t.getNorthWest(),o=t.getNorthEast(),i=t.getSouthEast(),n=t.getSouthWest(),a=[[r.lng,r.lat],[o.lng,o.lat],[i.lng,i.lat],[n.lng,n.lat]];e.setCoordinates(a),super._flush()}}return this}}});
|
package/examples/map.html
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
|
7
7
|
<link
|
|
8
|
-
href="https://api.mapbox.com/mapbox-gl-js/
|
|
8
|
+
href="https://api.mapbox.com/mapbox-gl-js/v3.15.0/mapbox-gl.css"
|
|
9
9
|
rel="stylesheet"
|
|
10
10
|
/>
|
|
11
|
-
<script src="https://api.mapbox.com/mapbox-gl-js/
|
|
11
|
+
<script src="https://api.mapbox.com/mapbox-gl-js/v3.15.0/mapbox-gl.js"></script>
|
|
12
12
|
<script src="https://www.unpkg.com/suncalc@1.9.0/suncalc.js"></script>
|
|
13
13
|
<script src="../dist/mapbox-gl-shadow-simulator.umd.min.js"></script>
|
|
14
14
|
<style>
|
package/examples/maplibre.html
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
<meta charset="UTF-8" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
|
8
|
-
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@
|
|
9
|
-
<script src="https://unpkg.com/maplibre-gl@
|
|
8
|
+
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@5.9.0/dist/maplibre-gl.css" />
|
|
9
|
+
<script src="https://unpkg.com/maplibre-gl@5.9.0/dist/maplibre-gl.js"></script>
|
|
10
10
|
<script src="https://www.unpkg.com/suncalc@1.9.0/suncalc.js"></script>
|
|
11
|
-
<script src="https://unpkg.com/protomaps-themes-base@4.
|
|
11
|
+
<script src="https://unpkg.com/protomaps-themes-base@4.5.0/dist/protomaps-themes-base.js"></script>
|
|
12
12
|
<script src="../dist/mapbox-gl-shadow-simulator.umd.min.js"></script>
|
|
13
13
|
<style>
|
|
14
14
|
body {
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
<meta charset="UTF-8" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
|
8
|
-
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@
|
|
9
|
-
<script src="https://unpkg.com/maplibre-gl@
|
|
8
|
+
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@5.9.0/dist/maplibre-gl.css" />
|
|
9
|
+
<script src="https://unpkg.com/maplibre-gl@5.9.0/dist/maplibre-gl.js"></script>
|
|
10
10
|
<script src="https://www.unpkg.com/suncalc@1.9.0/suncalc.js"></script>
|
|
11
|
-
<script src="https://unpkg.com/protomaps-themes-base@4.
|
|
11
|
+
<script src="https://unpkg.com/protomaps-themes-base@4.5.0/dist/protomaps-themes-base.js"></script>
|
|
12
12
|
<script src="../dist/mapbox-gl-shadow-simulator.umd.min.js"></script>
|
|
13
13
|
<style>
|
|
14
14
|
body {
|
package/examples/markers.html
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
|
7
7
|
<link
|
|
8
|
-
href="https://api.mapbox.com/mapbox-gl-js/
|
|
8
|
+
href="https://api.mapbox.com/mapbox-gl-js/v3.15.0/mapbox-gl.css"
|
|
9
9
|
rel="stylesheet"
|
|
10
10
|
/>
|
|
11
|
-
<script src="https://api.mapbox.com/mapbox-gl-js/
|
|
11
|
+
<script src="https://api.mapbox.com/mapbox-gl-js/v3.15.0/mapbox-gl.js"></script>
|
|
12
12
|
<script src="https://www.unpkg.com/suncalc@1.9.0/suncalc.js"></script>
|
|
13
13
|
<script src="../dist/mapbox-gl-shadow-simulator.umd.min.js"></script>
|
|
14
14
|
<style>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mapbox-gl-shadow-simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.64.0",
|
|
4
4
|
"description": "Display terrain and structure shadows cast by the sun in a custom style layer",
|
|
5
5
|
"main": "dist/mapbox-gl-shadow-simulator.umd.min.js",
|
|
6
6
|
"browser": "dist/mapbox-gl-shadow-simulator.umd.min.js",
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { LatLngLiteral, Map as LeafletMap } from "leaflet";
|
|
2
|
-
import { Map, MapboxGeoJSONFeature } from "mapbox-gl";
|
|
3
|
-
import { BuildingRasterizer } from "./buildings/BuildingRasterizer";
|
|
4
|
-
import { EventEmitter } from "./lib/EventEmitter";
|
|
5
|
-
import { HeightMap } from "./lib/heightMap";
|
|
6
|
-
import { TileMerger } from "./lib/TileMerger";
|
|
7
|
-
import { LatLngBounds } from "./map/geometryLeaflet";
|
|
8
|
-
import { UMap } from "./map/umap";
|
|
9
|
-
import { CompiledKernel } from "./shader/kernel";
|
|
10
|
-
import { Color } from "./types/color";
|
|
11
|
-
import { DSMSource, SunExposureOptions, TerrainSource } from "./types/shadeMapOptions";
|
|
12
|
-
export declare class ShadeMap extends EventEmitter {
|
|
13
|
-
_canvas: HTMLCanvasElement;
|
|
14
|
-
_gl?: WebGLRenderingContext;
|
|
15
|
-
_map?: Map | LeafletMap;
|
|
16
|
-
_compiledKernel?: CompiledKernel;
|
|
17
|
-
_color: Color;
|
|
18
|
-
_bounds?: LatLngBounds;
|
|
19
|
-
_buildingRasterizer?: BuildingRasterizer;
|
|
20
|
-
_tileMerger?: TileMerger;
|
|
21
|
-
_canopyMerger?: TileMerger;
|
|
22
|
-
_heightMap?: HeightMap;
|
|
23
|
-
options: {
|
|
24
|
-
date: Date;
|
|
25
|
-
color: string;
|
|
26
|
-
opacity: number;
|
|
27
|
-
sunExposure: {
|
|
28
|
-
enabled: boolean;
|
|
29
|
-
startDate: Date;
|
|
30
|
-
endDate: Date;
|
|
31
|
-
iterations: number;
|
|
32
|
-
};
|
|
33
|
-
apiKey: string;
|
|
34
|
-
terrainSource: {
|
|
35
|
-
maxZoom: number;
|
|
36
|
-
tileSize: number;
|
|
37
|
-
_overzoom: number;
|
|
38
|
-
getSourceUrl: (params: {
|
|
39
|
-
x: number;
|
|
40
|
-
y: number;
|
|
41
|
-
z: number;
|
|
42
|
-
}) => string;
|
|
43
|
-
getElevation: (params: {
|
|
44
|
-
r: number;
|
|
45
|
-
g: number;
|
|
46
|
-
b: number;
|
|
47
|
-
a: number;
|
|
48
|
-
}) => number;
|
|
49
|
-
};
|
|
50
|
-
canopySource: undefined;
|
|
51
|
-
dsmSource: {
|
|
52
|
-
bounds: {
|
|
53
|
-
lat: number;
|
|
54
|
-
lng: number;
|
|
55
|
-
}[];
|
|
56
|
-
data: Uint8ClampedArray;
|
|
57
|
-
width: number;
|
|
58
|
-
height: number;
|
|
59
|
-
maxHeight: number;
|
|
60
|
-
};
|
|
61
|
-
belowCanopy: boolean;
|
|
62
|
-
getFeatures: () => Promise<MapboxGeoJSONFeature[]>;
|
|
63
|
-
getSize: () => {
|
|
64
|
-
width: number;
|
|
65
|
-
height: number;
|
|
66
|
-
};
|
|
67
|
-
debug: (msg: string) => void;
|
|
68
|
-
};
|
|
69
|
-
constructor(...args: any[]);
|
|
70
|
-
onRemove(): this;
|
|
71
|
-
setDate(date: Date): this;
|
|
72
|
-
_setDateForTimezone(date: Date, tzId?: string): void;
|
|
73
|
-
setColor(color: string): this;
|
|
74
|
-
setOpacity(opacity: number): this;
|
|
75
|
-
setBelowCanopy(belowCanopy: boolean): this;
|
|
76
|
-
setTerrainSource(terrainSource: TerrainSource): this;
|
|
77
|
-
setCanopySource(canopySource: TerrainSource): this;
|
|
78
|
-
setDSMSource(dsmSource: DSMSource): this;
|
|
79
|
-
setSunExposure(enabled?: boolean, options?: SunExposureOptions): Promise<this>;
|
|
80
|
-
_lngLatToTextureCoords(lngLat: LatLngLiteral[]): number[][];
|
|
81
|
-
_getBounds(map: UMap, demZoom: number): LatLngBounds;
|
|
82
|
-
_getDEMZoom(map: UMap): number;
|
|
83
|
-
_reset(): Promise<this>;
|
|
84
|
-
_draw(heightMap: HeightMap): Promise<this>;
|
|
85
|
-
readPixel(x: number, y: number): Uint8Array;
|
|
86
|
-
readPixels(x: number, y: number, width: number, height: number): Uint8Array;
|
|
87
|
-
isPositionInSun(x: number, y: number): Promise<boolean>;
|
|
88
|
-
isPositionInShade(x: number, y: number): Promise<boolean>;
|
|
89
|
-
toGeoTiff(): {
|
|
90
|
-
data: Uint8Array;
|
|
91
|
-
metadata: {
|
|
92
|
-
width: number;
|
|
93
|
-
height: number;
|
|
94
|
-
ModelTiepoint: any[];
|
|
95
|
-
ModelPixelScale: number[];
|
|
96
|
-
GeographicTypeGeoKey: number;
|
|
97
|
-
GeogCitationGeoKey: string;
|
|
98
|
-
};
|
|
99
|
-
} | null;
|
|
100
|
-
_generateShadeProfile(params: {
|
|
101
|
-
locations: LatLngLiteral[];
|
|
102
|
-
dates: Date[];
|
|
103
|
-
sunColor: number[];
|
|
104
|
-
shadeColor: number[];
|
|
105
|
-
}): Uint8Array;
|
|
106
|
-
_generateLocationShadeProfile(params: {
|
|
107
|
-
location: LatLngLiteral;
|
|
108
|
-
startDate: Date;
|
|
109
|
-
endDate: Date;
|
|
110
|
-
sunColor: number[];
|
|
111
|
-
shadeColor: number[];
|
|
112
|
-
tzId: string;
|
|
113
|
-
panelAltitude: number;
|
|
114
|
-
panelAzimuth: number;
|
|
115
|
-
}): {
|
|
116
|
-
data: Uint8Array;
|
|
117
|
-
width: number;
|
|
118
|
-
height: number;
|
|
119
|
-
};
|
|
120
|
-
getHoursOfSun(x: number, y: number): number;
|
|
121
|
-
_repositionCanvas(bounds: LatLngBounds): void;
|
|
122
|
-
_flush(): void;
|
|
123
|
-
flushSync(): void;
|
|
124
|
-
_parseColor(color: string): {
|
|
125
|
-
r: number;
|
|
126
|
-
g: number;
|
|
127
|
-
b: number;
|
|
128
|
-
};
|
|
129
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Map } from "leaflet";
|
|
2
|
-
import { CanvasOverlay } from "./components/CanvasOverlay";
|
|
3
|
-
import { LatLngBounds } from "./map/geometryLeaflet";
|
|
4
|
-
import { ShadeMap } from "./ShadeMap";
|
|
5
|
-
import { ShadeMapOptions } from "./types/shadeMapOptions";
|
|
6
|
-
declare class ShadeMapLeaflet extends ShadeMap {
|
|
7
|
-
_canvasOverlay?: CanvasOverlay;
|
|
8
|
-
constructor(options: ShadeMapOptions);
|
|
9
|
-
addTo(map: Map): this;
|
|
10
|
-
onAdd(map: Map): this;
|
|
11
|
-
_repositionCanvas(bounds: LatLngBounds): void;
|
|
12
|
-
}
|
|
13
|
-
declare module "leaflet" {
|
|
14
|
-
function shadeMap(options: ShadeMapOptions): ShadeMapLeaflet;
|
|
15
|
-
}
|
|
16
|
-
export default ShadeMapLeaflet;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Map } from "mapbox-gl";
|
|
2
|
-
import { LatLngBounds } from "./map/geometryLeaflet";
|
|
3
|
-
import { ShadeMap } from "./ShadeMap";
|
|
4
|
-
import { ShadeMapOptions } from "./types/shadeMapOptions";
|
|
5
|
-
export default class extends ShadeMap {
|
|
6
|
-
id: string;
|
|
7
|
-
type: string;
|
|
8
|
-
canvasSourceId: string;
|
|
9
|
-
attributionSourceId: string;
|
|
10
|
-
canvasLayerId: string;
|
|
11
|
-
attributionLayerId: string;
|
|
12
|
-
_map?: Map;
|
|
13
|
-
_refreshing: number;
|
|
14
|
-
_raf: number;
|
|
15
|
-
_moveEndHandler: () => void;
|
|
16
|
-
_framebuffer?: WebGLFramebuffer;
|
|
17
|
-
constructor(options: ShadeMapOptions);
|
|
18
|
-
render(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
19
|
-
addTo(map: Map): this;
|
|
20
|
-
onAdd(map: Map): this;
|
|
21
|
-
onRemove(): this;
|
|
22
|
-
_getHeightMapCoords(x: number, y: number): any;
|
|
23
|
-
getHoursOfSun(x: number, y: number): number;
|
|
24
|
-
remove(): void;
|
|
25
|
-
readPixel(x: number, y: number): Uint8Array;
|
|
26
|
-
readPixels(x: number, y: number, width: number, height: number): Uint8Array;
|
|
27
|
-
isPositionInSun(x: number, y: number): Promise<boolean>;
|
|
28
|
-
isPositionInShade(x: number, y: number): Promise<boolean>;
|
|
29
|
-
_flush(): void;
|
|
30
|
-
_repositionCanvas(bounds: LatLngBounds): this;
|
|
31
|
-
}
|