From 54c040385065ff8863f9bbe5f66780eaca894ef1 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Sun, 14 May 2006 02:44:49 +0000 Subject: [PATCH] add LayerSwitcher control. Currently, when added, this will simply loop through all the map layers, display a div (with text in it) which allows you tu turn the layer on or off. Layer visibility is a new concept in Layer.js, including a getter and setter, which uses the style.visibility prop to change the status of the layer. git-svn-id: http://svn.openlayers.org/trunk/openlayers@31 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- example.html | 1 + google.html | 1 + lib/OpenLayers.js | 3 +- lib/OpenLayers/Control/LayerSwitcher.js | 41 +++++++++++++++++++++++++ lib/OpenLayers/Layer.js | 15 +++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 lib/OpenLayers/Control/LayerSwitcher.js diff --git a/example.html b/example.html index 1834c7ef2e..02439724ef 100644 --- a/example.html +++ b/example.html @@ -24,6 +24,7 @@ {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'} ); map.addLayer(layer); + map.addControl( new OpenLayers.Control.LayerSwitcher() ); map.setCenter(new OpenLayers.LatLon(lat, lon), zoom); } // --> diff --git a/google.html b/google.html index b85048cc3e..9e9a12c3af 100644 --- a/google.html +++ b/google.html @@ -29,6 +29,7 @@ map.setCenter(new OpenLayers.LatLon(lat, lon), zoom); map.addLayer(layer); map.addLayer(gmap); + map.addControl( new OpenLayers.Control.LayerSwitcher() ); } // --> diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index ecdd363d7a..4f015b563c 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -45,7 +45,8 @@ catch(e){ "OpenLayers/Layer/Grid.js", "OpenLayers/Layer/WMS.js", "OpenLayers/Control.js", - "OpenLayers/Control/PanZoom.js" + "OpenLayers/Control/PanZoom.js", + "OpenLayers/Control/LayerSwitcher.js" ); // etc. var allScriptTags = ""; diff --git a/lib/OpenLayers/Control/LayerSwitcher.js b/lib/OpenLayers/Control/LayerSwitcher.js new file mode 100644 index 0000000000..273c795d7b --- /dev/null +++ b/lib/OpenLayers/Control/LayerSwitcher.js @@ -0,0 +1,41 @@ +OpenLayers.Control.LayerSwitcher = Class.create(); +OpenLayers.Control.LayerSwitcher.prototype = + Object.extend( new OpenLayers.Control(), { + initialize: function() { + OpenLayers.Control.prototype.initialize.apply(this, arguments); + }, + + draw: function() { + // initialize our internal div + OpenLayers.Control.prototype.draw.apply(this); + var pixel = new OpenLayers.Pixel(this.map.div.clientWidth-200,4); + for(i=0; i