Ticket #3464 (new feature)

Opened 21 months ago

Last modified 21 months ago

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.

Attachments

OpenLayers.Control.Legend.js Download (10.6 KB) - added by lissyx 21 months ago.
OpenLayers.Control.Legend component
OpenLayers.Control.Legend.css Download (0.9 KB) - added by lissyx 21 months ago.
CSS part for description of OpenLayers.Control.Legend component
Capture-GLT Visualization with OpenLayers - Aurora (Build 20110815042007)-5.jpg Download (116.2 KB) - added by lissyx 21 months ago.
An overview of the component in action

Change History

Changed 21 months ago by lissyx

OpenLayers.Control.Legend component

Changed 21 months ago by lissyx

CSS part for description of OpenLayers.Control.Legend component

Changed 21 months ago by lissyx

An overview of the component in action

Changed 21 months ago by lissyx

  • cc lissyx+osgeo@… added
Note: See TracTickets for help on using tickets.