diff --git a/dist/leaflet.timedimension.control.css b/dist/leaflet.timedimension.control.css index e3f4700..9ad8977 100644 --- a/dist/leaflet.timedimension.control.css +++ b/dist/leaflet.timedimension.control.css @@ -1,14 +1,14 @@ /* - * Leaflet TimeDimension v1.1.1 - 2019-11-05 + * Leaflet TimeDimension v1.1.1 - 2020-11-12 * - * Copyright 2019 Biel Frontera (ICTS SOCIB) + * Copyright 2020 Biel Frontera (ICTS SOCIB) * datacenter@socib.es - * http://www.socib.es/ + * https://www.socib.es/ * * Licensed under the MIT license. * * Demos: - * http://apps.socib.es/Leaflet.TimeDimension/ + * https://apps.socib.es/Leaflet.TimeDimension/ * * Source: * git://github.com/socib/Leaflet.TimeDimension.git diff --git a/dist/leaflet.timedimension.min.js b/dist/leaflet.timedimension.min.js index 12cad61..4333fa6 100644 --- a/dist/leaflet.timedimension.min.js +++ b/dist/leaflet.timedimension.min.js @@ -1,18 +1,18 @@ /* - * Leaflet TimeDimension v1.1.1 - 2019-11-05 + * Leaflet TimeDimension v1.1.1 - 2020-11-12 * - * Copyright 2019 Biel Frontera (ICTS SOCIB) + * Copyright 2020 Biel Frontera (ICTS SOCIB) * datacenter@socib.es - * http://www.socib.es/ + * https://www.socib.es/ * * Licensed under the MIT license. * * Demos: - * http://apps.socib.es/Leaflet.TimeDimension/ + * https://apps.socib.es/Leaflet.TimeDimension/ * * Source: * git://github.com/socib/Leaflet.TimeDimension.git * */ -!function(i,e){if("function"==typeof define&&define.amd)define(["leaflet","iso8601-js-period"],i);else if("object"==typeof exports)module.exports=i(require("leaflet"),require("iso8601-js-period"));else if(void 0!==e&&e.L&&"undefined"!=typeof L){var t=nezasa.iso8601;e.L.TimeDimension=i(L,t)}}(function(i,e){if(void 0===t)var t={iso8601:e};return i.TimeDimension=(i.Layer||i.Class).extend({includes:i.Evented||i.Mixin.Events,initialize:function(e){i.setOptions(this,e),this._availableTimes=this._generateAvailableTimes(),this._currentTimeIndex=-1,this._loadingTimeIndex=-1,this._loadingTimeout=this.options.loadingTimeout||3e3,this._syncedLayers=[],this._availableTimes.length>0&&this.setCurrentTime(this.options.currentTime||this._getDefaultCurrentTime()),this.options.lowerLimitTime&&this.setLowerLimit(this.options.lowerLimitTime),this.options.upperLimitTime&&this.setUpperLimit(this.options.upperLimitTime)},getAvailableTimes:function(){return this._availableTimes},getCurrentTimeIndex:function(){return-1===this._currentTimeIndex?this._availableTimes.length-1:this._currentTimeIndex},getCurrentTime:function(){var i=-1;return(i=-1!==this._loadingTimeIndex?this._loadingTimeIndex:this.getCurrentTimeIndex())>=0?this._availableTimes[i]:null},isLoading:function(){return-1!==this._loadingTimeIndex},setCurrentTimeIndex:function(i){var e=this._upperLimit||this._availableTimes.length-1,t=this._lowerLimit||0;if(!((i=Math.min(Math.max(t,i),e))<0)){this._loadingTimeIndex=i;var s=this._availableTimes[i];this._checkSyncedLayersReady(this._availableTimes[this._loadingTimeIndex])?this._newTimeIndexLoaded():(this.fire("timeloading",{time:s}),setTimeout(function(i){i==this._loadingTimeIndex&&this._newTimeIndexLoaded()}.bind(this,i),this._loadingTimeout))}},_newTimeIndexLoaded:function(){if(-1!==this._loadingTimeIndex){var i=this._availableTimes[this._loadingTimeIndex];this._currentTimeIndex=this._loadingTimeIndex,this.fire("timeload",{time:i}),this._loadingTimeIndex=-1}},_checkSyncedLayersReady:function(i){for(var e=0,t=this._syncedLayers.length;e-1&&(t=this._loadingTimeIndex),(t+=i)>s&&(t=e?n:s),t-1&&(s=this._loadingTimeIndex);for(var a=0,o=this._syncedLayers.length;a0;){if((s+=i)>h){if(!t)break;s=l}if(s-1&&(s=this._loadingTimeIndex);for(var n=e,a=0,o=this._upperLimit||this._availableTimes.length-1,r=this._lowerLimit||0;n>0;){if((s+=i)>o){if(!t){n=0,a=e;break}s=r}if(s0&&e--,e},setAvailableTimes:function(e,t){var s=this.getCurrentTime(),n=this.getLowerLimit(),a=this.getUpperLimit();if("extremes"==t){var o=this.options.period||"P1D";this._availableTimes=i.TimeDimension.Util.explodeTimeRange(new Date(e[0]),new Date(e[e.length-1]),o)}else{var r=i.TimeDimension.Util.parseTimesExpression(e);if(0===this._availableTimes.length)this._availableTimes=r;else if("intersect"==t)this._availableTimes=i.TimeDimension.Util.intersect_arrays(r,this._availableTimes);else if("union"==t)this._availableTimes=i.TimeDimension.Util.union_arrays(r,this._availableTimes);else{if("replace"!=t)throw"Merge available times mode not implemented: "+t;this._availableTimes=r}}n&&this.setLowerLimit(n),a&&this.setUpperLimit(a),this.setCurrentTime(s),this.fire("availabletimeschanged",{availableTimes:this._availableTimes,currentTime:s})},getLowerLimit:function(){return this._availableTimes[this.getLowerLimitIndex()]},getUpperLimit:function(){return this._availableTimes[this.getUpperLimitIndex()]},setLowerLimit:function(i){var e=this._seekNearestTimeIndex(i);this.setLowerLimitIndex(e)},setUpperLimit:function(i){var e=this._seekNearestTimeIndex(i);this.setUpperLimitIndex(e)},setLowerLimitIndex:function(i){this._lowerLimit=Math.min(Math.max(i||0,0),this._upperLimit||this._availableTimes.length-1),this.fire("limitschanged",{lowerLimit:this._lowerLimit,upperLimit:this._upperLimit})},setUpperLimitIndex:function(i){this._upperLimit=Math.max(Math.min(i,this._availableTimes.length-1),this._lowerLimit||0),this.fire("limitschanged",{lowerLimit:this._lowerLimit,upperLimit:this._upperLimit})},getLowerLimitIndex:function(){return this._lowerLimit},getUpperLimitIndex:function(){return this._upperLimit}}),i.Map.addInitHook(function(){this.options.timeDimension&&(this.timeDimension=i.timeDimension(this.options.timeDimensionOptions||{}))}),i.timeDimension=function(e){return new i.TimeDimension(e)},i.TimeDimension.Util={getTimeDuration:function(i){if(void 0===t)throw"iso8601-js-period library is required for Leatlet.TimeDimension: https://github.com/nezasa/iso8601-js-period";return t.iso8601.Period.parse(i,!0)},addTimeDuration:function(i,e,t){void 0===t&&(t=!0),("string"==typeof e||e instanceof String)&&(e=this.getTimeDuration(e));var s=e.length,n=t?"getUTC":"get",a=t?"setUTC":"set";s>0&&0!=e[0]&&i[a+"FullYear"](i[n+"FullYear"]()+e[0]),s>1&&0!=e[1]&&i[a+"Month"](i[n+"Month"]()+e[1]),s>2&&0!=e[2]&&i[a+"Date"](i[n+"Date"]()+7*e[2]),s>3&&0!=e[3]&&i[a+"Date"](i[n+"Date"]()+e[3]),s>4&&0!=e[4]&&i[a+"Hours"](i[n+"Hours"]()+e[4]),s>5&&0!=e[5]&&i[a+"Minutes"](i[n+"Minutes"]()+e[5]),s>6&&0!=e[6]&&i[a+"Seconds"](i[n+"Seconds"]()+e[6])},subtractTimeDuration:function(i,e,t){("string"==typeof e||e instanceof String)&&(e=this.getTimeDuration(e));for(var s=[],n=0,a=e.length;n2&&t[2].length?t[2]:"P1D";return void 0!==e&&null!==e&&(a=e),this.explodeTimeRange(s,n,a)},explodeTimeRange:function(i,e,t,s){var n=this.getTimeDuration(t),a=[],o=new Date(i.getTime()),r=null,h=null,l=null,m=null;if(void 0!==s){var u=s.split("/");r=u[0].split(":")[0],h=u[0].split(":")[1],l=u[1].split(":")[0],m=u[1].split(":")[1]}for(;o=r&&o.getUTCHours()<=l)&&(o.getUTCHours()!=r||o.getUTCMinutes()>=h)&&(o.getUTCHours()!=l||o.getUTCMinutes()<=m)&&a.push(o.getTime()),this.addTimeDuration(o,n);return o>=e&&a.push(e.getTime()),a},parseTimeInterval:function(i){var e=i.split("/");if(2!=e.length)throw"Incorrect ISO9601 TimeInterval: "+i;var t=Date.parse(e[0]),s=null,n=null;return isNaN(t)?(n=this.getTimeDuration(e[0]),s=Date.parse(e[1]),t=new Date(s),this.subtractTimeDuration(t,n,!0),s=new Date(s)):(s=Date.parse(e[1]),isNaN(s)?(n=this.getTimeDuration(e[1]),s=new Date(t),this.addTimeDuration(s,n,!0)):s=new Date(s),t=new Date(t)),[t,s]},parseTimesExpression:function(i,e){var t=[];if(!i)return t;if("string"==typeof i||i instanceof String)for(var s,n,a=i.split(","),o=0,r=a.length;o0&&s.length>0;)t[0]s[0]?s.shift():(n.push(t.shift()),s.shift());return n},union_arrays:function(i,e){for(var t=i.slice(0),s=e.slice(0),n=[];t.length>0&&s.length>0;)t[0]s[0]?n.push(s.shift()):(n.push(t.shift()),s.shift());return t.length>0?n=n.concat(t):s.length>0&&(n=n.concat(s)),n},sort_and_deduplicate:function(i){for(var e=[],t=null,s=0,n=(i=i.slice(0).sort()).length;s-1&&(o=n-e)>0&&(a=t.splice(0,o),this._removeLayers(a)),i>-1){n=t.indexOf(s);var o=t.length-n-i-1;o>0&&(a=t.splice(n+i+1,o),this._removeLayers(a))}},_showLayer:function(i,e){this._currentLayer&&this._currentLayer!==i&&this._currentLayer.hide(),i.show(),this._currentLayer&&this._currentLayer===i||(this._currentLayer=i,this._currentTime=e,this._evictCachedTimes(this._timeCacheForward,this._timeCacheBackward))},_getLayerForTime:function(i){if(0==i||i==this._defaultTime||null==i)return this._baseLayer;if(this._layers.hasOwnProperty(i))return this._layers[i];var e=this._getNearestTime(i);if(this._layers.hasOwnProperty(e))return this._layers[e];var t=this._createLayerForTime(e);return this._layers[i]=t,t.on("load",function(i,e){i.setLoaded(!0),this._layers[e]||(this._layers[e]=i),this._timeDimension&&e==this._timeDimension.getCurrentTime()&&!this._timeDimension.isLoading()&&this._showLayer(i,e),this.fire("timeload",{time:e})}.bind(this,t,i)),t.onAdd=function(i){Object.getPrototypeOf(this).onAdd.call(this,i),this.hide()}.bind(t),t},_createLayerForTime:function(i){var e=this._baseLayer.options;return e.time=new Date(i).toISOString(),new this._baseLayer.constructor(this._baseLayer.getURL(),e)},_getLoadedTimes:function(){var i=[];for(var e in this._layers)this._layers.hasOwnProperty(e)&&i.push(e);return i.sort(function(i,e){return i-e})},_removeLayers:function(i){for(var e=0,t=i.length;ethis._timeCacheForward&&(this._timeCacheForward=i)},_requestTimeDimensionFromCapabilities:function(){if(!this._capabilitiesRequested){this._capabilitiesRequested=!0;var i=this._getCapabilitiesUrl();this._proxy&&(i=this._proxy+"?url="+encodeURIComponent(i));var e=new XMLHttpRequest;e.addEventListener("load",function(i){var e=i.currentTarget.responseXML;null!==e&&(this._defaultTime=Date.parse(this._getDefaultTimeFromCapabilities(e)),this._setDefaultTime=this._setDefaultTime||this._timeDimension&&0==this._timeDimension.getAvailableTimes().length,this.setAvailableTimes(this._parseTimeDimensionFromCapabilities(e)),this._setDefaultTime&&this._timeDimension&&this._timeDimension.setCurrentTime(this._defaultTime))}.bind(this)),e.overrideMimeType("application/xml"),e.open("GET",i),e.send()}},_getCapabilitiesUrl:function(){var e=this._baseLayer.getURL();this._getCapabilitiesAlternateUrl&&(e=this._getCapabilitiesAlternateUrl);var t=i.extend({},this._getCapabilitiesParams,{request:"GetCapabilities",service:"WMS",version:this._wmsVersion});return e+=i.Util.getParamString(t,e,t.uppercase)},_parseTimeDimensionFromCapabilities:function(i){var e=i.querySelectorAll('Layer[queryable="1"]'),t=this._baseLayer.wmsParams.layers,s=null,n=null;return e.forEach(function(i){i.querySelector("Name").innerHTML===t&&(s=i)}),s&&((n=this._getTimesFromLayerCapabilities(s))||(n=this._getTimesFromLayerCapabilities(s.parentNode))),n},_getTimesFromLayerCapabilities:function(i){for(var e=null,t=i.children,s=0,n=t.length;s0&&this._timeDimension.setCurrentTime(this._defaultTime))},_getNearestTime:function(i){if(this._layers.hasOwnProperty(i))return i;if(0==this._availableTimes.length)return i;for(var e=0,t=this._availableTimes.length;e0&&e--,this._availableTimes[e],this._availableTimes[e]}}),i.NonTiledLayer||(i.NonTiledLayer=(i.Layer||i.Class).extend({})),i.NonTiledLayer.include({_visible:!0,_loaded:!1,_originalUpdate:i.NonTiledLayer.prototype._update,_originalOnRemove:i.NonTiledLayer.prototype.onRemove,_update:function(){!this._visible&&this._loaded||this._originalUpdate()},onRemove:function(i){this._loaded=!1,this._originalOnRemove(i)},setLoaded:function(i){this._loaded=i},isLoaded:function(){return this._loaded},hide:function(){this._visible=!1,this._div.style.display="none"},show:function(){this._visible=!0,this._div.style.display="block"},getURL:function(){return this._wmsUrl}}),i.TileLayer.include({_visible:!0,_loaded:!1,_originalUpdate:i.TileLayer.prototype._update,_update:function(){!this._visible&&this._loaded||this._originalUpdate()},setLoaded:function(i){this._loaded=i},isLoaded:function(){return this._loaded},hide:function(){this._visible=!1,this._container&&(this._container.style.display="none")},show:function(){this._visible=!0,this._container&&(this._container.style.display="block")},getURL:function(){return this._url}}),i.timeDimension.layer.wms=function(e,t){return new i.TimeDimension.Layer.WMS(e,t)},i.TimeDimension.Layer.GeoJson=i.TimeDimension.Layer.extend({initialize:function(e,t){i.TimeDimension.Layer.prototype.initialize.call(this,e,t),this._updateTimeDimension=this.options.updateTimeDimension||!1,this._updateTimeDimensionMode=this.options.updateTimeDimensionMode||"extremes",this._duration=this.options.duration||null,this._addlastPoint=this.options.addlastPoint||!1,this._waitForReady=this.options.waitForReady||!1,this._defaultTime=0,this._availableTimes=[],this._loaded=!1,0==this._baseLayer.getLayers().length?this._waitForReady?this._baseLayer.on("ready",this._onReadyBaseLayer,this):this._loaded=!0:(this._loaded=!0,this._setAvailableTimes()),this._baseLayer.on("layeradd",function(){this._loaded&&this._setAvailableTimes()}.bind(this))},onAdd:function(e){i.TimeDimension.Layer.prototype.onAdd.call(this,e),this._loaded&&this._setAvailableTimes()},eachLayer:function(e,t){return this._currentLayer&&e.call(t,this._currentLayer),i.TimeDimension.Layer.prototype.eachLayer.call(this,e,t)},isReady:function(i){return this._loaded},_update:function(){if(this._map&&this._loaded){this._timeDimension.getCurrentTime();var e=this._timeDimension.getCurrentTime(),t=0;if(this._duration){var s=new Date(e);i.TimeDimension.Util.subtractTimeDuration(s,this._duration,!0),t=s.getTime()}for(var n=i.geoJson(null,this._baseLayer.options),a=this._baseLayer.getLayers(),o=0,r=a.length;o0)){var l=h.properties;l.last=!0,n.addData({type:"Feature",properties:l,geometry:{type:"Point",coordinates:h.geometry.coordinates[h.geometry.coordinates.length-1]}})}}this._currentLayer&&this._map.removeLayer(this._currentLayer),n.getLayers().length&&(n.addTo(this._map),this._currentLayer=n)}},_setAvailableTimes:function(){for(var e=[],t=this._baseLayer.getLayers(),s=0,n=t.length;st||s[o-1]e)for(var r=0;re&&(n=r),s[r]>t){a=r;break}null===n&&(n=0),null===a&&(a=o);var h=[];return h=i.geometry.coordinates[0].length?i.geometry.coordinates.slice(n,a):i.geometry.coordinates,{type:"Feature",properties:i.properties,geometry:{type:i.geometry.type,coordinates:h}}},_onReadyBaseLayer:function(){this._loaded=!0,this._setAvailableTimes(),this._update()}}),i.timeDimension.layer.geoJson=function(e,t){return new i.TimeDimension.Layer.GeoJson(e,t)},i.TimeDimension.Player=(i.Layer||i.Class).extend({includes:i.Evented||i.Mixin.Events,initialize:function(e,t){i.setOptions(this,e),this._timeDimension=t,this._paused=!1,this._buffer=this.options.buffer||5,this._minBufferReady=this.options.minBufferReady||1,this._waitingForBuffer=!1,this._loop=this.options.loop||!1,this._steps=1,this._timeDimension.on("timeload",function(i){this.release(),this._waitingForBuffer=!1}.bind(this)),this.setTransitionTime(this.options.transitionTime||1e3),this._timeDimension.on("limitschanged availabletimeschanged timeload",function(i){this._timeDimension.prepareNextTimes(this._steps,this._minBufferReady,this._loop)}.bind(this))},_tick:function(){var i=this._getMaxIndex(),e=this._timeDimension.getCurrentTimeIndex()>=i&&this._steps>0,t=0==this._timeDimension.getCurrentTimeIndex()&&this._steps<0;if((e||t)&&!this._loop)return this.pause(),this.stop(),void this.fire("animationfinished");if(!this._paused){var s=0,n=this._bufferSize;if(this._minBufferReady>0)if(s=this._timeDimension.getNumberNextTimesReady(this._steps,n,this._loop),this._waitingForBuffer){if(s0&&this._timeDimension.prepareNextTimes(this._steps,n,this._loop)}},_getMaxIndex:function(){return Math.min(this._timeDimension.getAvailableTimes().length-1,this._timeDimension.getUpperLimitIndex()||1/0)},start:function(e){this._intervalID||(this._steps=e||1,this._waitingForBuffer=!1,this.options.startOver&&this._timeDimension.getCurrentTimeIndex()===this._getMaxIndex()&&this._timeDimension.setCurrentTimeIndex(this._timeDimension.getLowerLimitIndex()||0),this.release(),this._intervalID=window.setInterval(i.bind(this._tick,this),this._transitionTime),this._tick(),this.fire("play"),this.fire("running"))},stop:function(){this._intervalID&&(clearInterval(this._intervalID),this._intervalID=null,this._waitingForBuffer=!1,this.fire("stop"))},pause:function(){this._paused=!0},release:function(){this._paused=!1},getTransitionTime:function(){return this._transitionTime},isPlaying:function(){return!!this._intervalID},isWaiting:function(){return this._waitingForBuffer},isLooped:function(){return this._loop},setLooped:function(i){this._loop=i,this.fire("loopchange",{loop:i})},setTransitionTime:function(i){this._transitionTime=i,"function"==typeof this._buffer?this._bufferSize=this._buffer.call(this,this._transitionTime,this._minBufferReady,this._loop):this._bufferSize=this._buffer,this._intervalID&&(this.stop(),this.start(this._steps)),this.fire("speedchange",{transitionTime:i,buffer:this._bufferSize})},getSteps:function(){return this._steps}}),i.UI=i.ui=i.UI||{},i.UI.Knob=i.Draggable.extend({options:{className:"knob",step:1,rangeMin:0,rangeMax:10},initialize:function(e,t){i.setOptions(this,t),this._element=i.DomUtil.create("div",this.options.className||"knob",e),i.Draggable.prototype.initialize.call(this,this._element,this._element),this._container=e,this.on("predrag",function(){this._newPos.y=0,this._newPos.x=this._adjustX(this._newPos.x)},this),this.on("dragstart",function(){i.DomUtil.addClass(e,"dragging")}),this.on("dragend",function(){i.DomUtil.removeClass(e,"dragging")}),i.DomEvent.on(this._element,"dblclick",function(i){this.fire("dblclick",i)},this),i.DomEvent.disableClickPropagation(this._element),this.enable()},_getProjectionCoef:function(){return(this.options.rangeMax-this.options.rangeMin)/(this._container.offsetWidth||this._container.style.width)},_update:function(){this.setPosition(i.DomUtil.getPosition(this._element).x)},_adjustX:function(i){var e=this._toValue(i)||this.getMinValue();return this._toX(this._adjustValue(e))},_adjustValue:function(i){return i=Math.max(this.getMinValue(),Math.min(this.getMaxValue(),i)),i-=this.options.rangeMin,i=Math.round(i/this.options.step)*this.options.step,i+=this.options.rangeMin,i=Math.round(100*i)/100},_toX:function(i){return(i-this.options.rangeMin)/this._getProjectionCoef()},_toValue:function(i){return i*this._getProjectionCoef()+this.options.rangeMin},getMinValue:function(){return this.options.minValue||this.options.rangeMin},getMaxValue:function(){return this.options.maxValue||this.options.rangeMax},setStep:function(i){this.options.step=i,this._update()},setPosition:function(e){i.DomUtil.setPosition(this._element,i.point(this._adjustX(e),0)),this.fire("positionchanged")},getPosition:function(){return i.DomUtil.getPosition(this._element).x},setValue:function(i){this.setPosition(this._toX(i))},getValue:function(){return this._adjustValue(this._toValue(this.getPosition()))}}),i.Control.TimeDimension=i.Control.extend({options:{styleNS:"leaflet-control-timecontrol",position:"bottomleft",title:"Time Control",backwardButton:!0,forwardButton:!0,playButton:!0,playReverseButton:!1,loopButton:!1,displayDate:!0,timeSlider:!0,timeSliderDragUpdate:!1,limitSliders:!1,limitMinimumRange:5,speedSlider:!0,minSpeed:.1,maxSpeed:10,speedStep:.1,timeSteps:1,autoPlay:!1,playerOptions:{transitionTime:1e3},timeZones:["UTC","Local"]},initialize:function(e){i.setOptions(e),i.Control.prototype.initialize.call(this,e),this._timeZoneIndex=0,this._timeDimension=this.options.timeDimension||null},onAdd:function(e){var t;return this._map=e,!this._timeDimension&&e.timeDimension&&(this._timeDimension=e.timeDimension),this._initPlayer(),t=i.DomUtil.create("div","leaflet-bar leaflet-bar-horizontal leaflet-bar-timecontrol"),this.options.backwardButton&&(this._buttonBackward=this._createButton("Backward",t)),this.options.playReverseButton&&(this._buttonPlayReversePause=this._createButton("Play Reverse",t)),this.options.playButton&&(this._buttonPlayPause=this._createButton("Play",t)),this.options.forwardButton&&(this._buttonForward=this._createButton("Forward",t)),this.options.loopButton&&(this._buttonLoop=this._createButton("Loop",t)),this.options.displayDate&&(this._displayDate=this._createButton("Date",t)),this.options.timeSlider&&(this._sliderTime=this._createSliderTime(this.options.styleNS+" timecontrol-slider timecontrol-dateslider",t)),this.options.speedSlider&&(this._sliderSpeed=this._createSliderSpeed(this.options.styleNS+" timecontrol-slider timecontrol-speed",t)),this._steps=this.options.timeSteps||1,this._timeDimension.on("timeload",this._update,this),this._timeDimension.on("timeload",this._onPlayerStateChange,this),this._timeDimension.on("timeloading",this._onTimeLoading,this),this._timeDimension.on("limitschanged availabletimeschanged",this._onTimeLimitsChanged,this),i.DomEvent.disableClickPropagation(t),t},addTo:function(){return i.Control.prototype.addTo.apply(this,arguments),this._onPlayerStateChange(),this._onTimeLimitsChanged(),this._update(),this},onRemove:function(){this._player.off("play stop running loopchange speedchange",this._onPlayerStateChange,this),this._player.off("waiting",this._onPlayerWaiting,this),this._timeDimension.off("timeload",this._update,this),this._timeDimension.off("timeload",this._onPlayerStateChange,this),this._timeDimension.off("timeloading",this._onTimeLoading,this),this._timeDimension.off("limitschanged availabletimeschanged",this._onTimeLimitsChanged,this)},_initPlayer:function(){this._player||(this.options.player?this._player=this.options.player:this._player=new i.TimeDimension.Player(this.options.playerOptions,this._timeDimension)),this.options.autoPlay&&this._player.start(this._steps),this._player.on("play stop running loopchange speedchange",this._onPlayerStateChange,this),this._player.on("waiting",this._onPlayerWaiting,this),this._onPlayerStateChange()},_onTimeLoading:function(e){e.time==this._timeDimension.getCurrentTime()&&this._displayDate&&i.DomUtil.addClass(this._displayDate,"loading")},_onTimeLimitsChanged:function(){var i=this._timeDimension.getLowerLimitIndex(),e=this._timeDimension.getUpperLimitIndex(),t=this._timeDimension.getAvailableTimes().length-1;this._limitKnobs&&(this._limitKnobs[0].options.rangeMax=t,this._limitKnobs[1].options.rangeMax=t,this._limitKnobs[0].setValue(i||0),this._limitKnobs[1].setValue(e||t)),this._sliderTime&&(this._sliderTime.options.rangeMax=t,this._sliderTime._update())},_onPlayerWaiting:function(e){this._buttonPlayPause&&this._player.getSteps()>0&&(i.DomUtil.addClass(this._buttonPlayPause,"loading"),this._buttonPlayPause.innerHTML=this._getDisplayLoadingText(e.available,e.buffer)),this._buttonPlayReversePause&&this._player.getSteps()<0&&(i.DomUtil.addClass(this._buttonPlayReversePause,"loading"),this._buttonPlayReversePause.innerHTML=this._getDisplayLoadingText(e.available,e.buffer))},_onPlayerStateChange:function(){if(this._buttonPlayPause&&(this._player.isPlaying()&&this._player.getSteps()>0?(i.DomUtil.addClass(this._buttonPlayPause,"pause"),i.DomUtil.removeClass(this._buttonPlayPause,"play")):(i.DomUtil.removeClass(this._buttonPlayPause,"pause"),i.DomUtil.addClass(this._buttonPlayPause,"play")),this._player.isWaiting()&&this._player.getSteps()>0?i.DomUtil.addClass(this._buttonPlayPause,"loading"):(this._buttonPlayPause.innerHTML="",i.DomUtil.removeClass(this._buttonPlayPause,"loading"))),this._buttonPlayReversePause&&(this._player.isPlaying()&&this._player.getSteps()<0?i.DomUtil.addClass(this._buttonPlayReversePause,"pause"):i.DomUtil.removeClass(this._buttonPlayReversePause,"pause"),this._player.isWaiting()&&this._player.getSteps()<0?i.DomUtil.addClass(this._buttonPlayReversePause,"loading"):(this._buttonPlayReversePause.innerHTML="",i.DomUtil.removeClass(this._buttonPlayReversePause,"loading"))),this._buttonLoop&&(this._player.isLooped()?i.DomUtil.addClass(this._buttonLoop,"looped"):i.DomUtil.removeClass(this._buttonLoop,"looped")),this._sliderSpeed&&!this._draggingSpeed){var e=this._player.getTransitionTime()||1e3;e=Math.round(1e4/e)/10,this._sliderSpeed.setValue(e)}},_update:function(){if(this._timeDimension)if(this._timeDimension.getCurrentTimeIndex()>=0){var e=new Date(this._timeDimension.getCurrentTime());this._displayDate&&(i.DomUtil.removeClass(this._displayDate,"loading"),this._displayDate.innerHTML=this._getDisplayDateFormat(e)),this._sliderTime&&!this._slidingTimeSlider&&this._sliderTime.setValue(this._timeDimension.getCurrentTimeIndex())}else this._displayDate&&(this._displayDate.innerHTML=this._getDisplayNoTimeError())},_createButton:function(e,t){var s=i.DomUtil.create("a",this.options.styleNS+" timecontrol-"+e.toLowerCase(),t);return s.href="#",s.title=e,i.DomEvent.addListener(s,"click",i.DomEvent.stopPropagation).addListener(s,"click",i.DomEvent.preventDefault).addListener(s,"click",this["_button"+e.replace(/ /i,"")+"Clicked"],this),s},_createSliderTime:function(e,t){var s,n,a,o,r;return s=i.DomUtil.create("div",e,t),n=i.DomUtil.create("div","slider",s),a=this._timeDimension.getAvailableTimes().length-1,this.options.limitSliders&&(r=this._limitKnobs=this._createLimitKnobs(n)),(o=new i.UI.Knob(n,{className:"knob main",rangeMin:0,rangeMax:a})).on("dragend",function(i){var e=i.target.getValue();this._sliderTimeValueChanged(e),this._slidingTimeSlider=!1},this),o.on("drag",function(i){this._slidingTimeSlider=!0;var e=this._timeDimension.getAvailableTimes()[i.target.getValue()];if(e){var t=new Date(e);this._displayDate&&(this._displayDate.innerHTML=this._getDisplayDateFormat(t)),this.options.timeSliderDragUpdate&&this._sliderTimeValueChanged(i.target.getValue())}},this),o.on("predrag",function(){var i,e;r&&(i=r[0].getPosition(),e=r[1].getPosition(),this._newPos.xe&&(this._newPos.x=e))},o),i.DomEvent.on(n,"click",function(e){if(!i.DomUtil.hasClass(e.target,"knob")){var t=e.touches&&1===e.touches.length?e.touches[0]:e,s=i.DomEvent.getMousePosition(t,n).x;r?r[0].getPosition()<=s&&s<=r[1].getPosition()&&(o.setPosition(s),this._sliderTimeValueChanged(o.getValue())):(o.setPosition(s),this._sliderTimeValueChanged(o.getValue()))}},this),o.setPosition(0),o},_createLimitKnobs:function(e){i.DomUtil.addClass(e,"has-limits");var t=this._timeDimension.getAvailableTimes().length-1,s=i.DomUtil.create("div","range",e),n=new i.UI.Knob(e,{className:"knob lower",rangeMin:0,rangeMax:t}),a=new i.UI.Knob(e,{className:"knob upper",rangeMin:0,rangeMax:t});return i.DomUtil.setPosition(s,0),n.setPosition(0),a.setPosition(t),n.on("dragend",function(i){var e=i.target.getValue();this._sliderLimitsValueChanged(e,a.getValue())},this),a.on("dragend",function(i){var e=i.target.getValue();this._sliderLimitsValueChanged(n.getValue(),e)},this),n.on("drag positionchanged",function(){i.DomUtil.setPosition(s,i.point(n.getPosition(),0)),s.style.width=a.getPosition()-n.getPosition()+"px"},this),a.on("drag positionchanged",function(){s.style.width=a.getPosition()-n.getPosition()+"px"},this),a.on("predrag",function(){var i=n._toX(n.getValue()+this.options.limitMinimumRange);a._newPos.x<=i&&(a._newPos.x=i)},this),n.on("predrag",function(){var i=a._toX(a.getValue()-this.options.limitMinimumRange);n._newPos.x>=i&&(n._newPos.x=i)},this),n.on("dblclick",function(){this._timeDimension.setLowerLimitIndex(0)},this),a.on("dblclick",function(){this._timeDimension.setUpperLimitIndex(this._timeDimension.getAvailableTimes().length-1)},this),[n,a]},_createSliderSpeed:function(e,t){var s=i.DomUtil.create("div",e,t),n=i.DomUtil.create("span","speed",s),a=i.DomUtil.create("div","slider",s),o=Math.round(1e4/(this._player.getTransitionTime()||1e3))/10;n.innerHTML=this._getDisplaySpeed(o);var r=new i.UI.Knob(a,{step:this.options.speedStep,rangeMin:this.options.minSpeed,rangeMax:this.options.maxSpeed});return r.on("dragend",function(i){var e=i.target.getValue();this._draggingSpeed=!1,n.innerHTML=this._getDisplaySpeed(e),this._sliderSpeedValueChanged(e)},this),r.on("drag",function(i){this._draggingSpeed=!0,n.innerHTML=this._getDisplaySpeed(i.target.getValue())},this),r.on("positionchanged",function(i){n.innerHTML=this._getDisplaySpeed(i.target.getValue())},this),i.DomEvent.on(a,"click",function(e){if(e.target!==r._element){var t=e.touches&&1===e.touches.length?e.touches[0]:e,s=i.DomEvent.getMousePosition(t,a).x;r.setPosition(s),n.innerHTML=this._getDisplaySpeed(r.getValue()),this._sliderSpeedValueChanged(r.getValue())}},this),r},_buttonBackwardClicked:function(){this._timeDimension.previousTime(this._steps)},_buttonForwardClicked:function(){this._timeDimension.nextTime(this._steps)},_buttonLoopClicked:function(){this._player.setLooped(!this._player.isLooped())},_buttonPlayClicked:function(){this._player.isPlaying()?this._player.stop():this._player.start(this._steps)},_buttonPlayReverseClicked:function(){this._player.isPlaying()?this._player.stop():this._player.start(-1*this._steps)},_buttonDateClicked:function(){this._switchTimeZone()},_sliderTimeValueChanged:function(i){this._timeDimension.setCurrentTimeIndex(i)},_sliderLimitsValueChanged:function(i,e){this._timeDimension.setLowerLimitIndex(i),this._timeDimension.setUpperLimitIndex(e)},_sliderSpeedValueChanged:function(i){this._player.setTransitionTime(1e3/i)},_getCurrentTimeZone:function(){return this.options.timeZones[this._timeZoneIndex]},_switchTimeZone:function(){"utc"==this._getCurrentTimeZone().toLowerCase()&&i.DomUtil.removeClass(this._displayDate,"utc"),this._timeZoneIndex=(this._timeZoneIndex+1)%this.options.timeZones.length;var e=this._getCurrentTimeZone();"utc"==e.toLowerCase()?(i.DomUtil.addClass(this._displayDate,"utc"),this._displayDate.title="UTC Time"):"local"==e.toLowerCase()?this._displayDate.title="Local Time":this._displayDate.title=e,this._update()},_getDisplayDateFormat:function(i){var e=this._getCurrentTimeZone();return"utc"==e.toLowerCase()?i.toISOString():"local"==e.toLowerCase()?i.toLocaleString():i.toLocaleString([],{timeZone:e,timeZoneName:"short"})},_getDisplaySpeed:function(i){return i+"fps"},_getDisplayLoadingText:function(i,e){return""+Math.floor(i/e*100)+"%"},_getDisplayNoTimeError:function(){return"Time not available"}}),i.Map.addInitHook(function(){this.options.timeDimensionControl&&(this.timeDimensionControl=i.control.timeDimension(this.options.timeDimensionControlOptions||{}),this.addControl(this.timeDimensionControl))}),i.control.timeDimension=function(e){return new i.Control.TimeDimension(e)},i.TimeDimension},window); \ No newline at end of file +!function(i,e){if("function"==typeof define&&define.amd)define(["leaflet","iso8601-js-period"],i);else if("object"==typeof exports)module.exports=i(require("leaflet"),require("iso8601-js-period"));else if(void 0!==e&&e.L&&"undefined"!=typeof L){var t=nezasa.iso8601;e.L.TimeDimension=i(L,t)}}(function(i,e){if(void 0===t)var t={iso8601:e};return i.TimeDimension=(i.Layer||i.Class).extend({includes:i.Evented||i.Mixin.Events,initialize:function(e){i.setOptions(this,e),this._availableTimes=this._generateAvailableTimes(),this._currentTimeIndex=-1,this._loadingTimeIndex=-1,this._loadingTimeout=this.options.loadingTimeout||3e3,this._syncedLayers=[],this._availableTimes.length>0&&this.setCurrentTime(this.options.currentTime||this._getDefaultCurrentTime()),this.options.lowerLimitTime&&this.setLowerLimit(this.options.lowerLimitTime),this.options.upperLimitTime&&this.setUpperLimit(this.options.upperLimitTime)},getAvailableTimes:function(){return this._availableTimes},getCurrentTimeIndex:function(){return-1===this._currentTimeIndex?this._availableTimes.length-1:this._currentTimeIndex},getCurrentTime:function(){var i=-1;return(i=-1!==this._loadingTimeIndex?this._loadingTimeIndex:this.getCurrentTimeIndex())>=0?this._availableTimes[i]:null},isLoading:function(){return-1!==this._loadingTimeIndex},setCurrentTimeIndex:function(i){var e=this._upperLimit||this._availableTimes.length-1,t=this._lowerLimit||0;if(!((i=Math.min(Math.max(t,i),e))<0)){this._loadingTimeIndex=i;var s=this._availableTimes[i];this._checkSyncedLayersReady(this._availableTimes[this._loadingTimeIndex])?this._newTimeIndexLoaded():(this.fire("timeloading",{time:s}),setTimeout(function(i){i==this._loadingTimeIndex&&this._newTimeIndexLoaded()}.bind(this,i),this._loadingTimeout))}},_newTimeIndexLoaded:function(){if(-1!==this._loadingTimeIndex){var i=this._availableTimes[this._loadingTimeIndex];this._currentTimeIndex=this._loadingTimeIndex,this.fire("timeload",{time:i}),this._loadingTimeIndex=-1}},_checkSyncedLayersReady:function(i){for(var e=0,t=this._syncedLayers.length;e-1&&(t=this._loadingTimeIndex),(t+=i)>s&&(t=e?n:s),t-1&&(s=this._loadingTimeIndex);for(var a=0,o=this._syncedLayers.length;a0;){if((s+=i)>h){if(!t)break;s=l}if(s-1&&(s=this._loadingTimeIndex);for(var n=e,a=0,o=this._upperLimit||this._availableTimes.length-1,r=this._lowerLimit||0;n>0;){if((s+=i)>o){if(!t){n=0,a=e;break}s=r}if(s0&&e--,e},setAvailableTimes:function(e,t){var s=this.getCurrentTime(),n=this.getLowerLimit(),a=this.getUpperLimit();if("extremes"==t){var o=this.options.period||"P1D";this._availableTimes=i.TimeDimension.Util.explodeTimeRange(new Date(e[0]),new Date(e[e.length-1]),o)}else{var r=i.TimeDimension.Util.parseTimesExpression(e);if(0===this._availableTimes.length)this._availableTimes=r;else if("intersect"==t)this._availableTimes=i.TimeDimension.Util.intersect_arrays(r,this._availableTimes);else if("union"==t)this._availableTimes=i.TimeDimension.Util.union_arrays(r,this._availableTimes);else{if("replace"!=t)throw"Merge available times mode not implemented: "+t;this._availableTimes=r}}n&&this.setLowerLimit(n),a&&this.setUpperLimit(a),this.setCurrentTime(s),this.fire("availabletimeschanged",{availableTimes:this._availableTimes,currentTime:s})},getLowerLimit:function(){return this._availableTimes[this.getLowerLimitIndex()]},getUpperLimit:function(){return this._availableTimes[this.getUpperLimitIndex()]},setLowerLimit:function(i){var e=this._seekNearestTimeIndex(i);this.setLowerLimitIndex(e)},setUpperLimit:function(i){var e=this._seekNearestTimeIndex(i);this.setUpperLimitIndex(e)},setLowerLimitIndex:function(i){this._lowerLimit=Math.min(Math.max(i||0,0),this._upperLimit||this._availableTimes.length-1),this.fire("limitschanged",{lowerLimit:this._lowerLimit,upperLimit:this._upperLimit})},setUpperLimitIndex:function(i){this._upperLimit=Math.max(Math.min(i,this._availableTimes.length-1),this._lowerLimit||0),this.fire("limitschanged",{lowerLimit:this._lowerLimit,upperLimit:this._upperLimit})},getLowerLimitIndex:function(){return this._lowerLimit},getUpperLimitIndex:function(){return this._upperLimit}}),i.Map.addInitHook(function(){this.options.timeDimension&&(this.timeDimension=i.timeDimension(this.options.timeDimensionOptions||{}))}),i.timeDimension=function(e){return new i.TimeDimension(e)},i.TimeDimension.Util={getTimeDuration:function(i){if(void 0===t)throw"iso8601-js-period library is required for Leatlet.TimeDimension: https://github.com/nezasa/iso8601-js-period";return t.iso8601.Period.parse(i,!0)},addTimeDuration:function(i,e,t){void 0===t&&(t=!0),("string"==typeof e||e instanceof String)&&(e=this.getTimeDuration(e));var s=e.length,n=t?"getUTC":"get",a=t?"setUTC":"set";s>0&&0!=e[0]&&i[a+"FullYear"](i[n+"FullYear"]()+e[0]),s>1&&0!=e[1]&&i[a+"Month"](i[n+"Month"]()+e[1]),s>2&&0!=e[2]&&i[a+"Date"](i[n+"Date"]()+7*e[2]),s>3&&0!=e[3]&&i[a+"Date"](i[n+"Date"]()+e[3]),s>4&&0!=e[4]&&i[a+"Hours"](i[n+"Hours"]()+e[4]),s>5&&0!=e[5]&&i[a+"Minutes"](i[n+"Minutes"]()+e[5]),s>6&&0!=e[6]&&i[a+"Seconds"](i[n+"Seconds"]()+e[6])},subtractTimeDuration:function(i,e,t){("string"==typeof e||e instanceof String)&&(e=this.getTimeDuration(e));for(var s=[],n=0,a=e.length;n2&&t[2].length?t[2]:"P1D";return void 0!==e&&null!==e&&(a=e),this.explodeTimeRange(s,n,a)},explodeTimeRange:function(i,e,t,s){var n=this.getTimeDuration(t),a=[],o=new Date(i.getTime()),r=null,h=null,l=null,m=null;if(void 0!==s){var u=s.split("/");r=u[0].split(":")[0],h=u[0].split(":")[1],l=u[1].split(":")[0],m=u[1].split(":")[1]}for(;o=r&&o.getUTCHours()<=l)&&(o.getUTCHours()!=r||o.getUTCMinutes()>=h)&&(o.getUTCHours()!=l||o.getUTCMinutes()<=m)&&a.push(o.getTime()),this.addTimeDuration(o,n);return o>=e&&a.push(e.getTime()),a},parseTimeInterval:function(i){var e=i.split("/");if(2!=e.length)throw"Incorrect ISO9601 TimeInterval: "+i;var t=Date.parse(e[0]),s=null,n=null;return isNaN(t)?(n=this.getTimeDuration(e[0]),s=Date.parse(e[1]),t=new Date(s),this.subtractTimeDuration(t,n,!0),s=new Date(s)):(s=Date.parse(e[1]),isNaN(s)?(n=this.getTimeDuration(e[1]),s=new Date(t),this.addTimeDuration(s,n,!0)):s=new Date(s),t=new Date(t)),[t,s]},parseTimesExpression:function(i,e){var t=[];if(!i)return t;if("string"==typeof i||i instanceof String)for(var s,n,a=i.split(","),o=0,r=a.length;o0&&s.length>0;)t[0]s[0]?s.shift():(n.push(t.shift()),s.shift());return n},union_arrays:function(i,e){for(var t=i.slice(0),s=e.slice(0),n=[];t.length>0&&s.length>0;)t[0]s[0]?n.push(s.shift()):(n.push(t.shift()),s.shift());return t.length>0?n=n.concat(t):s.length>0&&(n=n.concat(s)),n},sort_and_deduplicate:function(i){for(var e=[],t=null,s=0,n=(i=i.slice(0).sort(function(i,e){return i-e})).length;s-1&&(o=n-e)>0&&(a=t.splice(0,o),this._removeLayers(a)),i>-1){n=t.indexOf(s);var o=t.length-n-i-1;o>0&&(a=t.splice(n+i+1,o),this._removeLayers(a))}},_showLayer:function(i,e){this._currentLayer&&this._currentLayer!==i&&this._currentLayer.hide(),i.show(),this._currentLayer&&this._currentLayer===i||(this._currentLayer=i,this._currentTime=e,this._evictCachedTimes(this._timeCacheForward,this._timeCacheBackward))},_getLayerForTime:function(i){if(0==i||i==this._defaultTime||null==i)return this._baseLayer;if(this._layers.hasOwnProperty(i))return this._layers[i];var e=this._getNearestTime(i);if(this._layers.hasOwnProperty(e))return this._layers[e];var t=this._createLayerForTime(e);return this._layers[i]=t,t.on("load",function(i,e){i.setLoaded(!0),this._layers[e]||(this._layers[e]=i),this._timeDimension&&e==this._timeDimension.getCurrentTime()&&!this._timeDimension.isLoading()&&this._showLayer(i,e),this.fire("timeload",{time:e})}.bind(this,t,i)),t.onAdd=function(i){Object.getPrototypeOf(this).onAdd.call(this,i),this.hide()}.bind(t),t},_createLayerForTime:function(i){var e=this._baseLayer.options;return e.time=new Date(i).toISOString(),new this._baseLayer.constructor(this._baseLayer.getURL(),e)},_getLoadedTimes:function(){var i=[];for(var e in this._layers)this._layers.hasOwnProperty(e)&&i.push(e);return i.sort(function(i,e){return i-e})},_removeLayers:function(i){for(var e=0,t=i.length;ethis._timeCacheForward&&(this._timeCacheForward=i)},_requestTimeDimensionFromCapabilities:function(){if(!this._capabilitiesRequested){this._capabilitiesRequested=!0;var i=this._getCapabilitiesUrl();this._proxy&&(i=this._proxy+"?url="+encodeURIComponent(i));var e=new XMLHttpRequest;e.addEventListener("load",function(i){var e=i.currentTarget.responseXML;null!==e&&(this._defaultTime=Date.parse(this._getDefaultTimeFromCapabilities(e)),this._setDefaultTime=this._setDefaultTime||this._timeDimension&&0==this._timeDimension.getAvailableTimes().length,this.setAvailableTimes(this._parseTimeDimensionFromCapabilities(e)),this._setDefaultTime&&this._timeDimension&&this._timeDimension.setCurrentTime(this._defaultTime))}.bind(this)),e.overrideMimeType("application/xml"),e.open("GET",i),e.send()}},_getCapabilitiesUrl:function(){var e=this._baseLayer.getURL();this._getCapabilitiesAlternateUrl&&(e=this._getCapabilitiesAlternateUrl);var t=i.extend({},this._getCapabilitiesParams,{request:"GetCapabilities",service:"WMS",version:this._wmsVersion});return e+=i.Util.getParamString(t,e,t.uppercase)},_parseTimeDimensionFromCapabilities:function(i){var e=i.querySelectorAll('Layer[queryable="1"]'),t=this._baseLayer.wmsParams.layers.split(","),s=[],n=null;return e.forEach(function(i){t.includes(i.querySelector("Name").innerHTML)&&s.push(i)}),s.length&&(n=(n=(n=s.map(this._getTimesFromLayerCapabilities)).concat(s.map(function(i){return this._getTimesFromLayerCapabilities(i.parentNode)}.bind(this)))).filter(function(i){return null!=i})),n},_getTimesFromLayerCapabilities:function(i){for(var e=null,t=i.children,s=0,n=t.length;s0&&this._timeDimension.setCurrentTime(this._defaultTime))},_getNearestTime:function(i){if(this._layers.hasOwnProperty(i))return i;if(0==this._availableTimes.length)return i;for(var e=0,t=this._availableTimes.length;e0&&e--,this._availableTimes[e],this._availableTimes[e]}}),i.NonTiledLayer||(i.NonTiledLayer=(i.Layer||i.Class).extend({})),i.NonTiledLayer.include({_visible:!0,_loaded:!1,_originalUpdate:i.NonTiledLayer.prototype._update,_originalOnRemove:i.NonTiledLayer.prototype.onRemove,_update:function(){!this._visible&&this._loaded||this._originalUpdate()},onRemove:function(i){this._loaded=!1,this._originalOnRemove(i)},setLoaded:function(i){this._loaded=i},isLoaded:function(){return this._loaded},hide:function(){this._visible=!1,this._div.style.display="none"},show:function(){this._visible=!0,this._div.style.display="block"},getURL:function(){return this._wmsUrl}}),i.TileLayer.include({_visible:!0,_loaded:!1,_originalUpdate:i.TileLayer.prototype._update,_update:function(){!this._visible&&this._loaded||this._originalUpdate()},setLoaded:function(i){this._loaded=i},isLoaded:function(){return this._loaded},hide:function(){this._visible=!1,this._container&&(this._container.style.display="none")},show:function(){this._visible=!0,this._container&&(this._container.style.display="block")},getURL:function(){return this._url}}),i.timeDimension.layer.wms=function(e,t){return new i.TimeDimension.Layer.WMS(e,t)},i.TimeDimension.Layer.GeoJson=i.TimeDimension.Layer.extend({initialize:function(e,t){i.TimeDimension.Layer.prototype.initialize.call(this,e,t),this._updateTimeDimension=this.options.updateTimeDimension||!1,this._updateTimeDimensionMode=this.options.updateTimeDimensionMode||"extremes",this._duration=this.options.duration||null,this._addlastPoint=this.options.addlastPoint||!1,this._waitForReady=this.options.waitForReady||!1,this._updateCurrentTime=this.options.updateCurrentTime||this._updateTimeDimension,this._availableTimes=[],this._loaded=!1,0==this._baseLayer.getLayers().length?this._waitForReady?this._baseLayer.on("ready",this._onReadyBaseLayer,this):this._loaded=!0:(this._loaded=!0,this._setAvailableTimes()),this._baseLayer.on("layeradd",function(){this._loaded&&this._setAvailableTimes()}.bind(this))},onAdd:function(e){i.TimeDimension.Layer.prototype.onAdd.call(this,e),this._loaded&&this._setAvailableTimes()},eachLayer:function(e,t){return this._currentLayer&&e.call(t,this._currentLayer),i.TimeDimension.Layer.prototype.eachLayer.call(this,e,t)},isReady:function(i){return this._loaded},_update:function(){if(this._map&&this._loaded){this._timeDimension.getCurrentTime();var e=this._timeDimension.getCurrentTime(),t=0;if(this._duration){var s=new Date(e);i.TimeDimension.Util.subtractTimeDuration(s,this._duration,!0),t=s.getTime()}for(var n=i.geoJson(null,this._baseLayer.options),a=this._baseLayer.getLayers(),o=0,r=a.length;o0)){var l=h.properties;l.last=!0,n.addData({type:"Feature",properties:l,geometry:{type:"Point",coordinates:h.geometry.coordinates[h.geometry.coordinates.length-1]}})}}this._currentLayer&&this._map.removeLayer(this._currentLayer),n.getLayers().length&&(n.addTo(this._map),this._currentLayer=n)}},_setAvailableTimes:function(){for(var e=[],t=this._baseLayer.getLayers(),s=0,n=t.length;st||s[o-1]e)for(var r=0;re&&(n=r),s[r]>t){a=r;break}null===n&&(n=0),null===a&&(a=o);var h=[];return h=i.geometry.coordinates[0].length?i.geometry.coordinates.slice(n,a):i.geometry.coordinates,{type:"Feature",properties:i.properties,geometry:{type:i.geometry.type,coordinates:h}}},_onReadyBaseLayer:function(){this._loaded=!0,this._setAvailableTimes(),this._update()}}),i.timeDimension.layer.geoJson=function(e,t){return new i.TimeDimension.Layer.GeoJson(e,t)},i.TimeDimension.Player=(i.Layer||i.Class).extend({includes:i.Evented||i.Mixin.Events,initialize:function(e,t){i.setOptions(this,e),this._timeDimension=t,this._paused=!1,this._buffer=this.options.buffer||5,this._minBufferReady=this.options.minBufferReady||1,this._waitingForBuffer=!1,this._loop=this.options.loop||!1,this._steps=1,this._timeDimension.on("timeload",function(i){this.release(),this._waitingForBuffer=!1}.bind(this)),this.setTransitionTime(this.options.transitionTime||1e3),this._timeDimension.on("limitschanged availabletimeschanged timeload",function(i){this._timeDimension.prepareNextTimes(this._steps,this._minBufferReady,this._loop)}.bind(this))},_tick:function(){var i=this._getMaxIndex(),e=this._timeDimension.getCurrentTimeIndex()>=i&&this._steps>0,t=0==this._timeDimension.getCurrentTimeIndex()&&this._steps<0;if((e||t)&&!this._loop)return this.pause(),this.stop(),void this.fire("animationfinished");if(!this._paused){var s=0,n=this._bufferSize;if(this._minBufferReady>0)if(s=this._timeDimension.getNumberNextTimesReady(this._steps,n,this._loop),this._waitingForBuffer){if(s0&&this._timeDimension.prepareNextTimes(this._steps,n,this._loop)}},_getMaxIndex:function(){return Math.min(this._timeDimension.getAvailableTimes().length-1,this._timeDimension.getUpperLimitIndex()||1/0)},start:function(e){if(!this._intervalID){this._steps=e||1,this._waitingForBuffer=!1;var t=!1;this.options.startOver&&this._timeDimension.getCurrentTimeIndex()===this._getMaxIndex()&&(this._timeDimension.setCurrentTimeIndex(this._timeDimension.getLowerLimitIndex()||0),t=!0),this.release(),this._intervalID=window.setInterval(i.bind(this._tick,this),this._transitionTime),t||this._tick(),this.fire("play"),this.fire("running")}},stop:function(){this._intervalID&&(clearInterval(this._intervalID),this._intervalID=null,this._waitingForBuffer=!1,this.fire("stop"))},pause:function(){this._paused=!0},release:function(){this._paused=!1},getTransitionTime:function(){return this._transitionTime},isPlaying:function(){return!!this._intervalID},isWaiting:function(){return this._waitingForBuffer},isLooped:function(){return this._loop},setLooped:function(i){this._loop=i,this.fire("loopchange",{loop:i})},setTransitionTime:function(i){this._transitionTime=i,"function"==typeof this._buffer?this._bufferSize=this._buffer.call(this,this._transitionTime,this._minBufferReady,this._loop):this._bufferSize=this._buffer,this._intervalID&&(this.stop(),this.start(this._steps)),this.fire("speedchange",{transitionTime:i,buffer:this._bufferSize})},getSteps:function(){return this._steps}}),i.UI=i.ui=i.UI||{},i.UI.Knob=i.Draggable.extend({options:{className:"knob",step:1,rangeMin:0,rangeMax:10},initialize:function(e,t){i.setOptions(this,t),this._element=i.DomUtil.create("div",this.options.className||"knob",e),i.Draggable.prototype.initialize.call(this,this._element,this._element),this._container=e,this.on("predrag",function(){this._newPos.y=0,this._newPos.x=this._adjustX(this._newPos.x)},this),this.on("dragstart",function(){i.DomUtil.addClass(e,"dragging")}),this.on("dragend",function(){i.DomUtil.removeClass(e,"dragging")}),i.DomEvent.on(this._element,"dblclick",function(i){this.fire("dblclick",i)},this),i.DomEvent.disableClickPropagation(this._element),this.enable()},_getProjectionCoef:function(){return(this.options.rangeMax-this.options.rangeMin)/(this._container.offsetWidth||this._container.style.width)},_update:function(){this.setPosition(i.DomUtil.getPosition(this._element).x)},_adjustX:function(i){var e=this._toValue(i)||this.getMinValue();return this._toX(this._adjustValue(e))},_adjustValue:function(i){return i=Math.max(this.getMinValue(),Math.min(this.getMaxValue(),i)),i-=this.options.rangeMin,i=Math.round(i/this.options.step)*this.options.step,i+=this.options.rangeMin,i=Math.round(100*i)/100},_toX:function(i){return(i-this.options.rangeMin)/this._getProjectionCoef()},_toValue:function(i){return i*this._getProjectionCoef()+this.options.rangeMin},getMinValue:function(){return this.options.minValue||this.options.rangeMin},getMaxValue:function(){return this.options.maxValue||this.options.rangeMax},setStep:function(i){this.options.step=i,this._update()},setPosition:function(e){i.DomUtil.setPosition(this._element,i.point(this._adjustX(e),0)),this.fire("positionchanged")},getPosition:function(){return i.DomUtil.getPosition(this._element).x},setValue:function(i){this.setPosition(this._toX(i))},getValue:function(){return this._adjustValue(this._toValue(this.getPosition()))}}),i.Control.TimeDimension=i.Control.extend({options:{styleNS:"leaflet-control-timecontrol",position:"bottomleft",title:"Time Control",backwardButton:!0,forwardButton:!0,playButton:!0,playReverseButton:!1,loopButton:!1,displayDate:!0,timeSlider:!0,timeSliderDragUpdate:!1,limitSliders:!1,limitMinimumRange:5,speedSlider:!0,minSpeed:.1,maxSpeed:10,speedStep:.1,timeSteps:1,autoPlay:!1,playerOptions:{transitionTime:1e3},timeZones:["UTC","Local"]},initialize:function(e){i.setOptions(e),i.Control.prototype.initialize.call(this,e),this._timeZoneIndex=0,this._timeDimension=this.options.timeDimension||null},onAdd:function(e){var t;return this._map=e,!this._timeDimension&&e.timeDimension&&(this._timeDimension=e.timeDimension),this._initPlayer(),t=i.DomUtil.create("div","leaflet-bar leaflet-bar-horizontal leaflet-bar-timecontrol"),this.options.backwardButton&&(this._buttonBackward=this._createButton("Backward",t)),this.options.playReverseButton&&(this._buttonPlayReversePause=this._createButton("Play Reverse",t)),this.options.playButton&&(this._buttonPlayPause=this._createButton("Play",t)),this.options.forwardButton&&(this._buttonForward=this._createButton("Forward",t)),this.options.loopButton&&(this._buttonLoop=this._createButton("Loop",t)),this.options.displayDate&&(this._displayDate=this._createButton("Date",t)),this.options.timeSlider&&(this._sliderTime=this._createSliderTime(this.options.styleNS+" timecontrol-slider timecontrol-dateslider",t)),this.options.speedSlider&&(this._sliderSpeed=this._createSliderSpeed(this.options.styleNS+" timecontrol-slider timecontrol-speed",t)),this._steps=this.options.timeSteps||1,this._timeDimension.on("timeload",this._update,this),this._timeDimension.on("timeload",this._onPlayerStateChange,this),this._timeDimension.on("timeloading",this._onTimeLoading,this),this._timeDimension.on("limitschanged availabletimeschanged",this._onTimeLimitsChanged,this),i.DomEvent.disableClickPropagation(t),t},addTo:function(){return i.Control.prototype.addTo.apply(this,arguments),this._onPlayerStateChange(),this._onTimeLimitsChanged(),this._update(),this},onRemove:function(){this._player.off("play stop running loopchange speedchange",this._onPlayerStateChange,this),this._player.off("waiting",this._onPlayerWaiting,this),this._timeDimension.off("timeload",this._update,this),this._timeDimension.off("timeload",this._onPlayerStateChange,this),this._timeDimension.off("timeloading",this._onTimeLoading,this),this._timeDimension.off("limitschanged availabletimeschanged",this._onTimeLimitsChanged,this)},_initPlayer:function(){this._player||(this.options.player?this._player=this.options.player:this._player=new i.TimeDimension.Player(this.options.playerOptions,this._timeDimension)),this.options.autoPlay&&this._player.start(this._steps),this._player.on("play stop running loopchange speedchange",this._onPlayerStateChange,this),this._player.on("waiting",this._onPlayerWaiting,this),this._onPlayerStateChange()},_onTimeLoading:function(e){e.time==this._timeDimension.getCurrentTime()&&this._displayDate&&i.DomUtil.addClass(this._displayDate,"loading")},_onTimeLimitsChanged:function(){var i=this._timeDimension.getLowerLimitIndex(),e=this._timeDimension.getUpperLimitIndex(),t=this._timeDimension.getAvailableTimes().length-1;this._limitKnobs&&(this._limitKnobs[0].options.rangeMax=t,this._limitKnobs[1].options.rangeMax=t,this._limitKnobs[0].setValue(i||0),this._limitKnobs[1].setValue(e||t)),this._sliderTime&&(this._sliderTime.options.rangeMax=t,this._sliderTime._update())},_onPlayerWaiting:function(e){this._buttonPlayPause&&this._player.getSteps()>0&&(i.DomUtil.addClass(this._buttonPlayPause,"loading"),this._buttonPlayPause.innerHTML=this._getDisplayLoadingText(e.available,e.buffer)),this._buttonPlayReversePause&&this._player.getSteps()<0&&(i.DomUtil.addClass(this._buttonPlayReversePause,"loading"),this._buttonPlayReversePause.innerHTML=this._getDisplayLoadingText(e.available,e.buffer))},_onPlayerStateChange:function(){if(this._buttonPlayPause&&(this._player.isPlaying()&&this._player.getSteps()>0?(i.DomUtil.addClass(this._buttonPlayPause,"pause"),i.DomUtil.removeClass(this._buttonPlayPause,"play")):(i.DomUtil.removeClass(this._buttonPlayPause,"pause"),i.DomUtil.addClass(this._buttonPlayPause,"play")),this._player.isWaiting()&&this._player.getSteps()>0?i.DomUtil.addClass(this._buttonPlayPause,"loading"):(this._buttonPlayPause.innerHTML="",i.DomUtil.removeClass(this._buttonPlayPause,"loading"))),this._buttonPlayReversePause&&(this._player.isPlaying()&&this._player.getSteps()<0?i.DomUtil.addClass(this._buttonPlayReversePause,"pause"):i.DomUtil.removeClass(this._buttonPlayReversePause,"pause"),this._player.isWaiting()&&this._player.getSteps()<0?i.DomUtil.addClass(this._buttonPlayReversePause,"loading"):(this._buttonPlayReversePause.innerHTML="",i.DomUtil.removeClass(this._buttonPlayReversePause,"loading"))),this._buttonLoop&&(this._player.isLooped()?i.DomUtil.addClass(this._buttonLoop,"looped"):i.DomUtil.removeClass(this._buttonLoop,"looped")),this._sliderSpeed&&!this._draggingSpeed){var e=this._player.getTransitionTime()||1e3;e=Math.round(1e4/e)/10,this._sliderSpeed.setValue(e)}},_update:function(){if(this._timeDimension)if(this._timeDimension.getCurrentTimeIndex()>=0){var e=new Date(this._timeDimension.getCurrentTime());this._displayDate&&(i.DomUtil.removeClass(this._displayDate,"loading"),this._displayDate.innerHTML=this._getDisplayDateFormat(e)),this._sliderTime&&!this._slidingTimeSlider&&this._sliderTime.setValue(this._timeDimension.getCurrentTimeIndex())}else this._displayDate&&(this._displayDate.innerHTML=this._getDisplayNoTimeError())},_createButton:function(e,t){var s=i.DomUtil.create("a",this.options.styleNS+" timecontrol-"+e.toLowerCase(),t);return s.href="#",s.title=e,i.DomEvent.addListener(s,"click",i.DomEvent.stopPropagation).addListener(s,"click",i.DomEvent.preventDefault).addListener(s,"click",this["_button"+e.replace(/ /i,"")+"Clicked"],this),s},_createSliderTime:function(e,t){var s,n,a,o,r;return s=i.DomUtil.create("div",e,t),n=i.DomUtil.create("div","slider",s),a=this._timeDimension.getAvailableTimes().length-1,this.options.limitSliders&&(r=this._limitKnobs=this._createLimitKnobs(n)),(o=new i.UI.Knob(n,{className:"knob main",rangeMin:0,rangeMax:a})).on("dragend",function(i){var e=i.target.getValue();this._sliderTimeValueChanged(e),this._slidingTimeSlider=!1},this),o.on("drag",function(i){this._slidingTimeSlider=!0;var e=this._timeDimension.getAvailableTimes()[i.target.getValue()];if(e){var t=new Date(e);this._displayDate&&(this._displayDate.innerHTML=this._getDisplayDateFormat(t)),this.options.timeSliderDragUpdate&&this._sliderTimeValueChanged(i.target.getValue())}},this),o.on("predrag",function(){var i,e;r&&(i=r[0].getPosition(),e=r[1].getPosition(),this._newPos.xe&&(this._newPos.x=e))},o),i.DomEvent.on(n,"click",function(e){if(!i.DomUtil.hasClass(e.target,"knob")){var t=e.touches&&1===e.touches.length?e.touches[0]:e,s=i.DomEvent.getMousePosition(t,n).x;r?r[0].getPosition()<=s&&s<=r[1].getPosition()&&(o.setPosition(s),this._sliderTimeValueChanged(o.getValue())):(o.setPosition(s),this._sliderTimeValueChanged(o.getValue()))}},this),o.setPosition(0),o},_createLimitKnobs:function(e){i.DomUtil.addClass(e,"has-limits");var t=this._timeDimension.getAvailableTimes().length-1,s=i.DomUtil.create("div","range",e),n=new i.UI.Knob(e,{className:"knob lower",rangeMin:0,rangeMax:t}),a=new i.UI.Knob(e,{className:"knob upper",rangeMin:0,rangeMax:t});return i.DomUtil.setPosition(s,0),n.setPosition(0),a.setPosition(t),n.on("dragend",function(i){var e=i.target.getValue();this._sliderLimitsValueChanged(e,a.getValue())},this),a.on("dragend",function(i){var e=i.target.getValue();this._sliderLimitsValueChanged(n.getValue(),e)},this),n.on("drag positionchanged",function(){i.DomUtil.setPosition(s,i.point(n.getPosition(),0)),s.style.width=a.getPosition()-n.getPosition()+"px"},this),a.on("drag positionchanged",function(){s.style.width=a.getPosition()-n.getPosition()+"px"},this),a.on("predrag",function(){var i=n._toX(n.getValue()+this.options.limitMinimumRange);a._newPos.x<=i&&(a._newPos.x=i)},this),n.on("predrag",function(){var i=a._toX(a.getValue()-this.options.limitMinimumRange);n._newPos.x>=i&&(n._newPos.x=i)},this),n.on("dblclick",function(){this._timeDimension.setLowerLimitIndex(0)},this),a.on("dblclick",function(){this._timeDimension.setUpperLimitIndex(this._timeDimension.getAvailableTimes().length-1)},this),[n,a]},_createSliderSpeed:function(e,t){var s=i.DomUtil.create("div",e,t),n=i.DomUtil.create("span","speed",s),a=i.DomUtil.create("div","slider",s),o=Math.round(1e4/(this._player.getTransitionTime()||1e3))/10;n.innerHTML=this._getDisplaySpeed(o);var r=new i.UI.Knob(a,{step:this.options.speedStep,rangeMin:this.options.minSpeed,rangeMax:this.options.maxSpeed});return r.on("dragend",function(i){var e=i.target.getValue();this._draggingSpeed=!1,n.innerHTML=this._getDisplaySpeed(e),this._sliderSpeedValueChanged(e)},this),r.on("drag",function(i){this._draggingSpeed=!0,n.innerHTML=this._getDisplaySpeed(i.target.getValue())},this),r.on("positionchanged",function(i){n.innerHTML=this._getDisplaySpeed(i.target.getValue())},this),i.DomEvent.on(a,"click",function(e){if(e.target!==r._element){var t=e.touches&&1===e.touches.length?e.touches[0]:e,s=i.DomEvent.getMousePosition(t,a).x;r.setPosition(s),n.innerHTML=this._getDisplaySpeed(r.getValue()),this._sliderSpeedValueChanged(r.getValue())}},this),r},_buttonBackwardClicked:function(){this._timeDimension.previousTime(this._steps)},_buttonForwardClicked:function(){this._timeDimension.nextTime(this._steps)},_buttonLoopClicked:function(){this._player.setLooped(!this._player.isLooped())},_buttonPlayClicked:function(){this._player.isPlaying()?this._player.stop():this._player.start(this._steps)},_buttonPlayReverseClicked:function(){this._player.isPlaying()?this._player.stop():this._player.start(-1*this._steps)},_buttonDateClicked:function(){this._switchTimeZone()},_sliderTimeValueChanged:function(i){this._timeDimension.setCurrentTimeIndex(i)},_sliderLimitsValueChanged:function(i,e){this._timeDimension.setLowerLimitIndex(i),this._timeDimension.setUpperLimitIndex(e)},_sliderSpeedValueChanged:function(i){this._player.setTransitionTime(1e3/i)},_getCurrentTimeZone:function(){return this.options.timeZones[this._timeZoneIndex]},_switchTimeZone:function(){"utc"==this._getCurrentTimeZone().toLowerCase()&&i.DomUtil.removeClass(this._displayDate,"utc"),this._timeZoneIndex=(this._timeZoneIndex+1)%this.options.timeZones.length;var e=this._getCurrentTimeZone();"utc"==e.toLowerCase()?(i.DomUtil.addClass(this._displayDate,"utc"),this._displayDate.title="UTC Time"):"local"==e.toLowerCase()?this._displayDate.title="Local Time":this._displayDate.title=e,this._update()},_getDisplayDateFormat:function(i){var e=this._getCurrentTimeZone();return"utc"==e.toLowerCase()?i.toISOString():"local"==e.toLowerCase()?i.toLocaleString():i.toLocaleString([],{timeZone:e,timeZoneName:"short"})},_getDisplaySpeed:function(i){return i+"fps"},_getDisplayLoadingText:function(i,e){return""+Math.floor(i/e*100)+"%"},_getDisplayNoTimeError:function(){return"Time not available"}}),i.Map.addInitHook(function(){this.options.timeDimensionControl&&(this.timeDimensionControl=i.control.timeDimension(this.options.timeDimensionControlOptions||{}),this.addControl(this.timeDimensionControl))}),i.control.timeDimension=function(e){return new i.Control.TimeDimension(e)},i.TimeDimension},window); \ No newline at end of file diff --git a/dist/leaflet.timedimension.src.js b/dist/leaflet.timedimension.src.js index 2d67d9a..3c2fe27 100644 --- a/dist/leaflet.timedimension.src.js +++ b/dist/leaflet.timedimension.src.js @@ -1,14 +1,14 @@ /* - * Leaflet TimeDimension v1.1.1 - 2019-11-05 + * Leaflet TimeDimension v1.1.1 - 2020-11-12 * - * Copyright 2019 Biel Frontera (ICTS SOCIB) + * Copyright 2020 Biel Frontera (ICTS SOCIB) * datacenter@socib.es - * http://www.socib.es/ + * https://www.socib.es/ * * Licensed under the MIT license. * * Demos: - * http://apps.socib.es/Leaflet.TimeDimension/ + * https://apps.socib.es/Leaflet.TimeDimension/ * * Source: * git://github.com/socib/Leaflet.TimeDimension.git @@ -612,7 +612,9 @@ L.TimeDimension.Util = { }, sort_and_deduplicate: function(arr) { - arr = arr.slice(0).sort(); + arr = arr.slice(0).sort(function (a, b) { + return a - b; + }); var result = []; var last = null; for (var i = 0, l = arr.length; i < l; i++) { @@ -1043,22 +1045,25 @@ L.TimeDimension.Layer.WMS = L.TimeDimension.Layer.extend({ _parseTimeDimensionFromCapabilities: function(xml) { var layers = xml.querySelectorAll('Layer[queryable="1"]'); - var layerName = this._baseLayer.wmsParams.layers; - var layer = null; + var layerNames = this._baseLayer.wmsParams.layers.split(','); + var layersFiltered = []; var times = null; layers.forEach(function(current) { - if (current.querySelector("Name").innerHTML === layerName) { - layer = current; + if (layerNames.includes(current.querySelector("Name").innerHTML)) { + layersFiltered.push(current); } }) - if (layer) { - times = this._getTimesFromLayerCapabilities(layer); - if (!times) { - times = this._getTimesFromLayerCapabilities(layer.parentNode); - } + if (layersFiltered.length) { + times = layersFiltered.map(this._getTimesFromLayerCapabilities); + times = times.concat(layersFiltered.map((function(node){ + return this._getTimesFromLayerCapabilities(node.parentNode); + }).bind(this))) + times = times.filter(function(time){ + return time!=null; + }) } - + return times; }, @@ -1257,7 +1262,7 @@ L.TimeDimension.Layer.GeoJson = L.TimeDimension.Layer.extend({ this._duration = this.options.duration || null; this._addlastPoint = this.options.addlastPoint || false; this._waitForReady = this.options.waitForReady || false; - this._defaultTime = 0; + this._updateCurrentTime = this.options.updateCurrentTime || this._updateTimeDimension; this._availableTimes = []; this._loaded = false; if (this._baseLayer.getLayers().length == 0) { @@ -1358,9 +1363,13 @@ L.TimeDimension.Layer.GeoJson = L.TimeDimension.Layer.extend({ } } this._availableTimes = L.TimeDimension.Util.sort_and_deduplicate(times); + this._updateCurrentTime = this._updateCurrentTime || (this._timeDimension && this._timeDimension.getAvailableTimes().length == 0); if (this._timeDimension && (this._updateTimeDimension || this._timeDimension.getAvailableTimes().length == 0)) { this._timeDimension.setAvailableTimes(this._availableTimes, this._updateTimeDimensionMode); } + if (this._updateCurrentTime && this._timeDimension && this._availableTimes.length) { + this._timeDimension.setCurrentTime(this._availableTimes[0]); + } }, _getFeatureTimes: function(feature) { @@ -1549,16 +1558,19 @@ L.TimeDimension.Player = (L.Layer || L.Class).extend({ if (this._intervalID) return; this._steps = numSteps || 1; this._waitingForBuffer = false; + var startedOver = false; if (this.options.startOver){ if (this._timeDimension.getCurrentTimeIndex() === this._getMaxIndex()){ - this._timeDimension.setCurrentTimeIndex(this._timeDimension.getLowerLimitIndex() || 0); + this._timeDimension.setCurrentTimeIndex(this._timeDimension.getLowerLimitIndex() || 0); + startedOver = true; } } this.release(); this._intervalID = window.setInterval( L.bind(this._tick, this), this._transitionTime); - this._tick(); + if (!startedOver) + this._tick(); this.fire('play'); this.fire('running'); }, diff --git a/dist/leaflet.timedimension.src.withlog.js b/dist/leaflet.timedimension.src.withlog.js index 15393ac..0624f3b 100644 --- a/dist/leaflet.timedimension.src.withlog.js +++ b/dist/leaflet.timedimension.src.withlog.js @@ -1,14 +1,14 @@ /* - * Leaflet TimeDimension v1.1.1 - 2019-11-05 + * Leaflet TimeDimension v1.1.1 - 2020-11-12 * - * Copyright 2019 Biel Frontera (ICTS SOCIB) + * Copyright 2020 Biel Frontera (ICTS SOCIB) * datacenter@socib.es - * http://www.socib.es/ + * https://www.socib.es/ * * Licensed under the MIT license. * * Demos: - * http://apps.socib.es/Leaflet.TimeDimension/ + * https://apps.socib.es/Leaflet.TimeDimension/ * * Source: * git://github.com/socib/Leaflet.TimeDimension.git @@ -612,7 +612,9 @@ L.TimeDimension.Util = { }, sort_and_deduplicate: function(arr) { - arr = arr.slice(0).sort(); + arr = arr.slice(0).sort(function (a, b) { + return a - b; + }); var result = []; var last = null; for (var i = 0, l = arr.length; i < l; i++) { @@ -1043,22 +1045,25 @@ L.TimeDimension.Layer.WMS = L.TimeDimension.Layer.extend({ _parseTimeDimensionFromCapabilities: function(xml) { var layers = xml.querySelectorAll('Layer[queryable="1"]'); - var layerName = this._baseLayer.wmsParams.layers; - var layer = null; + var layerNames = this._baseLayer.wmsParams.layers.split(','); + var layersFiltered = []; var times = null; layers.forEach(function(current) { - if (current.querySelector("Name").innerHTML === layerName) { - layer = current; + if (layerNames.includes(current.querySelector("Name").innerHTML)) { + layersFiltered.push(current); } }) - if (layer) { - times = this._getTimesFromLayerCapabilities(layer); - if (!times) { - times = this._getTimesFromLayerCapabilities(layer.parentNode); - } - } - + if (layersFiltered.length) { + times = layersFiltered.map(this._getTimesFromLayerCapabilities); + times = times.concat(layersFiltered.map((function(node){ + return this._getTimesFromLayerCapabilities(node.parentNode); + }).bind(this))) + times = times.filter(function(time){ + return time!=null; + }) + } + console.log(times); return times; }, @@ -1257,7 +1262,7 @@ L.TimeDimension.Layer.GeoJson = L.TimeDimension.Layer.extend({ this._duration = this.options.duration || null; this._addlastPoint = this.options.addlastPoint || false; this._waitForReady = this.options.waitForReady || false; - this._defaultTime = 0; + this._updateCurrentTime = this.options.updateCurrentTime || this._updateTimeDimension; this._availableTimes = []; this._loaded = false; if (this._baseLayer.getLayers().length == 0) { @@ -1358,9 +1363,13 @@ L.TimeDimension.Layer.GeoJson = L.TimeDimension.Layer.extend({ } } this._availableTimes = L.TimeDimension.Util.sort_and_deduplicate(times); + this._updateCurrentTime = this._updateCurrentTime || (this._timeDimension && this._timeDimension.getAvailableTimes().length == 0); if (this._timeDimension && (this._updateTimeDimension || this._timeDimension.getAvailableTimes().length == 0)) { this._timeDimension.setAvailableTimes(this._availableTimes, this._updateTimeDimensionMode); } + if (this._updateCurrentTime && this._timeDimension && this._availableTimes.length) { + this._timeDimension.setCurrentTime(this._availableTimes[0]); + } }, _getFeatureTimes: function(feature) { @@ -1549,16 +1558,19 @@ L.TimeDimension.Player = (L.Layer || L.Class).extend({ if (this._intervalID) return; this._steps = numSteps || 1; this._waitingForBuffer = false; + var startedOver = false; if (this.options.startOver){ if (this._timeDimension.getCurrentTimeIndex() === this._getMaxIndex()){ - this._timeDimension.setCurrentTimeIndex(this._timeDimension.getLowerLimitIndex() || 0); + this._timeDimension.setCurrentTimeIndex(this._timeDimension.getLowerLimitIndex() || 0); + startedOver = true; } } this.release(); this._intervalID = window.setInterval( L.bind(this._tick, this), this._transitionTime); - this._tick(); + if (!startedOver) + this._tick(); this.fire('play'); this.fire('running'); }, diff --git a/package.json b/package.json index e3f0ede..f4e57fc 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,9 @@ "email": "datacenter@socib.es", "url": "https://www.socib.es/" }, + "scripts": { + "build" : "grunt" + }, "contributors": [ { "name": "Sylvain Marcadal (Ram)", diff --git a/src/leaflet.timedimension.layer.wms.js b/src/leaflet.timedimension.layer.wms.js index 8a9bc09..0720972 100644 --- a/src/leaflet.timedimension.layer.wms.js +++ b/src/leaflet.timedimension.layer.wms.js @@ -290,22 +290,24 @@ L.TimeDimension.Layer.WMS = L.TimeDimension.Layer.extend({ _parseTimeDimensionFromCapabilities: function(xml) { var layers = xml.querySelectorAll('Layer[queryable="1"]'); - var layerName = this._baseLayer.wmsParams.layers; - var layer = null; + var layerNames = this._baseLayer.wmsParams.layers.split(','); + var layersFiltered = []; var times = null; layers.forEach(function(current) { - if (current.querySelector("Name").innerHTML === layerName) { - layer = current; + if (layerNames.includes(current.querySelector("Name").innerHTML)) { + layersFiltered.push(current); } }) - if (layer) { - times = this._getTimesFromLayerCapabilities(layer); - if (!times) { - times = this._getTimesFromLayerCapabilities(layer.parentNode); - } + if (layersFiltered.length) { + times = layersFiltered.map(this._getTimesFromLayerCapabilities); + times = times.concat(layersFiltered.map((function(node){ + return this._getTimesFromLayerCapabilities(node.parentNode); + }).bind(this))) + times = times.filter(function(time){ + return time!=null; + }) } - return times; },