* @private * @function WebMap.prototype.getUniqueStyleGroup * @description 获取单值专题图的styleGroup * @param {Object} parameters- 图层信息 * @param {Array} features - feature 数组 * @returns {Array} 单值样式
(parameters, features)
| 3557 | * @returns {Array} 单值样式 |
| 3558 | */ |
| 3559 | async getUniqueStyleGroup(parameters, features) { |
| 3560 | // 找出所有的单值 |
| 3561 | let featureType = parameters.featureType, |
| 3562 | style = parameters.style, |
| 3563 | themeSetting = parameters.themeSetting; |
| 3564 | let fieldName = themeSetting.themeField; |
| 3565 | |
| 3566 | let names = [], |
| 3567 | customSettings = themeSetting.customSettings; |
| 3568 | for (let i in features) { |
| 3569 | let attributes = features[i].get('attributes'); |
| 3570 | let name = attributes[fieldName]; |
| 3571 | let isSaved = false; |
| 3572 | for (let j in names) { |
| 3573 | if (names[j] === name) { |
| 3574 | isSaved = true; |
| 3575 | break; |
| 3576 | } |
| 3577 | } |
| 3578 | if (!isSaved) { |
| 3579 | names.push(name); |
| 3580 | } |
| 3581 | } |
| 3582 | |
| 3583 | //生成styleGroup |
| 3584 | let styleGroup = []; |
| 3585 | const usedColors = this.getCustomSettingColors(customSettings, featureType).map((item) => item.toLowerCase()); |
| 3586 | const curentColors = this.getUniqueColors( |
| 3587 | themeSetting.colors || this.defaultParameters.themeSetting.colors, |
| 3588 | names.length + Object.keys(customSettings).length |
| 3589 | ).map((item) => item.toLowerCase()); |
| 3590 | const newColors = difference(curentColors, usedColors); |
| 3591 | for (let index = 0; index < names.length; index++) { |
| 3592 | const name = names[index]; |
| 3593 | //兼容之前自定义是用key,现在因为数据支持编辑,需要用属性值。 |
| 3594 | let key = this.webMapVersion === '1.0' ? index : name; |
| 3595 | let custom = customSettings[key]; |
| 3596 | if (Util.isString(custom)) { |
| 3597 | //兼容之前自定义只存储一个color |
| 3598 | custom = this.getCustomSetting(style, custom, featureType); |
| 3599 | customSettings[key] = custom; |
| 3600 | } |
| 3601 | if (!custom) { |
| 3602 | custom = this.getCustomSetting(style, newColors.shift(), featureType); |
| 3603 | } |
| 3604 | |
| 3605 | // 转化成 ol 样式 |
| 3606 | let olStyle, |
| 3607 | type = custom.type; |
| 3608 | if (type === 'SYMBOL_POINT') { |
| 3609 | olStyle = StyleUtils.getSymbolStyle(custom); |
| 3610 | } else if (type === 'SVG_POINT') { |
| 3611 | olStyle = await StyleUtils.getSVGStyle(custom); |
| 3612 | } else if (type === 'IMAGE_POINT') { |
| 3613 | olStyle = StyleUtils.getImageStyle(custom); |
| 3614 | } else { |
| 3615 | olStyle = await StyleUtils.toOpenLayersStyle(custom, featureType); |
| 3616 | } |
no test coverage detected