Utility
DG.Browser
A namespace with static properties for browser/feature detection.
if (DG.Browser.ie6) {
alert('Upgrade your browser, dude!');
}
Properties
Property | Type | Description |
---|---|---|
ie |
Boolean |
true for all Internet Explorer versions (not Edge). |
ielt9 |
Boolean |
true for Internet Explorer versions less than 9. |
edge |
Boolean |
true for the Edge web browser. |
webkit |
Boolean |
true for webkit-based browsers like Chrome and Safari (including mobile versions). |
gecko |
Boolean |
true for gecko-based browsers like Firefox. |
android |
Boolean |
true for any browser running on an Android platform. |
android23 |
Boolean |
true for browsers running on Android 2 or Android 3. |
chrome |
Boolean |
true for the Chrome browser. |
safari |
Boolean |
true for the Safari browser. |
ie3d |
Boolean |
true for all Internet Explorer versions supporting CSS transforms. |
webkit3d |
Boolean |
true for webkit-based browsers supporting CSS transforms. |
gecko3d |
Boolean |
true for gecko-based browsers supporting CSS transforms. |
opera12 |
Boolean |
true for the Opera browser supporting CSS transforms (version 12 or later). |
any3d |
Boolean |
true for all browsers supporting CSS transforms. |
mobile |
Boolean |
true for all browsers running in a mobile device. |
mobileWebkit |
Boolean |
true for all webkit-based browsers in a mobile device. |
mobileWebkit3d |
Boolean |
true for all webkit-based browsers in a mobile device supporting CSS transforms. |
mobileOpera |
Boolean |
true for the Opera browser in a mobile device. |
mobileGecko |
Boolean |
true for gecko-based browsers running in a mobile device. |
touch |
Boolean |
true for all browsers supporting touch events. |
msPointer |
Boolean |
true for browsers implementing the Microsoft touch events model (notably IE10). |
pointer |
Boolean |
true for all browsers supporting pointer events. |
retina |
Boolean |
true for browsers on a high-resolution "retina" screen. |
canvas |
Boolean |
true when the browser supports <canvas> . |
vml |
Boolean |
true if the browser supports VML. |
svg |
Boolean |
true when the browser supports SVG. |
DG.Util
Various utility functions.
Functions
Function | Returns | Description |
---|---|---|
extend(
|
Object |
Merges the properties of the src object (or multiple objects) into dest
object and returns the latter. Has an DG.extend shortcut. |
create(
|
Object |
Compatibility polyfill for Object.create |
bind(
|
Function |
Returns a new function bound to the arguments passed, like
Function.prototype.bind.
Has a DG.bind() shortcut. |
stamp(
|
Number |
Returns the unique ID of an object, assiging it one if it doesn't have it. |
throttle(
|
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 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 DG.bind shortcut. |
wrapNum(
|
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 |
Returns the number num rounded to digits decimals, or to 5 decimals by default. |
trim(
|
String |
Compatibility polyfill for String.prototype.trim |
splitWords(
|
String[] |
Trims and splits the string on whitespace and returns the array of parts. |
setOptions(
|
Object |
Merges the given properties to the options of the obj object, returning
the resulting options. See Class options . Has an DG.setOptions shortcut. |
getParamString(
|
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' )
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() |
Number |
Compatibility polyfill for Array.prototype.indexOf |
requestAnimFrame(
|
requestId: 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 an id that can be used to cancel the request. |
cancelAnimFrame(
|
|
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). |
DG.LineUtil
Various utility functions for polyine points processing, used by Leaflet internally to make polylines lightning-fast.
Functions
Function | Returns | Description |
---|---|---|
simplify(
|
Point[] |
Dramatically reduces the number of points in a polyline while retaining its shape and returns a new array of simplified points, using the Douglas-Peucker algorithm. Used for a huge performance boost when processing/displaying Leaflet polylines for each zoom level and also reducing visual noise. tolerance affects the amount of simplification (lesser value means higher quality but slower and with more points). Also released as a separated micro-library Simplify.js. |
pointToSegmentDistance(
|
Number |
Returns the distance between point p and segment p1 to p2 . |
closestPointOnSegment(
|
Number |
Returns the closest point from a point p on a segment p1 to p2 . |
DG.PolyUtil
Various utility functions for polygon geometries.
Functions
Function | Returns | Description |
---|---|---|
clipPolygon(
|
Point[] |
Clips the polygon geometry defined by the given points by the given bounds
(using the Sutherland-Hodgeman algorithm).
Used by Leaflet to only show polygon points that are on the screen or near, increasing
performance. Note that polygon points needs different algorithm for clipping
than polyline, so there's a seperate method for it. |