I've implemented a openlayers bbox strategy on a vector layer. I have my server return a nice jsonp object wrapped in the callback given by the request.

The problem is that during normal use of the map I get al lott of errors like:

TypeError: OpenLayers.Protocol.Script.registry.c18 is not a function

where c18 is the number of the request. The map keeps working, but these show up as actual errors in Firebug. This happens very often just playing around for a minute results in a dozen or so of these errors. In the 'NET' tab I can see that it seems to happen every time the map interface issues two requests for data.

GET poi?bbox=-0.597037...cript.registry.c18, 200 OK, localhost, 101.8KB,, 250ms

GET poi?bbox=-6.831778...cript.registry.c19, 200 OK, localhost, 102.3KB,, 421ms

I guess the callback corresponding to the first one of the set of two gets deleted by the second request, so when the first bit of data returns, you get the error. So, why does it fire two requests? and how to fix this. My guess is that it has something to do with resizing the map and zooming at the same time and both events result in a request??

Here is how I configured the layer. It's the only layer with a BBOX strategy:

var in_options = {
    'internalProjection': config.projection,
    'externalProjection': config.displayProjection

// add a layer to the map
this.layer = new OpenLayers.Layer.Vector("POI",{
    strategies: [
        new OpenLayers.Strategy.BBOX({
            resFactor: 2,
            active: false,
            autoActivate: false,
            ratio: 1.3
        new OpenLayers.Strategy.Cluster({
            distance: this.clusterDistance,
            threshold: this.clusterThreshold
    protocol: new OpenLayers.Protocol.Script({
        url: 'http://localhost/tests/poi',
        callbackKey: 'callback',
        format: new OpenLayers.Format.GeoJSON(in_options),
    styleMap: new OpenLayers.StyleMap({
        "default": style,
this.layer.strategies[0].calculateBounds = this.myCalculateBounds;

Edit I've looked at the layer properties, there are two listeners registered. One for the BBOX strategy and one for the cluster. None of these invoke each other. So I looked at the source of the BBOX strategy. The TriggerRead Method of the OpenLayers.Strategy.BBOX class has one argument: options. If you console log this one, it's just the event object send by the layers eventHandler. It's not an opion object associated with the BBOX instance. That also explains why the setting noAbort wasn't working. I changed this line:

if (this.response && !(options && options.noAbort === true)) {

into this:

if (this.response && !(this.noAbort && this.noAbort === true)) {

and ofcourse set the noAbort: true in the layer strategy

 new OpenLayers.Strategy.BBOX({
        resFactor: 2,
        active: false,
        autoActivate: false,
        ratio: 1.3,
        noAbort: true,

Did I discover a bug in OpenLayers?

  • I encountered double requests once i started playing with bbox strategy.Since when NoAbort option allows you to cancel request while secondary strategy sending request.Meanwhile,the reason in your condition may depend on options I believe.I corrected this issue by registering and overriding map's zoomend event where i force layer to refresh manually. – Myra Dec 3 '12 at 9:50

Your Answer

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

Browse other questions tagged or ask your own question.