Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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  =;
                                    var format = new OpenLayers.Format.WFST.v1_1_0({});
                                    var result =, {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 
share|improve this question
up vote 2 down vote accepted

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 =;
    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}
share|improve this answer
i know i need some js lesson. can you please explain how to send parameter to legendhandler and what e is?? – kinkajou Sep 28 '12 at 9:51
I've modified my answer, please check it out. – drnextgis Oct 1 '12 at 3:49
@Kitex please accept an answer if it was helpful. – drnextgis Oct 10 '12 at 1:43
thank u very much for help :) – kinkajou Oct 10 '12 at 2:02

Your Answer


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.