类名 FeatureSet

# new FeatureSet(options)

要素集合类,示例如下:[初始化要素集合对象]

[ES5引入方式]:
zondy.FeatureSet()
[ES6引入方式]:
import { FeatureSet } from "@mapgis/webclient-common"

参数:

名称 类型 默认值 描述
options Object

构造参数

id String

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

features Array []

要素数组

spatialReference SpatialReference new zondy.SpatialReference('EPSG:4326')

要素集合的参考系, 默认为4326,当要素的几何对象上制定了参考系时,用要素上的;当要素的集合对象上没有指定参考系时,则使用该参考系

支持如下方法:
[1、通过ID寻找要素]
[3、从geoJSON对象中导入数据]
[4、导出为GeoJSON数据]
[5、将一个要素数组对象转为要素集合]
[6、导出一个JSON对像]
[7、克隆并返回新的要素集合]
[8、通过传入的json构造并返回一个新的几何对象]

示例

初始化要素集合对象

// ES5引入方式
const { FeatureSet } = zondy
// ES6引入方式
import { FeatureSet } from "@mapgis/webclient-common"
//创建要素集合
let featureSet = new FeatureSet({
  //不填则创建一个随机的guid
  id: "你的id",
  //要素集合
  features: []
})

成员变量

Array

# features

要素数组 default []

String

# id

要素集合的id default 随机id

SpatialReference

# spatialReference

要素集合的参考系 default new zondy.SpatialReference('EPSG:4326')

String

# readonly type

该类的类型 default FeatureCollection

方法

# static fromArray(features, featureSet)

将一个要素数组对象转为要素集合

参数:

名称 类型 描述
features Array.<Object> | FeatureSet
featureSet FeatureSet

FeatureSet 新的featureSet对象

示例

将一个要素数组对象转为要素集合

// ES5引入方式
const { FeatureSet } = zondy
// ES6引入方式
import { FeatureSet } from "@mapgis/webclient-common"
featureSet = FeatureSet.fromArray(
  [
  {
    "attributes": {
      "FID": 650,
      "CODE": "420000",
      "CAPNAME": "武汉市",
      "mpPerimeter": "38.93733309514808",
      "mpArea": "17.556751278282672",
      "mpLayer": "18",
      "NAME": "湖北省"
    },
    "geometry": {
      "type": "Polygon",
      "coordinates": [[]]
    },
    "symbol": null
  }
],
  new FeatureSet()
)

# static fromGeoJSON(geoJSON)

从GeoJSON或TopoJSON对象中导入数据,若要素id相同,则会覆盖当前要素的值

参数:

名称 类型 描述
geoJSON

geoJSON数据

示例

从geoJSON对象中导入数据

//数据格式参考https://geojson.org/
FeatureSet.fromGeoJSON({
  //类型必须为FeatureCollection
  type: "FeatureCollection",
  //要素集合
  features: []
})

# static fromJSON(json)

通过传入的json构造并返回一个新的几何对象

参数:

名称 类型 描述
json Object

JSON对象

示例

通过传入的json构造并返回一个新的几何对象

// ES5引入方式
const { FeatureSet } = zondy
// ES6引入方式
import { FeatureSet } from "@mapgis/webclient-common"
const json = {
  //不填则创建一个随机的guid
  id: "你的id",
  //要素集合
  features: []
}
const featureSet = new FeatureSet.fromJSON(json)

# clone()

克隆并返回新的要素集合

克隆后的新要素集合

FeatureSet
示例

克隆并返回新的要素集合

let newFeatureSet = featureSet.clone();

# findFeatureById(id)

通过ID寻找要素,若没有id,则在要素的attributes中查找

参数:

名称 类型 描述
id

要素ID

Feature 要素对象

示例

通过ID寻找要素

let feature = featureSet.findFeatureById("要素id");

# toGeoJSON()

导出为GeoJSON数据

geoJSON数据

Object
示例

导出为GeoJSON数据

let geojson = featureSet.toGeoJSON();

# toJSON()

导出一个JSON对像

JSON对像

Object
构造函数
成员变量
方法
事件