简体   繁体   中英

performance at arcgis silverlight api

I am using GraphicsLayer for road symbology with SimpleLineSymbol . my code is same with below code:

    for (int i = 0; i < 200000; i++)
    {
        myGraphicsLayer.Graphics[i].Symbol = mySimpleLineSymbol;
    }

this code run fast but draw linesymbol on map is very slow.(Approximately 6 sec). please help me for increase symbology performance.

I collect all geometry into one polyline and create one graphic for that. then i create symbol and display. It takes one second for rendering and display on map .

        var myPolyline = new ESRI.ArcGIS.Client.Geometry.Polyline();

        for (int i = 0; i < 200000; i++)
        {
            myPolyline.Paths.Add(((ESRI.ArcGIS.Client.Geometry.Polyline)myGraphicsLayer.Graphics[i].Geometry).Paths[0]);
        }

        Graphic myGraph = new Graphic();

        myGraph.Geometry = myPolyline;

        ESRI.ArcGIS.Client.Symbols.SimpleLineSymbol sym = new ESRI.ArcGIS.Client.Symbols.SimpleLineSymbol();

        sym.Color = new SolidColorBrush(Colors.Red);

        sym.Width = 2;

        myGraph.Symbol = sym;

        myGraphicsLayer.Graphics.Add(myGraph);

That's a lot of lines. One idea would be to reduce the number of lines needing to be drawn. You could check the zoom level or scale of the map and use this in determining which lines to draw. For example, maybe at certain scales you only draw specific roads, such as major roads. You could do this by adding an if statement in the loop that checks for a particular attribute (assuming one exists):

if (myGraphicsLayer.Graphics[i].Attributes["Type"] == "major") { }

Since you have lots of features the performance is always going to be impacted though there are a few things to consider. First make sure that you have the latest versions of both Silverlight and the Esri API since there are often performance improvements in newer releases. Since you are rendering on the client then the specs of the host machine will affect the performance and if you can't take advantage of scale dependant rendering or feature clustering and you are just using a basic feature symbol then the only way to get better performance is to render the features on the server using ArcGIS Server and consuming them as a dynamic map service layer. This will mean that you won't be able to use maptips etc. though there are some workarounds for this such as showing popups on hover. You can also implement identify on click easily.

You can Divide task between Threads for parallel Working for better performance.

 new Thread(() =>
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    for (int j = 0; j < 50000; j++)
                    {

                        myGraphicsLayer.Graphics[j].Symbol = mySimpleLineSymbol;
                    }
                });

            }
).Start();


            new Thread(() =>
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    for (int k = 50000; k < 100000; k++)
                    {
                        myGraphicsLayer.Graphics[k].Symbol = mySimpleLineSymbol;
                    }
                });

            }
).Start();


            new Thread(() =>
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    for (int l = 100000; l < 150000; l++)
                    {
                        myGraphicsLayer.Graphics[l].Symbol = mySimpleLineSymbol;
                    }
                });

            }
).Start();


            new Thread(() =>
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    for (int m = 150000; m < 200000; m++)
                    {
                        myGraphicsLayer.Graphics[m].Symbol = mySimpleLineSymbol;
                    }
                });

            }
).Start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM