OpenLayers OpenLayers

Ticket #248 (closed bug: fixed)

Opened 2 years ago

Last modified 1 year ago

Map allows layers to be added twice

Reported by: anonymous Assigned to: euzuro
Priority: minor Milestone: 2.4 Release
Component: Layer Version:
Keywords: Cc:
State:

Description

I'm working on a project that repeatedly adds and removes layers from the map.

I've been seeing intermittent errors in Layers.Grid.moveTo() - this.grid.length not defined, because this.grid is null.

I think that what is happening is that moveTo() is sometimes being called on a layer after the layer has been destroyed. Layer.destroy() calls Grid.destroy(), and Grid.destroy() sets this.grid to null.

My code, when I'm removing a layer, is:

openLayersMap.removeLayer(layer);
layer.destroy();
layer = null;

My hack to make the symptom go away is to change Grid.moveTo().

from:

moveTo:function(bounds, zoomChanged, dragging) {
  if (bounds == null) {
    bounds = this.map.getExtent();
  }
  if (bounds != null) {
    ...

to:

moveTo:function(bounds, zoomChanged, dragging) {
  if (bounds == null) {
    bounds = this.map.getExtent();
  }
  if (bounds != null && this.grid != null) {
    ...

But I don't think this addresses the cause.

I haven't been able to make this happen on demand. I think there may be some sort of timing sensitive situation that allows it.

Revision 1418.

Attachments

double_addlayer.patch (1.4 kB) - added by crschmidt on 02/18/07 12:13:05.

Change History

09/20/06 17:57:54 changed by jdege@korterra.com

With revision 1497, I'm seeing the same problem in Map.setCenter().

setCenter() now loops through all the layers, calling layer,getVisibility() and if true calling layer.moveTo().

Layer.getVisibility() returns (this.div.style.display != "none").

If I repeatedly add and remove layers, every once in a while this will be called when this.div is null.

10/02/06 16:46:05 changed by sderle

  • milestone set to 2.2 Release.

10/02/06 16:46:55 changed by sderle

euzuro sez "make sure that removeLayer is actually working"

10/06/06 15:24:31 changed by euzuro

  • owner set to euzuro.
  • status changed from new to assigned.

10/12/06 09:37:21 changed by euzuro

  • milestone changed from 2.2 Release to 2.3 Release.

10/16/06 11:37:06 changed by jdege@korterra.com

I don't want to say "nevermind", quite, but...

One of our testers managed to create a repeatable sequence that would generate this, and from that I managed to track down what was going on, and it was a problem in my code.

There was a path through my code by which I would call Map.addLayer(layer) twice for the same layer. When I did so, I'd end up with the same layer occupying two positions in the Map.js layers array.

When I later called Map.removeLayer(layer) and layer.destroy(), I'd end up with one position in the layers array being null.

I'm having a hard time envisioning what someone would expect to happen should they intentionally add the same layer to the map multiple times, so I see no reason why effort should be made to make sure that this scenario works.

At most, it might be appropriate to place some guard code to prevent or warn when someone (like me) does so inadvertently.

10/25/06 06:27:40 changed by euzuro

  • component changed from general to Layer.

12/28/06 20:12:51 changed by euzuro

  • milestone changed from 2.3 Release to 2.4 Release.

02/18/07 11:19:22 changed by crschmidt

  • summary changed from Grid.moveTo() being called on layers that are no longer attached to the map? to Map allows layers to be added twice.

02/18/07 11:26:03 changed by crschmidt

  • keywords set to review.

Attached patch prevents the same layer from being added to the map twice.

02/18/07 12:13:05 changed by crschmidt

  • attachment double_addlayer.patch added.

03/08/07 14:59:33 changed by sderle

  • status changed from assigned to closed.
  • resolution set to fixed.

patch applied as r2538.

03/08/07 14:59:58 changed by sderle

correction, applied as r2539.

07/05/07 17:04:18 changed by euzuro

  • keywords deleted.