Select to view content in your preferred language

Set an existing line color

516
0
11-04-2021 12:15 AM
DavidMrázek
Frequent Contributor

Hello, I have a problem trying to create code in c #, I would like to find out when clicking on the button whether the layer (polyline) has joined the current map, whether it sets its color, whether it does not add and color it. The second part is not a problem when I have to set up a new line, but I do not know how to paint the existing one.

 

protected override async void OnClick()
        {
            await CreateMyLineAsync();
        }

        private static async Task CreateMyLineAsync()
        {
            await QueuedTask.Run(async () =>
            {

                SimpleRendererDefinition sDef = new SimpleRendererDefinition()
                {
                    SymbolTemplate = SymbolFactory.Instance
                        .ConstructLineSymbol(ColorFactory.Instance.GreenRGB, 2, SimpleLineStyle.Solid)
                        .MakeSymbolReference()

                };
                string pathFgdb = CoreModule.CurrentProject.DefaultGeodatabasePath;
                string fcLine = "Linie";
                object[] listOfParameters = { pathFgdb, fcLine, "POLYLINE", "", "DISABLED", "DISABLED", SpatialReferenceBuilder.CreateSpatialReference(5514) };
                await StartATask("management.CreateFeatureclass", listOfParameters);
                if (MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(l => l.Name == fcLine) == null)
                {
                    FeatureClass fc = ReturnFc(new Uri(pathFgdb), fcLine);
                    LayerFactory.Instance.CreateFeatureLayer(fc, MapView.Active.Map, layerName: fcLine, rendererDefinition: sDef);
                }
                else
                {
                     //SimpleLineSymbol lineSymbol = new SimpleLineSymbol(
                    //    SimpleLineSymbolStyle.Solid, Color.Black, 4);

                    //var blueSymbol = new SimpleLineSymbol() { Color = Colors.Black, Width = 4, Style = SimpleLineStyle.Solid };

                    //SimpleLineSymbol stateOutlineSymbol = new SimpleLineSymbol(
                    //    SimpleLineSymbolStyle.Solid, System.Drawing.Color.Black, 4);

                    //SimpleLineSymbol aSimpleLineSymbol = new SimpleLineSymbol();
                    //aSimpleLineSymbol.Color = new SolidColorBrush(Colors.Black);
                    //aSimpleLineSymbol.Style = SimpleLineSymbol.LineStyle.Solid;
                    //aSimpleLineSymbol.Width = 4;
                }

            });
        }

 

All options in else statment are broken and I don't know why.

I will be happy for any advice.

Thank you David

0 Replies