Creating a Map Legend

From OpenStreetMap Wiki
Jump to navigation Jump to search

Collection of discussions, tools and documents on how to generate map legends / keys


Discussions

Tools

Unfortunately none of these tools seem to be actively maintained

Wishlist for a legend tool:

  • able to process XML styles with mininal modifications
  • generate both HTML and printable formats
  • can be defined by simple spec file
  • optionally: exclude legend entries for objects not present in given map area at all
  • optionally: in addition to simple points, lines, rectangles: allow simple OSM XML "minimaps" for visualization of objects in context

RenderLegend

Last changed: 10 years ago

Language: Python 2 (but can easily be converted to Python 3)

Takes a legend specification file, produces small OSM XML format snippet files, and tries to render these using the original Mapnik style file.

As styles usually expect to read data from a PostGIS database though, RenderLegend tries to rewrite SQL queries in the original style into Mapnik filter expressions.

While this may have worked out ok ten years ago, its SQL "parser" does fail on most current styles, e.g. not being able to understand SQL UNIONs.

If this tool was to be reviced, it should probably rather store legend data to render in a dummy PostGIS instance, and render using the unmodified original style, instead of generating OSM XML, and trying to rewrite styles for that.

The general idea of its spec file is to organize a legend in pages and lines, with multiple elements per line. For each element only the legend object type and OSM tag values are given in the element definition, which <style> to use for rendering each element is fully determined by the given Mapnik style only.

Possible legend element types are: point, line, square, rectangle, pointtext, linetext, lineshield, squaretext, rectangletext, squarepoint, smallline

mtbmap make_legend.py

Mapnik-Legendary

Last Change: 5 years ago

Language: Ruby

This also uses a legend spec file, and an actual Mapnik style, to create a legend, somewhat similar to what RenderLegend is doing.

It depends on Ruby-Mapnik, which has been unmaintained for five years already, too.

Hartmut Holzgraefe failed to even build Ruby-Mapnik to begin with, or to find a binary package of it, so I don't even know yet how well it might work to begin with ...


render_legend() method in the Mapnik Python Bindings

TopOSM legend.py

had a legend.py script that's no longer used with the current site though, and apparently went missing in action ...

Active implementations