Class TLspFixedOnPathLabelLocationProvider
This label location provider positions points on a specific location on a line. This algorithm works for all shapes
that implement ILcdCurve
. To retrieve this curve, the anchor object of a label is used.
When the anchor object of the label is a composite shape, like an ILcdShapeList
or
ILcdComplexPolygon
, this label location provider first tries to find the largest sub-shape
and then finds a location for this sub-shape.
This label location provider only calculates a single label location. So if this label overlaps with an other
label, no alternative locations are available. If this functionality is needed, it can be done by creating a
composite TLspFixedOnPathLabelLocationProvider
.
Unlike TLspOnPathLabelingAlgorithm
, this label location provider doesn't try to keep the label inside the
view. When navigating away from the label location, no label location within the view bounds is
calculated. Because of this, this labeling location provider works more efficiently CPU-wise. On top of
that, this label location provider works by specifying a specific location on the line.
The used label painter must be an ILspStampLocationLabelPainter
.
If not, the label will not be placed. The placed label location will be a
ALspStampLabelLocation
.
To use this label location provider to create a labeling algorithm, the following code can be used:
TLspFixedOnPathLabelLocationProvider provider = new TLspFixedOnPathLabelLocationProvider();
TLspLabelingAlgorithm algorithm = new TLspLabelingAlgorithm(provider);
- Since:
- 2016.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Represents the horizontal alignment, i.e. the offset of the label parallel to the path, relative to the chosen point on the path.static enum
Represents the vertical alignment, i.e. the offset of the label perpendicular to the line. -
Constructor Summary
ConstructorDescriptionTLspFixedOnPathLabelLocationProvider
(double aRelativeLocation, TLspFixedOnPathLabelLocationProvider.VerticalAlignment aVerticalAlignment, TLspFixedOnPathLabelLocationProvider.HorizontalAlignment aHorizontalAlignment, double aVerticalOffset, double aHorizontalOffset) Creates a newTLspFixedOnPathLabelLocationProvider
. -
Method Summary
Modifier and TypeMethodDescriptiongetLocation
(TLspLabelID aLabel, int aLocationIndex, ALspLabelLocations aCurrentLabelLocations, TLspPaintState aPaintState, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspView aView) This method returns a location for the given label using the given location index.int
getMaxLocationCount
(TLspLabelID aLabel, TLspPaintState aPaintState, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspView aView) Returns the maximal number of locations to be tried for the given label.boolean
Returns if it is allowed for this location provider to place labels upside down.boolean
isValidLocation
(TLspLabelPlacement aLocation, ALspLabelLocations aCurrentLabelLocations, TLspPaintState aPaintState, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspView aView) Checks if the given location is a valid location.void
setAllowUpsideDown
(boolean aAllowUpsideDown) Sets if it is allowed for this location provider to place labels upside down.toString()
-
Constructor Details
-
TLspFixedOnPathLabelLocationProvider
public TLspFixedOnPathLabelLocationProvider(double aRelativeLocation, TLspFixedOnPathLabelLocationProvider.VerticalAlignment aVerticalAlignment, TLspFixedOnPathLabelLocationProvider.HorizontalAlignment aHorizontalAlignment, double aVerticalOffset, double aHorizontalOffset) Creates a newTLspFixedOnPathLabelLocationProvider
.- Parameters:
aRelativeLocation
- the location of the label, relative on the line. Values should lie in the interval [0, 1]. If not, anIllegalArgumentException
is thrown.aVerticalAlignment
- the alignment of the label perpendicular to the lineaHorizontalAlignment
- the alignment of the label with respect to the location on the line (parallel to the line):aVerticalOffset
- vertical space between the location on the line and the label in pixelsaHorizontalOffset
- horizontal space between the location and the label in pixels
-
-
Method Details
-
isAllowUpsideDown
public boolean isAllowUpsideDown()Returns if it is allowed for this location provider to place labels upside down.- Returns:
- if it is allowed for this location provider to place labels upside down.
- Since:
- 2022.0
- See Also:
-
setAllowUpsideDown
public void setAllowUpsideDown(boolean aAllowUpsideDown) Sets if it is allowed for this location provider 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:
aAllowUpsideDown
-true
to allow labels being painted upside done, andfalse
otherwise.- Since:
- 2022.0
- See Also:
-
getMaxLocationCount
public int getMaxLocationCount(TLspLabelID aLabel, TLspPaintState aPaintState, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspView aView) Description copied from class:ALspLabelLocationProvider
Returns the maximal number of locations to be tried for the given label. Override this method to return a custom number of locations. When overriding this method, one should also make sure that thegetLocation
method can create the same number of locations as returned by this method. By default, this method returns1
.- Overrides:
getMaxLocationCount
in classALspLabelLocationProvider
- Parameters:
aLabel
- the label.aPaintState
- the paint state.aLabelContext
- provides context information, such as priorities, PaintState, ...aView
- the view.- Returns:
- the maximal number of locations to be tried.
-
isValidLocation
public boolean isValidLocation(TLspLabelPlacement aLocation, ALspLabelLocations aCurrentLabelLocations, TLspPaintState aPaintState, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspView aView) Description copied from class:ALspLabelLocationProvider
Checks if the given location is a valid location. This check should be used if this label location provider is capable of producing the given location. Labeling algorithms may use this method for previous label locations. I.e. when using a previous label locations, this method can be used to verify if the previous label location can be used. By default, this method returnstrue
.- Overrides:
isValidLocation
in classALspLabelLocationProvider
- Parameters:
aLocation
- the location to check.aCurrentLabelLocations
- an ALspLabelLocations object containing locations for the currently placed labels.aPaintState
- the paint state.aLabelContext
- provides context information, such as priorities, PaintState, ...aView
- the view.- Returns:
- if the given location is a valid location.
-
getLocation
public TLspLabelPlacement getLocation(TLspLabelID aLabel, int aLocationIndex, ALspLabelLocations aCurrentLabelLocations, TLspPaintState aPaintState, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspView aView) Description copied from class:ALspLabelLocationProvider
This method returns a location for the given label using the given location index. Override this method to create custom locations for a label.- Specified by:
getLocation
in classALspLabelLocationProvider
- Parameters:
aLabel
- a label.aLocationIndex
- the location index.aCurrentLabelLocations
- an ALspLabelLocations object containing locations for the currently placed labels.aPaintState
- the paint stateaLabelContext
- provides context information, such as priorities, PaintState, ...aView
- the view.- Returns:
- the label location for the given label and index, or
null
if no location could be calculated.
-
toString
-