Search code examples
c#wpfvisual-studiosharpmap

SharpMap type conversion - WPF


I want to display a shapefile .shp in a SharpMap box, I wrote this code :

    public partial class Details : UserControl
    {
        public Details()
        {
            InitializeComponent();

            SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
            string path = @"D:\Studies\file.shp";
            SharpMap.Map myMap = new SharpMap.Map(new System.Drawing.Size(500, 250));
            vlay=new SharpMap.Data.Providers.ShapeFile(path);
            MapBox.Map.Layers.Add(vlay);
            MapBox.Map.ZoomToExtents();

        }
    }

it didn' run and it shows :

SharpMap.Data.Providers.ShapeFile can be converted to SharpMap.Layers.VectorLayer

What should I do ?


Solution

  • Assign vlay.DataSource, Like Clemens says:

     SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
     string path = @"D:\Studies\file.shp";
     vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(path);
     MapBox.Map.Layers.Add(vlay);
     MapBox.Map.ZoomToExtents();
     MapBox.Refresh();