Andrew Lee
Andrew Lee

Reputation: 13

How to set max zoom

So I noticed in the older version of the API there was a maxZoomLevel under nokia.maps.map.Display. However I can not find anything similar to this in the JS API 3.0.

Currently I am using

map.addEventListener('mapviewchange', function () {
    var zoom=map.getZoom();
    if(zoom<=maxZoom)  {
        map.setZoom(maxZoom)
    }
});

But once it hits the maxZoom and you zoom out more it is very choppy since it zooms out a bit then I set it back to maxZoom. Is there any better way of doing this?

Upvotes: 1

Views: 2751

Answers (2)

Aram Tchekrekjian
Aram Tchekrekjian

Reputation: 935

Just a small addition on the accepted answer, if anyone is trying to use a vector layer, as provided in the here maps examples, then you just need to select the vector object, as done below:

var defaultLayers = platform.createDefaultLayers();
defaultLayers.vector.normal.map.setMax(19); // this will set the max zoom level, so the user won't able to zoom deeper than 19 (close to buildings level)

var map = new H.Map(document.getElementById('map'),
            defaultLayers.vector.normal.map,
            {
                center: currentAddress,
                zoom: 18 // this is the default zoom level
            });

Upvotes: 2

user3505695
user3505695

Reputation:

You can set the max zoom for the layer, something like follow should work

var defaultLayers = platform.createDefaultLayers();
defaultLayers.normal.map.setMax(12);

var map = new H.Map(mapContainer,
  defaultLayers.normal.map,{
  center: {lat:39.2328, lng:9.01168},
});

Upvotes: 6

Related Questions