mapbox-gl-shadow-simulator 0.20.0 → 0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -116,7 +116,7 @@ Property name | Type | Default value | Comment
116
116
  `date` | `Date` | `new Date()` | Sun's position in the sky is based on this date
117
117
  `color` | `String` | `#000` | 3 or 6 digit hexadecimal number
118
118
  `opacity` | `Number` | `0.3`
119
- `showExposure` | `Boolean` | `false` | If set to true, display full-day sun exposure for `date` (**Note:** requires [suncalc](https://www.npmjs.com/package/suncalc))
119
+ `sunExposure` | `Object` | See [sunExposure](#sunExposure) | Display sun exposure for provided date range
120
120
  `terrainSource` | `Object` | See [terrainSource](#terrainsource) | Specify DEM or DSM tiles containing terrain elevation data
121
121
  `getFeatures` | `Function` | See [getFeatures](#getfeatures) | Returns GeoJSON of objects, such as buildings, to display on the map
122
122
 
@@ -131,6 +131,17 @@ Property name | Type | Default value | Comment
131
131
  `sourceUrl` | `Function` | `Returns tile encoding 0m elevation for all locations` | Returns url of DEM tile for given `(x, y, z)` coordinate
132
132
  `getElevation` | `Function` | `return (r * 256 + g + b / 256) - 32768` | Returns elevation in meters for each (r,g,b,a) pixel of DEM tile
133
133
 
134
+ #### sunExposure
135
+
136
+ An object describing sun exposure settings
137
+ Property name | Type | Default value | Comment
138
+ :--- | :--- | :--- | :---
139
+ `enabled` | `Boolean` | `false` | Should sun exposure be displayed
140
+ `startDate` | `Date` | `new Date()` | Start date of sun exposure time interval
141
+ `endDate` | `Date` | `new Date()` | End date of sun exposure time interval
142
+ `iterations` | `number` | `32` | Number of discrete chunks to calculate shadows for between startDate and endDate. A larger number will provide more detail but take longer to compute.
143
+
144
+
134
145
  ##### Open Data on AWS for terrainSource
135
146
 
136
147
  A global dataset providing bare-earth terrain heights, tiled for easy usage and provided on S3 - [More info](https://registry.opendata.aws/terrain-tiles/)
@@ -207,7 +218,7 @@ getFeatures: () => {
207
218
 
208
219
  `setOpacity(opacity: Number)` - change shade opacity
209
220
 
210
- `setShowExposure(show: Boolean)` - toggle between shadows and full-day sun exposure for `date` (**Note:** requires [suncalc](https://www.npmjs.com/package/suncalc))
221
+ `setSunExposure(enabled: Boolean, options: SunExposureOptions)` - toggle between shadows and sun exposure mode
211
222
 
212
223
  `getHoursOfSun(x: Number, y: Number)` - if sun exposure mode enabled, returns the hours of sunlight for a given pixel on the map
213
224
 
@@ -26,11 +26,21 @@ interface TerrainSource {
26
26
  }) => number;
27
27
  }
28
28
 
29
+ export interface SunExposureOptions {
30
+ startDate: Date;
31
+ endDate: Date;
32
+ iterations?: number;
33
+ }
34
+
35
+ export interface SunExposure extends SunExposureOptions {
36
+ enabled: boolean;
37
+ }
38
+
29
39
  interface ShadeMapOptions {
30
40
  date?: Date;
31
41
  color?: string;
32
42
  opacity?: number;
33
- showExposure?: boolean;
43
+ sunExposure?: SunExposure;
34
44
  terrainSource?: TerrainSource;
35
45
  getFeatures?: () => Promise<MapboxGeoJSONFeature[]>;
36
46
  apiKey: string;
@@ -42,11 +52,17 @@ declare class export_default extends EventEmitter {
42
52
  setDate(date: Date): this;
43
53
  setColor(color: string): this;
44
54
  setOpacity(opacity: number): this;
45
- setShowExposure(show: boolean): this;
55
+ setSunExposure(enabled: boolean, options: SunExposureOptions): Promise<this>;
46
56
  readPixel(x: number, y: number): Uint8Array;
47
57
  getHoursOfSun(x: number, y: number): number;
48
58
  addTo(map: Map): this;
49
59
  remove(): void;
60
+ _generateShadeProfile(params: {
61
+ pixels: number[];
62
+ dates: Date[];
63
+ sunColor: string;
64
+ shadeColor: string;
65
+ }): Uint8Array;
50
66
  }
51
67
 
52
68
  export { export_default as default, ShadeMapOptions };
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Copyright Ted Piotrowski 2023
3
3
  * Package: mapbox-gl-shadow-simulator
4
- * Version: 0.20.0
4
+ * Version: 0.21.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("suncalc")):"function"==typeof define&&define.amd?define(["suncalc"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).ShadeMap=e(t.suncalc)}(this,(function(t){"use strict";function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=e(t),n=function(t,e){return(n=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,e)};function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var i=function(){return(i=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function a(t,e,r,n){return new(r||(r=Promise))((function(o,i){function a(t){try{s(n.next(t))}catch(t){i(t)}}function u(t){try{s(n.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,u)}s((n=n.apply(t,e||[])).next())}))}function u(t,e){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function s(t,e){for(var r=0,n=e.length,o=t.length;r<n;r++,o++)t[o]=e[r];return t}function l(t,e,r){var n=e[1],o=e[0],i=n-o;return t===n&&r?t:((t-o)%i+i)%i+o}function c(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 f(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var p=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function m(t,e,r){return t instanceof f?t:h(t)?new f(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new f(t.x,t.y):new f(t,e,r)}function d(t,e){if(t)for(var r=e?[t,e]:t,n=0,o=r.length;n<o;n++)this.extend(r[n])}function _(t,e){return!t||t instanceof d?t:new d(t,e)}function x(t,e){if(t)for(var r=e?[t,e]:t,n=0,o=r.length;n<o;n++)this.extend(r[n])}function g(t,e){return t instanceof x?t:new x(t,e)}f.prototype={clone:function(){return new f(this.x,this.y)},add:function(t){return this.clone()._add(m(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(m(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 f(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new f(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=p(this.x),this.y=p(this.y),this},distanceTo:function(t){var e=(t=m(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=m(t)).x===this.x&&t.y===this.y},contains:function(t){return t=m(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+c(this.x)+", "+c(this.y)+")"}},d.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof f||"number"==typeof t[0]||"x"in t)e=r=m(t);else if(e=(t=_(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 m((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return m(this.min.x,this.max.y)},getTopRight:function(){return m(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 f?m(t):_(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=_(t);var e=this.min,r=this.max,n=t.min,o=t.max,i=o.x>=e.x&&n.x<=r.x,a=o.y>=e.y&&n.y<=r.y;return i&&a},overlaps:function(t){t=_(t);var e=this.min,r=this.max,n=t.min,o=t.max,i=o.x>e.x&&n.x<r.x,a=o.y>e.y&&n.y<r.y;return i&&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,o=Math.abs(e.y-r.y)*t;return _(m(e.x-n,e.y-o),m(r.x+n,r.y+o))},equals:function(t){return!!t&&(t=_(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},x.prototype={extend:function(t){var e,r,n=this._southWest,o=this._northEast;if(t instanceof y)e=t,r=t;else{if(!(t instanceof x))return t?this.extend(E(t)||g(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return n||o?(n.lat=Math.min(e.lat,n.lat),n.lng=Math.min(e.lng,n.lng),o.lat=Math.max(r.lat,o.lat),o.lng=Math.max(r.lng,o.lng)):(this._southWest=new y(e.lat,e.lng),this._northEast=new y(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,n=Math.abs(e.lat-r.lat)*t,o=Math.abs(e.lng-r.lng)*t;return new x(new y(e.lat-n,e.lng-o),new y(r.lat+n,r.lng+o))},getCenter:function(){return new y((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 y(this.getNorth(),this.getWest())},getSouthEast:function(){return new y(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 y||"lat"in t?E(t):g(t);var e,r,n=this._southWest,o=this._northEast;return t instanceof x?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=n.lat&&r.lat<=o.lat&&e.lng>=n.lng&&r.lng<=o.lng},intersects:function(t){t=g(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),o=t.getNorthEast(),i=o.lat>=e.lat&&n.lat<=r.lat,a=o.lng>=e.lng&&n.lng<=r.lng;return i&&a},overlaps:function(t){t=g(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),o=t.getNorthEast(),i=o.lat>e.lat&&n.lat<r.lat,a=o.lng>e.lng&&n.lng<r.lng;return i&&a},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=g(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var v=function(t){var e,r,n,o;for(r=1,n=arguments.length;r<n;r++)for(e in o=arguments[r])t[e]=o[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?l(t.lng,this.wrapLng,!0):t.lng;return new y(this.wrapLat?l(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,o=e.lng-r.lng;if(0===n&&0===o)return t;var i=t.getSouthWest(),a=t.getNorthEast();return new x(new y(i.lat-n,i.lng-o),new y(a.lat-n,a.lng-o))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,n=t.lat*r,o=e.lat*r,i=Math.sin((e.lat-t.lat)*r/2),a=Math.sin((e.lng-t.lng)*r/2),u=i*i+Math.cos(n)*Math.cos(o)*a*a,s=2*Math.atan2(Math.sqrt(u),Math.sqrt(1-u));return this.R*s}});function y(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 E(t,e,r){return t instanceof y?t:h(t)&&"object"!=typeof t[0]?3===t.length?new y(t[0],t[1],t[2]):2===t.length?new y(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new y(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new y(t,e,r)}y.prototype={equals:function(t,e){return!!t&&(t=E(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("+c(this.lat,t)+", "+c(this.lng,t)+")"},distanceTo:function(t){return v.distance(this,E(t))},wrap:function(){return v.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return g([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new y(this.lat,this.lng,this.alt)}};var T=8848,w=256;var R,b=function(t){var e=function(){return!t.getPitch};return{project:function(r,n){if(e())return t.project(r,n);var o=r.lat;return new f(function(t,e){return(t+180)/360*Math.pow(2,e)*w}(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)*w}(o,n))},unproject:function(r,n){return e()?t.unproject(r,n):new y((o=r.y,i=n,a=Math.PI-2*Math.PI*o/w/Math.pow(2,i),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/w/Math.pow(2,e)*360-180}(r.x,n));var o,i,a},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}},M=function(t){var e=function(t,e,r){var n=t.createShader(t.VERTEX_SHADER);if(null===n)return null;t.shaderSource(n,e),t.compileShader(n);var o=t.createShader(t.FRAGMENT_SHADER);if(null===o)return null;t.shaderSource(o,r),t.compileShader(o);var i=t.createProgram();if(null===i)return null;t.attachShader(i,n),t.attachShader(i,o),t.linkProgram(i),t.getProgramParameter(i,t.LINK_STATUS)||console.log(t.getProgramInfoLog(i));return i}(t,"\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","\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"),r=t.getAttribLocation(e,"a_position"),n=t.getUniformLocation(e,"xyz"),o=t.getUniformLocation(e,"dimensions"),i=t.getUniformLocation(e,"height_map"),a=t.getUniformLocation(e,"color"),u=t.createBuffer(),s=t.createBuffer(),l=t.createTexture();R={program:e,positionAttributeLocation:r,xyzUniformLocation:n,dimensionsUniformLocation:o,heightMapUniformLocation:i,colorUniformLocation:a,positionBuffer:u,indexBuffer:s,targetTexture:l}};var S=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]&&s([],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=[],o=0;o<arguments.length;o++)t[o]=arguments[o];n(),e.apply(r,t)}));return n},t}();function A(t,e,r){r=r||2;var n,o,i,a,u,s,l,c=e&&e.length,h=c?e[0]*r:t.length,f=L(t,0,h,r,!0),p=[];if(!f||f.next===f.prev)return p;if(c&&(f=function(t,e,r,n){var o,i,a,u=[];for(o=0,i=e.length;o<i;o++)(a=L(t,e[o]*n,o<i-1?e[o+1]*n:t.length,n,!1))===a.next&&(a.steiner=!0),u.push(O(a));for(u.sort(B),o=0;o<u.length;o++)r=N(u[o],r);return r}(t,e,f,r)),t.length>80*r){n=i=t[0],o=a=t[1];for(var m=r;m<h;m+=r)(u=t[m])<n&&(n=u),(s=t[m+1])<o&&(o=s),u>i&&(i=u),s>a&&(a=s);l=0!==(l=Math.max(i-n,a-o))?32767/l:0}return U(f,p,r,n,o,l,0),p}function L(t,e,r,n,o){var i,a;if(o===Q(t,e,r,n)>0)for(i=e;i<r;i+=n)a=V(i,t[i],t[i+1],a);else for(i=r-n;i>=e;i-=n)a=V(i,t[i],t[i+1],a);return a&&Z(a,a.next)&&(J(a),a=a.next),a}function P(t,e){if(!t)return t;e||(e=t);var r,n=t;do{if(r=!1,n.steiner||!Z(n,n.next)&&0!==G(n.prev,n,n.next))n=n.next;else{if(J(n),(n=e=n.prev)===n.next)break;r=!0}}while(r||n!==e);return e}function U(t,e,r,n,o,i,a){if(t){!a&&i&&function(t,e,r,n){var o=t;do{0===o.z&&(o.z=H(o.x,o.y,e,r,n)),o.prevZ=o.prev,o.nextZ=o.next,o=o.next}while(o!==t);o.prevZ.nextZ=null,o.prevZ=null,function(t){var e,r,n,o,i,a,u,s,l=1;do{for(r=t,t=null,i=null,a=0;r;){for(a++,n=r,u=0,e=0;e<l&&(u++,n=n.nextZ);e++);for(s=l;u>0||s>0&&n;)0!==u&&(0===s||!n||r.z<=n.z)?(o=r,r=r.nextZ,u--):(o=n,n=n.nextZ,s--),i?i.nextZ=o:t=o,o.prevZ=i,i=o;r=n}i.nextZ=null,l*=2}while(a>1)}(o)}(t,n,o,i);for(var u,s,l=t;t.prev!==t.next;)if(u=t.prev,s=t.next,i?I(t,n,o,i):D(t))e.push(u.i/r|0),e.push(t.i/r|0),e.push(s.i/r|0),J(t),t=s.next,l=s.next;else if((t=s)===l){a?1===a?U(t=C(P(t),e,r),e,r,n,o,i,2):2===a&&F(t,e,r,n,o,i):U(P(t),e,r,n,o,i,1);break}}}function D(t){var e=t.prev,r=t,n=t.next;if(G(e,r,n)>=0)return!1;for(var o=e.x,i=r.x,a=n.x,u=e.y,s=r.y,l=n.y,c=o<i?o<a?o:a:i<a?i:a,h=u<s?u<l?u:l:s<l?s:l,f=o>i?o>a?o:a:i>a?i:a,p=u>s?u>l?u:l:s>l?s:l,m=n.next;m!==e;){if(m.x>=c&&m.x<=f&&m.y>=h&&m.y<=p&&z(o,u,i,s,a,l,m.x,m.y)&&G(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function I(t,e,r,n){var o=t.prev,i=t,a=t.next;if(G(o,i,a)>=0)return!1;for(var u=o.x,s=i.x,l=a.x,c=o.y,h=i.y,f=a.y,p=u<s?u<l?u:l:s<l?s:l,m=c<h?c<f?c:f:h<f?h:f,d=u>s?u>l?u:l:s>l?s:l,_=c>h?c>f?c:f:h>f?h:f,x=H(p,m,e,r,n),g=H(d,_,e,r,n),v=t.prevZ,y=t.nextZ;v&&v.z>=x&&y&&y.z<=g;){if(v.x>=p&&v.x<=d&&v.y>=m&&v.y<=_&&v!==o&&v!==a&&z(u,c,s,h,l,f,v.x,v.y)&&G(v.prev,v,v.next)>=0)return!1;if(v=v.prevZ,y.x>=p&&y.x<=d&&y.y>=m&&y.y<=_&&y!==o&&y!==a&&z(u,c,s,h,l,f,y.x,y.y)&&G(y.prev,y,y.next)>=0)return!1;y=y.nextZ}for(;v&&v.z>=x;){if(v.x>=p&&v.x<=d&&v.y>=m&&v.y<=_&&v!==o&&v!==a&&z(u,c,s,h,l,f,v.x,v.y)&&G(v.prev,v,v.next)>=0)return!1;v=v.prevZ}for(;y&&y.z<=g;){if(y.x>=p&&y.x<=d&&y.y>=m&&y.y<=_&&y!==o&&y!==a&&z(u,c,s,h,l,f,y.x,y.y)&&G(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function C(t,e,r){var n=t;do{var o=n.prev,i=n.next.next;!Z(o,i)&&j(o,n,n.next,i)&&q(o,i)&&q(i,o)&&(e.push(o.i/r|0),e.push(n.i/r|0),e.push(i.i/r|0),J(n),J(n.next),n=t=i),n=n.next}while(n!==t);return P(n)}function F(t,e,r,n,o,i){var a=t;do{for(var u=a.next.next;u!==a.prev;){if(a.i!==u.i&&W(a,u)){var s=K(a,u);return a=P(a,a.next),s=P(s,s.next),U(a,e,r,n,o,i,0),void U(s,e,r,n,o,i,0)}u=u.next}a=a.next}while(a!==t)}function B(t,e){return t.x-e.x}function N(t,e){var r=function(t,e){var r,n=e,o=t.x,i=t.y,a=-1/0;do{if(i<=n.y&&i>=n.next.y&&n.next.y!==n.y){var u=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(u<=o&&u>a&&(a=u,r=n.x<n.next.x?n:n.next,u===o))return r}n=n.next}while(n!==e);if(!r)return null;var s,l=r,c=r.x,h=r.y,f=1/0;n=r;do{o>=n.x&&n.x>=c&&o!==n.x&&z(i<h?o:a,i,c,h,i<h?a:o,i,n.x,n.y)&&(s=Math.abs(i-n.y)/(o-n.x),q(n,t)&&(s<f||s===f&&(n.x>r.x||n.x===r.x&&X(r,n)))&&(r=n,f=s)),n=n.next}while(n!==l);return r}(t,e);if(!r)return e;var n=K(r,t);return P(n,n.next),P(r,r.next)}function X(t,e){return G(t.prev,t,e.prev)<0&&G(e.next,t,t.next)<0}function H(t,e,r,n,o){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*o|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-n)*o|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function O(t){var e=t,r=t;do{(e.x<r.x||e.x===r.x&&e.y<r.y)&&(r=e),e=e.next}while(e!==t);return r}function z(t,e,r,n,o,i,a,u){return(o-a)*(e-u)>=(t-a)*(i-u)&&(t-a)*(n-u)>=(r-a)*(e-u)&&(r-a)*(i-u)>=(o-a)*(n-u)}function W(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&&j(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(q(t,e)&&q(e,t)&&function(t,e){var r=t,n=!1,o=(t.x+e.x)/2,i=(t.y+e.y)/2;do{r.y>i!=r.next.y>i&&r.next.y!==r.y&&o<(r.next.x-r.x)*(i-r.y)/(r.next.y-r.y)+r.x&&(n=!n),r=r.next}while(r!==t);return n}(t,e)&&(G(t.prev,t,e.prev)||G(t,e.prev,e))||Z(t,e)&&G(t.prev,t,t.next)>0&&G(e.prev,e,e.next)>0)}function G(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function Z(t,e){return t.x===e.x&&t.y===e.y}function j(t,e,r,n){var o=k(G(t,e,r)),i=k(G(t,e,n)),a=k(G(r,n,t)),u=k(G(r,n,e));return o!==i&&a!==u||(!(0!==o||!Y(t,r,e))||(!(0!==i||!Y(t,n,e))||(!(0!==a||!Y(r,t,n))||!(0!==u||!Y(r,e,n)))))}function Y(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 k(t){return t>0?1:t<0?-1:0}function q(t,e){return G(t.prev,t,t.next)<0?G(t,e,t.next)>=0&&G(t,t.prev,e)>=0:G(t,e,t.prev)<0||G(t,t.next,e)<0}function K(t,e){var r=new $(t.i,t.x,t.y),n=new $(e.i,e.x,e.y),o=t.next,i=e.prev;return t.next=e,e.prev=t,r.next=o,o.prev=r,n.next=r,r.prev=n,i.next=n,n.prev=i,n}function V(t,e,r,n){var o=new $(t,e,r);return n?(o.next=n.next,o.prev=n,n.next.prev=o,n.next=o):(o.prev=o,o.next=o),o}function J(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function $(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function Q(t,e,r,n){for(var o=0,i=e,a=r-n;i<r;i+=n)o+=(t[a]-t[i])*(t[i+1]+t[a+1]),a=i;return o}function tt(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 n=0;n<r.coordinates.length;n++)t.push(i(i({},e),{geometry:i(i({},r),{type:"Polygon",coordinates:r.coordinates[n]})}))})),t.filter((function(t){return"Polygon"===t.geometry.type})).map((function(t){var e=t.geometry,r=t.properties,n=A.flatten(e.coordinates).vertices,o=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}))),i=A(n);return{aPosition:o,cuts:i.length>256?new Uint16Array(i):new Uint8Array(i),buildingHeight:function(t){var e=t,r=e.height,n=void 0===r?0:r,o=e.levels,i=void 0===o?0:o,a=e.render_height,u=void 0===a?0:a;if(i)return 3.04*i;return Math.max(n,u)}(r),startPos:[n[0],n[1]]}}))}A.deviation=function(t,e,r,n){var o=e&&e.length,i=o?e[0]*r:t.length,a=Math.abs(Q(t,0,i,r));if(o)for(var u=0,s=e.length;u<s;u++){var l=e[u]*r,c=u<s-1?e[u+1]*r:t.length;a-=Math.abs(Q(t,l,c,r))}var h=0;for(u=0;u<n.length;u+=3){var f=n[u]*r,p=n[u+1]*r,m=n[u+2]*r;h+=Math.abs((t[f]-t[m])*(t[p+1]-t[f+1])-(t[f]-t[p])*(t[m+1]-t[f+1]))}return 0===a&&0===h?0:Math.abs((h-a)/a)},A.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},n=0,o=0;o<t.length;o++){for(var i=0;i<t[o].length;i++)for(var a=0;a<e;a++)r.vertices.push(t[o][i][a]);o>0&&(n+=t[o-1].length,r.holes.push(n))}return r};var et=.40909994067971484,rt=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,o=Math.atan2(Math.sin(n)*Math.cos(et),Math.cos(n));return{dec:Math.asin(Math.sin(et)*Math.sin(n)),Hi:(4.889714432387314+6.3003876824396166*e-o)%(2*Math.PI)+2*Math.PI}},nt=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,o=(256*(r>>16&255)+(r>>24&255))/5,Math.max(n,o)));var r,n,o}),0);e({maxHeight:Math.min(T,n)})}))},ot=document.createElement("canvas"),it=ot.getContext("2d",{antialias:!1,alpha:!1});null!==it&&(it.imageSmoothingEnabled=!1),ot.width=w,ot.height=w;var at,ut=[],st=0,lt={width:0,height:0,tileLatLngBounds:new x(new y(0,0),new y(0,0)),imageData:new Uint8ClampedArray(0),visibleDEMPixelBounds:new d(new f(0,0),new f(0,0)),maxHeight:T,maxBuildingHeight:0,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0},ct=function(t){return a(void 0,void 0,void 0,(function(){var e,r,n,o,s,l,c,h,p,m,_,g,v,y,E,b,M,S,A,L,P,U,D,I,C,F,B,N,X,H,O,z,W,G,Z,j,Y,k,q,K,V;return u(this,(function(J){switch(J.label){case 0:e=t.map,r=t.getFeatures,n=t.terrainSource,o=t.tileLoaded,s=t.gl,l=t.bounds,c=n.getSourceUrl,h=n.getElevation,p=n.maxZoom,m=n.tileSize,rt={map:e,getFeatures:r},_=a(void 0,void 0,void 0,(function(){var t,e,r,n;return u(this,(function(o){switch(o.label){case 0:t=rt.map,e=rt.getFeatures,o.label=1;case 1:return o.trys.push([1,3,,4]),r=tt,[4,e()];case 2:return[2,r.apply(void 0,[o.sent(),t])];case 3:return n=o.sent(),console.log("Error merging buildings",n),[3,4];case 4:return[2,[]]}}))})),g=e.getZoom(),J.label=1;case 1:return J.trys.push([1,4,,5]),g=Math.min(p,g),v=Math.round(g),E=(y=l).getNorthWest(),b=y.getSouthEast(),M=new d(e.project(E,g),e.project(b,g)),S=M.max.x-M.min.x,A=M.max.y-M.min.y,L=new d(e.project(E,v),e.project(b,v)),P=new f(L.min.x,L.min.y),U=L.max.x-L.min.x,D=L.max.y-L.min.y,(I=L.max.subtract(L.min)).y>I.x&&(P.x-=w,U+=512),C=function(t){for(var e=t.upperLeft,r=t.zoom,n=t.innerWidth,o=t.innerHeight,i=e.divideBy(w).floor(),a=i.x+Math.floor((n+w)/w),u=Math.min(i.y+Math.floor((o+w)/w),Math.pow(2,r)-1),s=[],l=i.x;l<=a;l++)for(var c=i.y;c<=u;c++)s.push({x:l,y:c,z:r});return s}({upperLeft:P,zoom:v,innerWidth:U,innerHeight:D}),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)*w,yOffset:(t.y-r)*w}}))}(C),(B=JSON.stringify(F))===at&&v<p?[2,lt=i(i({},lt),{visibleDEMPixelBounds:L,demZoom:v,dirty:!0})]:(at=B,N={width:(et=F).reduce((function(t,e){return e.xOffset>t.xOffset?e:t})).xOffset+w,height:et.reduce((function(t,e){return e.yOffset>t.yOffset?e:t})).yOffset+w},[4,($=F,Q={width:X=N.width,height:H=N.height,crossOrigin:"Anonymous",getSourceUrl:c,getElevation:h,tileSize:m,tileLoaded:o},a(void 0,void 0,void 0,(function(){var t,e,r,n,o,i,s,l,c,h,f;return u(this,(function(p){switch(p.label){case 0:if(t=Q.width,e=Q.height,r=Q.crossOrigin,n=Q.getSourceUrl,o=Q.getElevation,i=Q.tileSize,s=Q.tileLoaded,!it)return[3,5];l=new Uint8ClampedArray(2*t*e),ut.forEach((function(t){return t.src=""})),ut=[],st=0,c=new Set,$.forEach((function(t){var e=i===w?t.x:Math.floor(t.x/2),r=i===w?t.y:Math.floor(t.y/2),o=i===w?t.z:t.z-1;c.add(n({x:e,y:r,z:o}))})),h=Array.from(c).map((function(e){return a(void 0,void 0,void 0,(function(){return u(this,(function(a){return[2,new Promise((function(a,u){var s=new Image;ut.push(s),s.onload=function(){$.filter((function(t){var r=i===w?t.x:Math.floor(t.x/2),o=i===w?t.y:Math.floor(t.y/2),a=i===w?t.z:t.z-1;return e===n({x:r,y:o,z:a})})).forEach((function(e){if(i===w)it.drawImage(s,0,0,w,w);else{var r=514===i?1:0,n=e.x%2*w,a=e.y%2*w;it.drawImage(s,n,a,w+r,w+r,0,0,w,w)}for(var u=it.getImageData(0,0,w,w).data,c=0;c<u.length;c+=4){var h=5*(o({r:u[c],g:u[c+1],b:u[c+2],a:0})||0),f=Math.floor(h/256),p=Math.floor(h%256);u[c/2]=f,u[c/2+1]=p}for(c=0;c<w;c++)l.set(u.slice(c*w*2,(c+1)*w*2),2*(e.yOffset*t+c*t+e.xOffset))})),a(null)},s.onerror=function(t){if(s.src!==s.originalSource)return u("new tiles requested");a(null)},s.crossOrigin=r||null,s.src=e,s.originalSource=s.src})).then((function(){st++,s(st,ut.length)}))]}))}))})),p.label=1;case 1:return p.trys.push([1,3,,4]),[4,Promise.all(h)];case 2:return p.sent(),[3,4];case 3:return f=p.sent(),console.log(h.length+" requests aborted",f),[2,null];case 4:return ut=[],[2,l];case 5:throw new Error("Could not get canvas context for merging tile images")}}))})))]);case 2:return null===(O=J.sent())?[2,lt=i(i({},lt),{visibleDEMPixelBounds:L,demZoom:v,dirty:!1})]:(z=function(t){var e=t.upperLeft,r=t.width,n=t.height,o=e.divideBy(w).floor().multiplyBy(w),i=o.add([r,n]);return new d(o,i)}({upperLeft:P,width:X,height:H}),W=new x(e.unproject(z.getTopLeft(),v),e.unproject(z.getBottomRight(),v)),G=0,[4,_]);case 3:return Z=J.sent(),G=function(t){var e=t.features,r=t.upperLeftTile,n=t.map,o=t.width,i=t.height,a=t.imageData,u=t.gl,s=r.x,l=r.y,c=r.z,h=R.program,p=R.positionAttributeLocation,m=R.xyzUniformLocation,d=R.dimensionsUniformLocation,_=R.heightMapUniformLocation,x=R.colorUniformLocation,g=R.positionBuffer,v=R.indexBuffer,y=R.targetTexture,E=0;u.useProgram(h),u.activeTexture(u.TEXTURE1);var T=u.createTexture();u.bindTexture(u.TEXTURE_2D,T),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,i,0,u.LUMINANCE_ALPHA,u.UNSIGNED_BYTE,a);var b=o*(n.getZoom()>15?2:1),M=i*(n.getZoom()>15?2:1);u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,y),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,b,M,0,u.RGBA,u.UNSIGNED_BYTE,null),n.getZoom()>15&&e.length>0?(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,b,M);var S=u.createFramebuffer();u.bindFramebuffer(u.FRAMEBUFFER,S);var A=u.COLOR_ATTACHMENT0;u.framebufferTexture2D(u.FRAMEBUFFER,A,u.TEXTURE_2D,y,0),u.bindBuffer(u.ARRAY_BUFFER,g),u.bindBuffer(u.ELEMENT_ARRAY_BUFFER,v),u.clearColor(0,0,0,0),u.clear(u.COLOR_BUFFER_BIT);var L=s*w,P=l*w,U=new f(L,P);u.uniform3f(m,L,P,c),u.uniform2f(d,o,i),u.uniform1i(_,1);var D=new Float32Array([-1,-1,1,-1,-1,1,1,1]);return u.enableVertexAttribArray(p),u.bufferData(u.ARRAY_BUFFER,D,u.STATIC_DRAW),u.vertexAttribPointer(p,2,u.FLOAT,!1,0,0),u.uniform4f(x,0,0,0,0),u.drawArrays(u.TRIANGLE_STRIP,0,4),e.forEach((function(t){var e=t.buildingHeight,r=t.aPosition,i=t.cuts,s=t.startPos,l=n.project({lng:s[0],lat:s[1]},c).subtract(U).floor(),h=256*a[l.y*o*2+2*l.x]+a[l.y*o*2+2*l.x+1]+5*e;if(!Number.isNaN(h)){var f=Math.floor(h/256)/256,m=Math.floor(h%256)/256;E=Math.max(E,h/5),u.uniform4f(x,f,m,0,1),u.bufferData(u.ARRAY_BUFFER,r,u.DYNAMIC_DRAW),u.vertexAttribPointer(p,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.deleteTexture(T),E}({upperLeftTile:F[0],width:X,height:H,map:e,features:Z,imageData:O,screenPixelBounds:M,gl:s}),T,j=window.innerWidth*window.innerHeight,Y=S*A,k=Math.sqrt(j/Y),q=Math.round(S*k),K=Math.round(A*k),lt={maxHeight:8848,maxBuildingHeight:G,width:X,height:H,tileLatLngBounds:W,imageData:O,visibleDEMPixelBounds:L,raster:F,demZoom:v,dirty:!0,outputWidth:q,outputHeight:K},[3,5];case 4:return V=J.sent(),console.error("Could not decode height map",V),[3,5];case 5:return[2,lt]}var $,Q,et,rt}))}))},ht=function(t,e){return[t.r/255,t.g/255,t.b/255,e]},ft=function(t,e){var r=e.date,n=rt(r),o=n.dec,i=n.Hi;t.updateDate({dec:o,Hi:i})},pt=function(t,e){return a(void 0,void 0,void 0,(function(){return u(this,(function(r){switch(r.label){case 0:return[4,t.updateDateRange(i({},e))];case 1:return[2,r.sent()]}}))}))},mt=function(t,e){var r=e.color,n=e.opacity,o=ht(r,n);t.updateColor({colorVec:o})};new x([0,0],[0,0]);var dt=function(t){var e=t.kernel,r=t.map,n=t.heightMap,o=t.now,a=t.color,u=t.opacity,s=t.maxZoom;try{var l=n.maxHeight,c=n.maxBuildingHeight,h=n.width,f=n.height,p=n.tileLatLngBounds,m=n.imageData,d=n.visibleDEMPixelBounds,_=n.demZoom;if(0===h||0===f)return;var x=d.min,g=d.max;if(!x||!g)return;var v=g.subtract(x).divideBy(_>s?Math.pow(2,_-s):1),y=v.x,E=v.y,T=r.project(p.getNorthWest(),_),R=x.divideBy(_>s?Math.pow(2,_-s):1).subtract(T),b=R.x,M=R.y,S=b/h,A=M/f,L=S+y/h,P=A+E/f,U=T.y/w/Math.pow(2,_),D=f/w/Math.pow(2,_),I=p.getWest(),C=Math.abs(p.getWest()-p.getEast())/h;!function(t,e){var r=e.color,n=e.opacity,o=e.date,a=e.imageData,u=e.maxBuildingHeight,s=ht(r,n),l=rt(o),c=l.dec,h=l.Hi;t.updateLocation(i({dec:c,Hi:h,colorVec:s,step:1},e)),nt(a).then((function(e){var r=e.maxHeight;t.updateMaxHeight({maxHeight:Math.max(r,u)})}))}(e,{imageData:m,maxHeight:l,maxBuildingHeight:c,width:h,height:f,date:o,heightMapZoom:_,mapZoom:r.getZoom(),xStart:S,yStart:A,xEnd:L,yEnd:P,topYCoord:U,ySize:D,color:a,opacity:u,west:I,dLng:C})}catch(t){console.error("EXCEPTION",t)}};function _t(t){var e=this,r=t.context,n=function(t){var e=t.gl,r=t.vSrc,n=t.fSrc,o=e.createShader(e.VERTEX_SHADER);e.shaderSource(o,r),e.compileShader(o);var i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(i,n),e.compileShader(i);var a=e.createProgram();return e.attachShader(a,o),e.attachShader(a,i),e.linkProgram(a),e.getProgramParameter(a,e.LINK_STATUS)||(console.error("Link failed: "+e.getProgramInfoLog(a)),console.error("vs info-log: "+e.getShaderInfoLog(o)),console.error("fs info-log: "+e.getShaderInfoLog(i))),a}({gl:r,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 aPos;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(aPos,0,1);vec4 textureSpace=gl_Position*0.5+0.5;vTexCoordCropped=vec2((user_xEnd-user_xStart)*textureSpace.x+user_xStart,(user_yEnd-user_yStart)*(1.0-textureSpace.y)+user_yStart);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;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(.5,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*user_width));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 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(user_z<cur_height){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;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(user_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+user_exposureDelta);}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 o=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,o);var i=new Float32Array([-1,-1,1,-1,-1,1,1,1]);r.bufferData(r.ARRAY_BUFFER,i,r.STATIC_DRAW);var s=r.getAttribLocation(n,"aPos");r.enableVertexAttribArray(s),r.vertexAttribPointer(s,2,r.FLOAT,!1,0,0),r.enable(r.BLEND),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA);var l=r.getUniformLocation(n,"user_a");r.uniform1i(l,0);var c=r.getUniformLocation(n,"user_width"),h=r.getUniformLocation(n,"user_height"),f=r.getUniformLocation(n,"user_maxHeight"),p=r.getUniformLocation(n,"user_zoom"),m=r.getUniformLocation(n,"user_topYCoord"),d=r.getUniformLocation(n,"user_ySize"),_=r.getUniformLocation(n,"user_step"),x=r.getUniformLocation(n,"user_west"),g=r.getUniformLocation(n,"user_dLng"),v=r.getUniformLocation(n,"user_dec"),y=r.getUniformLocation(n,"user_Hi"),E=r.getUniformLocation(n,"user_color"),T=r.getUniformLocation(n,"user_xStart"),w=r.getUniformLocation(n,"user_yStart"),R=r.getUniformLocation(n,"user_xEnd"),b=r.getUniformLocation(n,"user_yEnd"),M=r.getUniformLocation(n,"user_sunExposureTexture");r.uniform1i(M,2);var S=r.getUniformLocation(n,"user_renderToSunExposureTexture"),A=r.getUniformLocation(n,"user_outputSunExposure"),L=r.getUniformLocation(n,"user_exposureDelta"),P=r.getUniformLocation(n,"u_outputShadeProfile"),U=r.getUniformLocation(n,"u_gpxTexture"),D=r.getUniformLocation(n,"u_decHiTexture"),I=r.getUniformLocation(n,"u_sunColor"),C=function(){r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4)},F=0;return{updateLocation:function(t){t.imageData;var e=t.width,i=t.height,a=t.maxHeight,u=t.heightMapZoom;t.mapZoom;var l=t.topYCoord,M=t.ySize,S=t.colorVec,A=t.step,L=t.west,P=t.dLng,U=t.dec,D=t.Hi,I=t.xStart,F=t.xEnd,B=t.yStart,N=t.yEnd;r.useProgram(n),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindBuffer(r.ARRAY_BUFFER,o),r.vertexAttribPointer(s,2,r.FLOAT,!1,0,0),r.uniform1f(c,e),r.uniform1f(h,i),r.uniform1f(f,a),r.uniform1f(p,u),r.uniform1f(m,l),r.uniform1f(d,M),r.uniform4fv(E,S),r.uniform1f(_,A),r.uniform1f(x,L),r.uniform1f(g,P),r.uniform1f(v,U),r.uniform1f(y,D),r.uniform1f(T,I),r.uniform1f(w,B),r.uniform1f(R,F),r.uniform1f(b,N),window.requestAnimationFrame(C)},updateViewport:function(t){var e=t.xStart,n=t.yStart,o=t.xEnd,i=t.yEnd;r.uniform1f(T,e),r.uniform1f(w,n),r.uniform1f(R,o),r.uniform1f(b,i),window.requestAnimationFrame(C)},updateDate:function(t){var e=t.dec,n=t.Hi;r.uniform1f(v,e),r.uniform1f(y,n),window.requestAnimationFrame(C)},updateDateRange:function(t){return a(e,void 0,void 0,(function(){var e,n,o,i,a,s,l,c,h,f,p,m,d,_,x;return u(this,(function(g){switch(g.label){case 0:e=t.start,n=t.end,o=t.emit,i=F=Date.now(),a=25,r.uniform4fv(L,new Float32Array([1/a,0,0,0])),s=Math.floor((n.getTime()-e.getTime())/a),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),m=r.COLOR_ATTACHMENT0,r.viewport(0,0,l,c),d=function(t){return u(this,(function(n){switch(n.label){case 0:return o("tileloaded",t,a-1),i!==F?[2,{value:!0}]:[4,new Promise((function(n,o){window.requestAnimationFrame((function(){t%2==0?(r.uniform1i(M,2),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,h),r.framebufferTexture2D(r.FRAMEBUFFER,m,r.TEXTURE_2D,h,0)):(r.uniform1i(M,1),r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,f),r.framebufferTexture2D(r.FRAMEBUFFER,m,r.TEXTURE_2D,f,0));var o=rt(new Date(e.getTime()+s*t)),i=o.dec,a=o.Hi;r.uniform1f(v,i),r.uniform1f(y,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 _<a?[5,d(_)]:[3,4];case 2:if("object"==typeof(x=g.sent()))return[2,x.value];g.label=3;case 3:return _++,[3,1];case 4:return[4,new Promise((function(t,e){window.requestAnimationFrame((function(){i!==F&&t(!0),r.bindFramebuffer(r.FRAMEBUFFER,null),r.uniform1i(A,1),C(),r.uniform1i(S,0),r.uniform1i(A,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(E,e),window.requestAnimationFrame(C)},updateMaxHeight:function(t){var e=t.maxHeight;r.uniform1f(f,e)},generateShadeProfile:function(t){if(null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");var e=t.dates,o=t.pixels,i=t.shadeColor,a=t.sunColor;if(o.length%2!=0)throw new Error("Pixels array must have 2 numbers per coordinate");var u=o.map((function(t,e){return e%2==0?t/window.innerWidth:t/window.innerHeight})),s=o.length/2,l=e.length,c=r.getParameter(r.VIEWPORT),h=r.getUniform(n,E);r.uniform4fv(E,i),r.uniform4fv(I,a),r.uniform1i(P,1);var f=r.createTexture();r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,f);var p=u.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(U,2);var m=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,m);var d=e.map((function(t){var e=rt(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(d)),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(D,1),r.viewport(0,0,s,l),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4);var _=new Uint8Array(s*l*4);return r.readPixels(0,0,s,l,r.RGBA,r.UNSIGNED_BYTE,_),r.deleteTexture(m),r.deleteTexture(f),r.uniform1i(D,0),r.uniform1i(U,0),r.uniform1i(P,0),r.viewport(c[0],c[1],c[2],c[3]),r.uniform4fv(E,h),r.uniform4fv(I,[0,0,0,0]),_}}}var xt=function(t){function e(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var o=t.call(this)||this;o.options={date:new Date,color:"000",opacity:.3,showExposure:!1,apiKey:"",terrainSource:{maxZoom:15,tileSize:256,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 i=e[0];if(o.options=Object.assign(o.options,i),!o.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:o.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((function(t){return a(o,void 0,void 0,(function(){var e;return u(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 a(o,void 0,void 0,(function(){return u(this,(function(e){if(200!==t.status)throw new Error("Could not load ShadeMap API");return[2]}))}))})),o._suncalc=r.default||window.SunCalc;var s={preserveDrawingBuffer:!0,antialias:!1};return o._canvas=document.createElement("canvas"),o._gl=o._canvas.getContext("webgl",s)||o._canvas.getContext("experimental-webgl",s),o._compiledKernel=_t({context:o._gl}),o._color=o._parseColor(o.options.color),M(o._gl),o._reset=o._reset.bind(o),o._draw=o._draw.bind(o),o}return o(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&&(mt(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&&(mt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this},e.prototype.setShowExposure=function(t){return a(this,void 0,void 0,(function(){var e,r,n,o;return u(this,(function(i){switch(i.label){case 0:if(!this._suncalc)throw new Error("Using sun exposure requires suncalc library");return this.options.showExposure===t?[3,4]:this._map&&this._compiledKernel?(this.options.showExposure=t,!0!==t?[3,2]:(e=b(this._map).getCenter(),r=this._suncalc.getTimes(this.options.date,e.lat,e.lng),n=r.sunrise,o=r.sunset,[4,pt(this._compiledKernel,{start:n,end:o,emit:this.emit.bind(this)})])):[3,4];case 1:return!0===i.sent()?[2,this]:[3,3];case 2:ft(this._compiledKernel,{date:this.options.date}),i.label=3;case 3:this._flush(),i.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 a(this,void 0,void 0,(function(){var t,e,r=this;return u(this,(function(n){switch(n.label){case 0:if(this.options.debug("_reset()"),!this._map)return[3,2];t=b(this._map);try{this._bounds=t.getBounds()}catch(t){return console.error("Invalid bounds returned: ",t),[2,this]}return[4,ct({gl:this._gl,map:t,bounds:this._bounds,terrainSource:this.options.terrainSource,getFeatures:this.options.getFeatures,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 a(e,void 0,void 0,(function(){var e,r,n,o,i;return u(this,(function(a){switch(a.label){case 0:return this._canvas&&this._compiledKernel&&this._map?(dt({kernel:this._compiledKernel,map:b(this._map),heightMap:t,color:this._color,opacity:this.options.opacity,now:this.options.date,maxZoom:this.options.terrainSource.maxZoom}),this.options.showExposure&&this._suncalc?(e=this._bounds.getEast(),r=this._bounds.getWest(),n=this._map.getCenter(),o=this._suncalc.getTimes(this.options.date,n.lat,e).sunrise,i=this._suncalc.getTimes(this.options.date,n.lat,r).sunset,[4,pt(this._compiledKernel,{start:o,end:i,emit:this.emit.bind(this)})]):[3,2]):[3,3];case 1:if(!0===a.sent())return[2,this];a.label=2;case 2:this._repositionCanvas(this._bounds),a.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._generateShadeProfile=function(t){if(this._compiledKernel){var e=this._parseColor(t.sunColor),r=this._parseColor(t.shadeColor);return function(t,e){var r=ht(e.shadeColor,1),n=ht(e.sunColor,1);return t.generateShadeProfile(i(i({},e),{sunColor:n,shadeColor:r}))}(this._compiledKernel,i(i({},t),{sunColor:e,shadeColor:r}))}},e.prototype.getHoursOfSun=function(t,e){if(this._map&&this.options.showExposure&&this._suncalc){var r=this.readPixel(t,e),n=r[0],o=r[2],i=0;i=n>0?n/255*.5+.5:o>0?.5*(1-o/255):.5;var a=b(this._map).getCenter(),u=this._suncalc.getTimes(this.options.date,a.lat,a.lng),s=u.sunrise;return(u.sunset.getTime()-s.getTime())/1e3/3600*i}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}(S),gt="canvas-source",vt="attribution-source",yt="canvas-layer",Et="attribution-layer";return function(t){function e(e){var r=t.call(this,e)||this;return r.id="shademap-layer",r.type="custom",r._refreshing=0,r._raf=0,r.options.terrainSource.tileSize>256&&(r.options.terrainSource.maxZoom=r.options.terrainSource.maxZoom+1),r._moveEndHandler=function(){return r._map&&r._map.getPitch()<=45&&r._reset()},r}return o(e,t),e.prototype.render=function(t,e){},e.prototype.addTo=function(t){return t.addLayer(this),this},e.prototype.onAdd=function(t){var e=this;this._map=t,document.body.appendChild(this._canvas),this._canvas.style.display="none";var r=t.getBounds(),n=r.getNorthWest(),o=r.getNorthEast(),i=r.getSouthEast(),a=r.getSouthWest(),u=[[n.lng,n.lat],[o.lng,o.lat],[i.lng,i.lat],[a.lng,a.lat]];t.addSource(gt,{type:"canvas",canvas:this._canvas,coordinates:u,animate:!1}),t.addLayer({id:yt,type:"raster",source:gt,paint:{"raster-fade-duration":0}}),t.addSource(vt,{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[-122.210598,47.769799]}},attribution:'<a href="https://shademap.app/about">&copy; ShadeMap</a>'}),t.addLayer({id:Et,type:"fill",source:vt});var s=t.getSource("canvas-source"),l=function(){e._refreshing>0&&(s.texture.update(e._canvas,{premultiply:!0}),s.fire({type:"data",dataType:"source",sourceDataType:"content"}),e._refreshing--,e.options.debug("repaint"),1===e._refreshing&&e.emit("idle")),e._raf=requestAnimationFrame(l)};return this._raf=requestAnimationFrame(l),this._map.on("moveend",this._moveEndHandler),this._moveEndHandler(),this},e.prototype.onRemove=function(){return this._map&&(this._map.off("moveend",this._moveEndHandler),this._map.removeLayer(Et),this._map.removeLayer(yt),this._map.removeSource(vt),this._map.removeSource(gt)),cancelAnimationFrame(this._raf),document.body.removeChild(this._canvas),this.options.debug("onRemove called"),this},e.prototype._getHeightMapCoords=function(t,e){if(this._map&&this.options.showExposure&&this._suncalc&&this._bounds){var r=this._map.unproject([t,e]);if(r.toString()===this._map.unproject([t,e+1]).toString())return new f(-1,-1);var n=b(this._map),o=n.getZoom(),i=this._bounds,a=i.getNorthWest(),u=i.getSouthEast(),s=new d(n.project(a,o),n.project(u,o)),l=s.max.x-s.min.x,c=s.max.y-s.min.y,h=window.innerWidth*window.innerHeight,p=l*c,m=Math.sqrt(h/p),_=b(this._map).project(r,o).subtract(s.min);return _.y=s.max.y-s.min.y-_.y,_.multiplyBy(m)}return new f(-1,-1)},e.prototype.getHoursOfSun=function(t,e){if(this._map&&this._suncalc){var r=this._getHeightMapCoords(t,e),n=this.readPixel(r.x,r.y),o=n[0],i=n[0],a=n[2],u=0;o+i+a!==0&&(u=o>0?o/255*.5+.5:a>0?.5*(1-a/255):.5);var s=b(this._map).getCenter(),l=this._suncalc.getTimes(this.options.date,s.lat,s.lng),c=l.sunrise;return(l.sunset.getTime()-c.getTime())/1e3/3600*u}return 0},e.prototype.remove=function(){this._map&&this._map.removeLayer(this.id)},e.prototype._flush=function(){this._refreshing=2},e.prototype._repositionCanvas=function(t){if(this._map){var e=this._map.getSource("canvas-source");if(e){var r=t.getNorthWest(),n=t.getNorthEast(),o=t.getSouthEast(),i=t.getSouthWest(),a=[[r.lng,r.lat],[n.lng,n.lat],[o.lng,o.lat],[i.lng,i.lat]];e.setCoordinates(a),this._flush()}}return this},e}(xt)}));
8
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ShadeMap=e()}(this,(function(){"use strict";var t=function(e,r){return(t=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])})(e,r)};function e(e,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=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var r=function(){return(r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function n(t,e,r,n){return new(r||(r=Promise))((function(o,i){function a(t){try{s(n.next(t))}catch(t){i(t)}}function u(t){try{s(n.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,u)}s((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function i(t,e){for(var r=0,n=e.length,o=t.length;r<n;r++,o++)t[o]=e[r];return t}function a(t,e,r){var n=e[1],o=e[0],i=n-o;return t===n&&r?t:((t-o)%i+i)%i+o}function u(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}var s=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function l(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var c=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function h(t,e,r){return t instanceof l?t:s(t)?new l(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new l(t.x,t.y):new l(t,e,r)}function f(t,e){if(t)for(var r=e?[t,e]:t,n=0,o=r.length;n<o;n++)this.extend(r[n])}function p(t,e){return!t||t instanceof f?t:new f(t,e)}function d(t,e){if(t)for(var r=e?[t,e]:t,n=0,o=r.length;n<o;n++)this.extend(r[n])}function m(t,e){return t instanceof d?t:new d(t,e)}l.prototype={clone:function(){return new l(this.x,this.y)},add:function(t){return this.clone()._add(h(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(h(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 l(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new l(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=c(this.x),this.y=c(this.y),this},distanceTo:function(t){var e=(t=h(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=h(t)).x===this.x&&t.y===this.y},contains:function(t){return t=h(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+u(this.x)+", "+u(this.y)+")"}},f.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof l||"number"==typeof t[0]||"x"in t)e=r=h(t);else if(e=(t=p(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 h((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return h(this.min.x,this.max.y)},getTopRight:function(){return h(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 l?h(t):p(t))instanceof f?(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=p(t);var e=this.min,r=this.max,n=t.min,o=t.max,i=o.x>=e.x&&n.x<=r.x,a=o.y>=e.y&&n.y<=r.y;return i&&a},overlaps:function(t){t=p(t);var e=this.min,r=this.max,n=t.min,o=t.max,i=o.x>e.x&&n.x<r.x,a=o.y>e.y&&n.y<r.y;return i&&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,o=Math.abs(e.y-r.y)*t;return p(h(e.x-n,e.y-o),h(r.x+n,r.y+o))},equals:function(t){return!!t&&(t=p(t),this.min.equals(t.getTopLeft())&&this.max.equals(t.getBottomRight()))}},d.prototype={extend:function(t){var e,r,n=this._southWest,o=this._northEast;if(t instanceof _)e=t,r=t;else{if(!(t instanceof d))return t?this.extend(g(t)||m(t)):this;if(e=t._southWest,r=t._northEast,!e||!r)return this}return n||o?(n.lat=Math.min(e.lat,n.lat),n.lng=Math.min(e.lng,n.lng),o.lat=Math.max(r.lat,o.lat),o.lng=Math.max(r.lng,o.lng)):(this._southWest=new _(e.lat,e.lng),this._northEast=new _(r.lat,r.lng)),this},pad:function(t){var e=this._southWest,r=this._northEast,n=Math.abs(e.lat-r.lat)*t,o=Math.abs(e.lng-r.lng)*t;return new d(new _(e.lat-n,e.lng-o),new _(r.lat+n,r.lng+o))},getCenter:function(){return new _((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 _(this.getNorth(),this.getWest())},getSouthEast:function(){return new _(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 _||"lat"in t?g(t):m(t);var e,r,n=this._southWest,o=this._northEast;return t instanceof d?(e=t.getSouthWest(),r=t.getNorthEast()):e=r=t,e.lat>=n.lat&&r.lat<=o.lat&&e.lng>=n.lng&&r.lng<=o.lng},intersects:function(t){t=m(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),o=t.getNorthEast(),i=o.lat>=e.lat&&n.lat<=r.lat,a=o.lng>=e.lng&&n.lng<=r.lng;return i&&a},overlaps:function(t){t=m(t);var e=this._southWest,r=this._northEast,n=t.getSouthWest(),o=t.getNorthEast(),i=o.lat>e.lat&&n.lat<r.lat,a=o.lng>e.lng&&n.lng<r.lng;return i&&a},toBBoxString:function(){return[this.getWest(),this.getSouth(),this.getEast(),this.getNorth()].join(",")},equals:function(t,e){return!!t&&(t=m(t),this._southWest.equals(t.getSouthWest(),e)&&this._northEast.equals(t.getNorthEast(),e))},isValid:function(){return!(!this._southWest||!this._northEast)}};var x=function(t){var e,r,n,o;for(r=1,n=arguments.length;r<n;r++)for(e in o=arguments[r])t[e]=o[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 f(this.transformation.transform(e.min,r),this.transformation.transform(e.max,r))},infinite:!1,wrapLatLng:function(t){var e=this.wrapLng?a(t.lng,this.wrapLng,!0):t.lng;return new _(this.wrapLat?a(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,o=e.lng-r.lng;if(0===n&&0===o)return t;var i=t.getSouthWest(),a=t.getNorthEast();return new d(new _(i.lat-n,i.lng-o),new _(a.lat-n,a.lng-o))}},{wrapLng:[-180,180],R:6371e3,distance:function(t,e){var r=Math.PI/180,n=t.lat*r,o=e.lat*r,i=Math.sin((e.lat-t.lat)*r/2),a=Math.sin((e.lng-t.lng)*r/2),u=i*i+Math.cos(n)*Math.cos(o)*a*a,s=2*Math.atan2(Math.sqrt(u),Math.sqrt(1-u));return this.R*s}});function _(t,e,r){if(isNaN(t)||isNaN(e))throw new Error("Invalid LatLng object: ("+t+", "+e+")");this.lat=+t,this.lng=+e,void 0!==r&&(this.alt=+r)}function g(t,e,r){return t instanceof _?t:s(t)&&"object"!=typeof t[0]?3===t.length?new _(t[0],t[1],t[2]):2===t.length?new _(t[0],t[1]):null:null==t?t:"object"==typeof t&&"lat"in t?new _(t.lat,"lng"in t?t.lng:t.lon,t.alt):void 0===e?null:new _(t,e,r)}_.prototype={equals:function(t,e){return!!t&&(t=g(t),Math.max(Math.abs(this.lat-t.lat),Math.abs(this.lng-t.lng))<=(void 0===e?1e-9:e))},toString:function(t){return"LatLng("+u(this.lat,t)+", "+u(this.lng,t)+")"},distanceTo:function(t){return x.distance(this,g(t))},wrap:function(){return x.wrapLatLng(this)},toBounds:function(t){var e=180*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return m([this.lat-e,this.lng-r],[this.lat+e,this.lng+r])},clone:function(){return new _(this.lat,this.lng,this.alt)}};var v=8848,y=256;var E,T=function(t){var e=function(){return!t.getPitch};return{project:function(r,n){if(e())return t.project(r,n);var o=r.lat;return new l(function(t,e){return(t+180)/360*Math.pow(2,e)*y}(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)*y}(o,n))},unproject:function(r,n){return e()?t.unproject(r,n):new _((o=r.y,i=n,a=Math.PI-2*Math.PI*o/y/Math.pow(2,i),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/y/Math.pow(2,e)*360-180}(r.x,n));var o,i,a},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}},w=function(t){var e=function(t,e,r){var n=t.createShader(t.VERTEX_SHADER);if(null===n)return null;t.shaderSource(n,e),t.compileShader(n);var o=t.createShader(t.FRAGMENT_SHADER);if(null===o)return null;t.shaderSource(o,r),t.compileShader(o);var i=t.createProgram();if(null===i)return null;t.attachShader(i,n),t.attachShader(i,o),t.linkProgram(i),t.getProgramParameter(i,t.LINK_STATUS)||console.log(t.getProgramInfoLog(i));return i}(t,"\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","\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"),r=t.getAttribLocation(e,"a_position"),n=t.getUniformLocation(e,"xyz"),o=t.getUniformLocation(e,"dimensions"),i=t.getUniformLocation(e,"height_map"),a=t.getUniformLocation(e,"color"),u=t.createBuffer(),s=t.createBuffer(),l=t.createTexture();E={program:e,positionAttributeLocation:r,xyzUniformLocation:n,dimensionsUniformLocation:o,heightMapUniformLocation:i,colorUniformLocation:a,positionBuffer:u,indexBuffer:s,targetTexture:l}};var R=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]&&i([],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=[],o=0;o<arguments.length;o++)t[o]=arguments[o];n(),e.apply(r,t)}));return n},t}();function b(t,e,r){r=r||2;var n,o,i,a,u,s,l,c=e&&e.length,h=c?e[0]*r:t.length,f=M(t,0,h,r,!0),p=[];if(!f||f.next===f.prev)return p;if(c&&(f=function(t,e,r,n){var o,i,a,u=[];for(o=0,i=e.length;o<i;o++)(a=M(t,e[o]*n,o<i-1?e[o+1]*n:t.length,n,!1))===a.next&&(a.steiner=!0),u.push(N(a));for(u.sort(I),o=0;o<u.length;o++)r=C(u[o],r);return r}(t,e,f,r)),t.length>80*r){n=i=t[0],o=a=t[1];for(var d=r;d<h;d+=r)(u=t[d])<n&&(n=u),(s=t[d+1])<o&&(o=s),u>i&&(i=u),s>a&&(a=s);l=0!==(l=Math.max(i-n,a-o))?32767/l:0}return A(f,p,r,n,o,l,0),p}function M(t,e,r,n,o){var i,a;if(o===V(t,e,r,n)>0)for(i=e;i<r;i+=n)a=k(i,t[i],t[i+1],a);else for(i=r-n;i>=e;i-=n)a=k(i,t[i],t[i+1],a);return a&&z(a,a.next)&&(K(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||!z(n,n.next)&&0!==O(n.prev,n,n.next))n=n.next;else{if(K(n),(n=e=n.prev)===n.next)break;r=!0}}while(r||n!==e);return e}function A(t,e,r,n,o,i,a){if(t){!a&&i&&function(t,e,r,n){var o=t;do{0===o.z&&(o.z=B(o.x,o.y,e,r,n)),o.prevZ=o.prev,o.nextZ=o.next,o=o.next}while(o!==t);o.prevZ.nextZ=null,o.prevZ=null,function(t){var e,r,n,o,i,a,u,s,l=1;do{for(r=t,t=null,i=null,a=0;r;){for(a++,n=r,u=0,e=0;e<l&&(u++,n=n.nextZ);e++);for(s=l;u>0||s>0&&n;)0!==u&&(0===s||!n||r.z<=n.z)?(o=r,r=r.nextZ,u--):(o=n,n=n.nextZ,s--),i?i.nextZ=o:t=o,o.prevZ=i,i=o;r=n}i.nextZ=null,l*=2}while(a>1)}(o)}(t,n,o,i);for(var u,s,l=t;t.prev!==t.next;)if(u=t.prev,s=t.next,i?P(t,n,o,i):L(t))e.push(u.i/r|0),e.push(t.i/r|0),e.push(s.i/r|0),K(t),t=s.next,l=s.next;else if((t=s)===l){a?1===a?A(t=U(S(t),e,r),e,r,n,o,i,2):2===a&&D(t,e,r,n,o,i):A(S(t),e,r,n,o,i,1);break}}}function L(t){var e=t.prev,r=t,n=t.next;if(O(e,r,n)>=0)return!1;for(var o=e.x,i=r.x,a=n.x,u=e.y,s=r.y,l=n.y,c=o<i?o<a?o:a:i<a?i:a,h=u<s?u<l?u:l:s<l?s:l,f=o>i?o>a?o:a:i>a?i:a,p=u>s?u>l?u:l:s>l?s:l,d=n.next;d!==e;){if(d.x>=c&&d.x<=f&&d.y>=h&&d.y<=p&&X(o,u,i,s,a,l,d.x,d.y)&&O(d.prev,d,d.next)>=0)return!1;d=d.next}return!0}function P(t,e,r,n){var o=t.prev,i=t,a=t.next;if(O(o,i,a)>=0)return!1;for(var u=o.x,s=i.x,l=a.x,c=o.y,h=i.y,f=a.y,p=u<s?u<l?u:l:s<l?s:l,d=c<h?c<f?c:f:h<f?h:f,m=u>s?u>l?u:l:s>l?s:l,x=c>h?c>f?c:f:h>f?h:f,_=B(p,d,e,r,n),g=B(m,x,e,r,n),v=t.prevZ,y=t.nextZ;v&&v.z>=_&&y&&y.z<=g;){if(v.x>=p&&v.x<=m&&v.y>=d&&v.y<=x&&v!==o&&v!==a&&X(u,c,s,h,l,f,v.x,v.y)&&O(v.prev,v,v.next)>=0)return!1;if(v=v.prevZ,y.x>=p&&y.x<=m&&y.y>=d&&y.y<=x&&y!==o&&y!==a&&X(u,c,s,h,l,f,y.x,y.y)&&O(y.prev,y,y.next)>=0)return!1;y=y.nextZ}for(;v&&v.z>=_;){if(v.x>=p&&v.x<=m&&v.y>=d&&v.y<=x&&v!==o&&v!==a&&X(u,c,s,h,l,f,v.x,v.y)&&O(v.prev,v,v.next)>=0)return!1;v=v.prevZ}for(;y&&y.z<=g;){if(y.x>=p&&y.x<=m&&y.y>=d&&y.y<=x&&y!==o&&y!==a&&X(u,c,s,h,l,f,y.x,y.y)&&O(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function U(t,e,r){var n=t;do{var o=n.prev,i=n.next.next;!z(o,i)&&W(o,n,n.next,i)&&j(o,i)&&j(i,o)&&(e.push(o.i/r|0),e.push(n.i/r|0),e.push(i.i/r|0),K(n),K(n.next),n=t=i),n=n.next}while(n!==t);return S(n)}function D(t,e,r,n,o,i){var a=t;do{for(var u=a.next.next;u!==a.prev;){if(a.i!==u.i&&H(a,u)){var s=Y(a,u);return a=S(a,a.next),s=S(s,s.next),A(a,e,r,n,o,i,0),void A(s,e,r,n,o,i,0)}u=u.next}a=a.next}while(a!==t)}function I(t,e){return t.x-e.x}function C(t,e){var r=function(t,e){var r,n=e,o=t.x,i=t.y,a=-1/0;do{if(i<=n.y&&i>=n.next.y&&n.next.y!==n.y){var u=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(u<=o&&u>a&&(a=u,r=n.x<n.next.x?n:n.next,u===o))return r}n=n.next}while(n!==e);if(!r)return null;var s,l=r,c=r.x,h=r.y,f=1/0;n=r;do{o>=n.x&&n.x>=c&&o!==n.x&&X(i<h?o:a,i,c,h,i<h?a:o,i,n.x,n.y)&&(s=Math.abs(i-n.y)/(o-n.x),j(n,t)&&(s<f||s===f&&(n.x>r.x||n.x===r.x&&F(r,n)))&&(r=n,f=s)),n=n.next}while(n!==l);return r}(t,e);if(!r)return e;var n=Y(r,t);return S(n,n.next),S(r,r.next)}function F(t,e){return O(t.prev,t,e.prev)<0&&O(e.next,t,t.next)<0}function B(t,e,r,n,o){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*o|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-n)*o|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function N(t){var e=t,r=t;do{(e.x<r.x||e.x===r.x&&e.y<r.y)&&(r=e),e=e.next}while(e!==t);return r}function X(t,e,r,n,o,i,a,u){return(o-a)*(e-u)>=(t-a)*(i-u)&&(t-a)*(n-u)>=(r-a)*(e-u)&&(r-a)*(i-u)>=(o-a)*(n-u)}function H(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==e.i&&r.next.i!==e.i&&W(r,r.next,t,e))return!0;r=r.next}while(r!==t);return!1}(t,e)&&(j(t,e)&&j(e,t)&&function(t,e){var r=t,n=!1,o=(t.x+e.x)/2,i=(t.y+e.y)/2;do{r.y>i!=r.next.y>i&&r.next.y!==r.y&&o<(r.next.x-r.x)*(i-r.y)/(r.next.y-r.y)+r.x&&(n=!n),r=r.next}while(r!==t);return n}(t,e)&&(O(t.prev,t,e.prev)||O(t,e.prev,e))||z(t,e)&&O(t.prev,t,t.next)>0&&O(e.prev,e,e.next)>0)}function O(t,e,r){return(e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function z(t,e){return t.x===e.x&&t.y===e.y}function W(t,e,r,n){var o=Z(O(t,e,r)),i=Z(O(t,e,n)),a=Z(O(r,n,t)),u=Z(O(r,n,e));return o!==i&&a!==u||(!(0!==o||!G(t,r,e))||(!(0!==i||!G(t,n,e))||(!(0!==a||!G(r,t,n))||!(0!==u||!G(r,e,n)))))}function G(t,e,r){return e.x<=Math.max(t.x,r.x)&&e.x>=Math.min(t.x,r.x)&&e.y<=Math.max(t.y,r.y)&&e.y>=Math.min(t.y,r.y)}function Z(t){return t>0?1:t<0?-1:0}function j(t,e){return O(t.prev,t,t.next)<0?O(t,e,t.next)>=0&&O(t,t.prev,e)>=0:O(t,e,t.prev)<0||O(t,t.next,e)<0}function Y(t,e){var r=new q(t.i,t.x,t.y),n=new q(e.i,e.x,e.y),o=t.next,i=e.prev;return t.next=e,e.prev=t,r.next=o,o.prev=r,n.next=r,r.prev=n,i.next=n,n.prev=i,n}function k(t,e,r,n){var o=new q(t,e,r);return n?(o.next=n.next,o.prev=n,n.next.prev=o,n.next=o):(o.prev=o,o.next=o),o}function K(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function q(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function V(t,e,r,n){for(var o=0,i=e,a=r-n;i<r;i+=n)o+=(t[a]-t[i])*(t[i+1]+t[a+1]),a=i;return o}function J(t,e){return t.filter((function(t){return"MultiPolygon"===t.geometry.type})).forEach((function(e){var n=e.geometry;if(e.properties,e.type,"MultiPolygon"===n.type)for(var o=0;o<n.coordinates.length;o++)t.push(r(r({},e),{geometry:r(r({},n),{type:"Polygon",coordinates:n.coordinates[o]})}))})),t.filter((function(t){return"Polygon"===t.geometry.type})).map((function(t){var e=t.geometry,r=t.properties,n=b.flatten(e.coordinates).vertices,o=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}))),i=b(n);return{aPosition:o,cuts:i.length>256?new Uint16Array(i):new Uint8Array(i),buildingHeight:function(t){var e=t,r=e.height,n=void 0===r?0:r,o=e.levels,i=void 0===o?0:o,a=e.render_height,u=void 0===a?0:a;if(i)return 3.04*i;return Math.max(n,u)}(r),startPos:[n[0],n[1]]}}))}b.deviation=function(t,e,r,n){var o=e&&e.length,i=o?e[0]*r:t.length,a=Math.abs(V(t,0,i,r));if(o)for(var u=0,s=e.length;u<s;u++){var l=e[u]*r,c=u<s-1?e[u+1]*r:t.length;a-=Math.abs(V(t,l,c,r))}var h=0;for(u=0;u<n.length;u+=3){var f=n[u]*r,p=n[u+1]*r,d=n[u+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)},b.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},n=0,o=0;o<t.length;o++){for(var i=0;i<t[o].length;i++)for(var a=0;a<e;a++)r.vertices.push(t[o][i][a]);o>0&&(n+=t[o-1].length,r.holes.push(n))}return r};var $=.40909994067971484,Q=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,o=Math.atan2(Math.sin(n)*Math.cos($),Math.cos(n));return{dec:Math.asin(Math.sin($)*Math.sin(n)),Hi:(4.889714432387314+6.3003876824396166*e-o)%(2*Math.PI)+2*Math.PI}},tt=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,o=(256*(r>>16&255)+(r>>24&255))/5,Math.max(n,o)));var r,n,o}),0);e({maxHeight:Math.min(v,n)})}))},et=document.createElement("canvas"),rt=et.getContext("2d",{antialias:!1,alpha:!1});null!==rt&&(rt.imageSmoothingEnabled=!1),et.width=y,et.height=y;var nt,ot=[],it=0,at={width:0,height:0,tileLatLngBounds:new d(new _(0,0),new _(0,0)),imageData:new Uint8ClampedArray(0),visibleDEMPixelBounds:new f(new l(0,0),new l(0,0)),maxHeight:v,maxBuildingHeight:0,raster:[],demZoom:0,dirty:!1,outputWidth:0,outputHeight:0},ut=function(t){return n(void 0,void 0,void 0,(function(){var e,i,a,u,s,c,h,p,m,x,_,g,T,w,R,b,M,S,A,L,P,U,D,I,C,F,B,N,X,H,O,z,W,G,Z,j,Y,k,K,q,V;return o(this,(function($){switch($.label){case 0:e=t.map,i=t.getFeatures,a=t.terrainSource,u=t.tileLoaded,s=t.gl,c=t.bounds,h=a.getSourceUrl,p=a.getElevation,m=a.maxZoom,x=a.tileSize,ut={map:e,getFeatures:i},_=n(void 0,void 0,void 0,(function(){var t,e,r,n;return o(this,(function(o){switch(o.label){case 0:t=ut.map,e=ut.getFeatures,o.label=1;case 1:return o.trys.push([1,3,,4]),r=J,[4,e()];case 2:return[2,r.apply(void 0,[o.sent(),t])];case 3:return n=o.sent(),console.log("Error merging buildings",n),[3,4];case 4:return[2,[]]}}))})),g=e.getZoom(),$.label=1;case 1:return $.trys.push([1,4,,5]),g=Math.min(m,g),T=Math.round(g),R=(w=c).getNorthWest(),b=w.getSouthEast(),M=new f(e.project(R,g),e.project(b,g)),S=M.max.x-M.min.x,A=M.max.y-M.min.y,L=new f(e.project(R,T),e.project(b,T)),P=new l(L.min.x,L.min.y),U=L.max.x-L.min.x,D=L.max.y-L.min.y,(I=L.max.subtract(L.min)).y>I.x&&(P.x-=y,U+=512),C=function(t){for(var e=t.upperLeft,r=t.zoom,n=t.innerWidth,o=t.innerHeight,i=e.divideBy(y).floor(),a=i.x+Math.floor((n+y)/y),u=Math.min(i.y+Math.floor((o+y)/y),Math.pow(2,r)-1),s=[],l=i.x;l<=a;l++)for(var c=i.y;c<=u;c++)s.push({x:l,y:c,z:r});return s}({upperLeft:P,zoom:T,innerWidth:U,innerHeight:D}),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)*y,yOffset:(t.y-r)*y}}))}(C),(B=JSON.stringify(F))===nt&&T<m?[2,at=r(r({},at),{visibleDEMPixelBounds:L,demZoom:T,dirty:!0})]:(nt=B,N={width:(et=F).reduce((function(t,e){return e.xOffset>t.xOffset?e:t})).xOffset+y,height:et.reduce((function(t,e){return e.yOffset>t.yOffset?e:t})).yOffset+y},[4,(Q=F,tt={width:X=N.width,height:H=N.height,crossOrigin:"Anonymous",getSourceUrl:h,getElevation:p,tileSize:x,tileLoaded:u},n(void 0,void 0,void 0,(function(){var t,e,r,i,a,u,s,l,c,h,f;return o(this,(function(p){switch(p.label){case 0:if(t=tt.width,e=tt.height,r=tt.crossOrigin,i=tt.getSourceUrl,a=tt.getElevation,u=tt.tileSize,s=tt.tileLoaded,!rt)return[3,5];l=new Uint8ClampedArray(2*t*e),ot.forEach((function(t){return t.src=""})),ot=[],it=0,c=new Set,Q.forEach((function(t){var e=u===y?t.x:Math.floor(t.x/2),r=u===y?t.y:Math.floor(t.y/2),n=u===y?t.z:t.z-1;c.add(i({x:e,y:r,z:n}))})),h=Array.from(c).map((function(e){return n(void 0,void 0,void 0,(function(){return o(this,(function(n){return[2,new Promise((function(n,o){var s=new Image;ot.push(s),s.onload=function(){Q.filter((function(t){var r=u===y?t.x:Math.floor(t.x/2),n=u===y?t.y:Math.floor(t.y/2),o=u===y?t.z:t.z-1;return e===i({x:r,y:n,z:o})})).forEach((function(e){if(u===y)rt.drawImage(s,0,0,y,y);else{var r=514===u?1:0,n=e.x%2*y,o=e.y%2*y;rt.drawImage(s,n,o,y+r,y+r,0,0,y,y)}for(var i=rt.getImageData(0,0,y,y).data,c=0;c<i.length;c+=4){var h=5*(a({r:i[c],g:i[c+1],b:i[c+2],a:0})||0),f=Math.floor(h/256),p=Math.floor(h%256);i[c/2]=f,i[c/2+1]=p}for(c=0;c<y;c++)l.set(i.slice(c*y*2,(c+1)*y*2),2*(e.yOffset*t+c*t+e.xOffset))})),n(null)},s.onerror=function(t){if(s.src!==s.originalSource)return o("new tiles requested");n(null)},s.crossOrigin=r||null,s.src=e,s.originalSource=s.src})).then((function(){it++,s(it,ot.length)}))]}))}))})),p.label=1;case 1:return p.trys.push([1,3,,4]),[4,Promise.all(h)];case 2:return p.sent(),[3,4];case 3:return f=p.sent(),console.log(h.length+" requests aborted",f),[2,null];case 4:return ot=[],[2,l];case 5:throw new Error("Could not get canvas context for merging tile images")}}))})))]);case 2:return null===(O=$.sent())?[2,at=r(r({},at),{visibleDEMPixelBounds:L,demZoom:T,dirty:!1})]:(z=function(t){var e=t.upperLeft,r=t.width,n=t.height,o=e.divideBy(y).floor().multiplyBy(y),i=o.add([r,n]);return new f(o,i)}({upperLeft:P,width:X,height:H}),W=new d(e.unproject(z.getTopLeft(),T),e.unproject(z.getBottomRight(),T)),G=0,[4,_]);case 3:return Z=$.sent(),G=function(t){var e=t.features,r=t.upperLeftTile,n=t.map,o=t.width,i=t.height,a=t.imageData,u=t.gl,s=r.x,c=r.y,h=r.z,f=E.program,p=E.positionAttributeLocation,d=E.xyzUniformLocation,m=E.dimensionsUniformLocation,x=E.heightMapUniformLocation,_=E.colorUniformLocation,g=E.positionBuffer,v=E.indexBuffer,T=E.targetTexture,w=0;u.useProgram(f),u.activeTexture(u.TEXTURE1);var R=u.createTexture();u.bindTexture(u.TEXTURE_2D,R),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,i,0,u.LUMINANCE_ALPHA,u.UNSIGNED_BYTE,a);var b=o*(n.getZoom()>15?2:1),M=i*(n.getZoom()>15?2:1);u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,T),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,b,M,0,u.RGBA,u.UNSIGNED_BYTE,null),n.getZoom()>15&&e.length>0?(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,b,M);var S=u.createFramebuffer();u.bindFramebuffer(u.FRAMEBUFFER,S);var A=u.COLOR_ATTACHMENT0;u.framebufferTexture2D(u.FRAMEBUFFER,A,u.TEXTURE_2D,T,0),u.bindBuffer(u.ARRAY_BUFFER,g),u.bindBuffer(u.ELEMENT_ARRAY_BUFFER,v),u.clearColor(0,0,0,0),u.clear(u.COLOR_BUFFER_BIT);var L=s*y,P=c*y,U=new l(L,P);u.uniform3f(d,L,P,h),u.uniform2f(m,o,i),u.uniform1i(x,1);var D=new Float32Array([-1,-1,1,-1,-1,1,1,1]);return u.enableVertexAttribArray(p),u.bufferData(u.ARRAY_BUFFER,D,u.STATIC_DRAW),u.vertexAttribPointer(p,2,u.FLOAT,!1,0,0),u.uniform4f(_,0,0,0,0),u.drawArrays(u.TRIANGLE_STRIP,0,4),e.forEach((function(t){var e=t.buildingHeight,r=t.aPosition,i=t.cuts,s=t.startPos,l=n.project({lng:s[0],lat:s[1]},h).subtract(U).floor(),c=256*a[l.y*o*2+2*l.x]+a[l.y*o*2+2*l.x+1]+5*e;if(!Number.isNaN(c)){var f=Math.floor(c/256)/256,d=Math.floor(c%256)/256;w=Math.max(w,c/5),u.uniform4f(_,f,d,0,1),u.bufferData(u.ARRAY_BUFFER,r,u.DYNAMIC_DRAW),u.vertexAttribPointer(p,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.deleteTexture(R),w}({upperLeftTile:F[0],width:X,height:H,map:e,features:Z,imageData:O,screenPixelBounds:M,gl:s}),v,j=window.innerWidth*window.innerHeight,Y=S*A,k=Math.sqrt(j/Y),K=Math.round(S*k),q=Math.round(A*k),at={maxHeight:8848,maxBuildingHeight:G,width:X,height:H,tileLatLngBounds:W,imageData:O,visibleDEMPixelBounds:L,raster:F,demZoom:T,dirty:!0,outputWidth:K,outputHeight:q},[3,5];case 4:return V=$.sent(),console.error("Could not decode height map",V),[3,5];case 5:return[2,at]}var Q,tt,et,ut}))}))},st=function(t,e){return[t.r/255,t.g/255,t.b/255,e]},lt=function(t,e){var r=e.date,n=Q(r),o=n.dec,i=n.Hi;t.updateDate({dec:o,Hi:i})},ct=function(t,e){return n(void 0,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return[4,t.updateDateRange(r({},e))];case 1:return[2,n.sent()]}}))}))},ht=function(t,e){var r=e.color,n=e.opacity,o=st(r,n);t.updateColor({colorVec:o})};new d([0,0],[0,0]);var ft=function(t){var e=t.kernel,n=t.map,o=t.heightMap,i=t.now,a=t.color,u=t.opacity,s=t.maxZoom;try{var l=o.maxHeight,c=o.maxBuildingHeight,h=o.width,f=o.height,p=o.tileLatLngBounds,d=o.imageData,m=o.visibleDEMPixelBounds,x=o.demZoom;if(0===h||0===f)return;var _=m.min,g=m.max;if(!_||!g)return;var v=g.subtract(_).divideBy(x>s?Math.pow(2,x-s):1),E=v.x,T=v.y,w=n.project(p.getNorthWest(),x),R=_.divideBy(x>s?Math.pow(2,x-s):1).subtract(w),b=R.x,M=R.y,S=b/h,A=M/f,L=S+E/h,P=A+T/f,U=w.y/y/Math.pow(2,x),D=f/y/Math.pow(2,x),I=p.getWest(),C=Math.abs(p.getWest()-p.getEast())/h;!function(t,e){var n=e.color,o=e.opacity,i=e.date,a=e.imageData,u=e.maxBuildingHeight,s=st(n,o),l=Q(i),c=l.dec,h=l.Hi;t.updateLocation(r({dec:c,Hi:h,colorVec:s,step:1},e)),tt(a).then((function(e){var r=e.maxHeight;t.updateMaxHeight({maxHeight:Math.max(r,u)})}))}(e,{imageData:d,maxHeight:l,maxBuildingHeight:c,width:h,height:f,date:i,heightMapZoom:x,mapZoom:n.getZoom(),xStart:S,yStart:A,xEnd:L,yEnd:P,topYCoord:U,ySize:D,color:a,opacity:u,west:I,dLng:C})}catch(t){console.error("EXCEPTION",t)}};function pt(t){var e=this,r=t.context,i=function(t){var e=t.gl,r=t.vSrc,n=t.fSrc,o=e.createShader(e.VERTEX_SHADER);e.shaderSource(o,r),e.compileShader(o);var i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(i,n),e.compileShader(i);var a=e.createProgram();return e.attachShader(a,o),e.attachShader(a,i),e.linkProgram(a),e.getProgramParameter(a,e.LINK_STATUS)||(console.error("Link failed: "+e.getProgramInfoLog(a)),console.error("vs info-log: "+e.getShaderInfoLog(o)),console.error("fs info-log: "+e.getShaderInfoLog(i))),a}({gl:r,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 aPos;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(aPos,0,1);vec4 textureSpace=gl_Position*0.5+0.5;vTexCoordCropped=vec2((user_xEnd-user_xStart)*textureSpace.x+user_xStart,(user_yEnd-user_yStart)*(1.0-textureSpace.y)+user_yStart);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;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(.5,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*user_width));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 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(user_z<cur_height){user_curvature=earthRadiusInKm*(1.0-cos(user_distance*float(safeI+1)));if(user_z<(cur_height-user_curvature)){user_lit=0.0;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(user_color);}if(user_renderToSunExposureTexture){vec4 aggregateColor=texture2D(user_sunExposureTexture,vec2(vTexCoordFull.x,vTexCoordFull.y));if((user_lit==1.0)){color(aggregateColor.r,0.0,0.0,1.0);}else{color(aggregateColor.r+user_exposureDelta.r,0.0,0.0,1.0);}if(user_outputSunExposure){float timeInSun=1.0-aggregateColor.r;float h=0.5;vec4 blue=vec4(0.0,0.0,1.0,1.0);vec4 green=vec4(0.0,1.0,0.0,1.0);vec4 red=vec4(1.0,0.0,0.0,1.0);vec4 col=mix(mix(blue,green,timeInSun/h),mix(green,red,(timeInSun-h)/(1.0-h)),step(h,timeInSun));color(col.r,col.g,col.b,0.5);}}}void main(void){kernel();gl_FragColor=actualColor;}"});r.useProgram(i);var a=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,a);var u=new Float32Array([-1,-1,1,-1,-1,1,1,1]);r.bufferData(r.ARRAY_BUFFER,u,r.STATIC_DRAW);var s=r.getAttribLocation(i,"aPos");r.enableVertexAttribArray(s),r.vertexAttribPointer(s,2,r.FLOAT,!1,0,0),r.enable(r.BLEND),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA);var l=r.getUniformLocation(i,"user_a");r.uniform1i(l,0);var c=r.getUniformLocation(i,"user_width"),h=r.getUniformLocation(i,"user_height"),f=r.getUniformLocation(i,"user_maxHeight"),p=r.getUniformLocation(i,"user_zoom"),d=r.getUniformLocation(i,"user_topYCoord"),m=r.getUniformLocation(i,"user_ySize"),x=r.getUniformLocation(i,"user_step"),_=r.getUniformLocation(i,"user_west"),g=r.getUniformLocation(i,"user_dLng"),v=r.getUniformLocation(i,"user_dec"),y=r.getUniformLocation(i,"user_Hi"),E=r.getUniformLocation(i,"user_color"),T=r.getUniformLocation(i,"user_xStart"),w=r.getUniformLocation(i,"user_yStart"),R=r.getUniformLocation(i,"user_xEnd"),b=r.getUniformLocation(i,"user_yEnd"),M=r.getUniformLocation(i,"user_sunExposureTexture");r.uniform1i(M,2);var S=r.getUniformLocation(i,"user_renderToSunExposureTexture"),A=r.getUniformLocation(i,"user_outputSunExposure"),L=r.getUniformLocation(i,"user_exposureDelta"),P=r.getUniformLocation(i,"u_outputShadeProfile"),U=r.getUniformLocation(i,"u_gpxTexture"),D=r.getUniformLocation(i,"u_decHiTexture"),I=r.getUniformLocation(i,"u_sunColor"),C=function(){r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4)},F=0;return{updateLocation:function(t){t.imageData;var e=t.width,n=t.height,o=t.maxHeight,u=t.heightMapZoom;t.mapZoom;var l=t.topYCoord,M=t.ySize,S=t.colorVec,A=t.step,L=t.west,P=t.dLng,U=t.dec,D=t.Hi,I=t.xStart,F=t.xEnd,B=t.yStart,N=t.yEnd;r.useProgram(i),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindBuffer(r.ARRAY_BUFFER,a),r.vertexAttribPointer(s,2,r.FLOAT,!1,0,0),r.uniform1f(c,e),r.uniform1f(h,n),r.uniform1f(f,o),r.uniform1f(p,u),r.uniform1f(d,l),r.uniform1f(m,M),r.uniform4fv(E,S),r.uniform1f(x,A),r.uniform1f(_,L),r.uniform1f(g,P),r.uniform1f(v,U),r.uniform1f(y,D),r.uniform1f(T,I),r.uniform1f(w,B),r.uniform1f(R,F),r.uniform1f(b,N),window.requestAnimationFrame(C)},updateViewport:function(t){var e=t.xStart,n=t.yStart,o=t.xEnd,i=t.yEnd;r.uniform1f(T,e),r.uniform1f(w,n),r.uniform1f(R,o),r.uniform1f(b,i),window.requestAnimationFrame(C)},updateDate:function(t){var e=t.dec,n=t.Hi;r.uniform1f(v,e),r.uniform1f(y,n),window.requestAnimationFrame(C)},updateDateRange:function(t){return n(e,void 0,void 0,(function(){var e,n,i,a,u,s,l,c,h,f,p,d,m,x,_;return o(this,(function(g){switch(g.label){case 0:e=t.startDate,n=t.endDate,i=t.iterations,a=t.emit,u=F=Date.now(),r.uniform4fv(L,new Float32Array([1/i,0,0,0])),s=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),m=function(t){return o(this,(function(n){switch(n.label){case 0:return a("tileloaded",t,i-1),u!==F?[2,{value:!0}]:[4,new Promise((function(n,o){window.requestAnimationFrame((function(){t%2==0?(r.uniform1i(M,2),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,h),r.framebufferTexture2D(r.FRAMEBUFFER,d,r.TEXTURE_2D,h,0)):(r.uniform1i(M,1),r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,f),r.framebufferTexture2D(r.FRAMEBUFFER,d,r.TEXTURE_2D,f,0));var o=Q(new Date(e.getTime()+s*t)),i=o.dec,a=o.Hi;r.uniform1f(v,i),r.uniform1f(y,a),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4),n()}))}))];case 1:return n.sent(),[2]}}))},x=0,g.label=1;case 1:return x<i?[5,m(x)]:[3,4];case 2:if("object"==typeof(_=g.sent()))return[2,_.value];g.label=3;case 3:return x++,[3,1];case 4:return[4,new Promise((function(t,e){window.requestAnimationFrame((function(){u!==F&&t(!0),r.bindFramebuffer(r.FRAMEBUFFER,null),r.uniform1i(A,1),C(),r.uniform1i(S,0),r.uniform1i(A,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(E,e),window.requestAnimationFrame(C)},updateMaxHeight:function(t){var e=t.maxHeight;r.uniform1f(f,e)},generateShadeProfile:function(t){if(null===r.getExtension("OES_texture_float"))throw new Error("Float texture support required");var e=t.dates,n=t.pixels,o=t.shadeColor,a=t.sunColor;if(n.length%2!=0)throw new Error("Pixels array must have 2 numbers per coordinate");var u=n.map((function(t,e){return e%2==0?t/window.innerWidth:t/window.innerHeight})),s=n.length/2,l=e.length,c=r.getParameter(r.VIEWPORT),h=r.getUniform(i,E);r.uniform4fv(E,o),r.uniform4fv(I,a),r.uniform1i(P,1);var f=r.createTexture();r.activeTexture(r.TEXTURE2),r.bindTexture(r.TEXTURE_2D,f);var p=u.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(U,2);var d=r.createTexture();r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,d);var m=e.map((function(t){var e=Q(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(m)),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(D,1),r.viewport(0,0,s,l),r.clear(r.COLOR_BUFFER_BIT),r.drawArrays(r.TRIANGLE_STRIP,0,4);var x=new Uint8Array(s*l*4);return r.readPixels(0,0,s,l,r.RGBA,r.UNSIGNED_BYTE,x),r.deleteTexture(d),r.deleteTexture(f),r.uniform1i(D,0),r.uniform1i(U,0),r.uniform1i(P,0),r.viewport(c[0],c[1],c[2],c[3]),r.uniform4fv(E,h),r.uniform4fv(I,[0,0,0,0]),x}}}var dt=function(t){function i(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var i=t.call(this)||this;i.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,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(i.options=Object.assign(i.options,a),!i.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:i.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((function(t){return n(i,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 n(i,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 u={preserveDrawingBuffer:!0,antialias:!1};return i._canvas=document.createElement("canvas"),i._gl=i._canvas.getContext("webgl",u)||i._canvas.getContext("experimental-webgl",u),i._compiledKernel=pt({context:i._gl}),i._color=i._parseColor(i.options.color),w(i._gl),i._reset=i._reset.bind(i),i._draw=i._draw.bind(i),i}return e(i,t),i.prototype.onRemove=function(){return this._map&&this._map.off("moveend",this._reset),this},i.prototype.setDate=function(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(lt(this._compiledKernel,{date:this.options.date}),this._flush())):this.emit("idle"),this},i.prototype.setColor=function(t){return this.options.color!==t&&(this.options.color=t,this._color=this._parseColor(this.options.color),this._compiledKernel&&(ht(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this},i.prototype.setOpacity=function(t){return this.options.opacity!==t&&(this.options.opacity=t,this._compiledKernel&&(ht(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this},i.prototype.setSunExposure=function(t,e){return void 0===t&&(t=!1),n(this,void 0,void 0,(function(){var n,i,a,u,s;return o(this,(function(o){switch(o.label){case 0:return this._map&&this._compiledKernel?!1!==t?[3,1]:(this.options.sunExposure=r(r({},this.options.sunExposure),{enabled:t}),lt(this._compiledKernel,{date:this.options.date}),[3,3]):[3,4];case 1:if(i=(n=e).startDate,a=n.endDate,u=n.iterations,s=void 0===u?32:u,this.options.sunExposure={enabled:t,startDate:i,endDate:a,iterations:s},!(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,ct(this._compiledKernel,{startDate:i,endDate:a,iterations:s,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]}}))}))},i.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)},i.prototype._reset=function(){return n(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=T(this._map);try{this._bounds=t.getBounds()}catch(t){return console.error("Invalid bounds returned: ",t),[2,this]}return[4,ut({gl:this._gl,map:t,bounds:this._bounds,terrainSource:this.options.terrainSource,getFeatures:this.options.getFeatures,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]}}))}))},i.prototype._draw=function(t){var e=this;return this.options.debug("_draw()"),setTimeout((function(){return n(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?(ft({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,ct(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},i.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},i.prototype._generateShadeProfile=function(t){if(this._compiledKernel){var e=this._canvas.width,n=this._canvas.height,o=this._parseColor(t.sunColor),i=this._parseColor(t.shadeColor);this._canvas.width=t.pixels.length/2,this._canvas.height=t.dates.length;var a=function(t,e){var n=st(e.shadeColor,1),o=st(e.sunColor,1);return t.generateShadeProfile(r(r({},e),{sunColor:o,shadeColor:n}))}(this._compiledKernel,r(r({},t),{sunColor:o,shadeColor:i}));return this._canvas.width=e,this._canvas.height=n,a}return new Uint8Array},i.prototype.getHoursOfSun=function(t,e){if(this._map&&this.options.sunExposure.enabled){var r=this.readPixel(t,e),n=2*r[0],o=2*r[1],i=2*r[2],a=0;n+o+i!==0&&(a=n>0?n/255*.5+.5:i>0?.5*(1-i/255):.5);var u=this.options.sunExposure,s=u.startDate,l=(u.endDate.getTime()-s.getTime())/1e3/3600;return Math.abs(l*a)}return 0},i.prototype._repositionCanvas=function(t){},i.prototype._flush=function(){},i.prototype.flushSync=function(){this._gl.finish()},i.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},i}(R),mt="canvas-source",xt="attribution-source",_t="canvas-layer",gt="attribution-layer";return function(t){function r(e){var r=t.call(this,e)||this;return r.id="shademap-layer",r.type="custom",r._refreshing=0,r._raf=0,r.options.terrainSource.tileSize>256&&(r.options.terrainSource.maxZoom=r.options.terrainSource.maxZoom+1),r._moveEndHandler=function(){return r._map&&r._map.getPitch()<=45&&r._reset()},r}return e(r,t),r.prototype.render=function(t,e){},r.prototype.addTo=function(t){return t.addLayer(this),this},r.prototype.onAdd=function(t){var e=this;this._map=t,document.body.appendChild(this._canvas),this._canvas.style.display="none";var r=t.getBounds(),n=r.getNorthWest(),o=r.getNorthEast(),i=r.getSouthEast(),a=r.getSouthWest(),u=[[n.lng,n.lat],[o.lng,o.lat],[i.lng,i.lat],[a.lng,a.lat]];t.addSource(mt,{type:"canvas",canvas:this._canvas,coordinates:u,animate:!1}),t.addLayer({id:_t,type:"raster",source:mt,paint:{"raster-fade-duration":0}}),t.addSource(xt,{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[-122.210598,47.769799]}},attribution:'<a href="https://shademap.app/about">&copy; ShadeMap</a>'}),t.addLayer({id:gt,type:"fill",source:xt});var s=t.getSource("canvas-source"),l=function(){e._refreshing>0&&(s.texture.update(e._canvas,{premultiply:!0}),s.fire({type:"data",dataType:"source",sourceDataType:"content"}),e._refreshing--,e.options.debug("repaint"),1===e._refreshing&&e.emit("idle")),e._raf=requestAnimationFrame(l)};return this._raf=requestAnimationFrame(l),this._map.on("moveend",this._moveEndHandler),this._moveEndHandler(),this},r.prototype.onRemove=function(){return this._map&&(this._map.off("moveend",this._moveEndHandler),this._map.removeLayer(gt),this._map.removeLayer(_t),this._map.removeSource(xt),this._map.removeSource(mt)),cancelAnimationFrame(this._raf),document.body.removeChild(this._canvas),this.options.debug("onRemove called"),this},r.prototype._getHeightMapCoords=function(t,e){if(this._map&&this.options.sunExposure.enabled&&this._bounds){var r=this._map.unproject([t,e]);if(r.toString()===this._map.unproject([t,e+1]).toString())return new l(-1,-1);var n=T(this._map),o=n.getZoom(),i=this._bounds,a=i.getNorthWest(),u=i.getSouthEast(),s=new f(n.project(a,o),n.project(u,o)),c=s.max.x-s.min.x,h=s.max.y-s.min.y,p=window.innerWidth*window.innerHeight,d=c*h,m=Math.sqrt(p/d),x=T(this._map).project(r,o).subtract(s.min);return x.y=s.max.y-s.min.y-x.y,x.multiplyBy(m)}return new l(-1,-1)},r.prototype.getHoursOfSun=function(t,e){if(this._map){var r=this._getHeightMapCoords(t,e),n=this.readPixel(r.x,r.y),o=2*n[0],i=2*n[1],a=2*n[2],u=0;o+i+a!==0&&(u=o>0?o/255*.5+.5:a>0?.5*(1-a/255):.5);var s=this.options.sunExposure,l=s.startDate,c=(s.endDate.getTime()-l.getTime())/1e3/3600;return Math.abs(c*u)}return 0},r.prototype.remove=function(){this._map&&this._map.removeLayer(this.id)},r.prototype._flush=function(){this._refreshing=2},r.prototype._repositionCanvas=function(t){if(this._map){var e=this._map.getSource("canvas-source");if(e){var r=t.getNorthWest(),n=t.getNorthEast(),o=t.getSouthEast(),i=t.getSouthWest(),a=[[r.lng,r.lat],[n.lng,n.lat],[o.lng,o.lat],[i.lng,i.lat]];e.setCoordinates(a),this._flush()}}return this},r}(dt)}));
package/examples/map.html CHANGED
@@ -161,21 +161,24 @@
161
161
  clearInterval(intervalTimer);
162
162
  const target = e.target;
163
163
  if (!target.checked) {
164
- shadeMap && shadeMap.setShowExposure(false);
164
+ shadeMap && shadeMap.setSunExposure(false);
165
165
  increment.disabled = false;
166
166
  decrement.disabled = false;
167
167
  play.disabled = false;
168
168
  stop.disabled = false;
169
169
  exposureGradientContainer.style.display = 'none';
170
170
  } else {
171
- shadeMap && shadeMap.setShowExposure(true);
171
+ const { lat, lng } = map.getCenter();
172
+ const { sunrise, sunset } = SunCalc.getTimes(now, lat, lng);
173
+ shadeMap && shadeMap.setSunExposure(true, {
174
+ startDate: sunrise,
175
+ endDate: sunset
176
+ });
172
177
  increment.disabled = true
173
178
  decrement.disabled = true;
174
179
  play.disabled = true;
175
180
  stop.disabled = true;
176
181
 
177
- const { lat, lng } = map.getCenter();
178
- const { sunrise, sunset } = SunCalc.getTimes(now, lat, lng);
179
182
  const hours = (sunset - sunrise) / 1000 / 3600;
180
183
  const partial = hours - Math.floor(hours);
181
184
  const html = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapbox-gl-shadow-simulator",
3
- "version": "0.20.0",
3
+ "version": "0.21.1",
4
4
  "description": "Display terrain and structure shadows cast by the sun in a custom style layer",
5
5
  "main": "dist/mapbox-gl-shadow-simulator.umd.min.js",
6
6
  "types": "dist/mapbox-gl-shadow-simulator.d.ts",