How to get an array of objects after filtering in Yandex.Maps? I try this:

flats.setFilter(filters); myMap.geoObjects.add(flats); alert('Количество отфильтрованных объектов на карте: ' + flats.objects.overlays.getLenght()); 

As if overlay is incorrectly specified

A similar question in the Yandex.Maps API club: https://yandex.ru/blog/mapsapi/kak-uznat-kolichestvo-elementov-posle-primeneniya-setfilter

Example from the documentation: https://tech.yandex.com/maps/doc/jsapi/2.1/ref/reference/objectManager.OverlayCollection-docpage/#getLength If you do as in the example, it displays 0.

  • Can you give a more specific example of what doesn't work? - flapenguin
  • There is an array of 100 apartments with data on them (area, price, etc.). I set the filter: 1 million <price <2 million. There were, say, 50 such apartments. I display these 50 apartments on the map. And you need to get the number of these apartments and an array of them. The total number of apartments to get is obtained: flats.objects.getLength (). But the number of filtered - no. - Albert Alexandrov
  • What does "not work" mean? Is the wrong value returned or does the code fail with an error? If you put together an example on jsfiddle (or right here in the question), it will be much easier to answer your question. - flapenguin
  • Is to blame. Returns 0. - Albert Alexandrov
  • Overlays are created asynchronously, so there are 0 of them. Do you want the number of filtered elements in general or the number of filtered elements visible on the map? - flapenguin

1 answer 1

You can get an array of filtered objects themselves as isFilteredOut :

 objectManager.getAll().filter(function(x) { return !objectManager.getObjectState(x.id).isFilteredOut; }) 
  • It! Thank you very much! - Albert Alexandrov