I have a map with a tilecache baselayer and a WMS property layer. By clicking on a property a GetFeature request is done using OpenLayers.Protocol.WFS.fromWMSLayer for the protocol.
A test version of the map is at http://geonet.allerdale.gov.uk/testmapapp/allerdalelookup/?uprn=100110685115
When clicking on Property 5 Market Place (the one highlighted on load) a list of possible properties for that feature should appear. Sometimes this list shows as:
However on refreshing the page and clicking on the same feature it gives me:
The GetFeature request I am using is
var control = new OpenLayers.Control.GetFeature({
protocol: OpenLayers.Protocol.WFS.fromWMSLayer(llpg_layer,
{ outputFormat: "JSON",
readFormat: new OpenLayers.Format.GeoJSON()
}),
single: false,
clickTolerance: 10,
filterType: OpenLayers.Filter.Spatial.CONTAINS
});
control.events.register("getfeatureinfo", this, function(e) {
feature_layer.removeAllFeatures();
feature_layer.addFeatures([e.feature]);
showInfo(e.feature);
});
control.events.register("featuresselected", this, function(e){
var features = e.features;
if (features.length > 1){
multipleFeatures(features);
}
});
control.events.register("featureunselected", this, function(e) {
feature_layer.removeFeatures([e.feature]);
});
map.addControl(control);
control.activate();
From what I can see on Firebug the first request posts this:
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" outputFormat="JSON" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:Query typeName="AllerdaleOnly:abc_llpg">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:Contains>
<ogc:PropertyName></ogc:PropertyName>
<gml:Envelope xmlns:gml="http://www.opengis.net/gml">
<gml:lowerCorner>300587.38521012 528552.83828508</gml:lowerCorner>
<gml:upperCorner>300588.26715409 528553.72022905</gml:upperCorner>
</gml:Envelope>
</ogc:Contains>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>
And the second one posted this:
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" outputFormat="JSON" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:Query typeName="AllerdaleOnly:abc_llpg">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:Contains>
<ogc:PropertyName></ogc:PropertyName>
<gml:Envelope xmlns:gml="http://www.opengis.net/gml">
<gml:lowerCorner>300587.38521012 528544.23051142</gml:lowerCorner>
<gml:upperCorner>300588.26715409 528545.11245538</gml:upperCorner>
</gml:Envelope>
</ogc:Contains>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>
UPDATE
I have noticed the following
I have added mousePosition to a local version of the page, and when the feature (5 Market Place) selects as expected the top left and bottom right as follows:
Top Left: 300578.68/528556.80
Bottom Right: 300591.56/528550.80
When on reload the feature selects is not working as expected, the 2 corners' position has changed.
Top Left: 300578.86/528548.57
Bottom Right: 300591.38/528542.75
The following function is called in the initial map creation function, adding a highlighted feature and centring and zooming the map on that feature:
var searchBLPUs = function (uprn){
var filter = '<Filter xmlns:ogc="http://www.opengis.net/ogc">';
filter += '<PropertyIsEqualTo>';
filter += '<PropertyName>a_uprn</PropertyName><Literal>';
filter += uprn.trim();
filter += '</Literal></PropertyIsEqualTo></Filter>';
OpenLayers.Request.GET({
url: that.wfsurl,
params: {
typeName: "AllerdaleOnly:abc_llpg",
service: "WFS",
version: "1.1.0",
outputFormat: "JSON",
readFormat: new OpenLayers.Format.GeoJSON(),
srsName: "EPSG:27700",
request: "GetFeature",
filter: filter
},
success: function(reply) {
var format = new OpenLayers.Format.GeoJSON();
var feature = format.read(reply.responseText)[0];
that.centerOnFeature(feature.geometry);
var address = feature.attributes.b_address;
showAddress(address, feature.attributes.a_uprn);
},
failure: function(reply) {
alert("failed");
}
});
}
Best Answer
Perhaps this causes the problem as maybe it gets a new number after refresh and changes the number in the address bar sequentialy from a list? "Get a new UPRN" - "To obtain another UPRN number,
click onto any part of the map and the UPRN number will change in the address bar" Perhaps a map refresh before a click event would help along with a cache empty return.