Maps SDK for Web

tt.LngLatBounds

A LngLatBounds object represents a geographical bounding box, defined by its southwest and northeast points in longitude and latitude. If no arguments are provided to the constructor, a null bounding box is created. Note that any SDK method that accepts a LngLatBounds object as an argument or option can also accept an Array of two LngLatLike constructs and will perform an implicit conversion. This flexible type can be used like this:

  • var v1 = new tt.LngLatBounds( new tt.LngLat(-73.9876, 40.7661), new tt.LngLat(-73.9397, 40.8002) );
  • var v2 = new tt.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002])
  • var v3 = [[-73.9876, 40.7661], [-73.9397, 40.8002]];

Constructor

tt.LngLatBounds(sw, ne)

Example
var sw = new tt.LngLat(-73.9876, 40.7661);
var ne = new tt.LngLat(-73.9397, 40.8002);
var llb = new tt.LngLatBounds(sw, ne);
Parameters
Name Description
sw
Maps.LngLat
default:None
The southwest corner of the bounding box.
ne
Maps.LngLat
default:None
The northeast corner of the bounding box.

Methods

contains(lngLat): Boolean

Check if the point is within the bounding box.

Parameters
Name Description
lngLat
Maps.LngLat
default:None
Geographic point to check against.
Returns

True if the point is within the bounding box.

convert(input): Maps.LngLatBounds Static

Converts an array to a LngLatBounds object. If a LngLatBounds object is passed in, the function returns it unchanged. Internally, the function calls LngLat.convert to convert arrays to LngLat values.

Example
var arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
var llb = tt.LngLatBounds.convert(arr);
llb;   // = LngLatBounds {_sw: LngLat {lng: -73.9876, lat: 40.7661}, _ne: LngLat {lng: -73.9397, lat: 40.8002}}
Parameters
Name Description
input
Maps.LngLatBounds
default:None
An array of two coordinates to convert, or a LngLatBounds object to return.
Returns

A new LngLatBounds object, if a conversion occurred, or the original LngLatBounds object.

getCenter( ): Maps.LngLat

Returns the geographical coordinate equidistant from the bounding box's corners.

Example
var llb = new tt.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getCenter(); // = LngLat {lng: -73.96365, lat: 40.78315}
Returns

The bounding box's center.

getEast( ): Number

Returns the east edge of the bounding box.

Returns

The east edge of the bounding box.

getNorth( ): Number

Returns the north edge of the bounding box.

Returns

The north edge of the bounding box.

getNorthEast( ): Maps.LngLat

Returns the northeast corner of the bounding box.

Returns

The northeast corner of the bounding box.

getNorthWest( ): Maps.LngLat

Returns the northwest corner of the bounding box.

Returns

The northwest corner of the bounding box.

getSouth( ): Number

Returns the south edge of the bounding box.

Returns

The south edge of the bounding box.

getSouthEast( ): Maps.LngLat

Returns the southeast corner of the bounding box.

Returns

The southeast corner of the bounding box.

getSouthWest( ): Maps.LngLat

Returns the southwest corner of the bounding box.

Returns

The southwest corner of the bounding box.

getWest( ): Number

Returns the west edge of the bounding box.

Returns

The west edge of the bounding box.

isEmpty( ): Boolean

Check if the bounding box is an empty/null-type box.

Returns

True if bounds have been defined, otherwise false.

toArray( ): Array

Returns the bounding box represented as an array.

Example
var llb = new tt.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.toArray(); // = [[-73.9876, 40.7661], [-73.9397, 40.8002]]
Returns

The bounding box represented as an array, consisting of the southwest and northeast coordinates of the bounding represented as arrays of numbers.

toString( ): String

Return the bounding box represented as a string.

Example
var llb = new tt.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.toString(); // = "LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))"
Returns

The bounding box represents as a string of the format 'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))'.