0

Google マップ API v3 と InfoBubbles プラグインを使用しています。マップに複数のマーカーを設定しようとしています。各マーカーには、クリックすると開く InfoBubble があります。これらの InfoBubbless には、それぞれ独自のコンテンツと html を持つタブ (最大 3 つのタブ) があります。

タブとインフォバブルを使用してマップにマーカーを表示するにはどうすればよいですか。

現在、インデックスを渡しながら、infobubbles とマーカーを配列に設定し、パブリック関数を使用してクリックを処理しています。

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

1 に答える 1

0

上記と同じ方法を使用して、自分の質問に答えました。他の何人かから、これが正しい方法だという言葉を受け取りました。

次のコードを使用して単一の 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);
});  
于 2011-12-29T14:27:13.483 に答える