Ticket #3464 (new feature)
OpenLayers Legend Control
| Reported by: | lissyx | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | Future |
| Component: | Control | Version: | 2.10 |
| Keywords: | control, legend | Cc: | lissyx+osgeo@… |
| State: | Needs Discussion |
Description
Hello,
While working/prototyping with OpenLayers (I'm still quite a newbie on this library), I felt the need for a legend displaying tool, as you can find the layerswitcher component. I have no idea if it's a component that should/must be available in OpenLayers, but the fact that I saw several posts on the web about this topic makes me wonder I'm maybe not alone nor that insane.
So, using OpenLayers.Control.LayerSwitcher as a basis, I wrote a simple OpenLayers.Control.Legend component, that takes its place on the right of the screen, below LayerSwitcher. The core functionnality is quite simple: you pass an option object in the constructor that specifies:
- min value of the interval of data,
- max value --,
- function to call to calculate the color
- scale size, i.e. how many steps you want for the legend display
- unit, for formatting purpose (i.e. "value XXX (unit)")
- expected error value, i.e. a value that denotes a measure error (e.g. for a ping measure while surveying outdoor network coverage, this is network unrecheable).
Then it computes the scale to display as an array of objects:
{
value: Value,
intlow: Low bound of the value,
inthigh: High bound of the value,
color: Hex color string computed by the user's function,
iserror: Wether it is an expected error
}
This is used as a model when drawing contents in the redraw() method.
For my usage (displaying 3G network coverage/latency measured with 'ping' over a specific path, high speed train), it works quite well.

