JK0124
JK0124

Reputation: 395

Hightlight sidebar block on marker click

I have my current google maps code working to the point where if I click on the on the sidebar link, a marker event is fired then the infowindow is opened. What do I need to do to highlight the block on the sidebar when the marker is clicked??

function createMarkers(point, username, st) {
    var html = '<b>' + username + '</b> <br/> ' + st;

    var marker = new google.maps.Marker({
        position: point, 
        map: map, 
        //zIndex: Math.round(point.lat()*-100000)<<5,
        title: username
    });

    //Closes any open infowindow while clicking on another marker
    infowindow = new google.maps.InfoWindow();
    google.maps.event.addListener(marker, 'click', function() {
        infowindow.close();
        infowindow.setContent(html);
        infowindow.open(map, marker);
    });

    markersArray.push(marker);

    return marker;
}

When the marker is being created, I also created the sidebar entries:

sidebar.innerHTML += '<span id="sidebarTxt">'
                                     +'<a href="javascript:sidebar_click(' + i + ')">' 
                                     + '<b>' + name + '</b> </a> <br/> ' 
                                     + 'St: ' + st + '<br />' 
                                     + 'St Preference: ' + location + '<br />' 
                                     + 'Distance from me: ' + Number(distance).toFixed(2) + 'miles <br />' 
                                     +' </span>';

What do I need to do to highlight the block on the sidebar when the marker is clicked??

Upvotes: 1

Views: 687

Answers (1)

tusar
tusar

Reputation: 3424

Modify the click listener like this :

 google.maps.event.addListener(marker, 'click', function() {
    infowindow.close();
    infowindow.setContent(html);
    infowindow.open(map, marker);
    $("#sidebarTxt").toggleClass("new_style"); // this line adds the new_style to  sidebarTxt span
});

Where have some style

.new_style {
    border: 1px solid red;
}

Upvotes: 4

Related Questions