Skip to content

Commit 16f73ff

Browse files
authored
Implement samples using ReticleVertexTool for UWP (#1480)
1 parent ad2e9c5 commit 16f73ff

File tree

23 files changed

+1537
-505
lines changed

23 files changed

+1537
-505
lines changed

src/MAUI/Maui.Samples/Samples/NetworkAnalysis/FindServiceArea/FindServiceArea.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public FindServiceArea()
3434
{
3535
InitializeComponent();
3636

37-
// Create the map, graphics overlay, and sketch editor.
37+
// Create the map, graphics overlay, and geometry editor.
3838
Initialize();
3939
}
4040

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

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

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

133133
// Start the geometry editor.

src/UWP/ArcGIS.UWP.Viewer/ArcGIS.UWP.Viewer.csproj

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@
121121
</ItemGroup>
122122
<ItemGroup>
123123
<!-- Screenshots -->
124+
<Content Include="Samples\Geometry\CreateAndEditGeometries\CreateAndEditGeometries.jpg" />
125+
<Content Include="Samples\Geometry\SnapGeometryEdits\SnapGeometryEdits.jpg" />
124126
<Content Include="Samples\Location\LocationDrivenGeotriggers\LocationDrivenGeotriggers.jpg" />
125127
<Content Include="Samples\Layers\QueryCQLFilters\QueryCQLFilters.jpg" />
126128
<Content Include="Samples\Layers\DisplayOACollection\DisplayOACollection.jpg" />
@@ -179,6 +181,7 @@
179181
<Content Include="Samples\Geometry\NearestVertex\NearestVertex.jpg" />
180182
<Content Include="Samples\Geometry\Project\Project.jpg" />
181183
<Content Include="Samples\Geometry\ProjectWithSpecificTransformation\ProjectWithSpecificTransformation.jpg" />
184+
<Content Include="Samples\Geometry\SnapGeometryEdits\SnapGeometryEdits.jpg" />
182185
<Content Include="Samples\Geometry\SpatialOperations\SpatialOperations.jpg" />
183186
<Content Include="Samples\Geometry\SpatialRelationships\SpatialRelationships.jpg" />
184187
<Content Include="Samples\Geoprocessing\AnalyzeHotspots\AnalyzeHotspots.jpg" />
@@ -190,7 +193,6 @@
190193
<Content Include="Samples\GraphicsOverlay\DictionaryRendererGraphicsOverlay\DictionaryRendererGraphicsOverlay.jpg" />
191194
<Content Include="Samples\GraphicsOverlay\IdentifyGraphics\IdentifyGraphics.jpg" />
192195
<Content Include="Samples\GraphicsOverlay\ScenePropertiesExpressions\ScenePropertiesExpressions.jpg" />
193-
<Content Include="Samples\GraphicsOverlay\SketchOnMap\SketchOnMap.jpg" />
194196
<Content Include="Samples\GraphicsOverlay\SurfacePlacements\SurfacePlacements.jpg" />
195197
<Content Include="Samples\Hydrography\AddEncExchangeSet\AddEncExchangeSet.jpg" />
196198
<Content Include="Samples\Hydrography\ChangeEncDisplaySettings\ChangeEncDisplaySettings.jpg" />
@@ -386,6 +388,9 @@
386388
</ItemGroup>
387389
<ItemGroup>
388390
<!-- Sample Code -->
391+
<Compile Include="Samples\Geometry\SnapGeometryEdits\SnapGeometryEdits.xaml.cs">
392+
<DependentUpon>SnapGeometryEdits.xaml</DependentUpon>
393+
</Compile>
389394
<Compile Include="Samples\Location\LocationDrivenGeotriggers\LocationDrivenGeotriggers.xaml.cs">
390395
<DependentUpon>LocationDrivenGeotriggers.xaml</DependentUpon>
391396
</Compile>
@@ -705,6 +710,9 @@
705710
<Compile Include="Samples\Geometry\CutGeometry\CutGeometry.xaml.cs">
706711
<DependentUpon>CutGeometry.xaml</DependentUpon>
707712
</Compile>
713+
<Compile Include="Samples\Geometry\CreateAndEditGeometries\CreateAndEditGeometries.xaml.cs">
714+
<DependentUpon>CreateAndEditGeometries.xaml</DependentUpon>
715+
</Compile>
708716
<Compile Include="Samples\Geometry\CreateGeometries\CreateGeometries.xaml.cs">
709717
<DependentUpon>CreateGeometries.xaml</DependentUpon>
710718
</Compile>
@@ -747,9 +755,6 @@
747755
<Compile Include="Samples\GraphicsOverlay\IdentifyGraphics\IdentifyGraphics.xaml.cs">
748756
<DependentUpon>IdentifyGraphics.xaml</DependentUpon>
749757
</Compile>
750-
<Compile Include="Samples\GraphicsOverlay\SketchOnMap\SketchOnMap.xaml.cs">
751-
<DependentUpon>SketchOnMap.xaml</DependentUpon>
752-
</Compile>
753758
<Compile Include="Samples\GraphicsOverlay\SurfacePlacements\SurfacePlacements.xaml.cs">
754759
<DependentUpon>SurfacePlacements.xaml</DependentUpon>
755760
</Compile>
@@ -999,6 +1004,10 @@
9991004
</ItemGroup>
10001005
<ItemGroup>
10011006
<!-- Sample XAML -->
1007+
<Page Include="Samples\Geometry\SnapGeometryEdits\SnapGeometryEdits.xaml">
1008+
<SubType>Designer</SubType>
1009+
<Generator>MSBuild:Compile</Generator>
1010+
</Page>
10021011
<Page Include="Samples\Location\LocationDrivenGeotriggers\LocationDrivenGeotriggers.xaml">
10031012
<Generator>MSBuild:Compile</Generator>
10041013
<SubType>Designer</SubType>
@@ -1407,6 +1416,10 @@
14071416
<Generator>MSBuild:Compile</Generator>
14081417
<SubType>Designer</SubType>
14091418
</Page>
1419+
<Page Include="Samples\Geometry\CreateAndEditGeometries\CreateAndEditGeometries.xaml">
1420+
<Generator>MSBuild:Compile</Generator>
1421+
<SubType>Designer</SubType>
1422+
</Page>
14101423
<Page Include="Samples\Geometry\CreateGeometries\CreateGeometries.xaml">
14111424
<Generator>MSBuild:Compile</Generator>
14121425
<SubType>Designer</SubType>
@@ -1463,10 +1476,6 @@
14631476
<Generator>MSBuild:Compile</Generator>
14641477
<SubType>Designer</SubType>
14651478
</Page>
1466-
<Page Include="Samples\GraphicsOverlay\SketchOnMap\SketchOnMap.xaml">
1467-
<Generator>MSBuild:Compile</Generator>
1468-
<SubType>Designer</SubType>
1469-
</Page>
14701479
<Page Include="Samples\GraphicsOverlay\SurfacePlacements\SurfacePlacements.xaml">
14711480
<Generator>MSBuild:Compile</Generator>
14721481
<SubType>Designer</SubType>
@@ -1801,6 +1810,9 @@
18011810
<Compile Include="App.xaml.cs">
18021811
<DependentUpon>App.xaml</DependentUpon>
18031812
</Compile>
1813+
<Compile Include="Converters\InverseBoolConverter.cs">
1814+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1815+
</Compile>
18041816
<Compile Include="Converters\NullToVisibilityConverter.cs">
18051817
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18061818
</Compile>
@@ -1883,7 +1895,6 @@
18831895
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18841896
</Content>
18851897
</ItemGroup>
1886-
<ItemGroup />
18871898
<!-- Imports -->
18881899
<Import Project="..\..\Samples.Shared\ArcGIS.Samples.Shared.projitems" Label="Shared" />
18891900
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2016 Esri.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
5+
//
6+
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
7+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
8+
// language governing permissions and limitations under the License.
9+
10+
using System;
11+
using Windows.UI.Xaml.Data;
12+
13+
namespace ArcGIS.UWP.Viewer.Converters
14+
{
15+
public class InverseBoolConverter : IValueConverter
16+
{
17+
public object Convert(object value, Type targetType, object parameter, string culture)
18+
{
19+
if (value is bool)
20+
{
21+
return !(bool)value;
22+
}
23+
24+
return null;
25+
}
26+
27+
public object ConvertBack(object value, Type targetType, object parameter, string culture)
28+
{
29+
throw new NotImplementedException();
30+
}
31+
}
32+
}

src/UWP/ArcGIS.UWP.Viewer/Samples/Data/GeodatabaseTransactions/GeodatabaseTransactions.xaml.cs

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
88
// Language governing permissions and limitations under the License.
99

10+
using Esri.ArcGISRuntime;
1011
using Esri.ArcGISRuntime.Data;
1112
using Esri.ArcGISRuntime.Geometry;
1213
using Esri.ArcGISRuntime.Mapping;
1314
using Esri.ArcGISRuntime.Tasks;
1415
using Esri.ArcGISRuntime.Tasks.Offline;
16+
using Esri.ArcGISRuntime.UI.Editing;
1517
using System;
1618
using System.IO;
1719
using System.Threading.Tasks;
@@ -43,6 +45,9 @@ public partial class GeodatabaseTransactions
4345
private GeodatabaseFeatureTable _birdTable;
4446
private GeodatabaseFeatureTable _marineTable;
4547

48+
// Store a reference to the table to be edited.
49+
private GeodatabaseFeatureTable _editTable;
50+
4651
public GeodatabaseTransactions()
4752
{
4853
InitializeComponent();
@@ -216,64 +221,78 @@ private void BeginTransaction(object sender, RoutedEventArgs e)
216221
}
217222
}
218223

219-
private async void AddNewFeature(object sender, RoutedEventArgs args)
224+
private void AddNewFeature(object sender, RoutedEventArgs args)
220225
{
221-
// See if it was the "Birds" or "Marine" button that was clicked
226+
// See if it was the "Birds" or "Marine" button that was clicked.
222227
Button addFeatureButton = (Button)sender;
223228

224229
try
225230
{
226-
// Cancel execution of the sketch task if it is already active
227-
if (MyMapView.SketchEditor.CancelCommand.CanExecute(null))
228-
{
229-
MyMapView.SketchEditor.CancelCommand.Execute(null);
230-
}
231-
232-
// Store the correct table to edit (for the button clicked)
233-
GeodatabaseFeatureTable editTable = null;
231+
// Store the correct table to edit (for the button clicked).
234232
if (addFeatureButton == AddBirdButton)
235233
{
236-
editTable = _birdTable;
234+
_editTable = _birdTable;
237235
}
238236
else
239237
{
240-
editTable = _marineTable;
238+
_editTable = _marineTable;
241239
}
242240

243-
// Inform the user which table is being edited
244-
MessageTextBlock.Text = "Click the map to add a new feature to the geodatabase table '" + editTable.TableName + "'";
245-
246-
// Create a random value for the 'type' attribute (integer between 1 and 7)
247-
Random random = new Random(DateTime.Now.Millisecond);
248-
int featureType = random.Next(1, 7);
249-
250-
// Use the sketch editor to allow the user to draw a point on the map
251-
MapPoint clickPoint = await MyMapView.SketchEditor.StartAsync(Esri.ArcGISRuntime.UI.SketchCreationMode.Point, false) as MapPoint;
252-
253-
// Create a new feature (row) in the selected table
254-
Feature newFeature = editTable.CreateFeature();
241+
// Inform the user which table is being edited.
242+
MessageTextBlock.Text = "Click the map to add a new feature to the geodatabase table '" + _editTable.TableName + "'.";
255243

256-
// Set the geometry with the point the user clicked and the 'type' with the random integer
257-
newFeature.Geometry = clickPoint;
258-
newFeature.SetAttributeValue("type", featureType);
259-
260-
// Add the new feature to the table
261-
await editTable.AddFeatureAsync(newFeature);
244+
if (!MyMapView.GeometryEditor.IsStarted)
245+
{
246+
// Use the geometry editor to allow the user to draw a point on the map.
247+
MyMapView.GeometryEditor.Start(GeometryType.Point);
262248

263-
// Clear the message
264-
MessageTextBlock.Text = "New feature added to the '" + editTable.TableName + "' table";
265-
}
266-
catch (TaskCanceledException)
267-
{
268-
// Ignore if the edit was canceled
249+
MyMapView.GeometryEditor.PropertyChanged += GeometryEditor_PropertyChanged;
250+
}
269251
}
270252
catch (Exception ex)
271253
{
272-
// Report other exception messages
254+
// Report other exception messages.
273255
MessageTextBlock.Text = ex.Message;
274256
}
275257
}
276258

259+
private async void GeometryEditor_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
260+
{
261+
// Check if the user finished drawing a point on the map.
262+
if (e.PropertyName == nameof(GeometryEditor.Geometry) && MyMapView.GeometryEditor.Geometry?.IsEmpty == false)
263+
{
264+
// Disconnect event handler to prevent multiple calls.
265+
MyMapView.GeometryEditor.PropertyChanged -= GeometryEditor_PropertyChanged;
266+
267+
// Get the active geometry.
268+
Geometry geometry = MyMapView.GeometryEditor.Stop();
269+
270+
// Create a new feature (row) in the selected table.
271+
Feature newFeature = _editTable.CreateFeature();
272+
273+
// Create a random value for the 'type' attribute (integer between 1 and 7).
274+
var random = new Random(DateTime.Now.Millisecond);
275+
int featureType = random.Next(1, 7);
276+
277+
// Set the geometry with the point the user clicked and the 'type' with the random integer.
278+
newFeature.Geometry = geometry;
279+
newFeature.SetAttributeValue("type", featureType);
280+
281+
// Add the new feature to the table.
282+
string message = string.Empty;
283+
try
284+
{
285+
await _editTable.AddFeatureAsync(newFeature);
286+
MessageTextBlock.Text = "New feature added to the '" + _editTable.TableName + "' table.";
287+
}
288+
catch (ArcGISException ex)
289+
{
290+
// Report the exception message.
291+
MessageTextBlock.Text = ex.Message;
292+
}
293+
}
294+
}
295+
277296
private async void StopEditTransaction(object sender, RoutedEventArgs e)
278297
{
279298
// Create a new dialog that prompts for commit, rollback, or cancel
375 KB
Loading

0 commit comments

Comments
 (0)