I have problem creating feature count window. I have urls stored in as json object. I iterate it with jquery and send request to remote data. The I have featureStore which is initially set to 0. When the request is done i try to update it with new feature count but it only updates the last url of array here "S". The console of handler has always last value of the array here "S". Is there any way I can synchronize this? I think there are mulitple request and some request returns value faster than other without considering which url request is send. How do I synchronize so that I can update featureStore eaxctly as the elements in URL.

                var current ;         
                var featuresStore = 
                                     "F" : 0,
                                     "S" : 0

                          var urls = 
                                         "F" : "<Filter><PropertyIsEqualTo><PropertyName>Vendor</PropertyName><Literal>TE</Literal></PropertyIsEqualTo></Filter>)",
                                         "S" : "<Filter><PropertyIsEqualTo><PropertyName>Vendor</PropertyName><Literal>TE</Literal></PropertyIsEqualTo></Filter>)"   

                  //Feature Store before 

                   //reads nof of features  
                  var LegendHandler = function (request) {
                          var noOfFeature;
                             try {
                                    var xmlFormat  = new OpenLayers.Format.XML();
                                    var data  = xmlFormat.read(request.responseText);
                                    var format = new OpenLayers.Format.WFST.v1_1_0({});
                                    var result = format.read(data, {output: "object"});
                                    noOfFeature = result.numberOfFeatures;

                                    $("#messageText").val("Error "+e);
                                    console.log("Error "+e);
                                    noOfFeature = 0;
                                   featuresStore.current = noOfFeature;
                                   console.log("The current value is "+current);
            //Iterating over each URLs          
                                current = i;
                                console.log("The current value is "+current);
                        var request = OpenLayers.Request.GET({
                                    url: urls[i],
                                    callback: LegendHandler


                          //Feature Store after 

For example:

var arr = [];
LegendHandler = function(e){arr.push(e.status)};
OpenLayers.Request.GET({url: '***.json', callback:  LegendHandler});

It looks like you have edited your question. In this case for sending additional parameters to the callback function you should use scope option of OpenLayers.Request object. The solution of your task (I've tested it on my own data so you should to modify it a little bit):

var geojson = new OpenLayers.Format.GeoJSON();

function feature_count(request) {
    var features = geojson.read(request.responseText);
    fs[this.index].count = features.length;

var fs = [
        'url': 'http://hostname/users.json',
        'feature_count': 0
        'url': 'http://hostname/users.json',
        'feature_count': 0

for (var i=0; i<fs.length; i+=1) {
        url: fs[i].url,
        success: feature_count,
        scope: {'index': i}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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