The default labeling model IlvDefaultLabelingModel is a subclass of
IlvLabelingModel
. It has certain properties that may not be suitable for your
application:
- Only objects of type IlvLabel and IlvZoomableLabel are considered labels.
- All other objects are considered rectangular obstacles.
It is easy to change these properties by subclassing
IlvDefaultLabelingModel
. For instance, if you use only labels of class
MySpecialLabel
, you can override the method
isDefaultLabelClass
:
public boolean isDefaultLabelClass(Object obj) { return (obj instanceof MySpecialLabel); }
If you want some objects to be completely ignored, make sure they
are not considered as labels or obstacles. To avoid considering
objects of class
IgnorableGraphic
as obstacles, you can override the method
isObstacle
:
public boolean isDefaultObstacleClass(Object obj) { return super.isDefaultObstacleClass(obj) && !(obj instanceof IgnorableGraphic); }
Note
Instead of overriding
isDefaultLabelClass
and
isDefaultObstacleClass
, you can also specify which objects are labels and obstacles by
using the methods
setLabel
and
setObstacle
, as illustrated in Labels and obstacles in Java.
Some obstacles do not have a rectangular shape. For simplicity and
speed, the overlap value is based on the bounding box of normal
obstacles. Hence the default labeling model may compute overlaps in
situations where in fact there are no overlaps, because the
bounding box is usually a little larger than the area that is
really covered by the obstacle. You can correct this by overriding
the method
getOverlapValue
by implementing a more precise (but also more complex) overlap
test:
public double getObstacleOverlap( Object label, IlvRect labelBBox, Object obstacle, IlvRect obstacleBBox, float minDist) { ... complex calculation of the overlap considering the precise shape of ... the obstacle. If the label is closer than minDist to the obstacle, ... it should be considered as overlap ... if (hasOverlap) return a value proportional to the overlap; else return 0.0; }
Since the default labeling model IlvDefaultLabelingModel implements the IlvLabelingModelWithRotation interface, you
can similarly override all overlap methods that have a rotation
angle parameter for the labels. See The IlvLabelingModelWithRotation Interface.