- Removed unnecessary accessors from OpenLayers.Layer: getProjection(),
getMaxExtent(), getMaxResolution(), and getNumZoomLevels(). They were just wrapping around the properties. better to just access the property directly. Needed to update for these removals in many different files. - Improved initResolutions() functionality. It is now I believe both thorough and complete. The only exception is that we should maybe allow a way for the user to set up resolutions[] array using only minResolution and numZoomLevels instead of only maxResolution and numZoomLevels... but I'm not really sure anyone would ever really want to use that. And at any rate, I don't know the math for how to do it. I'm sure schuyler or Dr. 5 would. Oh. for a summary of how initResolutions works, see: http://trac.openlayers.org/wiki/SettingZoomLevels - Move getResolution(), initResolutions() out of HTTPRequest and into Layer. On thinking this through (and trying to write documentation), I realized that the real, true, GENERIC case for a layer will be using this awesome resolutions[] array that allows for setting number of zoom levels, default max resolutions, special scale arrays, etc. - Updated code for getZoomForExtent() to work with resolutions[] array, instead of using the the log 2 equation. - Move standard getZoomForExtent() and getExtent() out of Grid and into Layer. Like above, there is no reason for these methods to be found so far down in the food chain. They are part of the generic calculations for generic layers, so they belong in Layer. git-svn-id: http://svn.openlayers.org/trunk/openlayers@1379 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
112
lib/OpenLayers/Layer/FixedZoomLevels.js
Normal file
112
lib/OpenLayers/Layer/FixedZoomLevels.js
Normal file
@@ -0,0 +1,112 @@
|
||||
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
|
||||
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
|
||||
* text of the license. */
|
||||
|
||||
/**
|
||||
* Some Layers will already have established zoom levels (like google
|
||||
* or ve). Instead of trying to determine them and populate a resolutions[]
|
||||
* Array with those values, we will hijack the resolution functionality
|
||||
* here.
|
||||
*
|
||||
* When you subclass FixedZoomLevels:
|
||||
*
|
||||
* The initResolutions() call gets nullified, meaning no resolutions[] array
|
||||
* is set up. Which would be a big problem getResolution() in Layer, since
|
||||
* it merely takes map.zoom and indexes into resolutions[]... but....
|
||||
*
|
||||
* The getResolution() call is also overridden. Instead of using the
|
||||
* resolutions[] array, we simply calculate the current resolution based
|
||||
* on the current extent and the current map size. But how will we be able
|
||||
* to calculate the current extent without knowing the resolution...?
|
||||
*
|
||||
* The getExtent() function is also overridden. Instead of calculating extent
|
||||
* based on the center point and the current resolution, we instead
|
||||
* calculate the extent by getting the lonlats at the top-left and
|
||||
* bottom-right by using the getLonLatFromViewPortPx() translation function,
|
||||
* taken from the pixel locations (0,0) and the size of the map. But how
|
||||
* will we be able to do lonlat-px translation without resolution....?
|
||||
*
|
||||
* Whenever you implement a layer using OpenLayers.Layer.FixedZoomLevels,
|
||||
* it is your responsibility to provide the following three functions:
|
||||
*
|
||||
* - getLonLatFromViewPortPx()
|
||||
* - getViewPortPxFromLonLat()
|
||||
* - getZoomForExtent()
|
||||
*
|
||||
* ...those three functions should generally be provided by any reasonable
|
||||
* API that you might be working from.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
OpenLayers.Layer.FixedZoomLevels = Class.create();
|
||||
OpenLayers.Layer.FixedZoomLevels.prototype = {
|
||||
|
||||
/********************************************************/
|
||||
/* */
|
||||
/* Baselayer Functions */
|
||||
/* */
|
||||
/* The following functions must all be implemented */
|
||||
/* by all base layers */
|
||||
/* */
|
||||
/********************************************************/
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
initialize: function() {
|
||||
//this class is only just to add the following functions...
|
||||
// nothing to actually do here... but it is probably a good
|
||||
// idea to have layers that use these functions call this
|
||||
// inititalize() anyways, in case at some point we decide we
|
||||
// do want to put some functionality or state in here.
|
||||
},
|
||||
|
||||
initResolutions: function() {
|
||||
// resolutions are set automatically in the black-box. this is the
|
||||
// definition of a fixed-zoom-levels layer
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns Degrees per Pixel
|
||||
* @type float
|
||||
*/
|
||||
getResolution: function() {
|
||||
var viewSize = this.map.getSize();
|
||||
var extent = this.getExtent();
|
||||
return Math.max( extent.getWidth() / viewSize.w,
|
||||
extent.getHeight() / viewSize.h );
|
||||
},
|
||||
|
||||
/** Calculates using px-> lonlat translation functions on tl and br
|
||||
* corners of viewport
|
||||
*
|
||||
* @returns A Bounds object which represents the lon/lat bounds of the
|
||||
* current viewPort.
|
||||
* @type OpenLayers.Bounds
|
||||
*/
|
||||
getExtent: function () {
|
||||
var extent = null;
|
||||
|
||||
|
||||
var size = this.map.getSize();
|
||||
|
||||
var tlPx = new OpenLayers.Pixel(0,0);
|
||||
var tlLL = this.getLonLatFromViewPortPx(tlPx);
|
||||
|
||||
var brPx = new OpenLayers.Pixel(size.w, size.h);
|
||||
var brLL = this.getLonLatFromViewPortPx(brPx);
|
||||
|
||||
if ((tlLL != null) && (brLL != null)) {
|
||||
extent = new OpenLayers.Bounds(tlLL.lon,
|
||||
brLL.lat,
|
||||
brLL.lon,
|
||||
tlLL.lat);
|
||||
}
|
||||
|
||||
return extent;
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "FixedZoomLevels.js"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user