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
|
* @class
|
||||||
*/
|
*/
|
||||||
OpenLayers.Control.LayerSwitcher = Class.create();
|
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 =
|
OpenLayers.Control.LayerSwitcher.prototype =
|
||||||
Object.extend( new OpenLayers.Control(), {
|
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
|
* @constructor
|
||||||
@@ -21,6 +30,7 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @returns A reference to the DIV DOMElement containing the switcher tabs
|
||||||
* @type DOMElement
|
* @type DOMElement
|
||||||
*/
|
*/
|
||||||
draw: function() {
|
draw: function() {
|
||||||
@@ -31,6 +41,7 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @returns A reference to the DIV DOMElement containing the switcher tabs
|
||||||
* @type DOMElement
|
* @type DOMElement
|
||||||
*/
|
*/
|
||||||
redraw: function() {
|
redraw: function() {
|
||||||
@@ -44,17 +55,24 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
|||||||
new OpenLayers.Size(200, 20));
|
new OpenLayers.Size(200, 20));
|
||||||
|
|
||||||
div.innerHTML = this.map.layers[i].name;
|
div.innerHTML = this.map.layers[i].name;
|
||||||
var status = this.map.layers[i].getVisibility();
|
var visible = this.map.layers[i].getVisibility();
|
||||||
if (!status) {
|
if (!visible) {
|
||||||
div.style.backgroundColor = this.NONACTIVE_COLOR;
|
div.style.backgroundColor =
|
||||||
div.style.color = this.ACTIVE_COLOR;
|
OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR;
|
||||||
|
div.style.color =
|
||||||
|
OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR;
|
||||||
} else {
|
} else {
|
||||||
div.style.backgroundColor = this.ACTIVE_COLOR;
|
div.style.backgroundColor =
|
||||||
div.style.color = this.NONACTIVE_COLOR;
|
OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR;
|
||||||
|
div.style.color =
|
||||||
|
OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR;
|
||||||
}
|
}
|
||||||
div.style.padding = "5px";
|
div.style.padding = "5px";
|
||||||
|
|
||||||
|
//tag references onto the div for use in event handlers
|
||||||
div.layerid = i;
|
div.layerid = i;
|
||||||
div.map = this.map;
|
div.map = this.map;
|
||||||
|
|
||||||
div.ondblclick = this.doubleClick.bindAsEventListener(div);
|
div.ondblclick = this.doubleClick.bindAsEventListener(div);
|
||||||
div.onmousedown = this.singleClick.bindAsEventListener(div);
|
div.onmousedown = this.singleClick.bindAsEventListener(div);
|
||||||
}
|
}
|
||||||
@@ -68,15 +86,19 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
|||||||
* @param {event} evt
|
* @param {event} evt
|
||||||
*/
|
*/
|
||||||
singleClick: function(evt) {
|
singleClick: function(evt) {
|
||||||
var status = this.map.layers[this.layerid].getVisibility();
|
var visible = this.map.layers[this.layerid].getVisibility();
|
||||||
this.map.layers[this.layerid].setVisibility(!status);
|
if (visible) {
|
||||||
if (status) {
|
this.style.backgroundColor =
|
||||||
this.style.backgroundColor = this.NONACTIVE_COLOR;
|
OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR;
|
||||||
this.style.color = this.ACTIVE_COLOR;
|
this.style.color =
|
||||||
|
OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR;
|
||||||
} else {
|
} else {
|
||||||
this.style.backgroundColor = this.ACTIVE_COLOR;
|
this.style.backgroundColor =
|
||||||
this.style.color = this.NONACTIVE_COLOR;
|
OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR;
|
||||||
|
this.style.color =
|
||||||
|
OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR;
|
||||||
}
|
}
|
||||||
|
this.map.layers[this.layerid].setVisibility(!visible);
|
||||||
Event.stop(evt);
|
Event.stop(evt);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user