[Mapserver-users] MUM Presentation / MapClient

Jan Hartmann jhart at frw.uva.nl
Tue Sep 23 10:43:56 EDT 2003


I have never used HTML legends, but I see several ways of using them 
with MapClient.The first two are simple, the third one is more complex, 
and the fourth one is very flexible, but will require quite a bit of 
figuring.


1) In a simple windowed application, the main template file returned by 
MapServer is put inside the window. There is no essential difference 
between a windowed application and a normal MapServer application; in a 
regular application, all MapServer results will be put in a new page or 
a separate frame, while in a windowed application everything will be put 
within the window. This means that you can use the [legend] tag in the 
main template file just as usual.

2) You can request the legend only in a separate call to MapServer by 
setting MODE=LEGEND. In that case MapServer will return a raw image. If 
you use serverFrames, you can put this image wherever you want in the 
browser (see User Guide 4.2, and the serverframe2.html example). The 
code for this would be something like:

s1 = new serverFrame()
s1.setServerURL,"your_MapServer_CGI")
s1.setVar("map","your_mapfile")
s1.setVar("mode","legend")
s1.setTarget("some image in your page")
s1.submit()

On return, the legend image will be put in the specified browser image.

3) In normal mode (MODE=MAP), MapServer will return raw HTML code when 
the LEGEND TEMPLATE is set . This code will replace the [legend] tag in 
the main template file. If the main template file has only this [legend] 
tag, the returned page will be the complete HTML code for the HTML 
legend. Code to retrieve this would look like:

s1 = new serverFrame()
s2 = new serverFrame()
s1.setServerURL,"...")
s1.seVar("map","...")
s1.setTarget(s2)
s2.setExecOnReturn("funtion to process the returned HTML legend")
s1.submit()

On return, s2 will be filled with the HTML legend. This has to be copied 
to visible screen locations by an onReturn function. For this, you need 
to access the HTML code in s2 via the DOM interface, in other words to 
find out how the different elements are named. The complete 
serverFrame's HTML code can be reached as follows:

s2.contentWindow.document.body.innerHTML

You can copy this block to every element in the main HTML page. I use 
empty SPAN and DIV elements for this. If the main page looks like this:

<body>
...
<span id=legendSpan></span>
...
</body>

you can copy the legend from the serverFrame onto the page by:

var sp = document.getElementById("legendSpan")
var lg = s2.contentWindow.document.body
sp.innerHTML = lg.innerHTML

4) Alternatively, you can even access the individual elements of the 
returned legend HTML. I don't know exactly how this HTML is built up, 
but it looks as if the elements are ordered as tables. The first table 
can be accessed as:

var table1 = s2.contentWindow.document.getELementsByTagName("table")[0]

The individual elements of this table can be accessed from this table1 
variable. This gives great flexibility: you can put every single legend 
item wherever you want, but it will take some figuring how every element 
  is named.

mvg,

Jan


> Hi!
> I'm just testing the MapClient and I think it is great.
> My question:
> Is there a simple way to use HTML legends with MapClient.
> 
>  Mvh
> Lars-Göran Edholm    tel 026/24 14 36
> 1:e byggnadsinspektör
> Bygg- och miljökontoret
> 811 80 Sandviken
> lars-goran.edholm at sandviken.se
> 
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> 




More information about the mapserver-users mailing list