5

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?

1
  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.

  • 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
1

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

0

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

    var ol_wms = new OpenLayers.Layer.WMS.Untiled( "OpenLayers WMS", 
        "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, 
        { isBaseLayer: true} );
  var map = new OpenLayers.Map('map');
    map.addLayer(ol_wms);
    map.setCenter(new OpenLayers.LonLat(0, 0), 0);

For more, see this article: BaseLayers and Overlays

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.