Queries
In
,
the use of multiple serverFrames to display both a map and a query
is illustrated.
A window is created with three HTML elements: an image, a scrollable span
and an empty span.
Again, we create two serverFrames within a window. The first just requests
a map, but the second asks for the attributes of the mapped items.
(mode=itemnquery). For this MapServer needs three further pieces of
information: the layer the information comes from (countries: qlayer=countries),
the attribute field to be returned (country names: qitem=NAME),
and the regular expression used to select items (all items: qstring=/.*/).
The results of the query are sent back via the template files specified
in the countries layer definition (see
).
There are three of them: header, template and footer. When returning a query,
MapServer first send the header file, and next for every item found a copy
of the template file. At the end it sends the footer file.
We use these three files to return the query results as an HTML table.
The header file,
,
just contains the <table> definition.
has the definition of one table row:
<tr>lt;td>[NAME]<td>[shpext]
For each row returned by MapServer this line is produced, and the
variables between square brackets are replaced by the values of that row.
Finally, in
the table is concluded with </table>
As soon as the query returns to the browser,
it is placed in the target serverFrame
s4. The onReturn function ("displayQuery()") then copies this table
to the visible SPAN element in the window, next to the IMG element
with the map. Very important: the query results can be processed further
after return. The table within the serverFrame can be accessed as
var tbl = s4.contentWindow.document.getElementsByTagName("table")[0]
and its rows as "tbl.rows". The number of rows is "tbl.rows.length", and the
value of the second cell in the third row (France) is "tbl.rows[3].cells[1]".
In the "onReturn()" function of s4 I iterated over the returned extents to
get the global extent of all countries combined.