To create labels for graphic objects, the IlvMapLabelManager class relies on a label
factory implementing the IlvMapLabelFactory interface. Any object
implementing this interface is responsible for returning the
appropriate IlvMapLabelingLabel instances for specified IlvGraphic objects. This is done by
implementing the method:
labeler.setView(view); layerToLabel.getStyle().setLabelAttribute("NAME"); labeler.addLayer(layerToLabel); labeler.performLabeling(); public IlvMapLabelingLabel[] getGisLabel(IlvGraphic comp);
The default label factory performs the
following tasks:
- It extracts an attribute from the specified IlvGraphic object (according to the label attribute in the IlvMapStyle of the IlvMapLayer being labeled), and takes its
String
representation as the text of the label. - Then it creates the appropriate instance of the IlvMapLabelingLabel class, according to the kind of graphic object being labeled:
- IlvMapPointLabel for objects with an anchor point.
- IlvMapLineLabel for polyline objects (for example, label along the line).
- IlvMapAreaLabel for closed areas with a label placed within visible parts of the area.
The IlvMapLabelManager uses this default
implementation of the factory, but you can provide your own
implementation if you want to have fine control over what is
labeled, and how. To replace the default label factory with your
own label factory:
IlvMapLabelFactory myLabelFactory = new myLabelFactory(); //Your own implementation. //Get the map labeler. IlvMapLabeler labeler = IlvMapLabelerProperty.GetMapLabeler(manager); //Set the factory, if the labeler is an IlvMapDefaultLabeler instance. if(labeler instanceof IlvMapDefaultLabeler) { IlvMapDefaultLabeler dflt = (IlvMapDefaultLabeler)labeler; dflt.setLabelFactory(myLabelFactory); }
Controlling renderer parameters
When you implement your own IlvMapLabelFactory, you can specify a set
of layout and rendering parameters for each instance of IlvMapLabelingLabel that you create in the
constructor.
For more information about these parameters, see the IlvMapPointLabel, IlvMapLineLabel, and IlvMapAreaLabel classes.