2 * L.Util is a namespace for various utility functions.
6 extend: function(/*Object*/ dest
) /*-> Object*/ { // merge src properties into dest
7 var sources
= Array
.prototype.slice
.call(arguments
, 1);
8 for (var j
= 0, len
= sources
.length
, src
; j
< len
; j
++) {
9 src
= sources
[j
] || {};
11 if (src
.hasOwnProperty(i
)) {
19 bind: function(/*Function*/ fn
, /*Object*/ obj
) /*-> Object*/ {
21 return fn
.apply(obj
, arguments
);
26 var lastId
= 0, key
= '_leaflet_id';
27 return function(/*Object*/ obj
) {
28 obj
[key
] = obj
[key
] || ++lastId
;
33 requestAnimFrame
: (function() {
34 function timeoutDefer(callback
) {
35 window
.setTimeout(callback
, 1000 / 60);
38 var requestFn
= window
.requestAnimationFrame
||
39 window
.webkitRequestAnimationFrame
||
40 window
.mozRequestAnimationFrame
||
41 window
.oRequestAnimationFrame
||
42 window
.msRequestAnimationFrame
||
45 return function(callback
, context
, immediate
) {
46 callback
= context
? L
.Util
.bind(callback
, context
) : context
;
47 if (immediate
&& requestFn
=== timeoutDefer
) {
55 limitExecByInterval: function(fn
, time
, context
) {
56 var lock
, execOnUnlock
, args
;
60 args
.callee
.apply(context
, args
);
68 setTimeout(exec
, time
);
69 fn
.apply(context
, args
);
76 falseFn: function() { return false; },
78 formatNum: function(num
, digits
) {
79 var pow
= Math
.pow(10, digits
|| 5);
80 return Math
.round(num
* pow
) / pow
;
83 setOptions: function(obj
, options
) {
84 obj
.options
= L
.Util
.extend({}, obj
.options
, options
);
87 getParamString: function(obj
) {
90 if (obj
.hasOwnProperty(i
)) {
91 params
.push(i
+ '=' + obj
[i
]);
94 return '?' + params
.join('&');