auto labels in mapbasic code

563 views
Skip to first unread message

briggs

unread,
Feb 10, 2011, 8:46:40 AM2/10/11
to MapInfo-L
I am pretty new to mapbasic and not sure exactly how to make it so
that labels auto-display.

I have a subroutine that opens up a point .TAB file in the current
window, and I want it so that when you open it up, the labels
automatically display.

Sub MICRO10
Open Table "D:\MapInfo 101\Past Micro Projects\Micro2010"
Add Map layer Micro2010
End Sub

There is a field in the Micro2010.tab called civic numbers. I want to
display that field as a label in arial size 6, with the points to be
invisible, so that you see the labels, but not the points.

I have a custom menu in my mapinfo workspace that initiates the
MICRO2010 subroutine when I click on it.
What would I add to that simple Subroutine to make this happen?

Eric Blasenheim

unread,
Feb 10, 2011, 4:58:55 PM2/10/11
to MapInfo-L
I am sure some of the mavens of this list will send you the code, but
I have a suggestion of how you can teach yourself!

Once you've loaded your table, go into the layer control and make the
changes that you would like to enable programmatically.
With the MapBasic Window open (Options, Show MapBasic Window) you can
see the MapBasic commands that are sent to enable what you want. You
can copy the code into your app. You will want to replace hard coded
window identifiers with either FrontWindow() or store the right window
identifier in a variable. You also will probably use a layer name
rather than a number. There are plenty of examples in the docs on
that.

Your code is essentially just setting properties on the layer and
should eventually look like:

Set Map Window NameOfWindowVariable Layer Micro2010 Display Graphic
Symbol... Label Auto on.......

You can also save a workspace with the layer after you have set it the
way you want. Opening up the workspace in a text viewer will show you
the same Set Map commands.

To make the layer not show symbols you are going to use a symbol style
of none.

Eric Blasenheim
PBBI (MapInfo)

Adrian Gray

unread,
Feb 11, 2011, 7:12:47 AM2/11/11
to mapi...@googlegroups.com

Briggs,

 

When you are learning MapBasic it's a good idea to open the MapBasic window (Options, Show MapBasic Window), then perform the operation you want. You won't see iterative or multi-line code but simple functions and queries are laid out for you.

 

Here I've opened a layer, created a map window, opened Layer Control and set the labelling properties such that Auto Label is on and Street is the column I want to label. It can get more involved than this but it's a good start.

 

Open Table "C:\dummy_data\dataobject_alldata.TAB" Interactive

Map From dataobject_alldata

set map redraw off

Set Map Layer 1 Label With street Auto On

set map redraw on

 

You will notice that no code is displayed for the opening of Layer Control. You will also notice that once the layer has been opened, it's name is no longer used and is replaced by it's map window index "1" in this case as there is only one layer in the map widow. If you are opening your layer into an existing map window you will need to find your layer's index before you can auto label it. This can be done using a number of different functions or by simply looping the layers in the map window to find a match. Let me know if you don't know how to do this.

 

Regards

Adrian Gray

Viewshed Limited

http://www.viewshed.co.uk/

t: 01392 861946 f: 01392 861947

Orchard House Church Road Silverton Exeter EX5 4PD

registered in England and Wales: 5661115 VAT# 876 6186 72

 

MapInfo Professional, MapBasic and MapXtreme training, off-the-shelf and bespoke application development

 

miFormz Lite - Generic forms application for MapInfo Professional and MapInfo Professional RunTime Manipulators from v6 to the latest. Your forms can include Drop Down Lists, Check Boxes, Radio Buttons, List and Multi-List Boxes populated from Value Lists or from table lookups. Plus data validations: Dates, Integers, Small Integers and Decimals. Download a shareware version from our website.

 

Got an LLPG? - try FuzzyLLPG for FREE. It builds a layer of your addresses, has a fuzzy search engine enabling you to search for any part of an address, it can merge tables together based on the UPRN. Version 2 now comes as a web service. Download shareware versions from our website!

--

You received this message because you are subscribed to the

Google Groups "MapInfo-L" group.To post a message to this group, send

email to mapi...@googlegroups.com

To unsubscribe from this group, go to:

http://groups.google.com/group/mapinfo-l/subscribe?hl=en

For more options, information and links to MapInfo resources (searching

archives, feature requests, to visit our Wiki, visit the Welcome page at

http://groups.google.com/group/mapinfo-l?hl=en

Reply all
Reply to author
Forward
0 new messages