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

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

Fwd: [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: Fwd: [Geoserver-users] LayerSwitcher() not working

adityakumar529
Hi Dushan,
   Have a try with adding just one layer.
map.addLayer(base);



Aditya Kumar
GIS Developer
Reply | Threaded
Open this post in threaded view
|

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

Chris-4
Hi,
I have tried with only OSM as base layer and my custom format.
Here is a temporary live script: http://www.naslain.com/tmp/gis/
Firebug shows the XML parsing with points info; then the array of layers; but no displayed marks.
Best,
Chris

On 18 July 2013 12:45, adityakumar529 <[hidden email]> wrote:
Hi Dushan,
   Have a try with adding just one layer.
map.addLayer(base);



Aditya Kumar




-----
GIS Developer
India Urban Space Foundation
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Fwd-Geoserver-users-LayerSwitcher-not-working-tp5064950p5067316.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
Reply | Threaded
Open this post in threaded view
|

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

Chris-4
Hi,
I have created a "live script" with my custom format class; so it is possible to have access to the javascript: http://www.naslain.com/tmp/gis/ Using firebug, the XML and the features array are visible.
Untill now, my problem still occurs. No displayed marks :-(
Anyone?
Best,
Chris

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

Re: Fwd: [Geoserver-users] LayerSwitcher() notworking

Arnd Wippermann
Hi Chris,
 
your only mistake is the use of the text parser.
 
var features  = txt.read(txtstr); //instead of features.push(...)
is the right way to get your features.
 
you have also correct these parts
the txtstr should have a header (you commented it)
the body should have the same column length as the header (your body have one column more)
and IE doesn't like commas after the last item of an object list (your example doesn't work with IE8):
new OpenLayers.Control.LayerSwitcher()
 
 
################
 
 var txt = new OpenLayers.Format.Text();
 
 var txtstr = "lat\tlon\ttitle\tdescription\ticonSize\ticonOffset\ticon\n";
 
 for ( i=0; i < spots.length ; i++)
 {
    var spot = spots[i];
    var spot_name = spot.getElementsByTagName("spot_name")[0].childNodes[0].nodeValue;
    var gps_lat = spot.getElementsByTagName("gps_lat")[0].childNodes[0].nodeValue;
    var gps_long = spot.getElementsByTagName("gps_long")[0].childNodes[0].nodeValue;
    var spot_geopath = spot.getElementsByTagName("spot_geopath")[0].childNodes[0].nodeValue;
 
    //txtstr += gps_lat + "\t" + gps_long + "\t" + spot_name + "\tDESC.TEST\t21,25\t21,25\t-10,-25\thttp://www.openlayers.org/dev/img/marker.png";
    txtstr += gps_lat + "\t" + gps_long + "\t" + spot_name + "\tDESC.TEST\t21,25\t-10,-25\thttp://www.openlayers.org/dev/img/marker.png\n";
 }
 
    console.log('DEBUG XML PARSER: \n' + txtstr);
 
    var features  = txt.read(txtstr);  //instead of features.push(...), the text parser returns an array of features
 console.log(features.length);
 return features;
 
    },
    CLASS_NAME: "OpenLayers.Format.MyTestWebservice"
 
################
 
if you build the xml file by yourself, i suggest, that you change <wannadive-id> to <wannadive>.
Then you can get your spots as a collection of elements:
 
var searchResults = this.getElementsByTagNameNS(data, "*", "search_result");
var spots = this.getElementsByTagNameNS(searchResults[0], "*", "wannadive");
...
 
var spot_id         = this.getElementsByTagNameNS(spots[i], "*", "spot_id")[0].firstChild.nodeValue;
 
Regards,
Arnd

Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Chris
Gesendet: Freitag, 19. Juli 2013 19:28
An: OpenLayers ML
Betreff: Re: [OpenLayers-Users] Fwd: [Geoserver-users] LayerSwitcher() notworking

Hi,
I have created a "live script" with my custom format class; so it is possible to have access to the javascript: http://www.naslain.com/tmp/gis/ Using firebug, the XML and the features array are visible.
Untill now, my problem still occurs. No displayed marks :-(
Anyone?
Best,
Chris

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

Re: Fwd: [Geoserver-users] LayerSwitcher() notworking

Chris-4
This works perfectly now.
Thank you so much Arnd,

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