public final class PolylineCreator extends Object implements AutoCloseable, IGeometryCreator
It reacts on input events
to create polylines. The event handling behavior can be restricted based on the currently set line creation mode
.
The events handled in Click mode
are:
Click
events to append one point, and start inserting a new one. This results in changes
that are ChangeStatus#InProgressKeyPoint
, or ChangeStatus#Finished
when reaching the maximum point count
.
Mouse move
events to position the next individual point. This results in changes
that are ChangeStatus#InProgress
.
Double click
or long touch press
events to append a point, and finish creation. Long touch press events are only reacted upon if points were previously added via touch tap. This results in changes
that are ChangeStatus#Finished
, or ChangeStatus#InProgressKeyPoint
when the maximum point count
is not reached yet.
The events handled in Freehand mode
are:
Drag
events to continuously add points. Creation starts, with points being added as long as the drag event is ongoing, and creation is finished when dragging stops. Points are not added on every Drag
event, indeed a heuristic is used to only add a point when the distance to the previous point or the curvature is high enough.
changes
that are ChangeStatus#InProgressKeyPoint
if a new point is added, ChangeStatus#InProgress
if the drag move does not trigger a new point (i.e. the distance is too short compared to the previous point), or ChangeStatus#Finished
when the drag ends.
In Automatic mode
(the default creation mode), the first event since creation is started determines how polyline points are added. If the first event is a mouse click or touch tap
, events are added in Click
mode. If a drag
event is initiated, points are added in Freehand
mode.
It is possible to constrain polyline creation using:
minimum
point count
maximum
point count
constraint
This class does not allow you to interactively choose the elevation of the points. The elevation will by default be set to 0.
Constructor and Description |
---|
PolylineCreator(CoordinateReference reference)
Creates a new polyline creator instance.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected void |
finalize() |
IPolylineConstraint |
getConstraint() |
LineCreationMode |
getLineCreationMode() |
LineInterpolationType |
getLineInterpolationType() |
long |
getMaxPointCount() |
long |
getMinPointCount() |
EventResult |
onEvent(IInputEvent inputEvent,
FeatureCreateContext context)
Handles the given event, and returns if the event was handled or not.
|
void |
setConstraint(IPolylineConstraint constraint)
Sets the constraint to use during creation.
|
void |
setLineCreationMode(LineCreationMode mode)
The line creation mode is
Automatic by default. |
void |
setLineInterpolationType(LineInterpolationType lineInterpolationType)
Sets the line interpolation that is used for the geometry.
|
void |
setMaxPointCount(long maxPointCount)
Sets the maximum amount of points a polyline can have.
|
void |
setMinPointCount(long minPointCount)
Sets the minimum amount of points a polyline can have.
|
void |
start(IGeometryCreateCallback callback,
FeatureCreateContext context)
This method is called to start creation.
|
public PolylineCreator(@NotNull CoordinateReference reference)
reference
- the reference of the created polylinepublic void close()
close
in interface AutoCloseable
public void start(@NotNull IGeometryCreateCallback callback, @NotNull FeatureCreateContext context) throws NullPointerException
After this call, IGeometryCreator#onEvent
can be called.
When a IGeometryCreator
was started, it can not be started again until it has finished
. Implementations of this method are encouraged to throw an exception in that case to signal a programming error by the caller of this method.
start
in interface IGeometryCreator
callback
- the callback to signal geometry changes, and whether creation for the geometry has finished, cannot be null
.context
- the context, cannot be null
NullPointerException
- when null
is passed.@NotNull public EventResult onEvent(@NotNull IInputEvent inputEvent, @NotNull FeatureCreateContext context) throws NullPointerException
onEvent
in interface IGeometryCreator
inputEvent
- an event, cannot be null
context
- the context, cannot be null
NullPointerException
- when null
is passed.public void setConstraint(@Nullable IPolylineConstraint constraint)
The default is no constraint.
The constraint behavior is as follows:
PolylineChange
.
point insert
.
Constraints are not allowed to change the point count during creation. Doing this will result in an exception.
constraint
- the constraint. Can be null
.@Nullable public IPolylineConstraint getConstraint()
null
.setConstraint
public void setLineInterpolationType(@NotNull LineInterpolationType lineInterpolationType)
The default is LineInterpolationType#Geodesic
.
lineInterpolationType
- the line interpolation to use@NotNull public LineInterpolationType getLineInterpolationType()
public void setMinPointCount(long minPointCount) throws IllegalArgumentException
The creator cannot finish creation before the created polyline has at least this minimum point count. By default, this value is 2.
If the creation mode
is LineCreationMode#Freehand
, the feature creation is always finished when the final
DragEvent
is received. If not enough point were generated prior to it, the created polyline is filled with the needed amount of points at the last received location.
minPointCount
- the minimum number of points allowed.IllegalArgumentException
- if minPointCount
is lower than 2, or higher than the current max point count
.public long getMinPointCount()
setMinPointCount
public void setMaxPointCount(long maxPointCount) throws IllegalArgumentException
The creator automatically finishes creation when the polyline reaches this maximum point count. By default, this value is the maximum value of long
, which realistically corresponds to "no maximum".
maxPointCount
- the maximum number of points allowed.IllegalArgumentException
- if maxPointCount
is lower than the current min point count
.public long getMaxPointCount()
setMaxPointCount
public void setLineCreationMode(@NotNull LineCreationMode mode)
Automatic
by default.mode
- the creation mode that is used.LineCreationMode
@NotNull public LineCreationMode getLineCreationMode()
LineCreationMode