Add buttons to the PanZoom control which currently allow you to zoom to any level. Add a 'zoomTo' function that

allows you to specify a level. This will need to be refactored: Possibly the zoom control will become part of a 
subclass of PanZoom, "largePanZoom", which has a smaller set of controls.

Also add a DEFAULT_ZOOM_LEVELS setting, and an accesssor for said setting.


git-svn-id: http://svn.openlayers.org/trunk/openlayers@23 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-05-13 01:29:19 +00:00
parent 8bb245832c
commit bc8197969d
2 changed files with 28 additions and 2 deletions

View File

@@ -31,8 +31,12 @@ OpenLayers.Control.PanZoom.prototype =
this._addButton("panright", "east-mini.png", xy.addX(sz.w), sz); this._addButton("panright", "east-mini.png", xy.addX(sz.w), sz);
this._addButton("pandown", "south-mini.png", centered.addY(sz.h*2), sz); this._addButton("pandown", "south-mini.png", centered.addY(sz.h*2), sz);
this._addButton("zoomin", "zoom-plus-mini.png", centered.addY(sz.h*3), sz); this._addButton("zoomin", "zoom-plus-mini.png", centered.addY(sz.h*3), sz);
this._addButton("zoomextents", "zoom-world-mini.png", centered.addY(sz.h*4), sz); centered = centered.addY(sz.h*3);
this._addButton("zoomout", "zoom-minus-mini.png", centered.addY(sz.h*5), sz); for (var i=this.map.getZoomLevels(); i--; i>=0) {
centered = centered.addY(sz.h);
this._addButton("zoomLevel"+i, "zoom-world-mini.png", centered, sz);
}
this._addButton("zoomout", "zoom-minus-mini.png", centered.addY(sz.h), sz);
return this.div; return this.div;
}, },
@@ -61,7 +65,13 @@ OpenLayers.Control.PanZoom.prototype =
}, },
buttonDown: function (evt) { buttonDown: function (evt) {
if (this.action.startsWith("zoomLevel")) {
this.map.zoomTo(parseInt(this.action.substr(9,this.action.length)));
}
switch (this.action) { switch (this.action) {
case "zoomLevel0":
this.map.zoomExtent();
break;
case "panup": case "panup":
var resolution = this.map.getResolution(); var resolution = this.map.getResolution();
var center = this.map.getCenter(); var center = this.map.getCenter();

View File

@@ -7,6 +7,9 @@
OpenLayers.Map = Class.create(); OpenLayers.Map = Class.create();
OpenLayers.Map.prototype = { OpenLayers.Map.prototype = {
// int zoom levels, used to draw zoom dragging control
DEFAULT_ZOOM_LEVELS: 16,
// OpenLayers.Bounds // OpenLayers.Bounds
DEFAULT_FULL_EXTENT: new OpenLayers.Bounds(-90, -180, 90, 180), DEFAULT_FULL_EXTENT: new OpenLayers.Bounds(-90, -180, 90, 180),
@@ -171,6 +174,10 @@ OpenLayers.Map.prototype = {
return this.DEFAULT_FULL_EXTENT; return this.DEFAULT_FULL_EXTENT;
}, },
getZoomLevels: function() {
return this.DEFAULT_ZOOM_LEVELS;
},
/** /**
* @param {OpenLayers.Bounds} bounds * @param {OpenLayers.Bounds} bounds
* *
@@ -244,6 +251,15 @@ OpenLayers.Map.prototype = {
}, },
/**
* zoomTo
* Set Zoom To int
*/
zoomTo: function(zoom) {
this.zoom = zoom;
this.moveToNewExtent(true);
},
/** /**
* zoomOut * zoomOut
* Decrease zoom level by one. * Decrease zoom level by one.