Ajax control zoom in/zoom out

Topics: General Topics, SharpMap v0.9 / v1.x, Web Controls
Oct 11, 2011 at 8:38 PM


How to implement zoom in/zoom out in the ajax sharpmap control without using MapHandler. I read here "How do I use the HttpHandler for an ASP.NET application?" in "How To" that we can implement using session variables, but its not working for me. Please help me to implement the zoom in/zoom out functionality using session variables. This is my code, when i executing this zoom in/zoom out both  results nothing, the map remains with same size.

protected void Page_Load(object sender, EventArgs e)   


ajaxMap.Map = InitializeMapSQLKatmai(new System.Drawing.Size(900, 400));
        if (!Page.IsPostBack && !Page.IsCallback)
            //Set up the map. We use the method in the App_Code folder for initializing the map
            ajaxMap.Map.Center = new Point(0, 20);
            ajaxMap.FadeSpeed = 10;
            ajaxMap.ZoomSpeed = 10;           
            ajaxMap.Map.ZoomToExtents() ;
            //ajaxMap.Map.Zoom = 360;

            ajaxMap.Map.Center = (Point)ViewState["mapCenter"];
            ajaxMap.Map.Zoom = (Double)ViewState["mapZoom"];



private void CreateMap()
        ViewState.Add("mapZoom", ajaxMap.Map.Zoom);
        ViewState.Add("mapCenter", ajaxMap.Map.Center);

        System.Drawing.Image img = ajaxMap.Map.GetMap();
        string imgID = SharpMap.Web.Caching.InsertIntoCache(5, img);
        ajaxMap.ResponseFormat = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);





Oct 17, 2011 at 10:34 PM


If you dont want to use MapHandler you must set

ajaxMap.UseCache = true;
Oct 19, 2011 at 5:37 AM
Edited Oct 19, 2011 at 5:52 AM

Hi carjona,

Thanks for your reply. After I set the ajaxMap.UseCache = true,  not all the layers (country layer and label layers) are loading only the circle layer which I have added later is loading . Can you please verify what I have done wrong in my above code. I know that I need to do something with the 'viewstate' but not sure what to do.

Also can you please tell me how to draw route from one poin to another, do you have any samples please share that one also.

Thanks for your kind help.



Oct 21, 2011 at 3:20 PM

I think your code is fine. Maybe the problem is on your InitializeMap function.

Check if ALL of your layers are in the same projection and set SRID accordingly.

Also, to draw routes please see this measure tool http://sharpmap.codeplex.com/discussions/242607 as a source of inspiration


Oct 23, 2011 at 7:42 PM

Hi carjona,

Thanks a lot, great... Now zoom-in, zoom-out both works fine for me. Now I am working routes.

great thanks again,