# 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: []
})
成员变量
方法
# 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 |
geoJSON数据 |
示例
//数据格式参考https://geojson.org/
FeatureSet.fromGeoJSON({
//类型必须为FeatureCollection
type: "FeatureCollection",
//要素集合
features: []
})
# static fromJSON(json)
参数:
名称 | 类型 | 描述 |
---|---|---|
json |
Object | JSON对象 |
示例
// ES5引入方式
const { FeatureSet } = zondy
// ES6引入方式
import { FeatureSet } from "@mapgis/webclient-common"
const json = {
//不填则创建一个随机的guid
id: "你的id",
//要素集合
features: []
}
const featureSet = new FeatureSet.fromJSON(json)
# findFeatureById(id)
参数:
名称 | 类型 | 描述 |
---|---|---|
id |
要素ID |
Feature 要素对象
示例
let feature = featureSet.findFeatureById("要素id");