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
This commit is contained in:
Schuyler Erle
2006-05-16 19:27:22 +00:00
parent 58b202b359
commit 47bf4cdad8
2 changed files with 22 additions and 13 deletions

View File

@@ -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));
},

View File

@@ -4,7 +4,7 @@
<script type="text/javascript"><!--
var map;
function test_01_Map_constructor (t) {
t.plan( 9 );
t.plan( 12 );
map = new OpenLayers.Map($('map'));
t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map returns object" );
@@ -16,6 +16,9 @@
t.ok( map.layers instanceof Array, "map.layers is an Array" );
t.ok( map.controls instanceof Array, "map.controls is an Array" );
t.ok( map.events instanceof OpenLayers.Events, "map.events is an OpenLayers.Events" );
t.ok( map.maxExtent instanceof OpenLayers.Bounds, "map.maxExtent is an OpenLayers.Bounds" );
t.ok( map.maxZoomLevel > 0, "map.maxZoomLevel is set" );
t.ok( map.maxResolution > 0, "map.maxResolution is set" );
}
function test_02_Map_center(t) {
t.plan(4);
@@ -42,6 +45,12 @@
t.eq( parseInt(layer1.div.style.zIndex), map.Z_INDEX_BASE['Layer'],
"layer1 zIndex is set" );
}
function test_04_Map_options(t) {
t.plan(2);
map = new OpenLayers.Map($('map'), {maxZoomLevel: 5, maxResolution: 3.14159});
t.eq( map.maxZoomLevel, 5, "map.maxZoomLevel set correctly via options hash" );
t.eq( map.maxResolution, 3.14159, "map.maxResolution set correctly via options hash" );
}
function test_99_Map_destroy (t) {
t.plan( 2 );
map = new OpenLayers.Map($('map'));