private void AddNewMessage(SymbolViewModel symbolViewModel, Point p, string guid) { //create a new message var tam = new TimeAwareMilitaryMessage { VisibleTimeExtent = new TimeExtent(_mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.Start, _mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.End), Id = guid }; tam.Add(MilitaryMessage.TypePropertyName, Constants.MSG_TYPE_POSITION_REPORT); tam.Add(MilitaryMessage.ActionPropertyName, Constants.MSG_ACTION_UPDATE); tam.Add(MilitaryMessage.WkidPropertyName, "3857"); tam.Add(MilitaryMessage.SicCodePropertyName, symbolViewModel.SymbolID); tam.Add(MilitaryMessage.UniqueDesignationPropertyName, "1"); // Construct the Control Points based on the geometry type of the drawn geometry. var point = _mapView.ScreenToLocation(p); tam.SymbolGeometry = point; tam.Add(MilitaryMessage.ControlPointsPropertyName, point.X.ToString() + "," + point.Y.ToString()); //Process the message if (ProcessMessage(_militaryMessageLayer, tam)) { RecordMessageBeingAdded(tam); DoCloneMission(null); } else { MessageBox.Show("Failed to process message."); } }
private List <MapPoint> AdjustMapPoints(Polyline polyline, SymbolViewModel symbol) { // TODO find a better way to determine if we need to adjust the control points for the symbol if (symbol.SymbolID.Contains("POLA") || symbol.SymbolID.Contains("PPA")) { return(AdjustMapPoints(polyline, DrawShape.Arrow)); } return(AdjustMapPoints(polyline, DrawShape.Polyline)); }
private async void DoActionSymbolChanged(object param) { _selectedSymbol = param as SymbolViewModel; //Cancel editing if started if (_mapView.Editor.Cancel.CanExecute(null)) { _mapView.Editor.Cancel.Execute(null); } if (_selectedSymbol != null) { Dictionary <string, string> values = (Dictionary <string, string>)_selectedSymbol.Model.Values; _geometryType = values["GeometryType"]; DrawShape drawShape = DrawShape.Point; switch (_geometryType) { case "Point": drawShape = DrawShape.Point; break; case "Line": drawShape = DrawShape.Polyline; break; case "Polygon": drawShape = DrawShape.Polygon; break; default: drawShape = DrawShape.Point; break; } _editState = EditState.Create; try { // get geometry from editor var geometry = await _mapView.Editor.RequestShapeAsync(drawShape); _editState = EditState.None; // process symbol with geometry ProcessSymbol(_selectedSymbol, geometry); } catch (TaskCanceledException) { // clean up when drawing task is canceled } } }
/// <summary> /// Handler for when a selection of a symbol has changed /// </summary> /// <param name="param"></param> private void OnSymbolChanged(object param) { var e = param as SelectionChangedEventArgs; if (e == null) { return; } if (e.AddedItems.Count != 1) { return; } if (e.AddedItems[0].GetType() != typeof(SymbolViewModel)) { return; } SelectedSymbol = e.AddedItems[0] as SymbolViewModel; }
private List<MapPoint> AdjustMapPoints(Polyline polyline, SymbolViewModel symbol) { // TODO find a better way to determine if we need to adjust the control points for the symbol if (symbol.SymbolID.Contains("POLA") || symbol.SymbolID.Contains("PPA")) { return AdjustMapPoints(polyline, DrawShape.Arrow); } return AdjustMapPoints(polyline, DrawShape.Polyline); }
private void ProcessSymbol(SymbolViewModel symbol, Geometry geometry) { if (symbol == null || geometry == null) { return; } //create a new message var msg = new TimeAwareMilitaryMessage { VisibleTimeExtent = new TimeExtent(_mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.Start, _mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.End), Id = Guid.NewGuid().ToString("D"), SymbolGeometry = geometry }; // set default time extent //set the ID and other parts of the message msg.Add(MilitaryMessage.TypePropertyName, Constants.MSG_TYPE_POSITION_REPORT); msg.Add(MilitaryMessage.ActionPropertyName, Constants.MSG_ACTION_UPDATE); msg.Add(MilitaryMessage.WkidPropertyName, "3857"); msg.Add(MilitaryMessage.SicCodePropertyName, symbol.SymbolID); msg.Add(MilitaryMessage.UniqueDesignationPropertyName, "1"); // Construct the Control Points based on the geometry type of the drawn geometry. switch (geometry.GeometryType) { case GeometryType.Point: MapPoint point = geometry as MapPoint; if (point != null) msg.Add(MilitaryMessage.ControlPointsPropertyName, string.Format("{0},{1}", point.X.ToString(), point.Y.ToString())); break; case GeometryType.Polygon: Polygon polygon = geometry as Polygon; string cpts = polygon.Parts.SelectMany(pt => pt.GetPoints()).Aggregate(string.Empty, (current, segpt) => current + (";" + segpt.X.ToString() + "," + segpt.Y.ToString())); //foreach (var pt in polygon.Rings[0]) msg.Add(MilitaryMessage.ControlPointsPropertyName, cpts); break; case GeometryType.Polyline: Polyline polyline = geometry as Polyline; cpts = string.Empty; // TODO find a way to determine if polyline map points need adjustment based on symbol being drawn var mpList = AdjustMapPoints(polyline, symbol); cpts = mpList.Aggregate(cpts, (current, mp) => current + (";" + mp.X.ToString() + "," + mp.Y.ToString())); msg.Add(MilitaryMessage.ControlPointsPropertyName, cpts); break; } //Process the message if (ProcessMessage(_militaryMessageLayer, msg)) { RecordMessageBeingAdded(msg); DoCloneMission(null); } else { MessageBox.Show("Failed to process message."); } }
private async void DoActionSymbolChanged(object param) { _selectedSymbol = param as SymbolViewModel; //Cancel editing if started if (_mapView.Editor.Cancel.CanExecute(null)) { _mapView.Editor.Cancel.Execute(null); } if (_selectedSymbol != null) { Dictionary<string, string> values = (Dictionary<string, string>)_selectedSymbol.Model.Values; _geometryType = values["GeometryType"]; DrawShape drawShape = DrawShape.Point; switch (_geometryType) { case "Point": drawShape = DrawShape.Point; break; case "Line": drawShape = DrawShape.Polyline; break; case "Polygon": drawShape = DrawShape.Polygon; break; default: drawShape = DrawShape.Point; break; } _editState = EditState.Create; try { // get geometry from editor var geometry = await _mapView.Editor.RequestShapeAsync(drawShape); _editState = EditState.None; // process symbol with geometry ProcessSymbol(_selectedSymbol, geometry); } catch (TaskCanceledException) { // clean up when drawing task is canceled } } }
private void ProcessSymbol(SymbolViewModel symbol, Geometry geometry) { if (symbol == null || geometry == null) { return; } //create a new message var msg = new TimeAwareMilitaryMessage { VisibleTimeExtent = new TimeExtent(_mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.Start, _mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.End), Id = Guid.NewGuid().ToString("D"), SymbolGeometry = geometry }; // set default time extent //set the ID and other parts of the message msg.Add(MilitaryMessage.TypePropertyName, Constants.MSG_TYPE_POSITION_REPORT); msg.Add(MilitaryMessage.ActionPropertyName, Constants.MSG_ACTION_UPDATE); msg.Add(MilitaryMessage.WkidPropertyName, "3857"); msg.Add(MilitaryMessage.SicCodePropertyName, symbol.SymbolID); msg.Add(MilitaryMessage.UniqueDesignationPropertyName, "1"); // Construct the Control Points based on the geometry type of the drawn geometry. switch (geometry.GeometryType) { case GeometryType.Point: MapPoint point = geometry as MapPoint; if (point != null) { msg.Add(MilitaryMessage.ControlPointsPropertyName, string.Format("{0},{1}", point.X.ToString(), point.Y.ToString())); } break; case GeometryType.Polygon: Polygon polygon = geometry as Polygon; string cpts = polygon.Parts.SelectMany(pt => pt.GetPoints()).Aggregate(string.Empty, (current, segpt) => current + (";" + segpt.X.ToString() + "," + segpt.Y.ToString())); //foreach (var pt in polygon.Rings[0]) msg.Add(MilitaryMessage.ControlPointsPropertyName, cpts); break; case GeometryType.Polyline: Polyline polyline = geometry as Polyline; cpts = string.Empty; // TODO find a way to determine if polyline map points need adjustment based on symbol being drawn var mpList = AdjustMapPoints(polyline, symbol); cpts = mpList.Aggregate(cpts, (current, mp) => current + (";" + mp.X.ToString() + "," + mp.Y.ToString())); msg.Add(MilitaryMessage.ControlPointsPropertyName, cpts); break; } //Process the message if (ProcessMessage(_militaryMessageLayer, msg)) { RecordMessageBeingAdded(msg); DoCloneMission(null); } else { MessageBox.Show("Failed to process message."); } }