File tree Expand file tree Collapse file tree 2 files changed +34
-7
lines changed Expand file tree Collapse file tree 2 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -446,6 +446,34 @@ export class Util {
446
446
}
447
447
return false ;
448
448
}
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
+
449
477
/**
450
478
* @function ol.supermap.Util.setMask
451
479
* @description 为图层设置掩膜。
Original file line number Diff line number Diff line change @@ -2184,13 +2184,12 @@ export class WebMap extends Observable {
2184
2184
rows = datas . slice ( 1 ) ,
2185
2185
fieldIndex = titles . findIndex ( title => title === divisionField ) ;
2186
2186
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
+ }
2194
2193
//todo 需提示忽略无效数据
2195
2194
if ( feature ) {
2196
2195
let newFeature = window . cloneDeep ( feature ) ;
You can’t perform that action at this time.
0 commit comments