Select to view content in your preferred language

can you control grids in silverlight?

946
2
03-18-2011 10:04 AM
JimHenry
Emerging Contributor
Is there a grids feature that I can get access to either in xaml or c#?  I could do this with features but I would like to dynamically change the spacing without having to generate/swap features.

[ATTACH]5457[/ATTACH]
0 Kudos
2 Replies
JimHenry
Emerging Contributor
In case other are looking for an easy way to create a grid this link did help:
http://mappingcenter.esri.com/index.cfm?fa=ask.answers&q=223

But I would still like to create/modify a grid on the fly with a web app.
0 Kudos
JimHenry
Emerging Contributor
I was not thinking that the coordinate system that I was using would lay an evenly spaced grid but it does so I was able you use the following solution:

            List<ESRI.ArcGIS.Client.Geometry.Polyline> polylineList = new List<ESRI.ArcGIS.Client.Geometry.Polyline>();
            for (int lat = -90; lat <= 90; lat += 10)
            {
                ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection();

                pointCollection.Add(new MapPoint(-180, lat));
                pointCollection.Add(new MapPoint(180, lat));

                ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline();
                polyline.Paths.Add(pointCollection);

                polylineList.Add(polyline);
            }
            for (int lon = -180; lon <= 180; lon += 10)
            {
                ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection();

                pointCollection.Add(new MapPoint(lon, -90));
                pointCollection.Add(new MapPoint(lon, 90));

                ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline();
                polyline.Paths.Add(pointCollection);

                polylineList.Add(polyline);
            }

            GraphicsLayer graphicsLayer = Map.Layers["GridLines"] as GraphicsLayer;

            foreach (ESRI.ArcGIS.Client.Geometry.Polyline polyline in polylineList)
            {
                Graphic graphic = new Graphic()
                {
                    Symbol = LayoutRoot.Resources["DefaultLineSymbol"] as Symbol,
                    Geometry = polyline
                };

                graphicsLayer.Graphics.Add(graphic);
            }
0 Kudos