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 |
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.
Properties |
OpenLayers. String. numberRegEx | Used to test strings as numbers.
Functions |
OpenLayers. String. isNumeric | Determine whether a string contains only a numeric value.
String. startsWith | Deprecated.
String. contains | Deprecated.
String.trim | Deprecated.
String. camelize | Deprecated.
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.
Number. limitSigDigs | Deprecated.
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.
Function.bind | Deprecated.
Function. bindAsEventListener | Deprecated.
OpenLayers. Array | Contains convenience functions for array manipulation.
Functions |
filter | Filter an array.

## OpenLayers. String

Contains convenience functions for string manipulation.

Summary

Functions |
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.
Properties |
OpenLayers. String. numberRegEx | Used to test strings as numbers.
Functions |
OpenLayers. String. isNumeric | Determine whether a string contains only a numeric value.
String. startsWith | Deprecated.
String. contains | Deprecated.
String.trim | Deprecated.
String. camelize | Deprecated.

### Functions

### startsWith

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

Test whether a string starts with another string.

#### Parameters

str | {String} The string to test.
sub | {Sring} 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.

### Properties

### OpenLayers. String. numberRegEx

Used to test strings as numbers.

### Functions

### OpenLayers. String. isNumeric

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.

### String. startsWith

Deprecated. Whether or not a string starts with another string.

#### Parameters

sStart | {Sring} The string we’re testing for.

#### Returns

{Boolean} Whether or not this string starts with the string passed in.

### String. contains

Deprecated. Whether or not a string contains another string.

#### Parameters

str | {String} The string that we’re testing for.

#### Returns

{Boolean} Whether or not this string contains with the string passed in.

### String.trim

Deprecated. Removes leading and trailing whitespace characters from a string.

#### Returns

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

### String. camelize

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

#### Returns

{String} The string, camelized

## 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.
Number. limitSigDigs | Deprecated.

### 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.

### Number. limitSigDigs

Deprecated. Limit the number of significant digits on an integer. Does not work with floats!

#### Parameters

sig | {Integer}

#### Returns

{Integer} The number, rounded to the specified number of significant digits. If null, 0, or negative value passed in, returns 0

## 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.
Function.bind | Deprecated.
Function. bindAsEventListener | Deprecated.

### 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}

### Function.bind

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

#### Parameters

object | {Object} the this parameter

#### Returns

{Function} A closure with ‘this’ altered to the first argument.

### Function. bindAsEventListener

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

#### Parameters

object | {Object} A reference to this.

#### Returns

{Function}

## 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- /docs- /Core_JavaScript_1.5_Reference: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.

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

Limit the number of significant digits on a float.

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

Formats a number for output.

> 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.

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

Filter an array.
Close