@@ -2246,7 +2246,7 @@ export class WebMap extends Observable {
22462246 * @param {array } allFeatures - 图层上的feature集合
22472247 */
22482248 getFiterFeatures ( filterCondition , allFeatures ) {
2249- let condition = this . replaceFilterCharacter ( filterCondition ) ;
2249+ let condition = this . parseFilterCondition ( filterCondition ) ;
22502250 let sql = "select * from json where (" + condition + ")" ;
22512251 let filterFeatures = [ ] ;
22522252 for ( let i = 0 ; i < allFeatures . length ; i ++ ) {
@@ -2270,14 +2270,29 @@ export class WebMap extends Observable {
22702270
22712271 /**
22722272 * @private
2273- * @function ol.supermap.WebMap.prototype.replaceFilterCharacter
2274- * @description 替换查询语句 中的 and / AND / or / OR / = / !=
2275- * @param {string } filterString - 过滤条件
2273+ * @function ol.supermap.WebMap.prototype.parseFilterCondition
2274+ * @description 1、替换查询语句 中的 and / AND / or / OR / = / !=
2275+ * 2、匹配 Name in ('', ''),多条件需用()包裹
2276+ * @param {string } filterCondition - 过滤条件
22762277 * @return {string } 换成组件能识别的字符串
22772278 */
2278- replaceFilterCharacter ( filterString ) {
2279- filterString = filterString . replace ( / = / g, '==' ) . replace ( / A N D | a n d / g, '&&' ) . replace ( / o r | O R / g, '||' ) . replace ( / < = = / g, '<=' ) . replace ( / > = = / g, '>=' ) ;
2280- return filterString ;
2279+ parseFilterCondition ( filterCondition ) {
2280+ return filterCondition
2281+ . replace ( / = / g, "==" )
2282+ . replace ( / A N D | a n d / g, "&&" )
2283+ . replace ( / o r | O R / g, "||" )
2284+ . replace ( / < = = / g, "<=" )
2285+ . replace ( / > = = / g, ">=" )
2286+ . replace ( / \( ? [ ^ \( ] + ?\s + i n \s + \( [ ^ \) ] + ?\) \) ? / g, ( res ) => {
2287+ // res格式:(省份 in ('四川', '河南'))
2288+ const data = res . match ( / ( [ ^ ( ] + ?) \s + i n \s + \( ( [ ^ ) ] + ?) \) / ) ;
2289+ return data . length === 3
2290+ ? `(${ data [ 2 ]
2291+ . split ( "," )
2292+ . map ( ( c ) => `${ data [ 1 ] } == ${ c . trim ( ) } ` )
2293+ . join ( " || " ) } )`
2294+ : res ;
2295+ } ) ;
22812296 }
22822297
22832298 /**
@@ -2892,7 +2907,7 @@ export class WebMap extends Observable {
28922907 } ) ;
28932908 if ( layerInfo . filterCondition ) {
28942909 //过滤条件
2895- let condition = that . replaceFilterCharacter ( layerInfo . filterCondition ) ;
2910+ let condition = that . parseFilterCondition ( layerInfo . filterCondition ) ;
28962911 let sql = "select * from json where (" + condition + ")" ;
28972912 let filterResult = window . jsonsql . query ( sql , {
28982913 attributes : feature . get ( 'attributes' )
@@ -3042,7 +3057,7 @@ export class WebMap extends Observable {
30423057 return function ( feature ) {
30433058 if ( layerInfo . filterCondition ) {
30443059 //过滤条件
3045- let condition = that . replaceFilterCharacter ( layerInfo . filterCondition ) ;
3060+ let condition = that . parseFilterCondition ( layerInfo . filterCondition ) ;
30463061 let sql = "select * from json where (" + condition + ")" ;
30473062 let filterResult = window . jsonsql . query ( sql , {
30483063 attributes : feature . get ( 'attributes' )
0 commit comments