This guide explains how you can interactively create features on a Map, and integrate this capability in an
IController
.
Overview
You start the process of interactive feature creation by sending input events
to a creator
. A feature creator
creates the feature, and a geometry creator
creates its geometry.
The feature creator can convert
the created
geometries to a feature, and adds
them to the model.
Programmatically creating geometries
If you want to create geometries through the API instead of creating them interactively on the map, see the related article on geometries |
Configuring feature creation
To configure feature creation, you can use these classes:
-
Creator::Builder
to configure:-
The
feature layer
to add the new features to. -
The
feature creator
that defines how to create the feature, and which geometry to use. -
An
observer
that signals when a feature was added to the model, or if feature creation failed.
-
-
The
geometry provider
to specify how to apply created geometries to the initial feature. -
An
initial feature
to add the created geometry to.
Integrating a creator with a controller
You can use the Creator class as a part of an IController
implementation.
To integrate the feature creator:
-
Delegate the
input events
. The creator may or may not consume those events. Based on that information, the controller can decide to ignore the event, or use it for something else. For example, a creator can ignore mouse drag events, and use only mouse moves and click events. The controller can then still use the drag events to navigate the map. -
Add the
preview layer
to the controller’slayer list
. You must do that so that the map can visualize a preview of the created feature.
Setting line creation modes to define input events
The line creation mode
defines how input events generate a line by placing points in sequence.
The supported line creation modes are:
-
Click mode
- Each point is added at amouse click
ortouch tap
event. Creation is concluded with adouble click
or atouch long press
event. -
Freehand mode
- Points are sequentially added during adrag
gesture. The drag gesture can be a mouse drag or a touch drag. Creation is concluded once the drag gesture is finished. -
Automatic mode
- The first event received after the creator has started selects the mode: if a drag gesture is initiated, the line is created in freehand mode. If the first event is aclick
, the line is created in click mode. Clicks may be mouse clicks or touch taps.
You can configure the line creation mode of the following creators:
Constraining geometries during creation
The creation API supports geometry constraints out-of-the-box. You can use most
IGeometryCreator
implementations to configure a constraint
to apply during creation. See the related article
for more information.
Examples of customizations
The tutorial Creating a custom geometry creator shows how you can implement your own geometry creator.