VERIFIED SOLUTION i
X

Clarification of "Order Clause" in "Set Legend" and "Create Designer Legend" in MapBasic

UPDATED: November 13, 2018


Set Legend Order

The Set Legend statement applies to thematic legends only, but thematic legends can be displayed in the legacy floating Theme Legend window as well as the newer Legend Designer and Layout Designer windows. The Order clause in Set Legend allows you to change the order of legend rows for any thematic legend. You can specify ascending or descending order for any of the thematic legend types, but you can only the Individual Value thematic legend supports a custom order.

As an example, an Individual Value theme (as Layer 1 in the map) has 4 ranges, and thus 4 rows in its legend. They are “High”, “Moderate”, “Low”, and “Very High”.  To display the legend with the ranges in descending alphabetical order the MapBasic would be:

Set Legend Layer 1 Order Descending

To customize the order so that the ranges go from “Very High” to “Low” all the ranges need to be listed, so the (minimal) MapBasic would be:

Set Legend Layer 1 Order Custom Ranges Range "Very High" auto, Range "High" auto, Range "Moderate" auto, Range "Low" auto, Range default auto

The last part “Range default auto” is the “All Others” range. The order of the “All Others” range can also be changed – it is just being shown at the end.

Create Designer Legend Order/Alter Designer Frame Order

Create Designer Legend and Alter Designer Frame apply to any NON-thematic legend. These are legends you create for a map vector layer that isn’t a thematic layer. Both these statements support custom order of legend rows. 

The MapBasic Reference for both statements points to a pretty good explanation of how it works but here’s an example.  A legend has the following Create Designer Legend that creates a legend with 4 rows:

Create Designer Legend Frame From Layer 1
    Order Custom 2, 3, 4, 1
    Style Font ("Arial",0,8,0)
      Text "LIBRARY" Symbol (41,8388608,12,"MapInfo Miscellaneous",0,0) 
      Text "PRE-SCHOOL - PUBLIC" Symbol (38,16711935,12,"MapInfo Real Estate",0,0) 
      Text "PRIMARY SCHOOL - PRIVATE" Symbol (38,32768,12,"MapInfo Real Estate",0,0) 
      Text "PRIMARY SCHOOL - PUBLIC" Symbol (38,32768,12,"MapInfo Real Estate",0,0)
 
Each Text clause describes a legend row and the rows are saved to the workspace in their default order where each Text clause is numbered starting with 1 and increasing. The Order Custom clause applies a custom order to the rows by describing how the row ids are rearranged. For the above legend each Text clause is numbered like: 

Text "LIBRARY" Symbol (41,8388608,12,"MapInfo Miscellaneous",0,0)
Text "PRE-SCHOOL - PUBLIC" Symbol (38,16711935,12,"MapInfo Real Estate",0,0)
Text "PRIMARY SCHOOL - PRIVATE" Symbol (38,32768,12,"MapInfo Real Estate",0,0)
Text "PRIMARY SCHOOL - PUBLIC" Symbol (38,32768,12,"MapInfo Real Estate",0,0)
 
Order Custom 2,3,4,1 says the legend starts with row # 2, followed by 3 and 4, with the first Text clause at the end. 
 
2.  Text "PRE-SCHOOL - PUBLIC" Symbol (38,16711935,12,"MapInfo Real Estate",0,0) 
3.  Text "PRIMARY SCHOOL - PRIVATE" Symbol (38,32768,12,"MapInfo Real Estate",0,0) 
4.  Text "PRIMARY SCHOOL - PUBLIC" Symbol (38,32768,12,"MapInfo Real Estate",0,0)
1.  Text "LIBRARY" Symbol (41,8388608,12,"MapInfo Miscellaneous",0,0) 
 
 
The resulting legend looks like this:

Legend example

Environment Details

Products affected: MapBasic.
 

Downloads

  • No Downloads