From bc8197969dc9140b583ed68e853e75a7002133e6 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Sat, 13 May 2006 01:29:19 +0000 Subject: [PATCH] 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 --- lib/OpenLayers/Control/PanZoom.js | 14 ++++++++++++-- lib/OpenLayers/Map.js | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Control/PanZoom.js b/lib/OpenLayers/Control/PanZoom.js index b94d15d76f..ea9f2c38ff 100644 --- a/lib/OpenLayers/Control/PanZoom.js +++ b/lib/OpenLayers/Control/PanZoom.js @@ -31,8 +31,12 @@ OpenLayers.Control.PanZoom.prototype = 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("zoomin", "zoom-plus-mini.png", centered.addY(sz.h*3), sz); - this._addButton("zoomextents", "zoom-world-mini.png", centered.addY(sz.h*4), sz); - this._addButton("zoomout", "zoom-minus-mini.png", centered.addY(sz.h*5), sz); + centered = centered.addY(sz.h*3); + 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; }, @@ -61,7 +65,13 @@ OpenLayers.Control.PanZoom.prototype = }, buttonDown: function (evt) { + if (this.action.startsWith("zoomLevel")) { + this.map.zoomTo(parseInt(this.action.substr(9,this.action.length))); + } switch (this.action) { + case "zoomLevel0": + this.map.zoomExtent(); + break; case "panup": var resolution = this.map.getResolution(); var center = this.map.getCenter(); diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 2f6a44d377..9816f14b4b 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -7,6 +7,9 @@ OpenLayers.Map = Class.create(); OpenLayers.Map.prototype = { + // int zoom levels, used to draw zoom dragging control + DEFAULT_ZOOM_LEVELS: 16, + // OpenLayers.Bounds DEFAULT_FULL_EXTENT: new OpenLayers.Bounds(-90, -180, 90, 180), @@ -170,6 +173,10 @@ OpenLayers.Map.prototype = { getFullExtent: function () { return this.DEFAULT_FULL_EXTENT; }, + + getZoomLevels: function() { + return this.DEFAULT_ZOOM_LEVELS; + }, /** * @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 * Decrease zoom level by one.