public void RunApplyTextTool() { QueuedTask.Run(() => { // Take the currently selected text and update it as needed // get the first graphics layer in the map's collection of graphics layers var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList() .OfType <ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault(); if (graphicsLayer == null) { return; } var selectedGraphicLayers = MapView.Active.GetSelectedLayers().OfType <GraphicsLayer>(); if (selectedGraphicLayers.Count() == 0) { //nothing selected. So clear the selected graphic layer. SelectedGraphicsLayerTOC = null; MessageBox.Show("No graphic layer selected.", "Select layer"); return; } SelectedGraphicsLayerTOC = selectedGraphicLayers.FirstOrDefault(); var selectedElements = graphicsLayer.GetSelectedElements(). OfType <GraphicElement>().Where(elem => elem.GetGraphic() is CIMTextGraphic || elem.GetGraphic() is CIMParagraphTextGraphic); if (selectedElements.Count() == 0) { //nothing selected. So clear the selected graphic layer. MessageBox.Show("No Text or Paragraph Text workflow graphics selected.", "Select graphics"); return; } // Get the editbox or the dockpane textbox value string txtBoxString = null; string queryTxtBoxString = null; if (Module1.Current.blnDockpaneOpenStatus == false) { // Use values in the edit boxes txtBoxString = Module1.Current.TextValueEditBox.Text; queryTxtBoxString = Module1.Current.QueryValueEditBox.Text; if (txtBoxString == null || txtBoxString == "") { txtBoxString = " Default Text"; } else { txtBoxString = " " + txtBoxString; } if (queryTxtBoxString != null && queryTxtBoxString != "") { txtBoxString = txtBoxString + "\r\n " + queryTxtBoxString; } } if (Module1.Current.blnDockpaneOpenStatus == true) { _dockpane = FrameworkApplication.DockPaneManager.Find("GraphicTools_TextPane") as TextPaneViewModel; txtBoxString = _dockpane.TxtBoxDoc; queryTxtBoxString = _dockpane.QueryTxtBoxDoc; if (txtBoxString == null || txtBoxString == "") { txtBoxString = " Default Text"; } else { txtBoxString = " " + txtBoxString; } if (queryTxtBoxString != null && queryTxtBoxString != "") { txtBoxString = txtBoxString + "\r\n " + queryTxtBoxString; } } foreach (var elem in selectedElements) { // Get the CIMTextGraphic of the current text graphic and update it with contents of text box if (elem.GetGraphic() is CIMTextGraphic) { var newCIMGraphic = elem.GetGraphic() as CIMTextGraphic; newCIMGraphic.Text = txtBoxString; elem.SetGraphic(newCIMGraphic); } // Get the CIMParagraphTextGraphic of the current text graphic and update it with contents of text box if (elem.GetGraphic() is CIMParagraphTextGraphic) { var newCIMGraphic = elem.GetGraphic() as CIMParagraphTextGraphic; newCIMGraphic.Text = txtBoxString; elem.SetGraphic(newCIMGraphic); } } SelectedGraphicsLayerTOC.ClearSelection(); }); }
protected override void OnClick() { TextPaneViewModel.Show(); }
protected override Task <bool> OnSketchCompleteAsync(Geometry geometry) { if (Module1.Current.SelectedGraphicsLayerTOC == null) { MessageBox.Show("Select a graphics layer in the TOC", "No graphics layer selected", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation); return(Task.FromResult(true)); } if (_pointSymbol == null) { return(Task.FromResult(true)); } return(QueuedTask.Run(() => { var selectedElements = Module1.Current.SelectedGraphicsLayerTOC.GetSelectedElements(). OfType <GraphicElement>(); //If only one element is selected, is it of type Point? if (selectedElements.Count() == 1) { if (selectedElements.FirstOrDefault().GetGraphic() is CIMPointGraphic) //It is a Point { //So we use it var polySymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMPointGraphic; _pointSymbol = polySymbol.Symbol.Symbol as CIMPointSymbol; } } var cimGraphicElement = new CIMPointGraphic { Location = geometry as MapPoint, Symbol = _pointSymbol.MakeSymbolReference() }; Module1.Current.SelectedGraphicsLayerTOC.AddElement(cimGraphicElement); // Add a text label graphic next to the point graphic: if (selectedElements.Count() == 1) { if (selectedElements.FirstOrDefault().GetGraphic() is CIMTextGraphic) //It is a Text { var textSymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMTextGraphic; _textSymbol = textSymbol.Symbol.Symbol as CIMTextSymbol; } } // Get the ribbon or the dockpane text values string txtBoxString = null; string queryTxtBoxString = null; if (Module1.Current.blnDockpaneOpenStatus == false) { // Use value in the edit box txtBoxString = Module1.Current.TextValueEditBox.Text; queryTxtBoxString = Module1.Current.QueryValueEditBox.Text; if (txtBoxString == null || txtBoxString == "") { txtBoxString = " Default Text"; } else { txtBoxString = " " + txtBoxString; } if (queryTxtBoxString != null && queryTxtBoxString != "") { txtBoxString = txtBoxString + "\r\n " + queryTxtBoxString; } } if (Module1.Current.blnDockpaneOpenStatus == true) { _dockpane = FrameworkApplication.DockPaneManager.Find("GraphicTools_TextPane") as TextPaneViewModel; txtBoxString = _dockpane.TxtBoxDoc; queryTxtBoxString = _dockpane.QueryTxtBoxDoc; if (txtBoxString == null || txtBoxString == "") { txtBoxString = " Default Text"; } else { txtBoxString = " " + txtBoxString; } if (queryTxtBoxString != null && queryTxtBoxString != "") { txtBoxString = txtBoxString + "\r\n " + queryTxtBoxString; } } var textGraphic = new CIMTextGraphic { Symbol = _textSymbol.MakeSymbolReference(), Shape = geometry as MapPoint, Text = txtBoxString }; Module1.Current.SelectedGraphicsLayerTOC.AddElement(textGraphic); Module1.Current.SelectedGraphicsLayerTOC.ClearSelection(); return true; })); }
protected override Task <bool> OnSketchCompleteAsync(Geometry geometry) { QueuedTask.Run(() => { try { var layers = MapView.Active.Map.GetLayersAsFlattenedList(); var fL = layers.FirstOrDefault(l => l is FeatureLayer) as FeatureLayer; // if there is no featurelayer in the map then exit if (fL == null) { return; } var fLayer = MapView.Active.Map.FindLayers("Overall SVI - Tracts").FirstOrDefault() as BasicFeatureLayer; if (fLayer == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Tracts layer is not found.", "Error"); return; } RowCursor rowCursor = null; // define a spatial query filter var spatialQueryFilter = new SpatialQueryFilter { // passing the search geometry to the spatial filter FilterGeometry = geometry, // define the spatial relationship between search geometry and feature class SpatialRelationship = SpatialRelationship.Intersects }; // apply the spatial filter to the feature layer in question rowCursor = fLayer.Search(spatialQueryFilter); RowHandle rowHandle = null; var pctAge65 = string.Empty; if (rowCursor.MoveNext()) { var row = rowCursor.Current; rowHandle = new RowHandle(row); pctAge65 = Convert.ToString(row["EP_AGE65"]); } if (rowHandle != null) { // Get the editbox or the dockpane textbox value string txtBoxString = null; if (Module1.Current.blnDockpaneOpenStatus == false) { // Use value in the edit box txtBoxString = Module1.Current.QueryValueEditBox.Text; if (txtBoxString == null || txtBoxString == "") { Module1.Current.QueryValueEditBox.Text = "Age > 65: " + pctAge65 + "%"; } else { MessageBox.Show("Query value exists on Ribbon", "Query Text"); } } if (Module1.Current.blnDockpaneOpenStatus == true) { _dockpane = FrameworkApplication.DockPaneManager.Find("GraphicTools_TextPane") as TextPaneViewModel; txtBoxString = _dockpane.QueryTxtBoxDoc; if (txtBoxString == null || txtBoxString == "") { _dockpane.QueryTxtBoxDoc = "Age > 65: " + pctAge65 + "%"; } else { MessageBox.Show("Query value exists in Text pane", "Query Text"); } } } } catch (Exception exc) { // Catch any exception found and display in a message box ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Exception caught: " + exc.Message); return; } }); return(base.OnSketchCompleteAsync(geometry)); }