Class TLcdGXYContinuousLabelingAlgorithm
- All Implemented Interfaces:
ILcdCloneable
,ILcdGXYLabelingAlgorithm
,Cloneable
ILcdGXYLabelingAlgorithm
that offers continuously decluttered
labels, ideally suited for labeling moving objects (e.g., tracks).
When the objects move, the labels move along and avoid overlap in a continuous fashion by moving the labels around gently. The locations of the labels are not limited to a fixed number of possible locations, instead a label can be put everywhere on the map. By default there is no hard constraint on the distance between the label and the object. The labels do tend to move to their desired label location though.
Using this class, the desired location of the labels can be specified for all labels at once or for every label individually.
Which labels are removed in the labeling process is defined by the
label coverage property. Which labels should
be dropped first is influenced by the order in which labels are retrieved from the label infos
object, see TLcdCollectedLabelInfoList.getLabels()
. The default
is to never drop any labels.
- Use
setPadding(double)
to add space between labels. - Use
setReuseLocationsScaleRatioInterval(com.luciad.util.ILcdInterval)
to keep the relative location after zooming in the view. - Use
setClampOnScreenEdges(boolean)
to specify if labels can be partially outside the view. - Use
setLabelMovementBehavior(com.luciad.realtime.gxy.labeling.TLcdGXYContinuousLabelingAlgorithm.LabelMovementBehavior)
to specify when labels should be moved. - Use
setMinDistance(float)
to ensure labels are never too close to their object. - Use
setMaxDistance(float)
to ensure labels are never too far from their object. - Use
setDisallowedAngle(float)
to specify where a label can be positioned around its object.
This algorithm uses the obstacles and placements from the given ILcdLabelConflictChecker
to avoid placing labels at these locations.
For smooth visual results, the layer/view using this painter should be refreshed regularly.
This can for example be done by using the TLcdSimulator
, or by
refreshing the map using a timer, e.g. for a gxy layer/view :
Timer timer = new Timer( 50, new ActionListener() {
public void actionPerformed( ActionEvent e ) {
ILcdGXYView view = ...;
ILcdGXYLayer track_layer = ...;
view.invalidateGXYLayer( track_layer, true, this, "Invalidating track layer" );
}
}
} );
timer.setRepeats( true );
timer.start();
Using such a timer, it might be important with respect to performance to set
the correct number of background layers (see ILcdGXYView.getNumberOfCachedBackgroundLayers()
).
The TLcdSimulator
does this automatically (see TLcdSimulator.isManageNumberOfCachedBackgroundLayers()
).
Notes:
- This labeling algorithm never drops labels. This means that in some cases, when many labels need to be displayed, labels can overlap.
- This algorithm assumes the
ILcdGXYLabelPainter
of the layer implementsILcdGXYLabelPainter2
as it can only declutter labels if they can be placed freely, not when placement is limited to a fixed number of locations. - The bounds returned by the
ILcdGXYLabelPainter2
need to be independent of the location of the label for this algorithm to work well. Therefore the optionsetConsiderPinForBounds
ofTLcdGXYStampLabelPainter
is not supported in combination with this algorithm, as the pin varies in size depending on the label location. - This class supports rotated labels and rotated obstacles. However for performance reasons the axis aligned bounds of these labels are used in most calculations. Because of this, labels might not be optimally placed.
- The implementation of this labeling algorithm is thread-safe if the set master-slave dependency provider is thread-safe, the label priority provider is thread-safe and all overridden methods are implemented in a thread-safe manner.
- Since:
- 10.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Indicates when labels should be moved. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
MakesObject.clone()
public.collectLabelInfo
(List<TLcdLabelIdentifier> aLabelsToCollect, Graphics aGraphics, ILcdGXYView aGXYView) This method returns aTLcdCollectedLabelInfoList
object based on the given list ofTLcdLabelIdentifier
s.computeLabelPlacements
(TLcdCollectedLabelInfoList aLabelInfoList, ILcdLabelConflictChecker aLabelConflictChecker, ILcdGXYView aView) This method computes a list ofTLcdLabelPlacement
s using the givenTLcdCollectedLabelInfoList
.Returns the desired relative location.float
Returns the size of the disallowed range.Indicates when labels are moved.Returns the label placing priority provider.Returns the dependency provider that defines the master-slave dependency between labels.int
Returns the maximum declutter time.float
Returns the configured maximum allowed distance.double
Returns the maximum label coverage ratio.float
Returns the configured minimum allowed distance.protected double
getOrientation
(Object aDomainObject) Retrieves a domain object's orientation.double
Returns the padding around the labels.Returns the scale ratio interval in which label locations are reused.boolean
Indicates whether labels are clamped against screen edges.protected void
retrieveDesiredLabelLocation
(Graphics aGraphics, ILcdGXYContext aGXYContext, Object aObject, int aLabelIndex, int aSubLabelIndex, Point aRelativeLocationSFCT) Retrieves the desired label location for the given object, label and sub label index.void
setClampOnScreenEdges
(boolean aEnabled) Enable or disable clamping labels against screen edges.void
setDesiredRelativeLocation
(Point aDesiredRelativeLocation) Sets the desired relative label location: the location the labels tend to move to.void
setDisallowedAngle
(float aArcAngle) Set a range, relative to the object's heading, where labels cannot be placed.void
Indicate when labels should be moved.void
setLabelPriorityProvider
(ILcdGXYMultiLabelPriorityProvider aLabelPriorityProvider) Sets the label placing priority provider, specifying the priority for individual labels.void
setMasterSlaveDependencyProvider
(ILcdCollectedLabelInfoDependencyProvider aDependencyProvider) Sets the dependency provider that defines the master-slave dependency between labels.void
setMaxDeclutterTime
(int aMaxDeclutterTime) Sets the maximum time (in ms) that should be spend in decluttering the labels.void
setMaxDistance
(float aMaximumDistance) Set the maximum allowed distance of a label to its anchor point.void
setMaxLabelCoverage
(double aMaximumLabelCoverage) Sets the maximum label coverage ratio.void
setMinDistance
(float aMinimumDistance) Set the minimum allowed distance of a label to its anchor point.void
setPadding
(double aPadding) Sets the padding around the labels.void
setReuseLocationsScaleRatioInterval
(ILcdInterval aReuseLocationsScaleRatioInterval) Sets the scale ratio interval in which the label locations are reused.
-
Constructor Details
-
Method Details
-
setLabelMovementBehavior
public void setLabelMovementBehavior(TLcdGXYContinuousLabelingAlgorithm.LabelMovementBehavior aBehavior) Indicate when labels should be moved.- Use
MINIMAL_MOVEMENT
to avoid moving labels as much as possible - Use
REDUCED_MOVEMENT
to avoid moving labels when they are near other labels, but keep them close to their object - Use
OPTIMAL_SPREAD
to ensure an optimal spread of labels
The default is
OPTIMAL_SPREAD
.- Parameters:
aBehavior
- The desired behavior- Since:
- 2012.1
- Use
-
getLabelMovementBehavior
Indicates when labels are moved.- Returns:
- The current setting
- Since:
- 2012.1
- See Also:
-
setMinDistance
public void setMinDistance(float aMinimumDistance) Set the minimum allowed distance of a label to its anchor point.If set, a label cannot move closer to its anchor point than this distance. The distance is calculated from the point of the label closest to the anchor.
By default, the minimum distance is disabled (
0
). -