471,119 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

source code for zoom window(c#.net)

i want creat an web application(c#.net),which contains an image and one radiobutton list with 3 radiobuttons(zoom in ,zoom out ,zoom window)
when user checked on zoom in
imge has to be zoom
inthe similar manner when zoom window is checked,it allow to create a rectangle window by using mouse pressed and released.and particular area of the map/image must be zoomed


or my source code writen bellow.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Configuration;
  5. using System.Collections;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12.  
  13. public partial class Simple : System.Web.UI.Page
  14. {
  15.     private SharpMap.Map myMap;
  16.  
  17.     protected void Page_Load(object sender, EventArgs e)
  18.     {
  19.         //Set up the map. We use the method in the App_Code folder for initializing the map
  20.         myMap = MapHelper.InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value,(int)imgMap.Height.Value));
  21.         if (Page.IsPostBack) 
  22.         {
  23.             //Page is post back. Restore center and zoom-values from viewstate
  24.             myMap.Center = (SharpMap.Geometries.Point)ViewState["mapCenter"];
  25.             myMap.Zoom = (double)ViewState["mapZoom"];
  26.         }
  27.         else
  28.         {
  29.             //This is the initial view of the map. Zoom to the extents of the map:
  30.             //myMap.ZoomToExtents();
  31.             //or center on 0,0 and zoom to full earth (360 degrees)
  32.             //myMap.Center = new SharpMap.Geometries.Point(0,0);
  33.             //myMap.Zoom = 360;
  34.             //Create the map
  35.             GenerateMap();
  36.         }
  37.     }
  38.  
  39.     protected void imgMap_Click(object sender, ImageClickEventArgs e)
  40.     {
  41.         //Set center of the map to where the client clicked
  42.         myMap.Center = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
  43.         //Set zoom value if any of the zoom tools were selected
  44.         if (rblMapTools.SelectedValue == "0") //Zoom in
  45.             myMap.Zoom = myMap.Zoom * 0.5;
  46.          if (rblMapTools.SelectedValue == "1") //Zoom out
  47.             myMap.Zoom = myMap.Zoom * 2;
  48.         else if (rblMapTools.SelectedValue == "3") // Zoom Extent
  49.             myMap.ZoomToExtents();
  50.  
  51.         //Create the map
  52.         GenerateMap();
  53.     }
  54.  
  55.     /// <summary>
  56.     /// Creates the map, inserts it into the cache and sets the ImageButton Url
  57.     /// </summary>
  58.     private void GenerateMap()
  59.     {
  60.         //Save the current mapcenter and zoom in the viewstate
  61.         ViewState.Add("mapCenter", myMap.Center);
  62.         ViewState.Add("mapZoom", myMap.Zoom);
  63.         //Render map
  64.         System.Drawing.Image img = myMap.GetMap();
  65.         string imgID = SharpMap.Web.Caching.InsertIntoCache(1, img);
  66.         imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);
  67.     }
  68.  
  69. }
  70.  replay
Jan 23 '08 #1
0 8081

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by jjmraz | last post: by
reply views Thread by Philipp via DotNetMonster.com | last post: by
reply views Thread by fwsmaster | last post: by
11 posts views Thread by volcano | last post: by
11 posts views Thread by susiedba | last post: by
4 posts views Thread by sloan | last post: by
3 posts views Thread by AshokG | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.