简体   繁体   English

收听google.maps.InfoWindow类的domready事件

[英]Listening for the domready event for google.maps.InfoWindow class

So, I am trying to make add a google map to my webpage. 所以,我想在我的网页上添加一个谷歌地图。 I want to add a form into the pop-up bubble when you click on a marker on the map. 当您单击地图上的标记时,我想在弹出的气泡中添加一个表单。

The API documentation says that the domready API文档说明了domready

"event is fired when the containing the InfoWindow's content is attached to the DOM. You may wish to monitor this event if you are building out your info window content dynamically." “当包含InfoWindow的内容附加到DOM时会触发事件。如果要动态构建信息窗口内容,可能希望监视此事件。”

How do I listen to this event? 我该如何听这个活动?

This is the documentation . 这是文档

I just solved a similar problem myself. 我自己刚刚解决了类似的问题。 To listen for the domready event, use the following syntax: 要侦听domready事件,请使用以下语法:

infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(infoWindow, 'domready', function() {
      // whatever you want to do once the DOM is ready
});

The google.maps.event.addListener() event waits for the creation of the infowindow HTML structure 'domready' and before the opening of the infowindow defined styles are applied. google.maps.event.addListener()事件等待创建infowindow HTML结构'domready'并在应用infowindow定义的样式打开之前。

I have worked with this example : 我使用过这个例子:

google.maps.event.addListener(infowindow, 'domready', function() {

   // Reference to the DIV which receives the contents of the infowindow using jQuery
   var iwOuter = $('.gm-style-iw');
   var iwBackground = iwOuter.prev();

   // Remove the background shadow DIV
   iwBackground.children(':nth-child(2)').css({'display' : 'none'});

   // Remove the white background DIV
   iwBackground.children(':nth-child(4)').css({'display' : 'none'});

});

Then 然后

.gm-style-iw {
   width: 350px !important;
   top: 0 !important;
   left: 0 !important;
   background-color: #fff;
   box-shadow: 0 1px 6px rgba(178, 178, 178, 0.6);
   border: 1px solid rgba(72, 181, 233, 0.6);
   border-radius: 2px 2px 0 0;
}

Result : 结果: 在此输入图像描述

Reference : http://en.marnoto.com/2014/09/5-formas-de-personalizar-infowindow.html 参考: http//en.marnoto.com/2014/09/5-formas-de-personalizar-infowindow.html

Thanks 谢谢

var contentString = 'your form here';

var infowindow = new google.maps.InfoWindow({
    content: contentString
});

var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title:"My Form"
});

google.maps.event.addListener(marker, 'click', function() {
  infowindow.open(map,marker);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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