I'm new to OpenLayers and looking for some help. I would like to filter my shapefile with CQL and display the result. (that's actually working :-)
The Problem is that I don't know how to pan the map to the result. So here is my code. I would be overgrateful for your help!
suche = new OpenLayers.Layer.WMS(
"nkGIS:HauptAdressen - Tiled", "http://localhost:8080/geoserver/nkGIS/wms",
{
LAYERS: 'nkGIS:HauptAdressen',
STYLES: '',
transparent: "true",
format: 'image/png',
},
{
buffer: 0,
displayOutsideMaxExtent: true,
isBaseLayer: false,
yx : {'EPSG:900913' : false}
}
);
map.addLayers([suche]);
osm = new OpenLayers.Layer.OSM();
map.addLayers([poi]);
map.addLayers([osm]);
poi.setVisibility(false);
suche.setVisibility(false);
// support GetFeatureInfo
map.events.register('click', map, function (e) {
document.getElementById('nodelist').innerHTML = "Loading... please wait...";
var params = {
REQUEST: "GetFeatureInfo",
EXCEPTIONS: "application/vnd.ogc.se_xml",
BBOX: map.getExtent().toBBOX(),
SERVICE: "WMS",
INFO_FORMAT: 'text/html',
QUERY_LAYERS: map.layers[0].params.LAYERS,
FEATURE_COUNT: 50,
Layers: 'nkGIS:HauptAdressen',
WIDTH: map.size.w,
HEIGHT: map.size.h,
format: format,
styles: map.layers[0].params.STYLES,
srs: map.layers[0].params.SRS};
// handle the wms 1.3 vs wms 1.1 madness
if(map.layers[0].params.VERSION == "1.3.0") {
params.version = "1.3.0";
params.j = parseInt(e.xy.x);
params.i = parseInt(e.xy.y);
} else {
params.version = "1.1.1";
params.x = parseInt(e.xy.x);
params.y = parseInt(e.xy.y);
}
// merge filters
if(map.layers[0].params.CQL_FILTER != null) {
params.cql_filter = map.layers[0].params.CQL_FILTER;
}
OpenLayers.loadURL("http://localhost:8080/geoserver/nkGIS/wms", params, this, setHTML, setHTML);
OpenLayers.Event.stop(e);
});
}
function updateFilter(){
if(pureCoverage)
return;
var filterType = "cql";
var str = "SName LIKE'" + document.getElementById('str').value +"'" + "AND " + "HNR LIKE'" + document.getElementById('nr').value +"'";
// by default, reset all filters
var filterParams = {
str: null,
cql_filter: null,
featureId: null
};
if (OpenLayers.String.trim(str) != "") {
if (filterType == "cql")
filterParams["cql_filter"] = str;
}
// merge the new filter definitions
mergeNewParams(filterParams);
suche.setVisibility(true)
}
function resetFilter() {
if(pureCoverage)
return;
document.getElementById('str').value = "";
updateFilter();
}
function mergeNewParams(params){
suche.mergeNewParams(params);
}