mapserver with ASP.NET
Piero Cavalieri
piero.cavalieri at HEIDI.IT
Mon Feb 6 07:29:45 PST 2006
web_template.xml:
<?xml version="1.0" encoding="utf-8" ?>
<map>
<img value="[img]"/>
<mapwidth value="[mapwidth]"/>
<mapheight value="[mapheight]"/>
<scalebar value="[scalebar]"/>
<referenceMap value="[ref]"/>
<imgxy value="[center]"/>
<imgext value="[mapext]"/>
<legend>
<![CDATA[
[legend]
]]>
</legend>
</map>
code behind of the main aspx page:
...
...
protected string baseUrl = "";
protected string queryString = "";
protected string mapwidth = "";
protected string mapheight = "";
protected string scalebar = "";
protected string img ;
...
...
...
private void Page_Load(object sender, System.EventArgs e)
{
//LAYERS
for (int i=0; i< layer.Items.Count; i++) {
if (layer.Items[i].Selected) {
layers += "&layer=" + layer.Items
[i].Value;
}
}
queryString += layers;
if(!IsPostBack) {
//FIRST VIEW
baseUrl = Request.QueryString["baseUrl"];
...
...
...
//Make the REQUEST to the cgi
if(mode == "browse") {
generateImgXml(queryString);
} else {
//QUERY MODE
...
...
...
...
private void generateImgXml (string parameters) {
// Create a 'WebRequest' with the specified url.
queryString = baseUrl + parameters;
if(debug) Response.Write("<br>" + queryString);
HttpWebRequest webRequest = (HttpWebRequest)
WebRequest.Create(queryString);
//webRequest.KeepAlive = false;
webRequest.Timeout=10000;
webRequest.Method = "GET";
// Send the WebRequest and read response
HttpWebResponse webResponse = (HttpWebResponse)
webRequest.GetResponse();
Stream sResponse = webResponse.GetResponseStream();
StreamReader reader = new StreamReader(sResponse);
//first line is additional info from MapServer
string header = reader.ReadLine();
if(header == "<HTML>") { //errore
string message = reader.ReadToEnd();
message += "\n\n\"" + header + message
+ "\"\n\n";
Response.Write(message);
return;
}
//actual parameters
XmlDocument xmldoc = new XmlDocument();
string doc = reader.ReadToEnd();
xmldoc.LoadXml(doc);
xmldoc.PreserveWhitespace = true;
XmlNode root = xmldoc.DocumentElement;
img = root.SelectSingleNode("img").Attributes
["value"].Value;
mapwidth = root.SelectSingleNode
("mapwidth").Attributes["value"].Value;
mapheight = root.SelectSingleNode
("mapheight").Attributes["value"].Value;
scalebar = root.SelectSingleNode
("scalebar").Attributes["value"].Value;
imgxy = root.SelectSingleNode("imgxy").Attributes
["value"].Value;
imgext = root.SelectSingleNode("imgext").Attributes
["value"].Value;
referenceMap = root.SelectSingleNode
("referenceMap").Attributes["value"].Value;
legend = root.SelectSingleNode("legend").InnerText;
sResponse.Close();
reader.Close();
webResponse.Close();
}
Main aspx page (with applet Rosa, but I tried also jbox, dbox, and nothing
at all):
...
...
<APPLET NAME="RosaApplet" ARCHIVE="rosa/rosa.jar" CODE="Rosa2000" WIDTH="<%
=mapwidth%>" HEIGHT="<%=mapheight%>" MAYSCRIPT>
<PARAM NAME="TB_POSITION" VALUE="top">
<PARAM NAME="TB_ALIGN" VALUE="left">
<PARAM NAME="IMG_URL" VALUE="<%=img%>">
<PARAM NAME="INP_FORM_NAME" VALUE="mapserv">
<PARAM NAME="TB_BUTTONS"
VALUE="zoomin|zoomout|recentre|fullView|pquery|nquery|print">
<PARAM NAME="INP_TYPE_NAME" VALUE="INPUT_TYPE">
<PARAM NAME="INP_COORD_NAME" VALUE="INPUT_COORD">
<%
if(mode == "browse") {
Response.Write("<PARAM NAME=\"TB_SELECTED_BUTTON\"
VALUE=\"zoomin\">");
}
if(mode == "query") {
Response.Write("<PARAM NAME=\"TB_SELECTED_BUTTON\"
VALUE=\"pquery\">");
}
if(mode == "nquery") {
Response.Write("<PARAM NAME=\"TB_SELECTED_BUTTON\"
VALUE=\"nquery\">");
}
%>
...
...
This is "old" form style. There is a page reload at every request. I
suggest you use Ajax ( http://ajaxpro.schwarz-interactive.de/) instead,
wich is also more easy. I'll replay you later, cause I don't have time now
(and I just began to do it in free time after work).
Piero
More information about the MapServer-users
mailing list