I am new to GeoServer and I am trying to add a legend on an existing map. I am not sure where to add the legend XML file?
In the GeoServer user manual, they briefly talk about legend but it is not very clear: http://docs.geoserver.org/stable/en/user/advanced/wmsdecoration.html I think the legend XML file should be added in the web map services page (WMS). But I tried to search for the key word like legend or something on the page but I cannot find it. Am I on the right direction?
You are referring to WMS overlay decorations.
In the link http://docs.geoserver.org/stable/en/user/advanced/wmsdecoration.html that you included in the post, it gives the instructions needed to mimic the screenshot you've referenced.
To use decorations in a GetMap request, the administrator must first configure a decoration layout. These layouts are stored in a subdirectory called
layouts
in theGeoServer Data Directory
as XML files, one file per layout. Each layout file must have the extension .xml. Once a layout foo.xml is defined, users can request it by adding &format_options=layout:foo to the request parameters.
In essence, you:
layouts
folder that exists in the Data Directory on
the Geoserver (the specific path varies on the installation)&format_options=layout:foo
to the request parameters.This embeds the overlay onto the layer itself. This is in contrast with Jose's answer which involves an additional HTTP request (which could be referenced in a <img href=""/>
tag).
In either case, the legend component can be influenced by also applying a style in the request for the layer. These are commonly coded with SLD. For information on that is available here
== Edit 01 ==
For Reference, the path to the data directory can be found here:
This is the path on the server where geoserver is installed where the data directory resides. The Structure of Data Directory link has some detail on what is in this folder and the purpose of each item.