feature~PolygonFeature(geometry, attributes, style)

面地理要素类。

Summary

Methods:
clone

克隆一个新的feature要素,新要素与原有要素有相同。

copyTo

复制一个Feature,将得到的feature的地理范围中心变成传参的coordinate。该方法是以要素几何体的中心坐标到目标坐标为基准移动的,复制不影响原来的地理要素。

getStyle

获取当前要素的样式。

setStyle

设置地理要素的样式。该要素原有的样式会被给出的样式替代。

Constructor

new PolygonFeature(geometry, attributes, style)

Parameters:
Name Type Description
geometry module:geom~Geometry

地理几何体。

attributes Object

一个对象,用来描述地理要素的非空间属性。

style module:style~Style

用来描述地理要素在地图上表现形态。当添加到图层上时,如果不指定样式,则采用默认的图层样式。

Example
const polygon = new hmap.geom.Polygon([ring, ringHole]);
const featureStyle = {
    polygon: {
        fillColor: [73, 151, 191, 1],
        outlineWidth: 12,
        outlineColor: [31, 72, 98, 1],
    },
    label: {
        name: '面要素',
        fontColor: [31, 72, 98, 1],
        fontSize: 16,
        opacity: 1,
    },
};
polyFeature1 = new hmap.feature.PolygonFeature(polygon, {}, featureStyle);

Methods

clone() → {module:feature~Vector}

克隆一个新的feature要素,新要素与原有要素有相同。

Returns:
module:feature~Vector -

新的地理要素

Example
let newFeature = feature.clone();

copyTo(coordinate) → {module:feature~Vector}

复制一个Feature,将得到的feature的地理范围中心变成传参的coordinate。该方法是以要素几何体的中心坐标到目标坐标为基准移动的,复制不影响原来的地理要素。

Parameters:
Name Type Description
coordinate module:basetype~Coordinate

目标地理坐标。

Returns:
module:feature~Vector -

新地理要素

Example
let coordinate = new hmap.basetype.Coordinate(121,31,0);
let result = feature.copyTo(coordinate);

getStyle() → {object}

获取当前要素的样式。

Returns:
object -

样式

Example
let style = feature.getStyle();

setStyle(style)

设置地理要素的样式。该要素原有的样式会被给出的样式替代。

Parameters:
Name Type Description
style object

样式

Throws:

当参数style不是Style实例时,抛出异常:"the parameter style is neither an instance of Style nor null"

Example
feature.setStyle(style);