There is a map with labels and baluns (Yandex api 2.1), and there is a list of addresses outside the map. by clicking on this list, you need to open the balun, and center the map, everything seems to be done, but for some reason, the clicker does not always open the desired balun, what’s wrong? I really need help!

// По ΠΊΠ»ΠΈΠΊΡƒ Π½Π° адрСс, ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°Π΅Ρ‚ Π±Π°Π»ΡƒΠ½ ΠΈ Ρ†Π΅Π½Ρ‚Ρ€ΠΈΡ€ΡƒΠ΅Ρ‚ ΠΊΠ°Ρ€Ρ‚Ρƒ $('.filter-result').on('click', '.filter-result__item', function(){ $(".filter-result__item").removeClass('filter-result__item_active'); $(this).addClass('filter-result__item_active'); var pos = $(this).find('.shop-address').text(); var indexObj = $(this).index(); //Π½ΠΎΠΌΠ΅Ρ€ ΠΌΠ΅Ρ‚ΠΊΠΈ var point = myMap.geoObjects.get(indexObj); //ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Ρ‹ ΠΌΠ΅Ρ‚ΠΊΠΈ var npoint = $.map(point.geometry.getCoordinates(), Number); //Ρ†Π΅Π½Ρ‚Ρ€ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ ΠΊΠ°Ρ€Ρ‚Π° myMap.setCenter(npoint, 13, {checkZoomRange: true, }).then(function () { //ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚ΡŒ Π±Π°Π»ΡƒΠ½ point.balloon.open(); }, function (err) { }, this); }); 

    1 answer 1

    In general, I found an interesting point, crammed in console.log () myMap.geoObjects, I saw that the answers of the geocoder may come in a different order, and it turns out that the indices are always different, not the sequence I added initially, I solved the problem with Crutch ((. result

    By clicking, I consider the number of all addresses, after which the circle takes the address on the clicked element, and compares it with an array of objects that the map returns, though in a not very nice way point.balloon._geoObject.properties._data.balloonContent compare 2 lines of addresses, and if exactly, then open the balun

     $('.filter-result').on('click', '.filter-result__item', function(){ $(".filter-result__item").removeClass('filter-result__item_active'); $(this).addClass('filter-result__item_active'); var pos = $(this).find('.shop-address').text(); var indexObj = $(this).index(); var lengthOng = $(".filter-result__item").length; for(var i = 0; i < lengthOng; i++){ //Π½ΠΎΠΌΠ΅Ρ€ ΠΌΠ΅Ρ‚ΠΊΠΈ var point = myMap.geoObjects.get(i); //ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Ρ‹ ΠΌΠ΅Ρ‚ΠΊΠΈ var npoint = point.geometry.getCoordinates(); var balloonCont = point.balloon._geoObject.properties._data.balloonContent; if(pos === balloonCont){ myMap.setCenter(npoint, 13, {checkZoomRange: false}); point.balloon.open(); } } }); 

    If anyone knows how to do without such a crutch, I would be grateful.