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:
@@ -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));
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user