mapbox-gl-shadow-simulator 0.14.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -114,6 +114,7 @@ Property name | Type | Default value | Comment
114
114
  `date` | `Date` | `new Date()` | Sun's position in the sky is based on this date
115
115
  `color` | `String` | `#000` | 3 or 6 digit hexadecimal number
116
116
  `opacity` | `Number` | `0.3`
117
+ `showExposure` | `Boolean` | `false` | Display 24 hour sun exposure data if set to true (**Note:** requires [suncalc](https://www.npmjs.com/package/suncalc))
117
118
  `terrainSource` | `Object` | See [terrainSource](#terrainsource) | Specify DEM or DSM tiles containing terrain elevation data
118
119
  `getFeatures` | `Function` | See [getFeatures](#getfeatures) | Returns GeoJSON of objects, such as buildings, to display on the map
119
120
 
@@ -204,3 +205,4 @@ getFeatures: () => {
204
205
 
205
206
  `setOpacity(opacity: Number)` - change shade opacity
206
207
 
208
+ `setShowExposure(show: Boolean)` - toggle between shade layer and 24 hour sun exposure (**Note:** requires [suncalc](https://www.npmjs.com/package/suncalc))
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Copyright Ted Piotrowski 2022
3
3
  * Package: mapbox-gl-shadow-simulator
4
- * Version: 0.14.0
4
+ * Version: 0.15.0
5
5
  * For licensing visit: https://shademap.app/about/
6
6
  */
7
7
 
8
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("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{u(n.next(t))}catch(t){i(t)}}function s(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((n=n.apply(t,e||[])).next())}))}function s(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:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){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,s])}}}function u(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 f(t,e){if(!1===e)return t;var r=Math.pow(10,void 0===e?6:e);return Math.round(t*r)/r}var h=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function c(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var p=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function d(t,e,r){return t instanceof c?t:h(t)?new c(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new c(t.x,t.y):new c(t,e,r)}function m(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 m?t:new m(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)}c.prototype={clone:function(){return new c(this.x,this.y)},add:function(t){return this.clone()._add(d(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(d(t))},_subtract:function(t){return this.x-=t.x,this.y-=t.y,this},divideBy:function(t){return this.clone()._divideBy(t)},_divideBy:function(t){return this.x/=t,this.y/=t,this},multiplyBy:function(t){return this.clone()._multiplyBy(t)},_multiplyBy:function(t){return this.x*=t,this.y*=t,this},scaleBy:function(t){return new c(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new c(this.x/t.x,this.y/t.y)},round:function(){return this.clone()._round()},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},floor:function(){return this.clone()._floor()},_floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.clone()._ceil()},_ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},trunc:function(){return this.clone()._trunc()},_trunc:function(){return this.x=p(this.x),this.y=p(this.y),this},distanceTo:function(t){var e=(t=d(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=d(t)).x===this.x&&t.y===this.y},contains:function(t){return t=d(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+f(this.x)+", "+f(this.y)+")"}},m.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof c||"number"==typeof t[0]||"x"in t)e=r=d(t);else if(e=(t=_(t)).min,r=t.max,!e||!r)return this;return this.min||this.max?(this.min.x=Math.min(e.x,this.min.x),this.max.x=Math.max(r.x,this.max.x),this.min.y=Math.min(e.y,this.min.y),this.max.y=Math.max(r.y,this.max.y)):(this.min=e.clone(),this.max=r.clone()),this},getCenter:function(t){return d((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return d(this.min.x,this.max.y)},getTopRight:function(){return d(this.max.x,this.min.y)},getTopLeft:function(){return this.min},getBottomRight:function(){return this.max},getSize:function(){return this.max.subtract(this.min)},contains:function(t){var e,r;return(t="number"==typeof t[0]||t instanceof c?d(t):_(t))instanceof m?(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 _(d(e.x-n,e.y-o),d(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 m(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),s=i*i+Math.cos(n)*Math.cos(o)*a*a,u=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s));return this.R*u}});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("+f(this.lat,t)+", "+f(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,w=8848,M=256,b=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"),s=t.createBuffer(),u=t.createBuffer(),l=t.createTexture();T={program:e,positionAttributeLocation:r,xyzUniformLocation:n,dimensionsUniformLocation:o,heightMapUniformLocation:i,colorUniformLocation:a,positionBuffer:s,indexBuffer:u,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]&&u([],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 L(t,e,r){r=r||2;var n,o,i,a,s,u,l,f=e&&e.length,h=f?e[0]*r:t.length,c=S(t,0,h,r,!0),p=[];if(!c||c.next===c.prev)return p;if(f&&(c=function(t,e,r,n){var o,i,a,s=[];for(o=0,i=e.length;o<i;o++)(a=S(t,e[o]*n,o<i-1?e[o+1]*n:t.length,n,!1))===a.next&&(a.steiner=!0),s.push(H(a));for(s.sort(F),o=0;o<s.length;o++)r=B(s[o],r);return r}(t,e,c,r)),t.length>80*r){n=i=t[0],o=a=t[1];for(var d=r;d<h;d+=r)(s=t[d])<n&&(n=s),(u=t[d+1])<o&&(o=u),s>i&&(i=s),u>a&&(a=u);l=0!==(l=Math.max(i-n,a-o))?32767/l:0}return P(c,p,r,n,o,l,0),p}function S(t,e,r,n,o){var i,a;if(o===Q(t,e,r,n)>0)for(i=e;i<r;i+=n)a=Y(i,t[i],t[i+1],a);else for(i=r-n;i>=e;i-=n)a=Y(i,t[i],t[i+1],a);return a&&Z(a,a.next)&&(V(a),a=a.next),a}function A(t,e){if(!t)return t;e||(e=t);var r,n=t;do{if(r=!1,n.steiner||!Z(n,n.next)&&0!==W(n.prev,n,n.next))n=n.next;else{if(V(n),(n=e=n.prev)===n.next)break;r=!0}}while(r||n!==e);return e}function P(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=N(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,s,u,l=1;do{for(r=t,t=null,i=null,a=0;r;){for(a++,n=r,s=0,e=0;e<l&&(s++,n=n.nextZ);e++);for(u=l;s>0||u>0&&n;)0!==s&&(0===u||!n||r.z<=n.z)?(o=r,r=r.nextZ,s--):(o=n,n=n.nextZ,u--),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 s,u,l=t;t.prev!==t.next;)if(s=t.prev,u=t.next,i?I(t,n,o,i):U(t))e.push(s.i/r|0),e.push(t.i/r|0),e.push(u.i/r|0),V(t),t=u.next,l=u.next;else if((t=u)===l){a?1===a?P(t=D(A(t),e,r),e,r,n,o,i,2):2===a&&C(t,e,r,n,o,i):P(A(t),e,r,n,o,i,1);break}}}function U(t){var e=t.prev,r=t,n=t.next;if(W(e,r,n)>=0)return!1;for(var o=e.x,i=r.x,a=n.x,s=e.y,u=r.y,l=n.y,f=o<i?o<a?o:a:i<a?i:a,h=s<u?s<l?s:l:u<l?u:l,c=o>i?o>a?o:a:i>a?i:a,p=s>u?s>l?s:l:u>l?u:l,d=n.next;d!==e;){if(d.x>=f&&d.x<=c&&d.y>=h&&d.y<=p&&O(o,s,i,u,a,l,d.x,d.y)&&W(d.prev,d,d.next)>=0)return!1;d=d.next}return!0}function I(t,e,r,n){var o=t.prev,i=t,a=t.next;if(W(o,i,a)>=0)return!1;for(var s=o.x,u=i.x,l=a.x,f=o.y,h=i.y,c=a.y,p=s<u?s<l?s:l:u<l?u:l,d=f<h?f<c?f:c:h<c?h:c,m=s>u?s>l?s:l:u>l?u:l,_=f>h?f>c?f:c:h>c?h:c,x=N(p,d,e,r,n),g=N(m,_,e,r,n),v=t.prevZ,y=t.nextZ;v&&v.z>=x&&y&&y.z<=g;){if(v.x>=p&&v.x<=m&&v.y>=d&&v.y<=_&&v!==o&&v!==a&&O(s,f,u,h,l,c,v.x,v.y)&&W(v.prev,v,v.next)>=0)return!1;if(v=v.prevZ,y.x>=p&&y.x<=m&&y.y>=d&&y.y<=_&&y!==o&&y!==a&&O(s,f,u,h,l,c,y.x,y.y)&&W(y.prev,y,y.next)>=0)return!1;y=y.nextZ}for(;v&&v.z>=x;){if(v.x>=p&&v.x<=m&&v.y>=d&&v.y<=_&&v!==o&&v!==a&&O(s,f,u,h,l,c,v.x,v.y)&&W(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<=_&&y!==o&&y!==a&&O(s,f,u,h,l,c,y.x,y.y)&&W(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function D(t,e,r){var n=t;do{var o=n.prev,i=n.next.next;!Z(o,i)&&j(o,n,n.next,i)&&k(o,i)&&k(i,o)&&(e.push(o.i/r|0),e.push(n.i/r|0),e.push(i.i/r|0),V(n),V(n.next),n=t=i),n=n.next}while(n!==t);return A(n)}function C(t,e,r,n,o,i){var a=t;do{for(var s=a.next.next;s!==a.prev;){if(a.i!==s.i&&X(a,s)){var u=K(a,s);return a=A(a,a.next),u=A(u,u.next),P(a,e,r,n,o,i,0),void P(u,e,r,n,o,i,0)}s=s.next}a=a.next}while(a!==t)}function F(t,e){return t.x-e.x}function B(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 s=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(s<=o&&s>a&&(a=s,r=n.x<n.next.x?n:n.next,s===o))return r}n=n.next}while(n!==e);if(!r)return null;var u,l=r,f=r.x,h=r.y,c=1/0;n=r;do{o>=n.x&&n.x>=f&&o!==n.x&&O(i<h?o:a,i,f,h,i<h?a:o,i,n.x,n.y)&&(u=Math.abs(i-n.y)/(o-n.x),k(n,t)&&(u<c||u===c&&(n.x>r.x||n.x===r.x&&z(r,n)))&&(r=n,c=u)),n=n.next}while(n!==l);return r}(t,e);if(!r)return e;var n=K(r,t);return A(n,n.next),A(r,r.next)}function z(t,e){return W(t.prev,t,e.prev)<0&&W(e.next,t,t.next)<0}function N(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 H(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 O(t,e,r,n,o,i,a,s){return(o-a)*(e-s)>=(t-a)*(i-s)&&(t-a)*(n-s)>=(r-a)*(e-s)&&(r-a)*(i-s)>=(o-a)*(n-s)}function X(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)&&(k(t,e)&&k(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)&&(W(t.prev,t,e.prev)||W(t,e.prev,e))||Z(t,e)&&W(t.prev,t,t.next)>0&&W(e.prev,e,e.next)>0)}function W(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=q(W(t,e,r)),i=q(W(t,e,n)),a=q(W(r,n,t)),s=q(W(r,n,e));return o!==i&&a!==s||(!(0!==o||!G(t,r,e))||(!(0!==i||!G(t,n,e))||(!(0!==a||!G(r,t,n))||!(0!==s||!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 q(t){return t>0?1:t<0?-1:0}function k(t,e){return W(t.prev,t,t.next)<0?W(t,e,t.next)>=0&&W(t,t.prev,e)>=0:W(t,e,t.prev)<0||W(t,t.next,e)<0}function K(t,e){var r=new J(t.i,t.x,t.y),n=new J(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 Y(t,e,r,n){var o=new J(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 V(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 J(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 $(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=L.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=L(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,s=void 0===a?0:a;if(i)return 3.04*i;return Math.max(n,s)}(r),startPos:[n[0],n[1]]}}))}L.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 s=0,u=e.length;s<u;s++){var l=e[s]*r,f=s<u-1?e[s+1]*r:t.length;a-=Math.abs(Q(t,l,f,r))}var h=0;for(s=0;s<n.length;s+=3){var c=n[s]*r,p=n[s+1]*r,d=n[s+2]*r;h+=Math.abs((t[c]-t[d])*(t[p+1]-t[c+1])-(t[c]-t[p])*(t[d+1]-t[c+1]))}return 0===a&&0===h?0:Math.abs((h-a)/a)},L.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 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(w,n)})}))},et=document.createElement("canvas"),rt=et.getContext("2d",{antialias:!1,alpha:!1});null!==rt&&(rt.imageSmoothingEnabled=!1),et.width=M,et.height=M;var nt,ot=[],it=0,at={width:0,height:0,tileLatLngBounds:new x(new y(0,0),new y(0,0)),imageData:new Uint8ClampedArray(0),visibleDEMPixelBounds:new m(new c(0,0),new c(0,0)),maxHeight:w,maxBuildingHeight:0,raster:[],demZoom:0,dirty:!1,canvasWidth:0,canvasHeight:0},st=function(t){return a(void 0,void 0,void 0,(function(){var e,r,n,o,u,l,f,h,p,d,_,g,v,y,E,b,R,L,S,A,P,U,I,D,C,F,B,z,N,H,O,X,W,Z,j;return s(this,(function(G){switch(G.label){case 0:e=t.map,r=t.getFeatures,n=t.terrainSource,o=t.tileLoaded,u=t.gl,l=n.getSourceUrl,f=n.getElevation,h=n.maxZoom,p=n.tileSize,Y={map:e,getFeatures:r},d=a(void 0,void 0,void 0,(function(){var t,e,r,n;return s(this,(function(o){switch(o.label){case 0:t=Y.map,e=Y.getFeatures,o.label=1;case 1:return o.trys.push([1,3,,4]),r=$,[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,[]]}}))})),_=e.getZoom(),G.label=1;case 1:return G.trys.push([1,4,,5]),_=Math.min(h,_),g=Math.round(_),v=e.getBounds(),y=v.getNorthWest(),E=v.getSouthEast(),b=new m(e.project(y,_),e.project(E,_)),R=b.max.x-b.min.x,L=b.max.y-b.min.y,S=new m(e.project(y,g),e.project(E,g)),A=new c(S.min.x,S.min.y),P=S.max.x-S.min.x,U=S.max.y-S.min.y,(I=S.max.subtract(S.min)).y>I.x&&(A.x-=M,P+=512),D=function(t){for(var e=t.upperLeft,r=t.zoom,n=t.innerWidth,o=t.innerHeight,i=e.divideBy(M).floor(),a=i.x+Math.floor((n+M)/M),s=Math.min(i.y+Math.floor((o+M)/M),Math.pow(2,r)-1),u=[],l=i.x;l<=a;l++)for(var f=i.y;f<=s;f++)u.push({x:l,y:f,z:r});return u}({upperLeft:A,zoom:g,innerWidth:P,innerHeight:U}),C=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)*M,yOffset:(t.y-r)*M}}))}(D),(F=JSON.stringify(C))===nt&&g<h?[2,at=i(i({},at),{visibleDEMPixelBounds:S,demZoom:g,dirty:!0})]:(nt=F,B={width:(K=C).reduce((function(t,e){return e.xOffset>t.xOffset?e:t})).xOffset+M,height:K.reduce((function(t,e){return e.yOffset>t.yOffset?e:t})).yOffset+M},[4,(q=C,k={width:z=B.width,height:N=B.height,crossOrigin:"Anonymous",getSourceUrl:l,getElevation:f,tileSize:p,tileLoaded:o},a(void 0,void 0,void 0,(function(){var t,e,r,n,o,i,u,l,f,h,c;return s(this,(function(p){switch(p.label){case 0:if(t=k.width,e=k.height,r=k.crossOrigin,n=k.getSourceUrl,o=k.getElevation,i=k.tileSize,u=k.tileLoaded,!rt)return[3,5];l=new Uint8ClampedArray(2*t*e),ot.forEach((function(t){return t.src=""})),ot=[],it=0,f=new Set,q.forEach((function(t){var e=i===M?t.x:Math.floor(t.x/2),r=i===M?t.y:Math.floor(t.y/2),o=i===M?t.z:t.z-1;f.add(n({x:e,y:r,z:o}))})),h=Array.from(f).map((function(e){return a(void 0,void 0,void 0,(function(){return s(this,(function(a){return[2,new Promise((function(a,s){var u=new Image;ot.push(u),u.onload=function(){q.filter((function(t){var r=i===M?t.x:Math.floor(t.x/2),o=i===M?t.y:Math.floor(t.y/2),a=i===M?t.z:t.z-1;return e===n({x:r,y:o,z:a})})).forEach((function(e){if(i===M)rt.drawImage(u,0,0,M,M);else{var r=514===i?1:0,n=e.x%2*M,a=e.y%2*M;rt.drawImage(u,n,a,M+r,M+r,0,0,M,M)}for(var s=rt.getImageData(0,0,M,M).data,f=0;f<s.length;f+=4){var h=5*(o({r:s[f],g:s[f+1],b:s[f+2],a:0})||0),c=Math.floor(h/256),p=Math.floor(h%256);s[f/2]=c,s[f/2+1]=p}for(f=0;f<M;f++)l.set(s.slice(f*M*2,(f+1)*M*2),2*(e.yOffset*t+f*t+e.xOffset))})),a(null)},u.onerror=function(t){if(u.src!==u.originalSource)return s("new tiles requested");a(null)},u.crossOrigin=r||null,u.src=e,u.originalSource=u.src})).then((function(){it++,u(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 c=p.sent(),console.log(h.length+" requests aborted",c),[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===(H=G.sent())?[2,at=i(i({},at),{visibleDEMPixelBounds:S,demZoom:g,dirty:!1})]:(O=function(t){var e=t.upperLeft,r=t.width,n=t.height,o=e.divideBy(M).floor().multiplyBy(M),i=o.add([r,n]);return new m(o,i)}({upperLeft:A,width:z,height:N}),X=new x(e.unproject(O.getTopLeft(),g),e.unproject(O.getBottomRight(),g)),W=0,[4,d]);case 3:return Z=G.sent(),W=function(t){var e=t.features,r=t.upperLeftTile,n=t.map,o=t.width,i=t.height,a=t.imageData,s=t.gl,u=r.x,l=r.y,f=r.z,h=T.program,p=T.positionAttributeLocation,d=T.xyzUniformLocation,m=T.dimensionsUniformLocation,_=T.heightMapUniformLocation,x=T.colorUniformLocation,g=T.positionBuffer,v=T.indexBuffer,y=T.targetTexture,E=0;s.useProgram(h),s.activeTexture(s.TEXTURE1);var w=s.createTexture();s.bindTexture(s.TEXTURE_2D,w),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST),s.texImage2D(s.TEXTURE_2D,0,s.LUMINANCE_ALPHA,o,i,0,s.LUMINANCE_ALPHA,s.UNSIGNED_BYTE,a);var b=o*(n.getZoom()>15?2:1),R=i*(n.getZoom()>15?2:1);s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,y),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,b,R,0,s.RGBA,s.UNSIGNED_BYTE,null),n.getZoom()>15&&e.length>0?(s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST)):(s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR)),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.viewport(0,0,b,R);var L=s.createFramebuffer();s.bindFramebuffer(s.FRAMEBUFFER,L);var S=s.COLOR_ATTACHMENT0;s.framebufferTexture2D(s.FRAMEBUFFER,S,s.TEXTURE_2D,y,0),s.bindBuffer(s.ARRAY_BUFFER,g),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,v),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT);var A=u*M,P=l*M,U=new c(A,P);s.uniform3f(d,A,P,f),s.uniform2f(m,o,i),s.uniform1i(_,1);var I=new Float32Array([-1,-1,1,-1,-1,1,1,1]);return s.enableVertexAttribArray(p),s.bufferData(s.ARRAY_BUFFER,I,s.STATIC_DRAW),s.vertexAttribPointer(p,2,s.FLOAT,!1,0,0),s.uniform4f(x,0,0,0,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),e.forEach((function(t){var e=t.buildingHeight,r=t.aPosition,i=t.cuts,u=t.startPos,l=n.project({lng:u[0],lat:u[1]},f).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 c=Math.floor(h/256)/256,d=Math.floor(h%256)/256;E=Math.max(E,h/5),s.uniform4f(x,c,d,0,1),s.bufferData(s.ARRAY_BUFFER,r,s.DYNAMIC_DRAW),s.vertexAttribPointer(p,2,s.FLOAT,!1,0,0),s.bufferData(s.ELEMENT_ARRAY_BUFFER,i,s.DYNAMIC_DRAW),s.drawElements(s.TRIANGLES,i.length,i.length>256?s.UNSIGNED_SHORT:s.UNSIGNED_BYTE,0)}})),s.deleteTexture(w),E}({upperLeftTile:C[0],width:z,height:N,map:e,features:Z,imageData:H,screenPixelBounds:b,gl:u}),w,at={maxHeight:8848,maxBuildingHeight:W,width:z,height:N,tileLatLngBounds:X,imageData:H,visibleDEMPixelBounds:S,raster:C,demZoom:g,dirty:!0,canvasWidth:R,canvasHeight:L},[3,5];case 4:return j=G.sent(),console.error("Could not decode height map",j),[3,5];case 5:return[2,at]}var q,k,K,Y}))}))},ut=.40909994067971484,lt=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(ut),Math.cos(n));return{dec:Math.asin(Math.sin(ut)*Math.sin(n)),Hi:(4.889714432387314+6.3003876824396166*e-o)%(2*Math.PI)+2*Math.PI}},ft=function(t,e){return[t.r/255,t.g/255,t.b/255,e]},ht=function(t,e){var r=e.date,n=lt(r),o=n.dec,i=n.Hi;t.updateDate({dec:o,Hi:i})},ct=function(t,e){t.updateDateRange(i(i({},e),{getDeclination:lt}))},pt=function(t,e){var r=e.color,n=e.opacity,o=ft(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,s=t.opacity,u=t.maxZoom;try{var l=n.maxHeight,f=n.maxBuildingHeight,h=n.width,c=n.height,p=n.tileLatLngBounds,d=n.imageData,m=n.visibleDEMPixelBounds,_=n.demZoom;if(0===h||0===c)return;var x=m.min,g=m.max;if(!x||!g)return;var v=g.subtract(x).divideBy(_>u?Math.pow(2,_-u):1),y=v.x,E=v.y,T=r.project(p.getNorthWest(),_),w=x.divideBy(_>u?Math.pow(2,_-u):1).subtract(T),b=w.x,R=w.y,L=b/h,S=R/c,A=L+y/h,P=S+E/c,U=T.y/M/Math.pow(2,_),I=c/M/Math.pow(2,_),D=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,s=e.maxBuildingHeight,u=ft(r,n),l=lt(o),f=l.dec,h=l.Hi;t.updateLocation(i({dec:f,Hi:h,colorVec:u,step:1},e)),tt(a).then((function(e){var r=e.maxHeight;t.updateMaxHeight({maxHeight:Math.max(r,s)})}))}(e,{imageData:d,maxHeight:l,maxBuildingHeight:f,width:h,height:c,date:o,heightMapZoom:_,mapZoom:r.getZoom(),xStart:L,yStart:S,xEnd:A,yEnd:P,topYCoord:U,ySize:I,color:a,opacity:s,west:D,dLng:C})}catch(t){console.error("EXCEPTION",t)}};var mt,_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 c(function(t,e){return(t+180)/360*Math.pow(2,e)*M}(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)*M}(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/M/Math.pow(2,i),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/M/Math.pow(2,e)*360-180}(r.x,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}};function xt(t){var e=t.context,r=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:e,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 aPos;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;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);}",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);}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 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 float user_exposureTimeStep;float kernelResult;void kernel(){float maxHeight=user_maxHeight/1000.0;float user_x=vTexCoordCropped.x;float user_y=vTexCoordCropped.y;float user_z=getElevationFromSampler2D(user_a,user_x,user_y);float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=(user_west+(user_dLng*user_x*user_width));float user_H=integerCorrectionModulo((user_Hi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(user_dec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(user_dec))+((cos(user_lat)*cos(user_dec))*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(0.0,0.0,0.0,0.0);}else{color(user_color.r,user_color.g,user_color.b,user_color.a);}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_exposureTimeStep,user_color.g,user_color.b,1.0);}if(user_outputSunExposure){if(aggregateColor.r>.7){color(0.0,0.0,1.0,0.5);}else if(aggregateColor.r>.3){color(0.0,1.0,0.0,0.5);}else{color(1.0,0.0,0.0,0.5);}}}}void main(void){kernel();gl_FragColor=actualColor;}"});e.useProgram(r);var n=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,n);var o=new Float32Array([-1,-1,1,-1,-1,1,1,1]);e.bufferData(e.ARRAY_BUFFER,o,e.STATIC_DRAW);var i=e.getAttribLocation(r,"aPos");e.enableVertexAttribArray(i),e.vertexAttribPointer(i,2,e.FLOAT,!1,0,0),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA);var a=e.getUniformLocation(r,"user_a");e.uniform1i(a,0);var s=e.getUniformLocation(r,"user_width"),u=e.getUniformLocation(r,"user_height"),l=e.getUniformLocation(r,"user_maxHeight"),f=e.getUniformLocation(r,"user_zoom"),h=e.getUniformLocation(r,"user_topYCoord"),c=e.getUniformLocation(r,"user_ySize"),p=e.getUniformLocation(r,"user_step"),d=e.getUniformLocation(r,"user_west"),m=e.getUniformLocation(r,"user_dLng"),_=e.getUniformLocation(r,"user_dec"),x=e.getUniformLocation(r,"user_Hi"),g=e.getUniformLocation(r,"user_color"),v=e.getUniformLocation(r,"user_xStart"),y=e.getUniformLocation(r,"user_yStart"),E=e.getUniformLocation(r,"user_xEnd"),T=e.getUniformLocation(r,"user_yEnd"),w=e.getUniformLocation(r,"user_sunExposureTexture");e.uniform1i(w,2);var M=e.getUniformLocation(r,"user_renderToSunExposureTexture"),b=e.getUniformLocation(r,"user_outputSunExposure"),R=e.getUniformLocation(r,"user_exposureTimeStep"),L=function(){e.clear(e.COLOR_BUFFER_BIT),e.drawArrays(e.TRIANGLE_STRIP,0,4)};return{updateLocation:function(t){t.imageData;var o=t.width,a=t.height,w=t.maxHeight,M=t.heightMapZoom;t.mapZoom;var b=t.topYCoord,R=t.ySize,S=t.colorVec,A=t.step,P=t.west,U=t.dLng,I=t.dec,D=t.Hi,C=t.xStart,F=t.xEnd,B=t.yStart,z=t.yEnd;e.useProgram(r),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindBuffer(e.ARRAY_BUFFER,n),e.vertexAttribPointer(i,2,e.FLOAT,!1,0,0),e.uniform1f(s,o),e.uniform1f(u,a),e.uniform1f(l,w),e.uniform1f(f,M),e.uniform1f(h,b),e.uniform1f(c,R),e.uniform4fv(g,S),e.uniform1f(p,A),e.uniform1f(d,P),e.uniform1f(m,U),e.uniform1f(_,I),e.uniform1f(x,D),e.uniform1f(v,C),e.uniform1f(y,B),e.uniform1f(E,F),e.uniform1f(T,z),window.requestAnimationFrame(L)},updateViewport:function(t){var r=t.xStart,n=t.yStart,o=t.xEnd,i=t.yEnd;e.uniform1f(v,r),e.uniform1f(y,n),e.uniform1f(E,o),e.uniform1f(T,i),window.requestAnimationFrame(L)},updateDate:function(t){var r=t.dec,n=t.Hi;e.uniform1f(_,r),e.uniform1f(x,n),window.requestAnimationFrame(L)},updateDateRange:function(t){var r=t.start,n=t.end,o=t.getDeclination,i=t.emit;e.uniform1f(R,.04);var a=Math.floor((n.getTime()-r.getTime())/25),s=e.canvas.width,u=e.canvas.height,l=e.createTexture();e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,l),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,s,u,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR);var f=e.createTexture();e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,f),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,s,u,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.uniform1i(M,1);var h=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,h);var c=e.COLOR_ATTACHMENT0;e.viewport(0,0,s,u);for(var p=0;p<25;p++){i("tilesloaded",p,24),p%2==0?(e.uniform1i(w,2),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,l),e.framebufferTexture2D(e.FRAMEBUFFER,c,e.TEXTURE_2D,l,0)):(e.uniform1i(w,1),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,f),e.framebufferTexture2D(e.FRAMEBUFFER,c,e.TEXTURE_2D,f,0));var d=o(new Date(r.getTime()+a*p)),m=d.dec,g=d.Hi;e.uniform1f(_,m),e.uniform1f(x,g),e.clear(e.COLOR_BUFFER_BIT),e.drawArrays(e.TRIANGLE_STRIP,0,4)}e.bindFramebuffer(e.FRAMEBUFFER,null),e.uniform1i(b,1),window.requestAnimationFrame((function(){L(),e.uniform1i(M,0),e.uniform1i(b,0),e.deleteTexture(l),e.deleteTexture(f)}))},updateColor:function(t){var r=t.colorVec;e.uniform4fv(g,r),window.requestAnimationFrame(L)},updateMaxHeight:function(t){var r=t.maxHeight;e.uniform1f(l,r)}}}!function(t){t.LOW="low",t.MED="medium",t.HIGH="high"}(mt||(mt={}));var gt=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=t.call(this)||this;n.options={date:new Date,color:"000",opacity:.3,quality:mt.MED,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 o=e[0];if(n.options=Object.assign(n.options,o),!n.options.apiKey)throw new Error("Could not load ShadeMap: apiKey missing");fetch("https://shademap.app/sdk/load",{method:"POST",body:JSON.stringify({api_key:n.options.apiKey}),headers:{"Content-Type":"application/json"}}).then((function(t){return a(n,void 0,void 0,(function(){var e;return s(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(n,void 0,void 0,(function(){return s(this,(function(e){if(200!==t.status)throw new Error("Could not load ShadeMap API");return[2]}))}))})),n._canvasElWidth=window.innerWidth,n._canvasElHeight=window.innerHeight;var i={preserveDrawingBuffer:!0,antialias:!1};return n._canvas=document.createElement("canvas"),n._gl=n._canvas.getContext("webgl",i)||n._canvas.getContext("experimental-webgl",i),n._compiledKernel=xt({context:n._gl}),n._color=n._parseColor(n.options.color),b(n._gl),n._reset=n._reset.bind(n),n._draw=n._draw.bind(n),n._resize=n._resize.bind(n),n}return o(e,t),e.prototype.onRemove=function(){return this._map&&(this._map.off("moveend",this._reset),this._map.off("resize",this._resize)),this},e.prototype.setDate=function(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(ht(this._compiledKernel,{date:this.options.date}),this._flush())):this.emit("idle"),this},e.prototype.setColor=function(t){return this.options.color!==t&&(this.options.color=t,this._color=this._parseColor(this.options.color),this._compiledKernel&&(pt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this},e.prototype.setOpacity=function(t){return this.options.opacity!==t&&(this.options.opacity=t,this._compiledKernel&&(pt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this},e.prototype.setQuality=function(t){return this.options.quality!==t&&(this.options.quality=t,this._resizeCanvas(),this._reset()),this},e.prototype.setShowExposure=function(t){if(this.options.showExposure!==t&&this._map&&this._compiledKernel){if(this.options.showExposure=t,!0===t){var e=_t(this._map).getCenter(),n=r.default.getTimes(this.options.date,e.lat,e.lng),o=n.sunrise,i=n.sunset;ct(this._compiledKernel,{start:o,end:i,emit:this.emit.bind(this)})}else ht(this._compiledKernel,{date:this.options.date});this._flush()}return this},e.prototype._resize=function(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.options.debug("_resize w:"+t+" h:"+e),this._canvasElWidth=t,this._canvasElHeight=e,this._resizeCanvas()},e.prototype._resizeCanvas=function(){var t=this._canvasElWidth*(this.options.quality===mt.HIGH?2:1),e=this._canvasElHeight*(this.options.quality===mt.HIGH?2:1),r=window.innerWidth*window.innerHeight*(this.options.quality===mt.HIGH?2:1),n=t*e,o=Math.sqrt(r/n);this._canvas.width=t*o,this._canvas.height=e*o,this._gl.viewport(0,0,t*o,e*o)},e.prototype._reset=function(){return a(this,void 0,void 0,(function(){var t,e,r,n=this;return s(this,(function(o){switch(o.label){case 0:if(this.options.debug("_reset()"),!this._map)return[3,2];t=_t(this._map),e=void 0;try{e=t.getBounds()}catch(t){return console.error("Invalid bounds returned: ",t),[2,this]}return[4,st({gl:this._gl,map:t,terrainSource:this.options.terrainSource,getFeatures:this.options.getFeatures,quality:mt.MED,tileLoaded:function(t,e){return n.emit("tileloaded",t,e)}})];case 1:(r=o.sent()).dirty&&(this._resize(r.canvasWidth,r.canvasHeight),this._draw(r,e)),o.label=2;case 2:return[2,this]}}))}))},e.prototype._draw=function(t,e){var n=this;return this.options.debug("_draw()"),setTimeout((function(){if(n._canvas&&n._compiledKernel&&n._map){if(dt({kernel:n._compiledKernel,map:_t(n._map),heightMap:t,color:n._color,opacity:n.options.opacity,now:n.options.date,maxZoom:n.options.terrainSource.maxZoom}),n.options.showExposure){var o=n._map.getCenter(),i=r.default.getTimes(n.options.date,o.lat,o.lng),a=i.sunrise,s=i.sunset;ct(n._compiledKernel,{start:a,end:s,emit:n.emit.bind(n)})}n._repositionCanvas(e)}}),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._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}(R),vt="canvas-source",yt="attribution-source",Et="canvas-layer",Tt="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._resizeHandler=function(){return r._resize(window.innerWidth,window.innerHeight)},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,this._resizeCanvas(),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(),s=[[n.lng,n.lat],[o.lng,o.lat],[i.lng,i.lat],[a.lng,a.lat]];t.addSource(vt,{type:"canvas",canvas:this._canvas,coordinates:s,animate:!1}),t.addLayer({id:Et,type:"raster",source:vt,paint:{"raster-fade-duration":0}}),t.addSource(yt,{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:Tt,type:"fill",source:yt});var u=t.getSource("canvas-source"),l=function(){e._refreshing>0&&(u.texture.update(e._canvas,{premultiply:!0}),u.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._map.on("resize",this._resizeHandler),this._moveEndHandler(),this},e.prototype.onRemove=function(){return this._map&&(this._map.off("moveend",this._moveEndHandler),this._map.off("resize",this._resizeHandler),this._map.removeLayer(Tt),this._map.removeLayer(Et),this._map.removeSource(yt),this._map.removeSource(vt)),cancelAnimationFrame(this._raf),document.body.removeChild(this._canvas),this.options.debug("onRemove called"),this},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}(gt)}));
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{u(n.next(t))}catch(t){i(t)}}function s(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((n=n.apply(t,e||[])).next())}))}function s(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:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){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,s])}}}function u(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 f=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function h(t,e,r){this.x=r?Math.round(t):t,this.y=r?Math.round(e):e}var p=Math.trunc||function(t){return t>0?Math.floor(t):Math.ceil(t)};function d(t,e,r){return t instanceof h?t:f(t)?new h(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new h(t.x,t.y):new h(t,e,r)}function m(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 m?t:new m(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)}h.prototype={clone:function(){return new h(this.x,this.y)},add:function(t){return this.clone()._add(d(t))},_add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.clone()._subtract(d(t))},_subtract:function(t){return this.x-=t.x,this.y-=t.y,this},divideBy:function(t){return this.clone()._divideBy(t)},_divideBy:function(t){return this.x/=t,this.y/=t,this},multiplyBy:function(t){return this.clone()._multiplyBy(t)},_multiplyBy:function(t){return this.x*=t,this.y*=t,this},scaleBy:function(t){return new h(this.x*t.x,this.y*t.y)},unscaleBy:function(t){return new h(this.x/t.x,this.y/t.y)},round:function(){return this.clone()._round()},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},floor:function(){return this.clone()._floor()},_floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.clone()._ceil()},_ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},trunc:function(){return this.clone()._trunc()},_trunc:function(){return this.x=p(this.x),this.y=p(this.y),this},distanceTo:function(t){var e=(t=d(t)).x-this.x,r=t.y-this.y;return Math.sqrt(e*e+r*r)},equals:function(t){return(t=d(t)).x===this.x&&t.y===this.y},contains:function(t){return t=d(t),Math.abs(t.x)<=Math.abs(this.x)&&Math.abs(t.y)<=Math.abs(this.y)},toString:function(){return"Point("+c(this.x)+", "+c(this.y)+")"}},m.prototype={extend:function(t){var e,r;if(!t)return this;if(t instanceof h||"number"==typeof t[0]||"x"in t)e=r=d(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 d((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,t)},getBottomLeft:function(){return d(this.min.x,this.max.y)},getTopRight:function(){return d(this.max.x,this.min.y)},getTopLeft:function(){return this.min},getBottomRight:function(){return this.max},getSize:function(){return this.max.subtract(this.min)},contains:function(t){var e,r;return(t="number"==typeof t[0]||t instanceof h?d(t):_(t))instanceof m?(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 _(d(e.x-n,e.y-o),d(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 m(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),s=i*i+Math.cos(n)*Math.cos(o)*a*a,u=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s));return this.R*u}});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:f(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,w=8848,b=256,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"),s=t.createBuffer(),u=t.createBuffer(),l=t.createTexture();T={program:e,positionAttributeLocation:r,xyzUniformLocation:n,dimensionsUniformLocation:o,heightMapUniformLocation:i,colorUniformLocation:a,positionBuffer:s,indexBuffer:u,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]&&u([],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 L(t,e,r){r=r||2;var n,o,i,a,s,u,l,c=e&&e.length,f=c?e[0]*r:t.length,h=S(t,0,f,r,!0),p=[];if(!h||h.next===h.prev)return p;if(c&&(h=function(t,e,r,n){var o,i,a,s=[];for(o=0,i=e.length;o<i;o++)(a=S(t,e[o]*n,o<i-1?e[o+1]*n:t.length,n,!1))===a.next&&(a.steiner=!0),s.push(H(a));for(s.sort(F),o=0;o<s.length;o++)r=B(s[o],r);return r}(t,e,h,r)),t.length>80*r){n=i=t[0],o=a=t[1];for(var d=r;d<f;d+=r)(s=t[d])<n&&(n=s),(u=t[d+1])<o&&(o=u),s>i&&(i=s),u>a&&(a=u);l=0!==(l=Math.max(i-n,a-o))?32767/l:0}return P(h,p,r,n,o,l,0),p}function S(t,e,r,n,o){var i,a;if(o===Q(t,e,r,n)>0)for(i=e;i<r;i+=n)a=Y(i,t[i],t[i+1],a);else for(i=r-n;i>=e;i-=n)a=Y(i,t[i],t[i+1],a);return a&&Z(a,a.next)&&(V(a),a=a.next),a}function A(t,e){if(!t)return t;e||(e=t);var r,n=t;do{if(r=!1,n.steiner||!Z(n,n.next)&&0!==W(n.prev,n,n.next))n=n.next;else{if(V(n),(n=e=n.prev)===n.next)break;r=!0}}while(r||n!==e);return e}function P(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=N(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,s,u,l=1;do{for(r=t,t=null,i=null,a=0;r;){for(a++,n=r,s=0,e=0;e<l&&(s++,n=n.nextZ);e++);for(u=l;s>0||u>0&&n;)0!==s&&(0===u||!n||r.z<=n.z)?(o=r,r=r.nextZ,s--):(o=n,n=n.nextZ,u--),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 s,u,l=t;t.prev!==t.next;)if(s=t.prev,u=t.next,i?I(t,n,o,i):U(t))e.push(s.i/r|0),e.push(t.i/r|0),e.push(u.i/r|0),V(t),t=u.next,l=u.next;else if((t=u)===l){a?1===a?P(t=C(A(t),e,r),e,r,n,o,i,2):2===a&&D(t,e,r,n,o,i):P(A(t),e,r,n,o,i,1);break}}}function U(t){var e=t.prev,r=t,n=t.next;if(W(e,r,n)>=0)return!1;for(var o=e.x,i=r.x,a=n.x,s=e.y,u=r.y,l=n.y,c=o<i?o<a?o:a:i<a?i:a,f=s<u?s<l?s:l:u<l?u:l,h=o>i?o>a?o:a:i>a?i:a,p=s>u?s>l?s:l:u>l?u:l,d=n.next;d!==e;){if(d.x>=c&&d.x<=h&&d.y>=f&&d.y<=p&&O(o,s,i,u,a,l,d.x,d.y)&&W(d.prev,d,d.next)>=0)return!1;d=d.next}return!0}function I(t,e,r,n){var o=t.prev,i=t,a=t.next;if(W(o,i,a)>=0)return!1;for(var s=o.x,u=i.x,l=a.x,c=o.y,f=i.y,h=a.y,p=s<u?s<l?s:l:u<l?u:l,d=c<f?c<h?c:h:f<h?f:h,m=s>u?s>l?s:l:u>l?u:l,_=c>f?c>h?c:h:f>h?f:h,x=N(p,d,e,r,n),g=N(m,_,e,r,n),v=t.prevZ,y=t.nextZ;v&&v.z>=x&&y&&y.z<=g;){if(v.x>=p&&v.x<=m&&v.y>=d&&v.y<=_&&v!==o&&v!==a&&O(s,c,u,f,l,h,v.x,v.y)&&W(v.prev,v,v.next)>=0)return!1;if(v=v.prevZ,y.x>=p&&y.x<=m&&y.y>=d&&y.y<=_&&y!==o&&y!==a&&O(s,c,u,f,l,h,y.x,y.y)&&W(y.prev,y,y.next)>=0)return!1;y=y.nextZ}for(;v&&v.z>=x;){if(v.x>=p&&v.x<=m&&v.y>=d&&v.y<=_&&v!==o&&v!==a&&O(s,c,u,f,l,h,v.x,v.y)&&W(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<=_&&y!==o&&y!==a&&O(s,c,u,f,l,h,y.x,y.y)&&W(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)&&k(o,i)&&k(i,o)&&(e.push(o.i/r|0),e.push(n.i/r|0),e.push(i.i/r|0),V(n),V(n.next),n=t=i),n=n.next}while(n!==t);return A(n)}function D(t,e,r,n,o,i){var a=t;do{for(var s=a.next.next;s!==a.prev;){if(a.i!==s.i&&X(a,s)){var u=K(a,s);return a=A(a,a.next),u=A(u,u.next),P(a,e,r,n,o,i,0),void P(u,e,r,n,o,i,0)}s=s.next}a=a.next}while(a!==t)}function F(t,e){return t.x-e.x}function B(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 s=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(s<=o&&s>a&&(a=s,r=n.x<n.next.x?n:n.next,s===o))return r}n=n.next}while(n!==e);if(!r)return null;var u,l=r,c=r.x,f=r.y,h=1/0;n=r;do{o>=n.x&&n.x>=c&&o!==n.x&&O(i<f?o:a,i,c,f,i<f?a:o,i,n.x,n.y)&&(u=Math.abs(i-n.y)/(o-n.x),k(n,t)&&(u<h||u===h&&(n.x>r.x||n.x===r.x&&z(r,n)))&&(r=n,h=u)),n=n.next}while(n!==l);return r}(t,e);if(!r)return e;var n=K(r,t);return A(n,n.next),A(r,r.next)}function z(t,e){return W(t.prev,t,e.prev)<0&&W(e.next,t,t.next)<0}function N(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 H(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 O(t,e,r,n,o,i,a,s){return(o-a)*(e-s)>=(t-a)*(i-s)&&(t-a)*(n-s)>=(r-a)*(e-s)&&(r-a)*(i-s)>=(o-a)*(n-s)}function X(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)&&(k(t,e)&&k(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)&&(W(t.prev,t,e.prev)||W(t,e.prev,e))||Z(t,e)&&W(t.prev,t,t.next)>0&&W(e.prev,e,e.next)>0)}function W(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=q(W(t,e,r)),i=q(W(t,e,n)),a=q(W(r,n,t)),s=q(W(r,n,e));return o!==i&&a!==s||(!(0!==o||!G(t,r,e))||(!(0!==i||!G(t,n,e))||(!(0!==a||!G(r,t,n))||!(0!==s||!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 q(t){return t>0?1:t<0?-1:0}function k(t,e){return W(t.prev,t,t.next)<0?W(t,e,t.next)>=0&&W(t,t.prev,e)>=0:W(t,e,t.prev)<0||W(t,t.next,e)<0}function K(t,e){var r=new J(t.i,t.x,t.y),n=new J(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 Y(t,e,r,n){var o=new J(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 V(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 J(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 $(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=L.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=L(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,s=void 0===a?0:a;if(i)return 3.04*i;return Math.max(n,s)}(r),startPos:[n[0],n[1]]}}))}L.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 s=0,u=e.length;s<u;s++){var l=e[s]*r,c=s<u-1?e[s+1]*r:t.length;a-=Math.abs(Q(t,l,c,r))}var f=0;for(s=0;s<n.length;s+=3){var h=n[s]*r,p=n[s+1]*r,d=n[s+2]*r;f+=Math.abs((t[h]-t[d])*(t[p+1]-t[h+1])-(t[h]-t[p])*(t[d+1]-t[h+1]))}return 0===a&&0===f?0:Math.abs((f-a)/a)},L.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 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(w,n)})}))},et=document.createElement("canvas"),rt=et.getContext("2d",{antialias:!1,alpha:!1});null!==rt&&(rt.imageSmoothingEnabled=!1),et.width=b,et.height=b;var nt,ot=[],it=0,at={width:0,height:0,tileLatLngBounds:new x(new y(0,0),new y(0,0)),imageData:new Uint8ClampedArray(0),visibleDEMPixelBounds:new m(new h(0,0),new h(0,0)),maxHeight:w,maxBuildingHeight:0,raster:[],demZoom:0,dirty:!1,canvasWidth:0,canvasHeight:0},st=function(t){return a(void 0,void 0,void 0,(function(){var e,r,n,o,u,l,c,f,p,d,_,g,v,y,E,M,R,L,S,A,P,U,I,C,D,F,B,z,N,H,O,X,W,Z,j;return s(this,(function(G){switch(G.label){case 0:e=t.map,r=t.getFeatures,n=t.terrainSource,o=t.tileLoaded,u=t.gl,l=n.getSourceUrl,c=n.getElevation,f=n.maxZoom,p=n.tileSize,Y={map:e,getFeatures:r},d=a(void 0,void 0,void 0,(function(){var t,e,r,n;return s(this,(function(o){switch(o.label){case 0:t=Y.map,e=Y.getFeatures,o.label=1;case 1:return o.trys.push([1,3,,4]),r=$,[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,[]]}}))})),_=e.getZoom(),G.label=1;case 1:return G.trys.push([1,4,,5]),_=Math.min(f,_),g=Math.round(_),v=e.getBounds(),y=v.getNorthWest(),E=v.getSouthEast(),M=new m(e.project(y,_),e.project(E,_)),R=M.max.x-M.min.x,L=M.max.y-M.min.y,S=new m(e.project(y,g),e.project(E,g)),A=new h(S.min.x,S.min.y),P=S.max.x-S.min.x,U=S.max.y-S.min.y,(I=S.max.subtract(S.min)).y>I.x&&(A.x-=b,P+=512),C=function(t){for(var e=t.upperLeft,r=t.zoom,n=t.innerWidth,o=t.innerHeight,i=e.divideBy(b).floor(),a=i.x+Math.floor((n+b)/b),s=Math.min(i.y+Math.floor((o+b)/b),Math.pow(2,r)-1),u=[],l=i.x;l<=a;l++)for(var c=i.y;c<=s;c++)u.push({x:l,y:c,z:r});return u}({upperLeft:A,zoom:g,innerWidth:P,innerHeight:U}),D=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)*b,yOffset:(t.y-r)*b}}))}(C),(F=JSON.stringify(D))===nt&&g<f?[2,at=i(i({},at),{visibleDEMPixelBounds:S,demZoom:g,dirty:!0})]:(nt=F,B={width:(K=D).reduce((function(t,e){return e.xOffset>t.xOffset?e:t})).xOffset+b,height:K.reduce((function(t,e){return e.yOffset>t.yOffset?e:t})).yOffset+b},[4,(q=D,k={width:z=B.width,height:N=B.height,crossOrigin:"Anonymous",getSourceUrl:l,getElevation:c,tileSize:p,tileLoaded:o},a(void 0,void 0,void 0,(function(){var t,e,r,n,o,i,u,l,c,f,h;return s(this,(function(p){switch(p.label){case 0:if(t=k.width,e=k.height,r=k.crossOrigin,n=k.getSourceUrl,o=k.getElevation,i=k.tileSize,u=k.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=i===b?t.x:Math.floor(t.x/2),r=i===b?t.y:Math.floor(t.y/2),o=i===b?t.z:t.z-1;c.add(n({x:e,y:r,z:o}))})),f=Array.from(c).map((function(e){return a(void 0,void 0,void 0,(function(){return s(this,(function(a){return[2,new Promise((function(a,s){var u=new Image;ot.push(u),u.onload=function(){q.filter((function(t){var r=i===b?t.x:Math.floor(t.x/2),o=i===b?t.y:Math.floor(t.y/2),a=i===b?t.z:t.z-1;return e===n({x:r,y:o,z:a})})).forEach((function(e){if(i===b)rt.drawImage(u,0,0,b,b);else{var r=514===i?1:0,n=e.x%2*b,a=e.y%2*b;rt.drawImage(u,n,a,b+r,b+r,0,0,b,b)}for(var s=rt.getImageData(0,0,b,b).data,c=0;c<s.length;c+=4){var f=5*(o({r:s[c],g:s[c+1],b:s[c+2],a:0})||0),h=Math.floor(f/256),p=Math.floor(f%256);s[c/2]=h,s[c/2+1]=p}for(c=0;c<b;c++)l.set(s.slice(c*b*2,(c+1)*b*2),2*(e.yOffset*t+c*t+e.xOffset))})),a(null)},u.onerror=function(t){if(u.src!==u.originalSource)return s("new tiles requested");a(null)},u.crossOrigin=r||null,u.src=e,u.originalSource=u.src})).then((function(){it++,u(it,ot.length)}))]}))}))})),p.label=1;case 1:return p.trys.push([1,3,,4]),[4,Promise.all(f)];case 2:return p.sent(),[3,4];case 3:return h=p.sent(),console.log(f.length+" requests aborted",h),[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===(H=G.sent())?[2,at=i(i({},at),{visibleDEMPixelBounds:S,demZoom:g,dirty:!1})]:(O=function(t){var e=t.upperLeft,r=t.width,n=t.height,o=e.divideBy(b).floor().multiplyBy(b),i=o.add([r,n]);return new m(o,i)}({upperLeft:A,width:z,height:N}),X=new x(e.unproject(O.getTopLeft(),g),e.unproject(O.getBottomRight(),g)),W=0,[4,d]);case 3:return Z=G.sent(),W=function(t){var e=t.features,r=t.upperLeftTile,n=t.map,o=t.width,i=t.height,a=t.imageData,s=t.gl,u=r.x,l=r.y,c=r.z,f=T.program,p=T.positionAttributeLocation,d=T.xyzUniformLocation,m=T.dimensionsUniformLocation,_=T.heightMapUniformLocation,x=T.colorUniformLocation,g=T.positionBuffer,v=T.indexBuffer,y=T.targetTexture,E=0;s.useProgram(f),s.activeTexture(s.TEXTURE1);var w=s.createTexture();s.bindTexture(s.TEXTURE_2D,w),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST),s.texImage2D(s.TEXTURE_2D,0,s.LUMINANCE_ALPHA,o,i,0,s.LUMINANCE_ALPHA,s.UNSIGNED_BYTE,a);var M=o*(n.getZoom()>15?2:1),R=i*(n.getZoom()>15?2:1);s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,y),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,M,R,0,s.RGBA,s.UNSIGNED_BYTE,null),n.getZoom()>15&&e.length>0?(s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST)):(s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR)),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.viewport(0,0,M,R);var L=s.createFramebuffer();s.bindFramebuffer(s.FRAMEBUFFER,L);var S=s.COLOR_ATTACHMENT0;s.framebufferTexture2D(s.FRAMEBUFFER,S,s.TEXTURE_2D,y,0),s.bindBuffer(s.ARRAY_BUFFER,g),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,v),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT);var A=u*b,P=l*b,U=new h(A,P);s.uniform3f(d,A,P,c),s.uniform2f(m,o,i),s.uniform1i(_,1);var I=new Float32Array([-1,-1,1,-1,-1,1,1,1]);return s.enableVertexAttribArray(p),s.bufferData(s.ARRAY_BUFFER,I,s.STATIC_DRAW),s.vertexAttribPointer(p,2,s.FLOAT,!1,0,0),s.uniform4f(x,0,0,0,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),e.forEach((function(t){var e=t.buildingHeight,r=t.aPosition,i=t.cuts,u=t.startPos,l=n.project({lng:u[0],lat:u[1]},c).subtract(U).floor(),f=256*a[l.y*o*2+2*l.x]+a[l.y*o*2+2*l.x+1]+5*e;if(!Number.isNaN(f)){var h=Math.floor(f/256)/256,d=Math.floor(f%256)/256;E=Math.max(E,f/5),s.uniform4f(x,h,d,0,1),s.bufferData(s.ARRAY_BUFFER,r,s.DYNAMIC_DRAW),s.vertexAttribPointer(p,2,s.FLOAT,!1,0,0),s.bufferData(s.ELEMENT_ARRAY_BUFFER,i,s.DYNAMIC_DRAW),s.drawElements(s.TRIANGLES,i.length,i.length>256?s.UNSIGNED_SHORT:s.UNSIGNED_BYTE,0)}})),s.deleteTexture(w),E}({upperLeftTile:D[0],width:z,height:N,map:e,features:Z,imageData:H,screenPixelBounds:M,gl:u}),w,at={maxHeight:8848,maxBuildingHeight:W,width:z,height:N,tileLatLngBounds:X,imageData:H,visibleDEMPixelBounds:S,raster:D,demZoom:g,dirty:!0,canvasWidth:R,canvasHeight:L},[3,5];case 4:return j=G.sent(),console.error("Could not decode height map",j),[3,5];case 5:return[2,at]}var q,k,K,Y}))}))},ut=.40909994067971484,lt=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(ut),Math.cos(n));return{dec:Math.asin(Math.sin(ut)*Math.sin(n)),Hi:(4.889714432387314+6.3003876824396166*e-o)%(2*Math.PI)+2*Math.PI}},ct=function(t,e){return[t.r/255,t.g/255,t.b/255,e]},ft=function(t,e){var r=e.date,n=lt(r),o=n.dec,i=n.Hi;t.updateDate({dec:o,Hi:i})},ht=function(t,e){t.updateDateRange(i(i({},e),{getDeclination:lt}))},pt=function(t,e){var r=e.color,n=e.opacity,o=ct(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,s=t.opacity,u=t.maxZoom;try{var l=n.maxHeight,c=n.maxBuildingHeight,f=n.width,h=n.height,p=n.tileLatLngBounds,d=n.imageData,m=n.visibleDEMPixelBounds,_=n.demZoom;if(0===f||0===h)return;var x=m.min,g=m.max;if(!x||!g)return;var v=g.subtract(x).divideBy(_>u?Math.pow(2,_-u):1),y=v.x,E=v.y,T=r.project(p.getNorthWest(),_),w=x.divideBy(_>u?Math.pow(2,_-u):1).subtract(T),M=w.x,R=w.y,L=M/f,S=R/h,A=L+y/f,P=S+E/h,U=T.y/b/Math.pow(2,_),I=h/b/Math.pow(2,_),C=p.getWest(),D=Math.abs(p.getWest()-p.getEast())/f;!function(t,e){var r=e.color,n=e.opacity,o=e.date,a=e.imageData,s=e.maxBuildingHeight,u=ct(r,n),l=lt(o),c=l.dec,f=l.Hi;t.updateLocation(i({dec:c,Hi:f,colorVec:u,step:1},e)),tt(a).then((function(e){var r=e.maxHeight;t.updateMaxHeight({maxHeight:Math.max(r,s)})}))}(e,{imageData:d,maxHeight:l,maxBuildingHeight:c,width:f,height:h,date:o,heightMapZoom:_,mapZoom:r.getZoom(),xStart:L,yStart:S,xEnd:A,yEnd:P,topYCoord:U,ySize:I,color:a,opacity:s,west:C,dLng:D})}catch(t){console.error("EXCEPTION",t)}};var mt,_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 h(function(t,e){return(t+180)/360*Math.pow(2,e)*b}(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)*b}(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/b/Math.pow(2,i),180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))),function(t,e){return t/b/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}};function xt(t){var e=t.context,r=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:e,vSrc:"precision lowp float;precision lowp int;precision lowp sampler2D;attribute vec2 aPos;varying vec2 vTexCoordCropped;varying vec2 vTexCoordFull;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);}",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);}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 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 float user_exposureTimeStep;float kernelResult;void kernel(){float maxHeight=user_maxHeight/1000.0;float user_x=vTexCoordCropped.x;float user_y=vTexCoordCropped.y;float user_z=getElevationFromSampler2D(user_a,user_x,user_y);float user_PI=3.141592653589793;float user_2PI=6.283185307179586;float earthRadiusInKm=6378.137;float user_deg=57.29577951308232;float user_y_coord=user_topYCoord+(user_y*user_ySize);float user_lat_coord=(user_y_coord-0.5)/-0.15915494309189532;float user_lat=(2.0*atan(exp(user_lat_coord)))-(user_PI/2.0);float user_rad=0.017453292519943295;float user_lng=(user_west+(user_dLng*user_x*user_width));float user_H=integerCorrectionModulo((user_Hi-(user_rad*-user_lng)),user_2PI);float sun_azimuth=atan2(sin(user_H),((cos(user_H)*sin(user_lat))-(tan(user_dec)*cos(user_lat))));float sun_altitude=asin(((sin(user_lat)*sin(user_dec))+((cos(user_lat)*cos(user_dec))*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(0.0,0.0,0.0,0.0);}else{color(user_color.r,user_color.g,user_color.b,user_color.a);}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_exposureTimeStep,user_color.g,user_color.b,1.0);}if(user_outputSunExposure){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(red,green,aggregateColor.r/h),mix(green,blue,(aggregateColor.r-h)/(1.0-h)),step(h,aggregateColor.r));color(col.r,col.g,col.b,0.5);}}}void main(void){kernel();gl_FragColor=actualColor;}"});e.useProgram(r);var n=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,n);var o=new Float32Array([-1,-1,1,-1,-1,1,1,1]);e.bufferData(e.ARRAY_BUFFER,o,e.STATIC_DRAW);var i=e.getAttribLocation(r,"aPos");e.enableVertexAttribArray(i),e.vertexAttribPointer(i,2,e.FLOAT,!1,0,0),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA);var a=e.getUniformLocation(r,"user_a");e.uniform1i(a,0);var s=e.getUniformLocation(r,"user_width"),u=e.getUniformLocation(r,"user_height"),l=e.getUniformLocation(r,"user_maxHeight"),c=e.getUniformLocation(r,"user_zoom"),f=e.getUniformLocation(r,"user_topYCoord"),h=e.getUniformLocation(r,"user_ySize"),p=e.getUniformLocation(r,"user_step"),d=e.getUniformLocation(r,"user_west"),m=e.getUniformLocation(r,"user_dLng"),_=e.getUniformLocation(r,"user_dec"),x=e.getUniformLocation(r,"user_Hi"),g=e.getUniformLocation(r,"user_color"),v=e.getUniformLocation(r,"user_xStart"),y=e.getUniformLocation(r,"user_yStart"),E=e.getUniformLocation(r,"user_xEnd"),T=e.getUniformLocation(r,"user_yEnd"),w=e.getUniformLocation(r,"user_sunExposureTexture");e.uniform1i(w,2);var b=e.getUniformLocation(r,"user_renderToSunExposureTexture"),M=e.getUniformLocation(r,"user_outputSunExposure"),R=e.getUniformLocation(r,"user_exposureTimeStep"),L=function(){e.clear(e.COLOR_BUFFER_BIT),e.drawArrays(e.TRIANGLE_STRIP,0,4)};return{updateLocation:function(t){t.imageData;var o=t.width,a=t.height,w=t.maxHeight,b=t.heightMapZoom;t.mapZoom;var M=t.topYCoord,R=t.ySize,S=t.colorVec,A=t.step,P=t.west,U=t.dLng,I=t.dec,C=t.Hi,D=t.xStart,F=t.xEnd,B=t.yStart,z=t.yEnd;e.useProgram(r),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindBuffer(e.ARRAY_BUFFER,n),e.vertexAttribPointer(i,2,e.FLOAT,!1,0,0),e.uniform1f(s,o),e.uniform1f(u,a),e.uniform1f(l,w),e.uniform1f(c,b),e.uniform1f(f,M),e.uniform1f(h,R),e.uniform4fv(g,S),e.uniform1f(p,A),e.uniform1f(d,P),e.uniform1f(m,U),e.uniform1f(_,I),e.uniform1f(x,C),e.uniform1f(v,D),e.uniform1f(y,B),e.uniform1f(E,F),e.uniform1f(T,z),window.requestAnimationFrame(L)},updateViewport:function(t){var r=t.xStart,n=t.yStart,o=t.xEnd,i=t.yEnd;e.uniform1f(v,r),e.uniform1f(y,n),e.uniform1f(E,o),e.uniform1f(T,i),window.requestAnimationFrame(L)},updateDate:function(t){var r=t.dec,n=t.Hi;e.uniform1f(_,r),e.uniform1f(x,n),window.requestAnimationFrame(L)},updateDateRange:function(t){var r=t.start,n=t.end,o=t.getDeclination,i=t.emit;e.uniform1f(R,.04);var a=Math.floor((n.getTime()-r.getTime())/25),s=e.canvas.width,u=e.canvas.height,l=e.createTexture();e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,l),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,s,u,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR);var c=e.createTexture();e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,c),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,s,u,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.uniform1i(b,1);var f=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,f);var h=e.COLOR_ATTACHMENT0;e.viewport(0,0,s,u);for(var p=0;p<25;p++){i("tilesloaded",p,24),p%2==0?(e.uniform1i(w,2),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,l),e.framebufferTexture2D(e.FRAMEBUFFER,h,e.TEXTURE_2D,l,0)):(e.uniform1i(w,1),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,c),e.framebufferTexture2D(e.FRAMEBUFFER,h,e.TEXTURE_2D,c,0));var d=o(new Date(r.getTime()+a*p)),m=d.dec,g=d.Hi;e.uniform1f(_,m),e.uniform1f(x,g),e.clear(e.COLOR_BUFFER_BIT),e.drawArrays(e.TRIANGLE_STRIP,0,4)}e.bindFramebuffer(e.FRAMEBUFFER,null),e.uniform1i(M,1),window.requestAnimationFrame((function(){L(),e.uniform1i(b,0),e.uniform1i(M,0),e.deleteTexture(l),e.deleteTexture(c)}))},updateColor:function(t){var r=t.colorVec;e.uniform4fv(g,r),window.requestAnimationFrame(L)},updateMaxHeight:function(t){var r=t.maxHeight;e.uniform1f(l,r)}}}!function(t){t.LOW="low",t.MED="medium",t.HIGH="high"}(mt||(mt={}));var gt=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,quality:mt.MED,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 s(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 s(this,(function(e){if(200!==t.status)throw new Error("Could not load ShadeMap API");return[2]}))}))})),o._suncalc=r.default||window.SunCalc,o._canvasElWidth=window.innerWidth,o._canvasElHeight=window.innerHeight;var u={preserveDrawingBuffer:!0,antialias:!1};return o._canvas=document.createElement("canvas"),o._gl=o._canvas.getContext("webgl",u)||o._canvas.getContext("experimental-webgl",u),o._compiledKernel=xt({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._resize=o._resize.bind(o),o}return o(e,t),e.prototype.onRemove=function(){return this._map&&(this._map.off("moveend",this._reset),this._map.off("resize",this._resize)),this},e.prototype.setDate=function(t){return this.options.date.getTime()!==t.getTime()?(this.options.date=t,this._compiledKernel&&(ft(this._compiledKernel,{date:this.options.date}),this._flush())):this.emit("idle"),this},e.prototype.setColor=function(t){return this.options.color!==t&&(this.options.color=t,this._color=this._parseColor(this.options.color),this._compiledKernel&&(pt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this},e.prototype.setOpacity=function(t){return this.options.opacity!==t&&(this.options.opacity=t,this._compiledKernel&&(pt(this._compiledKernel,{color:this._color,opacity:this.options.opacity}),this._flush())),this},e.prototype.setQuality=function(t){return this.options.quality!==t&&(this.options.quality=t,this._resizeCanvas(),this._reset()),this},e.prototype.setShowExposure=function(t){if(!this._suncalc)throw new Error("Using sun exposure requires suncalc library");if(this.options.showExposure!==t&&this._map&&this._compiledKernel){if(this.options.showExposure=t,!0===t){var e=_t(this._map).getCenter(),r=this._suncalc.getTimes(this.options.date,e.lat,e.lng),n=r.sunrise,o=r.sunset;ht(this._compiledKernel,{start:n,end:o,emit:this.emit.bind(this)})}else ft(this._compiledKernel,{date:this.options.date});this._flush()}return this},e.prototype._resize=function(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.options.debug("_resize w:"+t+" h:"+e),this._canvasElWidth=t,this._canvasElHeight=e,this._resizeCanvas()},e.prototype._resizeCanvas=function(){var t=this._canvasElWidth*(this.options.quality===mt.HIGH?2:1),e=this._canvasElHeight*(this.options.quality===mt.HIGH?2:1),r=window.innerWidth*window.innerHeight*(this.options.quality===mt.HIGH?2:1),n=t*e,o=Math.sqrt(r/n);this._canvas.width=t*o,this._canvas.height=e*o,this._gl.viewport(0,0,t*o,e*o)},e.prototype._reset=function(){return a(this,void 0,void 0,(function(){var t,e,r,n=this;return s(this,(function(o){switch(o.label){case 0:if(this.options.debug("_reset()"),!this._map)return[3,2];t=_t(this._map),e=void 0;try{e=t.getBounds()}catch(t){return console.error("Invalid bounds returned: ",t),[2,this]}return[4,st({gl:this._gl,map:t,terrainSource:this.options.terrainSource,getFeatures:this.options.getFeatures,quality:mt.MED,tileLoaded:function(t,e){return n.emit("tileloaded",t,e)}})];case 1:(r=o.sent()).dirty&&(this._resize(r.canvasWidth,r.canvasHeight),this._draw(r,e)),o.label=2;case 2:return[2,this]}}))}))},e.prototype._draw=function(t,e){var r=this;return this.options.debug("_draw()"),setTimeout((function(){if(r._canvas&&r._compiledKernel&&r._map){if(dt({kernel:r._compiledKernel,map:_t(r._map),heightMap:t,color:r._color,opacity:r.options.opacity,now:r.options.date,maxZoom:r.options.terrainSource.maxZoom}),r.options.showExposure&&r._suncalc){var n=r._map.getCenter(),o=r._suncalc.getTimes(r.options.date,n.lat,n.lng),i=o.sunrise,a=o.sunset;ht(r._compiledKernel,{start:i,end:a,emit:r.emit.bind(r)})}r._repositionCanvas(e)}}),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._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}(R),vt="canvas-source",yt="attribution-source",Et="canvas-layer",Tt="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._resizeHandler=function(){return r._resize(window.innerWidth,window.innerHeight)},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,this._resizeCanvas(),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(),s=[[n.lng,n.lat],[o.lng,o.lat],[i.lng,i.lat],[a.lng,a.lat]];t.addSource(vt,{type:"canvas",canvas:this._canvas,coordinates:s,animate:!1}),t.addLayer({id:Et,type:"raster",source:vt,paint:{"raster-fade-duration":0}}),t.addSource(yt,{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:Tt,type:"fill",source:yt});var u=t.getSource("canvas-source"),l=function(){e._refreshing>0&&(u.texture.update(e._canvas,{premultiply:!0}),u.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._map.on("resize",this._resizeHandler),this._moveEndHandler(),this},e.prototype.onRemove=function(){return this._map&&(this._map.off("moveend",this._moveEndHandler),this._map.off("resize",this._resizeHandler),this._map.removeLayer(Tt),this._map.removeLayer(Et),this._map.removeSource(yt),this._map.removeSource(vt)),cancelAnimationFrame(this._raf),document.body.removeChild(this._canvas),this.options.debug("onRemove called"),this},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}(gt)}));
package/examples/map.html CHANGED
@@ -7,6 +7,7 @@
7
7
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
8
8
  <link href='https://api.mapbox.com/mapbox-gl-js/v2.7.0/mapbox-gl.css' rel='stylesheet' />
9
9
  <script src='https://api.mapbox.com/mapbox-gl-js/v2.7.0/mapbox-gl.js'></script>
10
+ <script src='https://www.unpkg.com/suncalc@1.9.0/suncalc.js'></script>
10
11
  <script src="../dist/mapbox-gl-shadow-simulator.umd.min.js"></script>
11
12
  <style>
12
13
  body {
@@ -35,6 +36,7 @@
35
36
  <button id="increment">+1 hour</button>
36
37
  <button id="play">Play</button>
37
38
  <button id="stop">Stop</button>
39
+ <label><input id="exposure" type="checkbox" autocomplete="off" />24 hour sun exposure</label>
38
40
  <button>
39
41
  <a href="https://shademap.app/about" target="_blank">Get API key</a>
40
42
  </button>
@@ -106,9 +108,9 @@
106
108
  const decrement = document.getElementById('decrement');
107
109
  const play = document.getElementById('play');
108
110
  const stop = document.getElementById('stop');
111
+ const exposure = document.getElementById('exposure');
109
112
 
110
113
  increment.addEventListener('click', () => {
111
-
112
114
  now = new Date(now.getTime() + 3600000);
113
115
  shadeMap && shadeMap.setDate(now);
114
116
  }, false);
@@ -128,6 +130,24 @@
128
130
  stop.addEventListener('click', () => {
129
131
  clearInterval(intervalTimer);
130
132
  })
133
+
134
+ exposure.addEventListener('click', (e) => {
135
+ clearInterval(intervalTimer);
136
+ const target = e.target;
137
+ if (!target.checked) {
138
+ shadeMap && shadeMap.setShowExposure(false);
139
+ increment.disabled = false;
140
+ decrement.disabled = false;
141
+ play.disabled = false;
142
+ stop.disabled = false;
143
+ } else {
144
+ shadeMap && shadeMap.setShowExposure(true);
145
+ increment.disabled = true
146
+ decrement.disabled = true;
147
+ play.disabled = true;
148
+ stop.disabled = true;
149
+ }
150
+ })
131
151
  /* End controls setup */
132
152
  </script>
133
153
  </body>
package/examples/node.ts CHANGED
@@ -59,12 +59,13 @@ map.on('load', () => {
59
59
  /* End ShadeMap setup */
60
60
 
61
61
  /* Controls setup */
62
- let intervalTimer;
62
+ let intervalTimer: number;
63
63
 
64
- const increment = document.getElementById('increment') as HTMLElement;
65
- const decrement = document.getElementById('decrement') as HTMLElement;
66
- const play = document.getElementById('play') as HTMLElement;
67
- const stop = document.getElementById('stop') as HTMLElement;
64
+ const increment = document.getElementById('increment') as HTMLButtonElement;
65
+ const decrement = document.getElementById('decrement') as HTMLButtonElement;
66
+ const play = document.getElementById('play') as HTMLButtonElement;
67
+ const stop = document.getElementById('stop') as HTMLButtonElement;
68
+ const exposure = document.getElementById('exposure') as HTMLInputElement;
68
69
 
69
70
  increment.addEventListener('click', () => {
70
71
 
@@ -86,5 +87,23 @@ play.addEventListener('click', () => {
86
87
 
87
88
  stop.addEventListener('click', () => {
88
89
  clearInterval(intervalTimer);
90
+ });
91
+
92
+ exposure.addEventListener('click', (e) => {
93
+ clearInterval(intervalTimer);
94
+ const target = e.target as HTMLInputElement;
95
+ if (!target.checked) {
96
+ shadeMap && shadeMap.setShowExposure(false);
97
+ increment.disabled = false;
98
+ decrement.disabled = false;
99
+ play.disabled = false;
100
+ stop.disabled = false;
101
+ } else {
102
+ shadeMap && shadeMap.setShowExposure(true);
103
+ increment.disabled = true
104
+ decrement.disabled = true;
105
+ play.disabled = true;
106
+ stop.disabled = true;
107
+ }
89
108
  })
90
109
  /* End controls setup */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapbox-gl-shadow-simulator",
3
- "version": "0.14.1",
3
+ "version": "0.15.0",
4
4
  "description": "Display terrain and structure shadows cast by the sun in a custom style layer",
5
5
  "main": "dist/mapbox-gl-shadow-simulator.umd.min.js",
6
6
  "types": "dist/mapbox-gl-shadow-simulator.d.ts",