Skip to content

Commit

Permalink
Implement samples using ReticleVertexTool for UWP (#1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
duffh authored and williambohrmann3 committed Jul 31, 2024
1 parent 4ac8fb7 commit 7b2fd92
Show file tree
Hide file tree
Showing 23 changed files with 1,537 additions and 505 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public FindServiceArea()
{
InitializeComponent();

// Create the map, graphics overlay, and sketch editor.
// Create the map, graphics overlay, and geometry editor.
Initialize();
}

Expand Down Expand Up @@ -64,7 +64,7 @@ private async void PlaceFacilityButton_Click(object sender, EventArgs e)
{
try
{
// Let the user tap on the map view using the point sketch mode.
// Let the user tap on the map view using the point geometry type.
_geometryType = GeometryType.Point;

// Start the geometry editor.
Expand Down Expand Up @@ -127,7 +127,7 @@ private async void DrawBarrierButton_Click(object sender, EventArgs e)
// Update the UI.
DrawBarrierButton.Text = "Finish drawing";

// Let the user draw on the map view using the polyline sketch mode.
// Let the user draw on the map view using the polyline geometry type.
_geometryType = GeometryType.Polyline;

// Start the geometry editor.
Expand Down
29 changes: 20 additions & 9 deletions src/UWP/ArcGIS.UWP.Viewer/ArcGIS.UWP.Viewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
</ItemGroup>
<ItemGroup>
<!-- Screenshots -->
<Content Include="Samples\Geometry\CreateAndEditGeometries\CreateAndEditGeometries.jpg" />
<Content Include="Samples\Geometry\SnapGeometryEdits\SnapGeometryEdits.jpg" />
<Content Include="Samples\Location\LocationDrivenGeotriggers\LocationDrivenGeotriggers.jpg" />
<Content Include="Samples\Layers\QueryCQLFilters\QueryCQLFilters.jpg" />
<Content Include="Samples\Layers\DisplayOACollection\DisplayOACollection.jpg" />
Expand Down Expand Up @@ -179,6 +181,7 @@
<Content Include="Samples\Geometry\NearestVertex\NearestVertex.jpg" />
<Content Include="Samples\Geometry\Project\Project.jpg" />
<Content Include="Samples\Geometry\ProjectWithSpecificTransformation\ProjectWithSpecificTransformation.jpg" />
<Content Include="Samples\Geometry\SnapGeometryEdits\SnapGeometryEdits.jpg" />
<Content Include="Samples\Geometry\SpatialOperations\SpatialOperations.jpg" />
<Content Include="Samples\Geometry\SpatialRelationships\SpatialRelationships.jpg" />
<Content Include="Samples\Geoprocessing\AnalyzeHotspots\AnalyzeHotspots.jpg" />
Expand All @@ -190,7 +193,6 @@
<Content Include="Samples\GraphicsOverlay\DictionaryRendererGraphicsOverlay\DictionaryRendererGraphicsOverlay.jpg" />
<Content Include="Samples\GraphicsOverlay\IdentifyGraphics\IdentifyGraphics.jpg" />
<Content Include="Samples\GraphicsOverlay\ScenePropertiesExpressions\ScenePropertiesExpressions.jpg" />
<Content Include="Samples\GraphicsOverlay\SketchOnMap\SketchOnMap.jpg" />
<Content Include="Samples\GraphicsOverlay\SurfacePlacements\SurfacePlacements.jpg" />
<Content Include="Samples\Hydrography\AddEncExchangeSet\AddEncExchangeSet.jpg" />
<Content Include="Samples\Hydrography\ChangeEncDisplaySettings\ChangeEncDisplaySettings.jpg" />
Expand Down Expand Up @@ -386,6 +388,9 @@
</ItemGroup>
<ItemGroup>
<!-- Sample Code -->
<Compile Include="Samples\Geometry\SnapGeometryEdits\SnapGeometryEdits.xaml.cs">
<DependentUpon>SnapGeometryEdits.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\Location\LocationDrivenGeotriggers\LocationDrivenGeotriggers.xaml.cs">
<DependentUpon>LocationDrivenGeotriggers.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -705,6 +710,9 @@
<Compile Include="Samples\Geometry\CutGeometry\CutGeometry.xaml.cs">
<DependentUpon>CutGeometry.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\Geometry\CreateAndEditGeometries\CreateAndEditGeometries.xaml.cs">
<DependentUpon>CreateAndEditGeometries.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\Geometry\CreateGeometries\CreateGeometries.xaml.cs">
<DependentUpon>CreateGeometries.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -747,9 +755,6 @@
<Compile Include="Samples\GraphicsOverlay\IdentifyGraphics\IdentifyGraphics.xaml.cs">
<DependentUpon>IdentifyGraphics.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\GraphicsOverlay\SketchOnMap\SketchOnMap.xaml.cs">
<DependentUpon>SketchOnMap.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\GraphicsOverlay\SurfacePlacements\SurfacePlacements.xaml.cs">
<DependentUpon>SurfacePlacements.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -999,6 +1004,10 @@
</ItemGroup>
<ItemGroup>
<!-- Sample XAML -->
<Page Include="Samples\Geometry\SnapGeometryEdits\SnapGeometryEdits.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Samples\Location\LocationDrivenGeotriggers\LocationDrivenGeotriggers.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -1407,6 +1416,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Samples\Geometry\CreateAndEditGeometries\CreateAndEditGeometries.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Samples\Geometry\CreateGeometries\CreateGeometries.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -1463,10 +1476,6 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Samples\GraphicsOverlay\SketchOnMap\SketchOnMap.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Samples\GraphicsOverlay\SurfacePlacements\SurfacePlacements.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -1801,6 +1810,9 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\InverseBoolConverter.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
<Compile Include="Converters\NullToVisibilityConverter.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
Expand Down Expand Up @@ -1883,7 +1895,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup />
<!-- Imports -->
<Import Project="..\..\Samples.Shared\ArcGIS.Samples.Shared.projitems" Label="Shared" />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
Expand Down
32 changes: 32 additions & 0 deletions src/UWP/ArcGIS.UWP.Viewer/Converters/InverseBoolConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2016 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 System;
using Windows.UI.Xaml.Data;

namespace ArcGIS.UWP.Viewer.Converters
{
public class InverseBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string culture)
{
if (value is bool)
{
return !(bool)value;
}

return null;
}

public object ConvertBack(object value, Type targetType, object parameter, string culture)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
// "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 Esri.ArcGISRuntime;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.Tasks.Offline;
using Esri.ArcGISRuntime.UI.Editing;
using System;
using System.IO;
using System.Threading.Tasks;
Expand Down Expand Up @@ -43,6 +45,9 @@ public partial class GeodatabaseTransactions
private GeodatabaseFeatureTable _birdTable;
private GeodatabaseFeatureTable _marineTable;

// Store a reference to the table to be edited.
private GeodatabaseFeatureTable _editTable;

public GeodatabaseTransactions()
{
InitializeComponent();
Expand Down Expand Up @@ -216,64 +221,78 @@ private void BeginTransaction(object sender, RoutedEventArgs e)
}
}

private async void AddNewFeature(object sender, RoutedEventArgs args)
private void AddNewFeature(object sender, RoutedEventArgs args)
{
// See if it was the "Birds" or "Marine" button that was clicked
// See if it was the "Birds" or "Marine" button that was clicked.
Button addFeatureButton = (Button)sender;

try
{
// Cancel execution of the sketch task if it is already active
if (MyMapView.SketchEditor.CancelCommand.CanExecute(null))
{
MyMapView.SketchEditor.CancelCommand.Execute(null);
}

// Store the correct table to edit (for the button clicked)
GeodatabaseFeatureTable editTable = null;
// Store the correct table to edit (for the button clicked).
if (addFeatureButton == AddBirdButton)
{
editTable = _birdTable;
_editTable = _birdTable;
}
else
{
editTable = _marineTable;
_editTable = _marineTable;
}

// Inform the user which table is being edited
MessageTextBlock.Text = "Click the map to add a new feature to the geodatabase table '" + editTable.TableName + "'";

// Create a random value for the 'type' attribute (integer between 1 and 7)
Random random = new Random(DateTime.Now.Millisecond);
int featureType = random.Next(1, 7);

// Use the sketch editor to allow the user to draw a point on the map
MapPoint clickPoint = await MyMapView.SketchEditor.StartAsync(Esri.ArcGISRuntime.UI.SketchCreationMode.Point, false) as MapPoint;

// Create a new feature (row) in the selected table
Feature newFeature = editTable.CreateFeature();
// Inform the user which table is being edited.
MessageTextBlock.Text = "Click the map to add a new feature to the geodatabase table '" + _editTable.TableName + "'.";

// Set the geometry with the point the user clicked and the 'type' with the random integer
newFeature.Geometry = clickPoint;
newFeature.SetAttributeValue("type", featureType);

// Add the new feature to the table
await editTable.AddFeatureAsync(newFeature);
if (!MyMapView.GeometryEditor.IsStarted)
{
// Use the geometry editor to allow the user to draw a point on the map.
MyMapView.GeometryEditor.Start(GeometryType.Point);

// Clear the message
MessageTextBlock.Text = "New feature added to the '" + editTable.TableName + "' table";
}
catch (TaskCanceledException)
{
// Ignore if the edit was canceled
MyMapView.GeometryEditor.PropertyChanged += GeometryEditor_PropertyChanged;
}
}
catch (Exception ex)
{
// Report other exception messages
// Report other exception messages.
MessageTextBlock.Text = ex.Message;
}
}

private async void GeometryEditor_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
// Check if the user finished drawing a point on the map.
if (e.PropertyName == nameof(GeometryEditor.Geometry) && MyMapView.GeometryEditor.Geometry?.IsEmpty == false)
{
// Disconnect event handler to prevent multiple calls.
MyMapView.GeometryEditor.PropertyChanged -= GeometryEditor_PropertyChanged;

// Get the active geometry.
Geometry geometry = MyMapView.GeometryEditor.Stop();

// Create a new feature (row) in the selected table.
Feature newFeature = _editTable.CreateFeature();

// Create a random value for the 'type' attribute (integer between 1 and 7).
var random = new Random(DateTime.Now.Millisecond);
int featureType = random.Next(1, 7);

// Set the geometry with the point the user clicked and the 'type' with the random integer.
newFeature.Geometry = geometry;
newFeature.SetAttributeValue("type", featureType);

// Add the new feature to the table.
string message = string.Empty;
try
{
await _editTable.AddFeatureAsync(newFeature);
MessageTextBlock.Text = "New feature added to the '" + _editTable.TableName + "' table.";
}
catch (ArcGISException ex)
{
// Report the exception message.
MessageTextBlock.Text = ex.Message;
}
}
}

private async void StopEditTransaction(object sender, RoutedEventArgs e)
{
// Create a new dialog that prompts for commit, rollback, or cancel
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7b2fd92

Please sign in to comment.