-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathMyGeometryEditor.cs
197 lines (188 loc) · 7.17 KB
/
MyGeometryEditor.cs
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
using System.Diagnostics;
using System.Drawing;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI.Editing;
using WinRT;
namespace EditorDemo
{
public class MyGeometryEditor : GeometryEditor
{
#region Tool Configurations
private VertexTool _moveTool = new VertexTool()
{
Configuration = new InteractionConfiguration()
{
//AllowMovingSelectedElement = true,
AllowMidVertexSelection = false,
AllowDeletingSelectedElement = false,
AllowPartCreation = false,
AllowGeometrySelection = true,
AllowPartSelection = true,
AllowScalingSelectedElement = false,
AllowVertexCreation = false,
AllowVertexSelection = false,
AllowRotatingSelectedElement = false,
RequireSelectionBeforeMove = false
},
Style = new GeometryEditorStyle
{
MidVertexSymbol = null,
VertexSymbol = null,
SelectedVertexSymbol = null,
SelectedMidVertexSymbol = null,
FeedbackVertexSymbol = null
}
};
private VertexTool _rotateTool = new VertexTool()
{
Configuration = new InteractionConfiguration()
{
AllowMovingSelectedElement = false,
AllowMidVertexSelection = false,
AllowDeletingSelectedElement = false,
AllowPartCreation = false,
AllowGeometrySelection = true,
AllowPartSelection = true,
AllowScalingSelectedElement = false,
AllowVertexCreation = false,
AllowVertexSelection = false,
AllowRotatingSelectedElement = true,
RequireSelectionBeforeMove = false
},
Style = new GeometryEditorStyle
{
MidVertexSymbol = null,
VertexSymbol = null,
SelectedVertexSymbol = null,
SelectedMidVertexSymbol = null,
FeedbackVertexSymbol = null
}
};
private VertexTool _vertexTool = new VertexTool()
{
Configuration = new InteractionConfiguration()
{
AllowMovingSelectedElement = true,
AllowMidVertexSelection = true,
AllowDeletingSelectedElement = true,
AllowPartCreation = false,
AllowGeometrySelection = false,
AllowPartSelection = false,
AllowScalingSelectedElement = false,
AllowVertexCreation = true,
AllowVertexSelection = true,
AllowRotatingSelectedElement = false,
RequireSelectionBeforeMove = false
},
Style = new GeometryEditorStyle
{
VertexTextSymbol = null,
VertexSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Square, System.Drawing.Color.Black, 9),
SelectedVertexSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Square, System.Drawing.Color.Black, 9),
MidVertexSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Gray, 8),
SelectedMidVertexSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Gray, 8),
FeedbackVertexSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.Black, 10),
}
};
private VertexTool _inactiveTool = new VertexTool()
{
Configuration = new InteractionConfiguration()
{
AllowMovingSelectedElement = false,
AllowMidVertexSelection = false,
AllowDeletingSelectedElement = true,
AllowPartCreation = false,
AllowGeometrySelection = false,
AllowPartSelection = true,
AllowScalingSelectedElement = false,
AllowVertexCreation = false,
AllowVertexSelection = false,
AllowRotatingSelectedElement = false,
RequireSelectionBeforeMove = false
},
Style = new GeometryEditorStyle()
{
MidVertexSymbol = null,
VertexSymbol = null,
SelectedVertexSymbol = null,
SelectedMidVertexSymbol = null,
FeedbackVertexSymbol = null, BoundingBoxSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, System.Drawing.Color.Cyan, 2)
}
};
#endregion
public bool IsMoveActive => IsStarted && Tool == _moveTool;
public bool IsRotateActive => IsStarted && Tool == _rotateTool;
public bool IsEditVerticesActive => IsStarted && Tool == _vertexTool;
public MyGeometryEditor()
{
PropertyChanged += OnPropertyChanged;
}
private Geometry? _geometry;
public Symbol? Symbol { get; private set; }
public void SetInactive()
{
Tool = _inactiveTool;
}
public void Initialize(Geometry geometry, Symbol? symbol)
{
_geometry = geometry;
Symbol = symbol;
if (symbol is not null)
{
if (geometry is Polygon)
{
_vertexTool.Style.FillSymbol = _rotateTool.Style.FillSymbol = _moveTool.Style.FillSymbol = _inactiveTool.Style.FillSymbol = symbol;
}
else if (geometry is Polyline)
{
_vertexTool.Style.LineSymbol = _rotateTool.Style.LineSymbol = _moveTool.Style.LineSymbol = symbol;
_inactiveTool.Style.LineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Cyan, 2);
}
else if (geometry is MapPoint || geometry is Multipoint)
{
}
}
Start(geometry);
Tool = _inactiveTool;
}
private void OnPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IsStarted):
break;
case nameof(SelectedElement):
break;
case nameof(Tool):
break;
case nameof(Geometry):
break;
}
}
private void EnsureStarted()
{
Debug.Assert(_geometry != null, "Geometry not set");
if (!IsStarted)
Start(_geometry);
}
public void Move()
{
Tool = _moveTool;
EnsureStarted();
SelectGeometry();
}
public void EditVertices()
{
Tool = _vertexTool;
EnsureStarted();
ClearSelection();
}
public void Rotate()
{
Tool = _rotateTool;
EnsureStarted();
SelectGeometry();
}
}
}