# new GeoJSONLayer(options)
geojson图层,仅支持文件服务
目前二维和三维上支持4326(包括4490,4214以及4610),3857以及EPSG支持的自定义坐标系,若是想要绘制源数据为非4326坐标系几何数据,需要在初始化时指定具体坐标系
参考示例:
[加载GeoJSON图层]
[ES5引入方式]:
zondy.layer.GraphicsLayer()
[ES6引入方式]:
import { GraphicsLayer } from "@mapgis/webclient-common"
参数:
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
options |
Object | 构造参数 |
|
url |
String | Object | 支持TopoJSON和GeoJSON数据的加载,可以传入GeoJSON Object或TopoJSON Object,如果传入为url,仅支持文件服务: |
|
id |
String | 图层id,若不填则给一个随机id |
|
visible |
Boolean | show | 图层可见性,参考示例:[图层可见性] |
opacity |
Number | 1 | 图层透明度,0~1之间的值,0完全透明,1不透明,参考示例:[图层透明度] |
spatialReference |
SpatialReference | 图层坐标系,默认为4326,若是想要绘制源数据为非4326坐标系几何数据,需要在初始化时指定具体坐标系 |
|
renderer |
BaseRenderer | 渲染样式, |
|
labelsVisible |
Boolean | false | 是否开启动态注记,仅支持三维动态注记渲染 |
labelingInfo |
Array.<LabelClass> | [] | 注记样式数组,可以和renderer同时启用,默认取数组的第一个样式,
仅支持三维场景,参考示例:[注记样式] |
elevationInfo |
ElevationInfo | 设置高程参数,指定几何是否贴地、贴模型、都贴、都不贴或者是绝对高度 |
|
minScale |
Number | 0 | 最小显示比例尺,图层在视图中可见的最小比例尺。 |
maxScale |
Number | 0 | 最大显示比例尺,图层在视图中可见的最大比例尺。 |
tokenKey |
String | 'token' | token名 |
tokenValue |
String | token值,只有当tokenValue存在时,才会绑定token |
|
customParameters |
Object | {} | 自定义查询参数,键值对,填写该参数后,会在数据请求的来链接后面以&key=value的形式拼接字符串 |
支持如下方法:
[1、加载图层资源][2、销毁图层]
[3、返回所有要素]
[4、查询要素数量]
[5、通过传入的json构造并返回一个新的几何对象]
6、导出为json对象
7、克隆几何对象
示例
// 初始化图层管理容器
// ES5引入方式
const { GeoJSONLayer } = zondy.layer
// ES6引入方式
import { GeoJSONLayer } from "@mapgis/webclient-common"
// 创建图层
const geojsonLayer = new GeoJSONLayer({
// 服务基地址
url: 'json数据地址'
})
// ES5引入方式
const { SpatialReference } = zondy
const { GeoJSONLayer } = zondy.layer
// ES6引入方式
import { SpatialReference, GeoJSONLayer } from "@mapgis/webclient-common"
// 创建图层
const geojsonLayer = new GeoJSONLayer({
// 服务基地址
url: 'json数据地址',
// 设置坐标系
spatialReference: new SpatialReference({
wkid: '坐标系的wkid'
})
})
// 删除图层
map.remove(geojsonLayer)
// ES5引入方式
const { Color} = zondy
const { GeoJSONLayer } = zondy.layer
const { UniqueValueRenderer } = zondy.renderer
const { SimpleLineSymbol,SimpleFillSymbol } = zondy.symbol
// ES6引入方式
import { Color,GeoJSONLayer,UniqueValueRenderer,SimpleLineSymbol,SimpleFillSymbol } from "@mapgis/webclient-common"
// 创建图层
const geojsonLayer = new GeoJSONLayer({
// 服务基地址
url: 'json数据地址',
// 渲染样式 - 单值专题图 - 区数据
renderer: new UniqueValueRenderer({
//字段名
field: '你的字段名',
// 默认符号,不在专题图指定范围内的会采用该样式,可不设置
defaultSymbol: new zondy.symbol.SimpleFillSymbol({
// 填充颜色
color: zondy.Color(1 , 1, 252),
// 外边线样式
outline: new SimpleLineSymbol({
//线颜色
color: new Color(255, 1, 0, 1),
//线宽
width: 1
})
}),
//单值专题图字段样式
uniqueValueInfos: [{
//指定字段值
value: "指定的值",
//匹配到该值后的样式
symbol: new SimpleFillSymbol({
// 填充颜色
color: Color(1, 1, 252),
// 外边线样式
outline: new SimpleLineSymbol({
//线符号颜色
color: new Color(255, 1, 0),
//线宽
width: 1
})
})
},{
//指定字段值
value: "指定的值",
//匹配到该值后的样式
symbol: new SimpleFillSymbol({
// 填充颜色
color: new Color(211, 111, 11, 1)
})
}]
})
})
// ES5引入方式
const { Color} = zondy
const { GeoJSONLayer } = zondy.layer
const { ClassBreakRenderer } = zondy.renderer
const { SimpleLineSymbol,SimpleFillSymbol } = zondy.symbol
// ES6引入方式
import { Color,GeoJSONLayer,ClassBreakRenderer, SimpleLineSymbol,SimpleFillSymbol} from "@mapgis/webclient-common"
// 创建图层
const geojsonLayer = new GeoJSONLayer({
// 服务基地址
url: 'json数据地址',
// 渲染样式 - 分段专题图 - 区数据
renderer: new ClassBreakRenderer({
//字段名
field: '你的字段名',
// 指定默认样式,不在专题图指定范围内的会采用该样式,可不设置
defaultSymbol: new SimpleFillSymbol({
// 填充颜色
color: new Color(222, 1, 252),
// 线符号样式
outline: new SimpleLineSymbol({
//线符号颜色
color: new zondy.Color(255, 1, 0),
//线宽
width: 1
})
}),
//分段专题图字段样式
classBreakInfos: [{
// 最大范围
maxValue: "最大范围",
// 最小范围
minValue: "最小范围",
//匹配到该值后的样式
symbol: new SimpleFillSymbol({
// 填充颜色
color: new Color(1, 1, 252),
// 线符号样式
outline: new SimpleLineSymbol({
//线符号颜色
color: new Color(255, 1, 0, 1),
//线宽
width: 1
})
})
}]
})
})
// ES5引入方式
const { GeoJSONLayer } = zondy.layer
const { SimpleRenderer } = zondy.renderer
const { SimpleFillSymbol,SimpleLineSymbol } = zondy.symbol
const { Color } = zondy
// ES6引入方式
import { Color,GeoJSONLayer, SimpleRenderer,SimpleLineSymbol,SimpleFillSymbol} from "@mapgis/webclient-common"
const geojsonLayer = new GeoJSONLayer({
// 服务基地址
url: 'json数据地址',
// 渲染样式 - 统一专题图 - 区数据
renderer: new SimpleRenderer({
// 设置几何的样式
symbol: new SimpleFillSymbol({
//线符号颜色
color: randomColor(),
// 外边线样式
outline: new SimpleLineSymbol({
// 外边线颜色
color: new Color(1, 1, 252),
// 外边线宽度
width: 1
})
})
})
})
// 加载完毕后,更改图层顺序
map.reorder(geojsonLayer, '要移动到的index');
// 创建图层
// ES5引入方式
const { GeoJSONLayer } = zondy.layer
// ES6引入方式
import { GeoJSONLayer } from "@mapgis/webclient-common"
const geojsonLayer = new GeoJSONLayer({
// 服务基地址
url: 'json数据地址',
// 设置图层可见性
visible: true
})
// 图层加载完成后,设置可见性
geojsonLayer.visible = !geojsonLayer.visible
// 创建图层
// ES5引入方式
const { GeoJSONLayer } = zondy.layer
// ES6引入方式
import { GeoJSONLayer } from "@mapgis/webclient-common"
const geojsonLayer = new zondy.layer.GeoJSONLayer({
// 服务基地址
url: 'json数据地址',
// 设置图层透明度
opacity: 1
})
// 图层加载完成后,设置可见性
geojsonLayer.opacity = 0.5
// ES5引入方式
const { LabelClass,Font } = zondy
const { TextSymbol } = zondy.symbol
const { GeoJSONLayer } = zondy.layer
// ES6引入方式
import { LabelClass,Font,TextSymbol,GeoJSONLayer } 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"
})
})
})
// 初始化GeoJSON图层
const geojsonLayer = new GeoJSONLayer({
// 服务基地址,当不指定图层名称时,默认查询第一个子图层
url: 'http://{ip}:{port}/igs/rest/services/{ServiceName}/FeatureServer',
// 可在此处设置渲染样式
renderer: {},
// 启用注记
labelsVisible: true,
// 设置注记样式
labelingInfo: [labelClass]
})
继承关系
成员变量
# opacity
图层透明度,0到1之间的值,0为完全透明,1为不透明,会触发图层更新完毕事件。IGSSceneLayer图层类型为地形时,不支持该属性。
- Inherited From:
方法
# static fromJSON(jsonopt)
参数:
名称 | 类型 | 描述 |
---|---|---|
json |
Object | JSON对象 |
示例
const json = {
// 服务基地址
url: 'json数据地址'
}
const geojsonLayer = new zondy.layer.GeoJSONLayer.fromJSON(json)
事件
# 图层刷新完毕事件
图层刷新完毕事件,请注意该事件是图层更新事件(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 | 事件接收对象 |
- Inherited From:
示例
图层刷新完毕事件
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 === 'refresh'){
console.log("图层刷新完毕事件:", event);
}
}
});
# 图层加载完毕事件
图层加载完毕事件
属性:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
event |
Object | 事件对象 |
||
type |
String |
<optional> |
'layerview-created' | 图层加载完毕事件 |
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 | 事件接收对象 |
- Inherited From:
示例
Layer.on('layerview-created', function (result) {
console.log("加载完毕:", result.layer)
});
# 图层显隐更新完毕事件
图层显隐更新完毕事件,请注意该事件是图层更新事件(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 | 事件接收对象 |
- Inherited From:
示例
图层显隐更新完毕事件
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 === 'visible'){
console.log("图层显隐更新事件:", event);
}
}
});
# 图层更新完毕事件
图层更新完毕事件
属性:
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 | 事件接收对象 |
- Inherited From:
示例
Layer.on('layerview-update', function (result) {
console.log("更新完毕:", result.layer)
});
# 图层样式更新完毕事件
图层样式更新完毕事件,请注意该事件是图层更新事件(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);
}
}
});
# 图层透明度更新完毕事件
图层透明度更新完毕事件,请注意该事件是图层更新事件(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 | 事件接收对象 |
- Inherited From:
示例
图层透明度更新完毕事件
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 === 'opacity'){
console.log("图层透明度更新事件:", event);
}
}
});
# 图层销毁完毕事件
图层销毁完毕事件
属性:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
event |
Object | 事件对象 |
||
type |
String |
<optional> |
'layerview-remove' | 图层销毁完毕事件 |
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 | 事件接收对象 |
- Inherited From:
示例
Layer.on('layerview-remove', function (result) {
console.log("销毁完毕:", result.layer)
});
# 图层顺序更新完毕事件
图层顺序更新完毕事件,请注意该事件是图层更新事件(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 | 事件接收对象 |
- Inherited From:
示例
图层顺序更新完毕事件
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 === 'index'){
console.log("图层顺序更新完毕事件:", event);
}
}
});