类名 GraphicsLayer

# new GraphicsLayer(options)

图形图层,不支持在线数据,仅支持传入多个几何对象并绘制
目前二维和三维上支持4326(包括4490,4214以及4610),3857以及EPSG支持的自定义坐标系,若是想要绘制非4326坐标系几何,需要在初始化要素对象的几何时,指定具体坐标系

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

针对图层的操作请在图层加载完毕事件中进行
Layer.on('layerview-created', function (result) {
console.log("加载完毕:", result.layer)
});
如果不想在该事件中放入业务代码,则请确认图层资源已加载完毕后再进行操作
if(layer.loadStatus === 'loaded') {
// 你的业务逻辑
}

参数:

名称 类型 默认值 描述
options Object

构造参数

graphics Array.<Feature>

几何对象,支持的几何数据如下:
1、点几何
2、多点几何
3、线几何
4、多线几何
5、区几何
6、多区几何
7、矩形几何
8、圆几何
参考示例:
[1、创建图层]
[2、删除图层]
[3、添加要素]
[4、添加自定义坐标系的要素]

id String

图层id,不给则给一个随机的id

visible Boolean show

图层可见性,参考示例:[图层可见性]

opacity Number 1

图层透明度,0~1之间的值,0完全透明,1不透明,参考示例:[图层透明度]

elevationInfo ElevationInfo

高度参数

支持如下方法:
[1、添加要素]
[2、删除要素]
[3、添加要素组]
[4、删除要素组]
[5、删除全部要素]
[6、通过传入的json构造并返回一个新的几何对象]
7、导出为json对象
8、克隆几何对象

示例

初始化图层

// ES5引入方式
const { Feature,Color} = zondy
const { Circle } = zondy.geometry
const { SimpleFillSymbol } = zondy.symbol
const { GraphicsLayer } = zondy.layer
// ES6引入方式
import { Color,Feature,Circle, GraphicsLayer,SimpleFillSymbol} from "@mapgis/webclient-common"
// 创建一个要素
const feature = new Feature({
  //不填则创建一个随机的guid
  id: '你的id',
  //设置属性
  attributes: {},
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [113, 30],
    // 半径
    radius: 4
  }),
  //设置样式
  symbol: new SimpleFillSymbol({
    //设置颜色
    color: new Color(255, 0, 112, 1)
  })
})
// 初始化几何图层
const graphicsLayer = new GraphicsLayer({
  graphics:[feature]
})

删除图层

map.remove(graphicsLayer)

将要素添加入图层

// ES5引入方式
const { Feature,Color} = zondy
const { Circle } = zondy.geometry
const { SimpleFillSymbol } = zondy.symbol
const { GraphicsLayer } = zondy.layer
// ES6引入方式
import { Feature,Color,Circle, GraphicsLayer,SimpleFillSymbol} from "@mapgis/webclient-common"
// 创建一个要素
const feature = new Feature({
  //不填则创建一个随机的guid
  id: '你的id',
  //设置属性
  attributes: {},
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [113, 30],
    // 半径
    radius: 4
  }),
  //设置样式
  symbol: new SimpleFillSymbol({
    //设置颜色
    color: new Color(255, 0, 112, 1)
  })
})
// 创建图层
const graphicsLayer = new GraphicsLayer()
// 添加要素
graphicsLayer.add(feature)

添加自定义坐标系的要素

// ES5引入方式
const { Feature,SpatialReference,Color} = zondy
const { Circle } = zondy.geometry
const { SimpleFillSymbol } = zondy.symbol
const { GraphicsLayer } = zondy.layer
// ES6引入方式
import { Feature,SpatialReference,Color,Circle, GraphicsLayer,SimpleFillSymbol} from "@mapgis/webclient-common"
// 创建一个要素
const feature = new Feature({
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [403511.251934197, 3320534.43647428],
    // 半径,单位像素
    radius: 4,
    // 设置坐标系
    spatialReference: new SpatialReference({
      wkid: '坐标系的wkid'
    })
  }),
  //设置样式
  symbol: new SimpleFillSymbol({
    //设置颜色
    color: new Color(255, 0, 112, 1)
  })
})
// 创建图层
const graphicsLayer = new GraphicsLayer()
// 添加要素
graphicsLayer.add(feature)

图层可见性

 // ES5引入方式
const { GraphicsLayer } = zondy.layer
// ES6引入方式
import {  GraphicsLayer } from "@mapgis/webclient-common"
// 创建图层时设置可见性
const graphicsLayer = new GraphicsLayer({
  // 设置图层visible
  visible: true
})

// 图层加载完成后,设置可见性
graphicsLayer.visible = !graphicsLayer.visible

图层透明度

// ES5引入方式
const { GraphicsLayer } = zondy.layer
// ES6引入方式
import {  GraphicsLayer } from "@mapgis/webclient-common"
// 创建图层时设置透明度
const graphicsLayer = new GraphicsLayer({
  opacity: 1
})

// 图层加载完成后,设置可见性
graphicsLayer.opacity = 0.5

图层顺序

// 加载完毕后,更改图层顺序
map.reorder(graphicsLayer, '要移动到的index');

继承关系

成员变量

String

版权所有

Inherited From:
String

# readonly description

图层描述

Inherited From:
ElevationInfo

# elevationInfo

高程模式参数

Object

# extendProps

当前图层对象上不支持的属性,二次开发用户希望挂在图层对像上的属性可以存储到该属性中

Inherited From:
Default Value:
  • {}
Object

# extensionOptions

初始化图层的额外参数,可以通过该参数传入引擎原生的构造参数

Inherited From:
Default Value:
  • {}
Extent

# readonly extent

图层范围,从服务元信息中获取

Inherited From:
FeatureCollection.<Feature>

# graphics

几何对象数组

String

# headers

设置服务请求头

Inherited From:
FetchMethod

# httpMethod

http请求方式

Inherited From:
String

# readonly id

图层id

Inherited From:
Number

# index

图层顺序

Inherited From:
Boolean

# readonly loaded

是否加载完毕

Overrides:
Default Value:
  • false
String

# readonly loadStatus

图层加载状态

Overrides:
Default Value:
  • not-loaded
Number

# maxScale

最大显示比例尺,图层在视图中可见的最大比例尺。

Overrides:
Number

# minScale

最小显示比例尺,图层在视图中可见的最小比例尺。

Overrides:
Number

# opacity

图层透明度,0到1之间的值,0为完全透明,1为不透明,会触发图层更新完毕事件。IGSSceneLayer图层类型为地形时,不支持该属性。

Inherited From:
SpatialReference

# spatialReference

图层坐标系对象

Inherited From:
String

# title

图层名称

Inherited From:
String

# tokenAttachType

token附加类型。默认psot请求优先附加到body,get请求优先附加到url末尾

Inherited From:
String

# tokenKey

token名

Overrides:
String

# tokenValue

token值

Overrides:
String

# readonly type

图层类型

Overrides:
Number

# visible

图层显示或隐藏,true则显示,false则隐藏,会触发图层更新完毕事件

Inherited From:

方法

# static fromJSON(jsonopt)

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

参数:

名称 类型 描述
json Object

JSON对象

示例

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

// ES5引入方式
const { Feature } = zondy
const { Circle } = zondy.geometry
const { GraphicsLayer } = zondy.layer
// ES6引入方式
import {  Feature,Circle,GraphicsLayer } from "@mapgis/webclient-common"
// 创建一个要素
const feature1 = new Feature({
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [113, 30],
    // 半径
    radius: 4
  })
})
const feature2 = new Feature({
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [123, 33],
    // 半径
    radius: 4
  })
})
const json = {
  graphics: [feature1, feature2]
}
// 创建图层
const graphicsLayer = new GraphicsLayer.fromJSON(json)

# add(feature)

添加要素,参考示例:[添加要素]

参数:

名称 类型 描述
feature Feature

要添加的要素

# addMany(features)

添加要素组

参数:

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

要添加的要素数组或集合

示例

添加要素组

// ES5引入方式
const { Feature } = zondy
const { Circle } = zondy.geometry
const { GraphicsLayer } = zondy.layer
// ES6引入方式
import {  Feature,Circle,GraphicsLayer } from "@mapgis/webclient-common"
// 创建一个要素
const feature1 = new Feature({
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [113, 30],
    // 半径
    radius: 4
  })
})
const feature2 = new Feature({
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [123, 33],
    // 半径
    radius: 4
  })
})
// 创建图层
const graphicsLayer = new GraphicsLayer()
map.add(graphicsLayer)
// 一次添加多个要素
graphicsLayer.addMany([feature1, feature2])

# clone()

克隆方法

Inherited From:

图层

Layer

# destroy()

Inherited From:
*

# isLoaded()

判断图层是否加载成功

Inherited From:

图层是否加载成功

Boolean

# refresh()

刷新图层

Inherited From:

# remove(feature)

删除要素

参数:

名称 类型 描述
feature Feature

要删除的要素

示例

删除要素

// ES5引入方式
const { Feature,Color } = zondy
const { Circle } = zondy.geometry
const { GraphicsLayer } = zondy.layer
const { SimpleFillSymbol } = zondy.symbol
// ES6引入方式
import {  Feature,Color,Circle,GraphicsLayer,SimpleFillSymbol } from "@mapgis/webclient-common"
// 创建一个要素
const feature = new Feature({
  //不填则创建一个随机的guid
  id: '你的id',
  //设置属性
  attributes: {},
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [113, 30],
    // 半径
    radius: 4
  }),
  //设置样式
  symbol: new SimpleFillSymbol({
    //设置颜色
    color: new Color(255, 0, 112, 1)
  })
})
// 创建图层
const graphicsLayer = new GraphicsLayer()
graphicsLayer.add(feature)
map.add(graphicsLayer)
// 删除要素
graphicsLayer.remove(feature)

# removeAll()

删除全部要素

示例

删除全部要素

// ES5引入方式
const { Feature } = zondy
const { Circle } = zondy.geometry
const { GraphicsLayer } = zondy.layer
// ES6引入方式
import {  Feature,Color,Circle,GraphicsLayer } from "@mapgis/webclient-common"
// 创建一个要素
const feature1 = new Feature({
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [113, 30],
    // 半径
    radius: 4
  })
})
const feature2 = new Feature({
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [123, 33],
    // 半径
    radius: 4
  })
})
// 创建图层
const graphicsLayer = new GraphicsLayer({
  graphics: [feature1, feature2]
})
map.add(graphicsLayer)
// 删除全部要素
graphicsLayer.removeAll()

# removeMany(features)

删除要素组

参数:

名称 类型 描述
features Array.<Feature>

要删除的要素数组或集合

示例

删除要素组

// ES5引入方式
const { Feature } = zondy
const { Circle } = zondy.geometry
const { GraphicsLayer } = zondy.layer
// ES6引入方式
import {  Feature,Circle,GraphicsLayer } from "@mapgis/webclient-common"
// 创建一个要素
const feature1 = new Feature({
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [113, 30],
    // 半径
    radius: 4
  })
})
const feature2 = new Feature({
  //构建几何
  geometry: new Circle({
    // 中心点
    center: [123, 33],
    // 半径
    radius: 4
  })
})
// 创建图层
const graphicsLayer = new GraphicsLayer({
  graphics: [feature1, feature2]
})
map.add(graphicsLayer)
// 一次删除多个要素
graphicsLayer.removeMany([feature1, feature2])

# toJSON()

转换为json对象

Overrides:

json对象

Object

事件

# 删除多个要素事件

删除多个要素事件,请注意该事件是图层更新事件(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 === 'removeMany'){
      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

事件接收对象

示例

子图层显隐更新完毕事件

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 === 'removeAll'){
      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

事件接收对象

示例

子图层显隐更新完毕事件

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 === 'remove'){
      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 === '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

事件接收对象

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);
    }
  }
});

# 添加多个要素事件

添加多个要素事件,请注意该事件是图层更新事件(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 === 'addMany'){
      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

事件接收对象

示例

子图层显隐更新完毕事件

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 === 'add'){
      console.log("添加要素事件:", event);
    }
  }
});
构造函数
成员变量
方法
事件