how to get the current zoom in openlayers
Asked Answered
K

2

25

i have a question. i need to know the actual zoom of the open layers map

$scope.refreshMap = function (lat, long) {
    map.setView(new ol.View({
        projection: 'EPSG:4326',
        center: [long, lat], 
        zoom: "here I do not know what to put"
    }));
};

i try with map.getZoom() but it doesn't work. the logcat throws me a

Uncaught TypeError: Object #<S> has no method 'getZoom'

i'm using the openlayers Version: v3.16.0

Knutson answered 18/8, 2016 at 12:5 Comment(0)
G
46

Zoom is a property of ol.View. So ol.Map has a ol.View that has zoom level, center, projection to say some.

map.getView().getZoom();
Gsuit answered 18/8, 2016 at 12:10 Comment(0)
K
0
$scope.refreshMap = function (lat, long) {
            var actualZoom = map.getView().getZoom();
            console.log(z);

            map.setView(new ol.View({
                projection: 'EPSG:4326',
                center: [long, lat], //long,lat
                zoom: actualZoom
            }));
};
Knutson answered 18/8, 2016 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.