forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleMsSqlSpatial.aspx.cs
More file actions
73 lines (68 loc) · 2.55 KB
/
SimpleMsSqlSpatial.aspx.cs
File metadata and controls
73 lines (68 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.UI;
using SharpMap;
using SharpMap.Web;
using Point=GeoAPI.Geometries.Coordinate;
public partial class SimpleMsSqlSpatial : Page
{
private Map myMap;
protected void Page_Load(object sender, EventArgs e)
{
//Set up the map. We use the method in the App_Code folder for initializing the map
myMap = MapHelper.InitializeMapMsSqlSpatial(new Size((int) imgMap.Width.Value, (int) imgMap.Height.Value));
if (Page.IsPostBack)
{
//Page is post back. Restore center and zoom-values from viewstate
myMap.Center = (Point) ViewState["mapCenter"];
myMap.Zoom = (double) ViewState["mapZoom"];
}
else
{
//This is the initial view of the map. Zoom to the extents of the map:
//myMap.ZoomToExtents();
//or center on 0,0 and zoom to full earth (360 degrees)
//myMap.Center = new GeoAPI.Geometries.Coordinate(0,0);
//myMap.Zoom = 360;
//Create the map
GenerateMap();
}
}
protected void imgMap_Click(object sender, ImageClickEventArgs e)
{
//Set center of the map to where the client clicked
myMap.Center = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
//Set zoom value if any of the zoom tools were selected
if (rblMapTools.SelectedValue == "0") //Zoom in
myMap.Zoom = myMap.Zoom*0.5;
else if (rblMapTools.SelectedValue == "1") //Zoom out
myMap.Zoom = myMap.Zoom*2;
//Create the map
GenerateMap();
}
/// <summary>
/// Creates the map, inserts it into the cache and sets the ImageButton Url
/// </summary>
private void GenerateMap()
{
//Save the current mapcenter and zoom in the viewstate
ViewState.Add("mapCenter", myMap.Center);
ViewState.Add("mapZoom", myMap.Zoom);
//Render map
Image img;
try
{
img = myMap.GetMap();
}
catch (SqlException ex)
{
throw new Exception(
"An error related to Sql occured. Ensure you have configured the database server correctly and updated the web.config file. See the readme in the MsSqlSpatialDemoDb folder.",
ex);
}
string imgID = Caching.InsertIntoCache(1, img);
imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);
}
}