2

I want to create combobox with all available scales, that could replace standard zoom slider control. As far as I know, there is no scale attribute in OL and scales must be calculated from resolutions. In api docs I found that resolutions can be retrieved from:

  1. view - if fixed resolutions were provided during initialization. In my case they were not and the result is undefined

var resolutions = this.map.getView().getResolutions();

  1. tileGrid of a layer - I do not have any base layer and for each layer in my map code below does not return resolutions

resolutions = layers[0].getSource().getTileGrid().getResolutions();

So now, how can get all available resolutions? I believe I can calculate them from projection but I can't find any proper method to do that.

EDIT:

Immediately after posting the question I found a workaround. I can create TileGrid from projecton and get the resolutions from there:

var projection = ol.proj.get(this.getSrs());
        var tileGrid = ol.tilegrid.createXYZ({
            extent: projection.getExtent(),
            tileSize: 512
        });

        console.log('projection resolutions', tileGrid.getResolutions());

but it does not seem to be good solution, so maybe somone can point me to the right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.