This guide explains how you can interactively edit features on a Map, and integrate this capability in an
IControllerIControllerIController.
Overview
The CPillar EditorEditorEditor translates input eventsinput eventsinput events
to edit actions that are applied to a configuredconfiguredconfigured selection
of features. For these features, the editor retrievesretrievesretrieves and
visualizesvisualizesvisualizes a set of handleshandleshandles.
The handles are linked to edit actions that perform the actual feature modificationfeature modificationfeature modification.
|
Programmatically creating geometries
link: If you want to edit geometries through the API instead of editing them interactively on the map, see the related article on geometries. |
Editing Features and Geometries
Base concepts
To understand how features or geometries are edited, a few concepts need to be explained.
Observable feature and geometries
To make it easier to observe the changes that are happening to an edited feature or geometry, the
Observable<T>Observable<T>Observable<T> class is used in the edit API:
This class stores a Feature or Geometry that can change during editing. It allows you to get the current state, and observe changes to the Feature or Geometry. This for example allows you to update the handles of an object that is being edited.
IEditHandle
IEditHandleIEditHandleIEditHandle is a visualvisualvisual
component on the map that triggers concrete edit actions based on input eventsinput eventsinput events.
An example is a point handle that is visualized as an icon, and that you can drag around, click on, or touch press.
An edit handle triggers a change to the feature or geometry by notifying that it has changed. A point handle will for example
send a notification that it has moved. Based on that notification, the IEditHandlesIEditHandlesIEditHandles
can modify a feature or geometry.
Example IEditHandleIEditHandleIEditHandle implementations are:
-
PointEditHandlePointEditHandlePointEditHandle: This handle is visualized by a point icon. It allows you to drag it around, click, or touch press it. It usesIPointEditActionIPointEditActionIPointEditActionto signal that an action is performed. -
TranslateEditHandleTranslateEditHandleTranslateEditHandle: This handle is either not visualized, or visualized by ashadow geometryshadow geometryshadow geometry. It allows you to drag it around, and translate an entire geometry. It usesITranslateEditActionITranslateEditActionITranslateEditActionto signal that an action is performed. -
LineEditHandleLineEditHandleLineEditHandle: This handle is visualized by a line geometry. It allows you to drag it around, click, or touch press it. It usesIPointEditActionIPointEditActionIPointEditActionto signal that an action is performed.
IEditHandles
IEditHandlesIEditHandlesIEditHandles is a collection of IEditHandleIEditHandleIEditHandle instances that is created
for a specific feature or geometry.
This collection must update its own handles whenever the edited object changes. The edited object can change in two cases:
-
By an edit action performed by one of its handles.
-
By an
external changeexternal changeexternal changeto the feature or geometry, for example originating from anIFeatureModelIFeatureModelIFeatureModelevent
In both cases, the observableobservableobservable featurefeaturefeature
or geometrygeometrygeometry will notify the IEditHandlesIEditHandlesIEditHandles that it has changed.
Triggered by this notification, IEditHandlesIEditHandlesIEditHandles can update its list of handles.
IEditHandles provider
IFeatureHandlesProviderIFeatureHandlesProviderIFeatureHandlesProvider and
IGeometryHandlesProviderIGeometryHandlesProviderIGeometryHandlesProvider can create an IEditHandlesIEditHandlesIEditHandles instance
for a given feature or geometry. These classes are typically stateless, and can be reused for more than one feature or
geometry.
Example IGeometryHandlesProviderIGeometryHandlesProviderIGeometryHandlesProvider implementations:
-
PointHandlesProviderPointHandlesProviderPointHandlesProvider: provides handles to edit Point geometries -
PolylineHandlesProviderPolylineHandlesProviderPolylineHandlesProvider: provides handles to edit Polyline geometries -
PolylineRingHandlesProviderPolylineRingHandlesProviderPolylineRingHandlesProvider: provides handles to edit PolylineRing geometries -
PatchHandlesProviderPatchHandlesProviderPatchHandlesProvider: provides handles to edit patches. This class doesn’t provide any handles itself, but it asks anotherIGeometryHandlesProviderIGeometryHandlesProviderIGeometryHandlesProviderto provide handles for its base geometry, for example aPolylineRingHandlesProviderPolylineRingHandlesProviderPolylineRingHandlesProvider. -
PolygonHandlesProviderPolygonHandlesProviderPolygonHandlesProvider: provides handles to edit polygons. This class doesn’t provide any handles itself, but it asks anotherIGeometryHandlesProviderIGeometryHandlesProviderIGeometryHandlesProviderto provide handles for its exterior and interior rings, for example aPolylineRingHandlesProviderPolylineRingHandlesProviderPolylineRingHandlesProvider.
Example IFeatureHandlesProviderIFeatureHandlesProviderIFeatureHandlesProvider implementations:
-
FeatureHandlesProviderFeatureHandlesProviderFeatureHandlesProvider: provides handles to edit a Feature byextractingextractingextractinga geometry from the feature and using anIGeometryHandlesProviderIGeometryHandlesProviderIGeometryHandlesProviderto provide handles for that geometry. After the geometry is modified, it is used to create modified Feature.
Editor
EditorEditorEditor determines which features are edited, and delegates its
input eventsinput eventsinput events to the edit handlesedit handlesedit handles
for that feature. It also provides a layerprovides a layerprovides a layer that can
visualize the used handles on the Map.
Handle interactions
The following diagram shows the most common interactions between the different concepts:
Handle interaction is wired together using callbacks and observers:
-
IEditHandleIEditHandleIEditHandleimplementations typically use an action to notifyIEditHandlesIEditHandlesIEditHandlesthat they have been modified. Based on this callback, theIEditHandlesIEditHandlesIEditHandlesimplementation can modify the feature or geometry. An example isPointEditHandlePointEditHandlePointEditHandlewhich usesIPointEditActionIPointEditActionIPointEditActionto communicate that the handle has been interacted with. -
IFeatureEditCallbackIFeatureEditCallbackIFeatureEditCallbackorIGeometryEditCallbackIGeometryEditCallbackIGeometryEditCallbacknotifyEditorEditorEditoror otherIEditHandlesIEditHandlesIEditHandlesthat the feature or geometry has been modified. -
ObservableObservableObservableof Feature and Geometry send notifications when a feature or geometry has been modified. This allows theIEditHandlesIEditHandlesIEditHandlesto update its handles. The change can be:-
external change: for example based on an event originating from
IFeatureModelIFeatureModelIFeatureModel -
editing changes: triggered by
EditorEditorEditorwhen receiving a callback fromIFeatureEditCallbackIFeatureEditCallbackIFeatureEditCallbackorIGeometryEditCallbackIGeometryEditCallbackIGeometryEditCallback
-
Configuring feature editing
To configure feature editing, you can use these classes:
-
Editor::Builder: toconfigure the edit candidatesconfigure the edit candidatesconfigure the edit candidatesused. -
FeatureLayer::Builder: toenable or disableenable or disableenable or disablefeature editing for a layer and to define anedit configurationedit configurationedit configuration. With this edit configuration, you can:-
Configure the handlesConfigure the handlesConfigure the handlesused to edit a Feature. -
ConfigureConfigureConfigurewhen theIFeatureModelIFeatureModelIFeatureModelis updated by the Editor. -
Provide the geometryProvide the geometryProvide the geometryused for editing a a Feature, and specify how to apply edited geometries to the Feature. This provider is mainly used by the defaultfeature handles providerfeature handles providerfeature handles provider.
-
Constraining geometries during editing
The editing API has out of the box support for geometry constraints. Most
IGeometryHandlesProviderIGeometryHandlesProviderIGeometryHandlesProvider implementations allow you to configure
a constraint that is applied during editing. See the related article
for more information.
Integrating an editor with a controller
You can use the EditorEditorEditor class as a part of an IControllerIControllerIController implementation. To integrate the feature
editor:
-
Delegate
input eventsinput eventsinput events. The editor 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, an editor can ignore mouse or touch events if there is no Feature at the position of those events. The controller can still use these events to navigate the map, though. -
Add the
handle layerhandle layerhandle layerto the controller’slayer listlayer listlayer list. You need to do that so that the map can visualize the edit handles. -
Change the
mouse cursormouse cursormouse cursorat theappropriate momentappropriate momentappropriate moment.
Examples of customizations
The following articles and tutorials give examples of how you can customize the edit behavior:
-
This tutorial shows you how to customize existing handles provider.
-
This tutorial shows you how you can extra handles to an existing handles provider.
-
This tutorial shows how you can implement your own handles provider.