Source: temp/jsdocinputdirs/cercalia.linestring.js

/**
 * @classdesc
 *
 * LineString Calss. This class lets you create a LineString on the map, with a defined style.
 * 
 * 
 * @constructor
 * @param {cercaliax.LinestringOptions} options Opciones del label
 */
cercalia.Linestring = function(options) {

	/**
	 * Class name
	 * @private
	 * @type {string}
	 */
	this.CLASS_NAME_ = "cercalia.Linestring";
	
	/**
     * @private
     * @type {string}
     */
    this.id_ = options.id ? options.id : 'CercaliaLinestring_id_' + Date.now() + (Math.random()*0xffffffff|0);

	/**
	 * @private
	 * @type {Array.<cercalia.LonLat>}
	 */
	this.path_ = options.path ? options.path : [];
	
	/**
	 * @private
	 * @type {Array.<ol.Coord>} 
	 */
	this.pathMap_ = this.getTransformedPath_(this.path_);
	
	/**
	 * @private
	 * @type {string}
	 */
	this.strokeColor_ = options.strokeColor ? options.strokeColor : '#00ff00'; 
	
	/**
	 * @private
	 * @type {number}
	 */
	this.strokeOpacity_ = options.strokeOpacity ? options.strokeOpacity : 0.75; 
	
	/**
	 * @private
	 * @type {number}
	 */
	this.strokeWidth_ = options.strokeWidth ? options.strokeWidth : 5; 

	/**
	 * @private
	 * @type {number}
	 */
	this.zIndex_ = options.zIndex ? options.zIndex : 100; 
	
	/**
	 * @private
	 * @type {boolean}
	 */
	this.draggable_ = options.draggable ? options.draggable : false;
	
	/**
	 * @private
	 * @type {ol.Feature}
	 */
	this.feature_ = null;

	
	this.setFeature_();
	
	/**
	 * @private
	 * @type {ol.style.Stroke}
	 */
	this.styleStroke_ = null;
	
	/**
	 * @private
	 * @type {ol.style.Style}
	 */
	this.style_ = null;
	
	/**
	 * @private
	 * @type {cercalia.Map}
	 */
	this.map_ = null;
	
	this.setStyle_();
	
	
	/**
	 * Hacemos que la feature del linestring sea ciclica. Para que des de la feature poder acceder a esta clase
	 * @type {cercalia.Linestring}
	 * @private
	 */
	this.feature_.linestring_ = this;
	
	/**
	 * @private
	 * @type {string}
	 */
	this.feature_.featureType_ = this.CLASS_NAME_;
	
};


/**
 * Transform path to ol.Coord array
 * @private
 * @param {Array.<cercalia.LonLat>} path
 * @return {Array.<ol.Coord>} pathMap
 */
cercalia.Linestring.prototype.getTransformedPath_ = function(path) {
	var length = path.length;
	var pathMap = new Array(length);
	var projectionCode = this.map_ ? this.map_.getProjectionCode() : 'EPSG:3857';
	for(var i = 0; i < length; i++){
		pathMap[i] = ol.proj.transform([path[i].getLon(), path[i].getLat()], 'EPSG:4326', projectionCode);
	}
	return pathMap;
};


/**
 * Create feature
 * @private
 */
cercalia.Linestring.prototype.setFeature_ = function(){
		
	/**
	 * Create feature
	 * @type {ol.Feature}
	 * @private
	 */
	this.feature_ = new ol.Feature({
		geometry: new ol.geom.LineString(this.pathMap_)
	});
	this.feature_.setId(this.id_);
	
};

/**
 * @return {ol.Feature} Objeto OpenLayers3 <a href="http://openlayers.org/en/v3.0.0/apidoc/ol.Feature.html">`ol.Feature`</a>
 */
cercalia.Linestring.prototype.getFeature = function(){
	return this.feature_;
};


/**
 * @param {boolean} draggable
 */
cercalia.Linestring.prototype.setDraggable = function(draggable){
	this.draggable_ = draggable;
};

/**
 * @return {boolean} If feature is draggable or not. Values `true` o `false`.
 */
cercalia.Linestring.prototype.isDraggable = function(){
	return this.draggable_;
};


/**
 * Change the zIndex
 * @param {number} zIndex
 */
cercalia.Linestring.prototype.setZIndex = function(zIndex){
	this.zIndex_ = zIndex;
	this.setStyle_();
};


/**
 * @return {number} CSS zIndex del Linestring
 */
cercalia.Linestring.prototype.getZIndex = function(){
	return this.zIndex_;
};

/**
 * Change the line color
 * @param {string} strokeColor
 */
cercalia.Linestring.prototype.setStrokeColor = function(strokeColor){
	this.strokeColor_ = strokeColor;
	this.setStyle_();
};

/**
 * @return {string} Current line color
 */
cercalia.Linestring.prototype.getStrokeColor = function(){
	return this.strokeColor_;
};

/**
 * Change the line opacity (0-1)
 * @param {number} strokeOpacity
 */
cercalia.Linestring.prototype.setStrokeOpacity = function(strokeOpacity){
	this.strokeOpacity_ = strokeOpacity;
	this.setStyle_();
};

/**
 * 
 * @return {number} Line opacity. Values between `[0..1]`
 */
cercalia.Linestring.prototype.getStrokeOpacity = function(){
	return this.strokeOpacity_;
};

/**
 * Change line width
 * @param {number} strokeWidth
 */
cercalia.Linestring.prototype.setStrokeWidth = function(strokeWidth){
	this.strokeWidth_ = strokeWidth;
	this.setStyle_();
};

/**
 * @return {number} line width.
 */
cercalia.Linestring.prototype.getStrokeWidth = function(){
	return this.strokeWidth_;
};


/**
 * Inicialize styles
 * @private
 */
cercalia.Linestring.prototype.setStyle_ = function() {	
	
	this.styleStroke_ = new ol.style.Stroke({
        color: cercalia.Util.transformColor2rgba(this.strokeColor_,this.strokeOpacity_),
        width: this.strokeWidth_
	});
	
	this.style_ = new ol.style.Style({
				stroke: this.styleStroke_,
				zIndex: this.zIndex_
	});

	this.feature_.setStyle(this.style_);	
};



/**
 * @param {cercalia.Map} map
 */
cercalia.Linestring.prototype.setMap = function(map){
	if(map){
		if(this.map_ == null){
			this.map_ = map;
		} else {
			alert('cercalia.linestring: Ya existía el Linestring');
		}
	} else {
		this.map_ = null;
	}
};

/**
 * Returns Linestring path
 * @return {Array.<cercalia.LonLat>} path
 */
cercalia.Linestring.prototype.getPath = function(){
	return this.path_;
};

/**
 * Change Linestring path sended by parameter
 * @param {Array.<cercalia.LonLat>} path
 */
cercalia.Linestring.prototype.setPath = function(path){
	this.path_ = path;
	this.pathMap_ = this.getTransformedPath_(this.path_);
	if(this.feature_){
		this.feature_.getGeometry().setCoordinates(this.pathMap_);
	} else {
		alert('Linestring sin feature creada!');
	}
};

/**
 * @return {cercalia.Bounds} LineString extension
 */
cercalia.Linestring.prototype.getBounds = function(){
	var extentOL = this.getFeature().getGeometry().getExtent();
	var projectionCode = this.map_ ? this.map_.getProjectionCode() : 'EPSG:3857';
	
	return new cercalia.Bounds(ol.proj.transformExtent(extentOL, projectionCode, 'EPSG:4326'));
};

/**
 *	Destroy the object and its atributes to clean up memory 
 */
cercalia.Linestring.prototype.destroy = function(){
	if(this.map_!=null){	
		this.map_.removeLinestrings(this);
		for (var key in this) {
			delete this[key];
		}
	}
};

/**
* @return {string} Object ClassName.
*/
cercalia.Linestring.prototype.getClass = function(){
	return this.CLASS_NAME_;
};