Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to change the name of the layers in the tree. This is part of my code:

var layer_group1 = new OpenLayers.Layer.WMS("layer_group1", 
                    url,
                    {
                        LAYERS: ['namespace:layer_a','namespace:layer_b','namespace:layer_c'],
                        format: "image/png",
                        transparent: "true",
                        projection: 'EPSG:4326'
                    },
                    {    

                        buffer: 0, 
                        displayOutsideMaxExtent: true,
                        isBaseLayer: false,
                        displayInLayerSwitcher: false,
                        yx : {'EPSG:4326' : true}

                    } 
                );

var layer_group2 = new OpenLayers.Layer.WMS("layer_group2", 
                    url,
                    {
                        LAYERS: 'namespace:layer_d',
                        format: "image/png",
                        transparent: "true",
                        projection: 'EPSG:4326'
                    },
                    {    
                        opacity:0.5,
                        buffer: 3,
                        displayOutsideMaxExtent: true,
                        displayInLayerSwitcher: false,
                        yx : {'EPSG:4326' : true}

                    } 
                );


    mapPanel = new GeoExt.MapPanel({
        border: true,
        region: "center",
        // we do not want all overlays, to try the OverlayLayerContainer
        map: mapa,
        center:[-6613943,-3793944],
        zoom: 7,
        layers: [ capaBase, layer_group1, layer_group2, gmap,gsat,vector]
    }    
)

I get the tree:

layer_group1
   |_ namespace:layer_a
   |_ namespace:layer_b
   |_ namespace:layer_c

layer_group2
   |_namespace:layer_d

But I want to expect:

layer_group1
   |_ Layer a
   |_ Layer b
   |_ Layer c

layer_group2
   |_ Layer d

How can I change the name of the layer in the tree?

PS: don't hesitate if you need more code.

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

I'm facing the same problem and I don't have a complete answer, but for now I'm avoiding the use of the namespace in the layer call.

If you specify the workspace in the url like:

url =  http://host:port/geoserver/namespace/wms

Then you don't need to specify namespace when you call the layers:

var layer_group1 = new OpenLayers.Layer.WMS("layer_group1", 
                url,
                {
                 // Here you change from "namespace:layer_a" to "layer_a"
                    LAYERS: ['layer_a','layer_b','layer_c'], 
                    format: "image/png",
                    transparent: "true",
                    projection: 'EPSG:4326'
                },
                {    

                    buffer: 0, 
                    displayOutsideMaxExtent: true,
                    isBaseLayer: false,
                    displayInLayerSwitcher: false,
                    yx : {'EPSG:4326' : true}

                } 
            ); 

You'll get:

layer_group1
|_ layer_a
|_ layer_b
|_ layer_c

I know is not what you want, but it could help you.

--------- UPDATE (03/07/2013) ---------------------

I find a solution using a non-oficial script. Is not difficult to use, but you need to use specific GeoExt and Ext library versions (using the latest one didn't work for me; I'm using version 3.2.1 for ext-all and ext-base). Also, you need to add base layer or you'll receive notifications that you don't have a map projection (even if you declare one). Maybe there's some configuration to fix that, but the easiest thing for me was to add a base layer.

You can have a better answer here and the example (pointed in the previous URL).

Still not the optimal solution, but it works as expected so far. I'm going to vacations right now, so I don't have the time to post a minimal example but I could do it at my return if you want. Anyway, the example I posted below is a very good one.

Cheers!

share|improve this answer
    
I will try later. I didn't found the solution so this is progress! Please let me know if you find the solution :) –  Overflow012 Jul 2 '13 at 11:59
    
This is very embarrassing. I tried change the name of layer in GeoServer from layer_a to Layer a and it works! I can create layers with spaces in the name. –  Overflow012 Jul 11 '13 at 23:35
    
Any idea how I can use this with GeoExt 2 ? –  Alophind Oct 9 '13 at 21:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.