2

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.

1 Answer 1

0

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!

3
  • I will try later. I didn't found the solution so this is progress! Please let me know if you find the solution :) Jul 2, 2013 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. Jul 11, 2013 at 23:35
  • Any idea how I can use this with GeoExt 2 ?
    – Alophind
    Oct 9, 2013 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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