OpenLayers Base Types - OpenLayers

# OpenLayers Base Types

OpenLayers custom string, number and function functions are described here.

Summary

OpenLayers Base Types | OpenLayers custom string, number and function functions are described here.
OpenLayers.String | Contains convenience functions for string manipulation.
Functions and Properties |
startsWith | Test whether a string starts with another string.
contains | Test whether a string contains another string.
trim | Removes leading and trailing whitespace characters from a string.
camelize | Camel-case a hyphenated string.
format | Given a string with tokens in the form ${token}, return a string with tokens replaced with properties from the given context object.
tokenRegEx | Used to find tokens in a string.
numberRegEx | Used to test strings as numbers.
isNumeric | Determine whether a string contains only a numeric value.
numericIf | Converts a string that appears to be a numeric value into a number.
OpenLayers.Number | Contains convenience functions for manipulating numbers.
Properties |
decimalSeparator | Decimal separator to use when formatting numbers.
thousandsSeparator | Thousands separator to use when formatting numbers.
Functions |
limitSigDigs | Limit the number of significant digits on a float.
format | Formats a number for output.
zeroPad | Create a zero padded string optionally with a radix for casting numbers.
OpenLayers.Function | Contains convenience functions for function manipulation.
Functions |
bind | Bind a function to an object.
bindAsEventListener | Bind a function to an object, and configure it to receive the event object as first parameter when called.
False | A simple function to that just does “return false”.
True | A simple function to that just does “return true”.
Void | A reusable function that returns ``undefined``.
OpenLayers.Array | Contains convenience functions for array manipulation.
Functions |
filter | Filter an array.

## OpenLayers.String

Contains convenience functions for string manipulation.

Summary

Functions and Properties |
startsWith | Test whether a string starts with another string.
contains | Test whether a string contains another string.
trim | Removes leading and trailing whitespace characters from a string.
camelize | Camel-case a hyphenated string.
format | Given a string with tokens in the form ${token}, return a string with tokens replaced with properties from the given context object.
tokenRegEx | Used to find tokens in a string.
numberRegEx | Used to test strings as numbers.
isNumeric | Determine whether a string contains only a numeric value.
numericIf | Converts a string that appears to be a numeric value into a number.

### Functions and Properties

### startsWith

> startsWith: function( | str,
> | sub | )

Test whether a string starts with another string.

#### Parameters

str | {String} The string to test.
sub | {String} The substring to look for.

#### Returns

{Boolean} The first string starts with the second.

### contains

> contains: function( | str,
> | sub | )

Test whether a string contains another string.

#### Parameters

str | {String} The string to test.
sub | {String} The substring to look for.

#### Returns

{Boolean} The first string contains the second.

### trim

> trim: function( | str | )

Removes leading and trailing whitespace characters from a string.

#### Parameters

str | {String} The (potentially) space padded string. This string is not modified.

#### Returns

{String} A trimmed version of the string with all leading and trailing spaces removed.

### camelize

> camelize: function( | str | )

Camel-case a hyphenated string. Ex. “chicken-head” becomes “chickenHead”, and “-chicken-head” becomes “ChickenHead”.

#### Parameters

str | {String} The string to be camelized. The original is not modified.

#### Returns

{String} The string, camelized

### format

> format: function( | template,
> | context,
> | args | )

Given a string with tokens in the form ${token}, return a string with tokens replaced with properties from the given context object. Represent a literal “${“ by doubling it, e.g. “${${“.

#### Parameters

template | {String} A string with tokens to be replaced. A template has the form “literal ${token}” where the token will be replaced by the value of context[“token”].
context | {Object} An optional object with properties corresponding to the tokens in the format string. If no context is sent, the window object will be used.
args | {Array} Optional arguments to pass to any functions found in the context. If a context property is a function, the token will be replaced by the return from the function called with these arguments.

#### Returns

{String} A string with tokens replaced from the context object.

### tokenRegEx

Used to find tokens in a string. Examples: ${a}, ${a.b.c}, ${a-b}, ${5}

### numberRegEx

Used to test strings as numbers.

### isNumeric

> isNumeric: function( | value | )

Determine whether a string contains only a numeric value.

#### Examples

>     OpenLayers.String.isNumeric("6.02e23") // true
>     OpenLayers.String.isNumeric("12 dozen") // false
>     OpenLayers.String.isNumeric("4") // true
>     OpenLayers.String.isNumeric(" 4 ") // false

#### Returns

{Boolean} String contains only a number.

### numericIf

> numericIf: function( | value,
> | trimWhitespace | )

Converts a string that appears to be a numeric value into a number.

#### Parameters

value | {String}
trimWhitespace | {Boolean}

#### Returns

{Number|String} a Number if the passed value is a number, a String otherwise.

## OpenLayers.Number

Contains convenience functions for manipulating numbers.

Summary

Properties |
decimalSeparator | Decimal separator to use when formatting numbers.
thousandsSeparator | Thousands separator to use when formatting numbers.
Functions |
limitSigDigs | Limit the number of significant digits on a float.
format | Formats a number for output.
zeroPad | Create a zero padded string optionally with a radix for casting numbers.

### Properties

### decimalSeparator

Decimal separator to use when formatting numbers.

### thousandsSeparator

Thousands separator to use when formatting numbers.

### Functions

### limitSigDigs

> limitSigDigs: function( | num,
> | sig | )

Limit the number of significant digits on a float.

#### Parameters

num | {Float}
sig | {Integer}

#### Returns

{Float} The number, rounded to the specified number of significant digits.

### format

> format: function( | num,
> | dec,
> | tsep,
> | dsep | )

Formats a number for output.

#### Parameters

num | {Float}
dec | {Integer} Number of decimal places to round to. Defaults to 0. Set to null to leave decimal places unchanged.
tsep | {String} Thousands separator. Default is “,”.
dsep | {String} Decimal separator. Default is “.”.

#### Returns

{String} A string representing the formatted number.

### zeroPad

> zeroPad: function( | num,
> | len,
> | radix | )

Create a zero padded string optionally with a radix for casting numbers.

#### Parameters

num | {Number} The number to be zero padded.
len | {Number} The length of the string to be returned.
radix | {Number} An integer between 2 and 36 specifying the base to use for representing numeric values.

## OpenLayers.Function

Contains convenience functions for function manipulation.

Summary

Functions |
bind | Bind a function to an object.
bindAsEventListener | Bind a function to an object, and configure it to receive the event object as first parameter when called.
False | A simple function to that just does “return false”.
True | A simple function to that just does “return true”.
Void | A reusable function that returns ``undefined``.

### Functions

### bind

> bind: function( | func,
> | object | )

Bind a function to an object. Method to easily create closures with ‘this’ altered.

#### Parameters

func | {Function} Input function.
object | {Object} The object to bind to the input function (as this).

#### Returns

{Function} A closure with ‘this’ set to the passed in object.

### bindAsEventListener

> bindAsEventListener: function( | func,
> | object | )

Bind a function to an object, and configure it to receive the event object as first parameter when called.

#### Parameters

func | {Function} Input function to serve as an event listener.
object | {Object} A reference to this.

#### Returns

{Function}

### False

> False : function()

A simple function to that just does “return false”. We use this to avoid attaching anonymous functions to DOM event handlers, which causes “issues” on IE<8.

#### Usage

document.onclick = OpenLayers.Function.False;

#### Returns

{Boolean}

### True

> True : function()

A simple function to that just does “return true”. We use this to avoid attaching anonymous functions to DOM event handlers, which causes “issues” on IE<8.

#### Usage

document.onclick = OpenLayers.Function.True;

#### Returns

{Boolean}

### Void

> Void: function()

A reusable function that returns ``undefined``.

#### Returns

{undefined}

## OpenLayers.Array

Contains convenience functions for array manipulation.

Summary

Functions |
filter | Filter an array.

### Functions

### filter

> filter: function( | array,
> | callback,
> | caller | )

Filter an array. Provides the functionality of the Array.prototype.filter extension to the ECMA-262 standard. Where available, Array.prototype.filter will be used.

Based on well known example from http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/filter

#### Parameters

array | {Array} The array to be filtered. This array is not mutated. Elements added to this array by the callback will not be visited.
callback | {Function} A function that is called for each element in the array. If this function returns true, the element will be included in the return. The function will be called with three arguments: the element in the array, the index of that element, and the array itself. If the optional caller parameter is specified the callback will be called with this set to caller.
caller | {Object} Optional object to be set as this when the callback is called.

#### Returns

{Array} An array of elements from the passed in array for which the callback returns true.

> startsWith: function( | str,
> | sub | )

Test whether a string starts with another string.

> contains: function( | str,
> | sub | )

Test whether a string contains another string.

> trim: function( | str | )

Removes leading and trailing whitespace characters from a string.

> camelize: function( | str | )

Camel-case a hyphenated string.

> format: function( | template,
> | context,
> | args | )

Given a string with tokens in the form ${token}, return a string with tokens replaced with properties from the given context object.

> isNumeric: function( | value | )

Determine whether a string contains only a numeric value.

> numericIf: function( | value,
> | trimWhitespace | )

Converts a string that appears to be a numeric value into a number.

> limitSigDigs: function( | num,
> | sig | )

Limit the number of significant digits on a float.

> format: function( | num,
> | dec,
> | tsep,
> | dsep | )

Formats a number for output.

> zeroPad: function( | num,
> | len,
> | radix | )

Create a zero padded string optionally with a radix for casting numbers.

> bind: function( | func,
> | object | )

Bind a function to an object.

> bindAsEventListener: function( | func,
> | object | )

Bind a function to an object, and configure it to receive the event object as first parameter when called.

> False : function()

A simple function to that just does “return false”.

> True : function()

A simple function to that just does “return true”.

> Void: function()

A reusable function that returns ``undefined``.

> filter: function( | array,
> | callback,
> | caller | )

Filter an array.
Close