Util | |||
Functions and Properties | |||
getElement | This is the old $() from prototype | ||
isElement | A cross-browser implementation of “e instanceof Element”. | ||
isArray | Tests that the provided object is an array. | ||
removeItem | Remove an object from an array. | ||
indexOf | Seems to exist already in FF, but not in MOZ. | ||
modifyDOMElement | Modifies many properties of a DOM element all at once. | ||
createDiv | Creates a new div and optionally set some standard attributes. | ||
createImage | Creates an img element with specific attribute values. | ||
IMAGE_RELOAD_ATTEMPTS | {Integer} How many times should we try to reload an image before giving up? | ||
alphaHackNeeded | {Boolean} true if the png alpha hack is necessary and possible, false otherwise. | ||
alphaHack | Checks whether it’s necessary (and possible) to use the png alpha hack which allows alpha transparency for png images under Internet Explorer. | ||
modifyAlphaImageDiv | |||
createAlphaImageDiv | |||
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. | ||
applyDefaults | Takes an object and copies any properties that don’t exist from another properties, by analogy with OpenLayers.Util.extend() from Prototype.js. | ||
getParameterString | |||
urlAppend | Appends a parameter string to a url. | ||
getImagesLocation | {String} The fully formatted image location string | ||
getImageLocation | {String} The fully formatted location string for a specified image | ||
Try | Execute functions until one of them doesn’t throw an error. | ||
getXmlNodeValue | |||
mouseLeft | |||
precision | {Number} The number of significant digits to retain to avoid floating point precision errors. | ||
toFloat | Convenience method to cast an object to a Number, rounded to the desired floating point precision. | ||
rad | |||
deg | |||
VincentyConstants | {Object} Constants for Vincenty functions. | ||
getParameters | Parse the parameters from a URL or from the current page itself into a JavaScript Object. | ||
lastSeqID | {Integer} The ever-incrementing count variable. | ||
createUniqueID | Create a unique identifier for this session. | ||
Constants | |||
INCHES_PER_UNIT | {Object} Constant inches per unit -- borrowed from MapServer mapscale.c derivation of nautical miles from http://en.wikipedia.org/wiki/Nautical_mile Includes the full set of units supported by CS-MAP (http://trac.osgeo.org/csmap/) and PROJ.4 (http://trac.osgeo.org/proj/) The hardcoded table is maintain in a CS-MAP source code module named CSdataU.c The hardcoded table of PROJ.4 units are in pj_units.c. | ||
DOTS_PER_INCH | {Integer} 72 (A sensible default) | ||
Functions | |||
normalizeScale | |||
getResolutionFromScale | |||
getScaleFromResolution | |||
pagePosition | Calculates the position of an element on the page | getViewportElement | Returns die viewport element of the document. |
isEquivalentUrl | Test two URLs for equivalence. | ||
createUrlObject | |||
removeTail | Takes a url and removes everything after the ? | ||
Constants | |||
IS_GECKO | {Boolean} True if the userAgent reports the browser to use the Gecko engine | ||
CANVAS_SUPPORTED | {Boolean} True if canvas 2d is supported. | ||
BROWSER_NAME | {String} A substring of the navigator.userAgent property. | ||
Functions | |||
getBrowserName | {String} A string which specifies which is the current browser in which we are running. | ||
getRenderedDimensions | Renders the contentHTML offscreen to determine actual dimensions for popup sizing. |
OpenLayers.Util.modifyDOMElement = function( element, id, px, sz, position, border, overflow, opacity )
Modifies many properties of a DOM element all at once. Passing in null to an individual parameter will avoid setting the attribute.
element | {DOMElement} DOM element to modify. |
id | {String} The element id attribute to set. |
px | {<OpenLayers.Pixel>|Object} The element left and top position, OpenLayers.Pixel or an object with a ‘x’ and ‘y’ properties. |
sz | {<OpenLayers.Size>|Object} The element width and height, OpenLayers.Size or an object with a ‘w’ and ‘h’ properties. |
position | {String} The position attribute. eg: absolute, relative, etc. |
border | {String} The style.border attribute. eg: solid black 2px |
overflow | {String} The style.overview attribute. |
opacity | {Float} Fractional value (0.0 - 1.0) |
OpenLayers.Util.createDiv = function( id, px, sz, imgURL, position, border, overflow, opacity )
Creates a new div and optionally set some standard attributes. Null may be passed to each parameter if you do not wish to set a particular attribute. Note - zIndex is NOT set on the resulting div.
id | {String} An identifier for this element. If no id is passed an identifier will be created automatically. |
px | {<OpenLayers.Pixel>|Object} The element left and top position, OpenLayers.Pixel or an object with a ‘x’ and ‘y’ properties. |
sz | {<OpenLayers.Size>|Object} The element width and height, OpenLayers.Size or an object with a ‘w’ and ‘h’ properties. |
imgURL | {String} A url pointing to an image to use as a background image. |
position | {String} The style.position value. eg: absolute, relative etc. |
border | {String} The the style.border value. eg: 2px solid black |
overflow | {String} The style.overflow value. Eg. hidden |
opacity | {Float} Fractional value (0.0 - 1.0) |
{DOMElement} A DOM Div created with the specified attributes.
OpenLayers.Util.createImage = function( id, px, sz, imgURL, position, border, opacity, delayDisplay )
Creates an img element with specific attribute values.
id | {String} The id field for the img. If none assigned one will be automatically generated. |
px | {<OpenLayers.Pixel>|Object} The element left and top position, OpenLayers.Pixel or an object with a ‘x’ and ‘y’ properties. |
sz | {<OpenLayers.Size>|Object} The element width and height, OpenLayers.Size or an object with a ‘w’ and ‘h’ properties. |
imgURL | {String} The url to use as the image source. |
position | {String} The style.position value. |
border | {String} The border to place around the image. |
opacity | {Float} Fractional value (0.0 - 1.0) |
delayDisplay | {Boolean} If true waits until the image has been loaded. |
{DOMElement} A DOM Image created with the specified attributes.
OpenLayers.Util.modifyAlphaImageDiv = function( div, id, px, sz, imgURL, position, border, sizing, opacity )
div | {DOMElement} Div containing Alpha-adjusted Image |
id | {String} |
px | {<OpenLayers.Pixel>|Object} OpenLayers.Pixel or an object with a ‘x’ and ‘y’ properties. |
sz | {<OpenLayers.Size>|Object} OpenLayers.Size or an object with a ‘w’ and ‘h’ properties. |
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.createAlphaImageDiv = function( id, px, sz, imgURL, position, border, sizing, opacity, delayDisplay )
id | {String} |
px | {<OpenLayers.Pixel>|Object} OpenLayers.Pixel or an object with a ‘x’ and ‘y’ properties. |
sz | {<OpenLayers.Size>|Object} OpenLayers.Size or an object with a ‘w’ and ‘h’ properties. |
imgURL | {String} |
position | {String} |
border | {String} |
sizing | {String} ‘crop’, ‘scale’, or ‘image’. Default is “scale” |
opacity | {Float} Fractional value (0.0 - 1.0) |
delayDisplay | {Boolean} If true waits until the image has been loaded. |
{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.upperCaseObject = function ( object )
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.
object | {Object} |
{Object} A new Object with all the same keys but uppercased
OpenLayers.Util.applyDefaults = function ( to, from )
Takes an object and copies any properties that don’t exist from another properties, by analogy with OpenLayers.Util.extend() from Prototype.js.
to | {Object} The destination object. |
from | {Object} The source object. Any properties of this object that are undefined in the to object will be set on the to object. |
{Object} A reference to the to object. Note that the to argument is modified in place and returned by this function.
OpenLayers.Util.getParameterString = function( params )
params | {Object} |
{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.urlAppend = function( url, paramStr )
Appends a parameter string to a url. This function includes the logic for using the appropriate character (none, & or ?) to append to the url before appending the param string.
url | {String} The url to append to |
paramStr | {String} The param string to append |
{String} The new url
OpenLayers.Util.Try = function()
Execute functions until one of them doesn’t throw an error. Capitalized because “try” is a reserved word in JavaScript. Taken directly from OpenLayers.Util.Try()
[*] | {Function} Any number of parameters may be passed to Try() It will attempt to execute each of them until one of them successfully executes. If none executes successfully, returns null. |
{*} The value returned by the first successfully executed function.
{Number} The number of significant digits to retain to avoid floating point precision errors.
We use 14 as a “safe” default because, although IEEE 754 double floats (standard on most modern operating systems) support up to about 16 significant digits, 14 significant digits are sufficient to represent sub-millimeter accuracy in any coordinate system that anyone is likely to use with OpenLayers.
If DEFAULT_PRECISION is set to 0, the original non-truncating behavior of OpenLayers <2.8 is preserved. Be aware that this will cause problems with certain projections, e.g. spherical Mercator.
OpenLayers.Util.toFloat = function ( number, precision )
Convenience method to cast an object to a Number, rounded to the desired floating point precision.
number | {Number} The number to cast and round. |
precision | {Number} An integer suitable for use with Number.toPrecision(). Defaults to OpenLayers.Util.DEFAULT_PRECISION. If set to 0, no rounding is performed. |
{Number} The cast, rounded number.
OpenLayers.Util.getParameters = function( url )
Parse the parameters from a URL or from the current page itself into a JavaScript Object. Note that parameter values with commas are separated out into an Array.
url | {String} Optional url used to extract the query string. If url is null or is not supplied, query string is taken from the page location. |
{Object} An object of key/value pairs from the query string.
OpenLayers.Util.createUniqueID = function( prefix )
Create a unique identifier for this session. Each time this function is called, a counter is incremented. The return will be the optional prefix (defaults to “id_”) appended with the counter value.
prefix | {String} Optional string to prefix unique id. Default is “id_”. |
{String} A unique id string, built on the passed in prefix.
{Object} Constant inches per unit -- borrowed from MapServer mapscale.c derivation of nautical miles from http://en.wikipedia.org/wiki/Nautical_mile Includes the full set of units supported by CS-MAP (http://trac.osgeo.org/csmap/) and PROJ.4 (http://trac.osgeo.org/proj/) The hardcoded table is maintain in a CS-MAP source code module named CSdataU.c The hardcoded table of PROJ.4 units are in pj_units.c.
OpenLayers.Util.getResolutionFromScale = function ( scale, units )
scale | {Float} |
units | {String} Index into OpenLayers.INCHES_PER_UNIT hashtable. Default is degrees |
{Float} The corresponding resolution given passed-in scale and unit parameters. If the given scale is falsey, the returned resolution will be undefined.
OpenLayers.Util.pagePosition = function( forElement )
Calculates the position of an element on the page
OpenLayers.Util.getViewportElement = function()
Returns die viewport element of the document. The viewport element is usually document.documentElement, except in IE,where it is either document.body or document.documentElement, depending on the document’s compatibility mode
OpenLayers.Util.isEquivalentUrl = function( url1, url2, options )
Test two URLs for equivalence.
Setting ‘ignoreCase’ allows for case-independent comparison.
url1 | {String} |
url2 | {String} |
options | {Object} Allows for customization of comparison: |
’ignoreCase’ | Default is True |
’ignorePort80’ | Default is True |
’ignoreHash’ | Default is True |
{Boolean} Whether or not the two URLs are equivalent
OpenLayers.Util.createUrlObject = function( url, options )
url | {String} |
options | {Object} A hash of options. |
ignoreCase | {Boolean} lowercase url, |
ignorePort80 | {Boolean} don’t include explicit port if port is 80, |
ignoreHash | {Boolean} Don’t include part of url after the hash (#). |
{Object} An object with separate url, a, port, host, and args parsed out and ready for comparison
OpenLayers.Util.getBrowserName = function()
{String} A string which specifies which is the current browser in which we are running.
If we are unable to property identify the browser, we return an empty string.
OpenLayers.Util.getRenderedDimensions = function( contentHTML, size, options )
Renders the contentHTML offscreen to determine actual dimensions for popup sizing. As we need layout to determine dimensions the content is rendered -9999px to the left and absolute to ensure the scrollbars do not flicker
contentHTML size - {OpenLayers.Size} If either the ‘w’ or ‘h’ properties is specified, we fix that dimension of the div to be measured. This is useful in the case where we have a limit in one dimension and must therefore meaure the flow in the other dimension. options - {Object}
displayClass | {String} Optional parameter. A CSS class name(s) string to provide the CSS context of the rendered content. |
containerElement | {DOMElement} Optional parameter. Insert the HTML to this node instead of the body root when calculating dimensions. |
This is the old $() from prototype
OpenLayers.Util.getElement = function()
A cross-browser implementation of “e instanceof Element”.
OpenLayers.Util.isElement = function( o )
Tests that the provided object is an array.
OpenLayers.Util.isArray = function( a )
Remove an object from an array.
OpenLayers.Util.removeItem = function( array, item )
Seems to exist already in FF, but not in MOZ.
OpenLayers.Util.indexOf = function( array, obj )
Modifies many properties of a DOM element all at once.
OpenLayers.Util.modifyDOMElement = function( element, id, px, sz, position, border, overflow, opacity )
Creates a new div and optionally set some standard attributes.
OpenLayers.Util.createDiv = function( id, px, sz, imgURL, position, border, overflow, opacity )
Creates an img element with specific attribute values.
OpenLayers.Util.createImage = function( id, px, sz, imgURL, position, border, opacity, delayDisplay )
Checks whether it’s necessary (and possible) to use the png alpha hack which allows alpha transparency for png images under Internet Explorer.
OpenLayers.Util.alphaHack = function()
OpenLayers.Util.modifyAlphaImageDiv = function( div, id, px, sz, imgURL, position, border, sizing, opacity )
OpenLayers.Util.createAlphaImageDiv = function( id, px, sz, imgURL, position, border, sizing, opacity, delayDisplay )
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.
OpenLayers.Util.upperCaseObject = function ( object )
Takes an object and copies any properties that don’t exist from another properties, by analogy with OpenLayers.Util.extend() from Prototype.js.
OpenLayers.Util.applyDefaults = function ( to, from )
OpenLayers.Util.getParameterString = function( params )
Appends a parameter string to a url.
OpenLayers.Util.urlAppend = function( url, paramStr )
{String} The fully formatted image location string
OpenLayers.Util.getImagesLocation = function()
{String} The fully formatted location string for a specified image
OpenLayers.Util.getImageLocation = function( image )
Execute functions until one of them doesn’t throw an error.
OpenLayers.Util.Try = function()
OpenLayers.Util.getXmlNodeValue = function( node )
OpenLayers.Util.mouseLeft = function ( evt, div )
Convenience method to cast an object to a Number, rounded to the desired floating point precision.
OpenLayers.Util.toFloat = function ( number, precision )
OpenLayers.Util.rad = function( x )
OpenLayers.Util.deg = function( x )
Parse the parameters from a URL or from the current page itself into a JavaScript Object.
OpenLayers.Util.getParameters = function( url )
Create a unique identifier for this session.
OpenLayers.Util.createUniqueID = function( prefix )
OpenLayers.Util.normalizeScale = function ( scale )
OpenLayers.Util.getResolutionFromScale = function ( scale, units )
OpenLayers.Util.getScaleFromResolution = function ( resolution, units )
Calculates the position of an element on the page
OpenLayers.Util.pagePosition = function( forElement )
Returns die viewport element of the document.
OpenLayers.Util.getViewportElement = function()
Test two URLs for equivalence.
OpenLayers.Util.isEquivalentUrl = function( url1, url2, options )
OpenLayers.Util.createUrlObject = function( url, options )
Takes a url and removes everything after the ?
OpenLayers.Util.removeTail = function( url )
{String} A string which specifies which is the current browser in which we are running.
OpenLayers.Util.getBrowserName = function()
Renders the contentHTML offscreen to determine actual dimensions for popup sizing.
OpenLayers.Util.getRenderedDimensions = function( contentHTML, size, options )