[OpenLayers-Users] Defining WFS-filter dynamically
Kai Behncke
Kai-Behncke at gmx.de
Thu Aug 13 13:25:28 EDT 2009
Dear users,
>
> I try to set a WFS-filter dynamically.
I found a solution now.
If I get e.g a list of comma-separated objekt_ids (4,20,56,.....) that shall be filtered in the wfs
I do:
suchobjekte = new String(suchobjekte);
y=suchobjekte.split(",");
var filter_body;
var filter_header = '<'+'?xml version="1.0" encoding="ISO-8859-1"?><wfs:GetFeature xmlns:ogc="http://www.opengis.net/ogc"xmlns:gml="http://www.opengis.net/gml"xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0"maxFeatures="5" outputFormat="GML2"><wfs:Query srsName="epsg:4326" typeName="gastronomie_ows">';
var filter_footer = '</wfs:Query></wfs:GetFeature>';
var filter_1_1 = new OpenLayers.Format.Filter({version: "1.1.0"});
var xml = new OpenLayers.Format.XML();
var wfs_url = "http://www.xyz.de/cgi-bin/mapserv?map=/............./ows.map";
if(y.length > 1) {
filter_body_1='<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:Or>';
filter_body_2="";
filter_body_3='</ogc:Or></ogc:Filter>';
for(var i=0;i< y.length;i++){
alert (y[i]);
filter_body_2= filter_body_2 +'<ogc:PropertyIsEqualTo matchCase="true"><ogc:PropertyName>objekt_id</ogc:PropertyName><ogc:Literal>'+y[i]+'</ogc:Literal></ogc:PropertyIsEqualTo>';
}
filter_body=filter_body_1 + filter_body_2 + filter_body_3;
} else {
var filter_body = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "objekt_id",
value: y[0]
});
filter_body = xml.write(filter_1_1.write(filter_body));
}
var final_filter = filter_header+filter_body+filter_footer;
req = new OpenLayers.Request.POST({
method: "POST",
url: wfs_url,
data: final_filter,
callback: do_what_i_want
});
....with that it works.
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
More information about the Users
mailing list