public class TLspLabelPlacer extends Object implements ILspLabelPlacer
Default implementation of ILspLabelPlacer
.
This label placer defines methods that can be used to
configure a placer using groups. Groups can be added using addPlacementGroup
. By default, four groups are already added :
DEFAULT_DECLUTTER_GROUP
: this group is used by default for all layers and all their labels. No labels in this group can overlap.DEFAULT_NO_DECLUTTER_GROUP: this group can be used for labels that should always be shown, even if they overlap.
DEFAULT_GRID_GROUP
: this group is used for grid labels by default. Because this is a separate group, grid labels are decluttered amongst themselves, but they can still overlap with other labels.DEFAULT_REALTIME_GROUP
: this convenience group can be used when labeling dynamic data, for example tracks. This group allows them to be decluttered independently from static labels.
This label placer does its work asynchronously using the ILspTaskExecutor
.
Calls to placeLabels()
simply schedule a new placement cycle. Use isFinished()
to determine if any placement is still ongoing or scheduled.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DECLUTTER_GROUP
Default group for labels that should not overlap.
|
static String |
DEFAULT_GRID_GROUP
Default group for grid labels.
|
static String |
DEFAULT_NO_DECLUTTER_GROUP
Default group for labels that can overlap.
|
static String |
DEFAULT_REALTIME_GROUP
Default group for realtime labels.
|
Constructor and Description |
---|
TLspLabelPlacer(ILspView aView)
Creates a label placer with the four default groups already added :
DEFAULT_DECLUTTER_GROUP , DEFAULT_NO_DECLUTTER_GROUP , DEFAULT_GRID_GROUP and DEFAULT_REALTIME_GROUP . |
Modifier and Type | Method and Description |
---|---|
void |
addLabelObstacleProvider(String aPlacementGroupID,
ILspLabelObstacleProvider aLabelObstacleProvider)
Attaches an obstacle provider to a label group.
|
void |
addPlacementGroup(String aPlacementGroupID,
ILspLabelConflictChecker aConflictChecker)
Adds a new group with the given settings to this placer.
|
void |
destroy()
Frees resources and tasks associated with this placer.
|
ALspLabelLocations |
getLabelLocations()
Returns the label locations object.
|
Collection<String> |
getPlacementGroups()
Returns a collection of all available placement groups.
|
boolean |
isFinished()
Indicates whether all calls to
ILspLabelPlacer.placeLabels() are completely processed or not. |
void |
placeLabels()
Place the labels for the associated view.
|
void |
removeLabelObstacleProvider(String aPlacementGroupID,
ILspLabelObstacleProvider aLabelObstacleProvider)
Detaches an obstacle provider from the group with the given id.
|
void |
removePlacementGroup(String aPlacementGroupID)
Removes a placement group from this placer.
|
public static final String DEFAULT_DECLUTTER_GROUP
public static final String DEFAULT_NO_DECLUTTER_GROUP
public static final String DEFAULT_GRID_GROUP
public static final String DEFAULT_REALTIME_GROUP
public TLspLabelPlacer(ILspView aView)
DEFAULT_DECLUTTER_GROUP
, DEFAULT_NO_DECLUTTER_GROUP
, DEFAULT_GRID_GROUP
and DEFAULT_REALTIME_GROUP
.aView
- The view this placer is used forpublic void addPlacementGroup(String aPlacementGroupID, ILspLabelConflictChecker aConflictChecker)
addLabelObstacleProvider(java.lang.String, com.luciad.view.lightspeed.label.ILspLabelObstacleProvider)
as well as in with ALspLabelStyleCollector.group(String)
.
Different groups are placed independently. So labels for two different groups may overlap.
aPlacementGroupID
- a group identifier.aConflictChecker
- the group's conflict checker.public void removePlacementGroup(String aPlacementGroupID)
The group cannot be used afterwards. If the group is still used by any label, results are unspecified.
aPlacementGroupID
- a group identifier.public Collection<String> getPlacementGroups()
public void addLabelObstacleProvider(String aPlacementGroupID, ILspLabelObstacleProvider aLabelObstacleProvider)
The label placer will try not the place labels on the areas indicated by this provider.
Note: you are responsible for de-registering the obstacle provider.
aPlacementGroupID
- the group id, see addPlacementGroup
.aLabelObstacleProvider
- the obstacle provider.public void removeLabelObstacleProvider(String aPlacementGroupID, ILspLabelObstacleProvider aLabelObstacleProvider)
aPlacementGroupID
- the group id, see addPlacementGroup
.aLabelObstacleProvider
- the obstacle provider.public ALspLabelLocations getLabelLocations()
ILspLabelPlacer
getLabelLocations
in interface ILspLabelPlacer
public void destroy()
Note: this call prevents additional placements from being scheduled, but
does not abort running placements. Normally, a view will shut down its ILspTaskExecutor
,
which will stop any running placements.
destroy
in interface ILspLabelPlacer
public boolean isFinished()
ILspLabelPlacer.placeLabels()
are completely processed or not.
In particular, if any placement is ongoing asyncronously, or if any placement is queued for
execution, this method returns false
.
isFinished
in interface ILspLabelPlacer
true
if there is no placement busy or scheduled, false
otherwise.public void placeLabels()
Place the labels for the associated view. In this method label placement and label decluttering can be performed.
It is advised to perform the actual work asynchronously, and have this method simply schedule a placement cycle. This is not mandatory however.
You can use ILspLabelPlacer.isFinished()
at any time to determine if this call is completely
processed.
This call schedules a placement cycle for asynchronous execution. If this placer is already busy placing labels, a new placement step is scheduled.
placeLabels
in interface ILspLabelPlacer