protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry) { //Add an overlay graphic to the map view _graphic = await this.AddOverlayAsync(geometry, _lineSymbol.MakeSymbolReference()); //define the text symbol var textSymbol = new CIMTextSymbol(); //define the text graphic var textGraphic = new CIMTextGraphic(); await QueuedTask.Run(() => { //Create a simple text symbol textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular"); //Sets the geometry of the text graphic textGraphic.Shape = geometry; //Sets the text string to use in the text graphic textGraphic.Text = "This is my line"; //Sets symbol to use to draw the text graphic textGraphic.Symbol = textSymbol.MakeSymbolReference(); //Draw the overlay text graphic _graphic = this.ActiveMapView.AddOverlay(textGraphic); }); return(true); }
protected override Task OnToolActivateAsync(bool active) { QueuedTask.Run(() => { _textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular"); }); return(base.OnToolActivateAsync(active)); }
protected override Task OnToolActivateAsync(bool active) { QueuedTask.Run(() => { _pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(CIMColor.CreateRGBColor(255, 255, 0, 40), 10, SimpleMarkerStyle.Circle); _textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 9.5, "Corbel", "Bold"); }); return(base.OnToolActivateAsync(active)); }
public void btnChangeRefscaleReset(object sender, EventArgs e) { QueuedTask.Run(() => { FeatureLayer a = MapView.Active.Map.Layers[1] as FeatureLayer; CIMTextSymbol s = a.LabelClasses[0].GetTextSymbol(); s.SetSize(14); a.LabelClasses[0].SetTextSymbol(s); }); }
public void btnChangeLayerFilter(object sender, EventArgs e) { var labelExpression = ((RadioButton)sender).Tag; QueuedTask.Run(() => { //Get the active map's definition - CIMMap. var cimMap = MapView.Active.Map.GetDefinition(); //Get the labeling engine from the map definition var cimGeneralPlacement = cimMap.GeneralPlacementProperties; if (cimGeneralPlacement is CIMMaplexGeneralPlacementProperties) { Debug.WriteLine("already using maplex"); } else { //Create a new Maplex label engine properties var cimMaplexGeneralPlacementProperties = new CIMMaplexGeneralPlacementProperties(); //Set the CIMMap's GeneralPlacementProperties to the new label engine cimMap.GeneralPlacementProperties = cimMaplexGeneralPlacementProperties; } FeatureLayer a = MapView.Active.Map.Layers[1] as FeatureLayer; if (labelExpression.ToString() == "None") { a.SetLabelVisibility(false); } else { //var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(s => s.ShapeType == esriGeometryType.esriGeometryPolyline); a.SetLabelVisibility(true); a.LabelClasses[0].SetExpression(labelExpression.ToString()); //$feature.RMNUMB + TextFormatting.NewLine + $feature.RMAREA CIMTextSymbol s = a.LabelClasses[0].GetTextSymbol(); s.SetSize(14); a.LabelClasses[0].SetTextSymbol(s); var lyrDefn = a.GetDefinition() as CIMFeatureLayer; //Get the label classes - we need the first one var listLabelClasses = lyrDefn.LabelClasses.ToList(); var theLabelClass = listLabelClasses.FirstOrDefault(); theLabelClass.MaplexLabelPlacementProperties.ThinDuplicateLabels = true; lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back a.SetDefinition(lyrDefn); //set the layer's definition } }); }
public static async Task <bool> DisplayTextBoxAsync(Layout layout, string elementName, double xPos, double yPos, CIMColor fontColor, double fontSize, string fontFamily, string fontStyle, string textBoxText) { await QueuedTask.Run(() => { //Build 2D point geometry Coordinate2D coord2D = new Coordinate2D(5, 5); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(fontColor, fontSize, fontFamily, fontStyle); sym.HorizontalAlignment = ArcGIS.Core.CIM.HorizontalAlignment.Left; GraphicElement ptTxtElm = LayoutElementFactory.Instance.CreatePointTextGraphicElement(layout, coord2D, textBoxText, sym); ptTxtElm.SetName(elementName); ptTxtElm.SetAnchor(Anchor.CenterPoint); ptTxtElm.SetX(xPos); ptTxtElm.SetY(yPos); }); return(true); }
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 (_textSymbol == 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 Text? if (selectedElements.Count() == 1) { if (selectedElements.FirstOrDefault().GetGraphic() is CIMTextGraphic) //It is a Text { //So we use it var textSymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMTextGraphic; _textSymbol = textSymbol.Symbol.Symbol as CIMTextSymbol; } } var textGraphic = new CIMTextGraphic { Symbol = _textSymbol.MakeSymbolReference(), Shape = geometry as MapPoint, Text = "Some Text" }; Module1.Current.SelectedGraphicsLayerTOC.AddElement(textGraphic); return true; })); }
/// <summary> /// Apply text symbol to a feature layer. /// </summary> private static Task ApplyLabelAsync(FeatureLayer featureLayer, CIMTextSymbol textSymbol) { return(QueuedTask.Run(() => { #region Apply text symbol to a feature layer //Note: call within QueuedTask.Run() //Get the layer's definition var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer; //Get the label classes - we need the first one var listLabelClasses = lyrDefn.LabelClasses.ToList(); var theLabelClass = listLabelClasses.FirstOrDefault(); //Set the label classes' symbol to the custom text symbol //Refer to the ProSnippets-TextSymbols wiki page for help with creating custom text symbols. //Example: var textSymbol = await CreateTextSymbolWithHaloAsync(); theLabelClass.TextSymbol.Symbol = textSymbol; lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back featureLayer.SetDefinition(lyrDefn); //set the layer's definition //set the label's visiblity featureLayer.SetLabelVisibility(true); #endregion })); }
/// <summary> /// Create a label for the weather feature layer. /// </summary> /// <param name="weatherLayer"></param> public static void SetLabeling(FeatureLayer weatherLayer) { // Get the CIMFeatureLayer definition. CIMFeatureLayer weatherLayerDefinition = weatherLayer.GetDefinition() as CIMFeatureLayer; // Get the label classes - we need the first one CIMLabelClass weatherLabelClass = weatherLayerDefinition.LabelClasses.FirstOrDefault(); if (weatherLabelClass != null) { // Create a new Arcade label expression. if (DamlSettings.Default.Celius) { weatherLabelClass.Expression = "$feature.Temperature + \" c \\r\" +$feature.Humidity + \" % \""; } else { weatherLabelClass.Expression = "(($feature.Temperature * 1.8) + 32)+ \" F \\r\" +$feature.Humidity + \" % \""; } // Create a polygon symbol for the halo CIMPolygonSymbol textHalo = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.WhiteRGB, SimpleFillStyle.Solid); // Create text symbol using the halo polygon CIMTextSymbol weatherTextSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 14, "Corbel", "Regular"); weatherTextSymbol.HaloSymbol = textHalo; weatherTextSymbol.HaloSize = 1; weatherTextSymbol.HaloSymbol.SetOutlineColor(ColorFactory.Instance.WhiteRGB); // Set the text symbol weatherLabelClass.TextSymbol.Symbol = weatherTextSymbol; // Update the layer definition weatherLayer.SetDefinition(weatherLayerDefinition); } }
public void btnChangeLayerFilter(object sender, EventArgs e) { var labelExpression = ((RadioButton)sender).Tag; QueuedTask.Run(() => { //Get the active map's definition - CIMMap. var cimMap = MapView.Active.Map.GetDefinition(); //Get the labeling engine from the map definition var cimGeneralPlacement = cimMap.GeneralPlacementProperties; if (cimGeneralPlacement is CIMMaplexGeneralPlacementProperties) { Debug.WriteLine("already using maplex"); } else { //Create a new Maplex label engine properties var cimMaplexGeneralPlacementProperties = new CIMMaplexGeneralPlacementProperties(); //Set the CIMMap's GeneralPlacementProperties to the new label engine cimMap.GeneralPlacementProperties = cimMaplexGeneralPlacementProperties; } FeatureLayer a = MapView.Active.Map.Layers[1] as FeatureLayer; if (labelExpression.ToString() == "None") { a.SetLabelVisibility(false); } else { a.SetLabelVisibility(true); a.LabelClasses[0].SetExpression(labelExpression.ToString()); //$feature.RMNUMB + TextFormatting.NewLine + $feature.RMAREA CIMTextSymbol s = a.LabelClasses[0].GetTextSymbol(); s.SetSize(14); a.LabelClasses[0].SetTextSymbol(s); } }); }
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; })); }
public void snippets_CreateLayoutElements() { LayoutView layoutView = LayoutView.Active; Layout layout = layoutView.Layout; #region Create point graphic with symbology //Create a simple 2D point graphic and apply an existing point style item as the symbology. //An alternative simple symbol is also provided below. This would completely elminate the 4 lines of code that reference a style. QueuedTask.Run(() => { //Build 2D point geometry Coordinate2D coord2D = new Coordinate2D(2.0, 10.0); //Reference a point symbol in a style StyleProjectItem ptStylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D"); SymbolStyleItem ptSymStyleItm = ptStylePrjItm.SearchSymbols(StyleItemType.PointSymbol, "City Hall")[0]; CIMPointSymbol pointSym = ptSymStyleItm.Symbol as CIMPointSymbol; pointSym.SetSize(50); //Set symbolology, create and add element to layout //CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 25.0, SimpleMarkerStyle.Star); //Alternative simple symbol GraphicElement ptElm = LayoutElementFactory.Instance.CreatePointGraphicElement(layout, coord2D, pointSym); ptElm.SetName("New Point"); }); #endregion #region Create line graphic with symbology //Create a simple 2D line graphic and apply an existing line style item as the symbology. //An alternative simple symbol is also provided below. This would completely elminate the 4 lines of code that reference a style. QueuedTask.Run(() => { //Build 2d line geometry List <Coordinate2D> plCoords = new List <Coordinate2D>(); plCoords.Add(new Coordinate2D(1, 8.5)); plCoords.Add(new Coordinate2D(1.66, 9)); plCoords.Add(new Coordinate2D(2.33, 8.1)); plCoords.Add(new Coordinate2D(3, 8.5)); Polyline linePl = PolylineBuilder.CreatePolyline(plCoords); //Reference a line symbol in a style StyleProjectItem lnStylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D"); SymbolStyleItem lnSymStyleItm = lnStylePrjItm.SearchSymbols(StyleItemType.LineSymbol, "Line with 2 Markers")[0]; CIMLineSymbol lineSym = lnSymStyleItm.Symbol as CIMLineSymbol; lineSym.SetSize(20); //Set symbolology, create and add element to layout //CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid); //Alternative simple symbol GraphicElement lineElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, linePl, lineSym); lineElm.SetName("New Line"); }); #endregion #region Create rectangle graphic with simple symbology //Create a simple 2D rectangle graphic and apply simple fill and outline symbols. QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D rec_ll = new Coordinate2D(1.0, 4.75); Coordinate2D rec_ur = new Coordinate2D(3.0, 5.75); Envelope rec_env = EnvelopeBuilder.CreateEnvelope(rec_ll, rec_ur); //Set symbolology, create and add element to layout CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 5.0, SimpleLineStyle.Solid); CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreenRGB, SimpleFillStyle.DiagonalCross, outline); GraphicElement recElm = LayoutElementFactory.Instance.CreateRectangleGraphicElement(layout, rec_env, polySym); recElm.SetName("New Rectangle"); }); #endregion #region Create text element with basic font properties //Create a simple point text element and assign basic symbology as well as basic text settings. QueuedTask.Run(() => { //Build 2D point geometry Coordinate2D coord2D = new Coordinate2D(3.5, 10); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.RedRGB, 32, "Arial", "Regular"); string textString = "Point text"; GraphicElement ptTxtElm = LayoutElementFactory.Instance.CreatePointTextGraphicElement(layout, coord2D, textString, sym); ptTxtElm.SetName("New Point Text"); //Change additional text properties ptTxtElm.SetAnchor(Anchor.CenterPoint); ptTxtElm.SetX(4.5); ptTxtElm.SetY(9.5); ptTxtElm.SetRotation(45); }); #endregion #region Create rectangle text with more advanced symbol settings //Create rectangle text with background and border symbology. Also notice how formatting tags are using within the text string. QueuedTask.Run(() => { //Build 2D polygon geometry List <Coordinate2D> plyCoords = new List <Coordinate2D>(); plyCoords.Add(new Coordinate2D(3.5, 7)); plyCoords.Add(new Coordinate2D(4.5, 7)); plyCoords.Add(new Coordinate2D(4.5, 6.7)); plyCoords.Add(new Coordinate2D(5.5, 6.7)); plyCoords.Add(new Coordinate2D(5.5, 6.1)); plyCoords.Add(new Coordinate2D(3.5, 6.1)); Polygon poly = PolygonBuilder.CreatePolygon(plyCoords); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular"); string text = "Some Text String that is really long and is <BOL>forced to wrap to other lines</BOL> so that we can see the effects." as String; GraphicElement polyTxtElm = LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(layout, poly, text, sym); polyTxtElm.SetName("New Polygon Text"); //(Optionally) Modify paragraph border CIMGraphic polyTxtGra = polyTxtElm.Graphic; CIMParagraphTextGraphic cimPolyTxtGra = polyTxtGra as CIMParagraphTextGraphic; cimPolyTxtGra.Frame.BorderSymbol = new CIMSymbolReference(); cimPolyTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid); polyTxtElm.SetGraphic(polyTxtGra); }); #endregion #region Create a new picture element with advanced symbol settings //Create a picture element and also set background and border symbology. QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D pic_ll = new Coordinate2D(6, 1); Coordinate2D pic_ur = new Coordinate2D(8, 2); Envelope env = EnvelopeBuilder.CreateEnvelope(pic_ll, pic_ur); //Create and add element to layout string picPath = @"C:\Temp\WhitePass.jpg"; GraphicElement picElm = LayoutElementFactory.Instance.CreatePictureGraphicElement(layout, env, picPath); picElm.SetName("New Picture"); //(Optionally) Modify the border and shadow CIMGraphic picGra = picElm.Graphic; CIMPictureGraphic cimPicGra = picGra as CIMPictureGraphic; cimPicGra.Frame.BorderSymbol = new CIMSymbolReference(); cimPicGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Solid); cimPicGra.Frame.ShadowSymbol = new CIMSymbolReference(); cimPicGra.Frame.ShadowSymbol.Symbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Solid); picElm.SetGraphic(picGra); }); #endregion #region Create a map frame and zoom to a bookmark //Create a map frame and also sets its extent by zooming the the extent of an existing bookmark. QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D mf_ll = new Coordinate2D(6.0, 8.5); Coordinate2D mf_ur = new Coordinate2D(8.0, 10.5); Envelope mf_env = EnvelopeBuilder.CreateEnvelope(mf_ll, mf_ur); //Reference map, create MF and add to layout MapProjectItem mapPrjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map")); Map mfMap = mapPrjItem.GetMap(); MapFrame mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, mf_env, mfMap); mfElm.SetName("New Map Frame"); //Zoom to bookmark Bookmark bookmark = mfElm.Map.GetBookmarks().FirstOrDefault(b => b.Name == "Great Lakes"); mfElm.SetCamera(bookmark); }); #endregion #region Create a legend for a specifc map frame //Create a legend for an associated map frame. QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D leg_ll = new Coordinate2D(6, 2.5); Coordinate2D leg_ur = new Coordinate2D(8, 4.5); Envelope leg_env = EnvelopeBuilder.CreateEnvelope(leg_ll, leg_ur); //Reference MF, create legend and add to layout MapFrame mapFrame = layout.FindElement("New Map Frame") as MapFrame; if (mapFrame == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING"); return; } Legend legendElm = LayoutElementFactory.Instance.CreateLegend(layout, leg_env, mapFrame); legendElm.SetName("New Legend"); }); #endregion #region Creating group elements //Create an empty group element at the root level of the contents pane //Note: call within QueuedTask.Run() GroupElement grp1 = LayoutElementFactory.Instance.CreateGroupElement(layout); grp1.SetName("Group"); //Create a group element inside another group element //Note: call within QueuedTask.Run() GroupElement grp2 = LayoutElementFactory.Instance.CreateGroupElement(grp1); grp2.SetName("Group in Group"); #endregion Creating group elements { #region Create scale bar Coordinate2D llScalebar = new Coordinate2D(6, 2.5); MapFrame mapframe = layout.FindElement("New Map Frame") as MapFrame; //Note: call within QueuedTask.Run() LayoutElementFactory.Instance.CreateScaleBar(layout, llScalebar, mapframe); #endregion } #region How to search for scale bars in a style var arcgis_2d = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D"); QueuedTask.Run(() => { var scaleBarItems = arcgis_2d.SearchScaleBars("Double Alternating Scale Bar"); }); #endregion #region How to add a scale bar from a style to a layout var arcgis_2dStyle = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D"); QueuedTask.Run(() => { //Imperial Double Alternating Scale Bar //Metric Double Alternating Scale Bar //or just use empty string to list them all... var scaleBarItem = arcgis_2d.SearchScaleBars("Double Alternating Scale Bar").FirstOrDefault(); Coordinate2D coord2D = new Coordinate2D(10.0, 7.0); MapFrame myMapFrame = layout.FindElement("Map Frame") as MapFrame; LayoutElementFactory.Instance.CreateScaleBar(layout, coord2D, myMapFrame, scaleBarItem); }); #endregion #region Create NorthArrow Coordinate2D llNorthArrow = new Coordinate2D(6, 2.5); MapFrame mf = layout.FindElement("New Map Frame") as MapFrame; //Note: call within QueuedTask.Run() var northArrow = LayoutElementFactory.Instance.CreateNorthArrow(layout, llNorthArrow, mf); #endregion #region How to search for North Arrows in a style var arcgis_2dStyles = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D"); QueuedTask.Run(() => { var scaleBarItems = arcgis_2dStyles.SearchNorthArrows("ArcGIS North 13"); }); #endregion #region How to add a North Arrow from a style to a layout var arcgis2dStyles = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D"); QueuedTask.Run(() => { var northArrowStyleItem = arcgis2dStyles.SearchNorthArrows("ArcGIS North 13").FirstOrDefault(); Coordinate2D nArrow = new Coordinate2D(6, 2.5); MapFrame newFrame = layout.FindElement("New Map Frame") as MapFrame; //Note: call within QueuedTask.Run() var newNorthArrow = LayoutElementFactory.Instance.CreateNorthArrow(layout, nArrow, newFrame, northArrowStyleItem); }); #endregion #region Create dynamic text var title = @"<dyn type = ""page"" property = ""name"" />"; Coordinate2D llTitle = new Coordinate2D(6, 2.5); //Note: call within QueuedTask.Run() var titleGraphics = LayoutElementFactory.Instance.CreatePointTextGraphicElement(layout, llTitle, null) as TextElement; titleGraphics.SetTextProperties(new TextProperties(title, "Arial", 24, "Bold")); #endregion #region Create dynamic table QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D tab_ll = new Coordinate2D(6, 2.5); Coordinate2D tab_ur = new Coordinate2D(12, 6.5); Envelope tab_env = EnvelopeBuilder.CreateEnvelope(tab_ll, tab_ur); MapFrame mapFrame = layout.FindElement("New Map Frame") as MapFrame; // get the layer MapProjectItem mapPrjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map")); Map theMap = mapPrjItem?.GetMap(); var lyrs = theMap?.FindLayers("Inspection Point Layer", true); if (lyrs?.Count > 0) { Layer lyr = lyrs[0]; var table1 = LayoutElementFactory.Instance.CreateTableFrame(layout, tab_env, mapFrame, lyr, new string[] { "No", "Type", "Description" }); } }); #endregion }
async public static void CreateElementSnippets() { //There are already many Create element snippets in the PRO snippets section. This section will only contain examples that are NOT in the Pro snippets section //Pro snippets region names includes: // Create point graphic with symbology // Create line graphic with symbology // Create rectangle graphic with simple symbology // Create text element with basic font properties // Create rectangle text with more advanced symbol settings // Create a new picture element with advanced symbol settings // Create a map frame and zoom to a bookmark // Create a legend for a specifc map frame // Creating group elements LayoutView lytView = LayoutView.Active; Layout layout = lytView.Layout; #region Create_BeizierCurve await QueuedTask.Run(() => { //Build geometry Coordinate2D pt1 = new Coordinate2D(1, 7.5); Coordinate2D pt2 = new Coordinate2D(1.66, 8); Coordinate2D pt3 = new Coordinate2D(2.33, 7.1); Coordinate2D pt4 = new Coordinate2D(3, 7.5); CubicBezierBuilder bez = new CubicBezierBuilder(pt1, pt2, pt3, pt4); CubicBezierSegment bezSeg = bez.ToSegment(); Polyline bezPl = PolylineBuilder.CreatePolyline(bezSeg); //Set symbology, create and add element to layout CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.RedRGB, 4.0, SimpleLineStyle.DashDot); GraphicElement bezElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, bezPl, lineSym); bezElm.SetName("New Bezier Curve"); }); #endregion Create_BeizierCurve #region Create_freehand await QueuedTask.Run(() => { //Build geometry List <Coordinate2D> plCoords = new List <Coordinate2D>(); plCoords.Add(new Coordinate2D(1.5, 10.5)); plCoords.Add(new Coordinate2D(1.25, 9.5)); plCoords.Add(new Coordinate2D(1, 10.5)); plCoords.Add(new Coordinate2D(0.75, 9.5)); plCoords.Add(new Coordinate2D(0.5, 10.5)); plCoords.Add(new Coordinate2D(0.5, 1)); plCoords.Add(new Coordinate2D(0.75, 2)); plCoords.Add(new Coordinate2D(1, 1)); Polyline linePl = PolylineBuilder.CreatePolyline(plCoords); //Set symbolology, create and add element to layout CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid); GraphicElement lineElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, linePl, lineSym); lineElm.SetName("New Freehand"); }); #endregion Create_freehand #region Create_polygon await QueuedTask.Run(() => { //Build geometry List <Coordinate2D> plyCoords = new List <Coordinate2D>(); plyCoords.Add(new Coordinate2D(1, 7)); plyCoords.Add(new Coordinate2D(2, 7)); plyCoords.Add(new Coordinate2D(2, 6.7)); plyCoords.Add(new Coordinate2D(3, 6.7)); plyCoords.Add(new Coordinate2D(3, 6.1)); plyCoords.Add(new Coordinate2D(1, 6.1)); Polygon poly = PolygonBuilder.CreatePolygon(plyCoords); //Set symbolology, create and add element to layout CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.DashDotDot); CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline); GraphicElement polyElm = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym); polyElm.SetName("New Polygon"); }); #endregion Create_polygon #region Create_circle await QueuedTask.Run(() => { //Build geometry Coordinate2D center = new Coordinate2D(2, 4); EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise); EllipticArcSegment cir = eabCir.ToSegment(); //Set symbolology, create and add element to layout CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Dash); CIMPolygonSymbol circleSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, outline); GraphicElement cirElm = LayoutElementFactory.Instance.CreateCircleGraphicElement(layout, cir, circleSym); cirElm.SetName("New Circle"); }); #endregion Create_circle #region Create_ellipse await QueuedTask.Run(() => { //Build geometry Coordinate2D center = new Coordinate2D(2, 2.75); EllipticArcBuilder eabElp = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise); EllipticArcSegment ellipse = eabElp.ToSegment(); //Set symbolology, create and add element to layout CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.GreenRGB, 2.0, SimpleLineStyle.Dot); CIMPolygonSymbol ellipseSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreyRGB, SimpleFillStyle.Vertical, outline); GraphicElement elpElm = LayoutElementFactory.Instance.CreateEllipseGraphicElement(layout, ellipse, ellipseSym); elpElm.SetName("New Ellipse"); }); #endregion Create_ellipse #region Create_lasso await QueuedTask.Run(() => { //Build geometry List <Coordinate2D> plyCoords = new List <Coordinate2D>(); plyCoords.Add(new Coordinate2D(1, 1)); plyCoords.Add(new Coordinate2D(1.25, 2)); plyCoords.Add(new Coordinate2D(1.5, 1.1)); plyCoords.Add(new Coordinate2D(1.75, 2)); plyCoords.Add(new Coordinate2D(2, 1.1)); plyCoords.Add(new Coordinate2D(2.25, 2)); plyCoords.Add(new Coordinate2D(2.5, 1.1)); plyCoords.Add(new Coordinate2D(2.75, 2)); plyCoords.Add(new Coordinate2D(3, 1)); Polygon poly = PolygonBuilder.CreatePolygon(plyCoords); //Set symbolology, create and add element to layout CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid); CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline); GraphicElement polyElm = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym); polyElm.SetName("New Lasso"); }); #endregion Create_lasso #region Create_CurveText await QueuedTask.Run(() => { //Build geometry Coordinate2D pt1 = new Coordinate2D(3.6, 7.5); Coordinate2D pt2 = new Coordinate2D(4.26, 8); Coordinate2D pt3 = new Coordinate2D(4.93, 7.1); Coordinate2D pt4 = new Coordinate2D(5.6, 7.5); CubicBezierBuilder bez = new CubicBezierBuilder(pt1, pt2, pt3, pt4); CubicBezierSegment bezSeg = bez.ToSegment(); Polyline bezPl = PolylineBuilder.CreatePolyline(bezSeg); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 24, "Comic Sans MS", "Regular"); GraphicElement bezTxtElm = LayoutElementFactory.Instance.CreateCurvedTextGraphicElement(layout, bezPl, "Curved Text", sym); bezTxtElm.SetName("New Splinned Text"); }); #endregion Create_CurveText #region Create_PolygonText await QueuedTask.Run(() => { //Build geometry List <Coordinate2D> plyCoords = new List <Coordinate2D>(); plyCoords.Add(new Coordinate2D(3.5, 7)); plyCoords.Add(new Coordinate2D(4.5, 7)); plyCoords.Add(new Coordinate2D(4.5, 6.7)); plyCoords.Add(new Coordinate2D(5.5, 6.7)); plyCoords.Add(new Coordinate2D(5.5, 6.1)); plyCoords.Add(new Coordinate2D(3.5, 6.1)); Polygon poly = PolygonBuilder.CreatePolygon(plyCoords); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular"); string text = "Some Text String that is really long and is <BOL>forced to wrap to other lines</BOL> so that we can see the effects." as String; GraphicElement polyTxtElm = LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(layout, poly, text, sym); polyTxtElm.SetName("New Polygon Text"); //(Optionally) Modify paragraph border CIMGraphic polyTxtGra = polyTxtElm.Graphic; CIMParagraphTextGraphic cimPolyTxtGra = polyTxtGra as CIMParagraphTextGraphic; cimPolyTxtGra.Frame.BorderSymbol = new CIMSymbolReference(); cimPolyTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid); polyTxtElm.SetGraphic(polyTxtGra); }); #endregion Create_PolygonText #region Create_CircleText await QueuedTask.Run(() => { //Build geometry Coordinate2D center = new Coordinate2D(4.5, 4); EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise); EllipticArcSegment cir = eabCir.ToSegment(); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreenRGB, 10, "Arial", "Regular"); string text = "Circle, circle, circle, circle, circle, circle, circle, circle, circle, circle, circle"; GraphicElement cirTxtElm = LayoutElementFactory.Instance.CreateCircleParagraphGraphicElement(layout, cir, text, sym); cirTxtElm.SetName("New Circle Text"); //(Optionally) Modify paragraph border CIMGraphic cirTxtGra = cirTxtElm.Graphic; CIMParagraphTextGraphic cimCirTxtGra = cirTxtGra as CIMParagraphTextGraphic; cimCirTxtGra.Frame.BorderSymbol = new CIMSymbolReference(); cimCirTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid); cirTxtElm.SetGraphic(cirTxtGra); }); #endregion Create_CircleText #region Create_EllipseText await QueuedTask.Run(() => { //Build geometry Coordinate2D center = new Coordinate2D(4.5, 2.75); EllipticArcBuilder eabElp = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise); EllipticArcSegment ellipse = eabElp.ToSegment(); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlueRGB, 10, "Arial", "Regular"); string text = "Ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse"; GraphicElement elpTxtElm = LayoutElementFactory.Instance.CreateEllipseParagraphGraphicElement(layout, ellipse, text, sym); elpTxtElm.SetName("New Ellipse Text"); //(Optionally) Modify paragraph border CIMGraphic elpTxtGra = elpTxtElm.Graphic; CIMParagraphTextGraphic cimElpTxtGra = elpTxtGra as CIMParagraphTextGraphic; cimElpTxtGra.Frame.BorderSymbol = new CIMSymbolReference(); cimElpTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid); elpTxtElm.SetGraphic(elpTxtGra); }); #endregion Create_EllipseText MapFrame mfElm = null; #region Create_MapFrame //This example creates a new map frame and changes the camera scale. await QueuedTask.Run(() => { //Build geometry Coordinate2D ll = new Coordinate2D(6.0, 8.5); Coordinate2D ur = new Coordinate2D(8.0, 10.5); Envelope env = EnvelopeBuilder.CreateEnvelope(ll, ur); //Reference map, create MF and add to layout MapProjectItem mapPrjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map")); Map mfMap = mapPrjItem.GetMap(); mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, env, mfMap); mfElm.SetName("New Map Frame"); //Set the camera Camera camera = mfElm.Camera; camera.Scale = 24000; mfElm.SetCamera(camera); }); #endregion Create_MapFrame #region Create_ScaleBar await QueuedTask.Run(() => { //Reference a North Arrow in a style StyleProjectItem stylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D"); ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars("Double Alternating Scale Bar 1")[0]; //Build geometry Coordinate2D center = new Coordinate2D(7, 8); //Reference MF, create north arrow and add to layout MapFrame mf = layout.FindElement("New Map Frame") as MapFrame; if (mf == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING"); return; } ScaleBar sbElm = LayoutElementFactory.Instance.CreateScaleBar(layout, center, mf, sbStyleItm); sbElm.SetName("New Scale Bar"); sbElm.SetWidth(2); sbElm.SetX(6); sbElm.SetY(7.5); }); #endregion Create_ScaleBar #region Create_NorthArrow await QueuedTask.Run(() => { //Reference a North Arrow in a style StyleProjectItem stylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D"); NorthArrowStyleItem naStyleItm = stylePrjItm.SearchNorthArrows("ArcGIS North 10")[0]; //Build geometry Coordinate2D center = new Coordinate2D(7, 5.5); //Reference MF, create north arrow and add to layout MapFrame mf = layout.FindElement("New Map Frame") as MapFrame; if (mf == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING"); return; } NorthArrow arrowElm = LayoutElementFactory.Instance.CreateNorthArrow(layout, center, mf, naStyleItm); arrowElm.SetName("New North Arrow"); arrowElm.SetHeight(1.75); arrowElm.SetX(7); arrowElm.SetY(6); }); #endregion Create_NorthArrow }
async protected override void OnClick() { //Check to see if the Game Board layout already exists LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Game Board")); if (layoutItem != null) { Layout lyt = await QueuedTask.Run(() => layoutItem.GetLayout()); //Next check to see if a layout view is already open that referencs the Game Board layout foreach (var pane in ProApp.Panes) { var lytPane = pane as ILayoutPane; if (lytPane == null) //if not a layout view, continue to the next pane { continue; } if (lytPane.LayoutView.Layout == lyt) //if there is a match, activate the view { (lytPane as Pane).Activate(); System.Windows.MessageBox.Show("Activating existing pane"); return; } } //If panes don't exist, then open a new pane await ProApp.Panes.CreateLayoutPaneAsync(lyt); System.Windows.MessageBox.Show("Opening already existing layout"); return; } //The layout does not exist so create a new one Layout layout = await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run <Layout>(() => { //*** CREATE A NEW LAYOUT *** //Set up a page CIMPage newPage = new CIMPage(); //required properties newPage.Width = 17; newPage.Height = 11; newPage.Units = LinearUnit.Inches; //optional rulers newPage.ShowRulers = true; newPage.SmallestRulerDivision = 0.5; layout = LayoutFactory.Instance.CreateLayout(newPage); layout.SetName("Game Board"); //*** INSERT MAP FRAME *** // create a new map with an ArcGIS Online basemap Map map = MapFactory.Instance.CreateMap("World Map", MapType.Map, MapViewingMode.Map, Basemap.NationalGeographic); //Build map frame geometry Coordinate2D ll = new Coordinate2D(4, 0.5); Coordinate2D ur = new Coordinate2D(13, 6.5); Envelope env = EnvelopeBuilder.CreateEnvelope(ll, ur); //Create map frame and add to layout MapFrame mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, env, map); mfElm.SetName("Main MF"); //Set the camera Camera camera = mfElm.Camera; camera.X = 3365; camera.Y = 5314468; camera.Scale = 175000000; mfElm.SetCamera(camera); //*** INSERT TEXT ELEMENTS *** //Title text Coordinate2D titleTxt_ll = new Coordinate2D(6.5, 10); CIMTextSymbol arial36bold = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlueRGB, 36, "Arial", "Bold"); GraphicElement titleTxtElm = LayoutElementFactory.Instance.CreatePointTextGraphicElement(layout, titleTxt_ll, "Feeling Puzzled?", arial36bold); titleTxtElm.SetName("Title"); //Instuctions text Coordinate2D recTxt_ll = new Coordinate2D(4.25, 6.5); Coordinate2D recTxt_ur = new Coordinate2D(13, 9.75); Envelope recEnv = EnvelopeBuilder.CreateEnvelope(recTxt_ll, recTxt_ur); CIMTextSymbol arial18 = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreyRGB, 20, "Arial", "Regular"); string text = "<bol>Instructions:</bol> " + "\n\n - Activate the map frame below and pan / zoom to desired extent" + "\n\n - Close map frame activation" + "\n\n - Click the 'Scramble Pieces' command" as String; GraphicElement recTxtElm = LayoutElementFactory.Instance.CreateRectangleParagraphGraphicElement(layout, recEnv, text, arial18); recTxtElm.SetName("Instructions"); //Service layer credits Coordinate2D slcTxt_ll = new Coordinate2D(0.5, 0.2); Coordinate2D slcTxt_ur = new Coordinate2D(16.5, 0.4); Envelope slcEnv = EnvelopeBuilder.CreateEnvelope(slcTxt_ll, slcTxt_ur); CIMTextSymbol arial8reg = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8, "Arial", "Regular"); String slcText = "<dyn type='layout' name='Game Board' property='serviceLayerCredits'/>"; GraphicElement slcTxtElm = LayoutElementFactory.Instance.CreateRectangleParagraphGraphicElement(layout, slcEnv, slcText, arial8reg); slcTxtElm.SetName("SLC"); //Status and results text (blank to start) Coordinate2D statusTxt_ll = new Coordinate2D(4.5, 7); CIMTextSymbol arial24bold = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 24, "Arial", "Bold"); GraphicElement statusTxtElm = LayoutElementFactory.Instance.CreatePointTextGraphicElement(layout, statusTxt_ll, "", arial24bold); statusTxtElm.SetName("Status"); return(layout); }); //*** OPEN LAYOUT VIEW (must be in the GUI thread) *** var layoutPane = await ProApp.Panes.CreateLayoutPaneAsync(layout); var sel = layoutPane.LayoutView.GetSelectedElements(); if (sel.Count > 0) { layoutPane.LayoutView.ClearElementSelection(); } }
protected override async Task <bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry) { try { if (_graphic != null) { _graphic.Dispose(); } //Polygon polygon; //await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => //{ // List<Coordinate2D> coordinates2 = new List<Coordinate2D>() //{ // //new Coordinate2D(-159.20168702818188, 21.876487211082708), // //new Coordinate2D(-159.42653907783114, 21.838951660451173), // //new Coordinate2D(-159.44077880308507, 21.94718691051718), // //new Coordinate2D(-159.21630329750306, 21.94718691051718), // //new Coordinate2D(-159.21413990271841, 21.9365008022738), // //new Coordinate2D(-159.21383956606297, 21.93655454291286), // //new Coordinate2D(-159.20168702818188, 21.876487211082708), // new Coordinate2D(-17773406.8675, 2478583.7239999995), // new Coordinate2D(-17773406.8675, 2578583.7239999995), // new Coordinate2D(-16773406.8675, 2578583.7239999995), // new Coordinate2D(-17773406.8675, 2478583.7239999995) //}; // CIMPolygonSymbol _polygonSymbol = null; // _polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Null, SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid)); // using (PolygonBuilder polygonBuilder = new PolygonBuilder(coordinates2, MapView.Active.Extent.SpatialReference)) // { // polygonBuilder.SpatialReference = MapView.Active.Extent.SpatialReference; // polygon = polygonBuilder.ToGeometry(); // geometry = polygonBuilder.ToGeometry(); // //Geometry geometry2 = GeometryEngine.Instance.ProjectEx(geometry, projTransFromSRs); // _graphic = MapView.Active.AddOverlayAsync(geometry, _polygonSymbol.MakeSymbolReference()); // } //}); //return true; //DockPane pane = FrameworkApplication.DockPaneManager.Find("test_docing_Panel_PlanetDocPane"); DockPane pane = FrameworkApplication.DockPaneManager.Find("test_docing_Panel_Demo"); //PlanetDocPaneViewModel planetDocPaneViewModel = (PlanetDocPaneViewModel)pane; //planetDocPaneViewModel.Users = "New collection" pane.Enabled = true; //Add an overlay graphic to the map view _graphic = await this.AddOverlayAsync(geometry, _lineSymbol.MakeSymbolReference()); //define the text symbol var textSymbol = new CIMTextSymbol(); //define the text graphic var textGraphic = new CIMTextGraphic(); //await QueuedTask.Run(() => //{ // //Create a simple text symbol // textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular"); // //Sets the geometry of the text graphic // textGraphic.Shape = geometry; // //Sets the text string to use in the text graphic // //textGraphic.Text = "This is my line"; // //Sets symbol to use to draw the text graphic // textGraphic.Symbol = textSymbol.MakeSymbolReference(); // //Draw the overlay text graphic // _graphic = this.ActiveMapView.AddOverlay(textGraphic); //}); string ejson = geometry.ToJson(); Polygon poly = (Polygon)geometry; IReadOnlyList <Coordinate2D> coordinates = poly.Copy2DCoordinatesToList(); ToGeoCoordinateParameter ddParam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); List <string> geocoords = new List <string>(); List <Tuple <double, double> > AllPts = new List <Tuple <double, double> >(); double x; double y; foreach (Coordinate2D item in coordinates) { MapPoint mapPoint = MapPointBuilder.CreateMapPoint(item, MapView.Active.Extent.SpatialReference); List <Tuple <string, string> > pts = new List <Tuple <string, string> >(); string dd1 = mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[0]; pts.Add(new Tuple <string, string>(mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[1], mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[0])); if (pts[0].Item1.Contains("W")) { x = double.Parse("-" + pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse("-" + pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length -1)))); } else if (pts[1].Item2.Contains("S")) { x = double.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse("-" + pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse("-" + pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)))); } else { x = double.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse(pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)))); } AllPts.Add(new Tuple <double, double>(x, y)); geocoords.Add(mapPoint.ToGeoCoordinateString(ddParam)); } double[,] sd = new double[AllPts.Count, 2]; for (int i = 0; i < AllPts.Count; i++) { sd[i, 0] = AllPts[i].Item1; //+ "," + AllPts[i].Item2; sd[i, 1] = AllPts[i].Item2; } List <double[, ]> ss = new List <double[, ]>(); ss.Add(sd); Config configPoints = new Config { type = "Polygon", coordinates = ss.ToArray() }; Config configGeom = new Config { type = "GeometryFilter", field_name = "geometry", config = configPoints }; //DateFilter Config dateconfigconfig2 = new Config { gte = "2019-05-19T16:51:19.926Z", lte = "2019-08-19T16:51:19.926Z" }; Config dateconfigconfig = new Config { type = "DateRangeFilter", field_name = "acquired", config = dateconfigconfig2 }; Config dateconfig = new Config { type = "OrFilter", config = new[] { dateconfigconfig } }; SearchFilter searchFilter = new SearchFilter(); List <string> typoes = new List <string>(); typoes.Add("PSScene4Band"); typoes.Add("SkySatCollect"); typoes.Add("REOrthoTile"); List <Config> mainconfigs = new List <Config>(); mainconfigs.Add(dateconfig); mainconfigs.Add(configGeom); searchFilter.item_types = typoes.ToArray(); Filter topfilter = new Filter(); topfilter.type = "AndFilter"; searchFilter.filter = topfilter; Config mainConfig = new Config(); searchFilter.filter.config = mainconfigs.ToArray(); //string json = JsonConvert.SerializeObject(searchFilter); string json = JsonConvert.SerializeObject(searchFilter, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); string asas = "{\"filter\":{\"type\":\"AndFilter\",\"config\":[{\"type\":\"GeometryFilter\",\"field_name\":\"geometry\",\"config\":{\"type\":\"Polygon\",\"coordinates\":[[[-159.44149017333984,21.877787931279187],[-159.44998741149902,21.87679231243837],[-159.45372104644778,21.872769941600623],[-159.45217609405518,21.866835742000745],[-159.44372177124023,21.864207091531895],[-159.43561077117923,21.86930503623256],[-159.44149017333984,21.877787931279187]]]}},{\"type\":\"OrFilter\",\"config\":[{\"type\":\"DateRangeFilter\",\"field_name\":\"acquired\",\"config\":{\"gte\":\"2019-05-22T16:36:32.254Z\",\"lte\":\"2019-08-22T16:36:32.254Z\"}}]}]},\"item_types\":[\"PSScene4Band\",\"REOrthoTile\",\"SkySatCollect\"]}"; //var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.somewhere.com/v2/cases"); HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; HttpClient client = new HttpClient(handler) { BaseAddress = new Uri("https://api.planet.com") }; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "data/v1/quick-search"); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.CacheControl = new CacheControlHeaderValue(); request.Headers.CacheControl.NoCache = true; request.Headers.Host = "api.planet.com"; request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); //request.Headers.Remove("Content-Type"); //request.Headers.Add("Content-Type", "application/json"); var content = new StringContent(json, Encoding.UTF8, "application/json"); request.Content = content; var byteArray = Encoding.ASCII.GetBytes("1fe575980e78467f9c28b552294ea410:hgvhgv"); client.DefaultRequestHeaders.Host = "api.planet.com"; //_client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); content.Headers.Remove("Content-Type"); content.Headers.Add("Content-Type", "application/json"); //client.DefaultRequestHeaders.AcceptEncoding.Add(StringWithQualityHeaderValue.Parse("gzip")); client.DefaultRequestHeaders.Add("Connection", "keep-alive"); client.DefaultRequestHeaders.Add("User-Agent", "ArcGISProC#"); //content.Headers.TryAddWithoutValidation("Authorization", "Basic " + Convert.ToBase64String(byteArray)); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "MWZlNTc1OTgwZTc4NDY3ZjljMjhiNTUyMjk0ZWE0MTA6");//Convert.ToBase64String(byteArray)); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); using (HttpResponseMessage httpResponse = client.SendAsync(request).Result) { using (HttpContent content2 = httpResponse.Content) { var json2 = content2.ReadAsStringAsync().Result; QuickSearchResult quickSearchResult = JsonConvert.DeserializeObject <QuickSearchResult>(json2); //Geometry geometry2 = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, JsonConvert.SerializeObject( quickSearchResult.features[5].geometry)); } } pane.Activate(); return(true); } catch (Exception exe) { if (_graphic != null) { _graphic.Dispose(); } return(false); } }
protected override async Task OnToolActivateAsync(bool active) { _calloutTextSymbol = await CreateBalloonCalloutAsync(); return; }