Class: Feature

Feature

new Feature(options)

base/feature/Feature.js, line 9

要素对象,封装单个空间要素的几何、属性、样式与高程信息,适用于图层渲染、要素编辑与服务交互场景,示例如下:[初始化要素对象]

Name Type Default Description
options Object {} 可选

构造参数

Name Type Default Description
id String 可选

要素的id,不给则给一个随机的默认id

attributes Object {} 可选

要素的属性

geometry Geometry 可选

要素的几何对象,支持如下:
矩形范围线多线多点多区

symbol Symbol {} 可选

客户端要素渲染样式,当使用GraphicsLayer图层绘制要素时,设置此参数来决定渲染结果,支持如下:
图片Marker符号简单Marker符号简单填充符号简单线符号文本符号

visible Boolean true 可选

要素是否可见

elevationInfo ElevationInfo 可选

高程模式参数

styleInfo Object 可选

服务端要素渲染样式,说明如下:
1、当使用FeatureServer的查询操作并返回要素时,styleInfo会记录查询到的服务端要素渲染样式 2、当执行FeatureServer的要素编辑操作时,设置此参数来更改要素样式,具体参数说明请参考IGS文档

extensionOptions Object {} 可选

初始化额外参数,可以通过该参数传入引擎原生的构造参数

Example

创建几何对象

// ES5引入方式
const { Feature, Color } = zondy
const { LineString } = zondy.geometry
const { SimpleLineSymbol } = zondy.symbol

// ES6引入方式
import { Feature, Color, LineString, SimpleLineSymbol } from "@mapgis/webclient-common"
let feature = new Feature({
  //不填则创建一个随机的guid
  id: "你的id",
  //设置属性
  attributes: {},
  //构建几何
  geometry: new LineString({
    coordinates: [[112.0, 30.0], [113.0, 30.0], [113.0, 31.0]]
  }),
  //设置样式
  symbol: new SimpleLineSymbol({
    //设置颜色
    color: new Color(255, 0, 0, 1),
    //设置线宽
    width: 2
  })
})

Members

additionalObject

额外属性,其中的arc3表示三点弧的信息

attributesObject

要素的属性 default {}

elevationInfoElevationInfo

高程模式参数

extensionOptionsObject

初始化额外参数,可以通过该参数传入引擎原生的构造参数

Default Value:
{}

geometryGeometry

要素的几何对象

idString

要素id default 随机id

styleInfoObject

服务端要素的样式,用于IGS的要素编辑操作,具体参数说明请参考IGS文档

symbolSymbol

要素的样式

typeString

对象类型

visibleBoolean

要素是否可见 default = true

Methods

clone(){Feature}

base/feature/Feature.js, line 225

克隆并返回新要素

Returns:
Type Description
Feature 与当前要素数据相同的新实例

fromGeoJSON(geoJSON)

base/feature/Feature.js, line 336

从geoJSON对象中导入数据

Name Type Description
geoJSON Object

GeoJSON 要素对象

Example

从geoJSON对象中导入数据

// ES5引入方式
const { Feature } = zondy

// ES6引入方式
import { Feature } from "@mapgis/webclient-common"
//数据格式参考https://geojson.org/
const feature = new Feature();
feature.fromGeoJSON({
  type: "Feature",
  geometry: {
    type: "LineString",
    coordinates: [
      [114.329481, 30.711953],
      [114.342372, 30.684553],
      [114.341474, 30.674527],
      [114.338273, 30.665863],
      [114.334533, 30.655893],
      [114.330017, 30.643386],
      [114.322936, 30.631171],
      [114.318749, 30.625032],
      [114.313923, 30.617818],
      [114.308156, 30.608404],
      [114.301348, 30.598718],
      [114.295038, 30.592581],
      [114.285992, 30.585234],
      [114.278415, 30.580865],
      [114.270119, 30.577433],
      [114.261901, 30.573909],
      [114.250444, 30.571547],
      [114.240741, 30.574025],
      [114.224975, 30.580306],
      [114.218822, 30.585491],
      [114.211532, 30.589347],
      [114.20474, 30.593382],
      [114.196667, 30.597536],
      [114.183062, 30.604521],
      [114.169464, 30.609907],
      [114.163868, 30.615064],
      [114.155941, 30.61846],
      [114.138907, 30.617699],
      [114.128567, 30.624968],
      [114.123644, 30.631684],
      [114.120804, 30.649056],
      [114.120828, 30.659055],
    ],
  },
  properties: {
    ln: "1号线",
    su: "1",
    kn: "轨道交通1号线",
    ls: "420100034364",
    cl: "3080B7",
    la: "",
    x: 1,
    li: "420100034364|420100034365",
    color: "#3080B7",
  },
});

toAttValue(){Array}

base/feature/Feature.js, line 459

导出为 IGS1.0 要素属性值数组

Returns:
Type Description
Array IGS1.0 属性值数组

toFType(){Number}

base/feature/Feature.js, line 476

导出为 IGS1.0 几何类型编码

Returns:
Type Description
Number IGS1.0 几何类型编码

toGeoJSON(){Object}

base/feature/Feature.js, line 359

导出为 GeoJSON 数据

Returns:
Type Description
Object GeoJSON 要素对象;几何坐标会自动转换为 EPSG:4326
Example

导出为GeoJSON数据

//导出为GeoJSON数据
let geojson = feature.toGeoJSON();

toGraphicInfo(){Object}

base/feature/Feature.js, line 424

导出为 IGS1.0 要素图形信息

Returns:
Type Description
Object IGS1.0 图形信息对象

toIGSFeature(){Object}

base/feature/Feature.js, line 382

导出为 IGS 服务接口要素对象

Returns:
Type Description
Object IGS 2.x 服务可直接消费的要素对象

toJSON(){Object}

base/feature/Feature.js, line 233

导出为标准 JSON 对象

Returns:
Type Description
Object 可用于序列化存储或网络传输的 JSON 对象

toOldIGSFeature(){Object}

base/feature/Feature.js, line 409

导出为 IGS1.0 服务接口要素对象

Returns:
Type Description
Object IGS1.0 要素对象

Feature.fromJSON(json)

base/feature/Feature.js, line 268

通过传入的 JSON 构造并返回一个新的要素对象

Name Type Description
json Object

要素 JSON 对象

Example
通过传入的 JSON 构造并返回一个新的要素对象\
// ES5引入方式
const { LineString } = zondy.geometry
const { Feature } = zondy

// ES6引入方式
import { LineString, Feature } from "@mapgis/webclient-common"
const json = {
  //设置属性
  attributes: {},
  //构建几何
  geometry: new LineString({
    coordinates: [[112.0, 30.0], [113.0, 30.0], [113.0, 31.0]]
  })
}
const feature = Feature.fromJSON(json)