Card index, clicked on the external link to open the balloon and centralize the map.



  • Got it. http://jsfiddle.net/AJIEKCEU/Leu6dvjr/ With the mark and the balunas, there's a list of addresses outside the map, and the click on that list needs to open a baloon, and centralize a map like that, but somehow it doesn't always open the right baloon. 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);
            });
    


  • Anyway, I found an interesting point in the console.log. https://jsfiddle.net/AJIEKCEU/6brtgw2g/

    I'm counting the number of all the addresses, and then the chikle takes the address on the clicked element, and compares to a set of objects that returns the map, and it's not a very beautiful way. point.balloon._geoObject.properties._data.balloonContentI'm comparing two lines of addresses, and if I do, I'll open the balloon.

    $('.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'd appreciate it.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2