forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobal.asax.cs
More file actions
124 lines (103 loc) · 4.44 KB
/
Global.asax.cs
File metadata and controls
124 lines (103 loc) · 4.44 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using SharpMapServer.Model;
using SharpMap.Layers;
using System.IO;
using System.Reflection;
using System.Xml.Serialization;
using NetTopologySuite;
using ProjNet.CoordinateSystems;
using ProjNet.CoordinateSystems.Transformations;
namespace SharpMapServer
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
var gss = new NtsGeometryServices();
var css = new SharpMap.CoordinateSystems.CoordinateSystemServices(
new CoordinateSystemFactory(),
new CoordinateTransformationFactory(),
SharpMap.Converters.WellKnownText.SpatialReference.GetAllReferenceSystems());
GeoAPI.GeometryServiceProvider.Instance = gss;
SharpMap.Session.Instance
.SetGeometryServices(gss)
.SetCoordinateSystemServices(css)
.SetCoordinateSystemRepository(css);
string settingsfile = Server.MapPath("~/App_Data/settings.xml");
XmlSerializer serializer = new XmlSerializer(typeof(SharpMapContext));
if (!System.IO.File.Exists(settingsfile))
{
/*create default settings*/
SharpMapContext ctx = new SharpMapContext();
ctx.Capabilities = new WmsCapabilities()
{
Title = "SharpMap Demo Server",
Abstract = "This is an example SharpMap server",
Keywords = "SharpMap,WMS"
};
ctx.Users = new List<User>();
ctx.Users.Add(new User { UserName = "admin", Password = "sharpmap" });
/*add default layer*/
ctx.Layers = new List<SharpMapServer.Model.WmsLayer>();
ctx.Layers.Add(new SharpMapServer.Model.WmsLayer() { Name = "States", Description = "Demo data over US States", Provider = "Shapefile", DataSource = "states.shp" });
FileStream fs = File.Create(settingsfile);
serializer.Serialize(fs, ctx);
fs.Close();
}
FileStream settingsStream = File.OpenRead(settingsfile);
var settings = (SharpMapContext)serializer.Deserialize(settingsStream);
settingsStream.Close();
WMSServer.m_Capabilities = new SharpMap.Web.Wms.Capabilities.WmsServiceDescription
{
Abstract = settings.Capabilities.Abstract,
AccessConstraints = settings.Capabilities.AccessConstraints,
Fees = settings.Capabilities.Fees,
Keywords = settings.Capabilities.Keywords.Split(','),
LayerLimit = settings.Capabilities.LayerLimit,
MaxHeight = settings.Capabilities.MaxHeight,
MaxWidth = settings.Capabilities.MaxWidth,
OnlineResource = settings.Capabilities.OnlineResource,
Title = settings.Capabilities.Title
};
WMSServer.m_Map = new SharpMap.Map();
foreach (var l in settings.Layers)
{
switch (l.Provider)
{
case "Shapefile":
VectorLayer lay = new VectorLayer(l.Name);
string ds = l.DataSource;
if (!Path.IsPathRooted(ds))
ds = Server.MapPath(ds);
lay.DataSource = new SharpMap.Data.Providers.ShapeFile(ds);
lay.SRID = 4326;
WMSServer.m_Map.Layers.Add(lay);
break;
}
}
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
}
}