leaflet-shadow-simulator 0.26.0 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [ted-piotrowski]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
package/README.md CHANGED
@@ -210,6 +210,35 @@ getFeatures: () => {
210
210
  },
211
211
  ```
212
212
 
213
+ ##### Using overpass turbo to load buildings
214
+
215
+ ```javascript
216
+ getFeatures: async () => {
217
+ if (map.getZoom() > 15) {
218
+ const bounds = map.getBounds();
219
+ const north = bounds.getNorth();
220
+ const south = bounds.getSouth();
221
+ const east = bounds.getEast();
222
+ const west = bounds.getWest();
223
+ const query = `https://overpass-api.de/api/interpreter?data=%2F*%0AThis%20has%20been%20generated%20by%20the%20overpass-turbo%20wizard.%0AThe%20original%20search%20was%3A%0A%E2%80%9Cbuilding%E2%80%9D%0A*%2F%0A%5Bout%3Ajson%5D%5Btimeout%3A25%5D%3B%0A%2F%2F%20gather%20results%0A%28%0A%20%20%2F%2F%20query%20part%20for%3A%20%E2%80%9Cbuilding%E2%80%9D%0A%20%20way%5B%22building%22%5D%28${south}%2C${west}%2C${north}%2C${east}%29%3B%0A%29%3B%0A%2F%2F%20print%20results%0Aout%20body%3B%0A%3E%3B%0Aout%20skel%20qt%3B`;
224
+ const response = await fetch(query)
225
+ const json = await response.json();
226
+ const geojson = osmtogeojson(json);
227
+ // If no building height, default to one storey of 3 meters
228
+ geojson.features.forEach(feature => {
229
+ if (!feature.properties) {
230
+ feature.properties = {};
231
+ }
232
+ if (!feature.properties.height) {
233
+ feature.properties.height = 3;
234
+ }
235
+ });
236
+ return geojson.features;
237
+ }
238
+ return [];
239
+ },
240
+ ```
241
+
213
242
  ### Available functions
214
243
 
215
244
  `setDate(date: Date)` - update shade layer to reflect new `date`
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Copyright Ted Piotrowski 2023
3
3
  * Package: leaflet-shadow-simulator
4
- * Version: 0.26.0
4
+ * Version: 0.29.1
5
5
  * For licensing visit: https://shademap.app/about/
6
6
  */
7
7
 
8
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("leaflet")):"function"==typeof define&&define.amd?define(["leaflet"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).ShadeMap=e(t.L)}(this,(function(t){"use strict";var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,r)};function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e,r,n){return new(r||(r=Promise))((function(i,o){function a(t){try{u(n.next(t))}catch(t){o(t)}}function s(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function a(t,e,r){if(r||2===arguments.length)for(var n,i=0,o=e.length;i<o;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}var s=function(e){function n(t,r,n){void 0===n&&(n={});var i=e.call(this,"",r,n)||this;return i._url=t,i}return r(n,e),n.prototype._initImage=function(){var e="CANVAS"===this._url.tagName,r=this._image=e?this._url:t.DomUtil.create("canvas");return t.DomUtil.addClass(r,"leaflet-image-layer"),this._zoomAnimated&&t.DomUtil.addClass(r,"leaflet-zoom-animated"),this.options.className&&t.DomUtil.addClass(r,this.options.className),r.onselectstart=t.Util.falseFn,r.onmousemove=t.Util.falseFn,this},n}(t.ImageOverlay);function u(t,e,r){var n=e[1],i=e[0],o=n-i;return t===n&&r?t:((t-i)%o+o)%o+i}function l(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}var c=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function h(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var f=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function p(t,e,r){return t instanceof h?t:c(t)?new h(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new h(t.x,t.y):new h(t,e,r)}function d(t,e){if(t)for(var r=e?[t,e]:t,n=0,i=r.length;n<i;n++)this.extend(r[n])}function x(t,e){return!t||t instanceof d?t:new d(t,e)}function m(t,e){if(t)for(var r=e?[t,e]:t,n=0,i=r.length;n<i;n++)this.extend(r[n])}function _(t,e){return t instanceof m?t:new m(t,e)}h.prototype={clone:function(){return new h(this.x,this.y)},add:function(t){return this.clone()._add(p(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(p(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 h(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new h(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=f(this.x),this.y=f(this.y),this},distanceTo:function(t){var e=(t=p(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=p(t)).x===this.x&&t.y===this.y},contains:function(t){return t=p(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+l(this.x)+", "+l(this.y)+")"}},d.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof h||"number"==typeof t[0]||"x"in t)e=r=p(t);else if(e=(t=x(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 p((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return p(this.min.x,this.max.y)},getTopRight:function(){return p(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 h?p(t):x(t))instanceof d?(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=x(t);var e=this.min,r=this.max,n=t.min,i=t.max,o=i.x>=e.x&&n.x<=r.x,a=i.y>=e.y&&n.y<=r.y;return o&&a},overlaps:function(t){t=x(t);var e=this.min,r=this.max,n=t.min,i=t.max,o=i.x>e.x&&n.x<r.x,a=i.y>e.y&&n.y<r.y;return o&&a},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,n=Math.abs(e.x-r.x)*t,i=Math.abs(e.y-r.y)*t;return x(p(e.x-n,e.y-i),p(r.x+n,r.y+i))},equals:function(t){return!!t&&(t=x(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},m.prototype={extend:function(t){var e,r,n=this._southWest,i=this._northEast;if(t instanceof v)e=t,r=t;else{if(!(t instanceof m))return t?this.extend(y(t)||_(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return n||i?(n.lat=Math.min(e.lat,n.lat),n.lng=Math.min(e.lng,n.lng),i.lat=Math.max(r.lat,i.lat),i.lng=Math.max(r.lng,i.lng)):(this._southWest=new v(e.lat,e.lng),this._northEast=new v(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,n=Math.abs(e.lat-r.lat)*t,i=Math.abs(e.lng-r.lng)*t;return new m(new v(e.lat-n,e.lng-i),new v(r.lat+n,r.lng+i))},getCenter:function(){return new v((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 v(this.getNorth(),this.getWest())},getSouthEast:function(){return new v(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 v||"lat"in t?y(t):_(t);var e,r,n=this._southWest,i=this._northEast;return t instanceof m?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=n.lat&&r.lat<=i.lat&&e.lng>=n.lng&&r.lng<=i.lng},intersects:function(t){t=_(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),i=t.getNorthEast(),o=i.lat>=e.lat&&n.lat<=r.lat,a=i.lng>=e.lng&&n.lng<=r.lng;return o&&a},overlaps:function(t){t=_(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),i=t.getNorthEast(),o=i.lat>e.lat&&n.lat<r.lat,a=i.lng>e.lng&&n.lng<r.lng;return o&&a},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=_(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var g=function(t){var e,r,n,i;for(r=1,n=arguments.length;r<n;r++)for(e in i=arguments[r])t[e]=i[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),n=this.scale(e);return this.transformation._transform(r,n)},pointToLatLng:function(t,e){var r=this.scale(e),n=this.transformation.untransform(t,r);return this.projection.unproject(n)},project:function(t){return this.projection.project(t)},unproject:function(t){return this.projection.unproject(t)},scale:function(t){return 256*Math.pow(2,t)},zoom:function(t){return Math.log(t/256)/Math.LN2},getProjectedBounds:function(t){if(this.infinite)return null;var e=this.projection.bounds,r=this.scale(t);return new d(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(t){var e=this.wrapLng?u(t.lng,this.wrapLng,!0):t.lng;return new v(this.wrapLat?u(t.lat,this.wrapLat,!0):t.lat,e,t.alt)},wrapLatLngBounds:function(t){var e=t.getCenter(),r=this.wrapLatLng(e),n=e.lat-r.lat,i=e.lng-r.lng;if(0===n&&0===i)return t;var o=t.getSouthWest(),a=t.getNorthEast();return new m(new v(o.lat-n,o.lng-i),new v(a.lat-n,a.lng-i))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,n=t.lat*r,i=e.lat*r,o=Math.sin((e.lat-t.lat)*r/2),a=Math.sin((e.lng-t.lng)*r/2),s=o*o+Math.cos(n)*Math.cos(i)*a*a,u=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s));return this.R*u}});function v(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 y(t,e,r){return t instanceof v?t:c(t)&&"object"!=typeof t[0]?3===t.length?new v(t[0],t[1],t[2]):2===t.length?new v(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new v(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new v(t,e,r)}v.prototype={equals:function(t,e){return!!t&&(t=y(t),Math.max(Math.abs(this.lat-t.lat),Math.abs(this.lng-t.lng))<=(void 0===e?1e-9:e))},toString:function(t){return"LatLng("+l(this.lat,t)+", "+l(this.lng,t)+")"},distanceTo:function(t){return g.distance(this,y(t))},wrap:function(){return g.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return _([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new v(this.lat,this.lng,this.alt)}};var E=8848,T=256,w=.40909994067971484,R=function(t){var e=t.valueOf()/864e5-10957.5,r=6.240059966692059+.017201969994578018*e,n=r+.017453292519943295*(1.9148*Math.sin(r)+.02*Math.sin(2*r)+3e-4*Math.sin(3*r))+1.796593062783907+Math.PI,i=Math.atan2(Math.sin(n)*Math.cos(w),Math.cos(n));return{dec:Math.asin(Math.sin(w)*Math.sin(n)),Hi:(4.889714432387314+6.3003876824396166*e-i)%(2*Math.PI)+2*Math.PI}},b=function(t,e,r){var n=1/e,i=Math.min(t[0]*n,255),o=Math.min(t[1]*n,255),a=Math.min(t[2]*n,255),s=0;return i+o+a!==0&&(s=i>0?i/255*.5+.5:a>0?.5*(1-a/255):.5),s*r};function A(t){var e=t.gl,r=t.vSrc,n=t.fSrc,i=e.createShader(e.VERTEX_SHADER);e.shaderSource(i,r),e.compileShader(i);var o=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(o,n),e.compileShader(o);var a=e.createProgram();return e.attachShader(a,i),e.attachShader(a,o),e.linkProgram(a),e.getProgramParameter(a,e.LINK_STATUS)||(console.error("Link failed: "+e.getProgramInfoLog(a)),console.error("vs info-log: "+e.getShaderInfoLog(i)),console.error("fs info-log: "+e.getShaderInfoLog(o))),a}function M(t){var e=this,r=t.context,n=A({gl:r,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 a_pos;attribute vec2 a_tex_cropped;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;varying vec2 vXSpace;varying vec2 vYSpace;uniform float user_xStart;uniform float user_yStart;uniform float user_xEnd;uniform float user_yEnd;void main(void){gl_Position=vec4(a_pos,0,1);vec4 textureSpace=gl_Position*0.5+0.5;vTexCoordCropped=a_tex_cropped;vTexCoordFull=vec2(textureSpace);vXSpace=vec2(user_xStart,user_xEnd);vYSpace=vec2(user_yStart,user_yEnd);}",fSrc:"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nprecision lowp int;precision lowp sampler2D;float atan2(float v1,float v2){if(v1==0.0||v2==0.0)return 0.0;return atan(v1,v2);}float _pow(float v1,float v2){if(v2==0.0)return 1.0;return pow(v1,v2);}float integerMod(float x,float y){float res=floor(mod(x,y));return res*(res>floor(y)-1.0 ? 0.0 : 1.0);}float divWithIntCheck(float x,float y){if(floor(x)==x&&floor(y)==y&&integerMod(x,y)==0.0){return float(int(x)/int(y));}return x/y;}float integerCorrectionModulo(float number,float divisor){if(number<0.0){number=abs(number);if(divisor<0.0){divisor=abs(divisor);}return-(number-(divisor*floor(divWithIntCheck(number,divisor))));}if(divisor<0.0){divisor=abs(divisor);}return number-(divisor*floor(divWithIntCheck(number,divisor)));}float getElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*256.0*256.0+result.g*256.0)/5000.0;}vec4 actualColor;void color(float r,float g,float b,float a){actualColor=vec4(r,g,b,a);}void color(float r,float g,float b){color(r,g,b,1.0);}void color(float r){color(r,r,r,1.0);}void color(vec4 color){actualColor=color;}const int LOOP_MAX=1000;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;uniform sampler2D user_a;uniform float user_width;uniform float user_height;uniform float user_maxHeight;uniform float user_zoom;uniform float user_topYCoord;uniform float user_ySize;uniform vec4 user_color;uniform vec4 u_sunColor;uniform float user_step;uniform float user_west;uniform float user_dLng;uniform float user_dec;uniform float user_Hi;uniform sampler2D user_sunExposureTexture;uniform bool user_renderToSunExposureTexture;uniform bool user_outputSunExposure;uniform vec4 user_exposureDelta;uniform bool u_outputShadeProfile;uniform sampler2D u_decHiTexture;uniform sampler2D u_gpxTexture;varying vec2 vXSpace;varying vec2 vYSpace;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=(vXSpace.y-vXSpace.x)*gpx.x+vXSpace.x;user_y=(vYSpace.y-vYSpace.x)*gpx.y+vYSpace.x;}float user_z=getElevationFromSampler2D(user_a,user_x,user_y);float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=user_west+(user_dLng*user_x);float user_H=integerCorrectionModulo((sunHi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(sunDec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(sunDec))+((cos(user_lat)*cos(sunDec))*cos(user_H))));float user_zoom_factor=_pow(2.0,user_zoom);float user_kmPerPixel=divWithIntCheck(156.5430339296875,user_zoom_factor)*abs(cos(user_lat));float user_dx=((-sin(sun_azimuth)*cos(sun_altitude))*user_step)/user_width;float user_dy=((cos(sun_azimuth)*cos(sun_altitude))*user_step)/user_height;float user_dz=((sin(sun_altitude)*user_kmPerPixel)*user_step);float shadow_bias=0.001;float user_lit=1.0;float user_curvature=0.0;float cur_height=0.0;float user_distance=0.0;float user_startX=user_x;float user_startY=user_y;user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;if((abs(1.0)<0.0)){kernelResult=0.0;return;}float minAngle=asin((earthRadiusInKm/(earthRadiusInKm+user_z)))-(user_PI/2.0);if(user_z<0.0||sun_altitude<minAngle){user_lit=0.0;}else{float xIter=ceil(user_dx<0.0 ? abs(user_x/user_dx):(1.0-user_x)/user_dx);float yIter=ceil(user_dy<0.0 ? abs(user_y/user_dy):(1.0-user_y)/user_dy);float zIter=ceil(user_dz<0.0 ? float(LOOP_MAX):(maxHeight-user_z)/user_dz);int iter=int(min(xIter,min(yIter,zIter)));float user_distance=(sqrt(pow(user_dx*user_width,2.0)+pow(user_dy*user_height,2.0))*user_kmPerPixel)/earthRadiusInKm;for(int safeI=0;safeI<LOOP_MAX;safeI++){if(safeI>iter){break;}cur_height=getElevationFromSampler2D(user_a,user_x,user_y);if(cur_height-user_z>shadow_bias){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;vec4 result=texture2D(user_a,vec2(user_x,user_y));if(result.z==1.0){shade_color=vec4(.92941,.4375,.078125,.85);}iter=0;break;}}user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;}}if((user_lit==1.0)){color(u_sunColor);}else{color(shade_color);}if(user_renderToSunExposureTexture){vec4 aggregateColor=texture2D(user_sunExposureTexture,vec2(vTexCoordFull.x,vTexCoordFull.y));if((user_lit==1.0)){color(aggregateColor.r,0.0,0.0,1.0);}else{color(aggregateColor.r+user_exposureDelta.r,0.0,0.0,1.0);}if(user_outputSunExposure){float timeInSun=1.0-aggregateColor.r;float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,0.5);}}}void main(void){kernel();gl_FragColor=actualColor;}"});r.useProgram(n);var a=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,a);var s=new Float32Array([-1,-1,1,-1,-1,1,1,1]);r.bufferData(r.ARRAY_BUFFER,s,r.STATIC_DRAW);var u=r.getAttribLocation(n,"a_pos");r.enableVertexAttribArray(u),r.vertexAttribPointer(u,2,r.FLOAT,!1,0,0);var l=r.getAttribLocation(n,"a_tex_cropped"),c=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,c);var h=new Float32Array([-1,-1,1,-1,-1,1,1,1]);r.bufferData(r.ARRAY_BUFFER,h,r.STATIC_DRAW),r.enableVertexAttribArray(l),r.vertexAttribPointer(l,2,r.FLOAT,!1,0,0),r.enable(r.BLEND),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA);var f=r.getUniformLocation(n,"user_a");r.uniform1i(f,0);var p=r.getUniformLocation(n,"user_width"),d=r.getUniformLocation(n,"user_height"),x=r.getUniformLocation(n,"user_maxHeight"),m=r.getUniformLocation(n,"user_zoom"),_=r.getUniformLocation(n,"user_topYCoord"),g=r.getUniformLocation(n,"user_ySize"),v=r.getUniformLocation(n,"user_step"),y=r.getUniformLocation(n,"user_west"),E=r.getUniformLocation(n,"user_dLng"),T=r.getUniformLocation(n,"user_dec"),w=r.getUniformLocation(n,"user_Hi"),b=r.getUniformLocation(n,"user_color"),M=r.getUniformLocation(n,"user_xStart"),U=r.getUniformLocation(n,"user_yStart"),L=r.getUniformLocation(n,"user_xEnd"),D=r.getUniformLocation(n,"user_yEnd"),P=r.getUniformLocation(n,"user_sunExposureTexture");r.uniform1i(P,2);var S=r.getUniformLocation(n,"user_renderToSunExposureTexture"),C=r.getUniformLocation(n,"user_outputSunExposure"),I=r.getUniformLocation(n,"user_exposureDelta"),F=r.getUniformLocation(n,"u_outputShadeProfile"),B=r.getUniformLocation(n,"u_gpxTexture"),X=r.getUniformLocation(n,"u_decHiTexture"),N=r.getUniformLocation(n,"u_sunColor"),z=function(){r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4)},O=0;return{updateLocation:function(t){var e=t.width,i=t.height,o=t.maxHeight,s=t.heightMapZoom,h=t.topYCoord,f=t.ySize,R=t.colorVec,A=t.step,M=t.west,U=t.dLng,L=t.dec,D=t.Hi,P=t.cornerClipCoords,S=t.cornerTextureCoords;r.useProgram(n),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindBuffer(r.ARRAY_BUFFER,a),r.bufferData(r.ARRAY_BUFFER,new Float32Array(P),r.STATIC_DRAW),r.vertexAttribPointer(u,2,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,c),r.bufferData(r.ARRAY_BUFFER,new Float32Array(S),r.STATIC_DRAW),r.vertexAttribPointer(l,2,r.FLOAT,!1,0,0),r.uniform1f(p,e),r.uniform1f(d,i),r.uniform1f(x,o),r.uniform1f(m,s),r.uniform1f(_,h),r.uniform1f(g,f),r.uniform4fv(b,R),r.uniform1f(v,A),r.uniform1f(y,M),r.uniform1f(E,U),r.uniform1f(T,L),r.uniform1f(w,D),window.requestAnimationFrame(z)},updateViewport:function(t){var e=t.xStart,n=t.yStart,i=t.xEnd,o=t.yEnd;r.uniform1f(M,e),r.uniform1f(U,n),r.uniform1f(L,i),r.uniform1f(D,o),window.requestAnimationFrame(z)},updateDate:function(t){var e=t.dec,n=t.Hi;r.uniform1f(T,e),r.uniform1f(w,n),window.requestAnimationFrame(z)},updateDateRange:function(t){return i(e,void 0,void 0,(function(){var e,n,i,a,s,u,l,c,h,f,p,d,x,m,_;return o(this,(function(g){switch(g.label){case 0:e=t.startDate,n=t.endDate,i=t.iterations,a=t.emit,s=O=Date.now(),r.uniform4fv(I,new Float32Array([1/i,0,0,0])),u=Math.floor((n.getTime()-e.getTime())/i),l=r.canvas.width,c=r.canvas.height,h=r.createTexture(),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,h),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,l,c,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),f=r.createTexture(),r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,f),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,l,c,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.uniform1i(S,1),p=r.createFramebuffer(),r.bindFramebuffer(r.FRAMEBUFFER,p),d=r.COLOR_ATTACHMENT0,r.viewport(0,0,l,c),x=function(t){return o(this,(function(n){switch(n.label){case 0:return a("tileloaded",t,i-1),s!==O?[2,{value:!0}]:[4,new Promise((function(n,i){window.requestAnimationFrame((function(){t%2==0?(r.uniform1i(P,2),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,h),r.framebufferTexture2D(r.FRAMEBUFFER,d,r.TEXTURE_2D,h,0)):(r.uniform1i(P,1),r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,f),r.framebufferTexture2D(r.FRAMEBUFFER,d,r.TEXTURE_2D,f,0));var i=R(new Date(e.getTime()+u*t)),o=i.dec,a=i.Hi;r.uniform1f(T,o),r.uniform1f(w,a),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4),n()}))}))];case 1:return n.sent(),[2]}}))},m=0,g.label=1;case 1:return m<i?[5,x(m)]:[3,4];case 2:if("object"==typeof(_=g.sent()))return[2,_.value];g.label=3;case 3:return m++,[3,1];case 4:return[4,new Promise((function(t,e){window.requestAnimationFrame((function(){s!==O&&t(!0),r.bindFramebuffer(r.FRAMEBUFFER,null),r.uniform1i(P,i%2==0?2:1),r.uniform1i(C,1),z(),r.uniform1i(S,0),r.uniform1i(C,0),r.deleteFramebuffer(p),r.deleteTexture(h),r.deleteTexture(f),t(!1)}))}))];case 5:return[2,g.sent()]}}))}))},updateColor:function(t){var e=t.colorVec;r.uniform4fv(b,e),window.requestAnimationFrame(z)},updateMaxHeight:function(t){var e=t.maxHeight;r.uniform1f(x,e)},generateShadeProfile:function(t){if(null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");var e=t.dates,i=t.pixels,o=t.shadeColor,a=t.sunColor;if(i.length%2!=0)throw new Error("Pixels array must have 2 numbers per coordinate");var s=i.map((function(t,e){return e%2==0?t/window.innerWidth:t/window.innerHeight})),u=i.length/2,l=e.length,c=r.getParameter(r.VIEWPORT),h=r.getUniform(n,b);r.uniform4fv(b,o),r.uniform4fv(N,a),r.uniform1i(F,1);var f=r.createTexture();r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,f);var p=s.map((function(t,e){return e%2==0?t:[t,0,0]})).flat();r.texImage2D(r.TEXTURE_2D,0,r.RGBA,p.length/4,1,0,r.RGBA,r.FLOAT,new Float32Array(p)),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.uniform1i(B,2);var d=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,d);var x=e.map((function(t){var e=R(t);return[-e.dec,e.Hi/10,0,0]})).flat();r.texImage2D(r.TEXTURE_2D,0,r.RGBA,1,e.length,0,r.RGBA,r.FLOAT,new Float32Array(x)),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.uniform1i(X,1),r.viewport(0,0,u,l),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4);var m=new Uint8Array(u*l*4);return r.readPixels(0,0,u,l,r.RGBA,r.UNSIGNED_BYTE,m),r.deleteTexture(d),r.deleteTexture(f),r.uniform1i(X,0),r.uniform1i(B,0),r.uniform1i(F,0),r.viewport(c[0],c[1],c[2],c[3]),r.uniform4fv(b,h),r.uniform4fv(N,[0,0,0,0]),m}}}var U=function(){function t(t){this.gl=t,this.program=A({gl:t,vSrc:"\nuniform vec3 xyz;\nuniform vec2 dimensions;\nattribute vec2 a_position;\nfloat PI = 3.141592653589793;\nvarying vec2 vCoord;\n\n\tvoid main() {\n\t\tif (abs(a_position) == vec2(1,1)) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = a_position * 0.5 + 0.5;\n\t\t\treturn;\n\t\t}\n\t\tfloat x = ((a_position.x + 180.0) / 360.0 * pow(2.0, xyz.z)) * 256.0 - xyz.x;\n\t\tfloat y = (1.0 - (log(a_position.y) / PI)) / 2.0 * pow(2.0, xyz.z) * 256.0 - xyz.y;\n\t\tvec2 transformed = vec2(x, y);\n\t\tvec2 normalized = transformed / dimensions;\n\t\tvec2 final = normalized * 2.0 - 1.0;\n\t\tgl_Position = vec4(final, 0, 1);\n\t}\n",fSrc:"\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform vec4 color;\nuniform sampler2D height_map;\nvarying vec2 vCoord;\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n\t \tgl_FragColor = vec4(textureColor.b, textureColor.a, 0, 1.0);\n\t\treturn;\n\t} \n\tgl_FragColor = color;\n}\n"}),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.xyzUniformLocation=t.getUniformLocation(this.program,"xyz"),this.dimensionsUniformLocation=t.getUniformLocation(this.program,"dimensions"),this.heightMapUniformLocation=t.getUniformLocation(this.program,"height_map"),this.colorUniformLocation=t.getUniformLocation(this.program,"color"),this.positionBuffer=t.createBuffer(),this.indexBuffer=t.createBuffer(),this.targetTexture=t.createTexture()}return t.prototype.raster=function(t){var e=this,r=t.features,n=t.upperLeftTile,i=t.map,o=t.width,a=t.height,s=t.imageData,u=t.gl,l=n.x,c=n.y,f=n.z,p=0;u.useProgram(this.program),u.activeTexture(u.TEXTURE1);var d=u.createTexture();u.bindTexture(u.TEXTURE_2D,d),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texImage2D(u.TEXTURE_2D,0,u.LUMINANCE_ALPHA,o,a,0,u.LUMINANCE_ALPHA,u.UNSIGNED_BYTE,s);var x=o,m=a;u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,this.targetTexture),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,x,m,0,u.RGBA,u.UNSIGNED_BYTE,null),i.getZoom()>15&&r.length>5?(u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST)):(u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.LINEAR)),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.viewport(0,0,x,m);var _=u.createFramebuffer();u.bindFramebuffer(u.FRAMEBUFFER,_);var g=u.COLOR_ATTACHMENT0;u.framebufferTexture2D(u.FRAMEBUFFER,g,u.TEXTURE_2D,this.targetTexture,0),u.bindBuffer(u.ARRAY_BUFFER,this.positionBuffer),u.bindBuffer(u.ELEMENT_ARRAY_BUFFER,this.indexBuffer),u.clearColor(0,0,0,0),u.clear(u.COLOR_BUFFER_BIT);var v=l*T,y=c*T,E=new h(v,y);u.uniform3f(this.xyzUniformLocation,v,y,f),u.uniform2f(this.dimensionsUniformLocation,o,a),u.uniform1i(this.heightMapUniformLocation,1);var w=new Float32Array([-1,-1,1,-1,-1,1,1,1]);return u.enableVertexAttribArray(this.positionAttributeLocation),u.bufferData(u.ARRAY_BUFFER,w,u.STATIC_DRAW),u.vertexAttribPointer(this.positionAttributeLocation,2,u.FLOAT,!1,0,0),u.uniform4f(this.colorUniformLocation,0,0,0,0),u.drawArrays(u.TRIANGLE_STRIP,0,4),r.forEach((function(t){var r=t.buildingHeight,n=t.aPosition,l=t.cuts,c=t.startPos,h=t.highlight,d=i.project({lng:c[0],lat:c[1]},f).subtract(E).floor();if(!(d.x<0||d.y<0||d.x>o||d.y>a)){var x=256*s[d.y*o*2+2*d.x]+s[d.y*o*2+2*d.x+1]+5*r,m=Math.floor(x/256)/256,_=Math.floor(x%256)/256;p=Math.max(p,x/5),u.uniform4f(e.colorUniformLocation,m,_,h?1:0,1),u.bufferData(u.ARRAY_BUFFER,n,u.DYNAMIC_DRAW),u.vertexAttribPointer(e.positionAttributeLocation,2,u.FLOAT,!1,0,0),u.bufferData(u.ELEMENT_ARRAY_BUFFER,l,u.DYNAMIC_DRAW),u.drawElements(u.TRIANGLES,l.length,l.length>256?u.UNSIGNED_SHORT:u.UNSIGNED_BYTE,0)}})),u.deleteFramebuffer(_),u.deleteTexture(d),p},t}(),L=function(){function t(){this.events={}}return t.prototype.on=function(t,e){var r=this;return"object"!=typeof this.events[t]&&(this.events[t]=[]),this.events[t].push(e),function(){return r.removeListener(t,e)}},t.prototype.removeListener=function(t,e){if("object"==typeof this.events[t]){var r=this.events[t].indexOf(e);r>-1&&this.events[t].splice(r,1)}},t.prototype.removeAllListeners=function(){var t=this;Object.keys(this.events).forEach((function(e){return t.events[e].splice(0,t.events[e].length)}))},t.prototype.emit=function(t){for(var e=this,r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];"object"==typeof this.events[t]&&a([],this.events[t]).forEach((function(t){return t.apply(e,r)}))},t.prototype.once=function(t,e){var r=this,n=this.on(t,(function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];n(),e.apply(r,t)}));return n},t}();function D(t,e,r){r=r||2;var n,i,o,a,s,u,l,c=e&&e.length,h=c?e[0]*r:t.length,f=P(t,0,h,r,!0),p=[];if(!f||f.next===f.prev)return p;if(c&&(f=function(t,e,r,n){var i,o,a,s=[];for(i=0,o=e.length;i<o;i++)(a=P(t,e[i]*n,i<o-1?e[i+1]*n:t.length,n,!1))===a.next&&(a.steiner=!0),s.push(W(a));for(s.sort(N),i=0;i<s.length;i++)r=z(s[i],r);return r}(t,e,f,r)),t.length>80*r){n=o=t[0],i=a=t[1];for(var d=r;d<h;d+=r)(s=t[d])<n&&(n=s),(u=t[d+1])<i&&(i=u),s>o&&(o=s),u>a&&(a=u);l=0!==(l=Math.max(o-n,a-i))?32767/l:0}return C(f,p,r,n,i,l,0),p}function P(t,e,r,n,i){var o,a;if(i===et(t,e,r,n)>0)for(o=e;o<r;o+=n)a=$(o,t[o],t[o+1],a);else for(o=r-n;o>=e;o-=n)a=$(o,t[o],t[o+1],a);return a&&Y(a,a.next)&&(Q(a),a=a.next),a}function S(t,e){if(!t)return t;e||(e=t);var r,n=t;do{if(r=!1,n.steiner||!Y(n,n.next)&&0!==Z(n.prev,n,n.next))n=n.next;else{if(Q(n),(n=e=n.prev)===n.next)break;r=!0}}while(r||n!==e);return e}function C(t,e,r,n,i,o,a){if(t){!a&&o&&function(t,e,r,n){var i=t;do{0===i.z&&(i.z=H(i.x,i.y,e,r,n)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next}while(i!==t);i.prevZ.nextZ=null,i.prevZ=null,function(t){var e,r,n,i,o,a,s,u,l=1;do{for(r=t,t=null,o=null,a=0;r;){for(a++,n=r,s=0,e=0;e<l&&(s++,n=n.nextZ);e++);for(u=l;s>0||u>0&&n;)0!==s&&(0===u||!n||r.z<=n.z)?(i=r,r=r.nextZ,s--):(i=n,n=n.nextZ,u--),o?o.nextZ=i:t=i,i.prevZ=o,o=i;r=n}o.nextZ=null,l*=2}while(a>1)}(i)}(t,n,i,o);for(var s,u,l=t;t.prev!==t.next;)if(s=t.prev,u=t.next,o?F(t,n,i,o):I(t))e.push(s.i/r|0),e.push(t.i/r|0),e.push(u.i/r|0),Q(t),t=u.next,l=u.next;else if((t=u)===l){a?1===a?C(t=B(S(t),e,r),e,r,n,i,o,2):2===a&&X(t,e,r,n,i,o):C(S(t),e,r,n,i,o,1);break}}}function I(t){var e=t.prev,r=t,n=t.next;if(Z(e,r,n)>=0)return!1;for(var i=e.x,o=r.x,a=n.x,s=e.y,u=r.y,l=n.y,c=i<o?i<a?i:a:o<a?o:a,h=s<u?s<l?s:l:u<l?u:l,f=i>o?i>a?i:a:o>a?o:a,p=s>u?s>l?s:l:u>l?u:l,d=n.next;d!==e;){if(d.x>=c&&d.x<=f&&d.y>=h&&d.y<=p&&G(i,s,o,u,a,l,d.x,d.y)&&Z(d.prev,d,d.next)>=0)return!1;d=d.next}return!0}function F(t,e,r,n){var i=t.prev,o=t,a=t.next;if(Z(i,o,a)>=0)return!1;for(var s=i.x,u=o.x,l=a.x,c=i.y,h=o.y,f=a.y,p=s<u?s<l?s:l:u<l?u:l,d=c<h?c<f?c:f:h<f?h:f,x=s>u?s>l?s:l:u>l?u:l,m=c>h?c>f?c:f:h>f?h:f,_=H(p,d,e,r,n),g=H(x,m,e,r,n),v=t.prevZ,y=t.nextZ;v&&v.z>=_&&y&&y.z<=g;){if(v.x>=p&&v.x<=x&&v.y>=d&&v.y<=m&&v!==i&&v!==a&&G(s,c,u,h,l,f,v.x,v.y)&&Z(v.prev,v,v.next)>=0)return!1;if(v=v.prevZ,y.x>=p&&y.x<=x&&y.y>=d&&y.y<=m&&y!==i&&y!==a&&G(s,c,u,h,l,f,y.x,y.y)&&Z(y.prev,y,y.next)>=0)return!1;y=y.nextZ}for(;v&&v.z>=_;){if(v.x>=p&&v.x<=x&&v.y>=d&&v.y<=m&&v!==i&&v!==a&&G(s,c,u,h,l,f,v.x,v.y)&&Z(v.prev,v,v.next)>=0)return!1;v=v.prevZ}for(;y&&y.z<=g;){if(y.x>=p&&y.x<=x&&y.y>=d&&y.y<=m&&y!==i&&y!==a&&G(s,c,u,h,l,f,y.x,y.y)&&Z(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function B(t,e,r){var n=t;do{var i=n.prev,o=n.next.next;!Y(i,o)&&K(i,n,n.next,o)&&V(i,o)&&V(o,i)&&(e.push(i.i/r|0),e.push(n.i/r|0),e.push(o.i/r|0),Q(n),Q(n.next),n=t=o),n=n.next}while(n!==t);return S(n)}function X(t,e,r,n,i,o){var a=t;do{for(var s=a.next.next;s!==a.prev;){if(a.i!==s.i&&j(a,s)){var u=J(a,s);return a=S(a,a.next),u=S(u,u.next),C(a,e,r,n,i,o,0),void C(u,e,r,n,i,o,0)}s=s.next}a=a.next}while(a!==t)}function N(t,e){return t.x-e.x}function z(t,e){var r=function(t,e){var r,n=e,i=t.x,o=t.y,a=-1/0;do{if(o<=n.y&&o>=n.next.y&&n.next.y!==n.y){var s=n.x+(o-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(s<=i&&s>a&&(a=s,r=n.x<n.next.x?n:n.next,s===i))return r}n=n.next}while(n!==e);if(!r)return null;var u,l=r,c=r.x,h=r.y,f=1/0;n=r;do{i>=n.x&&n.x>=c&&i!==n.x&&G(o<h?i:a,o,c,h,o<h?a:i,o,n.x,n.y)&&(u=Math.abs(o-n.y)/(i-n.x),V(n,t)&&(u<f||u===f&&(n.x>r.x||n.x===r.x&&O(r,n)))&&(r=n,f=u)),n=n.next}while(n!==l);return r}(t,e);if(!r)return e;var n=J(r,t);return S(n,n.next),S(r,r.next)}function O(t,e){return Z(t.prev,t,e.prev)<0&&Z(e.next,t,t.next)<0}function H(t,e,r,n,i){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*i|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-n)*i|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function W(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 G(t,e,r,n,i,o,a,s){return(i-a)*(e-s)>=(t-a)*(o-s)&&(t-a)*(n-s)>=(r-a)*(e-s)&&(r-a)*(o-s)>=(i-a)*(n-s)}function j(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&&K(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(V(t,e)&&V(e,t)&&function(t,e){var r=t,n=!1,i=(t.x+e.x)/2,o=(t.y+e.y)/2;do{r.y>o!=r.next.y>o&&r.next.y!==r.y&&i<(r.next.x-r.x)*(o-r.y)/(r.next.y-r.y)+r.x&&(n=!n),r=r.next}while(r!==t);return n}(t,e)&&(Z(t.prev,t,e.prev)||Z(t,e.prev,e))||Y(t,e)&&Z(t.prev,t,t.next)>0&&Z(e.prev,e,e.next)>0)}function Z(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function Y(t,e){return t.x===e.x&&t.y===e.y}function K(t,e,r,n){var i=q(Z(t,e,r)),o=q(Z(t,e,n)),a=q(Z(r,n,t)),s=q(Z(r,n,e));return i!==o&&a!==s||(!(0!==i||!k(t,r,e))||(!(0!==o||!k(t,n,e))||(!(0!==a||!k(r,t,n))||!(0!==s||!k(r,e,n)))))}function k(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 q(t){return t>0?1:t<0?-1:0}function V(t,e){return Z(t.prev,t,t.next)<0?Z(t,e,t.next)>=0&&Z(t,t.prev,e)>=0:Z(t,e,t.prev)<0||Z(t,t.next,e)<0}function J(t,e){var r=new tt(t.i,t.x,t.y),n=new tt(e.i,e.x,e.y),i=t.next,o=e.prev;return t.next=e,e.prev=t,r.next=i,i.prev=r,n.next=r,r.prev=n,o.next=n,n.prev=o,n}function $(t,e,r,n){var i=new tt(t,e,r);return n?(i.next=n.next,i.prev=n,n.next.prev=i,n.next=i):(i.prev=i,i.next=i),i}function Q(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function tt(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 et(t,e,r,n){for(var i=0,o=e,a=r-n;o<r;o+=n)i+=(t[a]-t[o])*(t[o+1]+t[a+1]),a=o;return i}function rt(t,e){return t.filter((function(t){return"MultiPolygon"===t.geometry.type})).forEach((function(e){var r=e.geometry;if(e.properties,e.type,"MultiPolygon"===r.type)for(var i=0;i<r.coordinates.length;i++)t.push(n(n({},e),{geometry:n(n({},r),{type:"Polygon",coordinates:r.coordinates[i]})}))})),t.filter((function(t){return"Polygon"===t.geometry.type})).map((function(t){var e=t.geometry,r=t.properties,n=D.flatten(e.coordinates).vertices,i=new Float32Array(n.map((function(t,e){if(e%2==1){var r=t*Math.PI/180;return Math.tan(r)+1/Math.cos(r)}return t}))),o=D(n),a=o.length>256?new Uint16Array(o):new Uint8Array(o),s=function(t){var e=t,r=e.height,n=void 0===r?0:r,i=e.levels,o=void 0===i?0:i,a=e.render_height,s=void 0===a?0:a;if(o)return 3.04*o;return Math.max(n,s)}(r),u=r.highlight||!1;return{aPosition:i,cuts:a,buildingHeight:s,startPos:[n[0],n[1]],highlight:u}}))}D.deviation=function(t,e,r,n){var i=e&&e.length,o=i?e[0]*r:t.length,a=Math.abs(et(t,0,o,r));if(i)for(var s=0,u=e.length;s<u;s++){var l=e[s]*r,c=s<u-1?e[s+1]*r:t.length;a-=Math.abs(et(t,l,c,r))}var h=0;for(s=0;s<n.length;s+=3){var f=n[s]*r,p=n[s+1]*r,d=n[s+2]*r;h+=Math.abs((t[f]-t[d])*(t[p+1]-t[f+1])-(t[f]-t[p])*(t[d+1]-t[f+1]))}return 0===a&&0===h?0:Math.abs((h-a)/a)},D.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},n=0,i=0;i<t.length;i++){for(var o=0;o<t[i].length;o++)for(var a=0;a<e;a++)r.vertices.push(t[i][o][a]);i>0&&(n+=t[i-1].length,r.holes.push(n))}return r};var nt,it=function(t){return new Promise((function(e,r){var n=new Int32Array(t.buffer).reduce((function(t,e){return Math.max(t,(n=(256*(255&(r=e))+(r>>8&255))/5,i=(256*(r>>16&255)+(r>>24&255))/5,Math.max(n,i)));var r,n,i}),0);e({maxHeight:Math.min(E,n)})}))},ot={width:0,height:0,tileLatLngBounds:new m(new v(0,0),new v(0,0)),imageData:new Uint8ClampedArray(0),visibleDEMPixelBounds:new d(new h(0,0),new h(0,0)),maxHeight:E,maxBuildingHeight:0,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0},at=function(t){return i(void 0,void 0,void 0,(function(){var e,r,a,s,u,l,c,f,p,x,_,g,v,y,w,R,b,A,M,U,L,D,P,S,C,I,F,B,X,N,z,O,H,W,G,j,Z,Y,K,k,q,V,J,$;return o(this,(function(Q){switch(Q.label){case 0:e=t.map,r=t.getFeatures,a=t.terrainSource,s=t.tileLoaded,u=t.gl,l=t.bounds,c=t.buildingRasterizer,f=t.tileMerger,p=a.getSourceUrl,x=a.getElevation,_=a.maxZoom,g=a.tileSize,v=a._overzoom,et={map:e,getFeatures:r},y=i(void 0,void 0,void 0,(function(){var t,e,r,n;return o(this,(function(i){switch(i.label){case 0:t=et.map,e=et.getFeatures,i.label=1;case 1:return i.trys.push([1,3,,4]),r=rt,[4,e()];case 2:return[2,r.apply(void 0,[i.sent(),t])];case 3:return n=i.sent(),console.log("Error merging buildings",n),[3,4];case 4:return[2,[]]}}))})),w=e.getZoom(),Q.label=1;case 1:return Q.trys.push([1,4,,5]),w=Math.min(v||_,w),R=Math.round(w),A=(b=l).getNorthWest(),M=b.getSouthEast(),U=new d(e.project(A,w),e.project(M,w)),L=new d(e.project(A,R),e.project(M,R)),D=new h(L.min.x,L.min.y),P=L.max.x-L.min.x,S=L.max.y-L.min.y,(C=L.max.subtract(L.min)).y>C.x&&(D.x-=T,P+=512),I=function(t){for(var e=t.upperLeft,r=t.zoom,n=t.innerWidth,i=t.innerHeight,o=e.divideBy(T).floor(),a=o.x+Math.floor((n+T)/T),s=Math.min(o.y+Math.floor((i+T)/T),Math.pow(2,r)-1),u=[],l=o.x;l<=a;l++)for(var c=o.y;c<=s;c++)u.push({x:l,y:c,z:r});return u}({upperLeft:D,zoom:R,innerWidth:P,innerHeight:S}),F=function(t){t.sort((function(t,e){return t.y!==e.y?t.y-e.y:t.x-e.x}));var e=t.reduce((function(t,e){return e.x<t.x?e:t})).x,r=t.reduce((function(t,e){return e.y<t.y?e:t})).y;return t.map((function(t){var n=Math.pow(2,t.z);return{x:(t.x%n+n)%n,y:(t.y%n+n)%n,z:t.z,xOffset:(t.x-e)*T,yOffset:(t.y-r)*T}}))}(I),(B=JSON.stringify(F))===nt&&R<_?[2,ot=n(n({},ot),{visibleDEMPixelBounds:L,demZoom:R,dirty:!0})]:(X={width:(tt=F).reduce((function(t,e){return e.xOffset>t.xOffset?e:t})).xOffset+T,height:tt.reduce((function(t,e){return e.yOffset>t.yOffset?e:t})).yOffset+T},N=X.width,z=X.height,[4,f.merge(F,{maxZoom:_,width:N,height:z,crossOrigin:"Anonymous",getSourceUrl:p,getElevation:x,tileSize:g,tileLoaded:s})]);case 2:return null===(O=Q.sent())?[2,ot=n(n({},ot),{visibleDEMPixelBounds:L,demZoom:R,dirty:!1})]:(H=function(t){var e=t.upperLeft,r=t.width,n=t.height,i=e.divideBy(T).floor().multiplyBy(T),o=i.add([r,n]);return new d(i,o)}({upperLeft:D,width:N,height:z}),W=new m(e.unproject(H.getTopLeft(),R),e.unproject(H.getBottomRight(),R)),G=0,[4,y]);case 3:return j=Q.sent(),G=c.raster({upperLeftTile:F[0],width:N,height:z,map:e,features:j,imageData:O,screenPixelBounds:U,gl:u}),E,Z=U.max.x-U.min.x,Y=U.max.y-U.min.y,K=window.innerWidth*window.innerHeight,k=Z*Y,q=Math.sqrt(K/k),V=Math.round(Z*q),J=Math.round(Y*q),nt=B,ot={maxHeight:8848,maxBuildingHeight:G,width:N,height:z,tileLatLngBounds:W,imageData:O,visibleDEMPixelBounds:L,raster:F,demZoom:R,dirty:!0,outputWidth:V,outputHeight:J},[3,5];case 4:return $=Q.sent(),console.error("Could not decode height map",$),[3,5];case 5:return[2,ot]}var tt,et}))}))},st=function(t){var e=t.tile,r=t.maxZoom,n=t.tileSize,i=e.x,o=e.y,a=e.z;if(a>r){var s=Math.pow(2,e.z-r);i=Math.floor(i/s),o=Math.floor(o/s),a=r}return{x:n===T?i:Math.floor(i/2),y:n===T?o:Math.floor(o/2),z:n===T?a:a-1}},ut=function(){function t(){var t=document.createElement("canvas");t.width=T,t.height=T,this.ctx=t.getContext("2d",{antialias:!1,alpha:!1}),null!==this.ctx&&(this.ctx.imageSmoothingEnabled=!1),this.inProgress=[],this.finished=0}return t.prototype.merge=function(t,e){return i(this,void 0,void 0,(function(){var r,n,a,s,u,l,c,h,f,p,d,x,m=this;return o(this,(function(_){switch(_.label){case 0:if(r=e.width,n=e.height,a=e.crossOrigin,s=e.getSourceUrl,u=e.getElevation,l=e.tileSize,c=e.tileLoaded,h=e.maxZoom,!this.ctx)return[3,5];f=new Uint8ClampedArray(2*r*n),this.inProgress.forEach((function(t){return t.src=""})),this.inProgress=[],this.finished=0,p=new Set,t.forEach((function(t){p.add(s(st({tile:t,maxZoom:h,tileSize:l})))})),d=Array.from(p).map((function(e){return i(m,void 0,void 0,(function(){var n=this;return o(this,(function(i){return[2,new Promise((function(i,o){var c=new Image;n.inProgress.push(c),c.onload=function(){t.filter((function(t){return e===s(st({tile:t,maxZoom:h,tileSize:l}))})).forEach((function(t){var e=0,i=0,o=514===l?1:0,a=T,s=T;if(l!==T&&(e=t.x%2*T,i=t.y%2*T,a=T,s=T),t.z>h){var p=Math.pow(2,t.z-h);l!==T&&(e=Math.floor(t.x/p)%2*T,i=Math.floor(t.y/p)%2*T),e+=T*(t.x%p/p),i+=T*(t.y%p/p),a=T/p,s=T/p}n.ctx.drawImage(c,o+e,o+i,a,s,0,0,a,s);for(var d=n.ctx.getImageData(0,0,a,s).data,x=new Uint8ClampedArray(131072),m=new Array(a*s),_=T/a,g=0;g<d.length;g+=4){var v=5*((y=u({r:d[g],g:d[g+1],b:d[g+2],a:0}))||0);m[g/4]=v}for(g=0;g<x.length;g+=2){var y=m[Math.floor(g/2/T/_)*a+Math.floor(g/2%T/_)],E=Math.floor(y/256),w=Math.floor(y%256);x[g]=E,x[g+1]=w}for(g=0;g<T;g++)f.set(x.slice(g*T*2,(g+1)*T*2),2*(t.yOffset*r+g*r+t.xOffset))})),i(null)},c.onerror=function(t){if(c.src!==c.originalSource)return o("new tiles requested");i(null)},c.crossOrigin=a||null,c.src=e,c.originalSource=c.src})).then((function(){n.finished++,c(n.finished,n.inProgress.length)}))]}))}))})),_.label=1;case 1:return _.trys.push([1,3,,4]),[4,Promise.all(d)];case 2:return _.sent(),[3,4];case 3:return x=_.sent(),console.log(d.length+" requests aborted",x),[2,null];case 4:return this.inProgress=[],[2,f];case 5:throw new Error("Could not get canvas context for merging tile images")}}))}))},t}(),lt=function(t,e){return[t.r/255,t.g/255,t.b/255,e]},ct=function(t,e){var r=e.date,n=R(r),i=n.dec,o=n.Hi;t.updateDate({dec:i,Hi:o})},ht=function(t,e){return i(void 0,void 0,void 0,(function(){return o(this,(function(r){switch(r.label){case 0:return[4,t.updateDateRange(n({},e))];case 1:return[2,r.sent()]}}))}))},ft=function(t,e){var r=e.color,n=e.opacity,i=lt(r,n);t.updateColor({colorVec:i})};new m([0,0],[0,0]);var pt=function(t){var e=t.kernel,r=t.map,i=t.heightMap,o=t.now,a=t.color,s=t.opacity;t.maxZoom;try{var u=i.maxHeight,l=i.maxBuildingHeight,c=i.width,h=i.height,f=i.tileLatLngBounds,p=i.imageData,d=i.visibleDEMPixelBounds,x=i.demZoom;if(0===c||0===h)return;var m=d.min,_=d.max;if(!m||!_)return;var g=_.subtract(m),v=g.x,y=g.y,E=r.project(f.getNorthWest(),x),w=r.screenUnproject([0,0]),b=r.screenUnproject([window.innerWidth,0]),A=r.screenUnproject([window.innerWidth,window.innerHeight]),M=[r.screenUnproject([0,window.innerHeight]),A,w,b].map((function(t){return r.project(t,x)})),U=M.map((function(t){return[(t.x-E.x)/c,(t.y-E.y)/h]})).flat(),L=M.map((function(t){return[(t.x-m.x)/v,(t.y-m.y)/y]})).map((function(t){return[2*t[0]-1,-1*(2*t[1]-1)]})).flat(),D=E.y/T/Math.pow(2,x),P=h/T/Math.pow(2,x),S=f.getWest(),C=Math.abs(f.getWest()-f.getEast());!function(t,e){var r=e.color,i=e.opacity,o=e.date,a=e.imageData,s=e.maxBuildingHeight,u=lt(r,i),l=R(o),c=l.dec,h=l.Hi;t.updateLocation(n({dec:c,Hi:h,colorVec:u,step:1},e)),it(a).then((function(e){var r=e.maxHeight;t.updateMaxHeight({maxHeight:Math.max(r,s)})}))}(e,{imageData:p,maxHeight:u,maxBuildingHeight:l,width:c,height:h,heightMapZoom:x,cornerTextureCoords:U,cornerClipCoords:L,topYCoord:D,ySize:P,west:S,dLng:C,date:o,color:a,opacity:s})}catch(t){console.error("EXCEPTION",t)}};var dt=function(t){var e=function(){return!t.getPitch};return{project:function(r,n){if(e())return t.project(r,n);var i=r.lat;return new h(function(t,e){return(t+180)/360*Math.pow(2,e)*T}(r.lng,n),function(t,e){return(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*T}(i,n))},unproject:function(r,n){return e()?t.unproject(r,n):new v((i=r.y,o=n,a=Math.PI-2*Math.PI*i/T/Math.pow(2,o),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/T/Math.pow(2,e)*360-180}(r.x,n));var i,o,a},screenUnproject:function(r){return e()?t.containerPointToLatLng(r):t.unproject(r)},getZoom:function(){return e()?t.getZoom():t.getZoom()+1},getCenter:function(){return t.getCenter()},getBounds:function(){return t.getBounds()},eachLayer:function(r){e()&&t.eachLayer(r)},getBearing:function(){return e()?0:t.getBearing()},getPitch:function(){return e()?0:t.getPitch()},rawMap:function(){return t},isLeaflet:e}},xt=function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.addTo=function(t){return this.onAdd(t)},e.prototype.onAdd=function(t){if(this._map=t,!this._canvasOverlay&&this._canvas){var e=this._map.getBounds();this._canvasOverlay=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new(s.bind.apply(s,a([void 0],t)))}(this._canvas,e),this._canvasOverlay.addTo(this._map)}return this._map.on("moveend",this._reset),this._reset(),this},e.prototype._repositionCanvas=function(t){this._canvasOverlay&&this._canvasOverlay.setBounds(t)},e}(function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=t.call(this)||this;n.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:function(t){return t.x,t.y,t.z,"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/7/17/45.png"},getElevation:function(t){return 256*t.r+t.g+t.b/256-32768}},getFeatures:function(){return Promise.resolve([])},debug:function(t){}};var a=e[0];if(n.options=Object.assign(n.options,a),!n.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:n.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((function(t){return i(n,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return 200===t.status?[3,2]:(e=Error.bind,[4,t.text()]);case 1:throw new(e.apply(Error,[void 0,r.sent()]));case 2:return[2]}}))}))})).catch((function(t){return i(n,void 0,void 0,(function(){return o(this,(function(e){if(200!==t.status)throw new Error("Could not load ShadeMap API");return[2]}))}))}));var s={preserveDrawingBuffer:!0,antialias:!1};return n._canvas=document.createElement("canvas"),n._gl=n._canvas.getContext("webgl",s)||n._canvas.getContext("experimental-webgl",s),n._compiledKernel=M({context:n._gl}),n._color=n._parseColor(n.options.color),n._buildingRasterizer=new U(n._gl),n._tileMerger=new ut,n._reset=n._reset.bind(n),n._draw=n._draw.bind(n),n}return r(e,t),e.prototype.onRemove=function(){return this._map&&this._map.off("moveend",this._reset),this},e.prototype.setDate=function(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(ct(this._compiledKernel,{date:this.options.date}),this._flush())):this.emit("idle"),this},e.prototype.setColor=function(t){return this.options.color!==t&&(this.options.color=t,this._color=this._parseColor(this.options.color),this._compiledKernel&&(ft(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this},e.prototype.setOpacity=function(t){return this.options.opacity!==t&&(this.options.opacity=t,this._compiledKernel&&(ft(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this},e.prototype.setSunExposure=function(t,e){return void 0===t&&(t=!1),i(this,void 0,void 0,(function(){var r,i,a,s,u;return o(this,(function(o){switch(o.label){case 0:return this._map&&this._compiledKernel?!1!==t?[3,1]:(this.options.sunExposure=n(n({},this.options.sunExposure),{enabled:t}),ct(this._compiledKernel,{date:this.options.date}),[3,3]):[3,4];case 1:if(i=(r=e).startDate,a=r.endDate,s=r.iterations,u=void 0===s?32:s,this.options.sunExposure={enabled:t,startDate:i,endDate:a,iterations:u},!(i instanceof Date&&a instanceof Date))throw new Error("Start date or end date or both are missing");if(a.getTime()<i.getTime())throw new Error("End date must come after the start date to calculate sun exposure");return[4,ht(this._compiledKernel,{startDate:i,endDate:a,iterations:u,emit:this.emit.bind(this)})];case 2:if(!0===o.sent())return[2,this];o.label=3;case 3:this._flush(),o.label=4;case 4:return[2,this]}}))}))},e.prototype._resizeCanvas=function(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.options.debug("_resize w:"+t+" h:"+e),this._canvas.width=t,this._canvas.height=e,this._gl.viewport(0,0,t,e)},e.prototype._reset=function(){return i(this,void 0,void 0,(function(){var t,e,r=this;return o(this,(function(n){switch(n.label){case 0:if(this.options.debug("_reset()"),!this._map)return[3,2];t=dt(this._map);try{this._bounds=t.getBounds()}catch(t){return console.error("Invalid bounds returned: ",t),[2,this]}return[4,at({gl:this._gl,map:t,bounds:this._bounds,terrainSource:this.options.terrainSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,tileLoaded:function(t,e){return r.emit("tileloaded",t,e)}})];case 1:(e=n.sent()).dirty&&(this._resizeCanvas(e.outputWidth,e.outputHeight),this._draw(e)),n.label=2;case 2:return[2,this]}}))}))},e.prototype._draw=function(t){var e=this;return this.options.debug("_draw()"),setTimeout((function(){return i(e,void 0,void 0,(function(){var e,r,n,i;return o(this,(function(o){switch(o.label){case 0:return this._canvas&&this._compiledKernel&&this._map?(pt({kernel:this._compiledKernel,map:dt(this._map),heightMap:t,color:this._color,opacity:this.options.opacity,now:this.options.date,maxZoom:this.options.terrainSource.maxZoom}),this.options.sunExposure.enabled?(e=this.options.sunExposure,r=e.startDate,n=e.endDate,i=e.iterations,[4,ht(this._compiledKernel,{startDate:r,endDate:n,iterations:i,emit:this.emit.bind(this)})]):[3,2]):[3,3];case 1:if(!0===o.sent())return[2,this];o.label=2;case 2:this._repositionCanvas(this._bounds),o.label=3;case 3:return[2]}}))}))}),0),this},e.prototype.readPixel=function(t,e){var r=new Uint8Array(4);return this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r),r},e.prototype.toGeoTiff=function(){var t=this;if(this._map){var e=this._canvas.width,r=this._canvas.height,n=function(e,r,n,i){var o=new Uint8Array(n*i*4);t._gl.readPixels(e,r,n,i,t._gl.RGBA,t._gl.UNSIGNED_BYTE,o);var a=n*i*1,s=1*n,u=(i-1)*s,l=new Uint8Array(a),c=new Uint8Array(a),h=0,f=t.options.sunExposure,p=f.startDate,d=f.endDate;t.options.sunExposure.enabled&&p&&d&&(h=d.getTime()-p.getTime());for(var x=0;x<o.length;x+=4){var m=void 0;if(t.options.sunExposure.enabled){var _=o.subarray(x,x+3),g=b(_,.5,h)/1e3/60,v=Math.min(Math.floor(g/6),255);m=new Uint8Array([v])}else m=o[x]+o[x+1]+o[x+2]===0?new Uint8Array([1]):new Uint8Array([0]);l.set(m,x/4*1)}for(x=0;x<a;x+=s)c.set(l.subarray(x,x+s),u-x);return c}(0,0,e,r),i=dt(this._map),o=i.getBounds().getNorthWest(),a=o.lat,s=o.lng,u=i.getBounds().getSouthEast(),l=[0,0,0,s,a,0],c=[(u.lng-s)/e,(a-u.lat)/r,0];return this.options.sunExposure.enabled,{data:n,metadata:{width:e,height:r,ModelTiepoint:l,ModelPixelScale:c,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}},e.prototype._generateShadeProfile=function(t){if(this._compiledKernel){var e=this._canvas.width,r=this._canvas.height,i=this._parseColor(t.sunColor),o=this._parseColor(t.shadeColor);this._canvas.width=t.pixels.length/2,this._canvas.height=t.dates.length;var a=function(t,e){var r=lt(e.shadeColor,1),i=lt(e.sunColor,1);return t.generateShadeProfile(n(n({},e),{sunColor:i,shadeColor:r}))}(this._compiledKernel,n(n({},t),{sunColor:i,shadeColor:o}));return this._canvas.width=e,this._canvas.height=r,a}return new Uint8Array},e.prototype.getHoursOfSun=function(t,e){if(this._map&&this.options.sunExposure.enabled){var r=this.readPixel(t,e),n=this.options.sunExposure,i=n.startDate,o=n.endDate.getTime()-i.getTime(),a=b(r,.5,o);return Math.abs(a/1e3/3600)}return 0},e.prototype._repositionCanvas=function(t){},e.prototype._flush=function(){},e.prototype.flushSync=function(){this._gl.finish()},e.prototype._parseColor=function(t){t=t.replace("#","");var 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},e}(L));return void 0!==window.L&&(window.L.shadeMap=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new(xt.bind.apply(xt,a([void 0],t)))}),xt}));
8
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("leaflet")):"function"==typeof define&&define.amd?define(["leaflet"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).ShadeMap=e(t.L)}(this,(function(t){"use strict";var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,r)};function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e,r,n){return new(r||(r=Promise))((function(i,o){function a(t){try{u(n.next(t))}catch(t){o(t)}}function s(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function a(t,e,r){if(r||2===arguments.length)for(var n,i=0,o=e.length;i<o;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}var s=function(e){function n(t,r,n){void 0===n&&(n={});var i=e.call(this,"",r,n)||this;return i._url=t,i}return r(n,e),n.prototype._initImage=function(){var e="CANVAS"===this._url.tagName,r=this._image=e?this._url:t.DomUtil.create("canvas");return t.DomUtil.addClass(r,"leaflet-image-layer"),this._zoomAnimated&&t.DomUtil.addClass(r,"leaflet-zoom-animated"),this.options.className&&t.DomUtil.addClass(r,this.options.className),r.onselectstart=t.Util.falseFn,r.onmousemove=t.Util.falseFn,this},n.prototype.setBounds=function(t){return this._bounds=t,this._map&&this._reset(),this},n}(t.ImageOverlay);function u(t,e,r){var n=e[1],i=e[0],o=n-i;return t===n&&r?t:((t-i)%o+o)%o+i}function l(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}var h=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function c(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var f=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function d(t,e,r){return t instanceof c?t:h(t)?new c(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new c(t.x,t.y):new c(t,e,r)}function p(t,e){if(t)for(var r=e?[t,e]:t,n=0,i=r.length;n<i;n++)this.extend(r[n])}function x(t,e){return!t||t instanceof p?t:new p(t,e)}function _(t,e){if(t)for(var r=e?[t,e]:t,n=0,i=r.length;n<i;n++)this.extend(r[n])}function m(t,e){return t instanceof _?t:new _(t,e)}c.prototype={clone:function(){return new c(this.x,this.y)},add:function(t){return this.clone()._add(d(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(d(t))},_subtract:function(t){return this.x-=t.x,this.y-=t.y,this},divideBy:function(t){return this.clone()._divideBy(t)},_divideBy:function(t){return this.x/=t,this.y/=t,this},multiplyBy:function(t){return this.clone()._multiplyBy(t)},_multiplyBy:function(t){return this.x*=t,this.y*=t,this},scaleBy:function(t){return new c(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new c(this.x/t.x,this.y/t.y)},round:function(){return this.clone()._round()},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},floor:function(){return this.clone()._floor()},_floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.clone()._ceil()},_ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},trunc:function(){return this.clone()._trunc()},_trunc:function(){return this.x=f(this.x),this.y=f(this.y),this},distanceTo:function(t){var e=(t=d(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=d(t)).x===this.x&&t.y===this.y},contains:function(t){return t=d(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+l(this.x)+", "+l(this.y)+")"}},p.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof c||"number"==typeof t[0]||"x"in t)e=r=d(t);else if(e=(t=x(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 d((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return d(this.min.x,this.max.y)},getTopRight:function(){return d(this.max.x,this.min.y)},getTopLeft:function(){return this.min},getBottomRight:function(){return this.max},getSize:function(){return this.max.subtract(this.min)},contains:function(t){var e,r;return(t="number"==typeof t[0]||t instanceof c?d(t):x(t))instanceof p?(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=x(t);var e=this.min,r=this.max,n=t.min,i=t.max,o=i.x>=e.x&&n.x<=r.x,a=i.y>=e.y&&n.y<=r.y;return o&&a},overlaps:function(t){t=x(t);var e=this.min,r=this.max,n=t.min,i=t.max,o=i.x>e.x&&n.x<r.x,a=i.y>e.y&&n.y<r.y;return o&&a},isValid:function(){return!(!this.min||!this.max)},pad:function(t){var e=this.min,r=this.max,n=Math.abs(e.x-r.x)*t,i=Math.abs(e.y-r.y)*t;return x(d(e.x-n,e.y-i),d(r.x+n,r.y+i))},equals:function(t){return!!t&&(t=x(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},_.prototype={extend:function(t){var e,r,n=this._southWest,i=this._northEast;if(t instanceof v)e=t,r=t;else{if(!(t instanceof _))return t?this.extend(y(t)||m(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return n||i?(n.lat=Math.min(e.lat,n.lat),n.lng=Math.min(e.lng,n.lng),i.lat=Math.max(r.lat,i.lat),i.lng=Math.max(r.lng,i.lng)):(this._southWest=new v(e.lat,e.lng),this._northEast=new v(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,n=Math.abs(e.lat-r.lat)*t,i=Math.abs(e.lng-r.lng)*t;return new _(new v(e.lat-n,e.lng-i),new v(r.lat+n,r.lng+i))},getCenter:function(){return new v((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 v(this.getNorth(),this.getWest())},getSouthEast:function(){return new v(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 v||"lat"in t?y(t):m(t);var e,r,n=this._southWest,i=this._northEast;return t instanceof _?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=n.lat&&r.lat<=i.lat&&e.lng>=n.lng&&r.lng<=i.lng},intersects:function(t){t=m(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),i=t.getNorthEast(),o=i.lat>=e.lat&&n.lat<=r.lat,a=i.lng>=e.lng&&n.lng<=r.lng;return o&&a},overlaps:function(t){t=m(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),i=t.getNorthEast(),o=i.lat>e.lat&&n.lat<r.lat,a=i.lng>e.lng&&n.lng<r.lng;return o&&a},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=m(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var g=function(t){var e,r,n,i;for(r=1,n=arguments.length;r<n;r++)for(e in i=arguments[r])t[e]=i[e];return t}({},{latLngToPoint:function(t,e){var r=this.projection.project(t),n=this.scale(e);return this.transformation._transform(r,n)},pointToLatLng:function(t,e){var r=this.scale(e),n=this.transformation.untransform(t,r);return this.projection.unproject(n)},project:function(t){return this.projection.project(t)},unproject:function(t){return this.projection.unproject(t)},scale:function(t){return 256*Math.pow(2,t)},zoom:function(t){return Math.log(t/256)/Math.LN2},getProjectedBounds:function(t){if(this.infinite)return null;var e=this.projection.bounds,r=this.scale(t);return new p(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(t){var e=this.wrapLng?u(t.lng,this.wrapLng,!0):t.lng;return new v(this.wrapLat?u(t.lat,this.wrapLat,!0):t.lat,e,t.alt)},wrapLatLngBounds:function(t){var e=t.getCenter(),r=this.wrapLatLng(e),n=e.lat-r.lat,i=e.lng-r.lng;if(0===n&&0===i)return t;var o=t.getSouthWest(),a=t.getNorthEast();return new _(new v(o.lat-n,o.lng-i),new v(a.lat-n,a.lng-i))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,n=t.lat*r,i=e.lat*r,o=Math.sin((e.lat-t.lat)*r/2),a=Math.sin((e.lng-t.lng)*r/2),s=o*o+Math.cos(n)*Math.cos(i)*a*a,u=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s));return this.R*u}});function v(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 y(t,e,r){return t instanceof v?t:h(t)&&"object"!=typeof t[0]?3===t.length?new v(t[0],t[1],t[2]):2===t.length?new v(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new v(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new v(t,e,r)}v.prototype={equals:function(t,e){return!!t&&(t=y(t),Math.max(Math.abs(this.lat-t.lat),Math.abs(this.lng-t.lng))<=(void 0===e?1e-9:e))},toString:function(t){return"LatLng("+l(this.lat,t)+", "+l(this.lng,t)+")"},distanceTo:function(t){return g.distance(this,y(t))},wrap:function(){return g.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return m([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new v(this.lat,this.lng,this.alt)}};var E=8848,T=256;var w=function(t,e){var r=t.lat;return new c(function(t,e){return(t+180)/360*Math.pow(2,e)*T}(t.lng,e),function(t,e){return(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*T}(r,e))},R=function(t,e){return new v((r=t.y,n=e,i=Math.PI-2*Math.PI*r/T/Math.pow(2,n),180/Math.PI*Math.atan(.5*(Math.exp(i)-Math.exp(-i)))),function(t,e){return t/T/Math.pow(2,e)*360-180}(t.x,e));var r,n,i},b=.40909994067971484,A=function(t){var e=t.valueOf()/864e5-10957.5,r=6.240059966692059+.017201969994578018*e,n=r+.017453292519943295*(1.9148*Math.sin(r)+.02*Math.sin(2*r)+3e-4*Math.sin(3*r))+1.796593062783907+Math.PI,i=Math.atan2(Math.sin(n)*Math.cos(b),Math.cos(n));return{dec:Math.asin(Math.sin(b)*Math.sin(n)),Hi:(4.889714432387314+6.3003876824396166*e-i)%(2*Math.PI)+2*Math.PI}},M=function(t,e,r){var n=1/e,i=Math.min(t[0]*n,255),o=Math.min(t[1]*n,255),a=Math.min(t[2]*n,255),s=0;return i+o+a!==0&&(s=i>0?i/255*.5+.5:a>0?.5*(1-a/255):.5),s*r};function U(t){var e=t.gl,r=t.vSrc,n=t.fSrc,i=e.createShader(e.VERTEX_SHADER);e.shaderSource(i,r),e.compileShader(i);var o=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(o,n),e.compileShader(o);var a=e.createProgram();return e.attachShader(a,i),e.attachShader(a,o),e.linkProgram(a),a}function P(t){var e=this,r=t.context,n=U({gl:r,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 a_pos;attribute vec2 a_tex_pos;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;void main(void){gl_Position=vec4(a_pos,0,1);vTexCoordFull=(gl_Position*0.5+0.5).xy;vTexCoordCropped=a_tex_pos;}",fSrc:"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nprecision lowp int;precision lowp sampler2D;float atan2(float v1,float v2){if(v1==0.0||v2==0.0)return 0.0;return atan(v1,v2);}float _pow(float v1,float v2){if(v2==0.0)return 1.0;return pow(v1,v2);}float integerMod(float x,float y){float res=floor(mod(x,y));return res*(res>floor(y)-1.0 ? 0.0 : 1.0);}float divWithIntCheck(float x,float y){if(floor(x)==x&&floor(y)==y&&integerMod(x,y)==0.0){return float(int(x)/int(y));}return x/y;}float integerCorrectionModulo(float number,float divisor){if(number<0.0){number=abs(number);if(divisor<0.0){divisor=abs(divisor);}return-(number-(divisor*floor(divWithIntCheck(number,divisor))));}if(divisor<0.0){divisor=abs(divisor);}return number-(divisor*floor(divWithIntCheck(number,divisor)));}float getElevationFromSampler2D(sampler2D tex,float x,float y){vec4 result=texture2D(tex,vec2(x,y));return(result.r*256.0*256.0+result.g*256.0)/5000.0;}vec4 actualColor;void color(float r,float g,float b,float a){actualColor=vec4(r,g,b,a);}void color(float r,float g,float b){color(r,g,b,1.0);}void color(float r){color(r,r,r,1.0);}void color(vec4 color){actualColor=color;}const int LOOP_MAX=1000;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;uniform sampler2D user_a;uniform float user_width;uniform float user_height;uniform float user_maxHeight;uniform float user_zoom;uniform float user_topYCoord;uniform float user_ySize;uniform vec4 user_color;uniform vec4 u_sunColor;uniform float user_step;uniform float user_west;uniform float user_dLng;uniform float user_dec;uniform float user_Hi;uniform sampler2D user_sunExposureTexture;uniform bool user_renderToSunExposureTexture;uniform bool user_outputSunExposure;uniform vec4 user_exposureDelta;uniform bool u_outputShadeProfile;uniform sampler2D u_decHiTexture;uniform sampler2D u_gpxTexture;uniform bool u_outputLocationShadeProfile;uniform vec2 u_shadeProfileLocation;float kernelResult;void kernel(){float sunDec=user_dec;float sunHi=user_Hi;vec4 shade_color=user_color;float maxHeight=user_maxHeight/1000.0;float user_x=vTexCoordCropped.x;float user_y=vTexCoordCropped.y;if(u_outputShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;vec4 gpx=texture2D(u_gpxTexture,vec2(vTexCoordFull.x,.5));user_x=gpx.x;user_y=gpx.y;}if(u_outputLocationShadeProfile==true){vec4 decHi=texture2D(u_decHiTexture,vec2(vTexCoordFull.x,1.0-vTexCoordFull.y));sunDec=-decHi.r;sunHi=decHi.g*10.0;user_x=u_shadeProfileLocation.x;user_y=u_shadeProfileLocation.y;}float user_z=getElevationFromSampler2D(user_a,user_x,user_y);float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=user_west+(user_dLng*user_x);float user_H=integerCorrectionModulo((sunHi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(sunDec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(sunDec))+((cos(user_lat)*cos(sunDec))*cos(user_H))));float user_zoom_factor=_pow(2.0,user_zoom);float user_kmPerPixel=divWithIntCheck(156.5430339296875,user_zoom_factor)*abs(cos(user_lat));float user_dx=((-sin(sun_azimuth)*cos(sun_altitude))*user_step)/user_width;float user_dy=((cos(sun_azimuth)*cos(sun_altitude))*user_step)/user_height;float user_dz=((sin(sun_altitude)*user_kmPerPixel)*user_step);float shadow_bias=0.001;float user_lit=1.0;float user_curvature=0.0;float cur_height=0.0;float user_distance=0.0;float user_startX=user_x;float user_startY=user_y;user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;if((abs(1.0)<0.0)){kernelResult=0.0;return;}float minAngle=asin((earthRadiusInKm/(earthRadiusInKm+user_z)))-(user_PI/2.0);if(user_z<0.0||sun_altitude<minAngle){user_lit=0.0;}else{float xIter=ceil(user_dx<0.0 ? abs(user_x/user_dx):(1.0-user_x)/user_dx);float yIter=ceil(user_dy<0.0 ? abs(user_y/user_dy):(1.0-user_y)/user_dy);float zIter=ceil(user_dz<0.0 ? float(LOOP_MAX):(maxHeight-user_z)/user_dz);int iter=int(min(xIter,min(yIter,zIter)));float user_distance=(sqrt(pow(user_dx*user_width,2.0)+pow(user_dy*user_height,2.0))*user_kmPerPixel)/earthRadiusInKm;for(int safeI=0;safeI<LOOP_MAX;safeI++){if(safeI>iter){break;}cur_height=getElevationFromSampler2D(user_a,user_x,user_y);if(cur_height-user_z>shadow_bias){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;vec4 result=texture2D(user_a,vec2(user_x,user_y));if(result.z==1.0){shade_color=vec4(.92941,.4375,.078125,.85);}iter=0;break;}}user_x+=user_dx;user_y+=user_dy;user_z+=user_dz;}}if((user_lit==1.0)){color(u_sunColor);}else{color(shade_color);}if(user_renderToSunExposureTexture){vec4 aggregateColor=texture2D(user_sunExposureTexture,vec2(vTexCoordFull.x,vTexCoordFull.y));if((user_lit==1.0)){color(aggregateColor.r,0.0,0.0,1.0);}else{color(aggregateColor.r+user_exposureDelta.r,0.0,0.0,1.0);}if(user_outputSunExposure){float timeInSun=1.0-aggregateColor.r;float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,0.5);}}}void main(void){kernel();gl_FragColor=actualColor;}"});r.useProgram(n);var a=r.createBuffer(),s=r.getAttribLocation(n,"a_pos"),u=r.createBuffer(),l=r.getAttribLocation(n,"a_tex_pos");r.enable(r.BLEND),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA);var h=r.getUniformLocation(n,"user_a");r.uniform1i(h,0);var c=r.getUniformLocation(n,"user_width"),f=r.getUniformLocation(n,"user_height"),d=r.getUniformLocation(n,"user_maxHeight"),p=r.getUniformLocation(n,"user_zoom"),x=r.getUniformLocation(n,"user_topYCoord"),_=r.getUniformLocation(n,"user_ySize"),m=r.getUniformLocation(n,"user_step"),g=r.getUniformLocation(n,"user_west"),v=r.getUniformLocation(n,"user_dLng"),y=r.getUniformLocation(n,"user_dec"),E=r.getUniformLocation(n,"user_Hi"),T=r.getUniformLocation(n,"user_color"),w=r.getUniformLocation(n,"user_xStart"),R=r.getUniformLocation(n,"user_yStart"),b=r.getUniformLocation(n,"user_xEnd"),M=r.getUniformLocation(n,"user_yEnd"),P=r.getUniformLocation(n,"user_sunExposureTexture");r.uniform1i(P,2);var D=r.getUniformLocation(n,"user_renderToSunExposureTexture"),L=r.getUniformLocation(n,"user_outputSunExposure"),C=r.getUniformLocation(n,"user_exposureDelta"),S=r.getUniformLocation(n,"u_outputShadeProfile"),I=r.getUniformLocation(n,"u_gpxTexture"),F=r.getUniformLocation(n,"u_decHiTexture"),B=r.getUniformLocation(n,"u_sunColor"),N=r.getUniformLocation(n,"u_outputLocationShadeProfile"),X=r.getUniformLocation(n,"u_shadeProfileLocation"),z=function(){r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4)},O=0;return{updateLocation:function(t){var e=t.width,i=t.height,o=t.maxHeight,h=t.heightMapZoom,w=t.topYCoord,R=t.ySize,b=t.colorVec,A=t.step,M=t.west,U=t.dLng,P=t.dec,D=t.Hi,L=t.cornerClipCoords,C=t.cornerTextureCoords;r.useProgram(n),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindBuffer(r.ARRAY_BUFFER,a),r.bufferData(r.ARRAY_BUFFER,new Float32Array(L),r.STATIC_DRAW),r.enableVertexAttribArray(s),r.vertexAttribPointer(s,2,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,u),r.bufferData(r.ARRAY_BUFFER,new Float32Array(C),r.STATIC_DRAW),r.enableVertexAttribArray(l),r.vertexAttribPointer(l,2,r.FLOAT,!1,0,0),r.uniform1f(c,e),r.uniform1f(f,i),r.uniform1f(d,o),r.uniform1f(p,h),r.uniform1f(x,w),r.uniform1f(_,R),r.uniform4fv(T,b),r.uniform1f(m,A),r.uniform1f(g,M),r.uniform1f(v,U),r.uniform1f(y,P),r.uniform1f(E,D),window.requestAnimationFrame(z)},updateViewport:function(t){var e=t.xStart,n=t.yStart,i=t.xEnd,o=t.yEnd;r.uniform1f(w,e),r.uniform1f(R,n),r.uniform1f(b,i),r.uniform1f(M,o),window.requestAnimationFrame(z)},updateDate:function(t){var e=t.dec,n=t.Hi;r.uniform1f(y,e),r.uniform1f(E,n),window.requestAnimationFrame(z)},updateDateRange:function(t){return i(e,void 0,void 0,(function(){var e,n,i,a,s,u,l,h,c,f,d,p,x,_,m;return o(this,(function(g){switch(g.label){case 0:e=t.startDate,n=t.endDate,i=t.iterations,a=t.emit,s=O=Date.now(),r.uniform4fv(C,new Float32Array([1/i,0,0,0])),u=Math.floor((n.getTime()-e.getTime())/i),l=r.canvas.width,h=r.canvas.height,c=r.createTexture(),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,c),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,l,h,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),f=r.createTexture(),r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,f),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,l,h,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.uniform1i(D,1),d=r.createFramebuffer(),r.bindFramebuffer(r.FRAMEBUFFER,d),p=r.COLOR_ATTACHMENT0,r.viewport(0,0,l,h),x=function(t){return o(this,(function(n){switch(n.label){case 0:return a("tileloaded",t,i-1),s!==O?[2,{value:!0}]:[4,new Promise((function(n,i){window.requestAnimationFrame((function(){t%2==0?(r.uniform1i(P,2),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,c),r.framebufferTexture2D(r.FRAMEBUFFER,p,r.TEXTURE_2D,c,0)):(r.uniform1i(P,1),r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,f),r.framebufferTexture2D(r.FRAMEBUFFER,p,r.TEXTURE_2D,f,0));var i=A(new Date(e.getTime()+u*t)),o=i.dec,a=i.Hi;r.uniform1f(y,o),r.uniform1f(E,a),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4),n()}))}))];case 1:return n.sent(),[2]}}))},_=0,g.label=1;case 1:return _<i?[5,x(_)]:[3,4];case 2:if("object"==typeof(m=g.sent()))return[2,m.value];g.label=3;case 3:return _++,[3,1];case 4:return[4,new Promise((function(t,e){window.requestAnimationFrame((function(){s!==O&&t(!0),r.bindFramebuffer(r.FRAMEBUFFER,null),r.uniform1i(P,i%2==0?2:1),r.uniform1i(L,1),z(),r.uniform1i(D,0),r.uniform1i(L,0),r.deleteFramebuffer(d),r.deleteTexture(c),r.deleteTexture(f),t(!1)}))}))];case 5:return[2,g.sent()]}}))}))},updateColor:function(t){var e=t.colorVec;r.uniform4fv(T,e),window.requestAnimationFrame(z)},updateMaxHeight:function(t){var e=t.maxHeight;r.uniform1f(d,e)},generateShadeProfile:function(t){if(null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");var e=t.dates,i=t.texCoords,o=t.shadeColor,u=t.sunColor,l=i.length,h=e.length,c=r.getParameter(r.VIEWPORT),f=r.getUniform(n,T);r.uniform4fv(T,o),r.uniform4fv(B,u),r.uniform1i(S,1);var d=r.createTexture();r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,d);var p=i.map((function(t){return[t[0],t[1],0,0]})).flat();r.texImage2D(r.TEXTURE_2D,0,r.RGBA,p.length/4,1,0,r.RGBA,r.FLOAT,new Float32Array(p)),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.uniform1i(I,2);var x=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,x);var _=e.map((function(t){var e=A(t);return[-e.dec,e.Hi/10,0,0]})).flat();r.texImage2D(r.TEXTURE_2D,0,r.RGBA,1,e.length,0,r.RGBA,r.FLOAT,new Float32Array(_)),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.uniform1i(F,1),r.viewport(0,0,l,h),r.clear(r.COLOR_BUFFER_BIT),r.bindBuffer(r.ARRAY_BUFFER,a),r.bufferData(r.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),r.STATIC_DRAW),r.enableVertexAttribArray(s),r.vertexAttribPointer(s,2,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLE_STRIP,0,4);var m=new Uint8Array(l*h*4);return r.readPixels(0,0,l,h,r.RGBA,r.UNSIGNED_BYTE,m),r.deleteTexture(x),r.deleteTexture(d),r.uniform1i(F,0),r.uniform1i(I,0),r.uniform1i(S,0),r.viewport(c[0],c[1],c[2],c[3]),r.uniform4fv(T,f),r.uniform4fv(B,[0,0,0,0]),m},generateLocationShadeProfile:function(t){if(null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");var e=t.dates,i=t.texCoord,o=t.shadeColor,u=t.sunColor,l=e[0].length,h=e.length,c=r.getParameter(r.VIEWPORT),f=r.getUniform(n,T);r.uniform4fv(T,o),r.uniform4fv(B,u),r.uniform1i(N,1),r.uniform2fv(X,[i[0],i[1]]);var d=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,d);var p=e.flat().map((function(t){var e=A(t);return[-e.dec,e.Hi/10,0,0]})).flat();r.texImage2D(r.TEXTURE_2D,0,r.RGBA,l,h,0,r.RGBA,r.FLOAT,new Float32Array(p)),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.uniform1i(F,1),r.viewport(0,0,l,h),r.clear(r.COLOR_BUFFER_BIT),r.bindBuffer(r.ARRAY_BUFFER,a),r.bufferData(r.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),r.STATIC_DRAW),r.enableVertexAttribArray(s),r.vertexAttribPointer(s,2,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLE_STRIP,0,4);var x=new Uint8Array(l*h*4);return r.readPixels(0,0,l,h,r.RGBA,r.UNSIGNED_BYTE,x),r.deleteTexture(d),r.uniform1i(F,0),r.uniform1i(N,0),r.viewport(c[0],c[1],c[2],c[3]),r.uniform4fv(T,f),r.uniform4fv(B,[0,0,0,0]),x}}}var D=function(){function t(t){this.gl=t,this.program=U({gl:t,vSrc:"\nuniform vec3 xyz;\nuniform vec2 dimensions;\nattribute vec2 a_position;\nfloat PI = 3.141592653589793;\nvarying vec2 vCoord;\n\n\tvoid main() {\n\t\tif (abs(a_position) == vec2(1,1)) {\n\t\t\tgl_Position = vec4(a_position, 0, 1);\n\t\t\tvCoord = a_position * 0.5 + 0.5;\n\t\t\treturn;\n\t\t}\n\t\tfloat x = ((a_position.x + 180.0) / 360.0 * pow(2.0, xyz.z)) * 256.0 - xyz.x;\n\t\tfloat y = (1.0 - (log(a_position.y) / PI)) / 2.0 * pow(2.0, xyz.z) * 256.0 - xyz.y;\n\t\tvec2 transformed = vec2(x, y);\n\t\tvec2 normalized = transformed / dimensions;\n\t\tvec2 final = normalized * 2.0 - 1.0;\n\t\tgl_Position = vec4(final, 0, 1);\n\t}\n",fSrc:"\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform vec4 color;\nuniform sampler2D height_map;\nvarying vec2 vCoord;\n\nvoid main() {\n\tif (color == vec4(0,0,0,0)) {\n\t \tvec4 textureColor = texture2D(height_map, vec2(vCoord.x, vCoord.y));\n\t \tgl_FragColor = vec4(textureColor.b, textureColor.a, 0, 1.0);\n\t\treturn;\n\t} \n\tgl_FragColor = color;\n}\n"}),this.positionAttributeLocation=t.getAttribLocation(this.program,"a_position"),this.xyzUniformLocation=t.getUniformLocation(this.program,"xyz"),this.dimensionsUniformLocation=t.getUniformLocation(this.program,"dimensions"),this.heightMapUniformLocation=t.getUniformLocation(this.program,"height_map"),this.colorUniformLocation=t.getUniformLocation(this.program,"color"),this.positionBuffer=t.createBuffer(),this.indexBuffer=t.createBuffer(),this.targetTexture=t.createTexture()}return t.prototype.raster=function(t){var e=this,r=t.features,n=t.upperLeftTile,i=t.mapZoom,o=t.width,a=t.height,s=t.imageData,u=t.gl,l=n.x,h=n.y,f=n.z,d=0;u.useProgram(this.program),u.activeTexture(u.TEXTURE1);var p=u.createTexture();u.bindTexture(u.TEXTURE_2D,p),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texImage2D(u.TEXTURE_2D,0,u.LUMINANCE_ALPHA,o,a,0,u.LUMINANCE_ALPHA,u.UNSIGNED_BYTE,s);var x=o,_=a;u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,this.targetTexture),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,x,_,0,u.RGBA,u.UNSIGNED_BYTE,null),i>15&&r.length>5?(u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST)):(u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.LINEAR)),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.viewport(0,0,x,_);var m=u.createFramebuffer();u.bindFramebuffer(u.FRAMEBUFFER,m);var g=u.COLOR_ATTACHMENT0;u.framebufferTexture2D(u.FRAMEBUFFER,g,u.TEXTURE_2D,this.targetTexture,0),u.bindBuffer(u.ARRAY_BUFFER,this.positionBuffer),u.bindBuffer(u.ELEMENT_ARRAY_BUFFER,this.indexBuffer),u.clearColor(0,0,0,0),u.clear(u.COLOR_BUFFER_BIT);var v=l*T,y=h*T,E=new c(v,y);u.uniform3f(this.xyzUniformLocation,v,y,f),u.uniform2f(this.dimensionsUniformLocation,o,a),u.uniform1i(this.heightMapUniformLocation,1);var R=new Float32Array([-1,-1,1,-1,-1,1,1,1]);return u.enableVertexAttribArray(this.positionAttributeLocation),u.bufferData(u.ARRAY_BUFFER,R,u.STATIC_DRAW),u.vertexAttribPointer(this.positionAttributeLocation,2,u.FLOAT,!1,0,0),u.uniform4f(this.colorUniformLocation,0,0,0,0),u.drawArrays(u.TRIANGLE_STRIP,0,4),r.forEach((function(t){var r=t.buildingHeight,n=t.aPosition,i=t.cuts,l=t.startPos,h=t.highlight,c=w({lng:l[0],lat:l[1]},f).subtract(E).floor();if(!(c.x<0||c.y<0||c.x>o||c.y>a)){var p=256*s[c.y*o*2+2*c.x]+s[c.y*o*2+2*c.x+1]+5*r,x=Math.floor(p/256)/256,_=Math.floor(p%256)/256;d=Math.max(d,p/5),u.uniform4f(e.colorUniformLocation,x,_,h?1:0,1),u.bufferData(u.ARRAY_BUFFER,n,u.DYNAMIC_DRAW),u.vertexAttribPointer(e.positionAttributeLocation,2,u.FLOAT,!1,0,0),u.bufferData(u.ELEMENT_ARRAY_BUFFER,i,u.DYNAMIC_DRAW),u.drawElements(u.TRIANGLES,i.length,i.length>256?u.UNSIGNED_SHORT:u.UNSIGNED_BYTE,0)}})),u.deleteFramebuffer(m),u.deleteTexture(p),d},t}(),L=function(){function t(){this.events={}}return t.prototype.on=function(t,e){var r=this;return"object"!=typeof this.events[t]&&(this.events[t]=[]),this.events[t].push(e),function(){return r.removeListener(t,e)}},t.prototype.removeListener=function(t,e){if("object"==typeof this.events[t]){var r=this.events[t].indexOf(e);r>-1&&this.events[t].splice(r,1)}},t.prototype.removeAllListeners=function(){var t=this;Object.keys(this.events).forEach((function(e){return t.events[e].splice(0,t.events[e].length)}))},t.prototype.emit=function(t){for(var e=this,r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];"object"==typeof this.events[t]&&a([],this.events[t]).forEach((function(t){return t.apply(e,r)}))},t.prototype.once=function(t,e){var r=this,n=this.on(t,(function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];n(),e.apply(r,t)}));return n},t}();function C(t,e,r){r=r||2;var n,i,o,a,s,u,l,h=e&&e.length,c=h?e[0]*r:t.length,f=S(t,0,c,r,!0),d=[];if(!f||f.next===f.prev)return d;if(h&&(f=function(t,e,r,n){var i,o,a,s=[];for(i=0,o=e.length;i<o;i++)(a=S(t,e[i]*n,i<o-1?e[i+1]*n:t.length,n,!1))===a.next&&(a.steiner=!0),s.push(Z(a));for(s.sort(O),i=0;i<s.length;i++)r=H(s[i],r);return r}(t,e,f,r)),t.length>80*r){n=o=t[0],i=a=t[1];for(var p=r;p<c;p+=r)(s=t[p])<n&&(n=s),(u=t[p+1])<i&&(i=u),s>o&&(o=s),u>a&&(a=u);l=0!==(l=Math.max(o-n,a-i))?32767/l:0}return F(f,d,r,n,i,l,0),d}function S(t,e,r,n,i){var o,a;if(i===nt(t,e,r,n)>0)for(o=e;o<r;o+=n)a=tt(o,t[o],t[o+1],a);else for(o=r-n;o>=e;o-=n)a=tt(o,t[o],t[o+1],a);return a&&k(a,a.next)&&(et(a),a=a.next),a}function I(t,e){if(!t)return t;e||(e=t);var r,n=t;do{if(r=!1,n.steiner||!k(n,n.next)&&0!==Y(n.prev,n,n.next))n=n.next;else{if(et(n),(n=e=n.prev)===n.next)break;r=!0}}while(r||n!==e);return e}function F(t,e,r,n,i,o,a){if(t){!a&&o&&function(t,e,r,n){var i=t;do{0===i.z&&(i.z=W(i.x,i.y,e,r,n)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next}while(i!==t);i.prevZ.nextZ=null,i.prevZ=null,function(t){var e,r,n,i,o,a,s,u,l=1;do{for(r=t,t=null,o=null,a=0;r;){for(a++,n=r,s=0,e=0;e<l&&(s++,n=n.nextZ);e++);for(u=l;s>0||u>0&&n;)0!==s&&(0===u||!n||r.z<=n.z)?(i=r,r=r.nextZ,s--):(i=n,n=n.nextZ,u--),o?o.nextZ=i:t=i,i.prevZ=o,o=i;r=n}o.nextZ=null,l*=2}while(a>1)}(i)}(t,n,i,o);for(var s,u,l=t;t.prev!==t.next;)if(s=t.prev,u=t.next,o?N(t,n,i,o):B(t))e.push(s.i/r|0),e.push(t.i/r|0),e.push(u.i/r|0),et(t),t=u.next,l=u.next;else if((t=u)===l){a?1===a?F(t=X(I(t),e,r),e,r,n,i,o,2):2===a&&z(t,e,r,n,i,o):F(I(t),e,r,n,i,o,1);break}}}function B(t){var e=t.prev,r=t,n=t.next;if(Y(e,r,n)>=0)return!1;for(var i=e.x,o=r.x,a=n.x,s=e.y,u=r.y,l=n.y,h=i<o?i<a?i:a:o<a?o:a,c=s<u?s<l?s:l:u<l?u:l,f=i>o?i>a?i:a:o>a?o:a,d=s>u?s>l?s:l:u>l?u:l,p=n.next;p!==e;){if(p.x>=h&&p.x<=f&&p.y>=c&&p.y<=d&&j(i,s,o,u,a,l,p.x,p.y)&&Y(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function N(t,e,r,n){var i=t.prev,o=t,a=t.next;if(Y(i,o,a)>=0)return!1;for(var s=i.x,u=o.x,l=a.x,h=i.y,c=o.y,f=a.y,d=s<u?s<l?s:l:u<l?u:l,p=h<c?h<f?h:f:c<f?c:f,x=s>u?s>l?s:l:u>l?u:l,_=h>c?h>f?h:f:c>f?c:f,m=W(d,p,e,r,n),g=W(x,_,e,r,n),v=t.prevZ,y=t.nextZ;v&&v.z>=m&&y&&y.z<=g;){if(v.x>=d&&v.x<=x&&v.y>=p&&v.y<=_&&v!==i&&v!==a&&j(s,h,u,c,l,f,v.x,v.y)&&Y(v.prev,v,v.next)>=0)return!1;if(v=v.prevZ,y.x>=d&&y.x<=x&&y.y>=p&&y.y<=_&&y!==i&&y!==a&&j(s,h,u,c,l,f,y.x,y.y)&&Y(y.prev,y,y.next)>=0)return!1;y=y.nextZ}for(;v&&v.z>=m;){if(v.x>=d&&v.x<=x&&v.y>=p&&v.y<=_&&v!==i&&v!==a&&j(s,h,u,c,l,f,v.x,v.y)&&Y(v.prev,v,v.next)>=0)return!1;v=v.prevZ}for(;y&&y.z<=g;){if(y.x>=d&&y.x<=x&&y.y>=p&&y.y<=_&&y!==i&&y!==a&&j(s,h,u,c,l,f,y.x,y.y)&&Y(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function X(t,e,r){var n=t;do{var i=n.prev,o=n.next.next;!k(i,o)&&q(i,n,n.next,o)&&$(i,o)&&$(o,i)&&(e.push(i.i/r|0),e.push(n.i/r|0),e.push(o.i/r|0),et(n),et(n.next),n=t=o),n=n.next}while(n!==t);return I(n)}function z(t,e,r,n,i,o){var a=t;do{for(var s=a.next.next;s!==a.prev;){if(a.i!==s.i&&K(a,s)){var u=Q(a,s);return a=I(a,a.next),u=I(u,u.next),F(a,e,r,n,i,o,0),void F(u,e,r,n,i,o,0)}s=s.next}a=a.next}while(a!==t)}function O(t,e){return t.x-e.x}function H(t,e){var r=function(t,e){var r,n=e,i=t.x,o=t.y,a=-1/0;do{if(o<=n.y&&o>=n.next.y&&n.next.y!==n.y){var s=n.x+(o-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(s<=i&&s>a&&(a=s,r=n.x<n.next.x?n:n.next,s===i))return r}n=n.next}while(n!==e);if(!r)return null;var u,l=r,h=r.x,c=r.y,f=1/0;n=r;do{i>=n.x&&n.x>=h&&i!==n.x&&j(o<c?i:a,o,h,c,o<c?a:i,o,n.x,n.y)&&(u=Math.abs(o-n.y)/(i-n.x),$(n,t)&&(u<f||u===f&&(n.x>r.x||n.x===r.x&&G(r,n)))&&(r=n,f=u)),n=n.next}while(n!==l);return r}(t,e);if(!r)return e;var n=Q(r,t);return I(n,n.next),I(r,r.next)}function G(t,e){return Y(t.prev,t,e.prev)<0&&Y(e.next,t,t.next)<0}function W(t,e,r,n,i){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*i|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-n)*i|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Z(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 j(t,e,r,n,i,o,a,s){return(i-a)*(e-s)>=(t-a)*(o-s)&&(t-a)*(n-s)>=(r-a)*(e-s)&&(r-a)*(o-s)>=(i-a)*(n-s)}function K(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&&q(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&($(t,e)&&$(e,t)&&function(t,e){var r=t,n=!1,i=(t.x+e.x)/2,o=(t.y+e.y)/2;do{r.y>o!=r.next.y>o&&r.next.y!==r.y&&i<(r.next.x-r.x)*(o-r.y)/(r.next.y-r.y)+r.x&&(n=!n),r=r.next}while(r!==t);return n}(t,e)&&(Y(t.prev,t,e.prev)||Y(t,e.prev,e))||k(t,e)&&Y(t.prev,t,t.next)>0&&Y(e.prev,e,e.next)>0)}function Y(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function k(t,e){return t.x===e.x&&t.y===e.y}function q(t,e,r,n){var i=J(Y(t,e,r)),o=J(Y(t,e,n)),a=J(Y(r,n,t)),s=J(Y(r,n,e));return i!==o&&a!==s||(!(0!==i||!V(t,r,e))||(!(0!==o||!V(t,n,e))||(!(0!==a||!V(r,t,n))||!(0!==s||!V(r,e,n)))))}function V(t,e,r){return e.x<=Math.max(t.x,r.x)&&e.x>=Math.min(t.x,r.x)&&e.y<=Math.max(t.y,r.y)&&e.y>=Math.min(t.y,r.y)}function J(t){return t>0?1:t<0?-1:0}function $(t,e){return Y(t.prev,t,t.next)<0?Y(t,e,t.next)>=0&&Y(t,t.prev,e)>=0:Y(t,e,t.prev)<0||Y(t,t.next,e)<0}function Q(t,e){var r=new rt(t.i,t.x,t.y),n=new rt(e.i,e.x,e.y),i=t.next,o=e.prev;return t.next=e,e.prev=t,r.next=i,i.prev=r,n.next=r,r.prev=n,o.next=n,n.prev=o,n}function tt(t,e,r,n){var i=new rt(t,e,r);return n?(i.next=n.next,i.prev=n,n.next.prev=i,n.next=i):(i.prev=i,i.next=i),i}function et(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 rt(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 nt(t,e,r,n){for(var i=0,o=e,a=r-n;o<r;o+=n)i+=(t[a]-t[o])*(t[o+1]+t[a+1]),a=o;return i}function it(t){return t.filter((function(t){return"MultiPolygon"===t.geometry.type})).forEach((function(e){var r=e.geometry;if(e.properties,e.type,"MultiPolygon"===r.type)for(var i=0;i<r.coordinates.length;i++)t.push(n(n({},e),{geometry:n(n({},r),{type:"Polygon",coordinates:r.coordinates[i]})}))})),t.filter((function(t){return"Polygon"===t.geometry.type})).map((function(t){var e=t.geometry,r=t.properties,n=C.flatten(e.coordinates).vertices,i=new Float32Array(n.map((function(t,e){if(e%2==1){var r=t*Math.PI/180;return Math.tan(r)+1/Math.cos(r)}return t}))),o=C(n),a=o.length>256?new Uint16Array(o):new Uint8Array(o),s=function(t){var e=t,r=e.height,n=void 0===r?0:r,i=e.levels,o=void 0===i?0:i,a=e.render_height,s=void 0===a?0:a;if(o)return 3.04*o;return Math.max(n,s)}(r),u=r.highlight||!1;return{aPosition:i,cuts:a,buildingHeight:s,startPos:[n[0],n[1]],highlight:u}}))}C.deviation=function(t,e,r,n){var i=e&&e.length,o=i?e[0]*r:t.length,a=Math.abs(nt(t,0,o,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(nt(t,l,h,r))}var c=0;for(s=0;s<n.length;s+=3){var f=n[s]*r,d=n[s+1]*r,p=n[s+2]*r;c+=Math.abs((t[f]-t[p])*(t[d+1]-t[f+1])-(t[f]-t[d])*(t[p+1]-t[f+1]))}return 0===a&&0===c?0:Math.abs((c-a)/a)},C.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},n=0,i=0;i<t.length;i++){for(var o=0;o<t[i].length;o++)for(var a=0;a<e;a++)r.vertices.push(t[i][o][a]);i>0&&(n+=t[i-1].length,r.holes.push(n))}return r};var ot,at=function(t){return new Promise((function(e,r){var n=new Int32Array(t.buffer).reduce((function(t,e){return Math.max(t,(n=(256*(255&(r=e))+(r>>8&255))/5,i=(256*(r>>16&255)+(r>>24&255))/5,Math.max(n,i)));var r,n,i}),0);e({maxHeight:Math.min(E,n)})}))},st={width:0,height:0,imageData:new Uint8ClampedArray(0),visibleDEMPixelBounds:new p(new c(0,0),new c(0,0)),DEMPixelBounds:new p(new c(0,0),new c(0,0)),maxHeight:E,maxBuildingHeight:0,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0},ut=function(t){return i(void 0,void 0,void 0,(function(){var e,r,a,s,u,l,h,f,d,x,_,m,g,v,y,R,b,A,M,U,P,D,L,C,S,I,F,B,N,X,z,O,H,G,W,Z;return o(this,(function(j){switch(j.label){case 0:e=t.demZoom,r=t.getFeatures,a=t.terrainSource,s=t.tileLoaded,u=t.gl,l=t.bounds,h=t.buildingRasterizer,f=t.tileMerger,d=a.getSourceUrl,x=a.getElevation,_=a.maxZoom,m=a.tileSize,K={getFeatures:r},g=i(void 0,void 0,void 0,(function(){var t,e,r;return o(this,(function(n){switch(n.label){case 0:t=K.getFeatures,n.label=1;case 1:return n.trys.push([1,3,,4]),e=it,[4,t()];case 2:return[2,e.apply(void 0,[n.sent()])];case 3:return r=n.sent(),console.log("Error merging buildings",r),[3,4];case 4:return[2,[]]}}))})),j.label=1;case 1:return j.trys.push([1,4,,5]),y=(v=l).getNorthWest(),R=v.getSouthEast(),b=new p(w(y,e),w(R,e)),A=new c(b.min.x,b.min.y),M=b.max.x-b.min.x,U=b.max.y-b.min.y,(P=b.max.subtract(b.min)).y>P.x&&(A.x-=T,M+=512),D=function(t){var e=t.upperLeft,r=t.width,n=t.height,i=e.divideBy(T).floor().multiplyBy(T),o=(Math.ceil(r/T)+1)*T,a=(Math.ceil(n/T)+1)*T,s=i.add([o,a]);return new p(i,s)}({upperLeft:A,width:M,height:U}),L=D.max.subtract(D.min),C=L.x,S=L.y,I=function(t){for(var e=t.upperLeft,r=t.width,n=t.height,i=t.zoom,o=e.divideBy(T).floor(),a=o.x+r/T,s=Math.min(o.y+n/T,Math.pow(2,i)-1),u=[],l=o.x;l<a;l++)for(var h=o.y;h<s;h++)u.push({x:l,y:h,z:i});return u}({upperLeft:D.min,width:C,height:S,zoom:e}),F=function(t){t.sort((function(t,e){return t.y!==e.y?t.y-e.y:t.x-e.x}));var e=t.reduce((function(t,e){return e.x<t.x?e:t})).x,r=t.reduce((function(t,e){return e.y<t.y?e:t})).y;return t.map((function(t){var n=Math.pow(2,t.z);return{x:(t.x%n+n)%n,y:(t.y%n+n)%n,z:t.z,xOffset:(t.x-e)*T,yOffset:(t.y-r)*T}}))}(I),B=b.max.x-b.min.x,N=b.max.y-b.min.y,X=B,z=N,(O=JSON.stringify(F))===ot&&e<_?[2,st=n(n({},st),{outputWidth:X,outputHeight:z,visibleDEMPixelBounds:b,demZoom:e,dirty:!0})]:[4,f.merge(F,{maxZoom:_,width:C,height:S,crossOrigin:"Anonymous",getSourceUrl:d,getElevation:x,tileSize:m,tileLoaded:s})];case 2:return null===(H=j.sent())?[2,st=n(n({},st),{visibleDEMPixelBounds:b,demZoom:e,dirty:!1})]:(G=0,[4,g]);case 3:return W=j.sent(),G=h.raster({upperLeftTile:F[0],width:C,height:S,mapZoom:e,features:W,imageData:H,gl:u}),E,ot=O,st={maxHeight:8848,maxBuildingHeight:G,width:C,height:S,imageData:H,DEMPixelBounds:D,visibleDEMPixelBounds:b,raster:F,demZoom:e,dirty:!0,outputWidth:X,outputHeight:z},[3,5];case 4:return Z=j.sent(),console.error("Could not decode height map",Z),[3,5];case 5:return[2,st]}var K}))}))},lt=function(t){var e=t.tile,r=t.maxZoom,n=t.tileSize,i=e.x,o=e.y,a=e.z;if(a>r){var s=Math.pow(2,e.z-r);i=Math.floor(i/s),o=Math.floor(o/s),a=r}return{x:n===T?i:Math.floor(i/2),y:n===T?o:Math.floor(o/2),z:n===T?a:a-1}},ht=function(){function t(){this.canvas=document.createElement("canvas"),this.canvas.width=T,this.canvas.height=T,this.ctx=this.canvas.getContext("2d",{antialias:!1,alpha:!1}),null!==this.ctx&&(this.ctx.imageSmoothingEnabled=!1),this.inProgress=[],this.finished=0}return t.prototype.merge=function(t,e){return i(this,void 0,void 0,(function(){var r,n,a,s,u,l,h,c,f,d,p,x,_=this;return o(this,(function(m){switch(m.label){case 0:if(r=e.width,n=e.height,a=e.crossOrigin,s=e.getSourceUrl,u=e.getElevation,l=e.tileSize,h=e.tileLoaded,c=e.maxZoom,!this.ctx)return[3,5];f=new Uint8ClampedArray(2*r*n),this.inProgress.forEach((function(t){return t.src=""})),this.inProgress=[],this.finished=0,d=new Set,t.forEach((function(t){d.add(s(lt({tile:t,maxZoom:c,tileSize:l})))})),p=Array.from(d).map((function(e){return i(_,void 0,void 0,(function(){var n=this;return o(this,(function(i){return[2,new Promise((function(i,o){var h=new Image;n.inProgress.push(h),h.onload=function(){t.filter((function(t){return e===s(lt({tile:t,maxZoom:c,tileSize:l}))})).forEach((function(t){var e=0,i=0,o=514===l?1:0,a=T,s=T;if(l!==T&&(e=t.x%2*T,i=t.y%2*T,a=T,s=T),t.z>c){var d=Math.pow(2,t.z-c);l!==T&&(e=Math.floor(t.x/d)%2*T,i=Math.floor(t.y/d)%2*T),e+=T*(t.x%d/d),i+=T*(t.y%d/d),a=T/d,s=T/d}n.ctx.clearRect(0,0,n.canvas.width,n.canvas.height),n.ctx.drawImage(h,o+e,o+i,a,s,0,0,a,s);for(var p=n.ctx.getImageData(0,0,a,s).data,x=new Uint8ClampedArray(131072),_=new Array(a*s),m=T/a,g=0;g<p.length;g+=4){var v=5*((y=u({r:p[g],g:p[g+1],b:p[g+2],a:0}))||0);_[g/4]=v}for(g=0;g<x.length;g+=2){var y=_[Math.floor(g/2/T/m)*a+Math.floor(g/2%T/m)],E=Math.floor(y/256),w=Math.floor(y%256);x[g]=E,x[g+1]=w}for(g=0;g<T;g++)f.set(x.slice(g*T*2,(g+1)*T*2),2*(t.yOffset*r+g*r+t.xOffset))})),i(null)},h.onerror=function(t){if(h.src!==h.originalSource)return o("new tiles requested");i(null)},h.crossOrigin=a||null,h.src=e,h.originalSource=h.src})).then((function(){n.finished++,h(n.finished,n.inProgress.length)}))]}))}))})),m.label=1;case 1:return m.trys.push([1,3,,4]),[4,Promise.all(p)];case 2:return m.sent(),[3,4];case 3:return x=m.sent(),console.log(p.length+" requests aborted",x),[2,null];case 4:return this.inProgress=[],[2,f];case 5:throw new Error("Could not get canvas context for merging tile images")}}))}))},t}(),ct=function(t,e){return[t.r/255,t.g/255,t.b/255,e]},ft=function(t,e){var r=e.date,n=A(r),i=n.dec,o=n.Hi;t.updateDate({dec:i,Hi:o})},dt=function(t,e){return i(void 0,void 0,void 0,(function(){return o(this,(function(r){switch(r.label){case 0:return[4,t.updateDateRange(n({},e))];case 1:return[2,r.sent()]}}))}))},pt=function(t,e){var r=e.color,n=e.opacity,i=ct(r,n);t.updateColor({colorVec:i})};new _([0,0],[0,0]);var xt=function(t){var e=t.kernel,r=t.map,i=t.heightMap,o=t.now,a=t.color,s=t.opacity;try{var u=i.maxHeight,l=i.maxBuildingHeight,h=i.width,c=i.height,f=i.DEMPixelBounds,d=i.imageData,p=i.visibleDEMPixelBounds,x=i.demZoom;if(0===h||0===c)return;var m=p.min,g=p.max;if(!m||!g)return;var v=g.subtract(m),y=v.x,E=v.y,w=f.min,b=r.getPixelDimensions(),M=r.screenUnproject([0,0]),U=r.screenUnproject([b.width,0]),P=r.screenUnproject([b.width,b.height]),D=[r.screenUnproject([0,b.height]),P,M,U].map((function(t){return r.project(t,x)})),L=D.map((function(t){return[(t.x-w.x)/h,(t.y-w.y)/c]})).flat(),C=D.map((function(t){return[(t.x-m.x)/y,(t.y-m.y)/E]})).map((function(t){return[2*t[0]-1,-1*(2*t[1]-1)]})).flat(),S=w.y/T/Math.pow(2,x),I=c/T/Math.pow(2,x),F=new _(R(f.getTopLeft(),x),R(f.getBottomRight(),x)),B=F.getWest(),N=Math.abs(F.getWest()-F.getEast());!function(t,e){var r=e.color,i=e.opacity,o=e.date,a=e.imageData,s=e.maxBuildingHeight,u=ct(r,i),l=A(o),h=l.dec,c=l.Hi;t.updateLocation(n({dec:h,Hi:c,colorVec:u,step:1},e)),at(a).then((function(e){var r=e.maxHeight;t.updateMaxHeight({maxHeight:Math.max(r,s)})}))}(e,{imageData:d,maxHeight:u,maxBuildingHeight:l,width:h,height:c,heightMapZoom:x,cornerTextureCoords:L,cornerClipCoords:C,topYCoord:S,ySize:I,west:B,dLng:N,date:o,color:a,opacity:s})}catch(t){console.error("EXCEPTION",t)}};var _t=function(t){var e=function(){return!t.getPitch};return{project:function(r,n){if(e())return t.project(r,n);var i=r.lat;return new c(function(t,e){return(t+180)/360*Math.pow(2,e)*T}(r.lng,n),function(t,e){return(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2*Math.pow(2,e)*T}(i,n))},unproject:function(r,n){return e()?t.unproject(r,n):new v((i=r.y,o=n,a=Math.PI-2*Math.PI*i/T/Math.pow(2,o),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/T/Math.pow(2,e)*360-180}(r.x,n));var i,o,a},screenUnproject:function(r){return e()?t.containerPointToLatLng(r):t.unproject(r)},getZoom:function(){return e()?t.getZoom():t.getZoom()+1},getCenter:function(){return t.getCenter()},getBounds:function(){return t.getBounds()},eachLayer:function(r){e()&&t.eachLayer(r)},getBearing:function(){return e()?0:t.getBearing()},getPitch:function(){return e()?0:t.getPitch()},rawMap:function(){return t},isLeaflet:e,getPixelDimensions:function(){var e=t.getContainer();return{width:e.clientWidth,height:e.clientHeight}},createBounds:function(t){var e=t.nw,r=t.se;return{getNorthWest:function(){return new v(e.lat,e.lng)},getNorthEast:function(){return new v(e.lat,r.lng)},getSouthWest:function(){return new v(r.lat,e.lng)},getSouthEast:function(){return new v(r.lat,r.lng)}}}}},mt=function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.addTo=function(t){return this.onAdd(t)},e.prototype.onAdd=function(t){if(this._map=t,!this._canvasOverlay&&this._canvas){var e=this._map.getBounds();this._canvasOverlay=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new(s.bind.apply(s,a([void 0],t)))}(this._canvas,e),this._canvasOverlay.addTo(this._map)}return this._map.on("moveend",this._reset),this._reset(),this},e.prototype._repositionCanvas=function(t){this._canvasOverlay&&this._canvasOverlay.setBounds(t)},e}(function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=t.call(this)||this;n.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:function(t){return t.x,t.y,t.z,"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/7/17/45.png"},getElevation:function(t){return 256*t.r+t.g+t.b/256-32768}},getFeatures:function(){return Promise.resolve([])},getSize:function(){return{width:Number.NaN,height:Number.NaN}},debug:function(t){}};var a=e[0];if(n.options=Object.assign(n.options,a),!n.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:n.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((function(t){return i(n,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return 200===t.status?[3,2]:(e=Error.bind,[4,t.text()]);case 1:throw new(e.apply(Error,[void 0,r.sent()]));case 2:return[2]}}))}))})).catch((function(t){return i(n,void 0,void 0,(function(){return o(this,(function(e){throw new Error("Could not load ShadeMap API. Key: "+this.options.apiKey+" Error: "+t)}))}))}));var s={preserveDrawingBuffer:!0,antialias:!1};return n._canvas=document.createElement("canvas"),n._gl=n._canvas.getContext("webgl",s)||n._canvas.getContext("experimental-webgl",s),n._compiledKernel=P({context:n._gl}),n._color=n._parseColor(n.options.color),n._buildingRasterizer=new D(n._gl),n._tileMerger=new ht,n._reset=n._reset.bind(n),n._draw=n._draw.bind(n),n}return r(e,t),e.prototype.onRemove=function(){return this._map&&this._map.off("moveend",this._reset),this},e.prototype.setDate=function(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(ft(this._compiledKernel,{date:this.options.date}),this._flush())):this.emit("idle"),this},e.prototype.setColor=function(t){return this.options.color!==t&&(this.options.color=t,this._color=this._parseColor(this.options.color),this._compiledKernel&&(pt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this},e.prototype.setOpacity=function(t){return this.options.opacity!==t&&(this.options.opacity=t,this._compiledKernel&&(pt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this},e.prototype.setSunExposure=function(t,e){return void 0===t&&(t=!1),i(this,void 0,void 0,(function(){var r,i,a,s,u;return o(this,(function(o){switch(o.label){case 0:return this._map&&this._compiledKernel?!1!==t?[3,1]:(this.options.sunExposure=n(n({},this.options.sunExposure),{enabled:t}),ft(this._compiledKernel,{date:this.options.date}),[3,3]):[3,4];case 1:if(i=(r=e).startDate,a=r.endDate,s=r.iterations,u=void 0===s?32:s,this.options.sunExposure={enabled:t,startDate:i,endDate:a,iterations:u},!(i instanceof Date&&a instanceof Date))throw new Error("Start date or end date or both are missing");if(a.getTime()<i.getTime())throw new Error("End date must come after the start date to calculate sun exposure");return[4,dt(this._compiledKernel,{startDate:i,endDate:a,iterations:u,emit:this.emit.bind(this)})];case 2:if(!0===o.sent())return[2,this];o.label=3;case 3:this._flush(),o.label=4;case 4:return[2,this]}}))}))},e.prototype._resizeCanvas=function(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.options.debug("_resize w:"+t+" h:"+e),this._canvas.width=t,this._canvas.height=e,this._gl.viewport(0,0,t,e)},e.prototype._lngLatToTextureCoords=function(t){if(this._heightMap){var e=this._heightMap,r=e.DEMPixelBounds,n=e.demZoom,i=e.width,o=e.height,a=r.min;return t.map((function(t){var e=w(t,n);return[(e.x-a.x)/i,(e.y-a.y)/o]}))}return[]},e.prototype._getBounds=function(t,e){var r=this.options.getSize(),n=r.width,i=r.height;if(Number.isNaN(n)||Number.isNaN(i))return t.getBounds();var o=t.getCenter(),a=w(o,e),s=R(new c(a.x-n/2,a.y-i/2),e),u=R(new c(a.x+n/2,a.y+i/2),e);return t.createBounds({nw:s,se:u})},e.prototype._getDEMZoom=function(t){var e=Math.min(this.options.terrainSource._overzoom||this.options.terrainSource.maxZoom,t.getZoom());return Math.round(e)},e.prototype._reset=function(){return i(this,void 0,void 0,(function(){var t,e,r,n=this;return o(this,(function(i){switch(i.label){case 0:if(this.options.debug("_reset()"),!this._map)return[3,3];t=_t(this._map),e=this._getDEMZoom(t);try{this._bounds=this._getBounds(t,e)}catch(t){return console.error("Invalid bounds returned: ",t),[2,this]}return[4,ut({gl:this._gl,demZoom:e,bounds:this._bounds,terrainSource:this.options.terrainSource,getFeatures:this.options.getFeatures,buildingRasterizer:this._buildingRasterizer,tileMerger:this._tileMerger,tileLoaded:function(t,e){return n.emit("tileloaded",t,e)}})];case 1:return r=i.sent(),this._heightMap=r,r.dirty?(this._resizeCanvas(r.outputWidth,r.outputHeight),[4,this._draw(r)]):[3,3];case 2:i.sent(),i.label=3;case 3:return[2,this]}}))}))},e.prototype._draw=function(t){return i(this,void 0,void 0,(function(){var e,r,n,i;return o(this,(function(o){switch(o.label){case 0:return this.options.debug("_draw()"),this._canvas&&this._compiledKernel&&this._map?(xt({kernel:this._compiledKernel,map:_t(this._map),heightMap:t,color:this._color,opacity:this.options.opacity,now:this.options.date,maxZoom:this.options.terrainSource.maxZoom}),this.options.sunExposure.enabled?(e=this.options.sunExposure,r=e.startDate,n=e.endDate,i=e.iterations,[4,dt(this._compiledKernel,{startDate:r,endDate:n,iterations:i,emit:this.emit.bind(this)})]):[3,2]):[3,3];case 1:if(!0===o.sent())return[2,this];o.label=2;case 2:this._repositionCanvas(this._bounds),o.label=3;case 3:return[2,this]}}))}))},e.prototype.readPixel=function(t,e){var r=new Uint8Array(4);return this._gl.readPixels(t,e,1,1,this._gl.RGBA,this._gl.UNSIGNED_BYTE,r),r},e.prototype.toGeoTiff=function(){var t=this;if(this._map){var e=this._canvas.width,r=this._canvas.height,n=function(e,r,n,i){var o=new Uint8Array(n*i*4);t._gl.readPixels(e,r,n,i,t._gl.RGBA,t._gl.UNSIGNED_BYTE,o);var a=n*i*1,s=1*n,u=(i-1)*s,l=new Uint8Array(a),h=new Uint8Array(a),c=0,f=t.options.sunExposure,d=f.startDate,p=f.endDate;t.options.sunExposure.enabled&&d&&p&&(c=p.getTime()-d.getTime());for(var x=0;x<o.length;x+=4){var _=void 0;if(t.options.sunExposure.enabled){var m=o.subarray(x,x+3),g=M(m,.5,c)/1e3/60,v=Math.min(Math.floor(g/6),255);_=new Uint8Array([v])}else _=o[x]+o[x+1]+o[x+2]===0?new Uint8Array([1]):new Uint8Array([0]);l.set(_,x/4*1)}for(x=0;x<a;x+=s)h.set(l.subarray(x,x+s),u-x);return h}(0,0,e,r),i=_t(this._map),o=i.getBounds().getNorthWest(),a=o.lat,s=o.lng,u=i.getBounds().getSouthEast(),l=[0,0,0,s,a,0],h=[(u.lng-s)/e,(a-u.lat)/r,0];return this.options.sunExposure.enabled,{data:n,metadata:{width:e,height:r,ModelTiepoint:l,ModelPixelScale:h,GeographicTypeGeoKey:4326,GeogCitationGeoKey:"WGS 84"}}}},e.prototype._generateShadeProfile=function(t){if(this._compiledKernel){var e=this._canvas.width,r=this._canvas.height;this._canvas.width=t.locations.length,this._canvas.height=t.dates.length;var i=this._lngLatToTextureCoords(t.locations),o=function(t,e){var r=ct({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=ct({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateShadeProfile(n(n({},e),{sunColor:r,shadeColor:i}))}(this._compiledKernel,n(n({},t),{texCoords:i}));return this._canvas.width=e,this._canvas.height=r,o}return new Uint8Array},e.prototype._generateLocationShadeProfile=function(t){if(this._compiledKernel){var e=this._canvas.width,r=this._canvas.height,i=t.startDate.getTime(),o=(t.endDate.getTime()-i)/86400/1e3,a=1440;this._canvas.width=o,this._canvas.height=a;for(var s=[],u=0;u<a;u++){for(var l=[],h=0;h<o;h++){var c=i+86400*h*1e3+60*u*1e3;l.push(new Date(c))}s.push(l)}var f=this._lngLatToTextureCoords([t.location])[0],d=function(t,e){var r=ct({r:e.sunColor[0],g:e.sunColor[1],b:e.sunColor[2]},1),i=ct({r:e.shadeColor[0],g:e.shadeColor[1],b:e.shadeColor[2]},1);return t.generateLocationShadeProfile(n(n({},e),{sunColor:r,shadeColor:i}))}(this._compiledKernel,n(n({},t),{dates:s,texCoord:f}));return this._canvas.width=e,this._canvas.height=r,d.toArray=function(){for(var e=new Array,r=0;r<o;r++){for(var n=[],i=1439;i>=0;i--){var a=i*o*4+4*r,s=this.slice(a,a+4);n.push(s.join("")===t.sunColor.join("")?1:0)}e.push(n)}return e},{data:d,width:o,height:a}}return{data:new Uint8Array,width:0,height:0}},e.prototype.getHoursOfSun=function(t,e){if(this.options.sunExposure.enabled){var r=this.readPixel(t,e),n=this.options.sunExposure,i=n.startDate,o=n.endDate.getTime()-i.getTime(),a=M(r,.5,o);return Math.abs(a/1e3/3600)}return 0},e.prototype._repositionCanvas=function(t){},e.prototype._flush=function(){},e.prototype.flushSync=function(){this._gl.finish()},e.prototype._parseColor=function(t){t=t.replace("#","");var 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},e}(L));return void 0!==window.L&&(window.L.shadeMap=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new(mt.bind.apply(mt,a([void 0],t)))}),mt}));
package/examples/map.html CHANGED
@@ -8,6 +8,7 @@
8
8
  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css" />
9
9
  <script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"></script>
10
10
  <script src='https://www.unpkg.com/suncalc@1.9.0/suncalc.js'></script>
11
+ <script src="https://unpkg.com/osmtogeojson/osmtogeojson.js"></script>
11
12
  <script src="../dist/leaflet-shadow-simulator.umd.min.js"></script>
12
13
  <style>
13
14
  body {
@@ -97,6 +98,35 @@
97
98
  tileSize: 256,
98
99
  getSourceUrl: ({ x, y, z }) => `https://s3.amazonaws.com/elevation-tiles-prod/terrarium/${z}/${x}/${y}.png`,
99
100
  getElevation: ({ r, g, b, a }) => (r * 256 + g + b / 256) - 32768,
101
+ _overzoom: 18,
102
+ },
103
+ getFeatures: async () => {
104
+ try {
105
+ if (map.getZoom() > 15) {
106
+ const bounds = map.getBounds();
107
+ const north = bounds.getNorth();
108
+ const south = bounds.getSouth();
109
+ const east = bounds.getEast();
110
+ const west = bounds.getWest();
111
+ const query = `https://overpass-api.de/api/interpreter?data=%2F*%0AThis%20has%20been%20generated%20by%20the%20overpass-turbo%20wizard.%0AThe%20original%20search%20was%3A%0A%E2%80%9Cbuilding%E2%80%9D%0A*%2F%0A%5Bout%3Ajson%5D%5Btimeout%3A25%5D%3B%0A%2F%2F%20gather%20results%0A%28%0A%20%20%2F%2F%20query%20part%20for%3A%20%E2%80%9Cbuilding%E2%80%9D%0A%20%20way%5B%22building%22%5D%28${south}%2C${west}%2C${north}%2C${east}%29%3B%0A%29%3B%0A%2F%2F%20print%20results%0Aout%20body%3B%0A%3E%3B%0Aout%20skel%20qt%3B`;
112
+ const response = await fetch(query)
113
+ const json = await response.json();
114
+ const geojson = osmtogeojson(json);
115
+ // If no building height, default to one storey of 3 meters
116
+ geojson.features.forEach(feature => {
117
+ if (!feature.properties) {
118
+ feature.properties = {};
119
+ }
120
+ if (!feature.properties.height) {
121
+ feature.properties.height = 3;
122
+ }
123
+ });
124
+ return geojson.features;
125
+ }
126
+ } catch (e) {
127
+ console.error(e);
128
+ }
129
+ return [];
100
130
  },
101
131
  debug: (msg) => { console.log(new Date().toISOString(), msg) }
102
132
  }).addTo(map);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leaflet-shadow-simulator",
3
- "version": "0.26.0",
3
+ "version": "0.29.1",
4
4
  "description": "Display terrain and structure shadows cast by the sun in a custom Leaflet layer",
5
5
  "main": "dist/leaflet-shadow-simulator.umd.min.js",
6
6
  "types": "dist/leaflet-shadow-simulator.d.ts",