Edit with branch versioning

View inAndroidFormsUWPWPFWinUIiOSView on GitHub

Create, query and edit a specific server version using service geodatabase.

Image of edit with branch versioning

Use case

Workflows often progress in discrete stages, with each stage requiring the allocation of a different set of resources and business rules. Typically, each stage in the overall process represents a single unit of work, such as a work order or job. To manage these, you can create a separate, isolated version and modify it. Once this work is complete, you can integrate the changes into the default version.

How to use the sample

Once loaded, the map will zoom to the extent of the feature layer. The current version is indicated at the top of the map. Tap "Create Version" to open a dialog to specify the version information (name, access, and description). See the Additional information section for restrictions on the version name.

Tap "Create" to create the version with the information that you specified. Select a feature to edit an attribute and/or tap a second time to relocate the point.

Tap the button in the top left corner to switch back and forth between the version you created and the default version. Edits will automatically be applied to your version when switching to the default version.

How it works

  1. Create and load a ServiceGeodatabase with a feature service URL that has enabled Version Management.
  2. Get the ServiceFeatureTable from the service geodatabase.
  3. Create a FeatureLayer from the service feature table.
  4. Create ServiceVersionParameters with a unique name, VersionAccess, and description.
    • Note - See the additional information section for more restrictions on the version name.
  5. Create a new version calling ServiceGeodatabase.CreateVersionAsync passing in the service version parameters.
  6. Get the Name property from the ServiceVersionInfo of the version created.
  7. Switch to the version you have just created using ServiceGeodatabase.SwitchVersionAsync, passing in the version name obtained from the service version info from step 6.
  8. Select a Feature from the map to edit its "TYPDAMAGE" attribute and location.
  9. Apply these edits to your version by calling ServiceGeodatabase.ApplyEditsAsync.
  10. Switch back and forth between your version and the default version to see how the two versions differ.

Relevant API

  • FeatureLayer
  • ServiceFeatureTable
  • ServiceGeodatabase
  • ServiceGeodatabase.ApplyEditsAsync
  • ServiceGeodatabase.CreateVersionAsync
  • ServiceGeodatabase.SwitchVersionAsync
  • ServiceVersionInfo
  • ServiceVersionParameters
  • VersionAccess

About the data

The feature layer used in this sample is Damage to commercial buildings located in Naperville, Illinois.

Additional information

Credentials:

  • Username: editor01
  • Passowrd: editor01.password

The name of the version must meet the following criteria:

  1. Must not exceed 62 characters
  2. Must not include: Period (.), Semicolon (;), Single quotation mark ('), Double quotation mark (")
  3. Must not include a space for the first character
  • Note - the version name will have the username and a period (.) prepended to it. E.g "editor01.MyNewUniqueVersionName"

Branch versioning access permission:

  1. VersionAccess.Public - Any portal user can view and edit the version.
  2. VersionAccess.Protected - Any portal user can view, but only the version owner, feature layer owner, and portal administrator can edit the version.
  3. VersionAccess.Private - Only the version owner, feature layer owner, and portal administrator can view and edit the version.

Tags

branch versioning, edit, version control, version management server

Sample Code

EditBranchVersioning.cs
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
// Copyright 2021 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: http://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.

using ArcGISRuntime;
using Esri.ArcGISRuntime.ArcGISServices;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Security;
using Esri.ArcGISRuntime.UI.Controls;
using Foundation;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using UIKit;

namespace ArcGISRuntimeXamarin.Samples.EditBranchVersioning
{
    [Register("EditBranchVersioning")]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Edit with branch versioning",
        category: "Data",
        description: "Create, query and edit a specific server version using service geodatabase.",
        instructions: "Once loaded, the map will zoom to the extent of the feature layer. The current version is indicated at the top of the map. Tap \"Create Version\" to open a dialog to specify the version information (name, access, and description). See the *Additional information* section for restrictions on the version name.",
        tags: new[] { "branch versioning", "edit", "version control", "version management server" })]
    public class EditBranchVersioning : UIViewController
    {
        // Hold references to UI controls.
        private MapView _myMapView;

        private UIStackView _damageView;
        private UIStackView _defaultView;
        private UIStackView _versionView;
        private UIView _topView;

        private UILabel _versionLabel;
        private UIButton _versionButton;

        private UITextField _nameField;
        private UIButton _proButton;
        private UITextField _descriptionField;
        private UIButton _confirmButton;
        private UIButton _cancelButton;

        private UILabel _moveText;
        private UIButton _damageButton;
        private UIButton _closeButton;

        private ArcGISFeature _selectedFeature;
        private FeatureLayer _featureLayer;
        private ServiceFeatureTable _featureTable;
        private ServiceGeodatabase _serviceGeodatabase;

        private VersionAccess? _userVersionAccess;

        private string _userCreatedVersionName;
        private string _userDamageLevel;
        private string _attributeFieldName = "typdamage";

        private List<VersionAccess> _accessLevels = new List<VersionAccess> { VersionAccess.Public, VersionAccess.Protected, VersionAccess.Private };
        private List<string> _damageLevels = new List<string> { "Destroyed", "Inaccessible", "Major", "Minor", "Affected" };

        public EditBranchVersioning()
        {
            Title = "Edit with branch versioning";
        }

        private async Task Initialize()
        {
            // Handle the login to the feature service.
            AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(async (info) =>
            {
                try
                {
                    // WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
                    string sampleServer7User = "editor01";
                    string sampleServer7Pass = "S7#i2LWmYH75";
                    return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return null;
                }
            });

            try
            {
                // Create a map.
                _myMapView.Map = new Map(BasemapStyle.ArcGISStreets);

                // Create and load a service geodatabase.
                _serviceGeodatabase = new ServiceGeodatabase(new Uri("https://sampleserver7.arcgisonline.com/server/rest/services/DamageAssessment/FeatureServer/0"));
                await _serviceGeodatabase.LoadAsync();

                // When the service geodatabase has loaded get the default version name.
                _versionLabel.Text = $"Current version: {_serviceGeodatabase.DefaultVersionName}";

                // Get the service feature table from the service geodatabase.
                _featureTable = _serviceGeodatabase.GetTable(0);

                // Create a feature layer from the service feature table and add it to the map.
                _featureLayer = new FeatureLayer(_featureTable);
                _myMapView.Map.OperationalLayers.Add(_featureLayer);
                await _featureLayer.LoadAsync();

                // When the feature layer has loaded set the viewpoint and update the UI.
                await _myMapView.SetViewpointAsync(new Viewpoint(_featureLayer.FullExtent));

                // Enable the UI.
                _versionButton.Enabled = true;
                _myMapView.GeoViewTapped += MapView_GeoViewTapped;
            }
            catch (Exception ex)
            {
                ShowAlert(ex.Message, ex.GetType().Name);
            }
        }

        private void VersionButtonClick(object sender, EventArgs e)
        {
            // Check if user version has been created.
            if (_userCreatedVersionName != null)
            {
                _ = SwitchVersion();
            }
            else
            {
                // Display UI for creating a new version.
                SwitchView(_versionView);
            }

            // Clear the selection.
            _featureLayer.ClearSelection();
            _selectedFeature = null;
        }

        private async Task SwitchVersion()
        {
            // Check if the default version is loaded.
            if (_serviceGeodatabase.VersionName == _serviceGeodatabase.DefaultVersionName)
            {
                // Switch to the user created version.
                await _serviceGeodatabase.SwitchVersionAsync(_userCreatedVersionName);
                _versionLabel.Text = $"Current version: {_serviceGeodatabase.VersionName}";
            }
            else
            {
                if (_serviceGeodatabase.HasLocalEdits())
                {
                    // Apply the edits made to the service geodatabase.
                    IReadOnlyList<FeatureTableEditResult> edits = await _serviceGeodatabase.ApplyEditsAsync();
                    if (!(edits?.Count > 0))
                    {
                        // Verify that there were no errors when applying edits.
                        if (!edits.ToArray()[0].EditResults[0].CompletedWithErrors)
                        {
                            ShowAlert("Applied edits successfully on the server");
                        }
                        else
                        {
                            ShowAlert(edits.ToArray()[0].EditResults[0].Error.Message);
                            return;
                        }
                    }
                }

                // Switch to the default version.
                await _serviceGeodatabase.SwitchVersionAsync(_serviceGeodatabase.DefaultVersionName);
                _versionLabel.Text = $"Current version: {_serviceGeodatabase.VersionName}";
            }
        }

        private bool VersionNameValid(string versionName)
        {
            // Verify that the version name is valid.
            if (versionName.Contains('.') || versionName.Contains(';') || versionName.Contains('\'') || versionName.Contains('\"'))
            {
                ShowAlert("Please enter a valid version name.\nThe name cannot contain the following characters:\n. ; ' \" ");
                return false;
            }
            else if (versionName.Length > 0 && versionName.StartsWith(" "))
            {
                ShowAlert("Version name cannot begin with a space");
                return false;
            }
            else if (versionName.Length > 62)
            {
                ShowAlert("Version name must not exceed 62 characters");
                return false;
            }
            else if (versionName.Length == 0)
            {
                ShowAlert("Please enter a version name");
                return false;
            }
            return true;
        }

        private void ShowAlert(string alertText, string titleText = "Alert")
        {
            new UIAlertView(titleText, alertText, (IUIAlertViewDelegate)null, "Ok", null).Show();
        }

        private async void MapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Check if a feature is selected and the service geodatabase is not on the default version.
            if (_selectedFeature is ArcGISFeature && _serviceGeodatabase.VersionName != _serviceGeodatabase.DefaultVersionName)
            {
                try
                {
                    // Load the feature.
                    await _selectedFeature.LoadAsync();

                    // Update the feature geometry.
                    _selectedFeature.Geometry = e.Location;

                    // Update the table.
                    await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);

                    // Update the service.
                    await ((ServiceFeatureTable)_selectedFeature.FeatureTable).ApplyEditsAsync();

                    ShowAlert("Moved feature " + _selectedFeature.Attributes["objectid"]);
                }
                catch (Exception ex)
                {
                    ShowAlert(ex.Message, "Failed to edit feature");
                }
            }
            else
            {
                try
                {
                    // Clear the selection.
                    _featureLayer.ClearSelection();
                    _selectedFeature = null;

                    // Perform an identify to determine if a user tapped on a feature.
                    IdentifyLayerResult identifyResult = await _myMapView.IdentifyLayerAsync(_featureLayer, e.Position, 2, false);

                    // Do nothing if there are no results.
                    if (!identifyResult.GeoElements.Any())
                    {
                        SwitchView(_defaultView);
                        return;
                    }

                    // Get the tapped feature.
                    _selectedFeature = (ArcGISFeature)identifyResult.GeoElements.First();

                    // Select the feature.
                    _featureLayer.SelectFeature(_selectedFeature);

                    // Get the current value.
                    string currentAttributeValue = _selectedFeature.Attributes[_attributeFieldName].ToString();

                    // Update the damage button.
                    _damageButton.SetTitle($"Damage: {currentAttributeValue}", UIControlState.Normal);

                    _moveText.Hidden = _serviceGeodatabase.VersionName == _serviceGeodatabase.DefaultVersionName;
                    _damageButton.Enabled = !_moveText.Hidden;

                    // Update the UI for the selection.
                    SwitchView(_damageView);
                }
                catch (Exception ex)
                {
                    ShowAlert(ex.Message, ex.GetType().Name);
                }
            }
        }

        private async Task ApplyDamageChange()
        {
            try
            {
                // Get the value from the UI.
                string selectedAttributeValue = _userDamageLevel;

                // Check if the new value is the same as the existing value.
                if (_selectedFeature.Attributes[_attributeFieldName].ToString() == selectedAttributeValue)
                {
                    return;
                }

                // Load the feature.
                await _selectedFeature.LoadAsync();

                // Update the attribute value.
                _selectedFeature.SetAttributeValue(_attributeFieldName, selectedAttributeValue);

                // Update the table.
                await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);

                // Update the service.
                await ((ServiceFeatureTable)_selectedFeature.FeatureTable).ApplyEditsAsync();

                ShowAlert("Edited feature " + _selectedFeature.Attributes["objectid"]);

                // Clear the selection.
                _featureLayer.ClearSelection();
                _selectedFeature = null;
            }
            catch (Exception ex)
            {
                ShowAlert(ex.Message, "Failed to edit feature");
            }
        }

        private async void ConfirmButtonClick(object sender, EventArgs e)
        {
            try
            {
                // Validate name and access input.
                if (!VersionNameValid(_nameField.Text))
                {
                    return;
                }

                if (_userVersionAccess is VersionAccess access)
                {
                    // Set the user defined name, access level and description as service version parameters
                    ServiceVersionParameters newVersionParameters = new ServiceVersionParameters();
                    newVersionParameters.Name = _nameField.Text;
                    newVersionParameters.Access = access;
                    newVersionParameters.Description = _descriptionField.Text ?? "";

                    ServiceVersionInfo newVersion = await _serviceGeodatabase.CreateVersionAsync(newVersionParameters);
                    _userCreatedVersionName = newVersion.Name;
                    _ = SwitchVersion();

                    _versionButton.SetTitle("Switch version", UIControlState.Normal);
                }
                else
                {
                    ShowAlert("Please select an access level");
                    return;
                }
            }
            catch (Exception ex)
            {
                ShowAlert(ex.Message, ex.GetType().Name);
            }
            finally
            {
                SwitchView(_defaultView);
            }
        }

        private void CancelButtonClick(object sender, EventArgs e) => SwitchView(_defaultView);

        private void ProtectionButtonClick(object sender, EventArgs e)
        {
            // Create prompt for the protection level.
            UIAlertController prompt = UIAlertController.Create("Choose protection level", string.Empty, UIAlertControllerStyle.ActionSheet);
            foreach (VersionAccess access in _accessLevels) prompt.AddAction(UIAlertAction.Create(Enum.GetName(typeof(VersionAccess), access), UIAlertActionStyle.Default, (o) => SetVersionAccess(access)));
            prompt.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));

            // Needed to prevent crash on iPad.
            UIPopoverPresentationController ppc = prompt.PopoverPresentationController;
            if (ppc != null)
            {
                ppc.SourceView = _proButton;
                ppc.PermittedArrowDirections = UIPopoverArrowDirection.Up;
            }

            // Present the prompt to the user.
            PresentViewController(prompt, true, null);
        }

        private void SetVersionAccess(VersionAccess access)
        {
            _userVersionAccess = access;
            _proButton.SetTitle($"Protection: {access}", UIControlState.Normal);
        }

        private void ChangeDamage(object sender, EventArgs e)
        {
            // Create prompt for the damage level.
            UIAlertController prompt = UIAlertController.Create("Change damage level", string.Empty, UIAlertControllerStyle.ActionSheet);
            foreach (string damageLevel in _damageLevels) prompt.AddAction(UIAlertAction.Create(damageLevel, UIAlertActionStyle.Default, (o) => ChangeUserDamage(damageLevel)));
            prompt.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));

            // Needed to prevent crash on iPad.
            UIPopoverPresentationController ppc = prompt.PopoverPresentationController;
            if (ppc != null)
            {
                ppc.SourceView = _proButton;
                ppc.PermittedArrowDirections = UIPopoverArrowDirection.Up;
            }

            // Present the prompt to the user.
            PresentViewController(prompt, true, null);
        }

        private void ChangeUserDamage(string damageLevel)
        {
            _userDamageLevel = damageLevel;
            _damageButton.SetTitle($"Damage: {damageLevel}", UIControlState.Normal);
        }

        private async void CloseDamage(object sender, EventArgs e)
        {
            SwitchView(_defaultView);

            if (_serviceGeodatabase.VersionName != _serviceGeodatabase.DefaultVersionName)
            {
                await ApplyDamageChange();
            }

            // Clear the selection.
            _featureLayer.ClearSelection();
            _selectedFeature = null;
        }

        private void SwitchView(UIView view)
        {
            foreach (var sv in _topView.Subviews) sv.Hidden = true;
            view.Hidden = false;
        }

        public override void LoadView()
        {
            // Create the views.
            View = new UIView { BackgroundColor = ApplicationTheme.BackgroundColor };

            _myMapView = new MapView();
            _myMapView.TranslatesAutoresizingMaskIntoConstraints = false;

            _topView = new UIView
            {
                BackgroundColor = ApplicationTheme.BackgroundColor,
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            _defaultView = new UIStackView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Spacing = 8,
                LayoutMarginsRelativeArrangement = true,
                Alignment = UIStackViewAlignment.Top,
                LayoutMargins = new UIEdgeInsets(8, 8, 8, 8),
                Axis = UILayoutConstraintAxis.Vertical,
            };

            UILabel instructions = new UILabel { TranslatesAutoresizingMaskIntoConstraints = false, Text = "Tap to select a feature." };

            _versionLabel = new UILabel { TranslatesAutoresizingMaskIntoConstraints = false, };

            _versionButton = new UIButton { TranslatesAutoresizingMaskIntoConstraints = false, Enabled = false };
            _versionButton.SetTitle("Create version", UIControlState.Normal);
            _versionButton.SetTitleColor(View.TintColor, UIControlState.Normal);

            _defaultView.AddArrangedSubview(instructions);
            _defaultView.AddArrangedSubview(_versionLabel);
            _defaultView.AddArrangedSubview(_versionButton);

            _versionView = new UIStackView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Spacing = 8,
                LayoutMarginsRelativeArrangement = true,
                Alignment = UIStackViewAlignment.Top,
                LayoutMargins = new UIEdgeInsets(8, 8, 8, 8),
                Axis = UILayoutConstraintAxis.Vertical,
                Hidden = true,
            };

            _nameField = new UITextField { Placeholder = "Name", };

            _proButton = new UIButton { };
            _proButton.SetTitle("Protection:", UIControlState.Normal);
            _proButton.SetTitleColor(View.TintColor, UIControlState.Normal);

            _descriptionField = new UITextField { Placeholder = "Description" };

            _confirmButton = new UIButton { };
            _confirmButton.SetTitle("Confirm", UIControlState.Normal);
            _confirmButton.SetTitleColor(View.TintColor, UIControlState.Normal);

            _cancelButton = new UIButton { };
            _cancelButton.SetTitle("Cancel", UIControlState.Normal);
            _cancelButton.SetTitleColor(UIColor.Red, UIControlState.Normal);

            _versionView.AddArrangedSubview(_nameField);
            _versionView.AddArrangedSubview(_proButton);
            _versionView.AddArrangedSubview(_descriptionField);
            _versionView.AddArrangedSubview(getRowStackView(new UIView[] { _confirmButton, _cancelButton }));

            _damageView = new UIStackView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Spacing = 8,
                LayoutMarginsRelativeArrangement = true,
                Alignment = UIStackViewAlignment.Top,
                LayoutMargins = new UIEdgeInsets(8, 8, 8, 8),
                Axis = UILayoutConstraintAxis.Vertical,
                Hidden = true,
            };

            _moveText = new UILabel { TranslatesAutoresizingMaskIntoConstraints = false, Text = "Tap to move feature." };

            _damageButton = new UIButton { };
            _damageButton.SetTitle("Damage:", UIControlState.Normal);
            _damageButton.SetTitleColor(View.TintColor, UIControlState.Normal);

            _closeButton = new UIButton { };
            _closeButton.SetTitle("Close", UIControlState.Normal);
            _closeButton.SetTitleColor(UIColor.Red, UIControlState.Normal);

            _damageView.AddArrangedSubview(_moveText);
            _damageView.AddArrangedSubview(_damageButton);
            _damageView.AddArrangedSubview(_closeButton);

            _topView.AddSubviews(_defaultView, _versionView, _damageView);

            // Add the views.
            View.AddSubviews(_myMapView, _topView);

            // Lay out the views.
            NSLayoutConstraint.ActivateConstraints(new[]
            {
                _topView.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor),
                _topView.LeadingAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.LeadingAnchor),
                _topView.TrailingAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TrailingAnchor),
                _topView.HeightAnchor.ConstraintEqualTo(150),

                _myMapView.TopAnchor.ConstraintEqualTo(_topView.BottomAnchor),
                _myMapView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor),
                _myMapView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _myMapView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
            });
        }

        private UIStackView getRowStackView(UIView[] views)
        {
            UIStackView row = new UIStackView(views);
            row.TranslatesAutoresizingMaskIntoConstraints = false;
            row.Spacing = 8;
            row.Axis = UILayoutConstraintAxis.Horizontal;
            row.Distribution = UIStackViewDistribution.FillEqually;
            return row;
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            _ = Initialize();
        }

        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            // Subscribe to events.
            _versionButton.TouchUpInside += VersionButtonClick;
            _proButton.TouchUpInside += ProtectionButtonClick;
            _confirmButton.TouchUpInside += ConfirmButtonClick;
            _cancelButton.TouchUpInside += CancelButtonClick;
            _damageButton.TouchUpInside += ChangeDamage;
            _closeButton.TouchUpInside += CloseDamage;
        }

        public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);

            // Unsubscribe from events, per best practice.
            _versionButton.TouchUpInside -= VersionButtonClick;
            _proButton.TouchUpInside -= ProtectionButtonClick;
            _confirmButton.TouchUpInside -= ConfirmButtonClick;
            _cancelButton.TouchUpInside -= CancelButtonClick;
            _damageButton.TouchUpInside -= ChangeDamage;
            _closeButton.TouchUpInside -= CloseDamage;
            _myMapView.GeoViewTapped -= MapView_GeoViewTapped;
        }
    }
}

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