Skip to main content

basic-types

This section describes the classes of basic data types that are often found in the pages of maps API guide and required for use with many maps API objects.

DG.LatLng

Represents a geographical point with a certain latitude and longitude.

var latlng = DG.latLng(54.98, 82.89);

All methods that accept LatLng objects also accept them in a simple Array form and simple object form (unless noted otherwise), so these lines are equivalent:

map.panTo([54.98, 82.89]);
map.panTo({ lon: 82.89, lat: 54.98 });
map.panTo({ lat: 54.98, lng: 82.89 });
map.panTo(DG.latLng(54.98, 82.89));

Constructor

FactoryDescription
DG.latLng( <Number> latitude, <Number> longitude, <Number> altitude? ) Creates an object representing a geographical point with the given latitude and longitude (and optionally altitude).
DG.latLng( <Array> coords ) Expects an array of the form [Number, Number] or [Number, Number, Number] instead.
DG.latLng( <Object> coords ) Expects an plain object of the form {lat: Number, lng: Number} or {lat: Number, lng: Number, alt: Number} instead.

Methods

MethodReturnsDescription
equals( <LatLng> otherLatLng, <Number> maxMargin? ) BooleanReturns true if the given LatLng point is at the same position (within a small margin of error). The margin of error can be overriden by setting maxMargin to a small number.
toString()StringReturns a string representation of the point (for debugging purposes).
distanceTo( <LatLng> otherLatLng ) NumberReturns the distance (in meters) to the given LatLng calculated using the Haversine formula.
wrap()LatLngReturns a new LatLng object with the longitude wrapped so it's always between -180 and +180 degrees.
toBounds( <Number> sizeInMeters ) LatLngBoundsReturns a new LatLngBounds object in which each boundary is sizeInMeters meters apart from the LatLng.

Properties

PropertyTypeDescription
latNumberLatitude in degrees.
lngNumberLongitude in degrees.
altNumberAltitude in meters (optional).

DG.LatLngBounds

Represents a rectangular geographical area on a map.

var southWest = DG.latLng(54.9801, 82.8974),
northEast = DG.latLng(54.9901, 82.9074),
bounds = DG.latLngBounds(southWest, northEast);

All methods that accept LatLngBounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:

map.fitBounds([
[54.9801, 82.8974],
[54.9901, 82.9074],
]);

Creation

FactoryDescription
DG.latLngBounds( <LatLng> southWest, <LatLng> northEast ) Creates a LatLngBounds object by defining south-west and north-east corners of the rectangle.
DG.latLngBounds( <LatLng[]> latlngs) Creates a LatLngBounds object defined by the geographical points it contains. Very useful for zooming the map to fit a particular set of locations with fitBounds.

Methods

MethodReturnsDescription
extend( <LatLng> latlng ) thisExtend the bounds to contain the given point.
extend( <LatLngBounds> otherBounds ) thisExtend the bounds to contain the given bounds.
pad( <Number> bufferRatio ) LatLngBoundsReturns bigger bounds created by extending the current bounds by a given percentage in each direction.
getCenter()LatLngReturns the center point of the bounds.
getSouthWest()LatLngReturns the south-west point of the bounds.
getNorthEast()LatLngReturns the north-east point of the bounds.
getNorthWest()LatLngReturns the north-west point of the bounds.
getSouthEast()LatLngReturns the south-east point of the bounds.
getWest()NumberReturns the west longitude of the bounds.
getSouth()NumberReturns the south latitude of the bounds.
getEast()NumberReturns the east longitude of the bounds.
getNorth()NumberReturns the north latitude of the bounds.
contains( <LatLngBounds> otherBounds ) BooleanReturns true if the rectangle contains the given one.
contains( <LatLng> latlng ) BooleanReturns true if the rectangle contains the given point.
intersects( <LatLngBounds> otherBounds ) BooleanReturns true if the rectangle intersects the given bounds. Two bounds intersect if they have at least one point in common.
overlaps( <Bounds> otherBounds ) BooleanReturns true if the rectangle overlaps the given bounds. Two bounds overlap if their intersection is an area.
toBBoxString()StringReturns a string with bounding box coordinates in a 'southwest_lng,southwest_lat,northeast_lng,northeast_lat' format. Useful for sending requests to web services that return geo data.
equals( <LatLngBounds> otherBounds ) BooleanReturns true if the rectangle is equivalent (within a small margin of error) to the given bounds.
isValid()BooleanReturns true if the bounds are properly initialized.

DG.Point

Represents a point with x and y coordinates in pixels.

var point = DG.point(200, 300);

All methods and options that accept Point objects also accept them in a simple Array form (unless noted otherwise), so these lines are equivalent:

map.panBy([200, 300]);
map.panBy(DG.point(200, 300));

Creation

FactoryDescription
DG.point( <Number> x, <Number> y, <Boolean> round? ) Creates a Point object with the given x and y coordinates. If optional round is set to true, rounds the x and y values.
DG.point( <Number[]> coords) Expects an array of the form [x, y] instead.

Methods

MethodReturnsDescription
clone()PointReturns a copy of the current point.
add( <Point> otherPoint ) PointReturns the result of addition of the current and the given points.
subtract( <Point> otherPoint ) PointReturns the result of subtraction of the given point from the current.
divideBy( <Number> num ) PointReturns the result of division of the current point by the given number.
multiplyBy( <Number> num ) PointReturns the result of multiplication of the current point by the given number.
scaleBy( <Point> scale ) PointMultiply each coordinate of the current point by each coordinate of scale. In linear algebra terms, multiply the point by the scaling matrix defined by scale.
unscaleBy( <Point> scale ) PointInverse of scaleBy. Divide each coordinate of the current point by each coordinate of scale.
round()PointReturns a copy of the current point with rounded coordinates.
floor()PointReturns a copy of the current point with floored coordinates (rounded down).
ceil()PointReturns a copy of the current point with ceiled coordinates (rounded up).
distanceTo( <Point> otherPoint ) NumberReturns the cartesian distance between the current and the given points.
equals( <Point> otherPoint ) BooleanReturns true if the given point has the same coordinates.
contains( <Point> otherPoint ) BooleanReturns true if both coordinates of the given point are less than the corresponding current point coordinates (in absolute values).
toString()StringReturns a string representation of the point for debugging purposes.

Properties

PropertyTypeDescription
xNumberx coordinate.
yNumbery coordinate.

DG.Bounds

Represents a rectangular area in pixel coordinates.

var p1 = DG.point(10, 10),
p2 = DG.point(40, 60),
bounds = DG.bounds(p1, p2);

All methods that accept Bounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:

otherBounds.intersects([
[10, 10],
[40, 60],
]);

Creation

FactoryDescription
DG.bounds( <Point> topLeft, <Point> bottomRight ) Creates a Bounds object from two coordinates (usually top-left and bottom-right corners).
DG.bounds( <Point[]> points ) Creates a Bounds object from the points it contains.

Methods

MethodReturnsDescription
extend( <Point> point ) thisExtends the bounds to contain the given point.
getCenter( <Boolean> round? ) PointReturns the center point of the bounds.
getBottomLeft()PointReturns the bottom-left point of the bounds.
getTopRight()PointReturns the top-right point of the bounds.
getSize()PointReturns the size of the given bounds.
contains( <Bounds> otherBounds ) BooleanReturns true if the rectangle contains the given one.
contains( <Point> point ) BooleanReturns true if the rectangle contains the given poing.
intersects( <Bounds> otherBounds ) BooleanReturns true if the rectangle intersects the given bounds. Two bounds intersect if they have at least one point in common.
overlaps( <Bounds> otherBounds ) BooleanReturns true if the rectangle overlaps the given bounds. Two bounds overlap if their intersection is an area.

Properties

PropertyTypeDescription
minPointThe top left corner of the rectangle.
maxPointThe bottom right corner of the rectangle.