如何在 Google 地图 API v3 中使用 Infobubbles() 和标签显示多个标记?



我正在使用谷歌地图api v3,和InfoBubbles插件。我正在尝试用多个标记填充地图。每个标记都有一个InfoBubble,点击后会打开。这些InfoBubbless有标签(最多3个标签),每个标签都有自己的内容和html。

我怎样才能让标记显示在地图上与他们的标签和信息气泡。

我目前正在将信息气泡和标记设置为数组,并使用公共函数来处理单击,同时传递索引。

        infoBubbles[i] = new InfoBubble({ 
            map: map, 
            minHeight: point[i].min_height,
            maxHeight: point[i].max_height,
            minWidth: point[i].min_width,
            maxWidth: point[i].max_width,
            disableAutoPan: false, 
            hideCloseButton: false, 
            arrowPosition: 30, 
            padding:12
        }); 
        google.maps.event.addListener(marker, 'click', handleMarkerClick(marker, i)); 

和标记点击功能:

function handleMarkerClick(marker,index) { 
    return function() { 
        if (!infoBubbles[index].isOpen()) { 
            infoBubbles[index].open(map, marker); 
        }else{
            infoBubbles[index].close(map, marker); 
        }
    } 
}

我用同样的方法回答了我自己的问题。我从其他几个人那里得到反馈,这是正确的方法。

我使用下面的代码来定义一个单独的infoBubble,我只是删除所有的选项卡,内容和重新定位/回流的内容为该气泡。

/**
 * add a listener for the click of a marker
 * when the marker is clicked, get the current amount
 * of tabs, and remove each tab. Then reset the width/heights
 * and readd the new tabs with their content.
 * @return {[type]}
 */
google.maps.event.addListener(marker, 'click', function(){
    /** remove all of the tabs from the infobubble, early prototype */
    if (tabCount > 0){
        for (var i = 0; i < tabCount; i++){
            infoBubble.removeTab(0);
        }   
        tabCount = 0;   
    }
    /** setup the min/max width and heights for the bubble */
    infoBubble.setMinWidth(this.infoBubble_minWidth);
    infoBubble.setMaxWidth(this.infoBubble_maxWidth);
    infoBubble.setMinHeight(this.infoBubble_minHeight);
    infoBubble.setMaxHeight(this.infoBubble_maxHeight);
    var tabs = this.infoBubble_tabs;
    /** @type {Number} set the counter to 1, since tab index starts at 1 */
    for (var ii = 0; ii < tabs.length; ii++) {
        infoBubble.addTab(tabs[ii].tabTitle, tabs[ii].tabContent);
        /** count the amount of tabs there are */
        tabCount++;
    }
    /** open the infoBubble */
    infoBubble.open(map, this);
});  

最新更新