Source: temp/jsdocinputdirs/cercalia.simplelabel.js

/**
 * @class cercalia.SimpleLabel
 * @constructor
 * @param {cercaliax.SimpleLabelOptions} options Marker options
 */
cercalia.SimpleLabel = function(options) {
	
	/**
	 * Class name
	 * @private
	 * @type {string}
	 */
	this.CLASS_NAME_ = "cercalia.SimpleLabel";

	/**
	 * @private
	 * @type {string}
	 */
	this.text_ = options.text ? options.text : 'SimpleLabel?';
	
	/**
	 * This property is used to store the text if it's hidden
	 * @private
	 * @type {string}
	 */
	this.textAux_ = this.text_;
	
	/**
	 * @private
	 * @type {boolean}
	 */	
	this.visible_ = options.visible||options.visible==0 ? options.visible : true;
	
	/**
	 * @private
	 * @type {string}
	 */
	this.fontFamily_ = options.fontFamily ? options.fontFamily : 'Tahoma';

	/**
	 * @private
	 * @type {string} 
	 */
	this.fontBold_ = options.fontBold||options.fontBold==0 ? 'bold' : 'normal';
	
	/**
	 * @private
	 * @type {string}
	 */
	this.fontSize_ = options.fontSize ? options.fontSize +'px' : '11px';

	
	/**
	 * @private
	 * @type {number}
	 */
	this.offsetX_ = options.offsetX ? options.offsetX : 0;
	
	/**
	 * @private
	 * @type {number}
	 */
	this.offsetY_ = options.offsetY ? options.offsetY : 0;
	
	/**
	 * @private
	 * @type {string}
	 */
	this.fillColor_ = options.color ? options.color : '#000000';
	
	/**
	 * @private
	 * @type {string}
	 */
	this.strokeColor_ = options.strokeColor ? options.strokeColor : '#ffffff';
	
	/**
	 * @private
	 * @type {string}
	 */
	this.strokeWidth_ = options.strokeWidth ? options.strokeWidth : 3; 
	
	/**
	 * @private
	 * @type {string}
	 */
	this.rotation_ = options.rotation ? Math.PI * options.rotation/180 : 0;
	
	/**
	 * @private
	 * @type {cercalia.Marker}
	 */
	this.feature_ = null;
	
	//Una vez inicializadas las variables asignamos el estilo
	this.setTextStyle_();

	if(!this.visible_){
		this.setVisible(false);
	}
	
};

/**
 * We update the marker if it's used
 * @private
 */
cercalia.SimpleLabel.prototype.updateOnFeature_ = function(){
	if(this.feature_){
		this.feature_.setSimpleLabel(this);
	}
};



/**
 * Assigns styles
 * @private
 */
cercalia.SimpleLabel.prototype.setTextStyle_ = function(){
	
	var font = this.fontBold_ + ' ' + this.fontSize_ + ' ' + this.fontFamily_;

	var options = {
		text: this.text_,
		font: font,
		offsetX: this.offsetX_,
		offsetY: this.offsetY_,
	    fill: new ol.style.Fill({color: this.fillColor_}),
	    stroke: new ol.style.Stroke({color: this.strokeColor_, width: this.strokeWidth_}),
	    rotation: this.rotation_
	};
	
	this.textStyle_ = new ol.style.Text(options);
};


/**
 * @return {ol.style.Text}
 */
cercalia.SimpleLabel.prototype.getTextStyle = function(){
	return this.textStyle_;
};

/**
 * Change the text passed by parameter. If have an assigned marker updates it
 * @param {string} text
 */
cercalia.SimpleLabel.prototype.setText = function(text){
	this.text_= text;
	this.textAux_ = text;
	this.setTextStyle_();
	this.updateOnFeature_();
};

/**
 * Returns the text
 * @return {string}
 */
cercalia.SimpleLabel.prototype.getText = function(){
	return this.text_;
};

/**
 * Returns the textAux
 * @return {string}
 */
cercalia.SimpleLabel.prototype.getTextAux = function(){
	return this.textAux_;
};

/**
 * Change the text passed by parameter. If have an assigned marker updates it
 * @param {string} fontFamily
 */
cercalia.SimpleLabel.prototype.setFontFamily = function(fontFamily){
	this.fontFamily_ = fontFamily;
	this.setTextStyle_();
	this.updateOnFeature_();
};

/**
 * Returns text font
 * @return {string}
 */
cercalia.SimpleLabel.prototype.getFontFamily = function(){
	return this.fontFamily_;
};

/**
 * Change the text passed by parameter. If have an assigned marker updates it
 * @param {boolean} fontBold
 */
cercalia.SimpleLabel.prototype.setFontBold = function(fontBold){
	this.fontBold_ = fontBold ? 'bold' : 'normal';
	this.setTextStyle_();
	this.updateOnFeature_();
};

/**
 * @return {boolean}
 */
cercalia.SimpleLabel.prototype.isFontBold = function(){
	return this.fontBold_=='bold';
};


/**
 * Change the text size in pixels. If have an assigned marker updates it
 * @param {number} fontSize
 */
cercalia.SimpleLabel.prototype.setFontSize = function(fontSize){
	this.fontSize_ = fontSize + "px";
	this.setTextStyle_();
	this.updateOnFeature_();
};


/**
 * Returns text font
 * @return {number}
 */
cercalia.SimpleLabel.prototype.getFontSize = function(){
	return parseInt(this.fontSize_.replace("px",""));
};


/**
 * Change displacement on the horizontal axis. If have an assigned marker updates it
 * @param {number} offsetX
 */
cercalia.SimpleLabel.prototype.setOffsetX = function(offsetX){
	this.offsetX_ = offsetX;
	this.setTextStyle_();
	this.updateOnFeature_();
};

/**
 * Returns displacement on the horizontal axis
 * @return {number}
 */
cercalia.SimpleLabel.prototype.getOffsetX = function(){
	return this.offsetX_;
};

/**
 * Change displacement on the vertical axis. If have an assigned marker updates it
 * @param {number} offsetY
 */
cercalia.SimpleLabel.prototype.setOffsetY = function(offsetY){
	this.offsetY_ = offsetY;
	this.setTextStyle_();
	this.updateOnFeature_();
};

/**
 * Returns displacement on the vertical axis
 * @return {number}
 */
cercalia.SimpleLabel.prototype.getOffsetY = function(){
	return this.offsetY_;
};

/**
 * Change text color. If have an assigned marker updates it
 * @param {string} fillColor
 */
cercalia.SimpleLabel.prototype.setFillColor = function(fillColor){
	this.fillColor_ = fillColor;
	this.setTextStyle_();
	this.updateOnFeature_();
};

/**
 * Returns displacement on the vertical axis
 * @return {number}
 */
cercalia.SimpleLabel.prototype.getFillColor = function(){
	return this.fillColor_;
};

/**
 * Change outline color. If have an assigned marker updates it
 * @param {string} strokeColor
 */
cercalia.SimpleLabel.prototype.setStrokeColor = function(strokeColor){
	this.strokeColor_ = strokeColor;
	this.setTextStyle_();
	this.updateOnFeature_();
};

/**
 * Returns outline color
 * @return {number}
 */
cercalia.SimpleLabel.prototype.getStrokeColor = function(){
	return this.strokeColor_;
};

/**
 * Change outline widht. If null, sets 0 value. If have an assigned marker updates it
 * @param {string} strokeWidth
 */
cercalia.SimpleLabel.prototype.setStrokeWidth = function(strokeWidth){
	this.strokeWidth_ = strokeWidth;
	this.setTextStyle_();
	this.updateOnFeature_();
};

/**
 * Devuelve la anchura del contorno
 * @return {number}
 */
cercalia.SimpleLabel.prototype.getStrokeWidth = function(){
	return this.strokeWidth_;
};

/**
 * Change the text passed by parameter. If have an assigned marker updates it
 * @param {number} rotation
 */
cercalia.SimpleLabel.prototype.setRotation = function(rotation){
	this.rotation_ = Math.PI * rotation/180;
	this.setTextStyle_();
	this.updateOnFeature_();
};

/**
 * Returns SimpleLabel rotation
 * @return {number}
 */
cercalia.SimpleLabel.prototype.getRotation = function(){
	return this.rotation_;
};


/**
 * @return {boolean} visible Returns if SimpleLabel is visible
 */
cercalia.SimpleLabel.prototype.isVisible = function(){
	return this.visible_;
};

/**
 * Show / hide label
 * @param {boolean} visible
 */
cercalia.SimpleLabel.prototype.setVisible = function(visible){
	this.visible_ = visible;
	if(visible){
		this.text_ = this.textAux_;
	} else {
		this.text_ = '';
	}
	
	this.setTextStyle_();
	this.updateOnFeature_();
};


/**
 * Assign a marker to this SimpleLabel
 * @param {cercalia.Marker} marker
 */
cercalia.SimpleLabel.prototype.setMarker = function(marker){
	this.feature_ = marker;
};


/**
 * Assign a marker to this SimpleLabel
 * @param {cercalia.Feature} feature
 */
cercalia.SimpleLabel.prototype.setFeature = function(feature){
	this.feature_ = feature;
};

/**
 * Destroy object
 */
cercalia.SimpleLabel.prototype.destroy = function(){
	for (var key in this) {
		delete this[key];
	}
};

/**
* Returns the object type.
* @return {string}
*/
cercalia.SimpleLabel.prototype.getClass = function(){
	return this.CLASS_NAME_;
};