简体   繁体   中英

how can i show multiple markers with infobubbles() & tabs in google maps api v3?

i am using google maps api v3, and the InfoBubbles plugin. I am trying to populate the map with multiple markers. Each marker has a InfoBubble that opens when clicked. These InfoBubbless have tabs (up to 3 tabs) each with their own content and html.

How can i get the markers to show on the maps with their tabs and infobubbles.

I am currently setting the infobubbles and markers to arrays and using a public function to handle the click, while passing the index.

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

and the marker click function:

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

i answered my own question by using the same method above. I received word back from several others that this is the correct way.

i use the following code to define a single infoBubble and i just remove all the tabs, content and reposition/reflow the content for that bubble.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM