OL3 Custom proj/resolutions and minZoom/maxZoom

581 views Asked by At

Is the use of ol.view minZoom and maxZomm in addition to resolutions in a non webmercator map OK? Are minZoom and maxZoom really ignored? Or can they cause troubles?

I have behaviour that I can't figure out. Here is my issue:

I use a WMTS service (EPSG:2154) as basemap in a ol3 map (EPSG:2154 too). I set both View resolutions and ol.tilegrid.WMTS resolutions with:

var resolutions = [305.748084412797, 152.87417449832975, 76.43695495723364, 38.21860977054807, 19.109304885274035, 9.554652442637018, 4.777326221318509, 2.3886631106592544, 1.1943315553296272, 0.5971657776648136, 0.2984505969011562, 0.13229193125051253 ];

and use matrixids in the ol.tilegrid.WMTS

var matrixids= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ,10 ,11];

The map is OK 12 zoom levels are available. Basemap matrix ids are consistent with map zoom level.

But trying to limit the zoom levels I set 'minZoom' and 'maxZoom' in the view options in addition to 'resolutions'.

If minZoom = 0 and maxZoom = 8, I still can zoom over the 12 levels and map zooms are consistent with the basemap tilematrix called.

If minZoom = 4 and maxZoom = 9, I can zoom over 12 levels... but

  • Map zoom level starts at 4 and goes up to 15 (the shift from initial zoom levels = minZoom set in ol.View)
  • The basemap tilematrix are now unconsistent with map zoom: at map zoom 4 it requests basemap zoom level 0 (no shift applied to basemap calls)

thanks !

1

There are 1 answers

1
Icarus On BEST ANSWER

Since minZoom and maxZoom make problems with resolutions, I would recommend you to add custom behavior to the event "change:resolution" as follows:

map.getView().on('change:resolution', function(e) {
    // Set Zoom
});

I have edited your jsfiddle