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:

http://localhost/Scripts/mapserv.exe?map=D:/Web/Heidi_Service/HGis/trentino.map&layer=DTM&layer=ECW&imgext=1600000.1
5000123.4 1620003.7 5010567.9&imgbox=143 200 200 255&imgxy=143
200&mode=browse

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
process.

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
method):

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

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

<?xml version="1.0" encoding="utf-8" ?>
<map>
 <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]"/>
 <legend>
     <![CDATA[
     [legend]
     ]]>
 </legend>
</map>

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.

Ciao
 Piero

2007/7/5, LITTLE Nelson <nelson.little at tenix.com>:
>
>  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 gmail.com]
> *Sent:* Wednesday, 4 July 2007 5:25 PM
> *To:* LITTLE Nelson
> *Cc:* MAPSERVER-USERS at lists.umn.edu
> *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 tenix.com>:
>
> 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:
> http://www.mapsherpa.com/gmap/gmap75.phtml).
>
>
>
> 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...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20070706/1b9e2a8a/attachment.html


More information about the mapserver-users mailing list