1

I'm developing a project in which OSM (OpenStreetMap) is default base map. There is one satellite image which is loaded after selecting it from layer list. I have assigned minzoom and maxzoom. Now I want when layer reach to minzoom that time satellite image will disappear and OSM layer appears as background layer. I have to call a function for this.

function zoomlevel()
    {
        if(maxZoom==18)
        {
            base_layer_definition_array.push(new ol.layer.Tile({
                  title: 'Satellite Image',
                group: "background",
                visible: false,
                crossOrigin: 'anonymous',
                source: new ol.source.XYZ({
                    urls:[
                        'http://localhost/tileserver/sate.png'
                    ],
                    minZoom: 0,
                    maxZoom: 21,
                    tilePixelRatio: 1
                })
            }));
        }
    }
1

You can watch to map view resolution changes and change the base layer, like:

map.getView().on('change:resolution', function(evt){
  var zoom = map.getView().getZoom();
  if (zoom < 18) {
    layer_satellite.setVisible(true);
  } else {
    layer_satellite.setVisible(false);
  }

  // or
  layer_satellite.setVisible(zoom < 18);
});

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.