C
C
Cyber_bober2016-12-29 11:11:12
JavaScript
Cyber_bober, 2016-12-29 11:11:12

How to link the menu and labels on the map?

Hello, there is a list of objects in the sidebar and a map with labels,

myMap.geoObjects
        .add(new ymaps.Placemark([51.707730, 94.420949], {
            balloonContent: '«Объект 1»'
        }, {
            preset: 'islands#icon',
            iconColor: '#0095b6'
        }))
        .add(new ymaps.Placemark([51.716023, 94.430310], {
            balloonContent: 'Объект2'
        }, {
            preset: 'islands#icon',
            iconColor: '#0095b6'
        }))

How can you link these objects so that when you click on a menu item, you highlight the corresponding balloon, and when you click on the balloon, highlight the menu item? Please tell me or poke into the appropriate section of the API, I did not find (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
anikavoi, 2016-12-29
@anikavoi

Move to the label and open the balloon like this:
//click opens the balloon and moves the map, the center coordinate of the label
$(document).on('click','.oneLevelSpan',function(){
var id = $(this).data ("id");
var coords = myPointGeoObject[id].geometry.getCoordinates();
myPointGeoObject[id].balloon.open();
myMap.setZoom(14).panTo(coords,{
flying: 1
});
} );
But if you want to change the style of the balloon... then probably remove the marker from the collection and create a new one with different properties.
Accordingly, you get two onClics - on the menu item and on the marker.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question