mirror of
https://github.com/medialab-prado/poblados-colonizacion-colonias-penitenciarias.git
synced 2024-12-27 04:51:22 +01:00
18 lines
38 KiB
JavaScript
18 lines
38 KiB
JavaScript
|
/*
|
||
|
* Leaflet TimeDimension v1.0.6 - 2016-07-28
|
||
|
*
|
||
|
* Copyright 2016 Biel Frontera (ICTS SOCIB)
|
||
|
* datacenter@socib.es
|
||
|
* http://www.socib.es/
|
||
|
*
|
||
|
* Licensed under the MIT license.
|
||
|
*
|
||
|
* Demos:
|
||
|
* http://apps.socib.es/Leaflet.TimeDimension/
|
||
|
*
|
||
|
* Source:
|
||
|
* git://github.com/socib/Leaflet.TimeDimension.git
|
||
|
*
|
||
|
*/
|
||
|
!function(a){L.TimeDimension=(L.Layer||L.Class).extend({includes:L.Mixin.Events,initialize:function(a){L.setOptions(this,a),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 a=-1;return a=-1!==this._loadingTimeIndex?this._loadingTimeIndex:this.getCurrentTimeIndex(),a>=0?this._availableTimes[a]:0},isLoading:function(){return-1!==this._loadingTimeIndex},setCurrentTimeIndex:function(a){var b=this._upperLimit||this._availableTimes.length-1,c=this._lowerLimit||0;if(a=Math.min(Math.max(c,a),b),!(0>a)){this._loadingTimeIndex=a;var d=this._availableTimes[a];this._checkSyncedLayersReady(this._availableTimes[this._loadingTimeIndex])?this._newTimeIndexLoaded():(this.fire("timeloading",{time:d}),setTimeout(function(a){a==this._loadingTimeIndex&&this._newTimeIndexLoaded()}.bind(this,a),this._loadingTimeout))}},_newTimeIndexLoaded:function(){if(-1!==this._loadingTimeIndex){var a=this._availableTimes[this._loadingTimeIndex];this._currentTimeIndex=this._loadingTimeIndex,this.fire("timeload",{time:a}),this._loadingTimeIndex=-1}},_checkSyncedLayersReady:function(a){for(var b=0,c=this._syncedLayers.length;c>b;b++)if(this._syncedLayers[b].isReady&&!this._syncedLayers[b].isReady(a))return!1;return!0},setCurrentTime:function(a){var b=this._seekNearestTimeIndex(a);this.setCurrentTimeIndex(b)},seekNearestTime:function(a){var b=this._seekNearestTimeIndex(a);return this._availableTimes[b]},nextTime:function(a,b){a||(a=1);var c=this._currentTimeIndex,d=this._upperLimit||this._availableTimes.length-1,e=this._lowerLimit||0;this._loadingTimeIndex>-1&&(c=this._loadingTimeIndex),c+=a,c>d&&(c=b?e:d),e>c&&(c=b?d:e),this.setCurrentTimeIndex(c)},prepareNextTimes:function(a,b,c){a||(a=1);var d=this._currentTimeIndex,e=d;this._loadingTimeIndex>-1&&(d=this._loadingTimeIndex);for(var f=0,g=this._syncedLayers.length;g>f;f++)this._syncedLayers[f].setMinimumForwardCache&&this._syncedLayers[f].setMinimumForwardCache(b);for(var h=b,i=this._upperLimit||this._availableTimes.length-1,j=this._lowerLimit||0;h>0;){if(d+=a,d>i){if(!c)break;d=j}if(j>d){if(!c)break;d=i}if(e===d)break;this.fire("timeloading",{time:this._availableTimes[d]}),h--}},getNumberNextTimesReady:function(a,b,c){a||(a=1);var d=this._currentTimeIndex;this._loadingTimeIndex>-1&&(d=this._loadingTimeIndex);for(var e=b,f=0,g=this._upperLimit||this._availableTimes.length-1,h=this._lowerLimit||0;e>0;){if(d+=a,d>g){if(!c){e=0,f=b;break}d=h}if(h>d){if(!c){e=0,f=b;break}d=g}var i=this._availableTimes[d];this._checkSyncedLayersReady(i)&&f++,e--}return f},previousTime:function(a,b){this.nextTime(-1*a,b)},registerSyncedLayer:function(a){this._syncedLayers.push(a),a.on("timeload",this._onSyncedLayerLoaded,this)},unregisterSyncedLayer:function(a){var b=this._syncedLayers.indexOf(a);-1!=b&&this._syncedLayers.splice(b,1),a.off("timeload",this._onSyncedLayerLoaded,this)},_onSyncedLayerLoaded:function(a){a.time==this._availableTimes[this._loadingTimeIndex]&&this._checkSyncedLayersReady(a.time)&&this._newTimeIndexLoaded()},_generateAvailableTimes:function(){if(this.options.times)return L.TimeDimension.Util.parseTimesExpression(this.options.times);if(this.options.timeInterval){var a=L.TimeDimension.Util.parseTimeInterval(this.options.timeInterval),b=this.options.period||"P1D",c=this.options.validTimeRange||void 0;return L.TimeDimension.Util.explodeTimeRange(a[0],a[1],b,c)}return[]},_getDefaultCurrentTime:function(){var a=this._seekNearestTimeIndex((new Date).getTime());return this._availableTimes[a]},_seekNearestTimeIndex:function(a)
|
||
|
this._sliderSpeed&&!this._draggingSpeed){var a=this._player.getTransitionTime()||1e3;a=Math.round(1e4/a)/10,this._sliderSpeed.setValue(a)}},_update:function(){if(this._timeDimension){var a=this._timeDimension.getCurrentTime();if(a>0){var b=new Date(a);this._displayDate&&(L.DomUtil.removeClass(this._displayDate,"loading"),this._displayDate.innerHTML=this._getDisplayDateFormat(b)),this._sliderTime&&!this._slidingTimeSlider&&this._sliderTime.setValue(this._timeDimension.getCurrentTimeIndex())}else this._displayDate&&(this._displayDate.innerHTML=this._getDisplayNoTimeError())}},_createButton:function(a,b){var c=L.DomUtil.create("a",this.options.styleNS+" timecontrol-"+a.toLowerCase(),b);return c.href="#",c.title=a,L.DomEvent.addListener(c,"click",L.DomEvent.stopPropagation).addListener(c,"click",L.DomEvent.preventDefault).addListener(c,"click",this["_button"+a.replace(/ /i,"")+"Clicked"],this),c},_createDisplayDate:function(a,b){var c=L.DomUtil.create("a",a+" utc",b);return c.href="#",c.title="UTC Time",L.DomEvent.addListener(c,"click",L.DomEvent.stopPropagation).addListener(c,"click",L.DomEvent.preventDefault).addListener(c,"click",this._toggleDateUTC,this),c},_createSliderTime:function(a,b){var c,d,e,f,g;return c=L.DomUtil.create("div",a,b),d=L.DomUtil.create("div","slider",c),e=this._timeDimension.getAvailableTimes().length-1,this.options.limitSliders&&(g=this._limitKnobs=this._createLimitKnobs(d)),f=new L.UI.Knob(d,{className:"knob main",rangeMin:0,rangeMax:e}),f.on("dragend",function(a){var b=a.target.getValue();this._sliderTimeValueChanged(b),this._slidingTimeSlider=!1},this),f.on("drag",function(a){this._slidingTimeSlider=!0;var b=this._timeDimension.getAvailableTimes()[a.target.getValue()];if(b){var c=new Date(b);this._displayDate&&(this._displayDate.innerHTML=this._getDisplayDateFormat(c)),this.options.timeSliderDragUpdate&&this._sliderTimeValueChanged(a.target.getValue())}},this),f.on("predrag",function(){var a,b;g&&(a=g[0].getPosition(),b=g[1].getPosition(),this._newPos.x<a&&(this._newPos.x=a),this._newPos.x>b&&(this._newPos.x=b))},f),L.DomEvent.on(d,"click",function(a){if(!L.DomUtil.hasClass(a.target,"knob")){var b=a.touches&&1===a.touches.length?a.touches[0]:a,c=L.DomEvent.getMousePosition(b,d).x;g?g[0].getPosition()<=c&&c<=g[1].getPosition()&&(f.setPosition(c),this._sliderTimeValueChanged(f.getValue())):(f.setPosition(c),this._sliderTimeValueChanged(f.getValue()))}},this),f.setPosition(0),f},_createLimitKnobs:function(a){L.DomUtil.addClass(a,"has-limits");var b=this._timeDimension.getAvailableTimes().length-1,c=L.DomUtil.create("div","range",a),d=new L.UI.Knob(a,{className:"knob lower",rangeMin:0,rangeMax:b}),e=new L.UI.Knob(a,{className:"knob upper",rangeMin:0,rangeMax:b});return L.DomUtil.setPosition(c,0),d.setPosition(0),e.setPosition(b),d.on("dragend",function(a){var b=a.target.getValue();this._sliderLimitsValueChanged(b,e.getValue())},this),e.on("dragend",function(a){var b=a.target.getValue();this._sliderLimitsValueChanged(d.getValue(),b)},this),d.on("drag positionchanged",function(){L.DomUtil.setPosition(c,L.point(d.getPosition(),0)),c.style.width=e.getPosition()-d.getPosition()+"px"},this),e.on("drag positionchanged",function(){c.style.width=e.getPosition()-d.getPosition()+"px"},this),e.on("predrag",function(){var a=d._toX(d.getValue()+this.options.limitMinimumRange);e._newPos.x<=a&&(e._newPos.x=a)},this),d.on("predrag",function(){var a=e._toX(e.getValue()-this.options.limitMinimumRange);d._newPos.x>=a&&(d._newPos.x=a)},this),d.on("dblclick",function(){this._timeDimension.setLowerLimitIndex(0)},this),e.on("dblclick",function(){this._timeDimension.setUpperLimitIndex(this._timeDimension.getAvailableTimes().length-1)},this),[d,e]},_createSliderSpeed:function(a,b){var c=L.DomUtil.create("div",a,b),d=L.DomUtil.create("span","speed",c),e=L.DomUtil.create("div","slider",c),f=Math.round(1e4/(this._player.getTransitionTime()||1e3))/10;d.innerHTML=this._getDisplaySpeed(f);var g=new L.UI.Knob(e,{step:this.options.speedStep,rangeMin:this.options.minSpeed,rangeMax:this.options.maxSpeed});return g.on("dragend",functi
|