public void ChangeColor()
 {
     // Change color of elements in this layer
     var color = Color.FromRgb(Convert.ToByte(_view.clrR.Value), Convert.ToByte(_view.clrG.Value), Convert.ToByte(_view.clrB.Value));
     var settings = new ShapeLayerSettings();
     settings.LineColor = color;
     var fileInfo = new FileInfo(_fileName);
     var settingsFile = fileInfo.Directory + "/" + fileInfo.Name + ".xml";
     ShapeLayer.WriteSettings(settings, settingsFile);
     var brush = new SolidColorBrush(color);
     foreach (var grp in _layer.Graphics)
     {
         dynamic symbol = grp.Symbol;
         if (symbol != null)
         {
             if (symbol.ToString().ToLower().Contains("simplelinesymbol"))
             {
                 try
                 {
                     symbol.Color = brush;
                 }
                 catch (Exception)
                 {
                 }
             }
             if (symbol.ToString().ToLower().Contains("simplefillsymbol"))
             {
                 try
                 {
                     symbol.Fill = brush;
                 }
                 catch (Exception)
                 {
                 }
             }
             /*try
             {
                 symbol.Fill = brush;
             }
             catch (Exception)
             {
             }*/
         }
     }
 }
Esempio n. 2
0
 public static void WriteSettings(ShapeLayerSettings settings, string fileName)
 {
     var xmlSer = new XmlSerializer(settings.GetType());
     using (var sw = new StreamWriter(fileName))
     {
         xmlSer.Serialize(sw, settings);
     }
 }
Esempio n. 3
0
        private void DrawPolyline(IEnumerable<Point> points, GraphicsLayer gl, ShapeLayerSettings settings)
        {
            // Transform geometry in Polyline
            //Dispatcher.Invoke(new System.Action(delegate
            Execute.OnUIThread(() =>
            {
                var graphicsLayer = gl; // emMain.Layers["MyGraphicsLayer"] as GraphicsLayer;
                var poly = new Polyline {SpatialReference = spRef};
                var pointsE = new ESRI.ArcGIS.Client.Geometry.PointCollection();

                foreach (var point in points)
                {
                    pointsE.Add(new MapPoint(point.X, point.Y));
                }

                poly.Paths.Add(pointsE);
                //poly.SpatialReference = _spRef;

                var grpPoly = new Graphic
                {
                    Symbol = new SimpleLineSymbol
                    {Color = new SolidColorBrush(settings.LineColor), Width = 2},
                    Geometry = poly
                };

                if (graphicsLayer != null) graphicsLayer.Graphics.Add(grpPoly);
            });
        }
Esempio n. 4
0
 public static ShapeLayerSettings GetSettings(string fileName)
 {
     var settings = new ShapeLayerSettings();
     try
     {
         var xmlSer = new XmlSerializer(settings.GetType());
         using (var sr = new StreamReader(fileName))
         {
             settings = (ShapeLayerSettings)xmlSer.Deserialize(sr);
         }
     }
     catch (Exception)
     {
        
     }
     return settings;
 }
Esempio n. 5
0
 public void AddShapefile(string filePath, GroupLayer curGrLayer)
 {
     Execute.OnUIThread(() =>
     {
         var grLay = new ShapeGraphicsLayer(filePath);
         //var grLay = new GraphicsLayer();
         var fi = new FileInfo(filePath);
         var settingsXml = fi.Directory + "/" + fi.Name + ".xml";
         var settings = new ShapeLayerSettings();
         if (File.Exists(settingsXml))
         {
             settings = GetSettings(settingsXml);
         }
         grLay.ID = fi.Name;
         grLay.Visible = false;
         grLay.Initialize();
         curGrLayer.ChildLayers.Add(grLay);
         using (var shapeFile = new Shapefile.Shapefile(filePath))
         {
             foreach (var shape in shapeFile)
             {
                                        //string[] metadataNames = shape.GetMetadataNames();
                                        // if (metadataNames != null)
                                        // {
                                        //     Console.WriteLine("Metadata:");
                                        //     var str = string.Empty;
                                        //     foreach (string metadataName in metadataNames)
                                        //     {
                                        //         str += String.Format("{0}={1} ({2})", metadataName, shape.GetMetadata(metadataName), shape.DataRecord.GetDataTypeName(shape.DataRecord.GetOrdinal(metadataName))) + Environment.NewLine;
                                        //     }
                                        //     Console.WriteLine();
                                        // }
                 switch (shape.Type)
                 {
                     case ShapeType.Polygon:
                         var shapePolygon = shape as ShapePolygon;
                         if (shapePolygon != null)
                             foreach (var part in shapePolygon.Parts)
                             {
                                 //Console.WriteLine("Polygon part:");
                                 var wpfShape = new System.Windows.Shapes.Polygon();
                                 var points = new System.Windows.Media.PointCollection();
                                 foreach (var point in part)
                                 {
                                     //Console.WriteLine("{0}, {1}", point.X, point.Y);
                                     double lat, lon;
                                                    //lat = point.Y;
                                                    //lon = point.X;
                                     CoordinateUtils.Rd2LonLat(point.X, point.Y, out lon, out lat);
                                     wpfShape.Points.Add(new Point(lon, lat));
                                     points.Add(new Point(lon, lat));
                                 }
                                 shapeList.Add(wpfShape);
                                 DrawPolygon(points, grLay, settings);
                             }
                         break;
                     case ShapeType.PolyLine:
                         var shapePolyline = shape as ShapePolyLine;
                         if (shapePolyline != null)
                             foreach (var part in shapePolyline.Parts)
                             {
                                 //Console.WriteLine("Polygon part:");
                                 var wpfShape = new System.Windows.Shapes.Polygon();
                                 var points = new System.Windows.Media.PointCollection();
                                 foreach (var point in part)
                                 {
                                     //Console.WriteLine("{0}, {1}", point.X, point.Y);
                                     //CoordinateUtils.Rd2LonLat(point.X,point.Y,out lon, out lat);
                                     var lat = point.Y;
                                     var lon = point.X;
                                     wpfShape.Points.Add(new Point(lon, lat));
                                     points.Add(new Point(lon, lat));
                                 }
                                 shapeList.Add(wpfShape);
                                 DrawPolyline(points, grLay, settings);
                             }
                         break;
                 }
             }
         }
     });
 }