This project has moved and is read-only. For the latest updates, please go here.

In Few cases SharpMap is not displayed. Why it happens so?

Topics: General Topics
Nov 28, 2006 at 4:47 AM
I am able to display the map sucessfully but
with same code some time the map is displayed and some time the Sharpmap is not displayed.
Can anyone say why it so?

the code that I have used is below:

if (Page.IsPostBack)
// Page is post back. Restore center and zoom-values from viewstate
// Filldll1();

map1 = mapFun(new System.Drawing.Size((int)ImageButton1.Width.Value, (int)ImageButton1.Height.Value), txtmap.Text);
map1.Center = (SharpMap.Geometries.Point)ViewState"mapCenter";
map1.Zoom = (double)ViewState"mapZoom";
map1 = mapFun(new System.Drawing.Size((int)ImageButton1.Width.Value, (int)ImageButton1.Height.Value), "theme1");
ViewState.Add("mapCenter", map1.Center);
ViewState.Add("mapZoom", map1.Zoom);
//Create the map
catch (Exception ex)

private SharpMap.Map mapFun(System.Drawing.Size outsize, string str3)

SharpMap.Map map = new SharpMap.Map(outsize);
SharpMap.Layers.VectorLayer lay = new SharpMap.Layers.VectorLayer(" ");
lay.DataSource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\" + str3 + "." + "shp"));
lay.Style.Outline = System.Drawing.Pens.Black;
lay.Style.EnableOutline = true;
lay.SRID = 4326;
return map;

private void CreateMap()
System.Drawing.Image img = map1.GetMap();
string imgID = SharpMap.Web.Caching.InsertIntoCache(1, img);
ImageButton1.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);


plz reply as soon as possible.
Thanks in advance.
Nov 28, 2006 at 6:00 AM
See the note in the WIKI:
Nov 29, 2006 at 10:43 AM
Thanks for the reply,

Here, it is taking only 2 arguments but not 4 arguments i,e
string imgID = SharpMap.Web.Caching.InsertIntoCache(5, myMap.GetMap(), Session.SessionID, Context);
imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);

It is showing error as:

No overload for method 'InsertIntoCache' takes '4' arguments

And I want to place the map in the cache for ever then for how many minutes I have to declared.

Thanks in advance.

Nov 30, 2006 at 6:31 AM
You can't put something in the cache forever. First of all you will run out of memory, and secondly the cache is automatically flushed once-in-a-while.
If you want a true cache, you should save it to disk and redirect the user to that.