[OpenLayers-Users] Cannot set layer visibility...

Christopher Schmidt crschmidt at metacarta.com
Wed Nov 19 10:40:15 EST 2008


On Wed, Nov 19, 2008 at 07:35:54AM -0800, Maps-R-us wrote:
> 
> I have three custom Google Maps tile layers in my project.  The setVisibility
> method does not seem to work for these types of layers.  Does this make
> sense?  Here is my source code:
> 
> map = new OpenLayers.Map('map',options);
> map.events.register("moveend", null, mapEvent);
> map.events.register("changelayer", null, mapLayerChanged);
> map.addControl(new OpenLayers.Control.LayerSwitcher());

All three of the following layers are baselayers. To pick a layer
between baselayers (which are mutually exclusive) you must call
map.setBaseLayer(layer) -- setVisibility will not help you.

-- CHris

> var mylayer3 = new OpenLayers.Layer.TMS(
> "Third Floor", "http://www.myurl.com.com//officeplans//3rd/Z", {
> 'type':'png', 'sphericalMercator': true, 'getURL':get_my_url });
> 					
> var mylayer2 = new OpenLayers.Layer.TMS(
> "Second Floor", "http://www.myurl.com//officeplans//2nd/Z", { 'type':'png',
> 'sphericalMercator': true, 'getURL':get_my_url });
> 			
> var mylayer1 = new OpenLayers.Layer.TMS(
> "First Floor", "http://www.myurl.com//officeplans//1st/Z", { 'type':'png',
> 'sphericalMercator': true, 'getURL':get_my_url });
> 			
> map.addLayers([mylayer1, mylayer2, mylayer3]);
> 
> switch (office) {
>     
> case "Testing": if (floor==1){
> alert("Floor 1 on");
> var lonLat = new OpenLayers.LonLat(latitude, longitude) ;
> lonLat.transform(map.displayProjection,map.getProjectionObject());
> mylayer1.setVisibility(true);
> mylayer2.setVisibility(false);
> mylayer3.setVisibility(false);
> map.setCenter(lonLat, 18);
> newfloor = floor; 
> break; 
> }  else if (floor==2) {
> alert("Floor 2 on");
> var lonLat = new OpenLayers.LonLat(latitude, longitude) ;
> lonLat.transform(map.displayProjection,map.getProjectionObject());
> mylayer1.setVisibility(false);
> mylayer3.setVisibility(false);
> mylayer2.setVisibility(true);
> map.setCenter(lonLat, 18);
> newfloor = floor; 
> break;
> }  else {
> alert("Floor 3 on");
> var lonLat = new OpenLayers.LonLat(latitude, longitude) ;
> lonLat.transform(map.displayProjection,map.getProjectionObject());
> mylayer1.setVisibility(false);
> mylayer3.setVisibility(true);
> mylayer3.setVisibility(false);
> map.setCenter(lonLat, 18);
> newfloor = floor; 
> break;	 
> }	 
> 
> Thanks in advance!
> 
> M
> -- 
> View this message in context: http://www.nabble.com/Cannot-set-layer-visibility...-tp20582359p20582359.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users

-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list