标记点击时突出显示侧边栏

时间:2012-03-26 21:39:16

标签: javascript jquery google-maps-api-3 google-maps-markers

我的当前谷歌地图代码正常工作,如果我点击侧边栏链接,会触发标记事件,然后打开信息窗口。单击标记时,我需要做什么来突出显示侧栏上的块?

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;
}

创建标记时,我还创建了侧边栏条目:

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>';

单击标记时,我需要做什么来突出显示侧栏上的块?

1 个答案:

答案 0 :(得分:4)

像这样修改click监听器:

 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
});

哪里有一些风格

.new_style {
    border: 1px solid red;
}