move baselayer functions down and separated from private layer functions
git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1284 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -320,67 +320,6 @@ OpenLayers.Layer.Grid.prototype =
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/********************************************************/
|
|
||||||
/* */
|
|
||||||
/* Baselayer Functions */
|
|
||||||
/* */
|
|
||||||
/********************************************************/
|
|
||||||
|
|
||||||
/** Calculates based on resolution, center, and mapsize
|
|
||||||
*
|
|
||||||
* @returns A Bounds object which represents the lon/lat bounds of the
|
|
||||||
* current viewPort.
|
|
||||||
* @type OpenLayers.Bounds
|
|
||||||
*/
|
|
||||||
getExtent: function () {
|
|
||||||
var extent = null;
|
|
||||||
|
|
||||||
var center = this.map.getCenter();
|
|
||||||
if (center != null) {
|
|
||||||
|
|
||||||
var res = this.map.getResolution();
|
|
||||||
var size = this.map.getSize();
|
|
||||||
var w_deg = size.w * res;
|
|
||||||
var h_deg = size.h * res;
|
|
||||||
|
|
||||||
extent = new OpenLayers.Bounds(center.lon - w_deg / 2,
|
|
||||||
center.lat - h_deg / 2,
|
|
||||||
center.lon + w_deg / 2,
|
|
||||||
center.lat + h_deg / 2);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return extent;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {OpenLayers.Bounds} bounds
|
|
||||||
*
|
|
||||||
* @return {int}
|
|
||||||
*/
|
|
||||||
getZoomForExtent: function (bounds) {
|
|
||||||
|
|
||||||
var maxRes = this.map.getMaxResolution();
|
|
||||||
var viewSize = this.map.getSize();
|
|
||||||
|
|
||||||
var width = bounds.getWidth();
|
|
||||||
var height = bounds.getHeight();
|
|
||||||
|
|
||||||
var degPerPixel = (width > height) ? width / viewSize.w
|
|
||||||
: height / viewSize.h;
|
|
||||||
|
|
||||||
var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) );
|
|
||||||
|
|
||||||
var maxZoomLevel = this.map.getMaxZoomLevel();
|
|
||||||
var minZoomLevel = this.map.getMinZoomLevel();
|
|
||||||
|
|
||||||
//make sure zoom is within bounds
|
|
||||||
zoom = Math.min( Math.max(zoom, minZoomLevel),
|
|
||||||
maxZoomLevel );
|
|
||||||
|
|
||||||
return zoom;
|
|
||||||
},
|
|
||||||
|
|
||||||
/** go through and remove all tiles from the grid, calling
|
/** go through and remove all tiles from the grid, calling
|
||||||
* destroy() on each of them to kill circular references
|
* destroy() on each of them to kill circular references
|
||||||
*
|
*
|
||||||
@@ -462,6 +401,68 @@ OpenLayers.Layer.Grid.prototype =
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/********************************************************/
|
||||||
|
/* */
|
||||||
|
/* Baselayer Functions */
|
||||||
|
/* */
|
||||||
|
/********************************************************/
|
||||||
|
|
||||||
|
/** Calculates based on resolution, center, and mapsize
|
||||||
|
*
|
||||||
|
* @returns A Bounds object which represents the lon/lat bounds of the
|
||||||
|
* current viewPort.
|
||||||
|
* @type OpenLayers.Bounds
|
||||||
|
*/
|
||||||
|
getExtent: function () {
|
||||||
|
var extent = null;
|
||||||
|
|
||||||
|
var center = this.map.getCenter();
|
||||||
|
if (center != null) {
|
||||||
|
|
||||||
|
var res = this.map.getResolution();
|
||||||
|
var size = this.map.getSize();
|
||||||
|
var w_deg = size.w * res;
|
||||||
|
var h_deg = size.h * res;
|
||||||
|
|
||||||
|
extent = new OpenLayers.Bounds(center.lon - w_deg / 2,
|
||||||
|
center.lat - h_deg / 2,
|
||||||
|
center.lon + w_deg / 2,
|
||||||
|
center.lat + h_deg / 2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return extent;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OpenLayers.Bounds} bounds
|
||||||
|
*
|
||||||
|
* @return {int}
|
||||||
|
*/
|
||||||
|
getZoomForExtent: function (bounds) {
|
||||||
|
|
||||||
|
var maxRes = this.map.getMaxResolution();
|
||||||
|
var viewSize = this.map.getSize();
|
||||||
|
|
||||||
|
var width = bounds.getWidth();
|
||||||
|
var height = bounds.getHeight();
|
||||||
|
|
||||||
|
var degPerPixel = (width > height) ? width / viewSize.w
|
||||||
|
: height / viewSize.h;
|
||||||
|
|
||||||
|
var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) );
|
||||||
|
|
||||||
|
var maxZoomLevel = this.map.getMaxZoomLevel();
|
||||||
|
var minZoomLevel = this.map.getMinZoomLevel();
|
||||||
|
|
||||||
|
//make sure zoom is within bounds
|
||||||
|
zoom = Math.min( Math.max(zoom, minZoomLevel),
|
||||||
|
maxZoomLevel );
|
||||||
|
|
||||||
|
return zoom;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/** @final @type String */
|
/** @final @type String */
|
||||||
CLASS_NAME: "OpenLayers.Layer.Grid"
|
CLASS_NAME: "OpenLayers.Layer.Grid"
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user