Yo uso la biblioteca Leaflet-WFST. Así que tengo capas wms y wfs. Con wms, todo es simple, hay cql_filter. Estoy escribiendo un código donde se aplica cql_filter al hacer clic en la casilla de verificación, aquí está el código:
$('#s23').click(function(){ if($("#s23").is(":checked")){ if(layer.wmsParams.cql_filter != '' && layer.wmsParams.cql_filter.includes('layer_id=23') == false){ layer.setParams({ cql_filter: layer.wmsParams.cql_filter + ' OR layer_id=23' }); }else layer.setParams({ cql_filter: 'layer_id=23' }); layer.setOpacity(1); }else if(layer.wmsParams.cql_filter.includes(' OR layer_id=23') == true){ l_edit = layer.wmsParams.cql_filter.replace(" OR layer_id=23", ""); layer.setParams({ cql_filter: l_edit }); }else if(layer.wmsParams.cql_filter.includes('layer_id=23 OR ') == true){ l_edit = layer.wmsParams.cql_filter.replace("layer_id=23 OR ", ""); layer.setParams({ cql_filter: l_edit }); }else layer.setParams({ cql_filter: '' }); console.log(layer.wmsParams.cql_filter); }); $('#s29').click(function(){ if($("#s29").is(":checked")){ console.log(layer); if(layer.wmsParams.cql_filter != '' && layer.wmsParams.cql_filter.includes('layer_id=29') == false) layer.setParams({ cql_filter: layer.wmsParams.cql_filter + ' OR layer_id=29' }); else layer.setParams({ cql_filter: 'layer_id=29' }); layer.setOpacity(1); console.log(layer.wmsParams.cql_filter); }else if(layer.wmsParams.cql_filter.includes(' OR layer_id=29') == true){ l_edit = layer.wmsParams.cql_filter.replace(" OR layer_id=29", ""); layer.setParams({ cql_filter: l_edit }); }else if(layer.wmsParams.cql_filter.includes('layer_id=29 OR ') == true){ l_edit = layer.wmsParams.cql_filter.replace("layer_id=29 OR ", ""); layer.setParams({ cql_filter: l_edit }); }else layer.setParams({ cql_filter: '' }); console.log(layer.wmsParams.cql_filter); });Aquí, si se agrega cql_filter cuando se hace clic en la casilla de verificación, si está vacía, se activa cql_filter: 'layer_id=23', y si hay algo en cql_filter, entonces cql_filter: layer.wmsParams.cql_filter + ' O layer_id=23 ' también si la casilla de verificación se desmarcó, entonces este layer_id se elimina de cql_filter.
Puedo usar este código:
var layer_23 = new L.Filter.EQ('layer_id', 23); //var OR = new L.Filter.Or(layer.options.filter, layer_23); layer.options.filter = layer_23; layer.loadFeatures(layer_23);Para agregar un nuevo filtro, pero no sé cómo puedo eliminarlo o editarlo.
La pregunta es, ¿cómo se puede hacer lo mismo?