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

I have been using map.setBaseLayer(layer); to switch to my preferred map layer, using the localStorage variable layer that is stored in my web browser, upon initialization of the map. But I realize that this is creating unnecessary calls to load the default (first layer) map tiles that I may not need if the preferred layer is the second or third one. Is there a way that I can pre-select the base layer to be displayed (before map initialization), without changing the order of the map layers?

share|improve this question
up vote 1 down vote accepted
  1. First You should define the layers but do not add them to map.
  2. Then set map.baseLayer = your-layer
  3. then add all layers to map.

OpenLayers add the first baselayer in map.baseLayer property but calls it only when add to map. So you can change the layer before being called.

share|improve this answer
I think this is a possible solution. Strangely, I am not facing this problem anymore. And I can't remember what I did. Maybe running the setBaseLayer immediately after initialization does the trick. Anyway thanks. – Question Overflow Nov 17 '13 at 9:03

Set them all as not visible with base layer as true, then just make visible the one you want.

share|improve this answer

I usually use the isBaseLayer property to set the baseLayer, like this:

    var ol_wms = new OpenLayers.Layer.WMS.Untiled( "OpenLayers WMS", 
        "", {layers: 'basic'}, 
        { isBaseLayer: true} );
  var map = new OpenLayers.Map('map');
    map.setCenter(new OpenLayers.LonLat(0, 0), 0);

For more, see this article: BaseLayers and Overlays

share|improve this answer
No, it doesn't work. isBaseLayer only defines whether the layer is a base layer. We can have many different base layers, but only one can be set at any time. You can try add a few layers to understand what I mean. – Question Overflow Apr 13 '13 at 12:24
If you have multiple Base Layers, then one which is top most (i.e added last) will be visible. So set whichever one you need last. – Devdatta Tengshe Apr 13 '13 at 15:42
The first layer, layer[0] will be visible by default. But as I have stated in my question, I don't want to change the map order. – Question Overflow Apr 14 '13 at 7:47

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.