Util

Various utility functions, used by Leaflet internally.

Functions

Function Returns Description
extend(<Object> dest, <Object> src?) Object Merges the properties of the src object (or multiple objects) into dest object and returns the latter. Has an L.extend shortcut.
create(<Object> proto, <Object> properties?) Object Compatibility polyfill for Object.create
bind(<Function> fn, ) Function Returns a new function bound to the arguments passed, like Function.prototype.bind. Has a L.bind() shortcut.
stamp(<Object> obj) Number Returns the unique ID of an object, assiging it one if it doesn't have it.
throttle(<Function> fn, <Number> time, <Object> context) Function Returns a function which executes function fn with the given scope context (so that the this keyword refers to context inside fn's code). The function fn will be called no more than one time per given amount of time. The arguments received by the bound function will be any arguments passed when binding the function, followed by any arguments passed when invoking the bound function. Has an L.bind shortcut.
wrapNum(<Number> num, <Number[]> range, <Boolean> includeMax?) Number Returns the number num modulo range in such a way so it lies within range[0] and range[1]. The returned value will be always smaller than range[1] unless includeMax is set to true.
falseFn() Function Returns a function which always returns false.
formatNum(<Number> num, <Number> digits?) Number Returns the number num rounded to digits decimals, or to 5 decimals by default.
trim(<String> str) String Compatibility polyfill for String.prototype.trim
splitWords(<String> str) String[] Trims and splits the string on whitespace and returns the array of parts.
setOptions(<Object> obj, <Object> options) Object Merges the given properties to the options of the obj object, returning the resulting options. See Class options. Has an L.setOptions shortcut.
getParamString(<Object> obj, <String> existingUrl?, <Boolean> uppercase?) String Converts an object into a parameter URL string, e.g. {a: "foo", b: "bar"} translates to '?a=foo&b=bar'. If existingUrl is set, the parameters will be appended at the end. If uppercase is true, the parameter names will be uppercased (e.g. '?A=foo&B=bar')
template(<String> str, <Object> data) String Simple templating facility, accepts a template string of the form 'Hello {a}, {b}' and a data object like {a: 'foo', b: 'bar'}, returns evaluated string ('Hello foo, bar'). You can also specify functions instead of strings for data values — they will be evaluated passing data as an argument.
isArray(obj) Boolean Compatibility polyfill for Array.isArray
indexOf(<Array> array, <Object> el) Number Compatibility polyfill for Array.prototype.indexOf
requestAnimFrame(<Function> fn, <Object> context?, <Boolean> immediate?) Number Schedules fn to be executed when the browser repaints. fn is bound to context if given. When immediate is set, fn is called immediately if the browser doesn't have native support for window.requestAnimationFrame, otherwise it's delayed. Returns a request ID that can be used to cancel the request.
cancelAnimFrame(<Number> id) undefined Cancels a previous requestAnimFrame. See also window.cancelAnimationFrame.

Properties

Property Type Description
lastId Number Last unique ID used by stamp()
emptyImageUrl String Data URI string containing a base64-encoded empty GIF image. Used as a hack to free memory from unused images on WebKit-powered mobile devices (by setting image src to this string).
v1.1.0
Props Wrld.Prop
Themes Wrld.themes
Heatmaps Wrld.Heatmap
Events Event objects
Services (Optional) WrldPoiApi