[OpenLayers-Users] change legend via layerswitcher selection

Maria Panagou snowdrop at ath.forthnet.gr
Sun Feb 10 10:40:51 EST 2008


Hi, I resolved a similar situation using the following code


map.events.register("changebaselayer",population per sq mile(2005),
function() {
		   if (this.getVisibility()) {
			 
document.getElementById('legend').src="http://optiplexa.mtri.org:8086/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=mtri:v_quality_crosstab&STYLE=polygon_eqi_colormap";
			  } else
			  {
			  document.getElementById('legend').src="";
			  }
			   });	   


and later in html code...
set the source of your image to src=

this means at first when layer isn't selected source of image is empty
(src=) and when the users chooses this layer from Layerswitcher,
"changebaselayer" event is triggered, which which gives the source it's
value.

In the case that your layer is overlay and not baselayer you can use the
event "visibilitychanged" on your layer i.e

population per sq mile(2005).events.register("visibilitychanged",macros,
function() {
		      if (this.getVisibility()) {
			 
document.getElementById('legend').src="http://optiplexa.mtri.org:8086/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=mtri:v_quality_crosstab&STYLE=polygon_eqi_colormap";
			  } else
			  {
			  document.getElementById('legend').src="";
			  }
			   });	   


Hope I helped !

Maria 



Keefauver wrote:
> 
> My javascript is rather rusty but is there a way to change a legend
> graphic dynamically (in this case an image tag below that receives its
> image via the GetLegendGraphic request) based on the layer selection
> within the layerswitcher? More succinctly put, a user selects a layer
> named "population per sq mile(2005)" the legend changes respectively.
> 
> 
> http://optiplexa.mtri.org:8086/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=mtri:v_quality_crosstab&STYLE=polygon_eqi_colormap 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/change-legend-via-layerswitcher-selection-tp15362040p15397357.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list