private async Task <StyleItemType> GetSelectedTypeFromGraphicsLayerAsync(GraphicsLayer graphicsLayers)
        {
            StyleItemType styleItemType = StyleItemType.PointSymbol; //default
                                                                     //Get all selected graphics
            List <Element> selectedElements = graphicsLayers.GetSelectedElements().ToList();

            if (selectedElements.Count == 0)
            {
                return(styleItemType);
            }
            //Convert "Element" list to "GraphicElement" list.
            var selectedGraphicElements = selectedElements.ConvertAll(x => (GraphicElement)x);
            //Get the type of the first graphic to compare against
            var firstGraphicElement = selectedElements.FirstOrDefault() as GraphicElement;
            await QueuedTask.Run(() =>
            {
                var firstGraphicElementType = firstGraphicElement.GetGraphic().GetType();
                //iterate to check if elements match
                var differentGraphicTypes = selectedGraphicElements.FirstOrDefault(se => se.GetGraphic().GetType() != firstGraphicElementType);
                if (differentGraphicTypes == null)
                //Find out what that type is
                {
                    var graphicElement = selectedElements.FirstOrDefault() as GraphicElement;
                    if (graphicElement.GetGraphic() is CIMPointGraphic)
                    {
                        styleItemType = StyleItemType.PointSymbol;
                    }
                    if (graphicElement.GetGraphic() is CIMTextGraphic)
                    {
                        styleItemType = StyleItemType.TextSymbol;
                    }
                    if (graphicElement.GetGraphic() is CIMLineGraphic)
                    {
                        styleItemType = StyleItemType.LineSymbol;
                    }
                    if (graphicElement.GetGraphic() is CIMPolygonGraphic)
                    {
                        styleItemType = StyleItemType.PolygonSymbol;
                    }
                }
            });

            return(styleItemType);
        }
Example #2
0
        private async Task GetStyleItemForGraphicsLayerAsync(GraphicsLayer graphicsLayer)
        {
            //Get all selected graphics
            List <Element> selectedElements = graphicsLayer.GetSelectedElements().ToList();

            if (selectedElements.Count == 0)
            {
                return;
            }
            if (!_isAllGraphicsSameType)
            {
                return;
            }

            //All graphics selected are the same now.
            //Convert "Element" list to "GraphicElement" list.
            var selectedGraphicElements = selectedElements.ConvertAll(x => (GraphicElement)x);
            //Get the type of the first graphic to compare against
            await QueuedTask.Run(() => {
                var firstGraphicElement = selectedGraphicElements.FirstOrDefault().GetGraphic();
                if (firstGraphicElement is CIMPointGraphic)
                {
                    SelectedStyleItemType = StyleItemType.PointSymbol;
                }
                if (firstGraphicElement is CIMTextGraphic)
                {
                    SelectedStyleItemType = StyleItemType.TextSymbol;
                }
                if (firstGraphicElement is CIMLineGraphic)
                {
                    SelectedStyleItemType = StyleItemType.LineSymbol;
                }
                if (firstGraphicElement is CIMPolygonGraphic)
                {
                    SelectedStyleItemType = StyleItemType.PolygonSymbol;
                }
            });
        }