Skip to content

Edit geometries with programmatic reticle tool

View on GitHub

Use the Programmatic Reticle Tool to edit and create geometries with programmatic operations to facilitate customized workflows such as those using buttons rather than tap interactions.

Image of edit geometries with programmatic reticle tool

Use case

A field worker can use a button driven workflow to mark important features on a map. They can digitize features like sample or observation locations, fences, pipelines, and building footprints using point, multipoint, polyline, and polygon geometries. To create and edit geometries, workers can use a vertex-based reticle tool to specify vertex locations by panning the map to position the reticle over a feature of interest. Using a button-driven workflow they can then place new vertices or pick up, move and drop existing vertices.

How to use the sample

To create a new geometry, select the geometry type you want to create (i.e. points, multipoints, polyline, or polygon) in the settings view. Tap the button to start the geometry editor, pan the map to position the reticle then tap the button to place a vertex. To edit an existing geometry, tap the geometry to be edited in the map and perform edits by positioning the reticle over a vertex and tapping the button to pick it up. The vertex can be moved by panning the map and dropped in a new position by tapping the button again.

Vertices can be selected and the viewpoint can be updated to their position by tapping them.

Vertex creation can be disabled using the switch in the settings view. When this switch is toggled off new vertex creation is prevented, existing vertices can be picked up and moved, but mid-vertices cannot be selected or picked up and will not grow when hovered. The feedback vertex and feedback lines under the reticle will also no longer be visible.

Use the buttons in the settings view to undo or redo changes made to the geometry and the cancel and done buttons to discard and save changes, respectively.

How it works

  1. Create a GeometryEditor and set it to the map view using ArcGISMapViewController.geometryEditor.
  2. Start the GeometryEditor using GeometryEditor.startWithGeometryType() to create a new geometry or GeometryEditor.startWithGeometry() to edit an existing geometry.
    • If using the Geometry Editor to edit an existing geometry, the geometry must be retrieved from the graphics overlay being used to visualize the geometry prior to calling the start method. To do this:
      • Use ArcGISMapViewController.identifyGraphicsOverlay() to identify graphics at the location of a tap.
      • Access the IdentifyGraphicsOverlayResult.graphics.
      • Find the desired graphic in the list.
      • Access the geometry associated with the Graphic using Graphic.geometry - this will be used in the GeometryEditor.StartWithGeometry() method.
  3. Create a ProgrammaticReticleTool and set the GeometryEditor.tool.
  4. Subscribe to the GeometryEditor.onHoveredElementChanged and GeometryEditor.onPickedUpElementChanged events.
    • These events can be used to update the UI state, such as determining the effect a button press will have.
  5. Listen to tap events when the geometry editor is active to select and navigate to tapped vertices and mid-vertices.
    • To retrieve the tapped element and update the viewpoint:
      • Use ArcGISMapViewController.identifyGeometryEditor() to identify geometry editor elements at the location of the tap.
      • Access the IdentifyGeometryEditorResult.elements.
      • Find the desired element in the list.
      • Depending on whether or not the element is a GeometryEditorVertex or GeometryEditorMidVertex use GeometryEditor.selectVertex() or GeometryEditor.selectMidVertex() to select it.
      • Update the viewpoint using ArcGISMapView.setViewpoint().
  6. Enable and disable the vertex creation preview using ProgrammaticReticleTool.vertexCreationPreviewEnabled.
    • To prevent mid-vertex growth when hovered use ProgrammaticReticleTool.style.growEffect.applyToMidVertices.
  7. Check to see if undo and redo are possible during an editing session using GeometryEditor.canUndo and GeometryEditor.canRedo. If it's possible, use GeometryEditor.undo() and GeometryEditor.redo().
    • A picked up element can be returned to its previous position using GeometryEditor.cancelCurrentAction(). This can be useful to undo a pick up without undoing any change to the geometry. Use the GeometryEditor.pickedUpElement property to check for a picked up element.
  8. Check whether the currently selected GeometryEditorElement can be deleted (GeometryEditor.selectedElement.canDelete). If the element can be deleted, delete using GeometryEditor.deleteSelectedElement().
  9. Call GeometryEditor.stop() to finish the editing session and store the Graphic. The GeometryEditor does not automatically handle the visualization of a geometry output from an editing session. This must be done manually by propagating the geometry returned into a Graphic added to a GraphicsOverlay.
    • To create a new Graphic in the GraphicsOverlay:
      • Create a new Graphic with the geometry returned by the GeometryEditor.stop() method.
      • Append the Graphic to the GraphicsOverlay(i.e. GraphicsOverlay.graphics.add(graphic)).
    • To update the geometry underlying an existing Graphic in the GraphicsOverlay:
      • Replace the existing Graphic's geometry property with the geometry returned by the GeometryEditor.stop() method.

Relevant API

  • ArcGISMapView
  • Geometry
  • GeometryEditor
  • Graphic
  • GraphicsOverlay
  • ProgrammaticReticleTool

Additional information

The sample demonstrates a number of workflows which can be altered depending on desired app functionality:

  • picking up a hovered element combines selection and pick up, this can be separated into two steps to require selection before pick up.

  • tapping a vertex or mid-vertex selects it and updates the viewpoint to its position. This could be changed to not update the viewpoint or also pick up the element.

With the hovered and picked up element changed events and the programmatic APIs on the ProgrammaticReticleTool a broad range of editing experiences can be implemented.

Tags

draw, edit, freehand, geometry editor, programmatic, reticle, sketch, vertex

Sample Code

edit_geometries_with_programmatic_reticle_tool.dart
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
// Copyright 2025 Esri
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import 'dart:async';

import 'package:arcgis_maps/arcgis_maps.dart';
import 'package:arcgis_maps_sdk_flutter_samples/common/common.dart';
import 'package:flutter/material.dart';

class EditGeometriesWithProgrammaticReticleTool extends StatefulWidget {
  const EditGeometriesWithProgrammaticReticleTool({super.key});

  @override
  State<EditGeometriesWithProgrammaticReticleTool> createState() =>
      _EditGeometriesWithProgrammaticReticleToolState();
}

class _EditGeometriesWithProgrammaticReticleToolState
    extends State<EditGeometriesWithProgrammaticReticleTool>
    with SampleStateSupport {
  // Create a controller for the map view.
  final _mapViewController = ArcGISMapView.createController();
  // Create a geometry editor.
  final _geometryEditor = GeometryEditor();
  // Create a programmatic reticle tool to be used by the geometry editor for editing.
  final _programmaticReticleTool = ProgrammaticReticleTool();

  // Create a graphics overlay to hold graphics created and edited by the geometry editor.
  final _graphicsOverlay = GraphicsOverlay();

  // Create a list of geometry types to make available for editing.
  final _geometryTypes = [
    GeometryType.point,
    GeometryType.multipoint,
    GeometryType.polyline,
    GeometryType.polygon,
  ];
  // The symbols used for displaying different geometry types.
  late final SimpleFillSymbol _polygonSymbol;
  late final SimpleLineSymbol _polylineSymbol;
  late final SimpleMarkerSymbol _pointSymbol;
  late final SimpleMarkerSymbol _multipointSymbol;

  // Create variables for holding state relating to the geometry editor for controlling the UI.
  Graphic? _selectedGraphic;
  GeometryType? _selectedGeometryType;
  var _hasPickedUpElement = false;
  GeometryEditorHoverable? _hoveredElement;
  var _allowVertexCreation = true;
  var _geometryEditorCanUndo = false;
  var _geometryEditorCanRedo = false;
  var _geometryEditorIsStarted = false;
  var _showSettings = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        left: false,
        right: false,
        child: Stack(
          children: [
            Column(
              children: [
                // Creates the top menu used for adjusting settings in the geometry editor.
                buildTopMenu(),
                Expanded(
                  // Add a map view to the widget tree and set a controller.
                  child: ArcGISMapView(
                    controllerProvider: () => _mapViewController,
                    onMapViewReady: onMapViewReady,
                    // Configure interactions with the map view using the onTap callback.
                    onTap: onTap,
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(10),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      // Creates the button which controls the current action of the geometry editor.
                      Expanded(child: buildGeometryEditorActionButton()),
                    ],
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
      // A bottom sheet that shows/hides settings relating to the geometry editor depending on the value of the showSettings flag.
      bottomSheet: _showSettings ? buildBottomSheet() : null,
    );
  }

  void onMapViewReady() {
    // Create a map with the imagery basemap style and set to the map view controller.
    final map = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISImageryStandard);
    _mapViewController.arcGISMap = map;

    // Configure some initial graphics and add to the graphics overlay.
    _graphicsOverlay.graphics.addAll(initialGraphics());
    // Add the graphics overlay to the map view.
    _mapViewController.graphicsOverlays.add(_graphicsOverlay);

    // Set an initial viewpoint over the graphics.
    _mapViewController.setViewpoint(
      Viewpoint.fromCenter(
        ArcGISPoint(
          x: -0.775395,
          y: 51.523806,
          spatialReference: SpatialReference.wgs84,
        ),
        scale: 20000,
      ),
    );

    // Set the programmatic reticle tool as the active tool on the geometry editor.
    _geometryEditor.tool = _programmaticReticleTool;
    // Listen to changes in the geometry editor to manage the UI.
    // When the picked up element changes, we update the state.
    _geometryEditor.onPickedUpElementChanged.listen(
      (pickedUpElement) =>
          setState(() => _hasPickedUpElement = pickedUpElement != null),
    );
    // When the hovered element changes, we update the state.
    _geometryEditor.onHoveredElementChanged.listen(
      (hoveredElement) => setState(() => _hoveredElement = hoveredElement),
    );
    // Listen to changes in canUndo and canRedo in order to enable/disable the UI.
    _geometryEditor.onCanUndoChanged.listen(
      (canUndo) => setState(() => _geometryEditorCanUndo = canUndo),
    );
    _geometryEditor.onCanRedoChanged.listen(
      (canRedo) => setState(() => _geometryEditorCanRedo = canRedo),
    );
    // Set the initial state of the geometry type.
    setState(() => _selectedGeometryType = GeometryType.point);
    // Set the geometry editor to the map view controller.
    _mapViewController.geometryEditor = _geometryEditor;
  }

  Future<void> onTap(Offset localPosition) async {
    if (_geometryEditorIsStarted) {
      // If the geometry editor is started, we use the identify geometry editor method at the tapped location.
      final identifyGeometryEditorResult = await _mapViewController
          .identifyGeometryEditor(screenPoint: localPosition, tolerance: 12);

      if (identifyGeometryEditorResult.elements.isNotEmpty) {
        // Get the first element from the result.
        final geometryEditorElement =
            identifyGeometryEditorResult.elements.first;
        if (geometryEditorElement is GeometryEditorVertex) {
          // If the element is a vertex, set the viewpoint to its position and select it using the vertex index.
          zoomToPoint(geometryEditorElement.point);
          _geometryEditor.selectVertex(
            partIndex: geometryEditorElement.partIndex,
            vertexIndex: geometryEditorElement.vertexIndex,
          );
        } else if (geometryEditorElement is GeometryEditorMidVertex &&
            _allowVertexCreation) {
          // If the element is a mid-vertex, set the viewpoint to its position and select it using the segment index.
          // We only select a mid-vertex if vertex creation is allowed because mid-vertices only exist in the display as a visual cue
          // to indicate new vertices can be inserted between existing vertices.
          zoomToPoint(geometryEditorElement.point);
          _geometryEditor.selectMidVertex(
            partIndex: geometryEditorElement.partIndex,
            segmentIndex: geometryEditorElement.segmentIndex,
          );
        }
      }
    } else {
      // If the geometry editor is not started, we perform an identify operation on the graphics overlays at the tapped location.
      final identifyGraphicsOverlayResult = await _mapViewController
          .identifyGraphicsOverlays(screenPoint: localPosition, tolerance: 12);

      if (identifyGraphicsOverlayResult.isNotEmpty &&
          identifyGraphicsOverlayResult.first.graphics.isNotEmpty) {
        // Get the first graphic from the first result.
        final identifiedGraphic =
            identifyGraphicsOverlayResult.first.graphics.first;
        if (identifiedGraphic.geometry != null) {
          // Select the graphic, hide it, and start an editing session with a copy of it.
          identifiedGraphic.isSelected = true;
          identifiedGraphic.isVisible = false;
          _geometryEditor.startWithGeometry(identifiedGraphic.geometry!);
          setState(() {
            _geometryEditorIsStarted = true;
            _selectedGraphic = identifiedGraphic;
          });

          if (_allowVertexCreation) {
            // If vertex creation is allowed, set the viewpoint to the center of the selected graphic's geometry.
            zoomToPoint(_selectedGraphic!.geometry!.extent.center);
          } else {
            // Otherwise, set the viewpoint to the end point of the first part of the respective geometry.
            switch (_selectedGraphic!.geometry) {
              case final Polygon polygon:
                zoomToPoint(polygon.parts.first.endPoint!);
              case final Polyline polyline:
                zoomToPoint(polyline.parts.first.endPoint!);
              case final Multipoint multiPoint:
                zoomToPoint(multiPoint.points.last);
              case final ArcGISPoint point:
                zoomToPoint(point);
            }
          }
        }
      }
    }
  }

  // Called from the UI when finishing editing to stop the geometry editor and save the results to the map.
  void stopAndSaveEdits() {
    // Stop the geometry editor and get the resulting geometry.
    final geometry = _geometryEditor.stop();
    if (geometry != null) {
      if (_selectedGraphic != null) {
        // If there is a selected graphic, update the geometry of the graphic being edited and make it visible again.
        _selectedGraphic!.geometry = geometry;
        _selectedGraphic!.isVisible = true;
        _selectedGraphic!.isSelected = false;
      } else {
        // If there is not a selected graphic, create a new graphic based on the geometry and add it to the graphics overlay.
        final graphic = Graphic(geometry: geometry);
        // Apply a symbol to the graphic depending on the geometry type.
        final geometryType = geometry.geometryType;
        if (geometryType == GeometryType.point) {
          graphic.symbol = _pointSymbol;
        } else if (geometryType == GeometryType.multipoint) {
          graphic.symbol = _multipointSymbol;
        } else if (geometryType == GeometryType.polyline) {
          graphic.symbol = _polylineSymbol;
        } else if (geometryType == GeometryType.polygon) {
          graphic.symbol = _polygonSymbol;
        }
        _graphicsOverlay.graphics.add(graphic);
      }
    }
    // Reset the state.
    setState(() {
      _geometryEditorIsStarted = false;
      _selectedGraphic = null;
      _selectedGeometryType = null;
    });
  }

  // Called from the UI to undo edits in the geometry editor.
  void onUndo() {
    if (_hasPickedUpElement) {
      // If there is a picked up element, use the cancelCurrentAction function to move the picked up geometry back to its original position before it is placed.
      _geometryEditor.cancelCurrentAction();
    } else {
      // Otherwise use the undo function to undo the last action.
      _geometryEditor.undo();
    }
  }

  // Called from the UI to redo edits in the geometry editor.
  void onRedo() {
    _geometryEditor.redo();
  }

  // Called from the UI to stop the geometry and discard all edits.
  void stopAndDiscardEdits() {
    // Stop the geometry editor and discard the geometry.
    _geometryEditor.stop();

    // Reset the state.
    _selectedGraphic?.isVisible = true;
    _selectedGraphic?.isSelected = false;
    setState(() {
      _geometryEditorIsStarted = false;
      _selectedGraphic = null;
      _selectedGeometryType = null;
    });
  }

  // Returns the relevant button to control the next programmatic action of the geometry editor based on its current state.
  ElevatedButton buildGeometryEditorActionButton() {
    if (!_geometryEditorIsStarted) {
      // If the geometry editor is not started, the button will start it.
      return ElevatedButton(
        onPressed: () {
          // Use the selected geometry type or default to using points.
          if (_selectedGeometryType == null) {
            setState(() => _selectedGeometryType = GeometryType.point);
          }
          // Start the geometry editor using the selected geometry type.
          _geometryEditor.startWithGeometryType(_selectedGeometryType!);
          setState(() => _geometryEditorIsStarted = true);
        },
        child: const Text('Start geometry editor'),
      );
    } else {
      if (_hasPickedUpElement) {
        // If something is picked up - the button will drop it.
        return ElevatedButton(
          onPressed: _programmaticReticleTool.placeElementAtReticle,
          child: const Text('Drop point'),
        );
      }
      // If a hovered element exists - the button will select it and pick it up.
      if (_hoveredElement is GeometryEditorVertex) {
        return ElevatedButton(
          onPressed: () {
            _programmaticReticleTool.selectElementAtReticle();
            _programmaticReticleTool.pickUpSelectedElement();
          },
          child: const Text('Pick up point'),
        );
      }
      if (_hoveredElement is GeometryEditorMidVertex) {
        return ElevatedButton(
          // We only pick up a mid-vertex if vertex creation is allowed because mid-vertices only exist in the display
          // as a visual cue to indicate new vertices can be inserted between existing vertices.
          onPressed: _allowVertexCreation
              ? () {
                  _programmaticReticleTool.selectElementAtReticle();
                  _programmaticReticleTool.pickUpSelectedElement();
                }
              : null,
          child: const Text('Pick up point'),
        );
      }
      // If there is no picked up or hovered element and vertex creation is allowed,
      // the button inserts a new vertex.
      return ElevatedButton(
        onPressed: _allowVertexCreation
            ? _programmaticReticleTool.placeElementAtReticle
            : null,
        child: const Text('Insert point'),
      );
    }
  }

  // Returns a series of buttons used to control and configure the geometry editor.
  Widget buildTopMenu() {
    return Padding(
      padding: const EdgeInsets.all(10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          // A button to stop and discard edits.
          ElevatedButton(
            onPressed: _geometryEditorIsStarted ? stopAndDiscardEdits : null,
            child: const Text('Cancel'),
          ),
          // A button to show the settings UI.
          ElevatedButton(
            onPressed: () => setState(() => _showSettings = true),
            child: const Text('Settings'),
          ),
          // A button to stop and save edits.
          ElevatedButton(
            onPressed: _geometryEditorIsStarted ? stopAndSaveEdits : null,
            child: const Text('Done'),
          ),
        ],
      ),
    );
  }

  // Build out a settings UI within the bottom sheet.
  Widget buildBottomSheet() {
    return BottomSheetSettings(
      onCloseIconPressed: () => setState(() => _showSettings = false),
      settingsWidgets: (context) => [buildSettings(context)],
    );
  }

  // Returns a toolbar of buttons with icons for editing functions. Tooltips are used to aid the user experience.
  Widget buildSettings(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(10),
      child: Column(
        spacing: 10,
        mainAxisSize: MainAxisSize.min,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            spacing: 10,
            children: [
              // Create a switch with a label that toggles whether vertex creation is allowed.
              const Text('Allow vertex creation:'),
              Switch(
                value: _allowVertexCreation,
                onChanged: (value) {
                  setState(() => _allowVertexCreation = value);
                  // Update the programmatic reticle tool and geometry editor settings based on the switch state.
                  _programmaticReticleTool.vertexCreationPreviewEnabled =
                      _allowVertexCreation;
                  _programmaticReticleTool
                          .style
                          .growEffect!
                          .applyToMidVertices =
                      _allowVertexCreation;
                },
              ),
            ],
          ),
          // A drop down button for selecting geometry type. Only visible if the geometry editor is not started.
          Visibility(
            visible: !_geometryEditorIsStarted,
            child: DropdownButton(
              alignment: Alignment.center,
              hint: Text(
                'Geometry Type',
                style: Theme.of(context).textTheme.labelMedium,
              ),
              icon: const Icon(Icons.arrow_drop_down),
              iconEnabledColor: Theme.of(context).colorScheme.primary,
              iconDisabledColor: Theme.of(context).disabledColor,
              style: Theme.of(context).textTheme.labelMedium,
              value: _selectedGeometryType,
              items: configureGeometryTypeMenuItems(),
              onChanged: (geometryType) {
                setState(() => _selectedGeometryType = geometryType);
              },
            ),
          ),
          // Buttons to undo or redo actions on the geometry editor.
          // Only visible if the geometry editor is started.
          Visibility(
            visible: _geometryEditorIsStarted,
            child: Row(
              spacing: 10,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Tooltip(
                  message: 'Undo',
                  child: ElevatedButton(
                    onPressed: _geometryEditorCanUndo || _hasPickedUpElement
                        ? onUndo
                        : null,
                    child: const Icon(Icons.undo),
                  ),
                ),
                Tooltip(
                  message: 'Redo',
                  child: ElevatedButton(
                    onPressed: _geometryEditorCanRedo ? onRedo : null,
                    child: const Icon(Icons.redo),
                  ),
                ),
              ],
            ),
          ),
          // Button to delete the selected element.
          // Only visible if the geometry editor is started.
          Visibility(
            visible: _geometryEditorIsStarted,
            child: Tooltip(
              message: 'Delete selected element',
              child: ElevatedButton(
                onPressed:
                    _geometryEditor.selectedElement != null &&
                        _geometryEditor.selectedElement!.canDelete
                    ? _geometryEditor.deleteSelectedElement
                    : null,
                child: const Text('Delete selected'),
              ),
            ),
          ),
        ],
      ),
    );
  }

  // Returns a list of drop down menu items for each geometry type.
  List<DropdownMenuItem<GeometryType>> configureGeometryTypeMenuItems() {
    return _geometryTypes.map((type) {
      return DropdownMenuItem(
        enabled: !_geometryEditorIsStarted,
        value: type,
        child: Text(
          type.name.capitalize(),
          style: !_geometryEditorIsStarted
              ? null
              : const TextStyle(
                  color: Colors.grey,
                  fontStyle: FontStyle.italic,
                ),
        ),
      );
    }).toList();
  }

  // Configure initial graphics to display on the map.
  List<Graphic> initialGraphics() {
    // Create symbols for each geometry type.
    _pointSymbol = SimpleMarkerSymbol(
      style: SimpleMarkerSymbolStyle.square,
      color: Colors.red,
      size: 10,
    );
    _multipointSymbol = SimpleMarkerSymbol(color: Colors.yellow, size: 5);
    _polylineSymbol = SimpleLineSymbol(color: Colors.blue, width: 2);
    final outlineSymbol = SimpleLineSymbol(
      style: SimpleLineSymbolStyle.dash,
      color: Colors.black,
    );
    _polygonSymbol = SimpleFillSymbol(
      color: Colors.red.withAlpha(76), // 0.3 * 255 = 76
      outline: outlineSymbol,
    );

    // Create geometries from JSON strings.
    const pinkneysGreenJson = '''
{"rings":[[[-84843.262719916485,6713749.9329888355],[-85833.376589175183,6714679.7122141244],
                    [-85406.822347959576,6715063.9827222107],[-85184.329997390232,6715219.6195847588],
                    [-85092.653857582554,6715119.5391713539],[-85090.446872787768,6714792.7656492386],
                    [-84915.369168906298,6714297.8798246197],[-84854.295522911285,6714080.907587287],
                    [-84843.262719916485,6713749.9329888355]]],"spatialReference":{"wkid":102100,"latestWkid":3857}}''';
    final pinkneysGreenGeometry = Geometry.fromJsonString(pinkneysGreenJson);

    const beechLodgeBoundaryJson = '''
{"paths":[[[-87090.652708065536,6714158.9244240439],[-87247.362370337316,6714232.880689906],
                    [-87226.314032974493,6714605.4697726099],[-86910.499335316243,6714488.006312645],
                    [-86750.82198052686,6714401.1768307304],[-86749.846825938366,6714305.8450344801]]],"spatialReference":{"wkid":102100,"latestWkid":3857}}''';
    final beechLodgeBoundaryGeometry = Geometry.fromJsonString(
      beechLodgeBoundaryJson,
    );

    const treeMarkersJson = '''
{"points":[[-86750.751150056443,6713749.4529355941],[-86879.381793060631,6713437.3335486846],
                    [-87596.503104619667,6714381.7342108283],[-87553.257569537804,6714402.0910389507],
                    [-86831.019903597829,6714398.4128562529],[-86854.105933315877,6714396.1957954112],
                    [-86800.624094892439,6713992.3374453448]],"spatialReference":{"wkid":102100,"latestWkid":3857}}''';
    final treeMarkersGeometry = Geometry.fromJsonString(treeMarkersJson);

    // Return a list of graphics for each geometry type.
    return [
      Graphic(geometry: pinkneysGreenGeometry, symbol: _polygonSymbol),
      Graphic(geometry: beechLodgeBoundaryGeometry, symbol: _polylineSymbol),
      Graphic(geometry: treeMarkersGeometry, symbol: _multipointSymbol),
    ];
  }

  // Zooms to the provided point using the current map scale.
  void zoomToPoint(ArcGISPoint point) {
    unawaited(
      _mapViewController.setViewpointAnimated(
        Viewpoint.fromCenter(point, scale: _mapViewController.scale),
      ),
    );
  }
}

extension on String {
  // An extension on String to capitalize the first character of the String.
  String capitalize() {
    return '${this[0].toUpperCase()}${substring(1)}';
  }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.