Hi, I use always a baselayer like
var fakeLayer = new OpenLayers.Layer.Vector("Fake"); fakeLayer.isBaseLayer = true; //fakeLayer.displayInLayerSwitcher = false; ,when i not use commercial layers. Arnd -----Ursprüngliche Nachricht----- Von: openlayers-users-boun...@lists.osgeo.org [mailto:openlayers-users-boun...@lists.osgeo.org] Im Auftrag von Puneet Kishor Gesendet: Sonntag, 28. November 2010 16:03 An: users Betreff: [OpenLayers-Users] Re: map.removeLayer vs. map.destroy I think I know what is going on, but I don't know why. Read on... Puneet Kishor wrote: > I have a map with lots of image layers (in addition to a few reference > layers) for "scenario A". References to these image layers are stored > in a global array, say "globLayers". I want to "reset" my map to > depict another "scenario B". Right now I am removing all the layers > for scenario A and then adding those for scenario B. It goes like so > > // Remove any old layers > if (globLayers.length > 0) { > for (var i = 0; i < globLayers.length; i++) { > map.removeLayer(globLayers[i]); > } > > // Reset globLayers > globLayers = []; > } > > /* > Create new layers (various values that define the layer > are calculated elsewhere) > */ > for (var year = this.config.start_year; year <= end_year; year++) { > var layer = new OpenLayers.Layer.Image( > year, > uri, > new OpenLayers.Bounds(xmin, ymin, xmax, ymax), > new OpenLayers.Size(img_w, img_h), > { > format: "image/gif", > isBaseLayer: false, > displayInLayerSwitcher: false, > visibility: false > } > ); > > // Register a moveend event that swaps the image on zoom level > change > layer.events.register("moveend", null, onzoom); > > globLayers.push(layer); > } > > map.addLayers(globLayers); > > All of the above works just fine the first time. If I change my > scenario, and load a new set of layers, I get the following error in > Firebug in "OpenLayers.js (line 837)" > > layer is undefined > if(this.allOverlays){layer.isBaseLayer=false;} > In my map options, I have allOverlays true. This is because I don't have an explicit base layer. This works the first time I create the map and add layers to it. However, if I remove the layers and add new layers back again, the above `if(this.allOverlays){layer.isBaseLayer=false}` is triggered. What can I do to avoid this? > Two questions -- one, what is the reason for the error above? and two, > should I be using map.removeLayers or map.destroy? I am assuming > map.removeLayers because my map object is still needed, and is reused. > In fact, I need it with all the other reference layers still visible. > > A corollary question -- under what scenarios does one use map.destroy? > What is its usefulness? > > Puneet. > _______________________________________________ Users mailing list us...@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/openlayers-users _______________________________________________ Users mailing list us...@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/openlayers-users