Skip to content

Commit

Permalink
Viewer增加setMinZoom和setMaxZoom方法
Browse files Browse the repository at this point in the history
  • Loading branch information
fanzia committed Sep 26, 2016
1 parent fda32b6 commit cab97f1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
14 changes: 14 additions & 0 deletions example/all/map/map_view_zoom.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,25 @@

alert("当前地图的级别是:" + level);
}

function setMaxZoom(){
var viewer = mapObj.getViewer();

viewer.setMaxZoom(10);
}

function setMinZoom(){
var viewer = mapObj.getViewer();

viewer.setMinZoom(3);
}
</script>
<title>Map5 -- 初始化地图</title>
<body onload="init()">
<button onclick="getZoom()">显示级别</button>
<button onclick="setZoom()">设置级别</button>
<button onclick="setMaxZoom()">设置最大显示级别</button>
<button onclick="setMinZoom()">设置最小显示级别</button>
<div id="mapDiv" style="height:800px;width:100%;position:absolute;">
</div>
</body>
Expand Down
28 changes: 27 additions & 1 deletion src/GeoBeans/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ GeoBeans.Viewer = GeoBeans.Class({
_rotation : 0.0,
_resolution : 1.0,

_transformation : null,
_minZoom : null,
_maxZoom : null,


initialize : function(map, options){
Expand Down Expand Up @@ -526,6 +527,10 @@ GeoBeans.Viewer.prototype.update = function(){
* @return {int} 最大显示级别
*/
GeoBeans.Viewer.prototype.getMaxZoom = function(){

if(this._maxZoom != null){
return this._maxZoom;
}
var map = this._map;

var layers = map.layers;
Expand All @@ -552,6 +557,9 @@ GeoBeans.Viewer.prototype.getMaxZoom = function(){
* @return {int} 最小显示级别
*/
GeoBeans.Viewer.prototype.getMinZoom = function(){
if(this._minZoom != null){
return this._minZoom;
}
var map = this._map;

var layers = map.layers;
Expand All @@ -572,3 +580,21 @@ GeoBeans.Viewer.prototype.getMinZoom = function(){
}
return minZoom;
};

/**
* 设置最大的显示级别
* @public
* @param {int} zoom 最大显示级别
*/
GeoBeans.Viewer.prototype.setMaxZoom = function(zoom){
this._maxZoom = zoom;
};

/**
* 设置最小的显示级别
* @public
* @param {int} zoom 最小的显示级别
*/
GeoBeans.Viewer.prototype.setMinZoom = function(zoom){
this._minZoom = zoom;
}

0 comments on commit cab97f1

Please sign in to comment.