# new IGSFeatureLayer(options)
IGS要素图层,
目前二维和三维上支持4326(包括4490,4214以及4610),3857以及EPSG支持的自定义坐标系,要素服务会自动读取元信息上的坐标系,不需要用户指定
[ES5引入方式]:
zondy.layer.IGSFeatureLayer()
[ES6引入方式]:
import { IGSFeatureLayer } from "@mapgis/webclient-common"
针对图层的操作请在图层加载完毕事件中进行
Layer.on('layerview-created', function (result) {
console.log("加载完毕:", result.layer)
});
如果不想在该事件中放入业务代码,则请确认图层资源已加载完毕后再进行操作
if(layer.loadStatus === 'loaded') {
// 你的业务逻辑
}
参数:
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
options |
Object | 构造参数 |
|
url |
String | 服务基地址, |
|
sublayerId |
Number | String | 0 | 要素服务的子图层id,有如下规则: |
gdbp |
String | 指定一个gdbp数据源来加载图形,格式如下:gdbp://MapGisLocal/武汉市/ds/4326矢量/sfcls/武汉市区划4326 |
|
id |
String | 图层id,图层的唯一标识,不指定则给一个随机id |
|
opacity |
Number | 1 | 图层透明度,0到1之间的值,0为完全透明,1为不透明,参考示例:[设置图层透明度] |
visible |
Boolean | true | 图层显示或隐藏,true则显示,false则隐藏,参考示例:[设置图层显示或隐藏] |
renderMode |
String | 'client' | 渲染模式,分为客户端渲染'client'和服务器端渲染'server',目前仅当gdbp存在时,server模式生效。 |
renderer |
Renderer | 渲染样式, |
|
definitionExpression |
String | '' | sql语句查询,例如 |
serverFilter |
FeatureFilter | null | 服务端要素过滤选项。 |
outFields |
Array.<String> | null | 服务器请求返回要素时,要素中包含的字段列表。默认为null,表示请求返回的要素中包含全字段。筛选要素字段可以通过数组传递,例如["NAME", "GDP2016", "GDP2017", "GDP2018"]。 |
labelsVisible |
Boolean | false | 是否开启动态注记,仅支持三维场景 |
labelingInfo |
Array.<LabelClass> | [] | 注记样式数组,可以和renderer同时启用,默认取数组的第一个样式,
仅支持三维场景,参考示例:[注记样式] |
minScale |
Number | 0 | 最小显示比例尺,图层在视图中可见的最小比例尺。 |
maxScale |
Number | 0 | 最大显示比例尺,图层在视图中可见的最大比例尺。 |
tokenKey |
String | 'token' | token名 |
tokenValue |
String | token值,只有当tokenValue存在时,才会绑定token |
|
supportArc3 |
Boolean | true | 是否返回三点弧段数据,为true则返回三个点代表三点弧段,否则返回离散的点 |
支持如下方法:
[1、加载图层资源][2、指定图层的要素查询]
[3、查询要素数量]
[4、通过传入的json构造并返回一个新的几何对象]
5、导出为json对象
6、克隆几何对象
示例
// ES5引入方式
const { IGSFeatureLayer } = zondy.layer
// ES6引入方式
import { IGSFeatureLayer} from "@mapgis/webclient-common"
// 添加图层
const igsFeatureLayer = new IGSFeatureLayer({
// 服务基地址
url: 'http://{ip}:{port}/igs/rest/services/{ServiceName}/FeatureServer'
})
// ES5引入方式
const { IGSFeatureLayer } = zondy.layer
// ES6引入方式
import { IGSFeatureLayer} from "@mapgis/webclient-common"
// 添加图层
const igsFeatureLayer = new IGSFeatureLayer({
// 服务基地址
url: 'http://{ip}:{port}/igs/rest/services/{ServiceName}/FeatureServer',
// 指定图层id
sublayerId: 2
})
<caption><h7 id='IGSFeatureLayer-url'>添加IGS要素图层-在基地址中指定图层id</h7></caption
// ES5引入方式
const { IGSFeatureLayer } = zondy.layer
// ES6引入方式
import { IGSFeatureLayer} from "@mapgis/webclient-common"
const igsFeatureLayer = new IGSFeatureLayer({
// 服务基地址,再基地址上指定图层id
url: 'http://{ip}:{port}/igs/rest/services/{ServiceName}/FeatureServer/1'
})
// ES5引入方式
const { IGSFeatureLayer } = zondy.layer
// ES6引入方式
import { IGSFeatureLayer} from "@mapgis/webclient-common"
const igsFeatureLayer = new IGSFeatureLayer({
// 服务基地址,再基地址上指定图层id
url: 'http://{ip}:{port}/igs/rest/mrfs/docs/{ServiceName}',
// 图层id
sublayerId: '1'
})
map.remove(igsFeatureLayer)
// ES5引入方式
const { IGSFeatureLayer } = zondy.layer
// ES6引入方式
import { IGSFeatureLayer} from "@mapgis/webclient-common"
// 在初始化时设置
const igsFeatureLayer = new IGSFeatureLayer({
// 服务基地址,再基地址上指定图层id
url: 'http://{ip}:{port}/igs/rest/services/{ServiceName}/FeatureServer/1',
// 设置透明度
opacity: 1
})
// 在图层加载完毕后设置
igsFeatureLayer.opacity = 0.5
// ES5引入方式
const { IGSFeatureLayer } = zondy.layer
// ES6引入方式
import { IGSFeatureLayer} from "@mapgis/webclient-common"
// 在初始化时设置
const igsFeatureLayer = new IGSFeatureLayer({
// 服务基地址,再基地址上指定图层id
url: 'http://{ip}:{port}/igs/rest/services/{ServiceName}/FeatureServer/1',
// 设置图层可见性
visible: true
})
// 在图层加载完毕后设置
igsFeatureLayer.visible = !igsFeatureLayer.visible
// 加载完毕后,更改图层顺序
map.reorder(igsFeatureLayer, '要移动到的index');
// ES5引入方式
const { IGSFeatureLayer } = zondy.layer
const { UniqueValueRenderer } = zondy.renderer
const { SimpleFillSymbol,SimpleLineSymbol } = zondy.symbol
const { Color } = zondy
// ES6引入方式
import { IGSFeatureLayer,UniqueValueRenderer,SimpleFillSymbol,SimpleLineSymbol,Color } from "@mapgis/webclient-common"
const igsFeatureLayer = new IGSFeatureLayer({
// 服务基地址,当不指定图层名称时,默认查询第一个子图层
url: 'http://{ip}:{port}/igs/rest/services/{ServiceName}/FeatureServer',
// 设置渲染样式-单值专题图
renderer: new UniqueValueRenderer({
// 专题图过滤字段名
field: '字段名',
// 默认样式,当没有匹配到指定值时,会使用默认样式
// 因为该数据的几何类型为区,因此设置区样式
defaultSymbol: new SimpleFillSymbol({
// 填充颜色
color: new Color(255, 0, 0),
// 外边线样式
outline: new SimpleLineSymbol({
// 线颜色
color: new Color(0, 0, 0),
// 线宽
width: 1
})
}),
// 单值专题图过滤条件数组
uniqueValueInfos: [
{
//指定字段值
value: '过滤字段值1',
//匹配到该值后的样式
// 因为该数据的几何类型为区,因此设置区样式
symbol: new SimpleFillSymbol({
// 填充颜色
color: new Color(255, 0, 0)
})
},
{
//指定字段值
// 因为该数据的几何类型为区,因此设置区样式
value: '过滤字段值2',
//匹配到该值后的样式
// 因为该数据的几何类型为区,因此设置区样式
symbol: new SimpleFillSymbol({
// 填充颜色
color: 'rgb(255, 123, 220)'
})
}
]
})
})
// ES5引入方式
const { IGSFeatureLayer } = zondy.layer
const { ClassBreakRenderer } = zondy.renderer
const { SimpleLineSymbol } = zondy.symbol
const { Color } = zondy
// ES6引入方式
import { IGSFeatureLayer,ClassBreakRenderer,SimpleLineSymbol,Color } from "@mapgis/webclient-common"
const igsFeatureLayer = new IGSFeatureLayer({
// 服务基地址,当不指定图层名称时,默认查询第一个子图层
url: 'http://{ip}:{port}/igs/rest/services/{ServiceName}/FeatureServer',
// 设置渲染样式-分段专题图
renderer: new ClassBreakRenderer({
// 专题图过滤字段名
field: '字段名',
// 默认样式,当没有匹配到指定值时,会使用默认样式
// 因为该数据的几何类型为线,因此设置线样式
defaultSymbol: new SimpleLineSymbol({
// 线符号颜色
color: new Color(1, 244, 0),
// 线宽
width: 3
}),
// 分段专题图过滤条件数组
classBreakInfos: [
{
// 最小过滤范围,field对应的值大于等于minValue
minValue: 0,
// 最大过滤范围,field对应的值小于maxValue
maxValue: 2,
// 匹配到该值后的样式
// 因为该数据的几何类型为线,因此设置线样式
symbol: new SimpleLineSymbol({
// 线符号颜色
color: new Color(1, 244, 0),
// 线宽
width: 3
})
},
{
// 最小过滤范围,field对应的值大于等于minValue
minValue: 3,
// 最大过滤范围,field对应的值小于maxValue
maxValue: 5,
// 匹配到该值后的样式
// 因为该数据的几何类型为线,因此设置线样式
symbol: new SimpleLineSymbol({
// 线符号颜色
color: new Color(111, 144, 10),
// 线宽
width: 3
})
},
{
// 最小过滤范围,field对应的值大于等于minValue
minValue: 5,
// 最大过滤范围,field对应的值小于maxValue
maxValue: 7,
// 匹配到该值后的样式
// 因为该数据的几何类型为线,因此设置线样式
symbol: new SimpleLineSymbol({
// 线符号颜色
color: new Color(22, 244, 10),
// 线宽
width: 3
})
},
{
// 最小过滤范围,field对应的值大于等于minValue
minValue: 7,
// 最大过滤范围,field对应的值小于maxValue
maxValue: 9,
// 匹配到该值后的样式
// 因为该数据的几何类型为线,因此设置线样式
symbol: new SimpleLineSymbol({
// 线符号颜色
color: new Color(33, 44, 10),
// 线宽
width: 3
})
},
{
// 最小过滤范围,field对应的值大于等于minValue
minValue: 9,
// 最大过滤范围,field对应的值小于maxValue
maxValue: 20,
// 匹配到该值后的样式
// 因为该数据的几何类型为线,因此设置线样式
symbol: new SimpleLineSymbol({
// 线符号颜色
color: new ZColor(123, 124, 110),
// 线宽
width: 3
})
}
]
})
})
// ES5引入方式
const { IGSFeatureLayer } = zondy.layer
const { SimpleRenderer } = zondy.renderer
const { SimpleFillSymbol,SimpleLineSymbol } = zondy.symbol
const { Color } = zondy
// ES6引入方式
import { IGSFeatureLayer,SimpleRenderer,SimpleFillSymbol,SimpleLineSymbol,Color } from "@mapgis/webclient-common"
const igsFeatureLayer = new IGSFeatureLayer({
// 服务基地址,当不指定图层名称时,默认查询第一个子图层
url: 'http://{ip}:{port}/igs/rest/services/{ServiceName}/FeatureServer',
// 设置渲染样式-统一专题图
renderer: new SimpleRenderer({
// 因为该数据的几何类型为区,因此设置区样式
symbol: new SimpleFillSymbol({
// 填充颜色
color: new Color(255, 0, 0),
// 外边线样式
outline: new SimpleLineSymbol({
// 线颜色
color: new Color(0, 0, 0),
// 线宽度
width: 1
})
})
})
})
// ES5引入方式
const { IGSFeatureLayer } = zondy.layer
// ES6引入方式
import { IGSFeatureLayer } from "@mapgis/webclient-common"
const igsFeatureLayer = new IGSFeatureLayer({
// 服务基地址,该地址为要素服务1.0地址
url: "http://{ip}:{port}/igs/rest/mrfs/layer",
// gdbp地址,在桌面的数据库中右键简单要素类,来获取该地址
gdbp: "gdbp://MapGisLocal/武汉市/ds/4326矢量/sfcls/武汉市区划4326"
})
// ES5引入方式
const { igsFeatureLayer } = zondy.layer
const { LabelClass ,Font} = zondy
const { TextSymbol } = zondy.symbol
// ES6引入方式
import { igsFeatureLayer,LabelClass,Font,TextSymbol } from "@mapgis/webclient-common"
// 初始化LabelClass
const labelClass = new LabelClass({
// 指定文本符号样式
symbol: new TextSymbol({
// 文字颜色
color: new Color(252, 100, 22, 1),
// 文字样式
font: new Font({
// 字体
family: "微软雅黑",
// 文字大小,单位像素
size: 30,
// 文字是否为斜体,正常模式
style: "normal",
// 文字粗细
weight: "normal"
})
})
})
// 初始化IGS要素图层
const igsFeatureLayer = new igsFeatureLayer({
// 服务基地址,当不指定图层名称时,默认查询第一个子图层
url: 'http://{ip}:{port}/igs/rest/services/{ServiceName}/FeatureServer',
// 可在此处设置渲染样式
renderer: {},
// 启用注记
labelsVisible: true,
// 设置注记样式
labelingInfo: [labelClass]
})
继承关系
成员变量
# outFields
服务器请求返回要素时,要素中包含的字段,默认为null,表示请求全字段。筛选要素字段可以通过数组传递,例如["NAME", "GDP2016", "GDP2017", "GDP2018"]
方法
# static fromJSON(jsonopt)
参数:
名称 | 类型 | 描述 |
---|---|---|
json |
Object | JSON对象 |
示例
const json = {
// 服务基地址
url: 'http://{ip}:{port}/igs/rest/services/{serviceName}/FeatureServer',
}
const igsFeatureLayer = new zondy.layer.IGSFeatureLayer.fromJSON(json)
# load()
加载图层资源
示例
// 初始化图层
const igsFeatureLayer = new zondy.layer.IGSFeatureLayer({
// 服务基地址
url: 'http://{ip}:{port}/igs/rest/services/{serviceName}/FeatureServer',
});
igsFeatureLayer.load().then((result) => {
// 获取完图层信息
console.log(result)
})
# queryFeatures(queryOptions)
指定图层的要素查询
参数:
名称 | 类型 | 描述 |
---|---|---|
queryOptions |
Object | 参考此接口的入参 |
示例
igsFeatureLayer.queryFeatures({
// 图层id
sublayerId: '0',
// where语句
where: "NAME='天门市'"
}).then((result) => {
console.log('查询结果:', result)
})
# queryFeaturesCount(queryOptions)
查询要素数量,仅支持igs2.0
参数:
名称 | 类型 | 描述 |
---|---|---|
queryOptions |
Object | 参考此接口的入参 |
示例
igsFeatureLayer.queryFeaturesCount({
// 图层id
sublayerId: '0',
// where语句
where: "NAME='天门市'"
}).then((result) => {
console.log('查询结果:', result)
})
事件
# 图层样式更新完毕事件
图层样式更新完毕事件,请注意该事件是图层更新事件(layerview-update)的子事件
属性:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
event |
Object | 事件对象 |
||
type |
String |
<optional> |
'layerview-update' | 图层更新完毕事件 |
message |
String |
<optional> |
null | 更新描述 |
updateContent |
Array.<UpdateContent> |
<optional> |
null | 更新详情对象 |
layer |
Layer |
<optional> |
null | 地图图层对象 |
layerView |
MapView |
<optional> |
null | 图层的视图对象 |
sourceTarget |
Layer |
<optional> |
null | 事件发起对象 |
target |
Map |
<optional> |
null | 事件接收对象 |
示例
图层样式更新完毕事件
Layer.on('layerview-update', function (event) {
// 获取更新事件对象
console.log("更新完毕:", event)
// 获取更新详情数组
const updateContent = event.updateContent
// 循环数组,根据事件名进行后续操作
for (let i = 0; i < updateContent.length; i++) {
// 图层样式更新完毕事件
if(updateContent[i].name === 'renderer'){
console.log("图层样式更新完毕事件:", event);
}
}
});