-
Notifications
You must be signed in to change notification settings - Fork 310
Adding a layer to the Map
Felix Obermaier edited this page Jan 10, 2018
·
3 revisions
Creating a Form with a MapControl
In the step you will add a layer to the mapcontrol created in the first step of the tutorial.
- Add a reference to SharpMap.dll if it's not already added
- Open the code for the form by right-clicking the form and choose "View Code"
- Add the following code to the constructor of the form
(The data: states_ugl.shp is located in this zip file on the tutorial overview page)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
vlay.DataSource = new SharpMap.Data.Providers.ShapeFile("path_to_data\\states_ugl.shp", true);
mapBox1.Map.Layers.Add(vlay);
mapBox1.Map.ZoomToExtents();
mapBox1.Refresh();
}
}
- Run the application and you should now see the US states in the map
- Set the Active tool to Pan
mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
- Run the application again and you should now be able to pan and zoom (by scrolling the mouse-wheel) in the map