# new Feature(options)
要素对象,示例如下:[初始化要素对象]
[ES5引入方式]:
zondy.Feature()
[ES6引入方式]:
import { Feature } from "@mapgis/webclient-common"
参数:
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
options |
Object | 构造参数 |
|
id |
String | 要素的id,不给则给一个随机的默认id |
|
attributes |
Object | {} | 要素的属性 |
geometry |
Geometry | ||
symbol |
Symbol | {} | 客户端要素渲染样式,当使用GraphicsLayer图层绘制要素时,设置此参数来决定渲染结果,支持如下: |
visible |
Boolean | true | 要素是否可见 |
elevationInfo |
ElevationInfo | 高程模式参数 |
|
styleInfo |
Object | 服务端要素渲染样式,说明如下: |
支持如下方法:
[1、从geoJSON对象中导入数据][2、导出为GeoJSON数据]
[3、通过传入的json构造并返回一个新的几何对象]
[4、导出一个JSON对像]
[5、克隆并返回新要素]
[6、导出为igs服务接口的要素对象]
[7、出为igs1.0服务接口的要素对象]
[8、导出为igs1.0的要素的图形信息]
[9、导出为igs1.0的要素的属性值]
[10、导出为igs1.0的要素的几何类型]
示例
// 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
})
})
成员变量
方法
# static fromJSON(json)
参数:
名称 | 类型 | 描述 |
---|---|---|
json |
Object | JSON对象 |
示例
<caption><h7>通过传入的json构造并返回一个新的几何对象</h7></caption>\
// 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 = new Feature.fromJSON(json)
# fromGeoJSON(geoJSON)
参数:
名称 | 类型 | 描述 |
---|---|---|
geoJSON |
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",
},
});