Mercurial > hg > STI-GWT
diff war/scripts/sti/DataObject.js @ 3:cf06b77a8bbd
Committed branch of the e4D repos sti-gwt branch 16384.
git-svn-id: http://dev.dariah.eu/svn/repos/eu.dariah.de/ap1/sti-gwt-dariah-geobrowser@36 f2b5be40-def6-11e0-8a09-b3c1cc336c6b
author | StefanFunk <StefanFunk@f2b5be40-def6-11e0-8a09-b3c1cc336c6b> |
---|---|
date | Tue, 17 Jul 2012 13:34:40 +0000 |
parents | |
children | 775477d89709 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/war/scripts/sti/DataObject.js Tue Jul 17 13:34:40 2012 +0000 @@ -0,0 +1,112 @@ +/** + * class that contains all needed information about an element of the resulting data set including time and place values + * @param {String} name the name of the data object + * @param {String} description description of the data object + * @param {String} place the place, the data object corresponds to + * @param {Date} time the time stamp, the data object corresponds to + * @param {int} granularity the granularity of the given time + * @param {float} lon the longitude value corresponding to the given place + * @param {float} lat the latitude value corresponding to the given place + * + * @constructor + */ +DataObject = function(name, description, place, timeStamp, timeSpan, granularity, lon, lat){ + + this.name = name; + this.description = description; + this.timeStamp = timeStamp; + this.timeSpan = timeSpan; + this.granularity = granularity; + this.longitude = lon; + this.latitude = lat; + + this.setPlaces(place); + this.status = false; + this.percentage = 0; + this.hoverSelect = false; + +}; + +DataObject.prototype = { + + /** + * sets the selection-percentage of the data object + * @param {float} percentage sets the percentage value (p); it describes the ratio to the actual selection <br> + * p = 0 if this data object is unselected, p = 1 if it is selected and 0 < p < 1 if its in a feather range + */ + setPercentage: function(percentage){ + if (this.percentage == percentage) + this.status = false; + else { + this.percentage = percentage; + this.status = true; + } + }, + + inTime: function( minTime, maxTime ){ + if( this.timeStamp != undefined ){ + if( this.timeStamp.getTime() >= minTime.getTime() && this.timeStamp.getTime() <= maxTime.getTime() ){ + return true; + } + } + else { + if( this.timeSpan.start.getTime() >= minTime.getTime() && this.timeSpan.start.getTime() <= maxTime.getTime() ){ + return true; + } + if( this.timeSpan.end.getTime() >= minTime.getTime() && this.timeSpan.end.getTime() <= maxTime.getTime() ){ + return true; + } + } + return false; + }, + + /** + * sets the object to a hover selection status + * @param {boolean} hover bool value that tells if an object is hovered or not + */ + setHover: function(hover){ + this.hoverSelect = hover; + if( this.percentage != 1 ){ + this.status = true; + } + }, + + /** + * return the string representation of the objects time + * @return the string representation of the objects time + */ + getTimeString: function(){ + if( this.timeStamp != undefined ){ + return SimileAjax.DateTime.getTimeString(this.granularity,this.timeStamp)+""; + } + else { + return ( SimileAjax.DateTime.getTimeString(this.granularity,this.timeSpan.start)+" - "+SimileAjax.DateTime.getTimeString(this.granularity,this.timeSpan.end)); + } + }, + + isSelected: function(){ + if( this.percentage > 0 || this.hoverSelect ){ + return true; + } + return false; + }, + + setPlaces: function(place){ + this.placeDetail = place.split("/"); + this.place = ""; + for( var i=0; i<this.placeDetail.length; i++ ){ + if( i>0 ){ + this.place += ", "; + } + this.place += this.placeDetail[i]; + } + }, + + getPlace: function(level){ + if( level >= this.placeDetail.length ){ + return this.placeDetail[this.placeDetail.length-1]; + } + return this.placeDetail[level]; + } + +};