MapInfo Pro

Expand all | Collapse all

Labeling question

  • 1.  Labeling question

    Posted 03-28-2019 17:28
    Is there a way to generate a background for a multi line label that is a complete rectangle?
    I have 3 uneven lines of text and want the background box to extend to the same margin on the right versus having the background only extend as far as the line of text.   Only way I know how to accomplish this is to add a bunch of spaces to the text lines that are short.

    Diana Ketza
    Channel Development Manager
    Little Rock AR

  • 2.  RE: Labeling question

    Posted 04-23-2019 08:56
    Hi Diana

    Here's a workaround that you can apply to get complete rectangular backgrounds. It does involve a bit of trial and error if you want the rectangles to be very close the label.

    For this demo purpose, I'm using a label on two lines but I'll let you know how you adjust it to three or more lines, too.

    This is my initial map. To make the background stand out a bit more, I have made it red.
    It's easy to see that the upper and some times the lower background is wider than the opposite.

    If we want to make them identical in width we need some way to identify the widest.
    In my example, I'm basically counting the number of characters in each. This expression gives me the number of characters in a given text text, here represented by a column name:
    It returns an integer value.

    I'll use the maximum number of characters as input to another function that basically will repeat one character a number of times.
    String$(10, "M")
    It returns this string: "MMMMMMMMMM". I have chosed M because that character is wider than most other characters.

    In my example above the originally label expression looks like this:
    UrbanAreaName + Chr$(10) + FormatNumber$(Round(CartesianArea(Object, "hectare"), 0.1))+" Ha"

    That is two lines divided by the Chr$(10) or sometimes Chr$(13).
    I need to compare the length of these two expression and use the longest. To do so, I write an expression like this:
    Maximum(Len(expression1), Len(expressions2)
    If I had more expressions that I need to compare, I can add an additional Maximum function around the first:
    Maximum(Maximum(Len(expression1), Len(expressions2), Len(expression3)

    My full expression will look like this:
    String$(Maximum(Len(UrbanAreaName), Len(FormatNumber$(Round(CartesianArea(Object, "hectare"), 0.1))+" Ha")), "M") + Chr$(10) + String$(Maximum(Len(UrbanAreaName), Len(FormatNumber$(Round(CartesianArea(Object, "hectare"), 0.1))+" Ha")), "M")

    Notice that I have to repeat the String$() expression as many times as I have lines in my label.
    As we still want to keep our original label, we add our layer again to the map below the original layer and set the global style of this additional layer to a non visible style. And then we apply this label expression to the layer. Also make sure that the original layer has label overlap turned on.

    First I set the labels to be displayed with a different text and label background color than the original layer as that gives me an view of how bigger it will be.

    If I'm happy with it, I change the text color and label background color to the same as the background color of the original layer. You can also turn off the label background of the original layer.

    If you think the label background is to wide, you can try replacing the M in the expression with a different character, for example N.

    Peter Horsbøll Møller
    Pitney Bowes