Class: Bounds

Bounds

表示边界类实例。使用 bounds 之前需要设置 left,bottom,right,top 四个属性,这些属性的初始值为 null。

new Bounds(left, bottom, right, top)

Usage
// 浏览器
<script type="text/javascript" src="https://iclient.supermap.io/dist/openlayers/iclient-ol.js"></script>
<script>
  new ol.supermap.Bounds(left, bottom, right, top);
  
  // 弃用的写法
  new SuperMap.Bounds(left, bottom, right, top);

</script>

// ES6 Import
import { Bounds } from '@supermap/iclient-ol';

new Bounds(left, bottom, right, top);

common/commontypes/Bounds.js, line 9
Name Type Description
left number | Array.<number> 可选

如果是number,则表示左边界,注意考虑宽度,理论上小于 right 值。如果是数组,则表示 [left, bottom, right, top] 左下右上组成的数组。

bottom number 可选

下边界。考虑高度,理论上小于 top 值。

right number 可选

右边界。

top number 可选

上边界。

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

Members

bottomnumber

最小的垂直坐标系。

centerLonLatLonLat

bounds 的地图空间的中心点。用 getCenterLonLat() 获得。

leftnumber

最小的水平坐标系。

最大的水平坐标系。

topnumber

最大的垂直坐标系。

Methods

static fromArray(bbox, reverseAxisOrder){Bounds}

common/commontypes/Bounds.js, line 684

通过边界框数组创建 Bounds。

Name Type Default Description
bbox Array.<number>

边界值数组。(e.g. [5,42,10,45])。

reverseAxisOrder boolean false 可选

是否是反转轴顺序。如果设为true,则倒转顺序(bottom,left,top,right),否则按正常轴顺序(left,bottom,right,top)。

Returns:
Type Description
Bounds 根据传入的数组创建的新的边界对象。
Example
var bounds = Bounds.fromArray([-180,-90,100,80]);

static fromSize(size){Bounds}

common/commontypes/Bounds.js, line 699

通过传入的边界大小来创建新的边界。

Name Type Description
size Size

边界大小。

Returns:
Type Description
Bounds 根据传入的边界大小的创建新的边界。
Example
var bounds = Bounds.fromSize(new Size(20,10));

static fromString(str, reverseAxisOrder){Bounds}

common/commontypes/Bounds.js, line 669

通过字符串参数创建新的 bounds 的构造函数。

Name Type Default Description
str string

边界字符串,用逗号隔开(e.g. "5,42,10,45")。

reverseAxisOrder boolean false 可选

是否反转轴顺序。 如果设为true,则倒转顺序(bottom,left,top,right),否则按正常轴顺序(left,bottom,right,top)。

Returns:
Type Description
Bounds 给定的字符串创建的新的边界对象。
Example
var bounds = Bounds.fromString("-180,-90,100,80");

static oppositeQuadrant(quadrant){string}

common/commontypes/Bounds.js, line 714

反转象限。"t"和"b" 交换,"r"和"l"交换, 如:"tl"变为"br"。

Name Type Description
quadrant string

代表象限的字符串,如:"tl"。

Returns:
Type Description
string 反转后的象限。

add(x, y){Bounds}

common/commontypes/Bounds.js, line 289

在当前的 Bounds 上按照传入的坐标点进行平移,返回新的范围。

Name Type Description
x number

坐标点的 x 坐标。

y number

坐标点的 y 坐标。

Returns:
Type Description
Bounds 新的 bounds,此 bounds 的坐标是由传入的 x,y 参数与当前 bounds 坐标计算所得。
Example
var bounds1 = new Bounds(-50,-50,40,40);
//bounds2 是新的 bounds
var bounds2 = bounds.add(20,10);

clone(){Bounds}

common/commontypes/Bounds.js, line 67

复制当前 bounds 对象。

Returns:
Type Description
Bounds 克隆后的 bounds。
Example
var bounds1 = new Bounds(-180,-90,180,90);
var bounds2 = bounds1.clone();

contains(x, y, inclusive){boolean}

common/commontypes/Bounds.js, line 417

判断传入的 x,y 坐标值是否在范围内。

Name Type Default Description
x number

x 坐标值。

y number

y 坐标值。

inclusive boolean true 可选

是否包含边界。

Returns:
Type Description
boolean 传入的 x,y 坐标是否在当前范围内。
Example
var bounds = new Bounds(-50,-50,40,40);
//isContains = true
var isContains = bounds.contains(40,40,true);

containsBounds(bounds, partial, inclusive){boolean}

common/commontypes/Bounds.js, line 529

判断目标边界是否被当前边界包含在内。

Name Type Default Description
bounds Bounds

目标边界。

partial boolean false 可选

目标边界的任意部分都包含在当前边界中则被认为是包含关系。 如果设为 false,整个目标边界全部被包含在当前边界范围内。

inclusive boolean true 可选

边缘共享是否被视为包含。

Returns:
Type Description
boolean 传入的边界是否被当前边界包含。
Example
var bounds = new Bounds(-180,-90,100,80);
var isContains = bounds.containsBounds(
     new Bounds(-170,-90,100,80),true,true
 );

containsLonLat(ll, options){boolean}

common/commontypes/Bounds.js, line 354

判断传入的坐标是否在范围内。

Name Type Description
ll LonLat | Object

对象或者是一个包含 'lon' 与 'lat' 属性的对象。

options Object

可选参数。

Name Type Default Description
inclusive boolean true 可选

是否包含边界。

worldBounds Bounds 可选

如果提供 worldBounds 参数, 如果 ll 参数提供的坐标超出了世界边界(worldBounds), 但是通过日界线的转化可以被包含, 它将被认为是包含在该范围内的。

Returns:
Type Description
boolean 传入坐标是否包含在范围内。
Example
var bounds1 = new Bounds(-50,-50,40,40);
//isContains1 = true
//这里的第二个参数可以直接为 boolean 类型,也就是inclusive
var isContains1 = bounds.containsLonLat(new LonLat(40,40),true);

//(40,40)在范围内,同样(40+360,40)也在范围内
var bounds2 = new Bounds(-50,-50,40,40);
//isContains2 = true;
var isContains2 = bounds2.containsLonLat(
     new LonLat(400,40),
     {
          inclusive:true,
          //全球的范围
          worldBounds: new Bounds(-180,-90,180,90)
     }
);

containsPixel(px, inclusive){boolean}

common/commontypes/Bounds.js, line 402

判断传入的像素是否在范围内。直接匹配大小,不涉及像素和地理转换。

Name Type Default Description
px Pixel

提供的像素参数。

inclusive boolean true 可选

是否包含边界。

Returns:
Type Description
boolean 传入的 pixel 在当前边界范围之内。
Example
var bounds = new Bounds(-50,-50,40,40);
//isContains = true
var isContains = bounds.containsPixel(new Pixel(40,40),true);

destroy()

common/commontypes/Bounds.js, line 652

销毁此对象。 销毁后此对象的所有属性为 null,而不是初始值。

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

determineQuadrant(lonlat){string}

common/commontypes/Bounds.js, line 559

判断传入坐标是否在 bounds 范围内的象限。以 bounds 中心点为坐标原点。

Name Type Description
lonlat LonLat

传入的坐标对象。

Returns:
Type Description
string 传入坐标所在的象限("br" "tr" "tl" "bl" 分别对应"右下","右上","左上" "左下")。
Example
var bounds = new Bounds(-180,-90,100,80);
//str = "tr";
var str = bounds.determineQuadrant(
     new LonLat(20,20)
 );

equals(bounds){boolean}

common/commontypes/Bounds.js, line 80

判断两个 bounds 对象是否相等。

Name Type Description
bounds Bounds

需要进行计较的 bounds。

Returns:
Type Description
boolean 如果 bounds 对象的边和传入的 bounds 一致则返回 true,不一致或传入的 bounds 参数为 NULL 则返回 false。
Example
var bounds1 = new Bounds(-180,-90,180,90);
var bounds2 = new Bounds(-180,-90,180,90);
var isEquals = bounds1.equals(bounds2);

extend(object)

common/commontypes/Bounds.js, line 308

在当前 bounds 上扩展 bounds,支持 point,lonlat 和 bounds。扩展后的 bounds 的范围是两者的结合。

Name Type Description
object GeometryPoint | LonLat | Bounds

可以是 point、lonlat 和 bounds。

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

getCenterLonLat(){LonLat}

common/commontypes/Bounds.js, line 237

获取地理格式的范围中心点。

Returns:
Type Description
LonLat 当前地理范围的中心点。
Example
var bounds = new Bounds(-180,-90,100,80);
var lonlat = bounds.getCenterLonLat();

getCenterPixel(){Pixel}

common/commontypes/Bounds.js, line 224

获取像素格式的范围中心点。

Returns:
Type Description
Pixel 像素格式的当前范围的中心点。
Example
var bounds = new Bounds(-180,-90,100,80);
var pixel = bounds.getCenterPixel();

getHeight(){number}

common/commontypes/Bounds.js, line 199

获取 bounds 的高度。

Returns:
Type Description
number 边界高度(top 减去 bottom)。
Example
var bounds = new Bounds(-180,-90,100,80);
//height = 170;
var height = bounds.getHeight();

getSize(){Size}

common/commontypes/Bounds.js, line 212

获取边框大小。

Returns:
Type Description
Size 边框大小。
Example
var bounds = new Bounds(-180,-90,100,80);
var size = bounds.getSize();

getWidth(){number}

common/commontypes/Bounds.js, line 186

获取 bounds 的宽度。

Returns:
Type Description
number 获取当前 bounds 的宽度(right 减去 left)。
Example
var bounds = new Bounds(-180,-90,100,80);
//width = 280;
var width = bounds.getWidth();

intersectsBounds(bounds, options){boolean}

common/commontypes/Bounds.js, line 453

判断目标边界范围是否与当前边界范围相交。如果两个边界范围中的任意边缘相交或者一个边界包含了另外一个就认为这两个边界相交。

Name Type Description
bounds Bounds

目标边界。

options Object

参数。

Name Type Default Description
inclusive boolean true 可选

边缘重合也看成相交。如果是false,两个边界范围没有重叠部分仅仅是在边缘相接(重合),这种情况被认为没有相交。

worldBounds Bounds 可选

提供了 worldBounds 参数,如果他们相交时是在全球范围内,两个边界将被视为相交。这仅适用于交叉或完全不在世界范围的边界。

Returns:
Type Description
boolean 传入的 bounds 对象与当前 bounds 相交。
Example
var bounds = new Bounds(-180,-90,100,80);
var isIntersects = bounds.intersectsBounds(
     new Bounds(-170,-90,120,80)
 );

scale(ratio, origin){Bounds}

common/commontypes/Bounds.js, line 254

按照比例扩大/缩小出一个新的 bounds。

Name Type Default Description
ratio number 1 可选

需要扩大的比例。

origin Pixel | LonLat 可选

扩大时的基准点,默认为当前 bounds 的中心点。

Returns:
Type Description
Bounds 通过 ratio、origin 计算得到的新的边界范围。
Example
var bounds = new Bounds(-50,-50,40,40);
var bounds2 = bounds.scale(2);

toArray(reverseAxisOrder){Array.<number>}

common/commontypes/Bounds.js, line 113

边界对象的数组表示形式。

Name Type Default Description
reverseAxisOrder boolean false 可选

是否反转轴顺序。 如果设为 true,则倒转顺序(bottom,left,top,right),否则按正常轴顺序(left,bottom,right,top)。

Returns:
Type Description
Array.<number> left, bottom, right, top 数组。
Example
var bounds = new 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}

common/commontypes/Bounds.js, line 134

取小数点后 decimal 位数字进行四舍五入再转换为 BBOX 字符串。

Name Type Default Description
decimal number 6 可选

边界方位坐标的有效数字个数。

reverseAxisOrder boolean false 可选

是否是反转轴顺序。 如果设为true,则倒转顺序(bottom,left,top,right),否则按正常轴顺序(left,bottom,right,top)。

Returns:
Type Description
string 边界对象的字符串表示形式,如:"5,42,10,45"。
Example
var bounds = new 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);

toServerJSONObject(){Object}

common/commontypes/Bounds.js, line 632

转换成对应的 JSON 格式对象。

Returns:
Type Description
Object JSON 格式的 Object 对象。
Example
var bounds = new Bounds(-180,-90,100,80);
var obj = bounds.toServerJSONObject();

toString(){string}

common/commontypes/Bounds.js, line 101

返回此对象的字符串形式。

Returns:
Type Description
string 边界对象的字符串表示形式(left,bottom,right,top),例如: "-180,-90,180,90"。
Example
var bounds = new Bounds(-180,-90,180,90);
var str = bounds.toString();

wrapDateLine(maxExtent, options){Bounds}

common/commontypes/Bounds.js, line 582

将当前 bounds 移动到最大边界范围内部(所谓的内部是相交或者内部)。

Name Type Description
maxExtent Bounds

最大的边界范围(一般是全球范围)。

options Object

可选选项参数。

Name Type Default Description
leftTolerance number 0 可选

left 允许的误差。

rightTolerance number 0 可选

right 允许的误差。

Returns:
Type Description
Bounds 克隆当前边界。如果当前边界完全在最大范围之外此函数则返回一个不同值的边界, 若落在最大边界的左边,则给当前的bounds值加上最大范围的宽度,即向右移动, 若落在右边,则向左移动,即给当前的bounds值加上负的最大范围的宽度。
Example
var bounds = new Bounds(380,-40,400,-20);
var maxExtent = new Bounds(-180,-90,100,80);
//新的bounds
var newBounds = bounds.wrapDateLine(maxExtent);