[OpenLayers-Users] Features Not Added to Vector Layer
Jerome A. Wendell
jawendell at digitalmapping.com
Tue Mar 19 12:56:34 PDT 2013
Phil,
Things appear to be working fine now. Below is the code that I ended up
with:
var filter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: 'myID',
value: args['myID']
});
var wfsProtocol = new OpenLayers.Protocol.WFS({
version: "1.1.0",
url:
"http://mydomain:8080/geoserver/mystore/wfs",
featureType: "mylayer", //name of the
geoserver layer
featureNS: "mystore", //name of the
geoserver store
geometryName: "the_geom",
srsName: "EPSG:4326",
scope: strategy
});
var strategy = new OpenLayers.Strategy.Fixed();
var myLayer = new OpenLayers.Layer.Vector("Selected Tract",
{
displayInLayerSwitcher: true,
isBaseLayer: false,
visibility: true,
styleMap: new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
stokeColor: "#FFFF00",
strokeOpacity: 0.5,
fillColor: "#FFFF00",
fillOpacity: 0.3
})
})
});
var response = wfsProtocol.read({
filter: filter,
callback: processWFSQuery
});
function processWFSQuery(response) {
try {
var gmlParser = new
OpenLayers.Format.GML.v3();
var features =
gmlParser.read(response.priv.responseXML);
if(features) {
for(var i = 0; i < features.length;
i++) {
var feature = features[i];
feature.geometry.transform(new
OpenLayers.Projection('EPSG:4326'),this.map.getProjectionObject());
myLayer.addFeatures(feature);
}
}
} catch(e) {
alert("Error: " + e);
}
map.zoomToExtent(myLayer.getDataExtent());
}
I appreciate all of your help.
Thanks,
Jerome
More information about the Users
mailing list