예제 #1
0
        public Task <bool> DoesStyleItemExists(StyleItemType styleItemType, string key)
        {
            var styleItemExists = QueuedTask.Run(() =>
            {
                bool styleItem = false;
                //Search for a specific point symbol in style
                SymbolStyleItem item = (SymbolStyleItem)_styleProjectItem?.LookupItem(styleItemType, key);
                if (item == null)
                {
                    styleItem = false;
                }
                else
                {
                    styleItem = true;
                }
                return(styleItem);
            });

            return(styleItemExists);
        }
예제 #2
0
        private Task AddStyleItemToStyle(StyleProjectItem styleProjectItem, CIMPointSymbol cimPointSymbol)
        {
            return(QueuedTask.Run(() =>
            {
                if (styleProjectItem == null || cimPointSymbol == null)
                {
                    throw new System.ArgumentNullException();
                }
                SymbolStyleItem symbolStyleItem = new SymbolStyleItem() //define the symbol
                {
                    Symbol = cimPointSymbol,
                    ItemType = StyleItemType.PointSymbol,
                    Category = $"{SelectedFontFamily}",
                    Name = $"{SelectedCharacter.Character.ToString()}",
                    Key = $"{SelectedCharacter.Character.ToString()}_{SelectedFontFamily}_3",
                    Tags = $"{SelectedFontFamily};{SelectedCharacter.Character.ToString()};point"
                };

                styleProjectItem.AddItem(symbolStyleItem);
            }));
        }
예제 #3
0
        private Task AddStyleItemToStyle(StyleProjectItem styleProjectItem, CIMPolygonSymbol cimPolygonSymbol)
        {
            return(QueuedTask.Run(() =>
            {
                if (styleProjectItem == null || cimPolygonSymbol == null)
                {
                    throw new System.ArgumentNullException();
                }

                SymbolStyleItem symbolStyleItem = new SymbolStyleItem()//define the symbol
                {
                    Symbol = cimPolygonSymbol,
                    ItemType = StyleItemType.PolygonSymbol,
                    Category = "BuildingFacade",
                    Name = SelectedRulePackage.Name,
                    Key = SelectedRulePackage.Name,
                    Tags = $"BuildingStyle, {SelectedRulePackage.Title}"
                };

                styleProjectItem.AddItem(symbolStyleItem);
            }));
        }
        /// <summary>
        /// Apply the selected symbol to the selected feature layers in the TOC whose geometry type match the symbol type.
        /// </summary>
        private Task ApplySelectedSymbol()
        {
            if (_selectedSymbol == null || string.IsNullOrEmpty(_selectedSymbol.Key))
            {
                return(Task.FromResult(0));
            }

            return(QueuedTask.Run(() =>
            {
                //Get symbol from symbol style item.
                var symbol = _selectedSymbol.Symbol;

                var mapView = MapView.Active;
                if (mapView == null)
                {
                    return;
                }

                //Get the feature layer currently selected in the Contents pane
                var selectedLayers = mapView.GetSelectedLayers().OfType <FeatureLayer>().Where(l => IsMatchingShapeType(l, symbol));

                //Only one feature layer should be selected in the Contents pane
                if (selectedLayers.Count() == 0)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Select at least one feature layer in the TOC whose geometry type matches the symbol's geometry type.", "No Valid Layer Selected");
                    //Clear the current selection in gallery
                    _selectedSymbol = null;
                    NotifyPropertyChanged(() => SelectedSymbol);
                    return;
                }

                var symbolReference = SymbolFactory.MakeSymbolReference(symbol);
                foreach (var layer in selectedLayers)
                {
                    var renderer = layer.CreateRenderer(new SimpleRendererDefinition(symbolReference));
                    layer.SetRenderer(renderer);
                }
            }));
        }
        private ImageSource getSymbolPicture(CIMRenderer renderer)
        {
            ImageSource _symbolPicture = null;

            switch (renderer.GetType().Name)
            {
            case "CIMSimpleRenderer":
                var simpleRenderer = renderer as CIMSimpleRenderer;

                //CIMSymbol symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 1.0, SimpleMarkerStyle.Circle);
                //You can generate a swatch for a text symbols also.
                var si = new SymbolStyleItem()
                {
                    Symbol      = simpleRenderer.Symbol.Symbol,
                    PatchHeight = 32,
                    PatchWidth  = 32
                };
                _symbolPicture = si.PreviewImage;

                break;

            case "CIMUniqueValueRenderer":
                var uniqueValueRenderer = renderer as CIMUniqueValueRenderer;
                var si1 = new SymbolStyleItem()
                {
                    Symbol      = uniqueValueRenderer.DefaultSymbol.Symbol,
                    PatchHeight = 32,
                    PatchWidth  = 32
                };
                _symbolPicture = si1.PreviewImage;

                break;

            default:
                break;
            }
            return(_symbolPicture);
        }
        /// <summary>
        /// Creates a SymbolStyleItem from a symbol
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private Task <SymbolStyleItem> CreateSymbolStyleItem(CIMSymbol symbol, string data)
        {
            var symbolStyleItem = QueuedTask.Run(() =>
            {
                SymbolStyleItem sItem = null;
                try
                {
                    sItem = new SymbolStyleItem() //define the symbol
                    {
                        Symbol   = symbol,
                        ItemType = StyleItemType.TextSymbol,
                        Name     = data,
                        Key      = data,
                        Tags     = data,
                    };
                }
                catch (Exception)
                {
                }
                return(sItem);
            });

            return(symbolStyleItem);
        }
        //Create a CIMSymbol from style item selected in the results gallery list box and
        //apply this newly created symbol to the feature layer currently selected in Contents pane
        private async void ApplyTheSelectedSymbol(SymbolStyleItem selectedStyleItemToApply)
        {
            if (selectedStyleItemToApply == null || string.IsNullOrEmpty(selectedStyleItemToApply.Key))
            {
                return;
            }

            await QueuedTask.Run(() =>
            {
                //Get the feature layer currently selected in the Contents pane
                var selectedLayers = MapView.Active.GetSelectedLayers();

                //Only one feature layer should be selected in the Contents pane
                if (selectedLayers.Count != 1)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Select the feature layer to which you want to apply the selected symbol. Only one feature layer should be selected.");
                    //Clear the current selection in gallery
                    _selectedStyleItem = null;
                    NotifyPropertyChanged(() => SelectedStyleItem);
                    return;
                }

                FeatureLayer ftrLayer = selectedLayers[0] as FeatureLayer;

                //The selected layer should be a feature layer
                if (ftrLayer == null)
                {
                    return;
                }

                //Get symbol from symbol style item.
                CIMSymbol symbolFromStyleItem = selectedStyleItemToApply.Symbol;

                //Make sure there isn't a mismatch between the type of selected symbol in gallery and feature layer geometry type
                if ((symbolFromStyleItem is CIMPointSymbol && ftrLayer.ShapeType != esriGeometryType.esriGeometryPoint) ||
                    (symbolFromStyleItem is CIMLineSymbol && ftrLayer.ShapeType != esriGeometryType.esriGeometryPolyline) ||
                    (symbolFromStyleItem is CIMPolygonSymbol && ftrLayer.ShapeType != esriGeometryType.esriGeometryPolygon && ftrLayer.ShapeType != esriGeometryType.esriGeometryMultiPatch))
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("There is a mismatch between symbol type and feature layer geometry type.");
                    //Clear the current selection in gallery
                    _selectedStyleItem = null;
                    NotifyPropertyChanged(() => SelectedStyleItem);
                    return;
                }


                //Get simple renderer from feature layer
                CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer;

                if (currentRenderer == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Select a feature layer symbolized with a simple renderer.");
                    //Clear the current selection in gallery
                    _selectedStyleItem = null;
                    NotifyPropertyChanged(() => SelectedStyleItem);
                    return;
                }

                //Set real world setting for created symbol = feature layer's setting
                //so that there isn't a mismatch between symbol and feature layer
                SymbolFactory.SetRealWorldUnits(symbolFromStyleItem, ftrLayer.UsesRealWorldSymbolSizes);

                //Set current renderer's symbol reference = symbol reference of the newly created symbol
                currentRenderer.Symbol = SymbolFactory.MakeSymbolReference(symbolFromStyleItem);

                //Update feature layer renderer with new symbol
                ftrLayer.SetRenderer(currentRenderer);
            });
        }
예제 #8
0
        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
        }
예제 #9
0
        public async void Examples()
        {
            #region Get symbol from SymbolStyleItem
            SymbolStyleItem symbolItem = null;
            CIMSymbol       symbol     = await QueuedTask.Run <CIMSymbol>(() =>
            {
                return(symbolItem.Symbol);
            });

            #endregion

            #region Get color from ColorStyleItem
            ColorStyleItem colorItem = null;
            CIMColor       color     = await QueuedTask.Run <CIMColor>(() =>
            {
                return(colorItem.Color);
            });

            #endregion

            #region Get color ramp from ColorRampStyleItem
            ColorRampStyleItem colorRampItem = null;
            CIMColorRamp       colorRamp     = await QueuedTask.Run <CIMColorRamp>(() =>
            {
                return(colorRampItem.ColorRamp);
            });

            #endregion

            #region Get north arrow from NorthArrowStyleItem
            NorthArrowStyleItem northArrowItem = null;
            CIMNorthArrow       northArrow     = await QueuedTask.Run <CIMNorthArrow>(() =>
            {
                return(northArrowItem.NorthArrow);
            });

            #endregion

            #region Get scale bar from ScaleBarStyleItem
            ScaleBarStyleItem scaleBarItem = null;
            CIMScaleBar       scaleBar     = await QueuedTask.Run <CIMScaleBar>(() =>
            {
                return(scaleBarItem.ScaleBar);
            });

            #endregion

            #region Get label placement from LabelPlacementStyleItem
            LabelPlacementStyleItem     labelPlacementItem = null;
            CIMLabelPlacementProperties labelPlacement     = await QueuedTask.Run <CIMLabelPlacementProperties>(() =>
            {
                return(labelPlacementItem.LabelPlacement);
            });

            #endregion

            #region Get grid from GridStyleItem
            GridStyleItem gridItem = null;
            CIMMapGrid    grid     = await QueuedTask.Run <CIMMapGrid>(() =>
            {
                return(gridItem.Grid);
            });

            #endregion

            #region Get legend from LegendStyleItem
            LegendStyleItem legendItem = null;
            CIMLegend       legend     = await QueuedTask.Run <CIMLegend>(() =>
            {
                return(legendItem.Legend);
            });

            #endregion

            #region Get table frame from TableFrameStyleItem
            TableFrameStyleItem tableFrameItem = null;
            CIMTableFrame       tableFrame     = await QueuedTask.Run <CIMTableFrame>(() =>
            {
                return(tableFrameItem.TableFrame);
            });

            #endregion

            #region Get map surround from MapSurroundStyleItem
            MapSurroundStyleItem mapSurroundItem = null;
            CIMMapSurround       mapSurround     = await QueuedTask.Run <CIMMapSurround>(() =>
            {
                return(mapSurroundItem.MapSurround);
            });

            #endregion
        }
 private Task<ImageSource> GenerateBitmapImageAsync(Dictionary<string, object> attributes) {
     return QueuedTask.Run(() => {
         CIMSymbol symbol = ArcGIS.Desktop.Mapping.SymbolFactory.GetDictionarySymbol("mil2525d", attributes);
         
         //At 1.3, 64 is the max pixel size we can scale to. This will be enhanced at 1.4 to support
         //scaling (eg up to 256, the preferred review size for military symbols)
         var si = new SymbolStyleItem() {
             Symbol = symbol,
             PatchHeight = 64,
             PatchWidth = 64
         };
         return si.PreviewImage;
     });
 }
예제 #11
0
        internal async void UpdateCluster(bool isTolerance)
        {
            if (MapView.Active == null)
            {
                return;
            }
            // Get Layer Name
            string inputFC = SelectedLayer.Name;

            int  minPoints = 2;
            bool parsed    = Int32.TryParse(MinPoints, out minPoints);

            /// Set PYT path -This could be inserted as a resource file //
            string tool_path = "C:\\Dev_summit\\2018\\InteractiveAnalytics\\pyt\\UpdateCluster.pyt\\UpdateClusterTool";

            IReadOnlyList <string> args = null;

            if (isTolerance)
            {
                /// Arguments for executing process using Tolerance
                args = Geoprocessing.MakeValueArray(inputFC, minPoints, ValueSlider, -1);
            }
            else
            {
                /// Arguments for executing process using Threshold
                args = Geoprocessing.MakeValueArray(inputFC, minPoints, -1, ValueThreshold);
            }

            Task <IGPResult> task;

            /// Execute the Tool in the python toolbox
            task = Geoprocessing.ExecuteToolAsync(tool_path, args, flags: GPExecuteToolFlags.AddToHistory);


            StyleProjectItem style;
            CIMPointSymbol   pointSymbol = null;

            /// Get Pro Styles
            style = await QueuedTask.Run <StyleProjectItem>(() => Project.Current.GetItems <StyleProjectItem>().First(s => s.Name == "ArcGIS 2D"));


            await QueuedTask.Run(() =>
            {
                /// Search for a specific Symbol
                /// Other styles Arcgis/Resouces/Styles/Styles.stylx SQLite DB
                SymbolStyleItem symbolStyleItem = (SymbolStyleItem)style.LookupItem(StyleItemType.PointSymbol, "Circle 1_Shapes_3");
                pointSymbol = (CIMPointSymbol)symbolStyleItem.Symbol;

                /// Cluster Ids based in Color Schema
                int[] ids = new int[] { -1, 1, 2, 3, 4, 5, 6, 7, 8 };

                /// Set Colors
                string[] colors = new string[] { "156,156,156", "166,206,227", "31,120,180", "178,223,138",
                                                 "51,160,44", "251,154,153", "227,26,28", "253,191,111",
                                                 "255,127,0" };
                /// Color Field
                String[] fields = new string[] { "COLOR_ID" };

                /// Make a reference of the point symbol
                CIMSymbolReference symbolPointTemplate = pointSymbol.MakeSymbolReference();

                /// Get definition of type symbology unique values
                UniqueValueRendererDefinition uniqueValueRendererDef = new UniqueValueRendererDefinition(fields, symbolPointTemplate, null, symbolPointTemplate, false);

                /// Get Current renderer of the Selected Layer
                CIMUniqueValueRenderer renderer  = (CIMUniqueValueRenderer)SelectedLayer.CreateRenderer(uniqueValueRendererDef);
                CIMUniqueValueClass[] newClasses = new CIMUniqueValueClass[colors.Count()];

                /// Get Point Symbol as string for creating other point colors
                string point = pointSymbol.ToXml();

                /// Create Each Color
                for (int i = 0; i < ids.Length; i++)
                {
                    CIMPointSymbol npoint = CIMPointSymbol.FromXml(point);
                    if (ids[i] == -1)
                    {
                        npoint.SetSize(4);
                    }
                    else
                    {
                        npoint.SetSize(6);
                    }
                    CIMSymbolReference symbolPointTemplatei = npoint.MakeSymbolReference();
                    newClasses[i]                          = new CIMUniqueValueClass();
                    newClasses[i].Values                   = new CIMUniqueValue[1];
                    newClasses[i].Values[0]                = new CIMUniqueValue();
                    newClasses[i].Values[0].FieldValues    = new string[1];
                    newClasses[i].Values[0].FieldValues[0] = ids[i].ToString();
                    newClasses[i].Label                    = ids[i].ToString();
                    newClasses[i].Symbol                   = symbolPointTemplatei;
                    var color = colors[i].Split(',');
                    double r  = Convert.ToDouble(color[0]);
                    double g  = Convert.ToDouble(color[1]);
                    double b  = Convert.ToDouble(color[2]);
                    newClasses[i].Symbol.Symbol.SetColor(CIMColor.CreateRGBColor(r, g, b));
                }
                /// Add Colors into the renderer
                renderer.Groups[0].Classes = newClasses;

                /// Apply new renderer in the layer
                SelectedLayer.SetRenderer(renderer);

                //SelectedLayer.RecalculateRenderer();
            });
        }
        //Create a CIMSymbol from style item selected in the results gallery list box and
        //apply this newly created symbol to the feature layer currently selected in Contents pane
        private async void ApplyTheSelectedSymbol(SymbolStyleItem selectedStyleItemToApply)
        {
            if (selectedStyleItemToApply == null || string.IsNullOrEmpty(selectedStyleItemToApply.Key))
                return;

            await QueuedTask.Run(() =>
            {
                //Get the feature layer currently selected in the Contents pane
                var selectedLayers = MapView.Active.GetSelectedLayers();

                //Only one feature layer should be selected in the Contents pane
                if(selectedLayers.Count != 1)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Select the feature layer to which you want to apply the selected symbol. Only one feature layer should be selected.");
                    //Clear the current selection in gallery
                    _selectedStyleItem = null;
                    NotifyPropertyChanged(() => SelectedStyleItem);
                    return;
                }

                FeatureLayer ftrLayer = selectedLayers[0] as FeatureLayer;

                //The selected layer should be a feature layer
                if (ftrLayer == null)
                    return;

                //Get symbol from symbol style item. 
                CIMSymbol symbolFromStyleItem = selectedStyleItemToApply.Symbol;
                                
                //Make sure there isn't a mismatch between the type of selected symbol in gallery and feature layer geometry type
                if ((symbolFromStyleItem is CIMPointSymbol && ftrLayer.ShapeType != esriGeometryType.esriGeometryPoint) ||
                    (symbolFromStyleItem is CIMLineSymbol && ftrLayer.ShapeType != esriGeometryType.esriGeometryPolyline) ||
                    (symbolFromStyleItem is CIMPolygonSymbol && ftrLayer.ShapeType != esriGeometryType.esriGeometryPolygon && ftrLayer.ShapeType != esriGeometryType.esriGeometryMultiPatch))
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("There is a mismatch between symbol type and feature layer geometry type.");
                    //Clear the current selection in gallery
                    _selectedStyleItem = null;
                    NotifyPropertyChanged(() => SelectedStyleItem);
                    return;
                }
                   

                //Get simple renderer from feature layer
                CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer;

                if (currentRenderer == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Select a feature layer symbolized with a simple renderer.");
                    //Clear the current selection in gallery
                    _selectedStyleItem = null;
                    NotifyPropertyChanged(() => SelectedStyleItem);
                    return;
                }

                //Set real world setting for created symbol = feature layer's setting 
                //so that there isn't a mismatch between symbol and feature layer
                SymbolFactory.SetRealWorldUnits(symbolFromStyleItem, ftrLayer.UsesRealWorldSymbolSizes);
               
                //Set current renderer's symbol reference = symbol reference of the newly created symbol
                currentRenderer.Symbol = SymbolFactory.MakeSymbolReference(symbolFromStyleItem);

                //Update feature layer renderer with new symbol
                ftrLayer.SetRenderer(currentRenderer);
            });
        }