The entry point for the dynamic map labeling mechanism is the IlvMapLabeler interface. A class
implementing this interface is responsible for managing labels for
a given IlvManager. The IlvMapLabelerProperty class is a named
property used to attach an
IlvMapLabeler
to an
IlvManager
. This map labeler handles all the data sources imported into the
manager. The model data is made persistent and saved when you save
the map.
You can access the map labeler by calling:
IlvMapLabeler labeler = IlvMapLabelerProperty.GetMapLabeler(manager);
If a specific labeler is not set for the property, this method
creates or returns an instance of IlvMapDefaultLabeler. This default labeler
class automatically creates and configures a map layer for labels
and listens for changes to the layer structure attached to the
view. This allows the labeling to be updated when layer order
changes. It also contains an internal IlvMapLabelFactory to create the appropriate
labels for graphic objects, according to the LABEL_ATTRIBUTE field
of the IlvMapLayer. For more information about
IlvMapLabelFactory
, see The IlvMapLabelFactory Interface.
To add labels to a given map layer on
your map:
-
Define the layer to be labeled:
IlvMapLayer layerToLabel;
-
Create a default
IlvMapDefaultLabeler
and set it on the manager:IlvMapLabeler labeler = IlvMapLabelerProperty.GetMapLabeler(manager);
-
Since this labeler has to interact with the view, you must indicate in which view it is to display the labels:
-
Set the label attribute for the map layer to specify which attribute of the graphic objects should be displayed as a label (check the available attributes in the file format you read in):
-
Register the map layer to label with the labeler:
-
Finally, notify the labeling thread to compute labels for all the labeled layers: