Class: Polygon

Polygon

用于绘制多边形要素,可以绘制出任何嵌套孔的线性环的层次结构, 绘制的多边形可以贴地、可以高空、可以拉升高度等。

// 添加图层
const layer = new EntityLayer().addToViewer(this.$viewer);
const polygon = new Polygon([
  new Position(118.78485929, 31.91394225, 0.24679262),
  new Position(118.7870894, 31.9140142, 0.00090438),
  new Position(118.78630686, 31.91318961, -0.10361775),
  new Position(118.78555958, 31.91317366, 0.3106204)
]).addToLayer(layer);
polygon.setStyle({
  material: Color.fromCssColor("rgba(241,12,12,0.5)"),
  outline: true
});
// 添加 holes
polygon.holes = [
  {
    positions: [
      new Position(118.78550702, 31.91376746, 0.09033209),
      new Position(118.78629252, 31.91377867, 1.01690474),
      new Position(118.78633432, 31.91338977, 0.07308486),
      new Position(118.78566242, 31.91329406, -0.06661843)
    ],
    holes: [
      {
        positions: [
          new Position(118.78586977, 31.91364417, -0.0788724),
          new Position(118.78609329, 31.91362571, -0.07865482),
          new Position(118.78596527, 31.91351248, -0.07844403)
        ]
      }
    ]
  }
];
// 注册 polygon 鼠标移入事件
polygon.on(MouseEventType.CLICK, evt => {
  console.log(evt);
});

new Polygon(positions)

overlay/base/Polygon.js, line 58
Name Type Description
positions Array.<Position>

多边形坐标串

Extends

Classes

Polygon

Members

attr

覆盖物的额外属性设置

readonlycenter

多边形中心点

readonlydelegate

覆盖物的代理对象

holes

多边形洞坐标串,格式参照示例代码

id

设置覆盖物的业务 id

readonlyoverlayEvent

覆盖物的事件对象

readonlyoverlayId

覆盖物唯一标识

positionsArray.<Position>

多边形坐标串

show

覆盖物的可见性

readonlystate

覆盖物的状态

Methods

staticPolygon.fromEntity(entity){any}

overlay/base/Polygon.js, line 219

从 entity 中解析出 Polygon

Name Type Description
entity Entity
Returns:
Type Description
any

inherited addToLayer(layer){Overlay}

overlay/Overlay.js, line 242

添加到指定图层

Name Type Description
layer EntityLayer

指定图层

Returns:
Type Description
Overlay

inherited fire(type, params){Overlay}

overlay/Overlay.js, line 282

触发事件

Name Type Description
type *
params *
Returns:
Type Description
Overlay

inherited off(type, callback, context){Overlay}

overlay/Overlay.js, line 270

注销事件

Name Type Description
type *

事件类型

callback *

监听回调

context *
Returns:
Type Description
Overlay

inherited on(type, callback, context){Overlay}

overlay/Overlay.js, line 257

注册事件

Name Type Description
type *

事件类型

callback *

监听回调

context *
Returns:
Type Description
Overlay

inherited remove(){Overlay}

overlay/Overlay.js, line 229

从图层上移出

Returns:
Type Description
Overlay

setLabel(text, textStyle){Polygon}

overlay/base/Polygon.js, line 164

设置文字标签

Name Type Description
text Property | string

指定文本的属性。支持显式换行符'\ n'。

textStyle Object

text 样式

Returns:
Type Description
Polygon

setStyle(style){Polygon}

overlay/base/Polygon.js, line 203

设置 Polygon 的样式

Name Type Description
style Object

样式可选属性

// 样式参数(可选)
{
  "height": 1, //高度
  "heightReference": 0, //高度参照,0:位置无参照,位置是绝对的,1:位置固定在地形上 2:位置高度是指地形上方的高度。
  "extrudedHeight": 0, //拉升高度
  "extrudedHeightReference": 0, // 拉伸的高度模式。 NONE: 0, CLAMP_TO_GROUND: 1, RELATIVE_TO_GROUND: 2
  "stRotation": 0, //旋转角度
  "fill": true, //是否用提供的材料填充多边形。
  "material": Color.WHITE, //材质
  "outline": false, //是否显示边框
  "outlineColor": Color.BLACK, //边框颜色
  "outlineWidth": 0, //边框宽度
  "closeTop": true, //顶面是否闭合
  "closeBottom": true, //底面是否闭合
  "arcType": 1, // 指定 polygon 线条类型。NONE: 0, GEODESIC: 1, RHUMB: 2
  "shadows": 0, //阴影类型,0:禁用、1:启用 、2:投射、3:接受
  "distanceDisplayCondition": {
    "near": 0, //最近距离
    "far": Number.MAX_VALUE //最远距离
  }, //根据距离设置可见
  "classificationType": 2, //分类 是否影响地形,3D切片或同时影响这两者。0:地形、1:3D切片、2:两者
  "zIndex": 0 //层级
}
Returns:
Type Description
Polygon