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

Why does this callback get ignored:

new OpenLayers.Layer.Vector("My layer",
        projection : "EPSG:4326",
        strategies : [ new OpenLayers.Strategy.Fixed(), refreshStrategy ],

        protocol : new OpenLayers.Protocol.HTTP(
          url    : "myphpurl.php",
          params : { rand : Math.random() * 1000 },
          format : new OpenLayers.Format.GeoJSON(),
          callback: function(){alert('test');}

I'm trying to get access to how many features were returned...

share|improve this question
up vote 2 down vote accepted

Callback get ignored because it's possible is overridden by another callback function internally (e.g. OpenLayers.Strategy.BBOX.merge). Use events mechanism for get feature count:

layer = new OpenLayers.Layer.Vector("My layer", ...){"loadend": function(e){console.log(e.object.features.length)}})

According to documentation callback property of OpenLayers.Protocol.HTTP is not marked as APIProperty, so it is for internal use only.

share|improve this answer

I think you're just missing the part where you ask the layer to read the data (see ** line below):

    var request = OpenLayers.Request.GET({
        url: serviceUrl.url,
        callback: function(request) {
            var geojson_format = new OpenLayers.Format.GeoJSON({
                'internalProjection': toProj,
                'externalProjection': fromProj
            **gfs =**

share|improve this answer
Thanks @yalestar! It looks like the request was already being made, but the callback was being overridden. I eventually just ended up overriding handleResponse to get that the info I needed. – Jonathan Dec 13 '12 at 14:39

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.