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 ?
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();