IconsLayer

图标图层

new YS.IconsLayer(options, global)

图标图层
Name Type Description
options Object 对象有下面这些属性:
Name Type Default Description
id String optional 唯一标识
name String optional 名称
category String optional 图层分组
maxHeight Number optional 最大显示距离
minHeight Number optional 最小显示距离
visible Boolean true optional 是否可见
closeDepth Boolean true optional 是否关闭深度检测
closeDepthDistance Boolean optional 指定相机距离多远禁用深度检测(开启深度检测时才有效)
isAddTree Boolean true optional 是否添加到图层树上
treeIcon String optional 图层树上显示的图标,默认不显示
cluster Object optional 图标聚合的设置,默认不设置不做聚合
Name Type Default Description
isCluster Boolean false optional 是否使用图标聚合
clusterHeight Number optional 聚合图标使用的高度,相机低于该高度将不启用聚合(默认一直生效)
fontSize Number 14 optional 聚合数字的字号,单位像素
image String 'YouScene/Assets/img/cluster/0.png' optional 聚合气泡的图片路径
labelOffset XY {x:0,y:-24} optional 文字相对聚合气泡点的偏移距离,单位像素
pixelRange Number 15 optional 用于扩展屏幕空间边界框的像素范围
minimumClusterSize Number 2 optional 聚合发生的最少点数量,即多少个点重合会被聚合
callback IconsLayer~createClusterCallback optional 每个聚合点的处理回调函数。设置了callback后,cluster.image失效。
默认不使用回调,每个聚合点使用image叠加被聚合icon的数量;
如果想自定义展现策略,例如使用不同的图标,可通过这个回调实现。
global Object 三维球对象(YouScene.earth)
Implements:
Examples:
var iconLayer = youScene.layers.addIconsLayer({
                 id: 'IconsLayer',
                 name: 'IconsLayer',
                 visible: true,
                 isAddTree: true
             });
// 聚合自定义图标
 var airlineIconLayer = youScene.layers.addIconsLayer({
    id: 'IconsLayer',
    name: 'IconsLayer',
    cluster: {
       isCluster: true,
       pixelRange: 20,
       minimumClusterSize: 2
     }
 });
聚合使用回调函数设置分级图标
function cbFunc(count){
   return {
     text: (count > 999) ?'999+': count.toString(),
     image: 'YouScene/Assets/img/cluster/' + ((count > 999) ?'wide.png' : 'narrow.png'),
     showImage: true,
     showText: true
   };
}
var airlineIconLayer = youScene.layers.addIconsLayer({
    cluster: {
       isCluster: true,
       callback: cbFunc
     }
 });
Demo:

Members

closeDepth : Boolean

获取和设置图层是否关闭深度检测

closeDepth : Boolean

获取和设置图层是否关闭深度检测

closeDepthDistance : Number

获取和设置图层深度检测的距离

closeDepthDistance : Number

获取和设置图层深度检测的距离

count : Number

获取图标数量

visible : Boolean

获取或设置是否可见

Methods

add(icon)Icon

添加图标
Name Type Description
icon Icon 对象
Fires:
  • IconsLayer#event:featureAdded
Returns:
icon对象

cameraChanged(callback)

相机变化时的回调函数
Name Type Description
callback IconsLayer~requestCallback 回调函数

clear()

清空icons

destroy()

销毁
Implements:

flashing()

IconsLayer闪烁

getById(id)Feature

根据id获取图层内对象
Name Type Description
id String 对象的id
Returns:
返回查找到的对象,找不到返回undefined
Implements:

getByIndex(index)Feature

根据索引获取图层内对象
Name Type Description
index Number 对象的索引号,[0, count)
Returns:
返回查找到的对象,找不到返回undefined
Implements:

remove(icon)Boolean

移除图标
Name Type Description
icon Icon 对象
Returns:
true/false

removeById(id)Boolean

通过id移除图标
Name Type Description
id String 唯一标识符
Returns:
true/false

useCluster(enable)

启用或关闭聚合,关闭可提升性能
Name Type Description
enable Boolean true时启用聚合,false时关闭聚合

Type Definitions

createClusterCallback(count)Object

生成一个聚合气泡的自定义函数回调
Name Type Description
count Number 这个气泡聚合的icon点数量
Returns:
返回这个聚合气泡的生成参数,结构如下:
{
  text: '显示的文本',
  showText: true, //是否显示气泡上数字
  image: 'YouScene/Assets/img/cluster/0.png', //气泡图标
  showImage: true //是否显示图标
}
Example:
function callback(count){
   if (count > 10000){
     text: '999+',
     image: '',
     showImage: false,
     showText: true
   }
   else {
     text: count.toString(),
     image: 'YouScene/Assets/img/cluster/0.png',
     showImage: true,
     showText: true
   }
}

requestCallback(Iconlayer)

回调函数
Name Type Description
Iconlayer IconsLayer iconlayer自身