English 中文(简体)
谷歌地图,InfoBubbles
原标题:Google Map with InfoBubbles

On this page, I show a Google map with InfoBubbles that appear over the map markers. The InfoBubbles are open initially. If you close them, you can re-open them by clicking on the marker. I would like the InfoBubbles to be closed initially. The relevant function (simplified to remove irrelevant stuff) is:

addMarker = function(festivalData, hasPopup) {

    var map = this._map;

    this.marker = new google.maps.Marker({
        position: new google.maps.LatLng(festivalData.latitude, festivalData.longitude),
        map: map
    });

    if (hasPopup) {
        var infoBubble = new InfoBubble({
            map: map,
            content: "<a href= " + festivalData.url + " >" + festivalData.name + "</a>",
            hideCloseButton: false,
        });

        infoBubble.open(map, this.marker);

        var infoBubbleHandler = function(bubble) {
            return function() {
                if (!bubble.isOpen()) {
                    bubble.open(map, this.marker);
                }
            }
        }(infoBubble);

        google.maps.event.addListener(this.marker,  click , infoBubbleHandler);
    }
}

我期望通过删除这一行文。

infoBubble.open(map, this.marker);

这将实现我的目标,但这只是彻底清除了InfoBubbles,以便他们甚至在你点击标识时不露面。 如何使InfoBubbles在一开始就关闭了,但在你点上标点时却开放了吗?

最佳回答

修改了所有提及这一点的内容。 标记为地方变量,并改变这种手递功能的创造,我认为这是想你想这样做的方法。

addMarker = function(festivalData, hasPopup) {

    var map = this._map;

    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(festivalData.latitude, festivalData.longitude),
        map: map
    });

    if (hasPopup) {
        var infoBubble = new InfoBubble({
            map: map,
            content: "<a href= " + festivalData.url + " >" + festivalData.name + "</a>",
            hideCloseButton: false,
        });

        //infoBubble.open(map, this.marker);

        var infoBubbleHandler = function() {
            if (!infoBubble.isOpen()) {
                infoBubble.open(map, marker);
            }
        };

        google.maps.event.addListener(marker,  click , infoBubbleHandler);
    }
}
问题回答

这是在一开始便使标识看不见,在点击时打开标识的容易办法。

var myLatLng = new google.maps.LatLng(some_lat, some_lng);
var marker = new google.maps.Marker({
        position: myLatLng,
        map: your_map,
        title: some_title,
        zIndex: some_z_index_int,
        clickable: true
    });

infoBubble = new InfoBubble({
      content:  <div>Some label</div> ,
      shadowStyle: 1,
      padding: 0,
      backgroundColor:  rgb(57,57,57) ,
      borderRadius: 4,
      arrowSize: 10,
      borderWidth: 1,
      borderColor:  #2c2c2c ,
      disableAutoPan: true,
      hideCloseButton: true,
      arrowPosition: 10,
      arrowStyle: 2
    });

google.maps.event.addListener(marker,  click , (function(marker, i) {
        return function() {

            infoBubble.open(map, marker);
        }
})(marker, i));

这是一种奇怪的行为,我也期望在取消<>开放<>><>>电话后再工作。

从我头上看,在布局开张后,试图立即关闭布局:

infoBubble.open(map, this.marker);
infoBubble.close();




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签