Architectural Question

Piero Cavalieri piero.cavalieri at GMAIL.COM
Fri Jul 6 13:19:31 EDT 2007

I developed in .NET/javascript, so u can't use code (and my boss doesn't let
me to give, also if it few lines of code...). However idea is that u could
collect relevant values from user interface (the web page) which u need to
build a new map (for example the list of layers, the current map extent
which is returned by mapserver itself in the [mapextent] template variable,
ecc...) and build a correct request for mapserver.
The list of layers and other key elements for the request, u take via
JavaScript with (for example):

var layersString = getLayers(); //this call a function which cicle on the
layers list and takes only those the user want.
imgext = document.getElementById("imgext").value;
imgbox = document.getElementById("imgbox").value; //setted by dbox/jbox
imgxy = document.getElementById("imgxy").value;   //setted by dbox/jbox

Than u build request for Mapserver, for example:

5000123.4 1620003.7 5010567.9&imgbox=143 200 200 255&imgxy=143

This request u need to pass mapserver cgi without doing a POST, otherwise u
have a page reload. For doing this, I have used an Ajax library which,
without doing a POST, let me to call a server side (.NET) function  from a
client side function (JavaScript).
So then I do (I'm still in JavaScript) a call like:

AjaxMethods.getMap(queryString, retrieveMapImage_callback);

This JavaScript function, "invoke" a server side function (with the same
signature, but without the retrieveMapImage_callback parameter). Details
about how the Javascript function invoke the server side function are
managed by the ajax library I used (and if u use other libraries, things
will be different), important thing is that there is no page reload in this

When the result of the server side  function, come back to JavaScript, the
retrieveMapImage_callback function is invoked. What I do in this function ?
It update map elements:

document.getElementById("mapwidth").value = res.value.mapwidth;
document.getElementById("mapheight").value = res.value.mapheight;
document.getElementById("imgxy").value = res.value.imgxy;
document.getElementById("imgext").value = res.value.imgext;
document.getElementById("legend").innerHTML = res.value.legend;
document.getElementById("scale").value = res.value.scale;
imgMap.src = res.value.mapImgUrl;
imgRef.src = res.value.referenceMap;
imgScalebar.src = res.value.scalebar;

But how can I have in server side, new values based on the request above ?
I  use an
System.Net.HttpWebRequest (this one is .NET, Java should have a similar

HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(queryString);

And what's the response? In the .map file I specified to use a particular
TEMPLATE "templates/web_template.xml" which is:

<?xml version="1.0" encoding="utf-8" ?>
 <host value="[host]"/>
 <img value="[img]"/>
 <mapwidth value="[mapwidth]"/>
 <mapheight value="[mapheight]"/>
 <scalebar value="[scalebar]"/>
 <referenceMap value="[ref]"/>
 <imgxy value="[center]"/>
 <imgext value="[mapext]"/>
 <scale value="[scale]"/>

Normally, when u use Mapserver in cgi mode, u have the html page which
contains those template parameters ( [] ). The html page do a POST,
mapserver substitute parameters in the page with new values and the page is
sent back to the client.
Here is different. The template is processed and remains on the server. You
parse the response of the HttpWebRequest, and create an object to send to
the client (the response to the Ajax call). Then the client update the page
as I explained above.
With Java, I think u colud use a library called DWR (Direct Web Remoting),
which is conceptually similar to the AjaxPro I used (both are free).
Note this is only a method I used, but u could do things in different ways
(u could study some php framework). Also I used MapServer in cgi mode. Maybe
u want to use Java Mapscript, so things will be different.


2007/7/5, LITTLE Nelson <nelson.little at>:
>  Thanks for your reply it was the only one I got. You mentioned a lot of
> new technologies so I am not sure what to use.
> Currently my web page is one big HTML form. I was thinking that maybe when
> the user clicks on 'Redraw Map' button then that button could call some
> JavaScript code which would update the Map Image – but how could JavaScript
> do that?
> Even if I used iFrame I still need some JavaScript to refresh the iFrame.
> Thanks,
> Nelson
>  ------------------------------
> *From:* Piero Cavalieri [mailto:piero.cavalieri at]
> *Sent:* Wednesday, 4 July 2007 5:25 PM
> *To:* LITTLE Nelson
> *Subject:* Re: [UMN_MAPSERVER-USERS] Architectural Question
> You could use iframe or ajax ways. I used AjaxPro with.NET and cgi
> Mapserver and I don't have a single page refresh (everything is updated in
> background: map, scalebar, legend, query results). If u use Java, I think u
> coluld try DWR (Direct Web Remoting). Seems to remember that JBox is more
> suitable to use with Ajax, but try some ways.
> Cheers
>  Piero
> 2007/7/4, LITTLE Nelson <nelson.little at>:
> Hello Mapserver users,
> I have developed a web based mapserver application using Java Mapscript &
> Servlets and it works well and looks great. I currently use the Rosa Applet
> as the map window display. My application is very similar in behaviour to
> the Mapserver Atlas application (AKA gmap) (online:
> Whenever the user hits 'Redraw Map' or clicks on a tool button, it causes
> the whole pages to be refreshed. My question is how could this be changed so
> that only the map window is refreshed, not the whole page? I know this is an
> architectural type question which is not really related to Mapserver, but if
> anyone would know the answer it would be the people on this list.
> Thanks,
> Nelson
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the mapserver-users mailing list