MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / getRangeStyleGroup

Method getRangeStyleGroup

src/openlayers/mapping/WebMap.js:3737–3845  ·  view source on GitHub ↗

* @private * @function WebMap.prototype.getRangeStyleGroup * @description 获取分段专题图的styleGroup样式 * @param {Object} parameters- 图层信息 * @param {Array} features - 所以的feature集合 * @returns {Array} styleGroups

(parameters, features)

Source from the content-addressed store, hash-verified

3735 * @returns {Array} styleGroups
3736 */
3737 async getRangeStyleGroup(parameters, features) {
3738 // 找出分段值
3739 let featureType = parameters.featureType,
3740 themeSetting = parameters.themeSetting,
3741 style = parameters.style;
3742 let count = themeSetting.segmentCount,
3743 method = themeSetting.segmentMethod,
3744 colors = themeSetting.colors,
3745 customSettings = themeSetting.customSettings,
3746 fieldName = themeSetting.themeField;
3747 let values = [],
3748 attributes;
3749 let segmentCount = count;
3750 let segmentMethod = method;
3751 let that = this;
3752 features.forEach(function (feature) {
3753 attributes = feature.get('attributes');
3754 try {
3755 if (attributes) {
3756 //过滤掉非数值的数据
3757 let value = attributes[fieldName.trim()];
3758 if (value !== undefined && value !== null && Util.isNumber(value)) {
3759 values.push(parseFloat(value));
3760 }
3761 } else if (feature.get(fieldName) && Util.isNumber(feature.get(fieldName))) {
3762 if (feature.get(fieldName)) {
3763 values.push(parseFloat(feature.get(fieldName)));
3764 }
3765 }
3766 } catch (e) {
3767 that.errorCallback && that.errorCallback(e);
3768 }
3769 });
3770
3771 let segements;
3772 try {
3773 segements = ArrayStatistic.getArraySegments(values, segmentMethod, segmentCount);
3774 } catch (e) {
3775 that.errorCallback && that.errorCallback(e);
3776 }
3777 if (segements) {
3778 let itemNum = segmentCount;
3779 if (attributes && segements[0] === segements[attributes.length - 1]) {
3780 itemNum = 1;
3781 segements.length = 2;
3782 }
3783
3784 //保留两位有效数
3785 for (let key in segements) {
3786 let value = segements[key];
3787 if (Number(key) === 0) {
3788 // 最小的值下舍入,要用两个等于号。否则有些值判断不对
3789 value = Math.floor(value * 100) / 100;
3790 } else {
3791 // 其余上舍入
3792 value = Math.ceil(value * 100) / 100 + 0.1; // 加0.1 解决最大值没有样式问题
3793 }
3794

Callers 5

createRangeSourceMethod · 0.95
WebMapSpec.jsFile · 0.45
WebMapSpec.jsFile · 0.45
successCallbackFunction · 0.45

Calls 7

forEachMethod · 0.80
trimMethod · 0.80
pushMethod · 0.80
getArraySegmentsMethod · 0.80
toOpenLayersStyleMethod · 0.80
getMethod · 0.45
getGradientColorsMethod · 0.45

Tested by

no test coverage detected