-
Notifications
You must be signed in to change notification settings - Fork 1
/
aerismaps-visualizer.min.js
2 lines (2 loc) · 17.9 KB
/
aerismaps-visualizer.min.js
1
2
/*! AerisMaps.Visualizer 2019-08-09 */
!function(a,b){"use strict";function c(a){this.message=a,"captureStackTrace"in Error?Error.captureStackTrace(this,c):this.stack=(new Error).stack}var d=a.AerisMaps||{};a.AerisMaps=d;var e=function(a,b){for(var c in b)b.hasOwnProperty(c)&&("object"==typeof a[c]&&a.hasOwnProperty(c)&&null!=a[c]?e(a[c],b[c]):a[c]=b[c]);return a},f=function(a){if("object"!=typeof a)return[];var b=[];for(var c in a)hasOwnProperty.call(a,c)&&b.push(c);return b},g=function(a){return a.constructor.toString().indexOf("Date")>-1},h=function(a,b){var c=a.getHours(),d="AM";b.indexOf("t")>-1&&c>=12&&(c>12&&(c-=12),d="PM");var e={"M+":a.getMonth()+1,"d+":a.getDate(),"h+":c,"m+":a.getMinutes(),"s+":a.getSeconds(),"q+":Math.floor((a.getMonth()+3)/3),S:a.getMilliseconds(),"t+":d};/(y+)/.test(b)&&(b=b.replace(RegExp.$1,(a.getFullYear()+"").substr(4-RegExp.$1.length)));for(var f in e)new RegExp("("+f+")").test(b)&&(b=b.replace(RegExp.$1,1==RegExp.$1.length?e[f]:("00"+e[f]).substr((""+e[f]).length)));return b},i=function(a,b){var c=a;for(var d in b)c=c.replace("{{"+d+"}}",b[d]);return c},j=function(a,b){a=a||[];var c=[];return a.forEach(function(a){b(a)&&c.push(a)}),c},k=function(a,b){var c,d=-1,e=a.length,f=b[0],g=b[1],h=b[2];switch(b.length){case 0:for(;++d<e;)(c=a[d]).callback.call(c.ctx);return;case 1:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f);return;case 2:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f,g);return;case 3:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f,g,h);return;default:for(;++d<e;)(c=a[d]).callback.apply(c.ctx,b);return}},l={on:function(a,b,c){return this._events||(this._events={}),(this._events[a]||(this._events[a]=[])).push({callback:b,context:c,ctx:c||this}),this},once:function(a,b,c){var d=this,e=_.once(function(){d.off(a,e),b.apply(this,arguments)});return e._callback=b,this.on(a,e,c)},off:function(a,b,c){if(!a&&!b&&!c)return this._events=void 0,this;for(var d,e=a?[a]:_.keys(this._events),f=0,g=e.lenght;f<g;f++){d=e[f];var h=this._events[d];if(h)if(b||c){for(var i=[],j=0,k=h.length;j<k;j++){var l=h[j];(b&&b!==l.callback&&b!==l.callback._callback||c&&c!==l.context)&&i.push(l)}i.length?this._events[d]=i:delete this._events[d]}else delete this._events[d]}return this},trigger:function(a){if(!this._events)return this;var b=arguments||[];if("[object Array]"!==Object.prototype.toString.call(b)){for(var c=[],d=f(b),e=0,g=d.length;e<g;e++)c.push(b[d[e]]);b=c}b=b.slice(1);var h=this._events[a],i=this._events.all;return h&&k(h,b),i&&k(i,arguments),this}},m=0,n=function(c){c.method=c.method||"GET";var d=null,e=a.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");e.onreadystatechange=function(){var b=e;if(4==b.readyState&&200==b.status){var f,g=b.getResponseHeader("Content-Type");f=g.match(/xml/gi)?b.responseXML:g.match(/json/gi)?JSON.parse(b.responseText):b.responseText,d?a[d](b.responseText):c.success&&c.success(f)}else 4==b.readyState&&200!=b.status&&c.error&&c.error(b.responseText,b.status)},c.dataType&&"jsonp"==c.dataType&&(d="__aw__"+ ++m);var f="";if(c.params)if(c.params.substr)f=c.params;else{for(var g in c.params)f+="&"+encodeURIComponent(g)+"="+encodeURIComponent(c.params[g]);f=f.substr(1)}if(d){var h=c.url+f;h=h+(-1!==h.indexOf("?")?"&":"?")+"callback="+d;var i=b.createElement("script");i.src=h,b.getElementsByTagName("body")[0].appendChild(i),a[d]=function(b){delete a[d],i.parentElement.removeChild(i),c.success&&c.success(b)}}else if("POST"==c.method){e.open("POST",c.url,!0);for(var j in c.headers)e.setRequestHeader(j,c.headers[j]);e.setRequestHeader("X-Requested-With","XMLHttpRequest"),e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.send(c.params)}else{f&&(f=(c.url.match(/\?/)?"&":"?")+f),e.open("GET",c.url+f,!0);for(var j in c.headers)e.setRequestHeader(j,c.headers[j]);e.send(null)}return e},o=function(a){var c=b.createElement("div"),d=b.createDocumentFragment(),e=null;for(c.innerHTML=a;e=c.firstChild;)d.appendChild(e);return d},p=function(a,b){var c,d=a.ownerDocument.defaultView;return d&&d.getComputedStyle?(b=b.replace(/([A-Z])/g,"-$1").toLowerCase(),d.getComputedStyle(a,null).getPropertyValue(b)):a.currentStyle&&(b=b.replace(/\-(\w)/g,function(a,b){return b.toUpperCase()}),c=a.currentStyle[b],/^\d+(em|pt|%|ex)?$/i.test(c))?function(b){var c=a.style.left,d=a.runtimeStyle.left;return a.runtimeStyle.left=a.currentStyle.left,a.style.left=b||0,b=a.style.pixelLeft+"px",a.style.left=c,a.runtimeStyle.left=d,b}(c):c},q=function(a){return this.el=a,this};q.prototype.select=function(a){return q.select(a,this.el)},q.prototype.show=function(){return this.el.style.display="block",this},q.prototype.hide=function(){return this.el.style.display="none",this},q.prototype.visible=function(){return"none"!=this.css("display")},q.prototype.css=function(a,b){if("string"==typeof a){if(null===b)return p(this.el,a);this.el.style[a]=b}else for(var c in a)this.el.style[c]=a[c];return this},q.prototype.addClass=function(a){var b=this.el;if(void 0!==a&&""!==a)if(b.classList)a=a.match(/\s/)?a.split(" "):[a],a.forEach(function(a){b.classList.add(a)});else{var c=b.className;c&&(c+=" "),b.className+=c+a}return this},q.prototype.removeClass=function(a){var b=this.el;if(void 0!==a&&""!==a)if(b.classList)a=a.match(/\s/)?a.split(" "):[a],a.forEach(function(a){b.classList.remove(a)});else{var c=new RegExp("\b"+a+"\b");b.className.replace(c,"")}return this},q.prototype.toggleClass=function(a){return this.hasClass(a)?this.removeClass(a):this.addClass(a),this},q.prototype.hasClass=function(a){return void 0!==a&&""!==a&&(this.el.classList?this.el.classList.contains(a):new RegExp("(^|\\s+)"+a+"(\\s+|$)").test(this.el.className))},q.prototype.html=function(a){if(void 0==a)return this.el.innerHTML;this.el.innerHTML=a},q.prototype.create=function(a){var b=a;return"string"==typeof b&&(b=o(a)),void 0===b.ext&&q.extend(b),b},q.prototype.append=function(a){var b=this.create(a);return this.el.appendChild(b),this},q.prototype.prepend=function(a){var c=this.create(a);return b.body.insertBefore(c,this.el.firstChild),this},q.prototype.remove=function(){this.el.parentNode.removeChild(this.el)},q.prototype.empty=function(){for(;this.el.firstChild;)this.el.removeChild(this.el.firstChild);return this},q.select=function(c,d){if("string"!=typeof c)return c;if(d||(d=b),d!=b&&d!=a){var e=b.documentMode||/Edge/.test(navigator.userAgent),f=c.match(/^\:scope/);f&&0!=f.length||e||(c=":scope "+c)}var g=Array.prototype.slice.call(d.querySelectorAll(c));return g.forEach(function(a){q.extend(a)}),1==g.length&&(g=g[0]),g},q.extend=function(a){a.ext=new q(a)},c.prototype=Object.create(Error.prototype),c.prototype.name="InvalidArgumentException",c.prototype.constructor=c,d.url="//{{server}}/{{client_id}}_{{client_secret}}/{{layers}}/{{size}}/{{region}}/{{time}}.{{format}}";var r=function(a,b){var d=this,f=e({server:"maps.aerisapi.com",loc:null,keys:{id:null,secret:null},refresh:0,autoplay:!1,autosize:!0,events:{click:function(){d.isPaused()||!d.isAnimating()?d.play():d.pause()}},map:{zoom:6,format:"png",size:{width:600,height:600},layers:["flat","radar","admin"],combined:!1},animation:{from:-21600,to:0,duration:2,endDelay:1,intervals:10},overlays:{title:null,timestamp:{format:"MM/dd/yyyy hh:mm tt",continuous:!0},branding:{html:null,img:null}}},b),h=(new Date).getTime();if(g(f.animation.from)?(this._fromOffset=null,f.animation.from=f.animation.from.getTime()):(this._fromOffset=1e3*f.animation.from,f.animation.from=h+this._fromOffset),g(f.animation.to)?(this._toOffset=null,f.animation.to=f.animation.to.getTime()):(this._toOffset=1e3*f.animation.to,f.animation.to=h+this._toOffset),this.target="string"==typeof a?q.select(a):q.extend(a),this.config=f,this.duration=f.animation.duration,this._endDelay=f.animation.endDelay,this._from=f.animation.from,this._to=f.animation.to,this._intervals=f.animation.intervals,this._elapsed=0,this._time=this._from,this._increment=0,this._delay=1/60,this._paused=!1,this._times=[],this._images={},this._currentImage=null,this._currentIntervalTime=0,this._isLoadingMetadata=!1,this._isLoading=!1,this._metadataCallbacks=[],!f.keys.id||0==f.keys.id.length||!f.keys.secret||0==f.keys.secret.length)throw new c('Invalid configuration values for "keys.id" and/or "keys.secret"');if(!f.loc||0==f.loc.length)throw new c('Invalid configuration value for "loc"');return this.init(),this};e(r.prototype,l),r.prototype.init=function(){if(this.target){var a=this;this.target.ext.css({position:"relative"}),!0===this.config.autosize&&this.target.ext.css({width:this.config.map.size.width+"px",height:this.config.map.size.height+"px"}),this.target.ext.addClass("amp-map");if(["base","content","overlay"].forEach(function(b,c){a.target.ext.append('<div class="amp-map-'+b+'"></div>');var d=a.target.ext.select(".amp-map-"+b);d.ext.css({position:"absolute",top:0,left:0,bottom:0,right:0,"z-index":c}),a["_"+b+"Target"]=d}),this.config.events)for(var b in this.config.events)this.target.addEventListener(b,function(){a.config.events[b]()});if(this.config.overlays.timestamp){this.target.ext.append('<div class="amp-map-timestamp"></div>'),this._timestamp=this.target.ext.select(".amp-map-timestamp"),this._timestamp.ext.css({"z-index":10});var c=this.config.overlays.timestamp;"object"==typeof c&&void 0!==c.continuous&&(!1===c.continuous?this.on("advance:image",function(b){a._updateTimestampOverlay(b.time)}):this.on("advance",function(b){a._updateTimestampOverlay(b.time)})),this.on("load:progress",function(b){a._updateTimestampOverlay(b.time)})}if(this.config.overlays.title&&(this.target.ext.append('<div class="amp-map-title">'+this.config.overlays.title+"</div>"),this.target.ext.select(".amp-map-title").ext.css({"z-index":11})),this.config.overlays.branding){this.target.ext.append('<div class="amp-map-branding"></div>');var d=this.config.overlays.branding,e=this.target.ext.select(".amp-map-branding");e.ext.css({"z-index":12}),void 0!=d.img?e.ext.html('<img src="'+d.img+'" />'):void 0!=d.html&&e.ext.html(d.html)}this._fetchLayerMetadata(function(){a.startup()})}},r.prototype.startup=function(){if(this.config.map.combined||(this._loadBase(this.config.map.layers),this._loadOverlays(this.config.map.layers)),this._times=this._timesForIntervals(),this.config.autoplay)this.play();else{var a=(new Date).getTime(),b=a;this._from>=a?b=this._from:this._to<=a&&(b=this._to),this.goToTime(b)}},r.prototype.play=function(){if(!this.isAnimating()&&!this._isLoading)if(!this._hasImages()||this._totalImages()<this._intervals)if(this._isLoadingMetadata){var a=this;this._metadataCallbacks.push(function(){a._loadData()})}else this._loadData();else this._paused=!1,this._updateTiming(),this.trigger("play",{from:new Date(this._from),to:new Date(this._to)}),this._time!=this._to&&this._to!=this._from||this.goToTime(this._from),function(a){a._timer=setInterval(function(){var b=a._time+a._increment;b>a._to?a.restart():a.goToTime(b)},1e3*a._delay)}(this)},r.prototype.stop=function(){this.pause(!1),this.trigger("stop"),this._paused=!1,null!=this._to&&this.goToTime(this._to)},r.prototype.restart=function(){this.pause(),function(a){a._restartTimeout&&clearTimeout(a._restartTimeout),a._restartTimeout=setTimeout(function(){a.goToTime(a._from),a.play()},1e3*a._endDelay)}(this)},r.prototype.pause=function(b){!1!==b&&(b=!0),this._paused=!0,this._timer&&a.clearInterval(this._timer),this._timer=null,this._restartTimeout&&a.clearTimeout(this._restartTimeout),b&&this.trigger("pause")},r.prototype.goToTime=function(a){this._time=g(a)?a.getTime():a,this._offset=a-this._from;var b=this._intervalClosestToTime(a),c=this._imageClosestToTime(b);c?(this._currentIntervalTime=b,c!=this._currentImage&&(c.ext.show(),this._currentImage&&this._currentImage.ext&&this._currentImage.ext.hide(),this._currentImage=c)):this.isAnimating()||b!=this._currentIntervalTime&&(this._loadInterval(b,!0),this._currentIntervalTime=b),this.trigger("advance",{time:this._time,offset:this._offset})},r.prototype.isAnimating=function(){return null!=this._timer},r.prototype.isPaused=function(){return this._paused},r.prototype.totalTime=function(){return this._to-this._from},r.prototype.currentTime=function(){return this._time},r.prototype.position=function(){this._offset,this.totalTime()},r.prototype.startDate=function(){return new Date(this._from)},r.prototype.setStartDate=function(a){this.stop(),this._from=g(a)?a.getTime():a,this._updateTiming(),this._images={},this._times=this._timesForIntervals(),this.trigger("start:change",this._from)},r.prototype.setStartOffset=function(a){this._fromOffset=a;var b=(new Date).getTime();this.setStartDate(b+a)},r.prototype.endDate=function(){return new Date(this._to)},r.prototype.setEndDate=function(a){this.stop(),this._to=g(a)?a.getTime():a,this._updateTiming(),this._images={},this._times=this._timesForIntervals(),this.trigger("end:change",this._to);var b=(new Date).getTime();this._to>b&&this.goToTime(b)},r.prototype.setEndOffset=function(a){this._toOffset=a;var b=(new Date).getTime();this.setEndDate(b+a)},r.prototype._updateTiming=function(){this._increment=(this._to-this._from)/this.duration*this._delay},r.prototype._intervalClosestToTime=function(a){var b=this._from,c=Math.abs(a-b);void 0==this._times&&(this._times=this._timesForIntervals());for(var d in this._times){var e=this._times[d],f=Math.abs(a-e);f<c&&(c=f,b=e)}return Math.round(b)},r.prototype._imageClosestToTime=function(a){var b=null,c=this._from,d=Math.abs(a-c);for(var e in this._images){var f=Math.abs(a-e);f<d&&(d=f,c=e)}return c!=this._lastImageTime&&this._images[c]&&(b=this._images[c],c=Math.round(c),this._lastImageTime=c,this.trigger("advance:image",{time:c,img:b})),b},r.prototype._hasImages=function(){var a=this._images;if(null===a)return!1;var b=!1;for(var c in a)if(hasOwnProperty.call(a,c))return!0;return b},r.prototype._totalImages=function(){var a=0;for(var b in this._images)a+=1;return a},r.prototype._updateTimestampOverlay=function(a){if(this._timestamp){var b=this.config.overlays.timestamp,c=null;"string"==typeof b?c=b:b.format&&(c=b.format),this._timestamp.innerHTML=h(new Date(a),c)}},r.prototype._timesForIntervals=function(){var a=(new Date).getTime();null!==this._fromOffset&&(this._from=a+this._fromOffset,this._time=this._from),null!==this._toOffset&&(this._to=a+this._toOffset);for(var b=this._intervals,c=Math.round((this._to-this._from)/(b-1)),d=[],e=null,f=0;f<b-1;f++){var g=this._from+c*f;0!=f&&g==e||(d.push(Math.round(g)),e=g)}return d.push(this._to),this._intervals=d.length,d};var s=null,t=null;r.prototype._loadData=function(){if(!this._isLoading){this._isLoading=!0,this._images={},this._contentTarget.ext.empty();var a=this._timesForIntervals();this.trigger("load:start",{times:a});var b=this,c=0,d=function(){b._loadInterval(a[c],!0,function(){c++,c>=a.length?(b._isLoading=!1,b.trigger("load:done"),b.play(),b.config.refresh>0&&(s&&clearTimeout(s),s=setTimeout(function(){b.stop(),b._loadData()},1e3*b.config.refresh))):d()})};t&&clearTimeout(t),t=setTimeout(function(){d()},100)}};var u={};r.prototype._loadInterval=function(a,b,c){a=Math.round(a);var d=q.select("#amp-"+a);if(d&&d.length>0)return void 0!=d[0]&&(d=d[0]),d.ext.show(),self._currentImage&&self._currentImage.ext&&self._currentImage.ext.hide(),self._currentImage=d,void(c&&c());var e=this.config,g=new Date(a),i=new Date(g.getTime()+60*g.getTimezoneOffset()*1e3),k=h(i,"yyyyMMddhhmm00"),l=this.layerGroups.base||[],m=this.layerGroups.overlay||[],n=l.concat(m),o=e.map.layers;e.map.combined||(o=j(e.map.layers,function(a){for(var b=0,c=n.length;b<c;b+=1)if(null!=a.match(new RegExp("^"+n[b])))return!1;return!0}));var p=this._urlForLayers(o,k);if(this._images||(this._images={}),this._images[a])return void(c&&c());var r=new Image;r.src=p,u[a]=r,function(d){r.onload=function(){d._images||(d._images={});var e=q.select("#amp-"+a);e&&1===e.length&&e.ext.remove();var g='<img id="amp-'+a+'" src="'+r.src+'" width="'+d.config.map.size.width+'" height="'+d.config.map.size.height+'" style="position:absolute;">';d._contentTarget.ext.append(g),e=q.select("#amp-"+a),e&&b&&(void 0!=e[0]&&(e=e[0]),d._images[a]=e),d._currentImage&&d._currentImage.ext&&d._currentImage.ext.hide(),d._currentImage=e,d.trigger("load:image",{date:new Date(a),src:r.src}),d.trigger("load:progress",{time:a,loaded:f(d._images).length,total:d._intervals}),c&&c(),u[a]=null}}(this)},r.prototype._loadBase=function(a){var b=this.layerGroups.base;if(b){var a=j(a,function(a){for(var c=0,d=b.length;c<d;c+=1)if(null!=a.match(new RegExp("^"+b[c])))return!0;return!1});if(a.length>0){var c=this._urlForLayers(a);this._baseTarget.ext.html('<img src="'+c+'" width="'+this.config.map.size.width+'" height="'+this.config.map.size.height+'" style="position:absolute;">')}}},r.prototype._loadOverlays=function(a){var b=this.layerGroups.overlay;if(b){var a=j(a,function(a){for(var c=0,d=b.length;c<d;c+=1)if(null!=a.match(new RegExp("^"+b[c])))return!0;return!1});if(a.length>0){var c=this._urlForLayers(a);this._overlayTarget.ext.html('<img src="'+c+'" width="'+this.config.map.size.width+'" height="'+this.config.map.size.height+'" style="position:absolute;">')}}},r.prototype._fetchLayerMetadata=function(a){this._isLoadingMetadata=!0;var b=this;n({url:"//cdn.aerisjs.com/layers.json",dataType:"json",success:function(c){var d=[];c.forEach(function(a){var b=a.category;b.match(/^base/)?b="base":b.match(/overlay/)&&(b="overlay"),void 0==d[b]&&(d[b]=[]),d[b].push(a.id)}),b.layerGroups=d,b._isLoadingMetadata=!1,b._metadataCallbacks&&b._metadataCallbacks.length>0&&b._metadataCallbacks.forEach(function(a){a()}),b._metadataCallbacks=null,a&&a()},error:function(a){console.log("failed!")}})},r.prototype._urlForLayers=function(a,b){var c=this.config,e=null!=c.loc.match(/^([0-9\.-]+,){3}[0-9\.-]+$/);return i(d.url,{server:c.server,client_id:c.keys.id,client_secret:c.keys.secret,layers:a.join(","),zoom:c.map.zoom,size:c.map.size.width+"x"+c.map.size.height,loc:c.loc,bounds:c.bounds,region:e?c.loc:c.loc+","+c.map.zoom,format:c.map.format,time:b||0})},r.prototype._reset=function(){this._images={},this._contentTarget.ext.empty()},a.AerisMaps.Visualizer=r,a.AerisMaps.Animation=r;for(var v,w="aerismaps-visualizer.css",x=q.select("link"),y=!0,z=new RegExp(w),A=0,B=x.length;A<B;A++)if(v=x[A],z.test(v.href)){y=!1;break}y&&q.select("head").ext.append('<link href="//cdn.aerisapi.com/css/'+w+'" rel="stylesheet" type="text/css"/>')}(window,document);