1 /***************************************
  2  * Copyright 2011, 2012 GlobWeb contributors.
  3  *
  4  * This file is part of GlobWeb.
  5  *
  6  * GlobWeb is free software: you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as published by
  8  * the Free Software Foundation, version 3 of the License, or
  9  * (at your option) any later version.
 10  *
 11  * GlobWeb is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14  * GNU Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU General Public License
 17  * along with GlobWeb. If not, see <http://www.gnu.org/licenses/>.
 18  ***************************************/
 19 
 20  define( function() {
 21  
 22 /**************************************************************************************************************/
 23 
 24 
 25 /** @name BaseLayer
 26 	@class
 27 	Base class for layer.
 28 	@param options Configuration properties for a BaseLayer:
 29 		<ul>
 30 			<li>name : the layer name</li>
 31 			<li>description :  its description</li>
 32 			<li>attribution : its attribution</li>
 33 			<li>icon : an icon to represent the layer</li>
 34 			<li>visible : a boolean flag to set the layer visible, default is true </li>
 35 			<li>opacity : an oapcity value, default is 1.0</li>
 36 		</ul>
 37  */
 38 var BaseLayer = function(options)
 39 {
 40 	this.globe = null;
 41 	this.name = options && options.hasOwnProperty('name') ? options['name'] : "";
 42 	this.attribution = options && options.hasOwnProperty('attribution') ? options['attribution'] : "";
 43 	this.icon = options && options.hasOwnProperty('icon') ? options['icon'] : "";
 44 	this.description = options && options.hasOwnProperty('description') ? options['description'] : "";
 45 	this._visible = options && options.hasOwnProperty('visible') ? options['visible'] : true;
 46 	this._opacity = options && options.hasOwnProperty('opacity') ? options['opacity'] : 1.0;
 47 }
 48 
 49 /**************************************************************************************************************/
 50 
 51 /** 
 52   Attach the raster layer to the globe
 53  */
 54 BaseLayer.prototype._attach = function( g )
 55 {
 56 	this.globe = g;
 57 	if ( this.attribution && this.globe.attributionHandler )
 58 	{
 59 		this.globe.attributionHandler.addAttribution(this);
 60 	}
 61 }
 62 
 63 /**************************************************************************************************************/
 64 
 65 /** 
 66   Detach the vector layer from the globe
 67  */
 68 BaseLayer.prototype._detach = function()
 69 {
 70 	if ( this.attribution && this.globe.attributionHandler )
 71 	{
 72 		this.globe.attributionHandler.removeAttribution(this);
 73 	}
 74 	
 75 	this.globe = null;
 76 }
 77 
 78 /**************************************************************************************************************/
 79 
 80 /**
 81   Get/Set the layer visible
 82  */
 83 BaseLayer.prototype.visible = function( arg )
 84 {
 85 	if ( typeof arg == "boolean" )
 86 	{
 87 		this._visible = arg;
 88 		if ( this.globe ) this.globe.renderContext.requestFrame();
 89 	}
 90 	return this._visible;
 91 }
 92 
 93 /**************************************************************************************************************/
 94 
 95 /**
 96   Get/Set the opacity of the layer
 97  */
 98 BaseLayer.prototype.opacity = function( arg )
 99 {
100 	if ( typeof arg == "number" )
101 	{
102 		this._opacity = arg;
103 		if ( this.globe ) this.globe.renderContext.requestFrame();
104 	}
105 	return this._opacity;
106 }
107 
108 return BaseLayer;
109 
110 });
111