Query
From Ka-Map Wiki
Contents |
[edit] ka-Map! Query
- How the ka-Map! query system works. Use the settings below to activate the query features.
[edit] Mapfile Query Configuration for ka-Map!
- Mapfile Metadata Configuration - how to setup your mapfile metadata to use with ka-Map!
LAYER
CLASS
#template file goes where your yourmapfileconf.map file is
#template file enables the layer results to happen (if queryable is marked true)
TEMPLATE "template.html"
END
METADATA
#this must be enabled to use ka-Map! query - map_query.php
"queryable" "true"
END
END
NB! The map file layer must also be part of ka-MAP layer to be queryable; i.e., the GROUP attribute must be defined (see Layers)
[edit] Example Mapfile
- Using the configuration above
LAYER
NAME "Cities"
GROUP "County"
STATUS ON
DATA "cities/cities"
TYPE POLYGON
MAXSCALE 3000000.0
MINSCALE 500001.0
LABELITEM "NAME"
CLASSITEM "FULL_NAME"
CLASS
NAME "Cities"
EXPRESSION /^City/
COLOR 255 255 255
OUTLINECOLOR 255 7 255
SIZE 3
TEMPLATE "template_city.html"
LABEL
TYPE TRUETYPE
FONT "tahoma-bold"
SIZE 7
POSITION AUTO
BUFFER 5
COLOR 0 0 0
OUTLINECOLOR 245 245 231
ANTIALIAS TRUE
PARTIALS FALSE
END
END
METADATA
"wms_title" "Cities"
"queryable" "true"
END
END
[edit] Using MapServer's Templating System for Queries
From Steve Lime & Alessio Di Lorenzo:
It is easy to use MapServer's normal query templating system from ka-map. The idea is that ka-map manages the coordinates and you pass those along to the MapServer CGI application. The techinique can potentially be used with any web application that takes in coordinate data.
Information on MapServer queries and examples can be found at:
DNR Test Suite - simple queries
In general, queries are pretty straight forward. There are 2 steps:
1. author a template file
Although templates are typically HTML files you can return XML or whatever. For example, if you have a DBF file with 3 attributes ITEM1, ITEM2 and ITEM3 then a template might look like:
<html>
<head><title>Sample Template</title></head>
<body>
<li> item 1 is [ITEM1]
<li> and item 2 is [ITEM2]
<li> but item 3 is [ITEM3]
</body>
</html>
2. reference the template in the LAYER Typically that means adding the line below to the template file.
TEMPLATE 'template.html'
Now, to access do a query that calls an external MapServer URL from ka-map you have to define a query method that is called when the KAMAP_QUERY event fires. The base ka-map demo does this and references a function called myQuery.
myQuery becomes very simple then and just creates a MapServer CGI URL and redirects the output to a new window. For example, the application:
http://maps.dnr.state.mn.us/ka-map/compass.html
myQuery (in startUp.js) becomes:
function myQuery( eventID, queryType, coords ) {
var szLayers = ;
var layers = myKaMap.getCurrentMap().getQueryableLayers();
if(layers.length==0) {
alert("No queryable layers at this scale and extent");
return;
}
for (var i=0;i<layers.length;i++) {
if (i > 0) szLayers = szLayers + "&" + layers[i].name;
else szLayers = layers[i].name;
}
window.open("/cgi-bin/mapserv?map=/path/to/mapfile.map&layers=all&mode=query&mapxy=" + coords[0] + +" + coords[1]);
}
Potential issues:
- this doesn't support query hiliting, the Omniverdi query system helps in this regard
- this should work nicely with other query modes but hasn't been tested
- I tend not to use layers with ka-map so directing a query against a single layer should be as easy as setting qlayer in the MapServer url, but hasn't been tested
[edit] Ominiverdi's query system
not completely developed. Actually it needs PHP5 and its XML module.
In CVS use index_query.html
CVS dump for this query system: http://www.ominiverdi.org/ka-map/ka-map/htdocs/index_query.html
A new layer is created when a query is made and only selected features are hilite and printed. An XML file returns the table for the selected features, should work with any vector layer in map file.
Metadata settings, layer level:
fields "fieldname:alias,fieldname:alias,fieldname:alias,fieldname:alias"
you can choose witch field in which order and with wich alias the XML will report the query result, alias is optional
hyperlink "fieldname"
you can set the field with hyperlink in the table:
hyperlink "fieldname|url"
the system will build the link so url?fieldname=val
rgbColor "100,50,100"
set line color for hilite otherwise green is used.
these are metadata we have used in the example.
queryable "true" "SEARCHFIELD" "name" fields "fibs:Code,name:Name,total:Population" hyperlink "total|http://www.ominiverdi.org"
The XML file is transformed by xsl, writing personal xsl is an easy way to change query result appearance.

