Class: VectorTileSubLayer

VectorTileSubLayer

new VectorTileSubLayer(options)

document/layer/baseLayer/VectorTileSubLayer.js, line 28

矢量瓦片子图层基类。

VectorTileSubLayerVectorTileLayer 的子节点(可形成树结构),用于对一组矢量瓦片样式图层(styleLayers) 进行统一控制,例如:显隐、透明度、专题渲染器(renderer)与三维注记(labelingInfo)。

关键点:

  • 修改 visible/opacity/renderer/labelingInfo 会更新关联的 styleLayers,并通过父图层触发 layer-update 事件;
  • styleLayers 为只读属性;
  • opacity/visible 支持累积计算(会与父节点/主图层的同名属性相乘/相与)。
Name Type Default Description
options Object {} 可选

构造参数

Name Type Default Description
originLayerType String 'SFeatureLayer' 可选

服务端原始子图层类型,一般来源于矢量瓦片服务的 mapinfo,例如 GroupLayerSFeatureLayerAnnotationLayer

styleLayers Array.<Object> [] 可选

关联的矢量瓦片样式图层数组。通常由 VectorTileLayer 内部创建并注入,外部一般只读取而不直接修改。

opacity Number 1 可选

子图层透明度(0~1)。会与父节点/主图层透明度相乘形成累积效果。

visible Boolean true 可选

子图层可见性。会与父节点/主图层可见性相与形成累积效果。

renderer BaseRenderer | Object | null null 可选

专题渲染器配置。支持 UniqueValueRendererClassBreakRendererSimpleRenderer

labelingInfo Array.<LabelClass> | Array.<Object> [] 可选

三维注记参数。仅当父图层 labelsRenderMode !== 'off-screen' 时生效。

Example

Create VectorTileSubLayer instance

// ES5 import style
const { VectorTileSubLayer } = zondy

// ES6 import style
import { VectorTileSubLayer } from '@mapgis/webclient-common'

Extends

Members

capabilitiesObject

子图层支持能力。子图层支持能力分为客户端能力和服务端能力,其中客户端能力包含cesium、leaflet、mapboxgl引擎能力。默认子图层客户端能力:所有引擎能力都为空;默认子图层服务端能力为空。

图层版权信息

descriptionString

子图层描述信息

extendPropsObject

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

Default Value:
{}

extensionOptionsObject

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

Default Value:
{}

extentExtent

子图层范围

idString

图层id,不给则生成随机id

labelingInfoArray.<LabelClass>

三维注记参数。

仅当父图层 labelsRenderMode !== 'off-screen' 时生效。

layerLayer

父图层对象。所有子图层(包含子图层的子图层)拥有同一个父图层对象。toJSON方法不会导出该属性。

maxScaleNumber

最大显示比例尺(最放大)。

当视图缩放到超过该比例尺范围时,子图层不可见。 maxScale 应始终小于 minScale

minScaleNumber

最小显示比例尺(最缩小)。

当视图缩小到超过该比例尺范围时,子图层不可见。 minScale 应始终大于 maxScale

opacityNumber

子图层透明度。

赋值后会递归更新子树,并通过父图层触发 layer-update

Default Value:
1

originLayerTypeString

服务端原始子图层类型。

常见:GroupLayerSFeatureLayer(也可能包含其他类型,如 AnnotationLayer)。

parentSubLayer Layer null

父节点对象。toJSON方法不会导出该属性。

专题渲染器。

赋值后会立即更新 styleLayers,并通过父图层触发 layer-update

spatialReferenceSpatialReference

空间参考系

styleLayersArray.<Object>

矢量瓦片子图层关联的矢量瓦片样式图层

sublayersCollection.<SubLayer> null

子图层集合。

  • 传入 Collection 时直接使用;
  • 传入数组时会将数组元素视为子图层配置并递归创建;
  • 传入 null 表示无子图层。

注意:该属性通过 _decorate() 实现类型包装,外部通常以 Collection 的方式访问。

titleString

图层名称

图层类型

visibleBoolean

子图层是否可见。

赋值后会递归更新子树,并通过父图层触发 layer-update

Default Value:
true

Methods

clone(){VectorTileSubLayer}

document/layer/baseLayer/VectorTileSubLayer.js, line 356

克隆当前子图层。

Returns:
Type Description
VectorTileSubLayer 克隆后的新实例

inherited fire(type, data, propagate){Object}

base/Evented.js, line 523

激发指定类型的事件

Name Type Description
type string 可选

事件类型

data Object 可选

待传递的数据

propagate Boolean 可选

是否传播到父级

Returns:
Type Description
Object 当前实例

inherited off(types, fn, context){Object}

base/Evented.js, line 337
Name Type Description
types string 可选

移除指定事件类型上绑定的回调函数
当类型为字符串时,可以移除单个或多个事件类型绑定的回调函数,单个事件:"click",多个事件:以空格分割:"click double-click";
当types为对象时,使用如下方式移除事件:{'click': onClickFun, 'mouse-move': onMouseMoveFun}

fn function 可选

事件回调函数,当types为字符串,且不指定要删除的回调函数时,删除该事件上的所有回调函数

context Object 可选

事件回调函数的this关键字将指向的对象

Returns:
Type Description
Object 当前实例
Examples

移除一个事件的指定回调函数

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
}
// 调用MapView或SceneView的off方法移除一个事件的回调函数
view.off('click', clickFunction)

移除一个事件的所有回调函数

// 一个事件的回调函数1
const clickFunction1 = function (event) {
  console.log("点击事件1:", event)
}

// 一个事件的回调函数2
const clickFunction2 = function (event) {
  console.log("点击事件2:", event)
}

// 调用MapView或SceneView的off方法移除一个事件的所有回调函数
// 不指定回调函数,则移除该事件上的所有绑定的回调函数
view.off('click')

移除多个事件的同一个指定的回调函数

// 多个事件的同一个回调函数
const eventFunction = function (event) {
  console.log("事件:", event)
}
// 调用MapView或SceneView的off方法移除多个事件的同一个指定的回调函数
view.off('click double-click', eventFunction)

移除多个指定事件的回调函数

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("click事件:", event)
}
// 调用MapView或SceneView的off方法移除多个指定事件的回调函数
view.off({
   // 移除click事件上一个指定的函数
  "click": clickFunction,
  // 移除double-click上所有指定的函数
  "double-click": undefined
})

删除时指定上下文 - types类型为字符串

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
}
// 调用MapView或SceneView的off方法移除一个事件的回调函数
view.off('click', clickFunction, view)
// 调用MapView或SceneView的off方法移除一个事件的所有回调函数
view.off('click', undefined, view)

删除时指定上下文 - types类型为对象

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("click事件:", event)
}
// 调用MapView或SceneView的off方法移除多个指定事件的回调函数
view.off({
   // 移除click事件上一个指定的函数
  "click": clickFunction,
  // 移除double-click上所有指定的函数
  "double-click": undefined
}, view)

inherited on(types, fn, context){Object}

base/Evented.js, line 240
Name Type Default Description
types String | Object null 可选

事件类型
当types为字符串时,可以定义单个或多个事件,单个事件:"click",多个事件:以空格分割:"click double-click";
当types为对象时,使用如下方式指定事件:{'click': onClickFun, 'mouse-move': onMouseMoveFun}

fn function null 可选

事件回调函数

context Object null 可选

事件回调函数的this关键字将指向的对象

Returns:
Type Description
Object 当前实例
Examples

注册一个事件

// 初始化一个点击事件回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
}
// 调用MapView或SceneView的on方法注册一个点击事件
view.on('click', clickFunction)

一次注册多个事件 - 同一个回调函数

// 初始化一个事件回调函数
const eventFunction = function (event) {
  console.log("事件:", event)
}

// 调用MapView或SceneView的on方法注册多个事件
// 多个事件类型使用同一个回调函数
view.on('click right-click-down', eventFunction)

一次注册多个事件 - 分别指回调应函数

// 初始化一个左键点击事件回调函数
const clickFunction = function (event) {
  console.log("click事件:", event)
}

// 初始化一个右键按下事件回调函数
const rightClickFunction = function (event) {
  console.log("right-click-down事件:", event)
}

// 调用MapView或SceneView的on方法注册多个事件
// 每一个事件类型,使用单独的回调函数
// 注意使用此种方式,一种类型的事件仅能指定一个回调函数
view.on({
  "click": clickFunction,
  "right-click-down": rightClickFunction
})

指定上下文 - types类型为字符串

// 初始化一个点击事件回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
  console.log("上下文对象:", this)
}
// 调用MapView或SceneView的on方法注册一个点击事件
// 指定view为回调函数的上下文对象
view.on('click', clickFunction, view)

指定上下文 - types类型为对象

// 初始化一个点击事件回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
  console.log("上下文对象:", this)
}
// 调用MapView或SceneView的on方法注册一个点击事件
// 指定view为回调函数的上下文对象
view.on({
  "click": clickFunction,
  "right-click-down": clickFunction
}, view)

inherited once(types, fn, context){Object}

base/Evented.js, line 592

事件监听,仅触发一次

Name Type Description
types string 可选

将侦听器函数(fn)添加到对象的特定事件类型中。您还可以传递几个空格分隔的类型(例如“click dblclick”),也可以传入例如 {click: onClick, mousemove: onMouseMove}。

fn function 可选

侦听器函数

context Object 可选

指定侦听器的上下文(this关键字将指向的对象)

Returns:
Type Description
Object 当前实例

toJSON(){Object}

document/layer/baseLayer/VectorTileSubLayer.js, line 340

导出为 JSON 配置。

Returns:
Type Description
Object JSON 配置对象

VectorTileSubLayer.fromJSON(json){VectorTileSubLayer}

document/layer/baseLayer/VectorTileSubLayer.js, line 329

通过 JSON 配置创建/恢复实例。

Name Type Description
json Object

JSON 配置对象

Returns:
Type Description
VectorTileSubLayer 新的实例