Class TLcdGXYFixedOnPathLabelingAlgorithm
- All Implemented Interfaces:
ILcdCloneable,ILcdGXYLabelingAlgorithm,Cloneable
Labels can be aligned left, center, or right relative to a specific point on the path, determined by the relative path position property (a value between 0.0 and 1.0). This property specifies the anchor point along the path geometry for label placement.
Vertical alignment modes (TLcdGXYFixedOnPathLabelingAlgorithm.VerticalAlignment.ABOVE, TLcdGXYFixedOnPathLabelingAlgorithm.VerticalAlignment.CENTER,
TLcdGXYFixedOnPathLabelingAlgorithm.VerticalAlignment.BELOW) control the label's position perpendicular to the path. Horizontal alignment modes
(TLcdGXYFixedOnPathLabelingAlgorithm.HorizontalAlignment.LEFT, TLcdGXYFixedOnPathLabelingAlgorithm.HorizontalAlignment.CENTER, TLcdGXYFixedOnPathLabelingAlgorithm.HorizontalAlignment.RIGHT)
control the label's position along the path's tangent.
Customizable horizontal and vertical offsets provide precise control over label placement. The anchor point determines where on the path the label is placed; alignment modes and offsets control the label's position relative to that anchor. Alignment does not affect the anchor’s location.
This class is useful for applications requiring precise label placement along paths, such as cartographic mapping where labels must follow the curvature of roads, rivers, and similar features.
Choosing between TLcdGXYOnPathLabelingAlgorithm and TLcdGXYFixedOnPathLabelingAlgorithm:
TLcdGXYOnPathLabelingAlgorithmautomatically finds optimal label positions along the path, balancing readability and collision avoidance. Use this for dynamic, automated labeling where label density and overlap are concerns.TLcdGXYFixedOnPathLabelingAlgorithmplaces labels at a fixed, user-specified relative position along the path, with explicit horizontal/vertical alignment and offset. Use this for precise, repeatable label placement (e.g., cartographic standards).TLcdGXYFixedOnPathLabelingAlgorithmoffers separate horizontal and vertical alignment and offset controls, while theTLcdGXYOnPathLabelingAlgorithmprovides general alignment modes (center, inside, outside, left, right, above, below).TLcdGXYOnPathLabelingAlgorithmcan reuse previous label locations for stability during view changes;TLcdGXYFixedOnPathLabelingAlgorithmalways places at the specified position.
- Since:
- 2026.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSpecifies whether the label should be placed left, centered or right aligned with respect to the point on the path.static enumSpecified whether the label should be placed above, below or centered on the path. -
Constructor Summary
ConstructorsConstructorDescriptionTLcdGXYFixedOnPathLabelingAlgorithm(double aRelativeLocation, TLcdGXYFixedOnPathLabelingAlgorithm.VerticalAlignment aVerticalAlignment, TLcdGXYFixedOnPathLabelingAlgorithm.HorizontalAlignment aHorizontalAlignment, double aVerticalOffset, double aHorizontalOffset) Creates a new path labeling algorithm with the specified parameters.TLcdGXYFixedOnPathLabelingAlgorithm(double aRelativeLocation, TLcdGXYFixedOnPathLabelingAlgorithm.VerticalAlignment aVerticalAlignment, TLcdGXYFixedOnPathLabelingAlgorithm.HorizontalAlignment aHorizontalAlignment, double aVerticalOffset, double aHorizontalOffset, ILcdGXYLabelingPathProvider aPathProvider) Creates a new path labeling algorithm with the specified parameters. -
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.Gets the horizontal alignment of the label relative to the point on the path.doubleGets the horizontal offset in pixels from the aligned position.Returns the label placing priority provider.doubleReturns the minimum length for a clipped path to contain a label.Returns the path provider used by this path labeling algorithm.doubleGets the relative position along the path where the label is placed.Gets the vertical alignment of the label relative to the path.doubleGets the vertical offset in pixels from the aligned position.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.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.voidsetHorizontalAlignment(TLcdGXYFixedOnPathLabelingAlgorithm.HorizontalAlignment aHorizontalAlignment) Sets the horizontal alignment of the label relative to the point on the path.voidsetHorizontalOffset(double aHorizontalOffset) Sets the horizontal offset in pixels from the aligned position.voidsetLabelPriorityProvider(ILcdGXYMultiLabelPriorityProvider aLabelPriorityProvider) Sets the label placing priority provider, specifying the priority for individual labels.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.voidsetRelativePathPosition(double aRelativePathPosition) Sets the relative position along the path where the label is anchored.voidsetVerticalAlignment(TLcdGXYFixedOnPathLabelingAlgorithm.VerticalAlignment aVerticalAlignment) Sets the vertical alignment of the label relative to the path.voidsetVerticalOffset(double aVerticalOffset) Sets the vertical offset in pixels from the aligned position.Methods inherited from class com.luciad.view.gxy.labeling.algorithm.discrete.ALcdGXYDiscretePlacementsLabelingAlgorithm
computeLabelPlacements
-
Constructor Details
-
TLcdGXYFixedOnPathLabelingAlgorithm
public TLcdGXYFixedOnPathLabelingAlgorithm(double aRelativeLocation, TLcdGXYFixedOnPathLabelingAlgorithm.VerticalAlignment aVerticalAlignment, TLcdGXYFixedOnPathLabelingAlgorithm.HorizontalAlignment aHorizontalAlignment, double aVerticalOffset, double aHorizontalOffset) Creates a new path labeling algorithm with the specified parameters. The labels are not placed along view bounds.The default path providerTLcdGXYLabelingPathProvideris used. The relative location must be between 0.0 and 1.0 where 0.0 represents the start of the path and 1.0 the end of the path.- Parameters:
aRelativeLocation- The relative location along the path (0.0 to 1.0).aVerticalAlignment- The vertical alignment of the label relative to the path.aHorizontalAlignment- The horizontal alignment of the label relative to the path point.aVerticalOffset- The vertical offset in pixels from the aligned position.aHorizontalOffset- The horizontal offset in pixels from the aligned position.
-
TLcdGXYFixedOnPathLabelingAlgorithm
public TLcdGXYFixedOnPathLabelingAlgorithm(double aRelativeLocation, TLcdGXYFixedOnPathLabelingAlgorithm.VerticalAlignment aVerticalAlignment, TLcdGXYFixedOnPathLabelingAlgorithm.HorizontalAlignment aHorizontalAlignment, double aVerticalOffset, double aHorizontalOffset, ILcdGXYLabelingPathProvider aPathProvider) Creates a new path labeling algorithm with the specified parameters. The relative location must be between 0.0 and 1.0 where 0.0 represents the start of the path and 1.0 the end of the path.- Parameters:
aRelativeLocation- The relative location along the path (0.0 to 1.0).aVerticalAlignment- The vertical alignment of the label relative to the path.aHorizontalAlignment- The horizontal alignment of the label relative to the path point.aVerticalOffset- The vertical offset in pixels from the aligned position.aHorizontalOffset- The horizontal offset in pixels from the aligned position.aPathProvider- The path provider to use for labeling.
-
-
Method Details
-
getHorizontalAlignment
Gets the horizontal alignment of the label relative to the point on the path.- Returns:
- The horizontal alignment.
-
setHorizontalAlignment
public void setHorizontalAlignment(TLcdGXYFixedOnPathLabelingAlgorithm.HorizontalAlignment aHorizontalAlignment) Sets the horizontal alignment of the label relative to the point on the path.- Parameters:
aHorizontalAlignment- The desired horizontal alignment.
-
getHorizontalOffset
public double getHorizontalOffset()Gets the horizontal offset in pixels from the aligned position.- Returns:
- The horizontal offset.
-
setHorizontalOffset
public void setHorizontalOffset(double aHorizontalOffset) Sets the horizontal offset in pixels from the aligned position. The offset is applied along the tangent of the path at the label position.- Parameters:
aHorizontalOffset- The desired horizontal offset.
-
getVerticalAlignment
Gets the vertical alignment of the label relative to the path.- Returns:
- The vertical alignment.
-
setVerticalAlignment
public void setVerticalAlignment(TLcdGXYFixedOnPathLabelingAlgorithm.VerticalAlignment aVerticalAlignment) Sets the vertical alignment of the label relative to the path.- Parameters:
aVerticalAlignment- The desired vertical alignment.
-
getVerticalOffset
public double getVerticalOffset()Gets the vertical offset in pixels from the aligned position.- Returns:
- The vertical offset.
-
setVerticalOffset
public void setVerticalOffset(double aVerticalOffset) Sets the vertical offset in pixels from the aligned position. The offset is applied perpendicular to the path at the label position.- Parameters:
aVerticalOffset- The desired vertical offset.
-
getRelativePathPosition
public double getRelativePathPosition()Gets the relative position along the path where the label is placed.- Returns:
- The relative path position (between 0.0 and 1.0).
-
setRelativePathPosition
public void setRelativePathPosition(double aRelativePathPosition) Sets the relative position along the path where the label is anchored. The value must be between 0.0 (start of the path) and 1.0 (end of the path), inclusive. This property determines the anchor point for label placement along the path geometry, independent of alignment or offset settings.- Parameters:
aRelativePathPosition- the desired relative path position, between 0.0 and 1.0 inclusive- Throws:
IllegalArgumentException- if the value is outside the range [0.0, 1.0]
-
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.
-
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.
-
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:
-
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, no label priorities are set.
The priority provider is used to sort the list of labels before their placements are computed.
- Parameters:
aLabelPriorityProvider- The priority provider to set.
-