[GIS] GetFeature with WFS layer is not working as the click coordinates are returned in spherical coordinates

geoservergetfeatureopenlayers-2wfs

GetFeature with WFS layer is not working as the click coordinates are returned in spherical coordinates.

Using GeoServer 2.1.3 and OpenLayers 2.11

Layer information is in EPSG:4326, WMS works fine, WFS transaction works fine

Trying to GetFeature information on click from the WFS layer as the total number of features are small and it is a custom vector layer.

control = new OpenLayers.Control.GetFeature({
    protocol: wfs_layer_protocol,
    box: false,
    hover: false,
    click: true
});

control.events.register("featureselected", this, pickNodeId);
map.addControl(control);
control.activate();

The WFS post request has the following bounds:

<gml:lowerCorner>-14710846.457064 4317003.9227542</gml:lowerCorner> 
<gml:upperCorner>-13710750.910779 6517099.4690396</gml:upperCorner>  
</gml:Envelope>
</ogc:BBOX>
</ogc:Filter>

Best Answer

try this:

control = new OpenLayers.Control.GetFeature({
  protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layer),
  box: true,
  hover: true,
  multipleKey: "shiftKey",
  toggleKey: "ctrlKey"
  });
control.events.register("featureselected", this, function(e) {
  var feat = e.feature;
  var res = feat.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"))
  alert(res);
  });

i hope it helps you...

Related Question