// Request geometry and new message to the layer private async void AddSymbolAsync(SymbolViewModel symbolViewModel) { try { Dictionary<string, string> values = (Dictionary<string, string>)symbolViewModel.Model.Values; string geometryControlType = values["GeometryType"]; DrawShape requestedShape = DrawShape.Point; switch (geometryControlType) { case "Point": requestedShape = DrawShape.Point; break; case "Line": requestedShape = DrawShape.Polyline; break; case "Polygon": requestedShape = DrawShape.Polygon; break; case "Circle": requestedShape = DrawShape.Circle; break; case "Rectangular": requestedShape = DrawShape.Rectangle; break; default: await new MessageDialog("Selected symbol is not supported in this sample", "Symbol Dictionary Search Sample").ShowAsync(); return; } while (true) { Esri.ArcGISRuntime.Geometry.Geometry geometry = null; try { geometry = await MyMapView.Editor.RequestShapeAsync(requestedShape, null, null); } catch { } if (geometry == null) return; // Create a new message Message msg = new Message(); // Set the ID and other parts of the message msg.Id = Guid.NewGuid().ToString(); msg.Add("_type", "position_report"); msg.Add("_action", "update"); msg.Add("_wkid", MyMapView.SpatialReference.Wkid.ToString()); msg.Add("sic", _selectedSymbol.SymbolID); msg.Add("uniquedesignation", "1"); // Construct the Control Points based on the geometry type of the drawn geometry. switch (requestedShape) { case DrawShape.Point: MapPoint point = geometry as MapPoint; msg.Add("_control_points", point.X.ToString(CultureInfo.InvariantCulture) + "," + point.Y.ToString(CultureInfo.InvariantCulture)); break; case DrawShape.Polygon: Polygon polygon = geometry as Polygon; string cpts = string.Empty; foreach (var pt in polygon.Parts[0].GetPoints()) cpts += ";" + pt.X.ToString(CultureInfo.InvariantCulture) + "," + pt.Y.ToString(CultureInfo.InvariantCulture); msg.Add("_control_points", cpts); break; case DrawShape.Polyline: Polyline polyline = geometry as Polyline; cpts = string.Empty; foreach (var pt in polyline.Parts[0].GetPoints()) cpts += ";" + pt.X.ToString(CultureInfo.InvariantCulture) + "," + pt.Y.ToString(CultureInfo.InvariantCulture); msg.Add("_control_points", cpts); break; } // Process the message if (!_messageLayer.ProcessMessage(msg)) await new MessageDialog("Failed to process message.", "Symbol Dictionary Search Sample").ShowAsync(); btnClearMap.IsEnabled = true; } } catch (Exception ex) { var _x = new MessageDialog(ex.Message, "Symbol Dictionary Search Sample").ShowAsync(); } }
// Request geometry and new message to the layer private async Task AddSymbolAsync(DrawShape requestedShape) { try { // Keep adding messages until next symbol is selected while (true) { var geometry = await mapView.Editor.RequestShapeAsync(requestedShape, null, null); // Create a new message Message msg = new Message(); // Set the ID and other parts of the message msg.Id = Guid.NewGuid().ToString(); msg.Add("_type", "position_report"); msg.Add("_action", "update"); msg.Add("_wkid", "3857"); msg.Add("sic", _selectedSymbol.SymbolID); msg.Add("uniquedesignation", "1"); // Construct the Control Points based on the geometry type of the drawn geometry. switch (requestedShape) { case DrawShape.Point: MapPoint point = geometry as MapPoint; msg.Add("_control_points", point.X.ToString(CultureInfo.InvariantCulture) + "," + point.Y.ToString(CultureInfo.InvariantCulture)); break; case DrawShape.Polygon: Polygon polygon = geometry as Polygon; string cpts = string.Empty; foreach (var pt in polygon.Rings[0]) cpts += ";" + pt.X.ToString(CultureInfo.InvariantCulture) + "," + pt.Y.ToString(CultureInfo.InvariantCulture); msg.Add("_control_points", cpts); break; case DrawShape.Polyline: Polyline polyline = geometry as Polyline; cpts = string.Empty; foreach (var pt in polyline.Paths[0]) cpts += ";" + pt.X.ToString(CultureInfo.InvariantCulture) + "," + pt.Y.ToString(CultureInfo.InvariantCulture); msg.Add("_control_points", cpts); break; } // Process the message if (!_messageLayer.ProcessMessage(msg)) await new MessageDialog("Failed to process message.", "Symbol Dictionary Search Sample").ShowAsync(); } } catch (TaskCanceledException taskCanceledException) { // Requsting geometry was canceled. } catch (Exception ex) { var _ = new MessageDialog(ex.Message, "Symbol Dictionary Search Sample").ShowAsync(); } }
// Request geometry and new message to the layer private async void AddSymbolAsync(DrawShape requestedShape) { try { // Keep adding messages until next symbol is selected while (true) { Esri.ArcGISRuntime.Geometry.Geometry geometry = null; try { geometry = await MyMapView.Editor.RequestShapeAsync(requestedShape, null, null); } catch { } if (geometry == null) return; // Create a new message Message msg = new Message(); // Set the ID and other parts of the message msg.Id = Guid.NewGuid().ToString(); msg.Add("_type", "position_report"); msg.Add("_action", "update"); msg.Add("_wkid", MyMapView.SpatialReference.Wkid.ToString()); msg.Add("sic", _selectedSymbol.SymbolID); msg.Add("uniquedesignation", "1"); // Construct the Control Points based on the geometry type of the drawn geometry. switch (requestedShape) { case DrawShape.Point: MapPoint point = geometry as MapPoint; msg.Add("_control_points", point.X.ToString(CultureInfo.InvariantCulture) + "," + point.Y.ToString(CultureInfo.InvariantCulture)); break; case DrawShape.Polygon: Polygon polygon = geometry as Polygon; string cpts = string.Empty; foreach (var pt in polygon.Parts[0].GetPoints()) cpts += ";" + pt.X.ToString(CultureInfo.InvariantCulture) + "," + pt.Y.ToString(CultureInfo.InvariantCulture); msg.Add("_control_points", cpts); break; case DrawShape.Polyline: Polyline polyline = geometry as Polyline; cpts = string.Empty; foreach (var pt in polyline.Parts[0].GetPoints()) cpts += ";" + pt.X.ToString(CultureInfo.InvariantCulture) + "," + pt.Y.ToString(CultureInfo.InvariantCulture); msg.Add("_control_points", cpts); break; } // Process the message if (!_messageLayer.ProcessMessage(msg)) MessageBox.Show("Failed to process message."); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Symbol Dictionary Search Sample"); } }