---
title: Class: Polygon
source: https://vjmap.com/en/doc/Class_Polygon.html
---

# Class: Polygon

创建多边形.

### Hierarchy

- [*OverlayLayerBase*](#classesdefaultoverlaylayerbasemd)

  ↳ **Polygon**

### Table of contents

#### Constructors

- [constructor](#constructor)

#### Properties

- [\_map](#_map)
- [layerId](#layerid)
- [options](#options)
- [sourceId](#sourceid)

#### Methods

- [addTo](#addto)
- [clickLayer](#clicklayer)
- [clickPopup](#clickpopup)
- [getData](#getdata)
- [getFillAntialias](#getfillantialias)
- [getFillColor](#getfillcolor)
- [getFillOpacity](#getfillopacity)
- [getFillOutlineColor](#getfilloutlinecolor)
- [getFillPattern](#getfillpattern)
- [getFillSortKey](#getfillsortkey)
- [getFillTranslate](#getfilltranslate)
- [getFillTranslateAnchor](#getfilltranslateanchor)
- [getLayerId](#getlayerid)
- [getLayerStyle](#getlayerstyle)
- [getSourceId](#getsourceid)
- [hide](#hide)
- [hoverFeatureState](#hoverfeaturestate)
- [hoverLayer](#hoverlayer)
- [hoverPointer](#hoverpointer)
- [hoverPopup](#hoverpopup)
- [remove](#remove)
- [setData](#setdata)
- [setFillAntialias](#setfillantialias)
- [setFillColor](#setfillcolor)
- [setFillOpacity](#setfillopacity)
- [setFillOutlineColor](#setfilloutlinecolor)
- [setFillPattern](#setfillpattern)
- [setFillSortKey](#setfillsortkey)
- [setFillTranslate](#setfilltranslate)
- [setFillTranslateAnchor](#setfilltranslateanchor)
- [setFilter](#setfilter)
- [setLayerStyle](#setlayerstyle)
- [setProperty](#setproperty)
- [show](#show)
- [toggle](#toggle)

### Constructors

#### constructor

\+ **new Polygon**(`options`: [*PolygonOptions*](#interfacesdefaultpolygonoptionsmd)): [*Polygon*](#classesdefaultpolygonmd)

##### Parameters

| Name | Type |
| :------ | :------ |
| `options` | [*PolygonOptions*](#interfacesdefaultpolygonoptionsmd) |

**Returns:** [*Polygon*](#classesdefaultpolygonmd)

Overrides: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

### Properties

#### \_map

• `Optional` **\_map**: *Map*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd).[_map](#_map)

___

#### layerId

• `Optional` **layerId**: *string*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd).[layerId](#layerid)

___

#### options

• **options**: [*PolygonOptions*](#interfacesdefaultpolygonoptionsmd)

___

#### sourceId

• `Optional` **sourceId**: *string*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd).[sourceId](#sourceid)

### Methods

#### addTo

▸ **addTo**(`map`: *Map*, `beforeId?`: *string*): *void*

##### Parameters

| Name | Type |
| :------ | :------ |
| `map` | *Map* |
| `beforeId?` | *string* |

**Returns:** *void*

Overrides: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### clickLayer

▸ **clickLayer**(`cb`: *any*): *any*

每当单击这些图层中的要素时都会触发回调。

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `cb` | *any* | Callback that receives event with .features property |

**Returns:** *any*

A function that removes the handler.

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### clickPopup

▸ **clickPopup**(`htmlFunc`: (`arg0`: {}) => *void*, `popupOptions?`: PopupOptions): *any*

每当单击这些图层中的要素时都会显示一个弹出窗口。

**`example`** clickPopup(f => `<h3>${f.properties.Name}</h3> ${f.properties.Description}`, { maxWidth: 500 });

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `htmlFunc` | (`arg0`: {}) => *void* | Function that receives feature and popup, returns HTML. |
| `popupOptions?` | PopupOptions | Options passed to `Popup()` to customise popup. |

**Returns:** *any*

A function that removes the handler.

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### getData

▸ **getData**(): *undefined* \| *Feature*<Geometry \| GeometryCollection, Properties\> \| *FeatureCollection*<Geometry \| GeometryCollection, Properties\> \| Geometry \| GeometryCollection

获取数据源的数据

**Returns:** *undefined* \| *Feature*<Geometry \| GeometryCollection, Properties\> \| *FeatureCollection*<Geometry \| GeometryCollection, Properties\> \| Geometry \| GeometryCollection

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### getFillAntialias

▸ **getFillAntialias**(): [*PropertyValueSpecificationEx*](#propertyvaluespecificationex)<boolean\>

获取图层的“填充抗锯齿”绘制属性。

**Returns:** [*PropertyValueSpecificationEx*](#propertyvaluespecificationex)<boolean\>

___

#### getFillColor

▸ **getFillColor**(): [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\>

获取图层的 `fill-color` 绘制属性。

**Returns:** [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\>

___

#### getFillOpacity

▸ **getFillOpacity**(): [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<number\>

获取图层的 `fill-opacity` 绘制属性。

**Returns:** [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<number\>

___

#### getFillOutlineColor

▸ **getFillOutlineColor**(): [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\>

获取图层的 `fill-outline-color` 绘制属性。

**Returns:** [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\>

___

#### getFillPattern

▸ **getFillPattern**(): [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\>

获取图层的`fill-pattern` 绘制属性。

**Returns:** [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\>

___

#### getFillSortKey

▸ **getFillSortKey**(): [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<number\>

获取图层的`fill-sort-key` 布局属性.

**Returns:** [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<number\>

___

#### getFillTranslate

▸ **getFillTranslate**(): [*PropertyValueSpecificationEx*](#propertyvaluespecificationex)<[*number*, *number*]\>

获取图层的 `fill-translate` 绘制属性。

**Returns:** [*PropertyValueSpecificationEx*](#propertyvaluespecificationex)<[*number*, *number*]\>

___

#### getFillTranslateAnchor

▸ **getFillTranslateAnchor**(): [*PropertyValueSpecificationEx*](#propertyvaluespecificationex)<``"map"`` \| ``"viewport"``\>

获取图层的 `fill-translate-anchor` 绘制属性。

**Returns:** [*PropertyValueSpecificationEx*](#propertyvaluespecificationex)<``"map"`` \| ``"viewport"``\>

___

#### getLayerId

▸ **getLayerId**(): *undefined* \| *string*

获取图层ID

**Returns:** *undefined* \| *string*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### getLayerStyle

▸ **getLayerStyle**(): [*LayerSpecification*](#layerspecification)

根据样式规范，获取给定图层 ID 的图层定义。

**Returns:** [*LayerSpecification*](#layerspecification)

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### getSourceId

▸ **getSourceId**(): *undefined* \| *string*

获取数据源ID

**Returns:** *undefined* \| *string*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### hide

▸ **hide**(): *void*

使给定的图层不可见。

**Returns:** *void*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### hoverFeatureState

▸ **hoverFeatureState**(`enterCb?`: (`arg0`: {}) => *void*, `leaveCb?`: (`arg0`: {}) => *void*): *void*

每当将鼠标悬停在这些图层中的某个特征上时，更新连接源 [s] 中特征的特征状态。

##### Parameters

| Name | Type |
| :------ | :------ |
| `enterCb?` | (`arg0`: {}) => *void* |
| `leaveCb?` | (`arg0`: {}) => *void* |

**Returns:** *void*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### hoverLayer

▸ **hoverLayer**(`cb`: *any*): *any*

当鼠标悬停在这些图层中的要素上时触发回调。

##### Parameters

| Name | Type |
| :------ | :------ |
| `cb` | *any* |

**Returns:** *any*

A function to remove the handler.

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### hoverPointer

▸ **hoverPointer**(): *void*

每当鼠标悬停在这些图层上时，将地图的光标设置为“指针”。

**Returns:** *void*

A function to remove the handler.

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### hoverPopup

▸ **hoverPopup**(`htmlFunc`: *any*, `popupOptions?`: PopupOptions): *any*

将鼠标悬停在这些图层中的某个要素上时，会显示一个弹出窗口。

**`example`** hoverPopup(f => `<h3>${f.properties.Name}</h3> ${f.properties.Description}`, { anchor: 'left' });

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `htmlFunc` | *any* | Function that receives feature and popup, returns HTML. |
| `popupOptions?` | PopupOptions | Options passed to `Popup()` to customise popup. |

**Returns:** *any*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### remove

▸ **remove**(): *void*

**Returns:** *void*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### setData

▸ **setData**(`data`: *any*): *void*

替换 GeoJSON 图层的当前数据。

##### Parameters

| Name | Type |
| :------ | :------ |
| `data` | *any* |

**Returns:** *void*

___

#### setFillAntialias

▸ **setFillAntialias**(`value`: [*PropertyValueSpecificationEx*](#propertyvaluespecificationex)<boolean\>): [*Polygon*](#classesdefaultpolygonmd)

为一个或多个图层设置`fill-antialias` 绘制属性。

##### Parameters

| Name | Type |
| :------ | :------ |
| `value` | [*PropertyValueSpecificationEx*](#propertyvaluespecificationex)<boolean\> |

**Returns:** [*Polygon*](#classesdefaultpolygonmd)

___

#### setFillColor

▸ **setFillColor**(`value`: [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\>): [*Polygon*](#classesdefaultpolygonmd)

为一个或多个图层设置`fill-color` 绘画属性。

##### Parameters

| Name | Type |
| :------ | :------ |
| `value` | [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\> |

**Returns:** [*Polygon*](#classesdefaultpolygonmd)

___

#### setFillOpacity

▸ **setFillOpacity**(`value`: [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<number\>): [*Polygon*](#classesdefaultpolygonmd)

为一个或多个图层设置`fill-opacity` 绘画属性。

##### Parameters

| Name | Type |
| :------ | :------ |
| `value` | [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<number\> |

**Returns:** [*Polygon*](#classesdefaultpolygonmd)

___

#### setFillOutlineColor

▸ **setFillOutlineColor**(`value`: [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\>): [*Polygon*](#classesdefaultpolygonmd)

为一个或多个图层设置`fill-outline-color` 绘画属性。

##### Parameters

| Name | Type |
| :------ | :------ |
| `value` | [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\> |

**Returns:** [*Polygon*](#classesdefaultpolygonmd)

___

#### setFillPattern

▸ **setFillPattern**(`value`: [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\>): [*Polygon*](#classesdefaultpolygonmd)

为一个或多个图层设置`fill-pattern` 绘制属性。

##### Parameters

| Name | Type |
| :------ | :------ |
| `value` | [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\> |

**Returns:** [*Polygon*](#classesdefaultpolygonmd)

___

#### setFillSortKey

▸ **setFillSortKey**(`value`: [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<number\>): [*Polygon*](#classesdefaultpolygonmd)

为一层或多层设置`fill-sort-key`布局属性。

##### Parameters

| Name | Type |
| :------ | :------ |
| `value` | [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<number\> |

**Returns:** [*Polygon*](#classesdefaultpolygonmd)

___

#### setFillTranslate

▸ **setFillTranslate**(`value`: [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\>): [*Polygon*](#classesdefaultpolygonmd)

为一个或多个图层设置`fill-translate` 绘制属性。

##### Parameters

| Name | Type |
| :------ | :------ |
| `value` | [*DataDrivenPropertyValueSpecification*](#datadrivenpropertyvaluespecification)<string\> |

**Returns:** [*Polygon*](#classesdefaultpolygonmd)

___

#### setFillTranslateAnchor

▸ **setFillTranslateAnchor**(`value`: [*PropertyValueSpecificationEx*](#propertyvaluespecificationex)<``"map"`` \| ``"viewport"``\>): [*Polygon*](#classesdefaultpolygonmd)

为一个或多个图层设置`fill-translate-anchor` 绘制属性。

##### Parameters

| Name | Type |
| :------ | :------ |
| `value` | [*PropertyValueSpecificationEx*](#propertyvaluespecificationex)<``"map"`` \| ``"viewport"``\> |

**Returns:** [*Polygon*](#classesdefaultpolygonmd)

___

#### setFilter

▸ **setFilter**(`filter`: [*FilterSpecification*](#filterspecification)): *void*

替换一个图层的过滤器。

**`example`** setFilter(['==','level','0']]);

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `filter` | [*FilterSpecification*](#filterspecification) | New filter to set. |

**Returns:** *void*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### setLayerStyle

▸ **setLayerStyle**(`style`: *any*): *void*

设置图层样式

##### Parameters

| Name | Type |
| :------ | :------ |
| `style` | *any* |

**Returns:** *void*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### setProperty

▸ **setProperty**(`prop`: *string* \| *object*, `value?`: *any*): *void*

在一个或多个图层上设置绘制或布局属性。

**`example`** setProperty('fillOpacity', 0.5)

##### Parameters

| Name | Type |
| :------ | :------ |
| `prop` | *string* \| *object* |
| `value?` | *any* |

**Returns:** *void*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### show

▸ **show**(): *void*

使给定的图层可见。

**Returns:** *void*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)

___

#### toggle

▸ **toggle**(`state`: *boolean*): *boolean*

根据参数使给定的图层隐藏或可见。

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `state` | *boolean* | True for visible, false for hidden. |

**Returns:** *boolean*

Inherited from: [OverlayLayerBase](#classesdefaultoverlaylayerbasemd)


<a name="classespolylinemd"></a>

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