new RendererCollection(collection)
Renderer集合对象,主要用于M3DModelCacheLayer的renderer属性需要多个Renderer样式的场景
| Name | Type | Description |
|---|---|---|
collection |
Array.<Object> |
render结构集合 这里对object属性结构有要求,需要使用指定两个属性: layerID:渲染图层ID,字符串类型 renderer:渲染器对象,BaseRenderer类型及其派生类 |
Example
const rendererCollection = new zondy.RendererCollection([
{
// 子图层ID
layerID: '1834734999',
// 渲染renderer
renderer: layerRenderer1
},
{
// 子图层ID
layerID: '1834734000',
// 渲染renderer
renderer: layerRenderer2
}
])
layer.renderer = rendererCollection
Extends
Members
-
itemsArray.<any>
-
数组集合中的元素
-
lengthNumber
-
数组集合的长度
Methods
-
inherited add(item, index){Collection}
base/Collection.js, line 94 -
添加一个元素到集合中
Name Type Description item* 要添加的元素
indexNumber 指的元素要添加的位置,如果不指定,默认添加到集合末尾
Returns:
Type Description Collection 添加完元素后的集合对象 Examples
添加一个元素到集合中 const collection = new Collection() collection.add({ key: 'value' })添加一个元素到集合中的指定位置 const collection = new Collection([1, 2, 3]) collection.add({ key: 'value' }, 1) -
inherited addMany(items, index)
base/Collection.js, line 115 -
添加多个元素到集合中,添加完成后会发送数据变更事件
Name Type Description itemsArray.<*> 要添加的多个元素
indexNumber 指的元素要添加的位置,如果不指定,默认添加到集合末尾
Examples
添加多个元素到集合中 const collection = new Collection() collection.addMany([1, 2, 3])添加多个元素到集合中的指定位置 const collection = new Collection([1, 2, 3]) collection.addMany([1, 2, 3], 2) -
inherited all(){Array.<*>}
base/Collection.js, line 801 -
获取集合中的所有元素并返回一个数组
Returns:
Type Description Array.<*> 集合中元素构成的数组 Example
返回集合对象中元素组成的数组 const collection = new Collection([1, 2, 3]) collection.all() -
inherited at(index){*}
base/Collection.js, line 140 -
返回指定下标处的元素
Name Type Description indexNumber 元素下标,默认从0开始,允许使用正整数和负整数,负整数从集合中的最后一个元素开始倒数
Returns:
Type Description * 查询到的元素 Example
返回指定下标处的元素 const collection = new Collection([1, 2, 3]) const item = collection.at(1) -
inherited clone(){Collection}
base/Collection.js, line 156 -
克隆并返回一个新集合对象
Returns:
Type Description Collection 克隆后的集合对象 Example
克隆并返回一个新集合对象 const collection = new Collection([1, 2, 3]) const cloneObj = collection.clone() -
inherited concat(collection){Collection}
base/Collection.js, line 173 -
将一个数组或者集合对象链接到当前集合对象末尾
Name Type Description collectionArray | Collection 要链接的数组或者集合对象
Returns:
Type Description Collection 链接后的新集合对象 Example
将一个数组或者集合对象链接到当前集合对象末尾 const collection = new Collection([1, 2, 3]) collection.concat([{'a': 1}, {'b': 2}]) collection.concat(new Collection([4, 5, 6])) -
inherited createInstance(item){*}
base/Collection.js, line 868 -
创建实例,可由子类重载
Name Type Description item* 要创建的实例对象
Returns:
Type Description * 创建的实例对象 -
inherited every(fn){Boolean}
base/Collection.js, line 206 -
检测数组所有元素是否都符合指定条件(通过函数提供)
Name Type Description fnfunction 过滤条件
Returns:
Type Description Boolean 是否全部满足过滤条件 Example
检测数组所有元素是否都符合指定条件 const collection = new Collection([1, 2, 3]) const isNumber = collection.every(function(item) { return typeof item === 'number' }) -
inherited filter(fn){Collection}
base/Collection.js, line 233 -
通过一个过滤条件(函数提供)来过滤并返回元素
Name Type Description fnfunction 过滤条件,如果过滤条件不是函数,则返回undefined
Returns:
Type Description Collection 过滤后的新集合对象 Example
通过一个过滤条件(函数提供)来过滤并返回元素 const collection = new Collection([1, 2, 3, 4, 5]) const newCollection = collection.filter(function(item) { return item > 2 }) -
inherited find(fn){*}
base/Collection.js, line 257 -
返回第一个符合过滤条件(函数提供)的元素,如果没找到则返回undefined
Name Type Description fnfunction 过滤条件,如果过滤条件不是函数,也返回undefined
Returns:
Type Description * 第一个符合过滤条件的元素 Example
返回第一个符合过滤条件(函数提供)的元素,如果没找到则返回undefined const collection = new Collection([1, 2, 3, 4, 5]) const item = collection.find(function(item) { return item > 2 }) -
inherited findIndex(fn){Number}
base/Collection.js, line 282 -
返回第一个符合过滤条件(函数提供)的元素的下标,如果没找到则返回-1
Name Type Description fnfunction 过滤条件
Returns:
Type Description Number 第一个符合过滤条件(函数提供)的元素的下标 Example
返回第一个符合过滤条件(函数提供)的元素的下标,如果没找到则返回-1 const collection = new Collection([1, 2, 3, 4, 5]) const index = collection.findIndex(function(item) { return item > 1 }) -
inherited flatten(fn){Collection}
base/Collection.js, line 300 -
扁平化一个集合对象,通过传入的扁平化函数来指定要扁平化的对象数组,直到指定的对象数组为空或者元素数量为0,之后返回一个新集合对象
Name Type Description fnfunction 扁平化函数,通过该函数来指定要扁平化的对象数组,如果该函数不是一个函数对象,则返回undefined
Returns:
Type Description Collection 扁平化后的集合对象 Example
扁平化一个集合对象 const collection = new Collection([{ layers: [1, 2, 3] },{ items: [4, 5, 6] }]) const flatten = collection.flatten(function(item) { return item.layers || item.items }) -
inherited forEach(fn){Collection}
base/Collection.js, line 347 -
对集合中的所有元素执行传入的函数
Name Type Description fnfunction 针对元素的执行函数,参考js数组的forEach方法
Returns:
Type Description Collection 执行完函数后的集合对象 Example
对集合中的所有元素执行传入的函数 const collection = new Collection([1, 2, 3]) collection.forEach(function(item) { console.log("item:", item) }) -
inherited getItemAt(index){*}
base/Collection.js, line 359 -
获取指定下标的元素,没找到则返回undefined
Name Type Description indexNumber 元素下标
Returns:
Type Description * 该下标下的元素 Example
获取指定下标的元素 const collection = new Collection([1, 2, 3]) const item = collection.getItemAt(1) -
inherited includes(item){Boolean}
base/Collection.js, line 371 -
判断集合中是否包含该元素
Name Type Description item* 要检查的元素对象
Returns:
Type Description Boolean 集合中是否包含该元素 Example
判断集合中是否包含该元素 const collection = new Collection([1, 2, 3]) const isInclude = collection.includes(2) -
inherited indexOf(item, fromIndex){Number}
base/Collection.js, line 393 -
返回元素在集合中的下标
Name Type Description item* 要在集合中寻找的元素
fromIndexNumber 选择起始下标,默认为0,即从何处开始寻找
Returns:
Type Description Number 元素在集合中的下标 Examples
判断集合中是否包含该元素 const item = { 'a': 1 } const collection = new Collection([item, 2, 3]) const index = collection.indexOf(item)判断集合中是否包含该元素-选择起始下标 const item = { 'a': 1 } const collection = new Collection([item, 2, 3, item]) const index = collection.indexOf(item, 1) -
inherited join(separator){String}
base/Collection.js, line 417 -
通过传入一个分隔符,将集合中的元素通过分隔符拼接成一个字符串并返回
Name Type Description separatorString 分割符号
Returns:
Type Description String 拼接完成的字符串 Example
通过传入一个分隔符,将集合中的元素通过分隔符拼接成一个字符串并返回 const collection = new Collection([1, 2, 3]) const str = collection.join(',') -
inherited lastIndexOf(item, fromIndex){Number}
base/Collection.js, line 438 -
从集合的最末尾开始,寻找该元素,并返回元素下标
Name Type Description item* 要寻找的元素
fromIndexNumber 从何处开始查找,默认为集合的长度-1
Returns:
Type Description Number 第一个找到的元素下标,未找到则返回-1 Examples
从集合的最末尾开始,寻找该元素,并返回元素下标 const collection = new Collection([1, 2, 3]) const index = collection.lastIndexOf(3)从集合的最末尾开始,寻找该元素,并返回元素下标 - 指定起始额位置 const collection = new Collection([1, 2, 3, 3, 3]) const index = collection.lastIndexOf(3, 3) -
inherited map(fn){Collection}
base/Collection.js, line 460 -
通过一个遍历函数来遍历该集合下的所有元素,并返回一个新集合对象
Name Type Description fnfunction 遍历函数
Returns:
Type Description Collection 遍历后的新集合对象 Example
通过一个遍历函数来遍历该集合下的所有元素,并返回一个新集合对象 const collection = new Collection([1, 2, 3]) const newCollection = collection.map(function (item) { return item + 1 }) -
inherited pop(){*}
base/Collection.js, line 481 -
删除并返回集合的最后一个元素
Returns:
Type Description * 集合的最后一个元素 Example
删除并返回集合的最后一个元素 const collection = new Collection([1, 2, 3]) const item = collection.pop() -
inherited push(item){Collection}
base/Collection.js, line 493 -
添加一个元素到集合中
Name Type Description item* 要添加的元素
Returns:
Type Description Collection 添加完元素后的集合对象 Example
添加一个元素到集合中 const collection = new Collection([1, 2, 3]) collection.push(4) -
inherited reduce(fn, baseValue){*}
base/Collection.js, line 508 -
接收一个函数做为累加器,将集合中的每一个元素(下标从小到大的顺序)进行累加,最后返回一个对象
Name Type Description fnfunction 累加器函数
baseValue* 累加的基础对象
Returns:
Type Description * 累加后的对象 Example
接收一个函数做为累加器,将集合中的每一个元素(下标从小到大的顺序)进行累加,最后返回一个对象 const collection = new Collection([1, 2, 3]) const sum = collection.reduce(function (reduceCarry, item) { return reduceCarry += item }, 0) -
inherited reduceRight(fn, baseValue){*}
base/Collection.js, line 539 -
接收一个函数做为累加器,将集合中的每一个元素(下标从大到小的顺序)进行累加,最后返回一个对象
Name Type Description fnfunction 累加器函数
baseValue* 累加的基础对象
Returns:
Type Description * 累加后的对象 Example
接收一个函数做为累加器,将集合中的每一个元素(下标从大到小的顺序)进行累加,最后返回一个对象 const collection = new Collection([1, 2, 3]) const sum = collection.reduce(function (reduceCarry, item) { console.log(item) }) -
remove(item){*}
document/layer/support/RendererCollection.js, line 81 -
Name Type Description itemitem Returns:
Type Description * -
removeAll(){*}
document/layer/support/RendererCollection.js, line 101 -
Returns:
Type Description * -
removeAt(){*}
document/layer/support/RendererCollection.js, line 116 -
Returns:
Type Description * -
removeMany(){*}
document/layer/support/RendererCollection.js, line 90 -
Returns:
Type Description * -
inherited reorder(item, index)
base/Collection.js, line 641 -
将指的元素调整到集合中指的下标位置
Name Type Description item* 要排序的元素
indexNumber 元素要调整到的位置
Example
将指的元素调整到集合中指的下标位置 const collection = new Collection([1, 2, 3]) collection.reorder(1, 2) -
inherited reverse(){Collection}
base/Collection.js, line 659 -
将集合对象中的元素反转,并返回新集合对象
Returns:
Type Description Collection 新的集合对象 Example
将集合对象中的元素反转,并返回新集合对象 const collection = new Collection([1, 2, 3]) const newCollection = collection.reverse() -
inherited shift(){*}
base/Collection.js, line 671 -
删除并返回集合的第一个元素(元素下标为0)
Returns:
Type Description * 集合的第一个元素 Example
删除并返回集合的第一个元素 const collection = new Collection([1, 2, 3]) const item = collection.shift() -
inherited slice(start, end){Collection}
base/Collection.js, line 684 -
截取集合中从start开始到end下标的元素,并返回一个新集合对象
Name Type Description startNumber 从0开始的元素小标
endNumber 截至的元素下标,不填则默认到集合最后一个元素
Returns:
Type Description Collection 新集合对象 Example
截取集合中从start开始到end下标的元素,并返回一个新集合对象 const collection = new Collection([1, 2, 3, 4, 5]) const newCollection = collection.slice(1, 3) -
inherited some(fn){Boolean}
base/Collection.js, line 704 -
判断集合对象中的元素是否满足过滤条件,只要有一个元素满足过滤条件,则会返回true,如果都不满足过滤条件,则返回false
Name Type Description fnfunction 过滤条件,如果过滤条件不是函数,也返回false
Returns:
Type Description Boolean 是否满足过滤条件 Example
判断集合对象中的元素是否满足过滤条件 const collection = new Collection([1, 2, 3, 4, 5]) const flag = collection.some(function (item) { return item === 1 }) -
inherited sort(fn){Collection}
base/Collection.js, line 734 -
通过一个排序函数来对当前的集合进行排序,之后返回一个新集合对象,参考js的sort函数
Name Type Description fnfunction 排序函数,不填则默认按从小到达排序
Returns:
Type Description Collection 新的集合对象 Example
通过一个排序函数来对当前的集合进行排序,之后返回一个新集合对象 const collection = new Collection([{ 'a': 2 },{ 'a': 1 },{ 'a': 3 }]) const newCollection = collection.sort(function (itemA, itemB) { return itemA.a - itemB.a }) -
inherited splice(start, deleteCount, items){Collection}
base/Collection.js, line 763 -
向集合中删除或添加一个元素,参考js的splice方法
Name Type Description startNumber 删除或添加的起始下标
deleteCountNumber 删除或添加的数量
items* repeatable 要删除或添加的元素
Returns:
Type Description Collection 新的集合对象 Examples
向集合中删除一个元素 const collection = new Collection([1, 2, 3]) const newCollection = collection.splice(1, 1)向集合中添加一个元素 const collection = new Collection([1, 2, 3]) collection.splice(1, 0, 1) -
inherited toArray(){Array}
base/Collection.js, line 775 -
返回集合对象中元素组成的数组
Returns:
Type Description Array 集合对象中元素组成的数组 Example
返回集合对象中元素组成的数组 const collection = new Collection([1, 2, 3]) collection.toArray() -
inherited unique(key){Collection}
base/Collection.js, line 829 -
去除集合中的重复元素
Name Type Description keyfunction | String 指定一个去重函数或者要素的去重字段
Returns:
Type Description Collection 去重后的集合对象 Examples
No Arguments
const unique = new Collection([2, 1, 2, 3, 3, 4, 5, 1, 2]).unique(); console.log(unique); // [2, 1, 3, 4, 5]Property Name
const students = new Collection([ { name: 'Rick', grade: 'A'}, { name: 'Mick', grade: 'B'}, { name: 'Richard', grade: 'A'}, ]); // Students with unique grades. students.unique('grade'); // [{ name: 'Rick', grade: 'A'}, { name: 'Mick', grade: 'B'}]With Callback
const students = new Collection([ { name: 'Rick', grade: 'A'}, { name: 'Mick', grade: 'B'}, { name: 'Richard', grade: 'A'}, ]); // Students with unique grades. students.unique(s => s.grade); // [{ name: 'Rick', grade: 'A'}, { name: 'Mick', grade: 'B'}] -
inherited unshift(items)
base/Collection.js, line 790 -
向集合起始位置添加一个或多个元素
Name Type Description items* repeatable 要添加的一个或多个元素
Example
返回集合对象中元素组成的数组 const collection = new Collection([1, 2, 3]) collection.unshift(1, 2)