Tell me, please, the example https://tech.yandex.ru/maps/jsbox/2.1/object_manager_filter shows filtering of objects.

What is not convenience and my question.

For example, to show only 'Schools' I need to remove the rest of the checkboxes ('Pharmacy', 'Store', 'Hospital', 'Bar'), this is not convenient, how to do the opposite, so that by ticking the corresponding objects appear?

In the example there is a code:

... // Создадим 5 пунктов выпадающего списка. var listBoxItems = ['Школа', 'Аптека', 'Магазин', 'Больница', 'Бар'] .map(function (title) { return new ymaps.control.ListBoxItem({ data: { content: title }, state: { selected: true } }) }), ... 

if state: selected: true is replaced with false , it turns out what is needed, but when all the checkboxes are cleared on the map there is no object, I understand that the isSelected method at this moment returns false. There is not enough isDeselected method to do the opposite.

Tell me, please, how to make sure that when the checkboxes are all cleared (deselect), show all the objects on the map, if you can use sands for example?

    1 answer 1

    It is enough to check that no tag types have been selected:

     function getFilterFunction(categories) { var isCategoriesEmpty = Object.values(categories).reduce(function(acc, value) {return acc || value}, false); return function (obj) { var content = obj.properties.balloonContent; return !isCategoriesEmpty || categories[content] } } 

    https://jsfiddle.net/kqc6epx9/

    • Thank you very much! This is what you need. - user337179