javascript 谷歌地图信息窗口事件打开

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11350234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 12:52:57  来源:igfitidea点击:

Google maps infowindow events on open

javascriptjquerygoogle-mapsgoogle-fusion-tables

提问by Juan Diego

Hi I am using google fusion tables and google maps, the thing is that my markers show up correctly, but I want to insert some images into the inforwindow. So the thing is that I do queries to find the location of those markers, and those markers can have many categories (that is why i couldnt use a merged table). And when the user clicks on the marker, the infowindow displays and shows the info on the marker. It used to include just a text of the categories, but I want to retrieve the icon from each category to display that on the infowindow. The thing is that the second query takes longer than the time it takes to display the info window. So i did a lame fix, I added

嗨,我正在使用谷歌融合表和谷歌地图,问题是我的标记显示正确,但我想在信息窗口中插入一些图像。所以事情是我做查询来找到这些标记的位置,这些标记可以有很多类别(这就是我不能使用合并表的原因)。当用户点击标记时,信息窗口会显示并显示标记上的信息。它过去只包含类别的文本,但我想从每个类别中检索图标以在信息窗口上显示该图标。问题是第二个查询花费的时间比显示信息窗口所花费的时间更长。所以我做了一个蹩脚的修复,我补充说

$('#infoWindowsCatDer').append(info);

at the end of the second query, so I guess you can see the problem, what happens if the windows takes a little bit longer to display than the query. This is something that should be handled by events right?

在第二个查询结束时,我想您可以看到问题,如果窗口显示时间比查询时间长一点会发生什么。这是应该由事件处理的事情吗?

Is there an event for

有没有活动

lastWindow.open(map);

So when the infowindow is completly open it can append the images?

那么当信息窗口完全打开时,它可以附加图像吗?

回答by Jonathan Wilson

The InfoWindow object fires the event domreadyevent when it is attached (fully loaded) to the DOM. You can see this in the API docs: https://developers.google.com/maps/documentation/javascript/reference#InfoWindow

InfoWindow 对象在domready附加(完全加载)到 DOM 时触发事件事件。您可以在 API 文档中看到这一点:https: //developers.google.com/maps/documentation/javascript/reference#InfoWindow

You could then have a listener like the one below to load content into the infoWindow after it has loaded itself:

然后,您可以使用如下所示的侦听器在加载自身后将内容加载到 infoWindow 中:

var referenceToInfoWindow = new google.maps.InfoWindow({content: 'My info' });

google.maps.event.addListener(referenceToInfoWindow, 'domready', function(){
    //code to dynamically load new content to infowindow
    //for example:
    //    var existing_content = referenceToInfoWindow.getContent();
    //    var new_content = "...";
    //    referenceToInfoWindow.setContent(existing_content + new_content);
});