---
title: Class: GeoBounds
source: https://vjmap.com/en/doc/Class_GeoBounds.html
---

# Class: GeoBounds

`GeoBounds` 地理范围.

### Table of contents

#### Constructors

- [constructor](#constructor)

#### Properties

- [max](#max)
- [min](#min)

#### Methods

- [center](#center)
- [clone](#clone)
- [closestPoint](#closestpoint)
- [contains](#contains)
- [height](#height)
- [intersect](#intersect)
- [isContains](#iscontains)
- [isIntersect](#isintersect)
- [leftBottom](#leftbottom)
- [leftTop](#lefttop)
- [randomGeoJsonLineCollection](#randomgeojsonlinecollection)
- [randomGeoJsonPointCollection](#randomgeojsonpointcollection)
- [randomGeoJsonPolygonCollection](#randomgeojsonpolygoncollection)
- [randomPoint](#randompoint)
- [randomPoints](#randompoints)
- [rightBottom](#rightbottom)
- [rightTop](#righttop)
- [scale](#scale)
- [scaleXY](#scalexy)
- [set](#set)
- [square](#square)
- [toArray](#toarray)
- [toPointArray](#topointarray)
- [toString](#tostring)
- [translate](#translate)
- [union](#union)
- [update](#update)
- [updateByBounds](#updatebybounds)
- [width](#width)
- [fromArray](#fromarray)
- [fromCenterWH](#fromcenterwh)
- [fromDataExtent](#fromdataextent)
- [fromString](#fromstring)

### Constructors

#### constructor

\+ **new GeoBounds**(`min?`: [*GeoPoint*](#classesdefaultgeopointmd), `max?`: [*GeoPoint*](#classesdefaultgeopointmd)): [*GeoBounds*](#classesdefaultgeoboundsmd)

##### Parameters

| Name | Type |
| :------ | :------ |
| `min?` | [*GeoPoint*](#classesdefaultgeopointmd) |
| `max?` | [*GeoPoint*](#classesdefaultgeopointmd) |

**Returns:** [*GeoBounds*](#classesdefaultgeoboundsmd)

### Properties

#### max

• **max**: [*GeoPoint*](#classesdefaultgeopointmd)

___

#### min

• **min**: [*GeoPoint*](#classesdefaultgeopointmd)

### Methods

#### center

▸ **center**(): [*GeoPoint*](#classesdefaultgeopointmd)

得到中心点

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### clone

▸ **clone**(): [*GeoBounds*](#classesdefaultgeoboundsmd)

 克隆

**Returns:** [*GeoBounds*](#classesdefaultgeoboundsmd)

___

#### closestPoint

▸ **closestPoint**(`testPoint`: [*GeoPoint*](#classesdefaultgeopointmd), `includeInterior?`: *boolean*): [*GeoPoint*](#classesdefaultgeopointmd)

查找边界框上最近的点并返回该点.

##### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `testPoint` | [*GeoPoint*](#classesdefaultgeopointmd) | - | 点. |
| `includeInterior` | *boolean* | true | 如果为true，则最近的点可以位于边界框内。如果为false，则最近的点只能位于边界框的外边缘上. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### contains

▸ **contains**(`point`: [*GeoPoint*](#classesdefaultgeopointmd)): *boolean*

查看点是否在包围盒中

##### Parameters

| Name | Type |
| :------ | :------ |
| `point` | [*GeoPoint*](#classesdefaultgeopointmd) |

**Returns:** *boolean*

___

#### height

▸ **height**(): *number*

 获取高度

**Returns:** *number*

___

#### intersect

▸ **intersect**(`b`: [*GeoBounds*](#classesdefaultgeoboundsmd)): ``null`` \| [*GeoBounds*](#classesdefaultgeoboundsmd)

两包围盒求交集

##### Parameters

| Name | Type |
| :------ | :------ |
| `b` | [*GeoBounds*](#classesdefaultgeoboundsmd) |

**Returns:** ``null`` \| [*GeoBounds*](#classesdefaultgeoboundsmd)

___

#### isContains

▸ **isContains**(`bound`: [*GeoBounds*](#classesdefaultgeoboundsmd)): *boolean*

求一个包围盒是否包含另一个包围盒

##### Parameters

| Name | Type |
| :------ | :------ |
| `bound` | [*GeoBounds*](#classesdefaultgeoboundsmd) |

**Returns:** *boolean*

___

#### isIntersect

▸ **isIntersect**(`bound`: [*GeoBounds*](#classesdefaultgeoboundsmd)): *boolean*

判断与另一个包围盒是否相交

##### Parameters

| Name | Type |
| :------ | :------ |
| `bound` | [*GeoBounds*](#classesdefaultgeoboundsmd) |

**Returns:** *boolean*

___

#### leftBottom

▸ **leftBottom**(): [*GeoPoint*](#classesdefaultgeopointmd)

得到左下角

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### leftTop

▸ **leftTop**(): [*GeoPoint*](#classesdefaultgeopointmd)

得到左上角

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### randomGeoJsonLineCollection

▸ **randomGeoJsonLineCollection**(`maxLineCount`: *number*, `maxPointCount`: *number*, `xRatio?`: *number*, `yRatio?`: *number*, `propertiesCb?`: (`index`: *number*) => Object, `minLineCount?`: *number*, `minPointCount?`: *number*): GeoJsonGeomertry

生成一个随机geojson线集合

##### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `maxLineCount` | *number* | - | 最多线的数目 |
| `maxPointCount` | *number* | - | 每条线最多的点的数目 |
| `xRatio` | *number* | 0.6 | x轴范围比例 缺省 0.6 |
| `yRatio` | *number* | 0.6 | y轴范围比例 缺省 0.6 |
| `propertiesCb?` | (`index`: *number*) => Object | - | 属性回调函数 |
| `minLineCount?` | *number* | - | 最少线的数目（缺省为1) |
| `minPointCount?` | *number* | - | 每条线最少的点的数目（缺省为2) |

**Returns:** GeoJsonGeomertry

___

#### randomGeoJsonPointCollection

▸ **randomGeoJsonPointCollection**(`count`: *number*, `xRatio?`: *number*, `yRatio?`: *number*, `propertiesCb?`: (`index`: *number*) => Object): GeoJsonGeomertry

生成一个随机geojson点集合

##### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `count` | *number* | - | 点的数目 |
| `xRatio` | *number* | 0.6 | x轴范围比例 缺省 0.6 |
| `yRatio` | *number* | 0.6 | y轴范围比例 缺省 0.6 |
| `propertiesCb?` | (`index`: *number*) => Object | - | 属性回调函数 |

**Returns:** GeoJsonGeomertry

___

#### randomGeoJsonPolygonCollection

▸ **randomGeoJsonPolygonCollection**(`maxPolygonCount`: *number*, `maxPointCount`: *number*, `xRatio?`: *number*, `yRatio?`: *number*, `propertiesCb?`: (`index`: *number*) => Object, `minPolygonCount?`: *number*, `minPointCount?`: *number*): GeoJsonGeomertry

生成一个随机geojson多边形集合

##### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `maxPolygonCount` | *number* | - | 最多多边形的数目 |
| `maxPointCount` | *number* | - | 每条线最多的点的数目 |
| `xRatio` | *number* | 0.6 | x轴范围比例 缺省 0.6 |
| `yRatio` | *number* | 0.6 | y轴范围比例 缺省 0.6 |
| `propertiesCb?` | (`index`: *number*) => Object | - | 属性回调函数 |
| `minPolygonCount?` | *number* | - | 最少多边形的数目(缺省为1) |
| `minPointCount?` | *number* | - | 每条线最少的点的数目(缺省为3) |

**Returns:** GeoJsonGeomertry

___

#### randomPoint

▸ **randomPoint**(`xRatio?`: *number*, `yRatio?`: *number*): [*GeoPoint*](#classesdefaultgeopointmd)

生成一个随机点

##### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `xRatio` | *number* | 0.6 | x轴范围比例 缺省 0.6 |
| `yRatio` | *number* | 0.6 | y轴范围比例 缺省 0.6 |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### randomPoints

▸ **randomPoints**(`minPointCount`: *number*, `maxPointCount`: *number*, `xRatio?`: *number*, `yRatio?`: *number*): [*GeoPoint*](#classesdefaultgeopointmd)[]

生成一个随机点序列

##### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `minPointCount` | *number* | - | 最少的点数 |
| `maxPointCount` | *number* | - | 最多的点数 |
| `xRatio` | *number* | 0.6 | x轴范围比例 缺省 0.6 |
| `yRatio` | *number* | 0.6 | y轴范围比例 缺省 0.6 |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)[]

___

#### rightBottom

▸ **rightBottom**(): [*GeoPoint*](#classesdefaultgeopointmd)

得到右下角

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### rightTop

▸ **rightTop**(): [*GeoPoint*](#classesdefaultgeopointmd)

得到右上角

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### scale

▸ **scale**(`ratio`: *number*, `origin?`: ``null`` \| [*GeoPoint*](#classesdefaultgeopointmd)): [*GeoBounds*](#classesdefaultgeoboundsmd)

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

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `ratio` | *number* | 比例 |
| `origin?` | ``null`` \| [*GeoPoint*](#classesdefaultgeopointmd) | 扩大时的基准点，默认为当前 bounds 的中心点 |

**Returns:** [*GeoBounds*](#classesdefaultgeoboundsmd)

___

#### scaleXY

▸ **scaleXY**(`ratioX`: *number*, `ratioY`: *number*, `origin?`: ``null`` \| [*GeoPoint*](#classesdefaultgeopointmd)): [*GeoBounds*](#classesdefaultgeoboundsmd)

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

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `ratioX` | *number* | X比例 |
| `ratioY` | *number* | Y比例 |
| `origin?` | ``null`` \| [*GeoPoint*](#classesdefaultgeopointmd) | 扩大时的基准点，默认为当前 bounds 的中心点 |

**Returns:** [*GeoBounds*](#classesdefaultgeoboundsmd)

___

#### set

▸ **set**(`min`: [*GeoPoint*](#classesdefaultgeopointmd), `max`: [*GeoPoint*](#classesdefaultgeopointmd)): *void*

设置包围盒范围

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `min` | [*GeoPoint*](#classesdefaultgeopointmd) | 最小值 |
| `max` | [*GeoPoint*](#classesdefaultgeopointmd) | 最大值 |

**Returns:** *void*

___

#### square

▸ **square**(`isLatlng?`: *boolean*, `isMinValue?`: *boolean*): [*GeoBounds*](#classesdefaultgeoboundsmd)

变成正方形，使宽高相等

**`return{geobounds}`**

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `isLatlng?` | *boolean* | 是否是经纬度 |
| `isMinValue?` | *boolean* | 是否取宽高的最小值或最大值，默认最大值 |

**Returns:** [*GeoBounds*](#classesdefaultgeoboundsmd)

___

#### toArray

▸ **toArray**(): *number*[]

返回数组

**Returns:** *number*[]

The coordinates represented as a array of the format `[minx, miny, maxx, maxy]'`.

___

#### toPointArray

▸ **toPointArray**(): [*number*, *number*][]

返回点数组，包括四个顶点

**Returns:** [*number*, *number*][]

The coordinates represented as a array of the format `[[minx,maxy], [maxx,maxy], [maxx,miny], [minx,miny]]'`.

___

#### toString

▸ **toString**(`fixed?`: *number*): *string*

返回字符串.

##### Parameters

| Name | Type | Default value |
| :------ | :------ | :------ |
| `fixed` | *number* | 6 |

**Returns:** *string*

The coordinates represented as a string of the format `minx, miny, maxx, maxy'`.

___

#### translate

▸ **translate**(`dx`: *number*, `dy`: *number*): *void*

位移包围盒

##### Parameters

| Name | Type |
| :------ | :------ |
| `dx` | *number* |
| `dy` | *number* |

**Returns:** *void*

___

#### union

▸ **union**(`bound`: [*GeoBounds*](#classesdefaultgeoboundsmd)): [*GeoBounds*](#classesdefaultgeoboundsmd)

求多个包围盒的并集

##### Parameters

| Name | Type |
| :------ | :------ |
| `bound` | [*GeoBounds*](#classesdefaultgeoboundsmd) |

**Returns:** [*GeoBounds*](#classesdefaultgeoboundsmd)

___

#### update

▸ **update**(`vertices`: [*GeoPoint*](#classesdefaultgeopointmd)[]): *void*

更新包围盒

##### Parameters

| Name | Type |
| :------ | :------ |
| `vertices` | [*GeoPoint*](#classesdefaultgeopointmd)[] |

**Returns:** *void*

___

#### updateByBounds

▸ **updateByBounds**(`bounds`: [*GeoBounds*](#classesdefaultgeoboundsmd) \| [*GeoBounds*](#classesdefaultgeoboundsmd)[]): *void*

根据子包围盒更新包围盒

##### Parameters

| Name | Type |
| :------ | :------ |
| `bounds` | [*GeoBounds*](#classesdefaultgeoboundsmd) \| [*GeoBounds*](#classesdefaultgeoboundsmd)[] |

**Returns:** *void*

___

#### width

▸ **width**(): *number*

 获取宽度

**Returns:** *number*

___

#### fromArray

▸ `Static` **fromArray**(`input`: [*number*, *number*, *number*, *number*]): [*GeoBounds*](#classesdefaultgeoboundsmd)

根据数组创建 `GeoBounds`.

Example:
```typescript
const b = GeoBounds.fromArray([left, bottom, right, top]);
```

##### Parameters

| Name | Type |
| :------ | :------ |
| `input` | [*number*, *number*, *number*, *number*] |

**Returns:** [*GeoBounds*](#classesdefaultgeoboundsmd)

___

#### fromCenterWH

▸ `Static` **fromCenterWH**(`center`: [*GeoPointLike*](#geopointlike), `width`: *number*, `height?`: *number*): [*GeoBounds*](#classesdefaultgeoboundsmd)

根据中心点和长，宽生成bounds

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `center` | [*GeoPointLike*](#geopointlike) | 中心点 |
| `width` | *number* | 宽 |
| `height?` | *number* | 高，不输入时与宽一样 |

**Returns:** [*GeoBounds*](#classesdefaultgeoboundsmd)

___

#### fromDataExtent

▸ `Static` **fromDataExtent**(`input`: [*GeoPoint*](#classesdefaultgeopointmd) \| *Feature*<Geometry \| GeometryCollection, Properties\> \| *FeatureCollection*<Geometry \| GeometryCollection, Properties\> \| Geometry \| GeometryCollection \| [*number*, *number*] \| [*number*, *number*, *number*] \| { `x`: *number* ; `y`: *number* ; `z?`: *number*  } \| { `lat`: *number* ; `lng`: *number*  } \| { `lat`: *number* ; `lon`: *number*  } \| [*GeoPointLike*](#geopointlike)[]): [*GeoBounds*](#classesdefaultgeoboundsmd)

根据数据范围来生成bounds

##### Parameters

| Name | Type |
| :------ | :------ |
| `input` | [*GeoPoint*](#classesdefaultgeopointmd) \| *Feature*<Geometry \| GeometryCollection, Properties\> \| *FeatureCollection*<Geometry \| GeometryCollection, Properties\> \| Geometry \| GeometryCollection \| [*number*, *number*] \| [*number*, *number*, *number*] \| { `x`: *number* ; `y`: *number* ; `z?`: *number*  } \| { `lat`: *number* ; `lng`: *number*  } \| { `lat`: *number* ; `lon`: *number*  } \| [*GeoPointLike*](#geopointlike)[] |

**Returns:** [*GeoBounds*](#classesdefaultgeoboundsmd)

___

#### fromString

▸ `Static` **fromString**(`input`: *string*): [*GeoBounds*](#classesdefaultgeoboundsmd)

根据数组创建 `GeoBounds`.

Example:
```typescript
const b = GeoBounds.fromString("[1,2,3,4]");
```

##### Parameters

| Name | Type |
| :------ | :------ |
| `input` | *string* |

**Returns:** [*GeoBounds*](#classesdefaultgeoboundsmd)


<a name="classesgeopointmd"></a>

[vjmap](#readmemd) / [Exports](#modulesmd) / GeoPoint
