[OpenLayers-Users] baseLayers visibility question
cgp
carina_palanca at forcorp.com
Wed Sep 23 17:15:47 EDT 2009
Hi,
This is what I do, although there might be other ways to do this:
If you want to display/hide a base layer, use
this.map.setBaseLayer(layer_name,true||false);
If you want to display/hide an overlay, use
this.map.getLayersByName(layer_name)[0].setVisibility(true||false);
To get the name, just use the name that you assigned when you created the
layer and added it to the map. So if you added the Google layers like this:
var gphy = new OpenLayers.Layer.Google("Google
Physical",{type:G_PHYSICAL_MAP,sphericalMercator:true});
var vector1 = new OpenLayers.Layer.Vector("Sample Vector Layer");
map.addLayers([gphy, vector1]);
The name of the layer that you pass in would be "Google Physical", or
"Sample Vector Layer".
Hope this helps.
mikani wrote:
>
> Hi I have a map in a form, and am submitting the map, and depending the
> layer that's checked from layerswitcher, I'd like to display selected map
> after submit.
>
> Any idea how I can do this?
> I tried setVisibility(true) after submit, and think that can do the trick,
> but I'm having a hard time getting the BaseLayers info.
> By default, i see form submits "...&baseLayers=Google+Streets",
> is there a way i can grab baseLayer by name?
> Thank you for any help!
>
> my sample code:
> var selectedlayer = document.searchform.selectedlayer;
>
> if (baselayer.length > 0)
> {
> //map.setBaseLayer(selectedlayer[1]);
>
> layer.setVisibility(true);
> alert('baselayerlength: '+baselayer.length +'baselayer:
> '+baselayer[1].visibility);
> }
> else {alert("not found");}
>
>
--
View this message in context: http://n2.nabble.com/baseLayers-visibility-question-tp3700787p3702474.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list