[OpenLayers-Dev] Exception in OpenLayers.Layer.Grid.removeBackBuffer

Tim-Hinnerk Heuer th.heuer at gmail.com
Wed Mar 14 21:43:47 EDT 2012


Just to wrap this up for now. I made an override function for now and reset
my fork on github to not have the if statement in there. If you encounter
this bug, consider doing the same.

In a file loaded after OpenLayers, define the following (I know this is a
hack):

/**
 * This fixes the bug where backBuffer is not a child of this.div
 * For some reason the check this.div.containsChildren(this.backBuffer)
 * does not always work.
 * Adminttedly, this is a hack but fixes the problem for now.
 */
OpenLayers.Layer.Grid.prototype.removeBackBuffer = function() {
    try {
        this.div.removeChild(this.backBuffer);
    } catch (error) {}
    this.backBuffer = null;
    this.backBufferResolution = null;
    if(this.backBufferTimerId !== null) {
        window.clearTimeout(this.backBufferTimerId);
        this.backBufferTimerId = null;
    }
};

Cheers,
Tim

On Thu, Mar 15, 2012 at 11:42 AM, Tim-Hinnerk Heuer <th.heuer at gmail.com>wrote:

> Just looking some more into my code as well. Is it possibly to do with the
> fact that there is a small amount of time that there is no base layer for
> the map object I'm using? Maybe I do need to change my application code and
> it's not something that should be fixed on the OL side of things. I set the
> base layer manually with map.setBaseLayer(myBaseLayer) which is where the
> error occurs.
>
> Maybe I need to clean up that bit of code...
>
> Thanks for all the input so far!
>
>
> On Thu, Mar 15, 2012 at 10:58 AM, Tim-Hinnerk Heuer <th.heuer at gmail.com>wrote:
>
>> Hi Andreas,
>>
>> Just looking in the source, I see what you mean:
>>     /**
>>      * Method: clone
>>      * Create a clone of this layer
>>      *
>>      * Returns:
>>      * {<OpenLayers.Layer.WMS>} An exact clone of this layer
>>      */
>>     clone: function (obj) {
>>
>>         if (obj == null) {
>>             obj = new OpenLayers.Layer.WMS(this.name,
>>                                            this.url,
>>                                            this.params,
>>                                            this.getOptions());
>>         }
>>
>>         //get all additions from superclasses
>>         obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
>> // POINTS TO Grid
>>
>>         // copy/set any non-init, non-simple values here
>>
>>         return obj;
>>     },
>>
>> but
>>
>>     /**
>>      * APIMethod: clone
>>      * Create a clone of this layer
>>      *
>>      * Parameters:
>>      * obj - {Object} Is this ever used?
>>      *
>>      * Returns:
>>      * {<OpenLayers.Layer.Grid>} An exact clone of this
>> OpenLayers.Layer.Grid
>>      */
>>     clone: function (obj) {
>>
>>         if (obj == null) {
>>             obj = new OpenLayers.Layer.Grid(this.name,
>>                                             this.url,
>>                                             this.params,
>>                                             this.getOptions());
>>         }
>>
>>         //get all additions from superclasses
>>         obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this,
>> [obj]);
>>
>>         // copy/set any non-init, non-simple values here
>>         if (this.tileSize != null) {
>>             obj.tileSize = this.tileSize.clone();
>>         }
>>
>>         // we do not want to copy reference to grid, so we make a new
>> array
>>         obj.grid = []; // THIS IS WHAT YOU MEAN, RIGHT?
>>         obj.gridResolution = null;
>>
>>         return obj;
>>     },
>>
>> I don't know how to figure out the problem quickly. I might just have to
>> leave the fix as is for now, but this might be good to keep in the back of
>> our minds in case we stumble upon this problem again.
>>
>> Cheers,
>> Tim
>>
>>
>> ++Tim Hinnerk Heuer++
>>
>>
>> Twitter: @timhheuer
>> Blog: http://www.thheuer.com
>>
>>
>>
>> On Wed, Mar 14, 2012 at 9:14 PM, Andreas Hocevar <ahocevar at opengeo.org>wrote:
>>
>>> The clone method does not clone the grid, so it is not affected by the
>>> state of any images in the grid, and it also does not clone any
>>> backbuffer related properties. So the issue must be a different one.
>>>
>>> Andreas.
>>>
>>> On Wed, Mar 14, 2012 at 8:36 AM, Tim-Hinnerk Heuer <th.heuer at gmail.com>
>>> wrote:
>>> > Just guessing here:
>>> > Maybe the state of a layer changes when the tiles finish loading to
>>> > something more consistent that can be cloned and maybe the <img>
>>> element is
>>> > in a different state or not even there while it is loading? I seem to
>>> > remember something like that when I was doing the VideoWMS. Correct me
>>> if
>>> > I'm wrong.
>>> >
>>> > Thanks,
>>> > Tim
>>> >
>>> > On Wed, Mar 14, 2012 at 8:28 PM, Eric Lemoine <
>>> eric.lemoine at camptocamp.com>
>>> > wrote:
>>> >>
>>> >> On Wed, Mar 14, 2012 at 8:08 AM, Andreas Hocevar <
>>> ahocevar at opengeo.org>
>>> >> wrote:
>>> >> > The only occasions I could think of that could potentially make
>>> >> > this.backBuffer both non-null and not a child of this.div is when a
>>> >> > layer is cloned during tile loading
>>> >>
>>> >> I had thought about this too. But I'm still failing to understand how
>>> >> cloning can lead to this state. Do you mind elaborating a bit? Thank
>>> >> you.
>>> >>
>>> >>
>>> >> --
>>> >> Eric Lemoine
>>> >>
>>> >> Camptocamp France SAS
>>> >> Savoie Technolac, BP 352
>>> >> 73377 Le Bourget du Lac, Cedex
>>> >>
>>> >> Tel : 00 33 4 79 44 44 96
>>> >> Mail : eric.lemoine at camptocamp.com
>>> >> http://www.camptocamp.com
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> Andreas Hocevar
>>> OpenGeo - http://opengeo.org/
>>> Expert service straight from the developers.
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20120315/909ca5df/attachment.html


More information about the Dev mailing list