b = geometry_name.tracePolygon(ʃmap_nameʅ);
The
Geometry.tracePolygon function displays a map that the user taps on to place the vertices of a polygon. While tracing the polygon on the map, the user may also drag vertices of the polygon by long pressing on them in order to modify the polygon. The function returns when the user has finished drawing the polygon on the map and taps the save button.
The optional argument
map_name is the name of a
Map object that will provide the display parameters used for the map that is shown while the user traces the polygon. You can use this parameter to set the
base map,
title, and
location/zoom level of the map. You can also use the map parameter to display
markers and
geometry on the map, however any callbacks for clicking on markers or on the map itself are ignored while tracing the polygon. Any buttons on the map are replaced by buttons for saving, clearing, and deleting the last point placed while the polygon is being traced. If the argument
map_name is omitted, a map with default settings is displayed while tracing the polygon.
After tracing the polygon, you can
save the geometry to a file, compute the
area of the polygon, or compute the
perimeter of the polygon.
If
geometry_name already contains a polygon, this polygon will be displayed and the user will be able to modify it by long pressing on the vertices to drag them. If the geometry contains more than one polygon, only the first polygon is shown. All entities in the geometry other than polygons are ignored. If the geometry was loaded from GeoJSON, any polygons in entities of type MultiPolygon are ignored. If you wish to capture a new polygon rather than editing the existing geometry, use the
Geometry.clear function before calling
Geometry.tracePolygon.
The function returns a logical value of 1 (true) if the user traced a polygon and 0 (false) if the file user canceled polygon tracing by tapping the back button.
// Declare a geometry
Geometry outline;
// Have the user trace the outline of a polygon
if outline.tracePolygon() then
// Save the outline to a GeoJSON file
outline.save("outline.geojson");
endif;
// Declare a geometry
Geometry plot;
// Declare a map
Map mymap;
// Set map display parameters
mymap.setBaseMap("basemap.mbtiles");
mymap.setTitle("Tap points on the map to outline the plot");
// Have the user trace the outline of a polygon using the map
if plot.tracePolygon(mymap) then
// Capture the plot area
PLOT_AREA = plot.area();
endif;