How do I create a map?

Initialize the map, add layers, setup style and render it:
SharpMap.Map myMap = new SharpMap.Map(new Size(400,300));
myMap.Size = new System.Drawing.Size(300,200); //Set output size

myMap.MinimumZoom = 100; //Minimum zoom allowed
myMap.BackgroundColor = Color.White; //Set background
myMap.Center = new SharpMap.Geometry.Point(725000, 6180000); //Set center of map

//Add PostGIS layer:
SharpMap.Layers.VectorLayer myLayer = new SharpMap.Layers.VectorLayer("My layer");
string ConnStr = "Server=127.0.0.1;Port=5432;UserId=postgres;Password=password;Database=myGisDb;";
myLayer.DataSource = new SharpMap.Data.Providers.PostGIS(ConnStr, "myTable", "the_geom", 32632);
myLayer.MaxVisible = 40000;
myMap.Layers.Add(myLayer);

//Render the map
////1st possibility: Set zoom level
//myMap.Zoom = 1200; //Set zoom level
//2nd. possibility: Zoom to extents
myMap.ZoomToExtents();
System.Drawing.Image imgMap = myMap.GetMap();
Note:
SharpMap.Data.Providers.Postgis is member of the SharpMap.Extensions project.

Last edited Mar 8, 2010 at 10:24 PM by FObermaier, version 6