Clear Layer and Add Layer (Legend)

Topics: Algorithms, CompactFramework, Data Access, Español, General Topics, Italiano, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, Web Controls, WinForms Controls
Jun 30, 2011 at 4:32 AM
Edited Jun 30, 2011 at 5:04 AM

Hi every one!

I want Clear all layer then add a new layer (legend).

I used code following for Web:

 protected void Page_Load(object sender, EventArgs e) 

  {     

       myMap = InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));       

       myMap.Zoom *= 0.07;       

if (Page.IsPostBack)       

{
       myMap.Center = (SharpMap.Geometries.Point)ViewState["mapCenter"];           

       myMap.Zoom = (double)ViewState["mapZoom"];                           

 }   

    else       

{         

      // myMap.ZoomToExtents();           

      ViewState.Add("mapCenter", myMap.Center);           

       ViewState.Add("mapZoom", myMap.Zoom);           

        CreateMap();                   

}        

}

  private SharpMap.Map InitializeMap(Size size)   

{        Map map = new Map(size);        

         SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");       

         layCountries.DataSource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\VNM_adm2.shp"), true);                                      layCountries.Style.Fill = new SolidBrush(Color.White);       

         layCountries.Style.Outline = System.Drawing.Pens.Gray;       

         layCountries.Style.EnableOutline = true;        map.Layers.Add(layCountries);       

         SharpMap.Layers.VectorLayer layriver = new SharpMap.Layers.VectorLayer("River");       

         layriver.DataSource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\vietnam_water.shp"), true);       

         layriver.Style.Fill = new SolidBrush(Color.DeepSkyBlue);       

         layriver.Style.Outline = System.Drawing.Pens.DeepSkyBlue;       

         layriver.Style.EnableOutline = true;       

         map.Layers.Add(layriver);

}

private void RefreshMap()   

{
        System.Drawing.Image img = myMap.GetMap(); 

 }

protected void btnClearMap (object sender, EventArgs e)   

{

        map.layer.clear ();

        RefeshMap();

}

error:  System.Drawing.Image img = myMap.GetMap();  =>No layers to render

i can't clear all layer.

Coordinator
Jun 30, 2011 at 12:01 PM

you could add a VectorLayer with an underlying GeometryProvider datasource that is containing e.g. a linestring that is the diagonal of your maps envelope.

Apply a Pen with a transparent color and you will see nothing

Hth FObermaier