Skip to content

Get Layer Legend

This endpoint provides the legend of a given layer in the form of HTML markup. A legend is what is shown when you click the info button on a layer in the map viewer. It contains a description of the layer, the actual legend explaining the meaning of the different colors and symbols, and additional metadata.

https://api3.geo.admin.ch/rest/services/ech/MapServer/{layerBodId}/legend

Request Details

To interact with the legend endpoint, you need to provide specific parameters in your request. These parameters are divided into Path Parameters, which are required and part of the URL, and Query Parameters, which are optional and modify the behavior of the request.

Path Parameters

ParametersDescription
layerBodId (required)The technical name or the layer ID.

Query Parameters

ParametersDescription
lang (optional)The language. Supported values: de, fr, it, rm, en. (Defaults to de if browser language does not match any of the possible values)
callback (optional)The name of the callback function.

Response Details

The endpoint returns an HTML document containing the legend for the specified layer. The response includes:

  • A title and abstract describing the layer.
  • A legend image showing the symbology used in the layer.
  • Additional metadata such as the layer ID, valid scale range, and links to detailed descriptions, metadata, and data sources.

No CSS styling is applied by default, allowing you to integrate the legend seamlessly into your own application or website. You can style the HTML response using your custom CSS to match your application's design.

Examples

Get the legend for ch.bafu.nabelstationen:

Request
Response
sh
curl https://api3.geo.admin.ch/rest/services/ech/MapServer/ch.bafu.nabelstationen/legend

Get the same legend using JSONP:

sh
$ curl https://api3.geo.admin.ch/rest/services/ech/MapServer/ch.bafu.nabelstationen/legend?callback=callback