push constant variables out of the class, make them static. other small coding standards changes.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@79 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -2,16 +2,25 @@
|
||||
* @class
|
||||
*/
|
||||
OpenLayers.Control.LayerSwitcher = Class.create();
|
||||
|
||||
/** color used in the UI to show a layer is active/displayed
|
||||
*
|
||||
* @final
|
||||
* @type String
|
||||
*/
|
||||
OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR = "darkblue";
|
||||
|
||||
/** color used in the UI to show a layer is deactivated/hidden
|
||||
*
|
||||
* @final
|
||||
* @type String
|
||||
*/
|
||||
OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR = "lightblue";
|
||||
|
||||
|
||||
OpenLayers.Control.LayerSwitcher.prototype =
|
||||
Object.extend( new OpenLayers.Control(), {
|
||||
|
||||
/** color used in the UI to show a layer is active/displayed
|
||||
* @type String */
|
||||
ACTIVE_COLOR: "darkblue",
|
||||
|
||||
/** color used in the UI to show a layer is deactivated/hidden
|
||||
* @type String */
|
||||
NONACTIVE_COLOR: "lightblue",
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
@@ -21,6 +30,7 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns A reference to the DIV DOMElement containing the switcher tabs
|
||||
* @type DOMElement
|
||||
*/
|
||||
draw: function() {
|
||||
@@ -31,6 +41,7 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns A reference to the DIV DOMElement containing the switcher tabs
|
||||
* @type DOMElement
|
||||
*/
|
||||
redraw: function() {
|
||||
@@ -44,17 +55,24 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
||||
new OpenLayers.Size(200, 20));
|
||||
|
||||
div.innerHTML = this.map.layers[i].name;
|
||||
var status = this.map.layers[i].getVisibility();
|
||||
if (!status) {
|
||||
div.style.backgroundColor = this.NONACTIVE_COLOR;
|
||||
div.style.color = this.ACTIVE_COLOR;
|
||||
var visible = this.map.layers[i].getVisibility();
|
||||
if (!visible) {
|
||||
div.style.backgroundColor =
|
||||
OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR;
|
||||
div.style.color =
|
||||
OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR;
|
||||
} else {
|
||||
div.style.backgroundColor = this.ACTIVE_COLOR;
|
||||
div.style.color = this.NONACTIVE_COLOR;
|
||||
div.style.backgroundColor =
|
||||
OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR;
|
||||
div.style.color =
|
||||
OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR;
|
||||
}
|
||||
div.style.padding = "5px";
|
||||
|
||||
//tag references onto the div for use in event handlers
|
||||
div.layerid = i;
|
||||
div.map = this.map;
|
||||
|
||||
div.ondblclick = this.doubleClick.bindAsEventListener(div);
|
||||
div.onmousedown = this.singleClick.bindAsEventListener(div);
|
||||
}
|
||||
@@ -68,15 +86,19 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
||||
* @param {event} evt
|
||||
*/
|
||||
singleClick: function(evt) {
|
||||
var status = this.map.layers[this.layerid].getVisibility();
|
||||
this.map.layers[this.layerid].setVisibility(!status);
|
||||
if (status) {
|
||||
this.style.backgroundColor = this.NONACTIVE_COLOR;
|
||||
this.style.color = this.ACTIVE_COLOR;
|
||||
var visible = this.map.layers[this.layerid].getVisibility();
|
||||
if (visible) {
|
||||
this.style.backgroundColor =
|
||||
OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR;
|
||||
this.style.color =
|
||||
OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR;
|
||||
} else {
|
||||
this.style.backgroundColor = this.ACTIVE_COLOR;
|
||||
this.style.color = this.NONACTIVE_COLOR;
|
||||
this.style.backgroundColor =
|
||||
OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR;
|
||||
this.style.color =
|
||||
OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR;
|
||||
}
|
||||
this.map.layers[this.layerid].setVisibility(!visible);
|
||||
Event.stop(evt);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user