From 47bf4cdad8096e9bd5fad4a30149ccb8069d7170 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Tue, 16 May 2006 19:27:22 +0000 Subject: [PATCH] Changed DEFAULT_ZOOM_LEVELS to maxZoomLevel, DEFAULT_FULL_EXTENT to maxExtent, and RESOLUTION_AT_ZOOM_LEVEL_0 to maxResolution. These values are no longer constants, but have (thanks to JavaScript object prototyping) sensible defaults. These defaults can now be overridden by passing a hash as the second argument of the Map constructor. Added tests to verify. git-svn-id: http://svn.openlayers.org/trunk/openlayers@56 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 24 ++++++++++++------------ tests/test_Map.html | 11 ++++++++++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 144939dc41..e568871a96 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -6,20 +6,19 @@ OpenLayers.Map = Class.create(); OpenLayers.Map.prototype = { + // Hash: base z-indexes for different classes of thing + Z_INDEX_BASE: { Layer: 100, Popup: 200, Control: 250 }, - // int zoom levels, used to draw zoom dragging control - DEFAULT_ZOOM_LEVELS: 16, + // int: zoom levels, used to draw zoom dragging control and limit zooming + maxZoomLevel: 16, // OpenLayers.Bounds - DEFAULT_FULL_EXTENT: new OpenLayers.Bounds(-90, -180, 90, 180), + maxExtent: new OpenLayers.Bounds(-90, -180, 90, 180), /* maxScale was determined empirically by finding the resolution of GMaps in degrees per pixel at zoom level 0. */ // float - RESOLUTION_AT_ZOOM_LEVEL_0: .3515625, // degrees per pixel - - // Hash: base z-indexes for different classes of thing - Z_INDEX_BASE: { Layer: 100, Popup: 200, Control: 250 }, + maxResolution: .3515625, // degrees per pixel // DOMElement: the div that our map lives in div: null, @@ -54,7 +53,9 @@ OpenLayers.Map.prototype = { /** * @param {DOMElement} div */ - initialize: function (div) { + initialize: function (div, options) { + Object.extend(this, options); + this.div = div; this.viewPortDiv = OpenLayers.Util.createDiv( @@ -182,11 +183,11 @@ OpenLayers.Map.prototype = { * @return {OpenLayers.Bounds} */ getFullExtent: function () { - return this.DEFAULT_FULL_EXTENT; + return this.maxExtent; }, getZoomLevels: function() { - return this.DEFAULT_ZOOM_LEVELS; + return this.maxZoomLevel; }, /** @@ -197,8 +198,7 @@ OpenLayers.Map.prototype = { getZoomForExtent: function (bounds) { var size = this.getSize(); var deg_per_pixel = bounds.width / size.w; - var zoom = Math.log( deg_per_pixel / this.RESOLUTION_AT_ZOOM_LEVEL_0) - / Math.log(2); + var zoom = Math.log(deg_per_pixel / this.maxResolution) / Math.log(2); return Math.floor(Math.max(zoom, 0)); }, diff --git a/tests/test_Map.html b/tests/test_Map.html index 2bd0995083..242c1ce17c 100644 --- a/tests/test_Map.html +++ b/tests/test_Map.html @@ -4,7 +4,7 @@