I want to be able to create a layer on init, then load features from a WFS protocol afterward. I'm having trouble doing this.
Using WFS protocol in vector constructor works fine and is not my problem: http://dev.openlayers.org/releases/OpenLayers-2.10/examples/wfs-filter.js
What i want to do is Add a layer like such:
var layer = new OpenLayers.Layer.Vector("Results", {
projection: new OpenLayers.Projection("EPSG:4326")
});
Then Query it using the WFS Protocol.... this is what i can't get to work... what i have so far is:
var protocol = new OpenLayers.Protocol.WFS({
version: "1.1.0",
url: MapBase.Configuration.GeoServer.WFS_Service.EndPointURL,
featurePrefix: MapBase.Configuration.GeoServer.WFS_Service.featurePrefix,
featureType: MapBase.Configuration.GeoServer.WFS_Service.featureType,
featureNS: MapBase.Configuration.GeoServer.WFS_Service.featureNS,
geometryName: MapBase.Configuration.GeoServer.WFS_Service.geometryName
});
var response = protocol.read({
maxFeatures: Search.Properties.maxResults,
callback: function (resp) {
console.log(resp);
layer.addFeatures(resp.features);
}
});
resp.features gets populated fine. My main problem is I can't find where to specify my filter and projection as i can in the Vector constructor. Even though i specified the projection in the vector constructor, when i addFeatures from my WFS response, they come back in a different projection because they end up really small spooning the west coast of Africa. Same thing with the filter. I don't see that WFS protocol alone supports applying a filter? It only seems to work in conjunction with a vector layer constructor.
This seems wrong though because the WFS protocol as described by the OGC support the filter and when openlayers submits it's WFS request via the vector constructor, it does indeed include it just fine. There should be a way to specify projection and filter in the WFS protocol alone?
EDIT #1:
What i have now:
var protocol = new OpenLayers.Protocol.WFS({
version: "1.1.0",
url: MapBase.Configuration.GeoServer.WFS_Service.EndPointURL,
featurePrefix: MapBase.Configuration.GeoServer.WFS_Service.featurePrefix,
featureType: MapBase.Configuration.GeoServer.WFS_Service.featureType,
featureNS: MapBase.Configuration.GeoServer.WFS_Service.featureNS,
geometryName: MapBase.Configuration.GeoServer.WFS_Service.geometryName,
srsName: "EPSG:4326"
// ,
// defaultFilter: myFilter
});
protocol.mergeWithDefaultFilter(Search.GetWFSSpatialFilters());