Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:

enter image description here

However on refreshing the page and clicking on the same feature it gives me:

enter image description here

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");
                    }
            });
   }
share|improve this question
    
have you tried pasting those messages into the demo/test servlet? –  iant Feb 21 '13 at 12:04
    
yes and they return address list 1 and address list 2 respectively. –  Peter Campbell Feb 21 '13 at 12:12
    
then what is the problem? –  iant Feb 21 '13 at 12:17
    
The problem is that I am getting different results when clicking on the same feature (No 5). I would expect to always get the 1st set of addresses when clicking on this feature. –  Peter Campbell Feb 21 '13 at 12:20
    
The issue seems to come from the fact that after a page refresh 5 Market Place is already selected. When you click on it again (for some reason) 7 Market place is then selected and this sent as the request. Not sure exactly what's going on here but it might be worth checking to see whether your selection code is affecting anything. The GetFeature request seems to be working ok though given the parameters. –  pecoanddeco Feb 21 '13 at 13:26

3 Answers 3

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.

share|improve this answer
    
It is not the address display that is the problem. The underlying feature select should return a consistant result when clicked within the bounds of a feature. –  Peter Campbell Feb 25 '13 at 11:01

I'm wondering whether it's a race issue. How do you control whether getfeatureinfo or featuresselected gets fired first when you click on the map? Could you check to see which order these are being fired as it might give a clue as to whether the map selection is causing the issue or not. I'm guessing a different feature is being passed to showInfo which is why the co-ordinates are different, and hence why the results are incorrect.

share|improve this answer
    
I think you are on to something here - if I remove the initial on document load search for feature, and then manually pan to and click on the 5 Market Place it is giving me the correct results every time (or the 5 times with refresh I have tested it). –  Peter Campbell Feb 25 '13 at 14:31
    
I have added map.updateSize() to the end of the initial Get Feature request, and the map is now showing the correct results every time the feature is clicked. –  Peter Campbell Feb 25 '13 at 15:02
    
Great, glad it helped. –  pecoanddeco Feb 25 '13 at 16:41
up vote 1 down vote accepted

In this case the centring and zooming of the map is delayed until the UPRN attribute has been used to get the matching Feature in the searchBLPUs function. By this time the map object has already been loaded and bound to the html div.

Therefore the map needs to be resized once the feature has been successfully returned and the map has been centred and zoomed.

The searchBLPUs function needs to be amended to add in the map.updateSize function:

    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);
                            map.updateSize();
                        },
                        failure: function(reply) {
                                alert("failed");
                        }
                });    
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.