Skip to content

Commit f4a3406

Browse files
author
chenguanglin
committed
【update】优化行政区划上图字段匹配规则
review by zhaoq
1 parent d782eb8 commit f4a3406

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

src/openlayers/core/Util.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,34 @@ export class Util {
446446
}
447447
return false;
448448
}
449+
450+
/**
451+
* @function ol.supermap.Util.getHighestMatchAdministration
452+
* @param {string} featureName 初始匹配的要素数组
453+
* @param {string} fieldName 要匹配的地名
454+
* @returns {boolean} 是否匹配
455+
*/
456+
static getHighestMatchAdministration(features, fieldName) {
457+
let filterFeatures = features.filter(item => {
458+
return Util.isMatchAdministrativeName(item.properties.Name, fieldName);
459+
})
460+
461+
let maxMatchPercent = 0, maxMatchFeature = null;
462+
filterFeatures.forEach(feature => {
463+
let count = 0;
464+
Array.from(new Set(feature.properties.Name.split(''))).forEach((char) => {
465+
if (fieldName.includes(char)) {
466+
count++;
467+
}
468+
});
469+
if (count > maxMatchPercent) {
470+
maxMatchPercent = count;
471+
maxMatchFeature = feature;
472+
}
473+
});
474+
return maxMatchFeature;
475+
}
476+
449477
/**
450478
* @function ol.supermap.Util.setMask
451479
* @description 为图层设置掩膜。

src/openlayers/mapping/WebMap.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,13 +2184,12 @@ export class WebMap extends Observable {
21842184
rows = datas.slice(1),
21852185
fieldIndex = titles.findIndex(title => title === divisionField);
21862186
rows.forEach(row => {
2187-
let feature = features.find(item => {
2188-
if (divisionType === 'GB-T_2260') {
2189-
return item.properties.GB === row[fieldIndex];
2190-
} else {
2191-
return Util.isMatchAdministrativeName(item.properties.Name, row[fieldIndex]);
2192-
}
2193-
})
2187+
let feature;
2188+
if (divisionType === 'GB-T_2260') {
2189+
feature = features.find(item => item.properties.GB === row[fieldIndex])
2190+
} else {
2191+
feature = Util.getHighestMatchAdministration(features, row[fieldIndex]);
2192+
}
21942193
//todo 需提示忽略无效数据
21952194
if (feature) {
21962195
let newFeature = window.cloneDeep(feature);

0 commit comments

Comments
 (0)