MATLAB Examples

Manipulate Displayed Map Objects By Name

This example shows how to manipulate displayed map objects by name. Many functions assign descriptive names to the Tag property of the objects they create. The namem and related functions allow you to control the display of groups of similarly named objects, determine the names and change them, if desired, and use the name in calls to get and set .

Display a vector map of the world.

f = axesm('fournier')
framem on;
gridm on;
plabel on;
mlabel('MLabelParallel',0)
load coastlines
plotm(coastlat,coastlon,'k','Tag','Coastline')
f = 

  Axes with properties:

             XLim: [0 1]
             YLim: [0 1]
           XScale: 'linear'
           YScale: 'linear'
    GridLineStyle: '-'
         Position: [0.1300 0.1100 0.7750 0.8150]
            Units: 'normalized'

  Use GET to show all properties

List the names of the objects in the current axes using namem .

namem
ans =

  6x9 char array

    'PLabel   '
    'MLabel   '
    'Parallel '
    'Meridian '
    'Coastline'
    'Frame    '

Use handlem to get handles to graphic objects in the map. You use these handles to get or set object properties. For example, to change the line width of the coastline with set . If you call handlem with no arguments, it opens a graphical user interface that lists all the map axes objects. You can select objects interactively.

set(handlem('Coastline'),'LineWidth',2)

Change the colors of the meridian and parallel labels separately.

set(handlem('Mlabel'),'Color',[.5 .2 0])
set(handlem('Plabel'),'Color',[.2 .5 0])

Change the color of the labels to be the same.

setm(f,'fontcolor', [.4 .5 .6])

Use handlem specifying the 'all' modifier to get a list of all text objects or all line objects.

t = handlem('alltext')
l = handlem('allline')
t = 

  26x1 Text array:

  Text    (PLabel)
  Text    (PLabel)
  Text    (PLabel)
  Text    (PLabel)
  Text    (PLabel)
  Text    (PLabel)
  Text    (PLabel)
  Text    (PLabel)
  Text    (PLabel)
  Text    (PLabel)
  Text    (PLabel)
  Text    (PLabel)
  Text    (PLabel)
  Text    (MLabel)
  Text    (MLabel)
  Text    (MLabel)
  Text    (MLabel)
  Text    (MLabel)
  Text    (MLabel)
  Text    (MLabel)
  Text    (MLabel)
  Text    (MLabel)
  Text    (MLabel)
  Text    (MLabel)
  Text    (MLabel)
  Text    (MLabel)


l = 

  3x1 Line array:

  Line    (Parallel)
  Line    (Meridian)
  Line    (Coastline)