Merge all changes from the naturaldocs sandbox. This brings all the work that

has been done in the NaturalDocs branch back to trunk. Thanks to everyone who
helped out in making this happen. (I could list people, but the list would
be long, and I'm already mentally on vacation.)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@3545 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-06-29 15:59:20 +00:00
parent f1c61fd0d6
commit 3948913bfc
107 changed files with 8658 additions and 4011 deletions
+354 -196
View File
@@ -4,11 +4,12 @@
/**
* @class
* Namespace: Util
*/
OpenLayers.Util = new Object();
/**
* Function: getElement
* This is the old $() from prototype
*/
OpenLayers.Util.getElement = function() {
@@ -34,7 +35,10 @@ if ($ == null) {
var $ = OpenLayers.Util.getElement;
}
/* from Prototype.js */
/**
* Function: extend
* From Prototype.js
*/
OpenLayers.Util.extend = function(destination, source) {
for (property in source) {
destination[property] = source[property];
@@ -43,14 +47,18 @@ OpenLayers.Util.extend = function(destination, source) {
};
/** Remove an object from an array. Iterates through the array
* to find the item, then removes it.
*
* @param {Object} item
*
* @returns A reference to the array
* @type Array
*/
/**
* Function: removeItem
* Remove an object from an array. Iterates through the array
* to find the item, then removes it.
*
* Parameters:
* array - {Array}
* item - {Object}
*
* Return
* {Array} A reference to the array
*/
OpenLayers.Util.removeItem = function(array, item) {
for(var i=0; i < array.length; i++) {
if(array[i] == item) {
@@ -62,15 +70,23 @@ OpenLayers.Util.removeItem = function(array, item) {
};
/**
* Function: clearArray
*/
OpenLayers.Util.clearArray = function(array) {
array.length = 0;
};
/** Seems to exist already in FF, but not in MOZ.
/**
* Function: indexOf
* Seems to exist already in FF, but not in MOZ.
*
* @param {Array} array
* @param {Object} obj
* Parameters:
* array - {Array}
* obj - {Object}
*
* Returns:
* {Integer} The index at, which the object was found in the array.
* If not found, returns -1.v
*/
OpenLayers.Util.indexOf = function(array, obj) {
@@ -83,13 +99,16 @@ OpenLayers.Util.indexOf = function(array, obj) {
/**
* @param {String} id
* @param {OpenLayers.Pixel} px
* @param {OpenLayers.Size} sz
* @param {String} position
* @param {String} border
* @param {String} overflow
* @param {float} opacity Fractional value (0.0 - 1.0)
* Function: modifyDOMElement
*
* Parameters:
* id - {String}
* px - {<OpenLayers.Pixel>}
* sz - {<OpenLayers.Size>}
* position - {String}
* border - {String}
* overflow - {String}
* opacity - {Float} Fractional value (0.0 - 1.0)
*/
OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position,
border, overflow, opacity) {
@@ -121,20 +140,23 @@ OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position,
};
/**
* zIndex is NOT set
*
* @param {String} id
* @param {OpenLayers.Pixel} px
* @param {OpenLayers.Size} sz
* @param {String} imgURL
* @param {String} position
* @param {String} border
* @param {String} overflow
* @param {float} opacity Fractional value (0.0 - 1.0)
*
* @returns A DOM Div created with the specified attributes.
* @type DOMElement
*/
* Function: createDiv
*
* Note: zIndex is NOT set
*
* Parameters:
* id - {String}
* px - {<OpenLayers.Pixel>}
* sz - {<OpenLayers.Size>}
* imgURL - {String}
* position - {String}
* border - {String}
* overflow - {String}
* opacity - {Float} Fractional value (0.0 - 1.0)
*
* Return:
* {DOMElement} A DOM Div created with the specified attributes.
*/
OpenLayers.Util.createDiv = function(id, px, sz, imgURL, position,
border, overflow, opacity) {
@@ -157,19 +179,22 @@ OpenLayers.Util.createDiv = function(id, px, sz, imgURL, position,
return dom;
};
/**
* @param {String} id
* @param {OpenLayers.Pixel} px
* @param {OpenLayers.Size} sz
* @param {String} imgURL
* @param {String} position
* @param {String} border
* @param {Boolean} delayDisplay
* @param {float} opacity Fractional value (0.0 - 1.0)
*
* @returns A DOM Image created with the specified attributes.
* @type DOMElement
*/
/**
* Function: createImage
*
* Parameters:
* id - {String}
* px - {<OpenLayers.Pixel>}
* sz - {<OpenLayers.Size>}
* imgURL - {String}
* position - {String}
* border - {String}
* delayDisplay - {Boolean}
* opacity - {Float} Fractional value (0.0 - 1.0)
*
* Return:
* {DOMElement} A DOM Image created with the specified attributes.
*/
OpenLayers.Util.createImage = function(id, px, sz, imgURL, position, border,
opacity, delayDisplay) {
@@ -207,22 +232,30 @@ OpenLayers.Util.createImage = function(id, px, sz, imgURL, position, border,
};
/**
* @deprecated -- Use OpenLayers.Util.modifyDOMElement() or
* OpenLayers.Util.modifyAlphaImageDiv()
* Function: setOpacity
* Deprecated.
* This function has been deprecated. Instead, please use
* OpenLayers.Util.modifyDOMElement()
* or
* OpenLayers.Util.modifyAlphaImageDiv()
*
* Set the opacity of a DOM Element
* Note that for this function to work in IE, elements must "have layout"
* according to:
* http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/haslayout.asp
* Note that for this function to work in IE, elements must "have layout"
* according to:
* http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/haslayout.asp
*
* @param {DOMElement} element Set the opacity on this DOM element
* @param {Float} opacity Opacity value (0.0 - 1.0)
* Parameters:
* element - {DOMElement} Set the opacity on this DOM element
* opacity - {Float} Opacity value (0.0 - 1.0)
*/
OpenLayers.Util.setOpacity = function(element, opacity) {
OpenLayers.Util.modifyDOMElement(element, null, null, null,
null, null, null, opacity);
}
/**
* Function: onImageLoad
*/
OpenLayers.Util.onImageLoad = function() {
// The complex check here is to solve issues described in #480.
// Every time a map view changes, it increments the 'viewRequestID'
@@ -245,8 +278,23 @@ OpenLayers.Util.onImageLoad = function() {
}
};
/**
* Property: onImageLoadErrorColor
* {String} The color tiles with load errors will turn.
* Default is "pink"
*/
OpenLayers.Util.onImageLoadErrorColor = "pink";
/**
* Property: onImageLoadErrorColor
* {Integer} How many times should we try to reload an image before giving up?
* Default is 0
*/
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 0;
/**
* Function: onImageLoadError
*/
OpenLayers.Util.onImageLoadError = function() {
this._attempts = (this._attempts) ? (this._attempts + 1) : 1;
if(this._attempts <= OpenLayers.IMAGE_RELOAD_ATTEMPTS) {
@@ -257,7 +305,12 @@ OpenLayers.Util.onImageLoadError = function() {
this.style.display = "";
};
/**
* Function: alphaHack
*
* Return:
* {Boolean}
*/
OpenLayers.Util.alphaHack = function() {
var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
@@ -278,16 +331,18 @@ OpenLayers.Util.alphaHack = function() {
}
/**
* @param {DOMElement} div Div containing Alpha-adjusted Image
* @param {String} id
* @param {OpenLayers.Pixel} px
* @param {OpenLayers.Size} sz
* @param {String} imgURL
* @param {String} position
* @param {String} border
* @param {String} sizing 'crop', 'scale', or 'image'. Default is "scale"
* @param {float} opacity Specified as fraction (0.4, etc)
*/
* Function: modifyAlphaImageDiv
*
* div - {DOMElement} Div containing Alpha-adjusted Image
* id - {String}
* px - {<OpenLayers.Pixel>}
* sz - {<OpenLayers.Size>}
* imgURL - {String}
* position - {String}
* border - {String}
* sizing {String} 'crop', 'scale', or 'image'. Default is "scale"
* opacity - {Float} Fractional value (0.0 - 1.0)
*/
OpenLayers.Util.modifyAlphaImageDiv = function(div, id, px, sz, imgURL,
position, border, sizing,
opacity) {
@@ -326,19 +381,21 @@ OpenLayers.Util.modifyAlphaImageDiv = function(div, id, px, sz, imgURL,
};
/**
* @param {String} id
* @param {OpenLayers.Pixel} px
* @param {OpenLayers.Size} sz
* @param {String} imgURL
* @param {String} position
* @param {String} border
* @param {String} sizing 'crop', 'scale', or 'image'. Default is "scale"
* @param {Boolean} delayDisplay
*
* @returns A DOM Div created with a DOM Image inside it. If the hack is
* needed for transparency in IE, it is added.
* @type DOMElement
*/
* Function: createAlphaImageDiv
*
* id - {String}
* px - {<OpenLayers.Pixel>}
* sz - {<OpenLayers.Size>}
* imgURL - {String}
* position - {String}
* border - {String}
* sizing {String} 'crop', 'scale', or 'image'. Default is "scale"
* delayDisplay{Boolean}
*
* Return:
* {DOMElement} A DOM Div created with a DOM Image inside it. If the hack is
* needed for transparency in IE, it is added.
*/
OpenLayers.Util.createAlphaImageDiv = function(id, px, sz, imgURL,
position, border, sizing,
opacity, delayDisplay) {
@@ -363,15 +420,18 @@ OpenLayers.Util.createAlphaImageDiv = function(id, px, sz, imgURL,
};
/** Creates a new hashtable and copies over all the keys from the
* passed-in object, but storing them under an uppercased
* version of the key at which they were stored.
*
* @param {Object} object
*
* @returns A new Object with all the same keys but uppercased
* @type Object
*/
/**
* Function: upperCaseObject
* Creates a new hashtable and copies over all the keys from the
* passed-in object, but storing them under an uppercased
* version of the key at which they were stored.
*
* Parameters:
* object - {Object}
*
* Returns:
* {Object} A new Object with all the same keys but uppercased
*/
OpenLayers.Util.upperCaseObject = function (object) {
var uObject = new Object();
for (var key in object) {
@@ -380,13 +440,16 @@ OpenLayers.Util.upperCaseObject = function (object) {
return uObject;
};
/** Takes a hashtable and copies any keys that don't exist from
* another hashtable, by analogy with OpenLayers.Util.extend() from
* Prototype.js.
*
* @param {Object} to
* @param {Object} from
*/
/**
* Function: applyDefaults
* Takes a hashtable and copies any keys that don't exist from
* another hashtable, by analogy with OpenLayers.Util.extend() from
* Prototype.js.
*
* Parameters:
* to - {Object}
* from - {Object}
*/
OpenLayers.Util.applyDefaults = function (to, from) {
for (var key in from) {
if (to[key] == null) {
@@ -396,16 +459,19 @@ OpenLayers.Util.applyDefaults = function (to, from) {
};
/**
* @param {Object} params
*
* @returns a concatenation of the properties of an object in
* http parameter notation.
* (ex. <i>"key1=value1&key2=value2&key3=value3"</i>)
* If a parameter is actually a list, that parameter will then
* be set to a comma-seperated list of values (foo,bar) instead
* of being URL escaped (foo%3Abar).
* @type String
*/
* Function: getParameterString
*
* Parameters:
* params - {Object}
*
* Return:
* {String} A concatenation of the properties of an object in
* http parameter notation.
* (ex. <i>"key1=value1&key2=value2&key3=value3"</i>)
* If a parameter is actually a list, that parameter will then
* be set to a comma-seperated list of values (foo,bar) instead
* of being URL escaped (foo%3Abar).
*/
OpenLayers.Util.getParameterString = function(params) {
paramsArray = new Array();
@@ -432,18 +498,27 @@ OpenLayers.Util.getParameterString = function(params) {
return paramsArray.join("&");
};
/**
* @returns The fully formatted image location string
* @type String
*/
/**
* Property: ImgPath
* {String} Default is ''.
*/
OpenLayers.ImgPath = '';
/**
* Function: getImagesLocation
*
* Return:
* {String} The fully formatted image location string
*/
OpenLayers.Util.getImagesLocation = function() {
return OpenLayers.ImgPath || (OpenLayers._getScriptLocation() + "img/");
};
/* Originally from Prototype */
/**
* Function: Try
*
*/
OpenLayers.Util.Try = function() {
var returnValue;
@@ -459,13 +534,18 @@ OpenLayers.Util.Try = function() {
}
/** These could/should be made namespace aware?
*
* @param {} p
* @param {str} tagName
*
* @return {Array}
*/
/**
* Function: getNodes
*
* These could/should be made namespace aware?
*
* Parameters:
* p - {}
* tagName - {String}
*
* Return:
* {Array}
*/
OpenLayers.Util.getNodes=function(p, tagName) {
var nodes = OpenLayers.Util.Try(
function () {
@@ -480,11 +560,15 @@ OpenLayers.Util.getNodes=function(p, tagName) {
};
/**
* @param {Array} nodes
* @param {str} tagName
*
* @return {Array}
*/
* Function: _getNodes
*
* Parameters:
* nodes - {Array}
* tagName - {String}
*
* Return:
* {Array}
*/
OpenLayers.Util._getNodes=function(nodes, tagName) {
var retArray = new Array();
for (var i=0;i<nodes.length;i++) {
@@ -499,12 +583,16 @@ OpenLayers.Util._getNodes=function(nodes, tagName) {
/**
* @param {} parent
* @param {str} item
* @param {int} index
*
* @return {str}
*/
* Function: getTagText
*
* Parameters:
* parent - {}
* item - {String}
* index - {Integer}
*
* Return:
* {String}
*/
OpenLayers.Util.getTagText = function (parent, item, index) {
var result = OpenLayers.Util.getNodes(parent, item);
if (result && (result.length > 0))
@@ -524,10 +612,13 @@ OpenLayers.Util.getTagText = function (parent, item, index) {
};
/**
* @param {XMLNode} node
* Function: getXmlNodeValue
*
* @returns The text value of the given node, without breaking in firefox or IE
* @type String
* Parameters:
* node - {XMLNode}
*
* Return:
* {String} The text value of the given node, without breaking in firefox or IE
*/
OpenLayers.Util.getXmlNodeValue = function(node) {
var val = null;
@@ -546,11 +637,15 @@ OpenLayers.Util.getXmlNodeValue = function(node) {
};
/**
* @param {Event} evt
* @param {HTMLDivElement} div
*
* @return {boolean}
*/
* Function: mouseLeft
*
* Parameters:
* evt - {Event}
* div - {HTMLDivElement}
*
* Return:
* {Boolean}
*/
OpenLayers.Util.mouseLeft = function (evt, div) {
// start with the element to which the mouse has moved
var target = (evt.relatedTarget) ? evt.relatedTarget : evt.toElement;
@@ -562,7 +657,27 @@ OpenLayers.Util.mouseLeft = function (evt, div) {
return (target != div);
};
/**
* Function: rad
*
* Parameters:
* x - {Float}
*
* Return:
* {Float}
*/
OpenLayers.Util.rad = function(x) {return x*Math.PI/180;};
/**
* Function: distVincenty
*
* Parameters:
* p1 - {Float}
* p2 - {Float}
*
* Return:
* {Float}
*/
OpenLayers.Util.distVincenty=function(p1, p2) {
var a = 6378137, b = 6356752.3142, f = 1/298.257223563;
var L = OpenLayers.Util.rad(p2.lon - p1.lon);
@@ -599,11 +714,14 @@ OpenLayers.Util.distVincenty=function(p1, p2) {
};
/**
* @param {String} url Optional url used to extract the query string.
* If null, query string is taken from page location.
* Function: getArgs
*
* @returns An object of key/value pairs from the query string.
* @type Object
* Parameters:
* url - {String} Optional url used to extract the query string.
* If null, query string is taken from page location.
*
* Return:
* {Object} An object of key/value pairs from the query string.
*/
OpenLayers.Util.getArgs = function(url) {
if(url == null) {
@@ -638,14 +756,22 @@ OpenLayers.Util.getArgs = function(url) {
return args;
}
/**
* Property: lastSeqID
* {Integer} The ever-incrementing count variable.
* Used for generating unique ids.
*/
OpenLayers.Util.lastSeqID = 0;
/**
* @param {String} prefix String to prefix random id. If null, default
* is "id_"
* Function: createUniqueID
*
* @returns A unique id string, built on the passed in prefix
* @type String
* Parameters:
* prefix {String} String to prefix random id.
* If null, default is "id_"
*
* Return:
* {String} A unique id string, built on the passed in prefix
*/
OpenLayers.Util.createUniqueID = function(prefix) {
if (prefix == null) {
@@ -655,10 +781,10 @@ OpenLayers.Util.createUniqueID = function(prefix) {
return prefix + OpenLayers.Util.lastSeqID;
};
/** Constant inches per unit
* -- borrowed from MapServer mapscale.c
*
* @type Object */
/**
* Constant: INCHES_PER_UNIT
* {Object} Constant inches per unit -- borrowed from MapServer mapscale.c
*/
OpenLayers.INCHES_PER_UNIT = {
'inches': 1.0,
'ft': 12.0,
@@ -670,18 +796,23 @@ OpenLayers.INCHES_PER_UNIT = {
OpenLayers.INCHES_PER_UNIT["in"]= OpenLayers.INCHES_PER_UNIT.inches;
OpenLayers.INCHES_PER_UNIT["degrees"] = OpenLayers.INCHES_PER_UNIT.dd;
/** A sensible default
* @type int */
/**
* Constant: DOTS_PER_INCH
* {Integer} 72 (A sensible default)
*/
OpenLayers.DOTS_PER_INCH = 72;
/**
* @param {float} scale
* Function: normalzeScale
*
* @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
* Parameters:
* scale {float}
*
* Return:
* {Float} 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
*/
OpenLayers.Util.normalizeScale = function (scale) {
var normScale = (scale > 1.0) ? (1.0 / scale)
@@ -690,13 +821,16 @@ OpenLayers.Util.normalizeScale = function (scale) {
};
/**
* @param {float} scale
* @param {String} units Index into OpenLayers.INCHES_PER_UNIT hashtable.
* Default is degrees
* Function: getResolutionFromScale
*
* @returns The corresponding resolution given passed-in scale and unit
* parameters.
* @type float
* Parameters:
* scale - {Float}
* units - {String} Index into OpenLayers.INCHES_PER_UNIT hashtable.
* Default is degrees
*
* Return:
* {Float} The corresponding resolution given passed-in scale and unit
* parameters.
*/
OpenLayers.Util.getResolutionFromScale = function (scale, units) {
@@ -712,13 +846,16 @@ OpenLayers.Util.getResolutionFromScale = function (scale, units) {
};
/**
* @param {float} resolution
* @param {String} units Index into OpenLayers.INCHES_PER_UNIT hashtable.
* Default is degrees
* Function: getScaleFromResolution
*
* @returns The corresponding scale given passed-in resolution and unit
* parameters.
* @type float
* Parameters:
* resolution - {Float}
* units - {String} Index into OpenLayers.INCHES_PER_UNIT hashtable.
* Default is degrees
*
* Return:
* {Float} The corresponding scale given passed-in resolution and unit
* parameters.
*/
OpenLayers.Util.getScaleFromResolution = function (resolution, units) {
@@ -731,18 +868,33 @@ OpenLayers.Util.getScaleFromResolution = function (resolution, units) {
return scale;
};
/** @deprecated Please use directly OpenLayers.Event.stop() passing 'true' as
* the 2nd argument (preventDefault)
/**
* Function: safeStopPropagation
* Deprecated.
*
* This function has been deprecated. Please use directly
* OpenLayers.Event.stop() passing 'true' as the 2nd
* argument (preventDefault)
*
* Safely stop the propagation of an event *without* preventing
* the default browser action from occurring.
*
* @param {Event} evt
* Parameter:
* evt - {Event}
*/
OpenLayers.Util.safeStopPropagation = function(evt) {
OpenLayers.Event.stop(evt, true);
};
/**
* Function: pagePositon
*
* Parameters:
* forElement - {DOMElement}
*
* Return:´
* {Array} two item array, L value then T value.
*/
OpenLayers.Util.pagePosition = function(forElement) {
var valueT = 0, valueL = 0;
@@ -767,7 +919,9 @@ OpenLayers.Util.pagePosition = function(forElement) {
};
/** Test two URLs for equivalence.
/**
* Function: isEquivalentUrl
* Test two URLs for equivalence.
*
* Setting 'ignoreCase' allows for case-independent comparison.
*
@@ -779,17 +933,16 @@ OpenLayers.Util.pagePosition = function(forElement) {
* - Pathname (for relative <-> absolute comparison)
* - Arguments (so they can be out of order)
*
*
* Parameters:
* url1 - {String}
* url2 - {String}
* options - {Object} Allows for customization of comparison:
* 'ignoreCase' - Default is True
* 'ignorePort80' - Default is True
* 'ignoreHash' - Default is True
*
* @param {String} url1
* @param {String} url2
* @param {Object} options allows for customization of comparison:
* 'ignoreCase' - Default is True
* 'ignorePort80' - Default is True
* 'ignoreHash' - Default is True
*
* @returns Whether or not the two URLs are equivalent
* @type Boolean
* Return:
* {Boolean} Whether or not the two URLs are equivalent
*/
OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) {
options = options || new Object();
@@ -851,14 +1004,15 @@ OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) {
};
/**
* @private
*
* @param {String} url
* @param {Object} options
* Function: createUrlObject
*
* @returns An object with separate url, a, port, host, and args parsed out
* and ready for comparison
* @type Object
* Parameters:
* url - {String}
* options - {Object}
*
* Return:
* {Object} An object with separate url, a, port, host, and args parsed out
* and ready for comparison
*/
OpenLayers.Util.createUrlObject = function(url, options) {
options = options || new Object();
@@ -961,10 +1115,13 @@ OpenLayers.Util.createUrlObject = function(url, options) {
};
/**
* @param {String} url
* Function: removeTail
*
* @returns The string with all queryString and Hash removed
* @type String
* Parameters:
* url - {String}
*
* Return:
* {String} The string with all queryString and Hash removed
*/
OpenLayers.Util.removeTail = function(url) {
var head = null;
@@ -983,8 +1140,11 @@ OpenLayers.Util.removeTail = function(url) {
/**
* @returns A string which specifies which is the current
* browser in which we are running.
* Function: getBrowserName
*
* Return:
* {String} A string which specifies which is the current
* browser in which we are running.
*
* Currently-supported browser detection and codes:
* * 'opera' -- Opera
@@ -995,8 +1155,6 @@ OpenLayers.Util.removeTail = function(url) {
*
* If we are unable to property identify the browser, we
* return an empty string.
*
* @type String
*/
OpenLayers.Util.getBrowserName = function() {
var browserName = "";