Class TLcdGXYOnPathLabelingAlgorithm
- All Implemented Interfaces:
ILcdCloneable,ILcdGXYLabelingAlgorithm,Cloneable
setMinimumGap(double).
There are a few ways to determine on which side of the path the label lies, see
setAlignmentMode.
The used label painter must be an ILcdGXYLabelPainter2. If not,
the label will be painted at an incorrect location.
The implementation of this labeling algorithm is thread-safe, as long as the set
ILcdGXYLabelingPathProvider is thread-safe.
- Since:
- 10.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAlignment mode that determines if label are placed on, outside or inside the paths. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new on path labeling algorithm that can be used to place labels on or along paths.TLcdGXYOnPathLabelingAlgorithm(ILcdGXYLabelingPathProvider aPathProvider, boolean aPlaceLabelsAlongViewBounds) Creates a new on path labeling algorithm that can be used to place labels on or along paths returned by the given path provider. -
Method Summary
Modifier and TypeMethodDescriptionclone()MakesObject.clone()public.collectLabelInfo(List<TLcdLabelIdentifier> aLabelsToCollect, Graphics aGraphics, ILcdGXYView aGXYView) This method returns aTLcdCollectedLabelInfoListobject based on the given list ofTLcdLabelIdentifiers.protected Iterator<TLcdCollectedLabelInfo> createLabelIterator(TLcdCollectedLabelInfoList aLabelInfoList, ILcdLabelConflictChecker aBoundsConflictChecker, ILcdGXYView aView) Creates a newIteratorthat iterates over theTLcdCollectedLabelInfos.protected ILcdLabelPlacementEvaluatorcreateLabelPlacementEvaluator(TLcdCollectedLabelInfoList aLabelInfoList, ILcdLabelConflictChecker aBoundsConflictChecker, ILcdGXYView aView) Creates a newILcdLabelPlacementEvaluatorusing the given parameters.protected Iterator<TLcdLabelPlacement> createLabelPlacementIterator(TLcdCollectedLabelInfo aLabel, TLcdCollectedLabelInfoList aLabelInfoList, ILcdLabelConflictChecker aBoundsConflictChecker, ILcdGXYView aView) Creates a newIteratorthat iterates over theTLcdLabelPlacements for the given label.doubleReturns the additional offset value.Returns the alignment used for the placed labels.Returns the label placing priority provider.intReturns the maximum number ofTLcdLabelPlacements tried to place a label.doubleReturns the minimum gap between two labels on the same path.doubleReturns the minimum length for a clipped path to contain a label.Returns the path provider used by this path labeling algorithm.booleanReturns if it is allowed for this labeling algorithm to place labels upside down.booleanReturns if it is allowed for this labeling algorithm to rotate labels.booleanReturns if this algorithm reuses the previous label locations.voidsetAdditionalOffset(double aAdditionalOffset) Sets an additional offset value.voidsetAlignmentMode(TLcdGXYOnPathLabelingAlgorithm.AlignmentMode aAlignmentMode) Sets the alignment for the placed labels.voidsetAllowLabelsUpsideDown(boolean aAllowLabelsUpsideDown) Sets if it is allowed for this labeling algorithm to place labels upside down.voidsetAllowRotation(boolean aAllowRotation) Sets if it is allowed for this labeling algorithm to rotate labels.voidsetLabelPriorityProvider(ILcdGXYMultiLabelPriorityProvider aLabelPriorityProvider) Sets the label placing priority provider, specifying the priority for individual labels.voidsetMaximumAttemptCount(int aMaximumAttemptCount) Sets the maximum number ofTLcdLabelPlacements tried to place a label.voidsetMinimumGap(double aMinimumGap) Sets the minimum gap between two labels on the same path.voidsetMinimumPathLength(double aMinimumPathLength) Sets the minimum length for a clipped path to contain a label.voidsetPathProvider(ILcdGXYLabelingPathProvider aPathProvider) Sets the path provider to be used by this path labeling algorithm.voidsetReusePreviousLocations(boolean aReusePreviousLocations) When set totrue, this labeling algorithm will try to reuse the previous label locations.Methods inherited from class com.luciad.view.gxy.labeling.algorithm.discrete.ALcdGXYDiscretePlacementsLabelingAlgorithm
computeLabelPlacements
-
Constructor Details
-
TLcdGXYOnPathLabelingAlgorithm
public TLcdGXYOnPathLabelingAlgorithm()Creates a new on path labeling algorithm that can be used to place labels on or along paths. When using this constructor,TLcdGXYLabelingPathProvideris used as path provider and labels are not placed along the view bounds. -
TLcdGXYOnPathLabelingAlgorithm
public TLcdGXYOnPathLabelingAlgorithm(ILcdGXYLabelingPathProvider aPathProvider, boolean aPlaceLabelsAlongViewBounds) Creates a new on path labeling algorithm that can be used to place labels on or along paths returned by the given path provider.- Parameters:
aPathProvider- a path provider.aPlaceLabelsAlongViewBounds-trueif labels should also be placed along the view bounds, orfalseotherwise.
-
-
Method Details
-
getMinimumGap
public double getMinimumGap()Returns the minimum gap between two labels on the same path.- Returns:
- the minimum gap between two labels on the same path.
- See Also:
-
setMinimumGap
public void setMinimumGap(double aMinimumGap) Sets the minimum gap between two labels on the same path. This distance is expressed in pixels and should be positive.The default value is 100 pixels.
- Parameters:
aMinimumGap- the minimal gap between two labels on the same path.
-
getMinimumPathLength
public double getMinimumPathLength()Returns the minimum length for a clipped path to contain a label.- Returns:
- the minimum length for a clipped path to contain a label.
- See Also:
-
setMinimumPathLength
public void setMinimumPathLength(double aMinimumPathLength) Sets the minimum length for a clipped path to contain a label. This length is expressed in pixels and should be positive. When a clipped path has a length smaller than the given length, it will not be labeled.The default value is 0 pixels, i.e. no path will be excluded from being labeled.
- Parameters:
aMinimumPathLength- the minimal length for a clipped path to contain a label.
-
getMaximumAttemptCount
public int getMaximumAttemptCount()Returns the maximum number ofTLcdLabelPlacements tried to place a label.- Returns:
- the maximum number of
TLcdLabelPlacements tried to place a label. - See Also:
-
setMaximumAttemptCount
public void setMaximumAttemptCount(int aMaximumAttemptCount) Sets the maximum number ofTLcdLabelPlacements tried to place a label. This parameter can be adjusted to tweak the performance of this labeling algorithm. A lower value is more efficient while a higher value allows more placements, and increases the chance that a valid label placement is found.By default this value is
8.- Parameters:
aMaximumAttemptCount- the maximum number ofTLcdLabelPlacements tried to place a label.- See Also:
-
getAlignmentMode
Returns the alignment used for the placed labels.- Returns:
- the alignment used for the placed labels.
- See Also:
-
setAlignmentMode
Sets the alignment for the placed labels. In case this value is INSIDE or OUTSIDE, LEFT, RIGHT, ABOVE or BELOW, the label is offset in the direction perpendicular to the path by half of its height and an additional offset ( seegetAdditionalOffset()).By default, this value is CENTER
- Parameters:
aAlignmentMode- the alignment for the placed labels.
-
getAdditionalOffset
public double getAdditionalOffset()Returns the additional offset value.- Returns:
- the additional offset value.
- See Also:
-
setAdditionalOffset
public void setAdditionalOffset(double aAdditionalOffset) Sets an additional offset value. This offset is only used when the alignment mode (getAlignmentMode()) is eitherOUTSIDE,INSIDE, LEFT, RIGHT, ABOVE or BELOW. The offset determines the distance in pixels of the label from the path. The given distance should be a positive value.The default value is
1.0.- Parameters:
aAdditionalOffset- an additional offset value.
-
isAllowLabelsUpsideDown
public boolean isAllowLabelsUpsideDown()Returns if it is allowed for this labeling algorithm to place labels upside down.- Returns:
- if it is allowed for this labeling algorithm to place labels upside down.
- See Also:
-
setAllowLabelsUpsideDown
public void setAllowLabelsUpsideDown(boolean aAllowLabelsUpsideDown) Sets if it is allowed for this labeling algorithm to place labels upside down. If set totrue, there is no restriction on the rotation of the labels. If set tofalse, labels that are rotated upside down are rotated 180 degrees around their center. In this context, upside down means that the rotation of the label lies between 90 and 270 degrees, assuming that 0 degrees lies at 3 'o clock.The default value is
false.- Parameters:
aAllowLabelsUpsideDown-trueto allow labels being painted upside done, andfalseotherwise.- See Also:
-
isAllowRotation
public boolean isAllowRotation()Returns if it is allowed for this labeling algorithm to rotate labels.- Returns:
- if it is allowed for this labeling algorithm to rotate labels.
- See Also:
-
setAllowRotation
public void setAllowRotation(boolean aAllowRotation) Sets if it is allowed for this labeling algorithm to rotate labels. If set totrue, labels will be rotated in order to follow the path. If set tofalse, labels will not be rotated, and will be placed on the path.The default value is
true.- Parameters:
aAllowRotation-trueto allow labels to be rotated, andfalseotherwise.- See Also:
-
getPathProvider
Returns the path provider used by this path labeling algorithm.- Returns:
- the path provider used by this path labeling algorithm.
-
setPathProvider
Sets the path provider to be used by this path labeling algorithm.- Parameters:
aPathProvider- the path provider to be used by this path labeling algorithm.
-
getLabelPriorityProvider
Returns the label placing priority provider.- Returns:
- the label placing priority provider.
- See Also:
-
setLabelPriorityProvider
Sets the label placing priority provider, specifying the priority for individual labels. This priority provider specifies the order in which labels are placed. In the event labels overlap, those with higher priority are painted on top of labels with lower priority. So lower priority labels are the first candidates if labels need to be obscured.When no label priority provider is set, a default label priority provider is used which returns
Integer.MAX_VALUEfor all labels.The priority provider is used to sort the list of labels before their placements are computed.
- Parameters:
aLabelPriorityProvider- The priority provider to set.
-
isReusePreviousLocations
public boolean isReusePreviousLocations()Returns if this algorithm reuses the previous label locations.- Returns:
trueif this algorithm reuses the previous label locations.- See Also:
-
setReusePreviousLocations
public void setReusePreviousLocations(boolean aReusePreviousLocations) When set totrue, this labeling algorithm will try to reuse the previous label locations. Reusing previous label locations causes the labels to be some more stable, i.e. labels don't always move when for example the view is panned, or when labeled objects are selected. This is because label positions are only recalculated when the previous label location has become invalid.When using this option,
getMinimumGap()will still be respected. Because of this the previous label location will not be reused in some cases.Trying to place a label at the previous label location will count as one attempt out of
getMaximumAttemptCount(). The previous label location will always be attempted first.Note: For this option to work, the domain objects for which labels are placed should implement
ILcdCache. When they do not implementILcdCachethe labels of those domain object behave as if this option is set tofalse.The default value is
false.- Parameters:
aReusePreviousLocations-trueto enable reusing previous label locations, andfalseto disable it.- See Also:
-
clone
Description copied from interface:ILcdCloneableMakes
When for example extending fromObject.clone()public.java.lang.Object, it can be implemented like this:public Object clone() { try { return super.clone(); } catch ( CloneNotSupportedException e ) { // Cannot happen: extends from Object and implements Cloneable (see also Object.clone) throw new RuntimeException( e ); } }- Specified by:
clonein interfaceILcdCloneable- See Also:
-
collectLabelInfo
public TLcdCollectedLabelInfoList collectLabelInfo(List<TLcdLabelIdentifier> aLabelsToCollect, Graphics aGraphics, ILcdGXYView aGXYView) Description copied from interface:ILcdGXYLabelingAlgorithmThis method returns aTLcdCollectedLabelInfoListobject based on the given list ofTLcdLabelIdentifiers. The returnedTLcdCollectedLabelInfoListshould contain aTLcdCollectedLabelInfoobject for each label that should be placed.Each
TLcdCollectedLabelInfoshould also contain all information needed bycomputeLabelPlacementsto place the labels. In order to enable correct asynchronous label placing, all calls to the layer and the (label) painters should be done in this method. The results should then be stored in the info objects.It is possible that the returned
TLcdCollectedLabelInfoListdoesn't contain aTLcdCollectedLabelInfoobject for every givenTLcdLabelIdentifier. In that case the missing labels are not placed.- Specified by:
collectLabelInfoin interfaceILcdGXYLabelingAlgorithm- Parameters:
aLabelsToCollect- the labels for which aTLcdCollectedLabelInfoListshould be created.aGraphics- the graphics.aGXYView- the view.- Returns:
- a
TLcdCollectedLabelInfoListwhich contains all the information needed to place the labels.
-
createLabelIterator
protected Iterator<TLcdCollectedLabelInfo> createLabelIterator(TLcdCollectedLabelInfoList aLabelInfoList, ILcdLabelConflictChecker aBoundsConflictChecker, ILcdGXYView aView) Description copied from class:ALcdGXYDiscretePlacementsLabelingAlgorithmCreates a newIteratorthat iterates over theTLcdCollectedLabelInfos. The abstract labeling algorithm will continue iterating overTLcdCollectedLabelInfos as long asIterator.hasNext()returnstrue. When it returnsfalse, no more labels will be tried, andcomputeLabelPlacementsreturns.Iterator.hasNext()should always be called before callingIterator.next(), and if it returnstrue,Iterator.next()should never returnnull.The implementation of this method should be as independent as possible. It should not rely on
createLabelPlacementIteratororcreateLabelPlacementEvaluator. Not respecting this might result in unexpected behaviour when wrapping or extending this class.The returned
TLcdCollectedLabelInfoshould be correctly initialized, i.e. it should contain all information needed to create validTLcdLabelPlacements usingcreateLabelPlacementIterator. It should also always point to its correspondingTLcdCollectedLabeledObjectInfo.Override this method to provide a custom implementation.
- Specified by:
createLabelIteratorin classALcdGXYDiscretePlacementsLabelingAlgorithm- Parameters:
aLabelInfoList- the label infos object that contains all information needed to place the labels.aBoundsConflictChecker- the bounds conflict checker to be used when evaluating label placements.aView- the view.- Returns:
- a new
Iteratorthat iterates overTLcdCollectedLabelInfos.
-
createLabelPlacementIterator
protected Iterator<TLcdLabelPlacement> createLabelPlacementIterator(TLcdCollectedLabelInfo aLabel, TLcdCollectedLabelInfoList aLabelInfoList, ILcdLabelConflictChecker aBoundsConflictChecker, ILcdGXYView aView) Description copied from class:ALcdGXYDiscretePlacementsLabelingAlgorithmCreates a newIteratorthat iterates over theTLcdLabelPlacements for the given label. The abstract labeling algorithm will continue iterating overTLcdLabelPlacements as long asIterator.hasNext()returnstrue. When it returnsfalse, a new label will be tried.Iterator.hasNext()should always be called before callingIterator.next(), and if it returnstrue,Iterator.next()should never returnnull.The implementation of this method should be as independent as possible. It should not rely on
createLabelIteratororcreateLabelPlacementEvaluator. Not respecting this might result in unexpected behaviour when wrapping or extending this class.The returned
TLcdLabelPlacementshould be correctly initialized, i.e. it should at least be able to return a valid label location, bounds rectangle and bounds rotation. It should also reference its correspondingTLcdCollectedLabelInfo.Override this method to provide a custom implementation.
- Specified by:
createLabelPlacementIteratorin classALcdGXYDiscretePlacementsLabelingAlgorithm- Parameters:
aLabel- the label for which an iterator should be created.aLabelInfoList- the info object that contains all information needed to place the labels.aBoundsConflictChecker- the bounds conflict checker to be used when evaluating label placements.aView- the view.- Returns:
- a new
Iteratorthat iterates overTLcdLabelPlacements.
-
createLabelPlacementEvaluator
protected ILcdLabelPlacementEvaluator createLabelPlacementEvaluator(TLcdCollectedLabelInfoList aLabelInfoList, ILcdLabelConflictChecker aBoundsConflictChecker, ILcdGXYView aView) Description copied from class:ALcdGXYDiscretePlacementsLabelingAlgorithmCreates a newILcdLabelPlacementEvaluatorusing the given parameters. It evaluates the placements returned bycreateLabelPlacementIterator, and returns aPlacementResultto denote if the placement should be used for its label or not.The following actions are undertaken for the following placement results :
PlacementResult.SUCCESS: the given label placement will be used for its label, it will be added to the list of placed labels, and it will be added to the givenILcdLabelConflictChecker. After that,ILcdLabelPlacementEvaluator.placementAppliedwill be called and no more placements are tried for the label.PlacementResult.FALLBACK: the abstract algorithm will try to find an other placements which returnsPlacementResult.SUCCESS. When no such placement is found, this placement will be added to the list of placed labels, and it will be added to the givenILcdLabelConflictChecker. After that,ILcdLabelPlacementEvaluator.placementAppliedwill be called.PlacementResult.TRY_NEW_PLACEMENT: the abstract algorithm will try to find an other placement which returnsPlacementResult.SUCCESSorPlacementResult.FALLBACK. When no such placement is found,ILcdLabelPlacementEvaluator.noPlacementAppliedis called.PlacementResult.FAILED: the abstract algorithm will immediately callILcdLabelPlacementEvaluator.noPlacementAppliedand will not try to find other placements for the label.
Override this method to provide a custom implementation.
- Specified by:
createLabelPlacementEvaluatorin classALcdGXYDiscretePlacementsLabelingAlgorithm- Parameters:
aLabelInfoList- the info object that contains all information needed to place the labels.aBoundsConflictChecker- the bounds conflict checker to be used when evaluating label placements.aView- the view- Returns:
- a new LabelPlacementEvaluator
- See Also:
-