1

I specified the raster file with "name" and "title" in Geoserver.

For example, I have these in Geoserver:

name,  Title  
AT:usa, "This is a map of USA"  

Can I return the title ("This is a map of USA" ) as the layer name in Openlayers layer switcher when I call the WMS service for this layer by name? By default, it shows "usa" in the layer switcher.

5
  • What is the value of the first param passed to the openlayers layer constructor? I bet it is "usa". Now do you want do dynamically fetch the layer name from geoserver?
    – unicoletti
    Oct 1, 2011 at 7:06
  • Do you think this is the only way?
    – Seen
    Oct 1, 2011 at 12:52
  • There are 2 ways: dynamic (difficult) and static (easy)
    – unicoletti
    Oct 1, 2011 at 13:18
  • I was expecting the title parameter would come with the post back WMS. So could you tell me how to do static one? Thanks! @unicoletti
    – Seen
    Oct 1, 2011 at 14:58
  • You can parse the WMS GetCapabilities response to get the name and title of the layers in the service. name is for computer interaction, title is for humans to read.
    – nmtoken
    Jan 16, 2017 at 13:36

1 Answer 1

2

I suppose you are creating your OpenLayers WMS layer as follows:

var wms = new OpenLayers.Layer.WMS("This is a map if USA",
                               "http://yourgeoserver/geoserver/wms",
                               {layers: "AT:usa"});

then the first parameter is the layer name that will be displayed in the layer switcher. Simply set it to whatever you like it to be.

1
  • I think this is an easy way to get around. That is how I did it exactly. Thanks!
    – Seen
    Oct 1, 2011 at 16:47

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.