[OpenLayers-Users] Layer Query with Mapserver: How to do?
Arnd Wippermann
arnd.wippermann at web.de
Fri Nov 21 02:13:05 EST 2008
You have only to provide the url and layer for the request, the extent comes
from the click event.
I do something like this:
map.events.register('click', map, function (e)
{
//MapServer supports Query by Box!
var QueryByBox = false;
//##########################################################################
##
//set new imgsize and extent for query (it's like a zoom in)
//##########################################################################
##
var QImgSize = {w:100, h:100};
var tolx = 5;
var toly = 5;
var tolerance = new OpenLayers.Pixel(tolx, toly);
var min_px = new OpenLayers.Pixel(e.xy.x - tolerance.x, e.xy.y +
tolerance.y);
var max_px = new OpenLayers.Pixel(e.xy.x + tolerance.x, e.xy.y -
tolerance.y);
var min_ll = map.getLonLatFromPixel(min_px);
var max_ll = map.getLonLatFromPixel(max_px);
var BBOX = Array(min_ll.lon, min_ll.lat, max_ll.lon, max_ll.lat);
//##########################################################################
##
var theUrl = map.layers[map.aktLayer].url;
if(theUrl.search(/\?/)!=-1)
var theParams = "&mode=nquery"; //returns all matching results,
mode=query returns only 1 matching result
else
var theParams = "?mode=nquery";
theParams += "&qlayers=" +
map.layers[map.aktLayer].vendor.aktqlayers.replace(/,/,"+");
theParams += "&layers=" +
map.layers[map.aktLayer].vendor.aktqlayers.replace(/,/,"+");
theParams += "&map_projection=init=" + map.projection;
theParams += "&mapext=" + BBOX.join("+");
theParams += "&imgext=" + BBOX.join("+");
theParams += "&map_size=" + QImgSize.w + "+" + QImgSize.h;
theParams += "&imgxy=" + QImgSize.w + "+" + QImgSize.h;
if(QueryByBox==true)
theParams += "&imgbox=" + "0+0+" + QImgSize.w + "+" +
QImgSize.h;
else
{
theParams += "&img.x=" + QImgSize.w/2;
theParams += "&img.y=" + QImgSize.h/2;
}
window.open(theUrl + theParams);
});
Arnd Wippermann
More information about the Users
mailing list