Computing on the fly a reasonable layout for map legends
For a given vector layer legend and a user-defined rectangle (established with mouse events: mouse down + dragging + mouse up) we need to compute the location and size of the area for each legend sample item. Our goal is simply having a nice-looking legend box like this one:
So the parameters whose values we must compute automatically are:
- Number of columns
- Width (w) and height (h) of each sample item (the same for all)
- How many items we are going to draw (not necessarily all items available in the legend)
We'll start by stating the criteria that will guide our little algorithm:
- The w/h ratio will be 8 at most. If we need to truncate a label to achieve this, we'll do.
- The font size and number of columns will be chosen so that available room is used in the best way.
- If h is less than 3 mm, we'll reduce the number of items included, but we must include all items if the total number of items available in the legend is 20 or less. If we cannot achieve this, the legend box will be empty, so the user will be forced to enlarge the legend box frame.
- If the last column is not full, items will have the same spacing as in other columns, thus leaving some empty space in the bottom-right corner.
Comments
Post a Comment