Search code examples
openlayersopenstreetmapopenlayers-3

OpenLayers 3 - Serve OSM basemap tiles only for specific bbox


I would like to create a web map which is based on OSM basemap but I need only the tiles for the specific country I need to analyze. The reason for this is that I want to avoid loading more tiles when the user drags the map, hence increasing data downloaded and loading time.

I am not looking for tiles development locally but in setting OpenLayers 3 parameters limiting the OSM baselayer rendering.

Is there a way for this?


Solution

  • You can set an extent in the layer constructor. e.g. for an OSM layer restricted to Switzerland

        new ol.layer.Tile({
          source: new ol.source.OSM(),
          extent: ol.proj.transformExtent([5.9,45.8,10.55,47.85],'EPSG:4326','EPSG:3857')
        })