@@ -2267,7 +2267,7 @@ export class WebMap extends Observable {
22672267 * @param {array } allFeatures - 图层上的feature集合
22682268 */
22692269 getFiterFeatures ( filterCondition , allFeatures ) {
2270- let condition = this . replaceFilterCharacter ( filterCondition ) ;
2270+ let condition = this . parseFilterCondition ( filterCondition ) ;
22712271 let sql = "select * from json where (" + condition + ")" ;
22722272 let filterFeatures = [ ] ;
22732273 for ( let i = 0 ; i < allFeatures . length ; i ++ ) {
@@ -2291,14 +2291,29 @@ export class WebMap extends Observable {
22912291
22922292 /**
22932293 * @private
2294- * @function ol.supermap.WebMap.prototype.replaceFilterCharacter
2295- * @description 替换查询语句 中的 and / AND / or / OR / = / !=
2296- * @param {string } filterString - 过滤条件
2294+ * @function ol.supermap.WebMap.prototype.parseFilterCondition
2295+ * @description 1、替换查询语句 中的 and / AND / or / OR / = / !=
2296+ * 2、匹配 Name in ('', ''),多条件需用()包裹
2297+ * @param {string } filterCondition - 过滤条件
22972298 * @return {string } 换成组件能识别的字符串
22982299 */
2299- replaceFilterCharacter ( filterString ) {
2300- filterString = filterString . replace ( / = / g, '==' ) . replace ( / A N D | a n d / g, '&&' ) . replace ( / o r | O R / g, '||' ) . replace ( / < = = / g, '<=' ) . replace ( / > = = / g, '>=' ) ;
2301- return filterString ;
2300+ parseFilterCondition ( filterCondition ) {
2301+ return filterCondition
2302+ . replace ( / = / g, "==" )
2303+ . replace ( / A N D | a n d / g, "&&" )
2304+ . replace ( / o r | O R / g, "||" )
2305+ . replace ( / < = = / g, "<=" )
2306+ . replace ( / > = = / g, ">=" )
2307+ . replace ( / \( ? [ ^ \( ] + ?\s + i n \s + \( [ ^ \) ] + ?\) \) ? / g, ( res ) => {
2308+ // res格式:(省份 in ('四川', '河南'))
2309+ const data = res . match ( / ( [ ^ ( ] + ?) \s + i n \s + \( ( [ ^ ) ] + ?) \) / ) ;
2310+ return data . length === 3
2311+ ? `(${ data [ 2 ]
2312+ . split ( "," )
2313+ . map ( ( c ) => `${ data [ 1 ] } == ${ c . trim ( ) } ` )
2314+ . join ( " || " ) } )`
2315+ : res ;
2316+ } ) ;
23022317 }
23032318
23042319 /**
@@ -2926,7 +2941,7 @@ export class WebMap extends Observable {
29262941 } ) ;
29272942 if ( layerInfo . filterCondition ) {
29282943 //过滤条件
2929- let condition = that . replaceFilterCharacter ( layerInfo . filterCondition ) ;
2944+ let condition = that . parseFilterCondition ( layerInfo . filterCondition ) ;
29302945 let sql = "select * from json where (" + condition + ")" ;
29312946 let filterResult = window . jsonsql . query ( sql , {
29322947 attributes : feature . get ( 'attributes' )
@@ -3076,7 +3091,7 @@ export class WebMap extends Observable {
30763091 return function ( feature ) {
30773092 if ( layerInfo . filterCondition ) {
30783093 //过滤条件
3079- let condition = that . replaceFilterCharacter ( layerInfo . filterCondition ) ;
3094+ let condition = that . parseFilterCondition ( layerInfo . filterCondition ) ;
30803095 let sql = "select * from json where (" + condition + ")" ;
30813096 let filterResult = window . jsonsql . query ( sql , {
30823097 attributes : feature . get ( 'attributes' )
0 commit comments