5
layer_osm = new OpenLayers.Layer.OSM( "Simple OSM Map","",{
        isBaseLayer : true,
        displayInLayerSwitcher : false,
        numZoomLevels: 26,
    });

I have several WFS and WMS Layers on Top of a OSM Base Layer, and I want to stop loading the OSM layer at zoom 19, which is the max zoom for OSM. When I increase the zoom level above 19, I get 404 when loading the OSM tiles. I simply want my OSM Layer to stop loading tiles when zoom level > 19. How can I do that?

3 Answers 3

5

You can use the setOpacity function to show/hide the layer_osm by detecting the zoom level on each zoom change. For example, use the below snippet

map.events.register("zoomend", map, function(){
     var zoom = map.getZoom();
     console.log(zoom);
     if(zoom>19){
        layer_osm.setOpacity(0);
     }
     else{
        layer_osm.setOpacity(1);
     }
});

Here is a working fiddle. Zoom in the map and when you'd exceed the zoom level 19, you see that OSM layer hides while the WMS layer stays there.

4
+50

Inside the layer parameters, define custom resolution for zoom greater than 19. As in this case i have defined the resolutions till zoom level 22.

map = new OpenLayers.Map("osm");
var layer_osm = new OpenLayers.Layer.OSM(null, null, {
        resolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
                      19567.87923828125, 9783.939619140625, 4891.9698095703125,
                      2445.9849047851562, 1222.9924523925781, 611.4962261962891,
                      305.74811309814453, 152.87405654907226, 76.43702827453613,
                      38.218514137268066, 19.109257068634033, 9.554628534317017,
                      4.777314267158508, 2.388657133579254, 1.194328566789627,
                      0.5971642833948135, 0.25, 0.1, 0.05],
        serverResolutions: [156543.03390625, 78271.516953125,39135.7584765625,
                            19567.87923828125, 9783.939619140625,
                            4891.9698095703125, 2445.9849047851562,
                            1222.9924523925781, 611.4962261962891,
                            305.74811309814453, 152.87405654907226,
                            76.43702827453613, 38.218514137268066,
                            19.109257068634033, 9.554628534317017,
                            4.777314267158508, 2.388657133579254,
                            1.194328566789627, 0.5971642833948135],
        transitionEffect: 'resize'
    });
        map.addLayer(layer_osm);

the above script will result in loading the osm tiles from last zoom level (i.e. zoom 19) and show the same tiles for every zoom greater than 19.

3
  • when zooming in, everything is fine now. When zooming out, the ratio to the vector layer crushes.
    – Lokomotywa
    Commented May 9, 2016 at 11:42
  • generally, I would prefer the OSM tiles do be not displayed at all after zooming to zoom level > 19
    – Lokomotywa
    Commented May 9, 2016 at 11:47
  • 1
    'stop loading OSM tiles while zoom in' i don't know if that is possible. However setting layer opacity to zero, as mentioned by @muzaffar can do the trick Commented May 10, 2016 at 5:09
3

Adding maxZoomLevel:19 should do the trick

layer_osm = new OpenLayers.Layer.OSM( "Simple OSM Map","",{
        isBaseLayer : true,
        displayInLayerSwitcher : false,
        maxZoomLevel: 19

    });
13
  • unfortunately, that does not work.
    – Lokomotywa
    Commented May 6, 2016 at 10:22
  • What platform are you using? Commented May 6, 2016 at 10:23
  • firefox 44.0 on ubuntu 15.04
    – Lokomotywa
    Commented May 6, 2016 at 10:25
  • 1
    if I ommit numZoomLevels: 26, I cannot zoom closer than 19, but that is exactly what I need.
    – Lokomotywa
    Commented May 6, 2016 at 10:28
  • try using numZoomLevels: null Commented May 6, 2016 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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