@@ -2267,7 +2267,7 @@ export class WebMap extends Observable {
2267
2267
* @param {array } allFeatures - 图层上的feature集合
2268
2268
*/
2269
2269
getFiterFeatures ( filterCondition , allFeatures ) {
2270
- let condition = this . replaceFilterCharacter ( filterCondition ) ;
2270
+ let condition = this . parseFilterCondition ( filterCondition ) ;
2271
2271
let sql = "select * from json where (" + condition + ")" ;
2272
2272
let filterFeatures = [ ] ;
2273
2273
for ( let i = 0 ; i < allFeatures . length ; i ++ ) {
@@ -2291,14 +2291,29 @@ export class WebMap extends Observable {
2291
2291
2292
2292
/**
2293
2293
* @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 - 过滤条件
2297
2298
* @return {string } 换成组件能识别的字符串
2298
2299
*/
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
+ } ) ;
2302
2317
}
2303
2318
2304
2319
/**
@@ -2926,7 +2941,7 @@ export class WebMap extends Observable {
2926
2941
} ) ;
2927
2942
if ( layerInfo . filterCondition ) {
2928
2943
//过滤条件
2929
- let condition = that . replaceFilterCharacter ( layerInfo . filterCondition ) ;
2944
+ let condition = that . parseFilterCondition ( layerInfo . filterCondition ) ;
2930
2945
let sql = "select * from json where (" + condition + ")" ;
2931
2946
let filterResult = window . jsonsql . query ( sql , {
2932
2947
attributes : feature . get ( 'attributes' )
@@ -3076,7 +3091,7 @@ export class WebMap extends Observable {
3076
3091
return function ( feature ) {
3077
3092
if ( layerInfo . filterCondition ) {
3078
3093
//过滤条件
3079
- let condition = that . replaceFilterCharacter ( layerInfo . filterCondition ) ;
3094
+ let condition = that . parseFilterCondition ( layerInfo . filterCondition ) ;
3080
3095
let sql = "select * from json where (" + condition + ")" ;
3081
3096
let filterResult = window . jsonsql . query ( sql , {
3082
3097
attributes : feature . get ( 'attributes' )
0 commit comments