0

I'm using OpenLayers to show my map with some layers. I've a field where I can add some filters with CQL code. I can successfully add a new filter to my map, and only the right points appear in my map but when I try to remove the filters it's deleting my Layer instead of my previous CQL_Filter result, so is deleting ALL the points from the map.

//My var map is previously declared
var layerFromMap = map.getLayersByName(input.name)[0];
//If my input is empty then I should delete the filters, like resetting the search
if (input.value.length > 0) {
    layerFromMap.mergeNewParams({ 'CQL_FILTER': input.value });
    layerFromMap.redraw();
} else {
    delete layerFromMap.params.CQL_FILTER;
    layerFromMap.redraw();
}

When input is empty layerFromMapparams.CQL_FILTER is deleting my layer from the map, so all the points are deleted. Why is this happening? How can I only remove the filter so all the points appear again?

2

I just find out how to do it and is very simple, just set the CQL_FILTER to null:

//My var map is previously declared
var layerFromMap = map.getLayersByName(input.name)[0];
//If my input is empty then I should delete the filters, like resetting the search
if (input.value.length > 0) {
    layerFromMap.mergeNewParams({ 'CQL_FILTER': input.value });
    layerFromMap.redraw();
} else {
    layerFromMap.mergeNewParams({ 'CQL_FILTER': null });
    layerFromMap.redraw();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.