12  REST for Legends

A legend provides a key to the information displayed on a simple, class, or thematic layer. Consider, for example, our map of the proportion of 2008 votes in each county that were for the Democratic presidential candidate (see REST for Thematic Layers). Each county is represented by one of six colors (red, orange, yellow, green, teal, blue) corresponding to the proportion from low to high. But there's no indication on the map of what those colors mean. The following steps illustrate how to add a legend providing that information:

1.  Recreate the path for the original map by starting with the host, version, API key, and endpoint, then adding the layer definition, the base map code, and the query string that specifies the map's centerpoint, size, and zoom:


2.  At end of the query string, append the Boolean legend parameter and set the value to 1 (enabled):


2.  In the query string, change the value of the longitude and width parameters so that when the map is rendered the legend will not obscure any part of the United States:
- shift the centerpoint East by increasing lng;
- increase width.


4.  Put it all together and you have the complete REST path for the map:


Here's an excerpt of the map, showing a legend, that is returned from the above URL (to see the full map in a new window, click here):

Note: For complete details on the purpose and valid values of legend layer properties, both required and optional, refer to the /legend page of the Mapfluence REST API Reference at http://developer.urbanmapping.com/docs/mapfluence/rest/2.0/reference/tile/Legend.