This topic provides a quick guide to the essentials of specifying text for labels. Slight details will change in upcoming builds but the content of this topic will still apply. For a quick start, see the 5 Minute Tutorial - Labels from Fields and Expressions video.
Manifold allows us to specify the text for a label that freely mixes any static text with text dynamically taken from fields or from SQL expressions using very simple syntax. It is a simple system that is easy to use while providing great power and flexibility.
We will work with a map that shows a drawing of Mexico with states (provinces) in Mexico as areas. The view below shows the map slightly zoomed into the Mexico drawing region.
The table for the drawing has Name, Population, and Geom fields.
To create labels, in the Project pane, we right-click on the Mexico drawing and then in the context menu that pops open we choose File - Create - New Labels to launch the New Labels dialog.
In the New Labels dialog we enter Mexico Labels as the name for the new labels component.
The Text box will be loaded with a list of fields in the drawing's table that can be used as a source of text, as well as a <pattern> choice that allows specifying a text pattern that uses multiple fields. The Text box by default will be loaded with a field name the dialog guesses will be useful, picking a text field as a first choice.
In the dialog's Text box we choose the Name field from the pull down list of fields in the drawing. That will use the Name field as the source of text for labels. Press Create Labels in the New Labels dialog to create a new labels component based on the Mexico drawing. Drag and drop the new Mexico Labels layer into the map.
The result is a layer of labels where the text content of each label is taken from the Name field for that object's record. In the illustration above we have used the Style pane to increase the size of the font used to 10 points, larger than the default 8 points.
The Style pane for labels shows the pattern used for the label's text, in this case, just [Name], a simple reference to the Name field. We can edit that by clicking the Edit Text button and editing the text pattern to change it to State: [Name]. Text that we enter other than a [ ] reference to a field name or a [[ ]] use of an expression is literally repeated in the label.
The same text pattern is used for all labels in a labels component. The variation in each label in the map comes from different text values for each object in the Name field.
Whatever we provide as text outside of the name of a field or an expression is reprinted literally in the label.
We can use more than one field in a label, and we can use more than one line in a label. Whatever text, including new lines, we put into the label text will be repeated faithfully. White space does not matter inside an expression, that is, within the double [[ ]] brackets, but outside an expression white space is taken literally.
For example, we can use both the Name field and also the Population field in a label.
The positioning of the text in two lines in the Style pane is repeated when label text is rendered in the map. Although the Population field is a numeric data type (an Int32), it is automatically printed as text in the label.
We can use an SQL expression, within double square [[ ]] brackets, to do computations within the label text.
For example, if we edit the text to use the pattern:
Pop: [[ Round([Population] / 1000) ]] K
We can divide the population by 1000, and then round the result to have fewer digits. The Style pane illustration shown above wraps the text for the second line since the size of pane used in the illustration is too narrow to show the entire line without wrapping.
Although the result of the expression is a numeric value, it is automatically printed as text in the label. Note that all label text in the text pattern outside of the [[ ]] expression and the [ ] field is printed literally as it is entered in the pattern.
We can use almost any SQL expression, including using any of hundreds of SQL functions, within an expression.
For example, we can edit the text pattern to be:
That uses the GeomArea function to get the area of a polygonal area object, as well as the Round function to trim off digits beyond the decimal point. We have written the pattern using white space freely within the expression's double [[ ]] brackets to provide a more legible expression.
As pointed out on the forum by SQL master tjhb, we can use CASE and other SQL constructions:
For example, we can edit the pattern text to be:
CASE WHEN [Population] > 2000000
THEN 'High' ELSE 'Low' END
The result of the expression is text, either High or Low, depending on the value of the Population field.
The text from the expression is inserted into the pattern where the [[ ]] expression occurs.
We can format text for labels in many different ways using the rich set of formatting SQL functions available in Manifold.
Consider a map of US states, where the table for the map has four fields. A Geom field gives the geometry of each state, a State field using nvarchar text type gives the name of the state, and a Date field that is a datetime type gives the date on which the state was admitted into the United States.
Using the Create - New Labels dialog We can create labels using the State field.
In the Project pane, we right-click on the US states drawing and then choose Create - New Labels. In the New Labels dialog we enter Labels for the name, and we choose the State field as the source of the text.
Press Create Labels, and then we drag and drop the new labels component into the map.
Each label takes its text from the State field of the US states drawing. We have formatted the Labels layer using the Style pane to use Segoe UI font in Semibold weight, with a slight shadow in very light gray.
In the Style pane we can edit the label text to use a different field.
With the focus on the Labels layer, in the Style pane we press the Edit Text button to edit the text pattern for the label. We change it to [Date] to use the date field.
The labels system will automatically CAST the datetime type used by the Date field into text, which is then displayed. However, using the full contents of the datetime field is confusing, since the time component is all zeros (the date of accession of each state does not include the actual time it joined the US, only the day, month, and year).
We can format the date to any one of many other formats by using the StringFormatDateTime SQL function.
The StringFormatDateTime SQL function takes as its arguments the field from which to take the date, in this case the Date field, a text pattern that is one or more characters, in this case a single d character that indicates a simple date format, and a final argument which is a language code, such as en-US or de-DE, which can also be left empty with just two single quotes, as used in this case.
The text pattern for the label is:
[State] - Admitted
StringFormatDateTime([Date], 'd', '')
We also use the State field to get the name of each state, and ordinary text in the form of - Admitted, which like all text outside of single [ ] or double [[ ]] brackets is repeated literally for each label.
We press OK to apply changes in the dialog.
The Style pane, if sized to a narrower size as used in these illustrations, will wrap the expression.
The map will instantly update to show the new text created for labels by the text pattern, and function, we used. We have zoomed further into the display above.
If we want to change the format of the text generated by the StringFormatDateTime function by altering the text pattern argument. In the Style pane we press Edit Text, and then in the text pattern we change the lower case d character to an upper case D character.
The expression now is:
[State] - Admitted
StringFormatDateTime([Date], 'D', '')
The upper case D character specifies a long date, with the day of the week and the month spelled out.
The map window immediately updates to show the new labels generated by the new text pattern.
Instead of using single letter format codes, we can use more complex strings for the format specifier argument to create custom formats.
[State] - Admitted
StringFormatDateTime([Date], 'ddd, d-MMM-yyyy hh:mm tt', '')
Using the above argument results in:
It takes but a few seconds to press the Edit Text button and to change the label text pattern.
For example, we can rearrange the date format string argument for the function to put the year first:
[State] - Admitted
StringFormatDateTime([Date], 'yyyy - ddd MMM d, hh:mm tt', '')
Text within the argument, such as commas, that is not one of the formatting tokens is quoted literally.
That makes it easy to format datetime values exactly as we want.
Since the datetime values in the table we are using do not have significant times, we can eliminate use of the times, and use long formats for the day of the week and the month:
[State] - Admitted
StringFormatDateTime([Date], 'yyyy - dddd, MMMM d', '')
The result is:
To see all of the many options that we can use with the StringFormatDateTime function we can look up the entry for that function in the String SQL Functions topic.
We can align multiline text in labels to left aligned, right aligned, or centered using the Position tab in the Label Style or Symbol dialog, as discussed in the Style: Labels topic.
With the focus on the labels layer, in the Style pane click on the Total style button or on the Symbol button. In the menu that appears, choose the More... button.
In the Position tab, chose the Align setting desired, using the left hand Align box.
Text will be aligned as desired.
Language codes used by functions that take a language argument, such as those used in this topic, are standard language codes as used in many settings in Windows, such as de-DE for German language as used in Germany, or en-US for English as used in the US. A table giving 655 language codes, including broad variations as haw-US for Hawaiian language as used in the United States, can be downloaded in the language_codes.map Release 9 project from the Manifold website.
5 Minute Tutorial - Labels from Fields and Expressions
Since the videos below were created, the Style pane has acquired a label text section that gives the text pattern for creating labels. However, all information shown in the videos below on how to format labels in terms of colors, symbology, sizes and so on are exactly the same so the videos are still a great help in learning how to format labels.
Manifold 9 - Style Pane Quickstart - Points - A fast and easy introduction to the new Style and formatting capabilities for Pionts in Manifold Release 9 and Viewer. Learn how to rapidly change colors, symbology, sizes and rotations including the use of vector symbols, fonts and even bitmap images. The new system is "always on" and immediately shows changes in the main workspace for rapid, easy choice of exactly the visual effect we want. This video gets right to the basics used every day.
Manifold 9 - Style Pane Quickstart - Lines - Learn how to use the spectacular new style capabilities for lines in Manifold Release 9 and Manifold Viewer to create an endless variety lines quickly and easily. See how to add arrowheads or other symbols to the ends of lines, how to customize lines with repeating symbols, how to start lines with custom symbols and how to add accessory left and right lines for exactly the right effect.
Manifold 9 - Style Pane Quickstart - Areas - New area style capabilities in Release 9 and Viewer make it easy to rapidly create spectacular visuals that get the story across with clarity and compelling effect. Learn how to use point and click controls to fill areas, control borders, draw "inner area" effects and "outer area" effects for a seeming infinite range of options, all available with a rapid click of the mouse. Use bitmap images for area effects too!
Manifold 9 - Style Pane Quickstart - Labels - Recent builds of Release 9 have added extensive new style facilities for labels, making it easy to choose a wide variety of effects, including sidecar icons, box frames, drop shadows and many others. This video shows how fast and easy point-and-click dialogs make it easy to create exactly the label look you want. Works for the free Manifold Viewer, too!
Manifold 9 - Bitmap Styles - A quick, first look at very extensive additions to Style, enabling use of bitmaps for styles, inner and outer area hatches, left and right line style additions and many other new features.
String SQL Functions
Example: Add Labels to a Map - How to manually add labels to a map.