* @function LevelRenderer.Storage.prototype.iterShape * @description 遍历迭代器。 * * @param {function} fun - 迭代回调函数,return true终止迭代。 * @param {Object} option - 迭代参数,缺省为仅降序遍历普通层图形。 * @param {boolean} [hover=true] - 是否是高亮层图形。 * @param {string} [normal='down'] - 是否是普通层图形,迭代时是否指
(fun, option)
| 71 | * @return {LevelRenderer.Storage} this。 |
| 72 | */ |
| 73 | iterShape(fun, option) { |
| 74 | if (!option) { |
| 75 | var defaultIterateOption = { |
| 76 | hover: false, |
| 77 | normal: 'down', |
| 78 | update: false |
| 79 | }; |
| 80 | option = defaultIterateOption; |
| 81 | } |
| 82 | |
| 83 | if (option.hover) { |
| 84 | // 高亮层数据遍历 |
| 85 | for (var i = 0, l = this._hoverElements.length; i < l; i++) { |
| 86 | var el = this._hoverElements[i]; |
| 87 | el.updateTransform(); |
| 88 | if (fun(el)) { |
| 89 | return this; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | if (option.update) { |
| 95 | this.updateShapeList(); |
| 96 | } |
| 97 | |
| 98 | // 遍历: 'down' | 'up' |
| 99 | switch (option.normal) { |
| 100 | case 'down': |
| 101 | { |
| 102 | // 降序遍历,高层优先 |
| 103 | let l = this._shapeList.length; |
| 104 | while (l--) { |
| 105 | if (fun(this._shapeList[l])) { |
| 106 | return this; |
| 107 | } |
| 108 | } |
| 109 | break; |
| 110 | } |
| 111 | // case 'up': |
| 112 | default: |
| 113 | { |
| 114 | // 升序遍历,底层优先 |
| 115 | for (let i = 0, l = this._shapeList.length; i < l; i++) { |
| 116 | if (fun(this._shapeList[i])) { |
| 117 | return this; |
| 118 | } |
| 119 | } |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return this; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * @function LevelRenderer.Storage.prototype.getHoverShapes |
no test coverage detected