Class: Bounds

SuperMap.Bounds

The Bounds class. Before to call bounds,you have to set left, bottom, right and top,all values are initialized to null.

new SuperMap.Bounds(left, bottom, right, top, array)

Bounds.js, line 7
Name Type Description
left number optional

The left bounds of the box. Note that for width calculations, this is assumed to be less than the right value.

bottom number optional

The bottom bounds of the box. Note that for height calculations, this is assumed to be less than the top value.

right number optional

The right bounds.

top number optional

The top bounds.

array Array.<number> optional

[left, bottom, right, top], If multiple parameters are passed at the same time, an array consisting of the bottom left and the top right is used.

Example
var bounds = new SuperMap.Bounds();
bounds.extend(new SuperMap.LonLat(4,5));
bounds.extend(new SuperMap.LonLat(5,6));
bounds.toBBOX(); // returns 4,5,5,6

Members

bottomnumber

The bottom bounds of the box. Note that for height calculations, this is assumed to be less than the top value.

centerLonLatSuperMap.LonLat

The center of the map. You can get it by getCenterLonLat().

leftnumber

The left bounds of the box. Note that for width calculations, this is assumed to be less than the right value.

namestring

Prefix of verification information, the name part in the name=value part, and the default is "token".

Default Value:
'token'

The right bounds.

topnumber

The top bounds.

valuestring

Verification information which is used to pass the safety verification when user visits the services that is subject to security restrictions.

Methods

SuperMap.Bounds.fromArray(bbox, reverseAxisOrder){SuperMap.Bounds}

Bounds.js, line 676

Create Bounds by boundary frame array.

Name Type Default Description
bbox Array.<float>

Array of bounds values (e.g. [5,42,10,45])

reverseAxisOrder boolean false optional

Whether to reverse the axis order. If set to true, reverse order (bottom, left, top, right), Otherwise in normal axis order.

Returns:
Type Description
SuperMap.Bounds New bounds object built from the passed-in Array.
Example
var bounds = SuperMap.Bounds.fromArray([-180,-90,100,80]);

SuperMap.Bounds.fromSize(size){SuperMap.Bounds}

Bounds.js, line 691

Create new boundary by input boundary size.

Name Type Description
size SuperMap.Size

Input bounds size.

Returns:
Type Description
SuperMap.Bounds New bounds object built from the passed-in size.
Example
var bounds = SuperMap.Bounds.fromSize(new SuperMap.Size(20,10));

SuperMap.Bounds.fromString(str, reverseAxisOrder){SuperMap.Bounds}

Bounds.js, line 662

Create new constructor of bounds from a parameter string.

Name Type Default Description
str string

Boundary strings, separated by commas (e.g. "5,42,10,45").

reverseAxisOrder boolean false optional

Whether to reverse the axis order. If set to true, reverse order (bottom, left, top, right), Otherwise in normal axis order.

Returns:
Type Description
SuperMap.Bounds New bounds object built from the passed-in String.
Example
var bounds = SuperMap.Bounds.fromString("-180,-90,100,80");

SuperMap.Bounds.oppositeQuadrant(quadrant){string}

Bounds.js, line 706

Reverse quadrant. Turned "t" and "b", turned "r" and "l", for instance:"tl" turned to be"br".

Name Type Description
quadrant string

The string representing a quadrant,for instance:"tl".

Returns:
Type Description
string Reversed quadrant.

add(x, y){SuperMap.Bounds}

Bounds.js, line 283

Pan on the current bounds according to the input coordinates, returns the new bounds.

Name Type Description
x float

The x coordinate.

y float

The y coordinate.

Returns:
Type Description
SuperMap.Bounds A new bounds whose coordinates are the same as this, but shifted by the passed-in x and y values.
Example
var bounds1 = new SuperMap.Bounds(-50,-50,40,40);
//bounds2 is new bounds
var bounds2 = bounds.add(20,10);

clone(){SuperMap.Bounds}

Bounds.js, line 64

Copy the current bounds object.

Returns:
Type Description
SuperMap.Bounds Return a clone of bounds.
Example
var bounds1 = new SuperMap.Bounds(-180,-90,180,90);
var bounds2 = bounds1.clone();

contains(x, y, inclusive){boolean}

Bounds.js, line 409

Returns whether the bounds object contains the given x and y.

Name Type Default Description
x float

The x coordinate.

y float

The y coordinate.

inclusive boolean true optional

Whether or not include the border.

Returns:
Type Description
boolean Whether the passed x,y coordinates are in the current range.
Example
var bounds = new SuperMap.Bounds(-50,-50,40,40);
//isContains = true
var isContains = bounds.contains(40,40,true);

containsBounds(bounds, partial, inclusive){boolean}

Bounds.js, line 524

Returns whether the bounds object contains the given bounds.

Name Type Default Description
bounds SuperMap.Bounds

The target bounds.

partial boolean false optional

If any of the target corners is within this bounds consider the bounds contained. If false, the entire target bounds must be contained within this bounds.

inclusive boolean true optional

Treat shared edges as contained.

Returns:
Type Description
boolean The passed-in bounds object is contained within this bounds.
Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
var isContains = bounds.containsBounds(
     new SuperMap.Bounds(-170,-90,100,80),true,true
 );

containsLonLat(ll, options){boolean}

Bounds.js, line 348

Returns whether the bounds object contains the given lonLat.

Name Type Description
ll SuperMap.LonLat | Object

SuperMap.LonLat object or an object with a ‘lon’ and ‘lat’ properties.

options Object

The optional parameter.

Name Type Default Description
inclusive boolean true optional

Whether or not include the border.

worldBounds SuperMap.Bounds optional

If a worldBounds is provided, the ll will be considered as contained if it exceeds the world bounds, but can be wrapped around the dateline so it is contained by this bounds.

Returns:
Type Description
boolean The passed-in lonlat is within this bounds.
Example
var bounds1 = new SuperMap.Bounds(-50,-50,40,40);
//isContains1 = true
//The second parameter can be Boolean, that is, inclusive
var isContains1 = bounds.containsLonLat(new SuperMap.LonLat(40,40),true);

//(40,40) is within the ranges, and (40+360,40) is within it
var bounds2 = new SuperMap.Bounds(-50,-50,40,40);
//isContains2 = true;
var isContains2 = bounds2.containsLonLat(
     new SuperMap.LonLat(400,40),
     {
          inclusive:true,
          //The ranges of the globe
          worldBounds: new SuperMap.Bounds(-180,-90,180,90)
     }
);

containsPixel(px, inclusive)

Bounds.js, line 395

Judge whether the input pixel is in the range. Directly match the size, not related to the conversion between pixel and geographical coordinate system.

Name Type Default Description
px SuperMap.Pixel

pixel parameter.

inclusive boolean true optional

Whether or not include the border.

Example
var bounds = new SuperMap.Bounds(-50,-50,40,40);
//isContains = true
var isContains = bounds.containsPixel(new SuperMap.Pixel(40,40),true);

destroy()

Bounds.js, line 646

Destroy the object. All properties of the object will be null after it is destroyed.

Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
bounds.destroy();

determineQuadrant(lonlat){string}

Bounds.js, line 554

A quadrant that determines whether the incoming coordinates are within bounds. Take the bounds center point as the coordinate origin.

Name Type Description
lonlat SuperMap.LonLat

The passed coordinate objects.

Returns:
Type Description
string The quadrant where the incoming coordinates are located ("br" "tr" "tl" "bl" corresponds to "bottom right", "top right", "top left" and "bottom left" respectively.
Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
//str = "tr";
var str = bounds.determineQuadrant(
     new SuperMap.LonLat(20,20)
 );

equals(bounds){boolean}

Bounds.js, line 77

Determines whether two bounds objects are equal.

Name Type Description
bounds SuperMap.Bounds

Bounds to be measured.

Returns:
Type Description
boolean Boolean value indicating whether the passed-in bounds object has the same edges as this. True means the same, if the passed in is null or not the same, returns false.
Example
var bounds1 = new SuperMap.Bounds(-180,-90,180,90);
var bounds2 = new SuperMap.Bounds(-180,-90,180,90);
var isEquals = bounds1.equals(bounds2);

extend(object)

Bounds.js, line 302

Extend bounds on current bounds, supporting point, LonLat and bounds. The extended bounds is the union of both.

Name Type Description
object SuperMap.Geometry.Point | SuperMap.LonLat | SuperMap.Bounds

can be point, LonLat and bounds.

Example
var bounds1 = new SuperMap.Bounds(-50,-50,40,40);
//bounds changes
bounds.extend(new SuperMap.LonLat(50,60));

getCenterLonLat(){SuperMap.LonLat}

Bounds.js, line 231

Get the center point of the range in geographical format.

Returns:
Type Description
SuperMap.LonLat Return the center point of current bounds in geographical format.
Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
var lonlat = bounds.getCenterLonLat();

getCenterPixel(){SuperMap.Pixel}

Bounds.js, line 218

Get the center point of the range in pixel format.

Returns:
Type Description
SuperMap.Pixel Return the center point of current bounds in the pixel format.
Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
var pixel = bounds.getCenterPixel();

getHeight(){float}

Bounds.js, line 193

Get the height of bounds.

Returns:
Type Description
float Returns boundary height(top-bottom).
Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
//height = 170;
var height = bounds.getHeight();

getSize(){SuperMap.Size}

Bounds.js, line 206

Get the border size.

Returns:
Type Description
SuperMap.Size Return the border size.
Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
var size = bounds.getSize();

getValue(){string}

Credential.js, line 49

Get value.

Returns:
Type Description
string Returns the value string which is the token value under the iServer service.
Example
var credential = new SuperMap.Credential("2OMwGmcNlrP2ixqv1Mk4BuQMybOGfLOrljruX6VcYMDQKc58Sl9nMHsqQaqeBx44jRvKSjkmpZKK1L596y7skQ..","token");
// str = "2OMwGmcNlrP2ixqv1Mk4BuQMybOGfLOrljruX6VcYMDQKc58Sl9nMHsqQaqeBx44jRvKSjkmpZKK1L596y7skQ..";
var str = credential.getValue();

getWidth(){float}

Bounds.js, line 180

Get the width of bounds.

Returns:
Type Description
float The width of the bounds (right minus left).
Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
//width = 280;
var width = bounds.getWidth();

intersectsBounds(bounds, options){boolean}

Bounds.js, line 445

Determine whether the target bounds intersects this bounds. Bounds are considered intersecting if any of their edges intersect or if one bounds contains the other.

Name Type Description
bounds SuperMap.Bounds

The target bounds.

options Object

parameter.

Name Type Default Description
inclusive boolean true optional

Treat coincident borders as intersecting. If false, bounds that do not overlap but only touch at the border will not be considered as intersecting.

worldBounds SuperMap.Bounds optional

If a worldBounds is provided, two bounds will be considered as intersecting if they intersect when shifted to within the world bounds. This applies only to bounds that cross or are completely outside the world bounds.

Returns:
Type Description
boolean The passed-in bounds object intersects this bounds.
Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
var isIntersects = bounds.intersectsBounds(
     new SuperMap.Bounds(-170,-90,120,80)
 );

scale(ratio, origin){SuperMap.Bounds}

Bounds.js, line 248

Get a new bounds by zooming according to a certain scale.

Name Type Default Description
ratio float 1 optional

The proportion that needs to be expanded.

origin SuperMap.Pixel | SuperMap.LonLat optional

Base point when extending, the default is the center of the current bounds.

Returns:
Type Description
SuperMap.Bounds A new bounds that is scaled by ratio from origin.
Example
var bounds = new SuperMap.Bounds(-50,-50,40,40);
var bounds2 = bounds.scale(2);

toArray(reverseAxisOrder){Array.<number>}

Bounds.js, line 110

Returns an array representation of the bounds object.

Name Type Default Description
reverseAxisOrder boolean false optional

Whether to reverse the axis order. If set to true, reverse order (bottom, left, top, right), Otherwise in normal axis order.

Returns:
Type Description
Array.<number> lleft, bottom, right, top array
Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
//array1 = [-180,-90,100,80];
var array1 = bounds.toArray();
//array1 = [-90,-180,80,100];
var array2 = bounds.toArray(true);

toBBOX(decimal, reverseAxisOrder){string}

Bounds.js, line 130

Take the decimal number, then round up and round down, then convert it to BBOX string

Name Type Default Description
decimal integer 6 optional

The number of significant digits of the boundary orientation coordinates.

reverseAxisOrder boolean false optional

Whether to reverse the axis order. If set to true, reverse order (bottom, left, top, right), Otherwise in normal axis order.

Returns:
Type Description
string A string representation of the bounding object, such as: "5, 42, 10, 45".
Example
var bounds = new SuperMap.Bounds(-1.1234567,-1.7654321,1.4444444,1.5555555);
//str1 = "-1.123457,-1.765432,1.444444,1.555556";
var str1 = bounds.toBBOX();
//str2 = "-1.1,-1.8,1.4,1.6";
var str2 = bounds.toBBOX(1);
//str2 = "-1.8,-1.1,1.6,1.4";
var str2 = bounds.toBBOX(1,true);

toGeometry(){SuperMap.Geometry.Polygon}

Bounds.js, line 161

Create a new polygon geometry based on this bounds.

Returns:
Type Description
SuperMap.Geometry.Polygon Create a new polygon geometry based on this bounds.
Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
var geo = bounds.toGeometry();

toServerJSONObject(){Object}

Bounds.js, line 626

Transform to JSON object.

Returns:
Type Description
Object Return the JSON object.
Example
var bounds = new SuperMap.Bounds(-180,-90,100,80);
var obj = bounds.toServerJSONObject();

toString(){string}

Bounds.js, line 98

Return the string format of this object.

Returns:
Type Description
string String format of the bounds object (left,bottom,right,top), e.g., : “-180,-90,180,90”
Example
var bounds = new SuperMap.Bounds(-180,-90,180,90);
var str = bounds.toString();

wrapDateLine(maxExtent, options){SuperMap.Bounds}

Bounds.js, line 577

Move the current bounds inside the maximum ranges(inside means intersection or within).

Name Type Description
maxExtent SuperMap.Bounds

The maximum ranges(generally, it is the global ranges).

options Object

The optional parameter.

Name Type Default Description
leftTolerance float 0 optional

Allow for a margin of error with the ‘left’ value of this bound.

rightTolerance float 0 optional

Allow for a margin of error with the ‘right’ value of this bound.

Returns:
Type Description
SuperMap.Bounds A copy of this bounds, but wrapped around the “dateline” (as specified by the borders of maxExtent). Note that this function only returns a different bounds value if this bounds is entirely outside of the maxExtent. If this bounds straddles the dateline (is part in/part out of maxExtent), the returned bounds will be merely a copy of this one.
Example
var bounds = new SuperMap.Bounds(380,-40,400,-20);
var maxExtent = new SuperMap.Bounds(-180,-90,100,80);
var newBounds = bounds.wrapDateLine(maxExtent);