Skip to content
mtehver edited this page Apr 8, 2014 · 13 revisions

Introduction

AdvancedMap project has com.nutiteq.editable.EditableMapView class, which is extension of MapView for interactivity on map. Specifically it has logic of editing of vector elements: points, markers, lines, polygons. It is implemented on top of core SDK (with no changes in the core or MapView itself).

There are two sample app Activities for data editing:

  • Editable CartoDB - edit data in CartoDB table, using their online API. Sample is with some Nutiteq test tables.
  • Editable Vector File - this sample requires user to select a Shapefile or Spatialite file, one table from it, and edit the data. This is a sample for offline editing.

Basic editing implementation for polygons, lines and points is same for both, see following video:

Editing video sample

General editable Layer usage steps

1. Create view

Instead of MapView use EditableMapView

2. Configure view

Configure map settings and base layer (usually a raster layer), as in usual app.

3. Add editable layer

Instead of GeometryLayer, EditableGeometryLayer with special editable data source has to be used. AdvancedMap has three ready-made editable datasources: CartoDB data source, OGR (Shapefile) data source and Spatialite datasource. It is easy to create own data source implementations, see next chapter about this.

4. Define EditableMapView.EditEventListener

This is specific listener for number of editing events. Add it to EditableMapView. You may want to implement there:

  • snapElementVertex - snap to another element vertex
  • onElementChanged - mark element as changed (or save to data source)
  • onElementDeleted - remove element from the layer
  • onElementSelected/onElementDeselected - update UI for specific element types
  • onDragStart/onDrag/onDragEnd - actions, perhaps also UI updates during dragging. No need to save here, onElementChanged will called also after drag

5. Add editing controls (optional)

Unless your editor is just for single object, then you probably want UI controls (on-screen buttons) to have some editing functions: to add new object, delete, save, undo/redo, save changes. The visibility and state of the objects could change based on current editing and object selection state, what you get from EditEventListener events. See the editable map activity samples how to use controls.

The samples include also undo/redo functions, and a stack to keep object state stack for this. There is also object property editor, which enables to change object name.

6. Customize editor overlay layer (optional)

Editable view uses special overlay layer for displaying control points that can be dragged around. It is possible to customize the styles of the control points. OverlayLayerStyle provides 3 styles for control points in different states: normal control points, virtual control points and active (dragged) control points. By default, small half-transparent circles are used, but any other bitmap can be used also.

Overlay layer is created/removed dynamically by EditableMapView object. It is important to always call EditableMapView.stopMapping when Activity receives onStop event - otherwise the duplicate overlay layers can be created after device orientation changes.

Create custom editable vector data source

EditableVectorDataSource is a simple interface built on top of normal vector data source:

public interface EditableVectorDataSource<T extends VectorElement> extends VectorDataSource<T> {
	long insertElement(T element);
	void updateElement(long id, T element);
	void deleteElement(long id);
}

It is recommended to first create a non-editable data source and then extend the class by implementing additional editable vector data source methods.

Clone this wiki locally