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:

http://query.mapfluence.com/2.0/MFDOCS/map/mode=theme|select=umi.us_elections.2008_pres.prt_dem_pty|from=umi.us_census00.county_geometry|breaks=0.33,0.45,0.55,0.67|border=808080_1|styles=ff0000,ff8000,ffff00,00ff80,0000ff|opacity=0.5/g/?lat=39&lng=-96&width=800&height=480&zoom=4

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

/?lat=39&lng=-96&width=800&height=480&zoom=4&legend=1

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.

/?lat=39&lng=-88&width=975&height=480&zoom=4&legend=1

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

http://query.mapfluence.com/2.0/MFDOCS/map/mode=theme|select=umi.us_elections.2008_pres.prt_dem_pty|from=umi.us_census00.county_geometry|breaks=0.33,0.45,0.55,0.67|border=808080_1|styles=ff0000,ff8000,ffff00,00ff80,0000ff|opacity=0.5/g/?lat=39&lng=-88&width=975&height=480&zoom=4&legend=1

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.

Top