Commit scale-based methods back into trunk. Layers or Maps now support setting
a list of scales or resolutions in the options to the constructor, from which resolutions are calculated. Map now has a 'setScale' function which will allow you to zoom to as close to a given scale as possible. git-svn-id: http://svn.openlayers.org/trunk/openlayers@1171 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1113,32 +1113,58 @@ OpenLayers.Util.createUniqueID = function(prefix) {
|
||||
return prefix + Math.round(Math.random() * 10000);
|
||||
};
|
||||
|
||||
/** constant inches per unit */
|
||||
OpenLayers.INCHES_PER_UNIT = { // borrowed from MapServer mapscale.c
|
||||
/** Constant inches per unit
|
||||
* -- borrowed from MapServer mapscale.c
|
||||
*
|
||||
* @type Object */
|
||||
OpenLayers.INCHES_PER_UNIT = {
|
||||
'inches': 1.0,
|
||||
'in': 1.0,
|
||||
'ft': 12.0,
|
||||
'mi': 63360.0,
|
||||
'm': 39.3701,
|
||||
'km': 39370.1,
|
||||
'dd': 4374754,
|
||||
'degrees': 4374754
|
||||
};
|
||||
OpenLayers.INCHES_PER_UNIT["in"]= OpenLayers.INCHES_PER_UNIT.inches;
|
||||
OpenLayers.INCHES_PER_UNIT["degrees"] = OpenLayers.INCHES_PER_UNIT.dd;
|
||||
|
||||
/** sensible default */
|
||||
/** A sensible default
|
||||
* @type int */
|
||||
OpenLayers.DOTS_PER_INCH = 72;
|
||||
|
||||
/**
|
||||
* @param {float} scale
|
||||
*
|
||||
* @returns A normalized scale value, in 1 / X format.
|
||||
* This means that if a value less than one ( already 1/x) is passed
|
||||
* in, it just returns scale directly. Otherwise, it returns
|
||||
* 1 / scale
|
||||
* @type float
|
||||
*/
|
||||
OpenLayers.Util.normalizeScale = function (scale) {
|
||||
if (scale > 1.0)
|
||||
return 1.0 / scale;
|
||||
else
|
||||
return scale;
|
||||
var normScale = (scale > 1.0) ? (1.0 / scale)
|
||||
: scale;
|
||||
return normScale;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {float} scale
|
||||
* @param {String} units Index into OpenLayers.INCHES_PER_UNIT hashtable.
|
||||
* Default is degrees
|
||||
*
|
||||
* @returns The corresponding resolution given passed-in scale and unit
|
||||
* parameters.
|
||||
* @type float
|
||||
*/
|
||||
OpenLayers.Util.getResolutionFromScale = function (scale, units) {
|
||||
if (!units) units = "degrees";
|
||||
scale = OpenLayers.Util.normalizeScale(scale);
|
||||
return 1 / (scale * OpenLayers.INCHES_PER_UNIT[units]
|
||||
* OpenLayers.DOTS_PER_INCH);
|
||||
};
|
||||
|
||||
if (units == null) {
|
||||
units = "degrees";
|
||||
}
|
||||
|
||||
normScale = OpenLayers.Util.normalizeScale(scale);
|
||||
|
||||
var resolution = 1 / (normScale * OpenLayers.INCHES_PER_UNIT[units]
|
||||
* OpenLayers.DOTS_PER_INCH);
|
||||
return resolution;
|
||||
};
|
||||
Reference in New Issue
Block a user