Repost: [Geoserver-users] LayerSwitcher() not working

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Repost: [Geoserver-users] LayerSwitcher() not working

dushan

Hi,
I'm using 5 layers and passing random values to VIEWPARAMS to select the wanted area. I added a layer switcher(mentioned in red at the bottom of the script) to show/hide layers. but switch layer component doesn't appear on openlayers map viewer. Please be kind to respond. need help.

Regards.

<script src="wms_files/OpenLayers.js" type="text/javascript"></script>
<script defer="defer" type="text/javascript">
var legs = "<%= geoParam %>";
var layer_one_legs = "<%= geoParamLayerOne %>";
var layer_two_legs = "<%= geoParamLayerTwo %>";
var layer_three_legs = "<%= geoParamLayerThree %>";
var layer_four_legs = "<%= geoParamLayerFour %>";
var layer_four_five = "<%= geoParamLayerFive %>";

var map;
var base;

var layer_one;
var layer_two;
var layer_three;
var layer_four;
var layer_five;

/* pink tile avoidance */
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 5;
/* make OL compute scale according to WMS spec */
OpenLayers.DOTS_PER_INCH = 25.4 / 0.28;

function init() {

format = 'image/png';
var bounds = new OpenLayers.Bounds(
                    97057.023,
                    174768.406,
                    118472.391,
                    192859.141);
var options = {
                    controls : [],
                    maxExtent : bounds,
                    maxResolution : 83.65378125000001,
                    projection : "EPSG:2020",
                    units : 'm'
};
map = new OpenLayers.Map('map', options);
/* setup base layer */
base = new OpenLayers.Layer.WMS(
"Base",
"http://localhost:8080/geoserver/wms",
{
LAYERS : 'rda2',
transparent: "true",
singleTile: true,
format : format
},
{
buffer : 0,
isBaseLayer : true,
displayInLayerSwitcher:false
});
/* setup layer_one */
layer_one = new OpenLayers.Layer.WMS(
"Layer 01",
"http://localhost:8080/geoserver/wms",
{
VIEWPARAMS: layer_one_legs,
LAYERS : 'RDA2_VIEW_LAYER_ONE',
transparent: "true",
singleTile: true,
format : format
},
{
buffer : 0,
isBaseLayer : false,
displayInLayerSwitcher:true
});
/* setup layer_two */
layer_two = new OpenLayers.Layer.WMS(
"Layer 02",
"http://localhost:8080/geoserver/wms",
{
VIEWPARAMS: layer_two_legs,
LAYERS : 'RDA2_VIEW_LAYER_TWO',
transparent: "true",
singleTile: true,
format : format
},
{
buffer : 0,
isBaseLayer : false,
displayInLayerSwitcher:true
});
/* setup layer_three */
layer_three = new OpenLayers.Layer.WMS(
"Layer 03",
"http://localhost:8080/geoserver/wms",
{
VIEWPARAMS: layer_three_legs,
LAYERS : 'RDA2_VIEW_LAYER_THREE',
transparent: "true",
singleTile: true,
format : format
},
{
buffer : 0,
isBaseLayer : false,
displayInLayerSwitcher:true
});
/* setup layer_four */
layer_four = new OpenLayers.Layer.WMS(
"Layer 04",
"http://localhost:8080/geoserver/wms",
{
VIEWPARAMS: layer_four_legs,
LAYERS : 'RDA2_VIEW_LAYER_FOUR',
transparent: "true",
singleTile: true,
format : format
},
{
buffer : 0,
isBaseLayer : false,
displayInLayerSwitcher:true
});
/* setup layer_five */
layer_five = new OpenLayers.Layer.WMS(
"Layer 05",
"http://localhost:8080/geoserver/wms",
{
VIEWPARAMS: layer_four_five,
LAYERS : 'RDA2_VIEW_LAYER_FIVE',
transparent: "true",
singleTile: true,
format : format
},
{
buffer : 0,
isBaseLayer : false,
displayInLayerSwitcher:true
});
/* map.addLayers([untiled, tiled ]); */
map.addLayers([base, layer_five, layer_four, layer_three, layer_two, layer_one]);

/* build up all controls */
map.addControl(new OpenLayers.Control.PanZoomBar(
{
position : new OpenLayers.Pixel(2,15)
}));
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToExtent(bounds);
}
</script>

--
Me on Web
http://dushan888.wordpress.com

_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: Repost: [Geoserver-users] LayerSwitcher() not working

Steffen G
try:

map.addControl(new OpenLayers.Control.PanZoomBar({
    position : new OpenLayers.Pixel(2,15)
}));
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToExtent(bounds);

Your last bracket is wrong.
Reply | Threaded
Open this post in threaded view
|

Re: Repost: [Geoserver-users] LayerSwitcher() not working

dushan
Thank you for replying. I still cant see the difference of your code and mine (the wrong bracket). Anyways I replaced your code with mine. but its still the same. Please help.
Regards.
Reply | Threaded
Open this post in threaded view
|

Re: Repost: [Geoserver-users] LayerSwitcher() not working

Claudio V.
Do you get any console errors? It could be that it's been displayed below the map or other component. You could also inform where you want it to be rendered with:
    map.addControl(new OpenLayers.Control.LayerSwitcher({'div': document.getElementById("myDiv")}));


2013/7/10 dushan <[hidden email]>
Thank you for replying. I still cant see the difference of your code and mine
(the wrong bracket). Anyways I replaced your code with mine. but its still
the same. Please help.
Regards.



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Repost-Geoserver-users-LayerSwitcher-not-working-tp5065279p5065391.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users


_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users