Create legend with mixed symbols and images

I am trying to add a legend to my map, using a mix of symbols (S 11p ...) and images (I /image/path ...). The problem I am having is two fold: first, while the symbols all draw nicely, one per line, each with their associated label, the image seems to ignore line spacing and ends up with the next symbol drawn on top of it. Secondly, there appears to be no way to add a label to the image.

To work around these issues, I have come up with the following gobldy gook:

G 3p
S 11p a 16p red - 23p gps
G 3p
I /path/to/image.png 16p LT
G -1l
T webcam
G 1l
G 3p
S 11p t 16p green - 23p seismometer

which almost works, except that the T webcam text is all the way to the left, overlapping the image. To get it to offset properly, it would seem I need to use the P directive just before the T, the first argument of which is x - which I need to be 23p. But there I get stuck. Trying something like P 23p - - - - - - - gives me a Record 0 had bad x coordinate error. Hours of searching the documentation hasn’t helped, since all it says is ...x y font angle justify are defined above (No, they aren’t - they aren’t defined anywhere I can find).

And there I am stuck. I could use just a raw number for the x value, but I’d be left guessing at what value to use to get a 23p offset to line up with the symbol labels. How do I properly insert a “symbol” line in my legend that uses an image rather than a symbol?

Some thoughts: We did not consider the image a symbol so there is no label option. However, I would recommend L rather than T or P for this. I know I will advance the line-spacing by the height of the image, but would have to see if that is causing trouble with what comes after. As you know, G can help with vertical spacing.

Thanks. I actually tried using L prior to looking into T and P, but 1) It uses the wrong font by default (though I suspect with another half hour or so of digging through the documentation I could figure out how to set it to match, since font is one of the parameters) whereas T uses the correct font by default, and 2) I’m still left with the left offset problem, only with L there doesn’t appear to be any formatting options that could fix it, like P appears to be able to do for T maybe columns, somehow set to the correct width?

Perhaps a better approach overall would be to see if I can decipher how to make custom symbols - the image I am using is fairly simple. Another bonus of that approach appears to be that I wouldn’t have to manually set the legend width, whereas with I I do…

There is also the option of posting a feature request if you can convince me that I should take an optional label etc. I am not quite seeing what you do yet so if you can post something graphical then I may become inspired to solve it.

Sure. Here is an example of what I have managed to come up with so far.

The idea is that I have generated this map from user input, with various features (here GPS, Seismometer, tilt meter, and webcams, but there could be others - satellite uplink? Relay station? etc.) marked on the map with various symbols. Some of the markers lend themselves easily to basic symbols, or perhaps custom symbols when/if I figure that out (such as the star for GPS), but initially all the markers are provided as .png images.

Plotting these markers on the map is easy enough with Figure.image(), but getting them into the legend is proving more difficult. Note that even now, the webcam entry doesn’t quite line up with the other entries, and getting to this point required a lot of “magic numbers” that I came up with by simply tweaking them over many tries until it lined up - as such, the approach feels fragile to me.

I generally tend to think that if I have to fight with a tool to accomplish what I want, then I am probably doing something wrong. As such, if there is a better way to accomplish the goal of having multiple, perhaps complicated, markers on both the map and in the legend, I’m all ears! :slight_smile:

1 Like