How to set max zoom

半城伤御伤魂 提交于 2019-12-11 12:12:29

问题


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?


回答1:


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},
});



回答2:


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
            });


来源:https://stackoverflow.com/questions/35635036/how-to-set-max-zoom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!