This guide explains how you can interactively create features on a Map, and integrate this capability in an
IControllerIControllerIController.
Overview
You start the process of interactive feature creation by sending input eventsinput eventsinput events
to a creatorcreatorcreator. A feature creatorfeature creatorfeature creator creates the feature, and a geometry creatorgeometry creatorgeometry creator creates its geometry.
The feature creator can convertconvertconvert the created
geometries to a feature, and addsaddsadds 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::Builderto configure:-
The
feature layerfeature layerfeature layerto add the new features to. -
The
feature creatorfeature creatorfeature creatorthat defines how to create the feature, and which geometry to use. -
An
observerobserverobserverthat signals when a feature was added to the model, or if feature creation failed.
-
-
The
geometry providergeometry providergeometry providerto specify how to apply created geometries to the initial feature. -
An
initial featureinitial featureinitial featureto add the created geometry to.
Integrating a creator with a controller
You can use the Creator class as a part of an IControllerIControllerIController implementation.
To integrate the feature creator:
-
Delegate the
input eventsinput eventsinput 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 layerpreview layerpreview layerto the controller’slayer listlayer listlayer 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 modeline creation modeline creation mode
defines how input events generate a line by placing points in sequence.
The supported line creation modes are:
-
Click modeClick modeClick mode- Each point is added at amouse clickmouse clickmouse clickortouch taptouch taptouch tapevent. Creation is concluded with adouble clickdouble clickdouble clickor atouch long presstouch long presstouch long pressevent. -
Freehand modeFreehand modeFreehand mode- Points are sequentially added during adragdragdraggesture. The drag gesture can be a mouse drag or a touch drag. Creation is concluded once the drag gesture is finished. -
Automatic modeAutomatic modeAutomatic 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 aclickclickclick, 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
IGeometryCreatorIGeometryCreatorIGeometryCreator 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.