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 {
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 为图层设置掩膜。
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments