【问题标题】:how can i show multiple markers with infobubbles() & tabs in google maps api v3?如何在谷歌地图 api v3 中使用 infobubbles() 和标签显示多个标记?
【发布时间】:2011-12-27 17:01:25
【问题描述】:

我正在使用 google maps 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); 
        }
    } 
}

【问题讨论】:

    标签: javascript google-maps-api-3 infobubble


    【解决方案1】:

    我使用上述相同的方法回答了我自己的问题。我从其他几个人那里收到消息说这是正确的方法。

    我使用以下代码来定义单个 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);
    });  
    

    【讨论】:

    • 只是对我自己的问题的更新,我向开发人员提交了一个错误,他们修复了它。我已经编辑了我的答案以反映我的最终代码。
    猜你喜欢
    • 2014-03-05
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2012-04-02
    • 1970-01-01
    • 2013-01-30
    • 1970-01-01
    相关资源
    最近更新 更多