2014-10-27 96 views
0

我生成的地圖與Here maps JS Api 3.0。我想將縮放限制爲最小/最大值並平移到給定的矩形。有沒有辦法做到這一點? 例如:限制平移和縮放在這裏地圖3.0

map.setMinZoom(4); 
map.setMaxZoom(14); 
map.setPanRestriction(rectangle); 

回答

0

我猜你想限制視到現在你有你的圖像疊加...

最簡單的方法是聽來查看模型和和視口更新類似的另一個例子: Custom map overlay heremaps js api v3

現在你可以看看地圖的中心座標,看看它是否在你想要顯示的邊界內。如果沒有,請將其設置在邊界內。類似的規定可能會爲你工作:

var bounds = new H.geo.Rect(45, -45, -45, 45); 
 

 
map.getViewModel().addEventListener('sync', function() { 
 
    var center = map.getCenter(), 
 
     adjustLat, 
 
     adjustLng; 
 
    if (!bounds.containsPoint(center)) { 
 
    if (center.lat > bounds.getTop()) { 
 
     adjustLat = bounds.getTop(); 
 
    } else if (center.lat < bounds.getBottom()) { 
 
     adjustLat = bounds.getBottom(); 
 
    } else { 
 
     adjustLat = center.lat; 
 
    } 
 
    if (center.lng < bounds.getLeft()) { 
 
     adjustLng = bounds.getLeft(); 
 
    } else if (center.lng > bounds.getRight()) { 
 
     adjustLng = bounds.getRight(); 
 
    } else { 
 
     adjustLng = center.lng; 
 
    } 
 
    map.setCenter({ 
 
     lat: adjustLat, 
 
     lng: adjustLng 
 
    }); 
 
    } 
 
}); 
 

 
//Debug code to visualize where your restriction is 
 
map.addObject(new H.map.Rect(bounds));