Reputation: 339
I am using WMS as overlay map. I want to filter the point shapefile which is in WMS. Currently using only WMS Code to display in whole. For that following is the code.
var jpl_wms = new OpenLayers.Layer.WMS("Administrative Layer",
"http://localhost:8080/geoserver/test/wms",
{layers: "maharashtra_administrative",transparent: true},{isBaseLayer:false});
map.addLayer(jpl_wms);
this is point file. I want to pass parameter to restrict the points to be display(i.e point<100). Please help me out if any one know.
Upvotes: 0
Views: 4878
Reputation: 3856
You can restrict points in WMS layer by attaching filter to it. First create filter based on some attribute in your shape file:
var filter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "id",
value: 5
});
That will create filter object. You'll need to parse it to XML string. Following code will do the job:
var parser = new OpenLayers.Format.Filter.v1_1_0();
var filterAsXml = parser.write(filter);
var xml = new OpenLayers.Format.XML();
var filterAsString = xml.write(filterAsXml);
Now that you have a string you can attach it to your WMS layer:
jpl_wms.params["FILTER"] = filterAsString;
If the layer is already drawn you'll have do call redraw()
method in order to apply filter:
jpl_wms.redraw();
Upvotes: 4