How to change the InfoWindow Background color

半腔热情 提交于 2019-12-20 12:46:09

问题


I'm facing the problem,My google Map API showing default InfoWindow with background color white.I want change the White color to Black color. REF CODE:

google.maps.event.addListener(marker, 'mouseover', function() {


    infoWindow.setContent(html);
        infoWindow.open(map, marker);
               //infoWindow.setStyle("background-color: red");


      });

回答1:


I came up with a simple solution. This might not be a very elegant solution but it works fine if you don't have huge styling needs.

Since we can add our own html and style it. The marker background element is mainly the one which causes problem. For simple styling, instead of learning a whole new library, we can just remove that element using jQuery.

Insert this code in your init function and it will remove the background element.

google.maps.event.addListenerOnce(map, 'idle', function(){
    jQuery('.gm-style-iw').prev('div').remove();
}); 

Now, you are free to style your own divs. I styled the infoWindow in my project using this approach.

Hope it will help.




回答2:


You can use the InfoBox here in Google Maps Utility.

This class behaves like google.maps.InfoWindow, but it supports several additional properties for advanced styling. An InfoBox can also be used as a map label.

You can also use CSS to style it. By checking this tutorial and this, it will give you a sample code on how to do it.



来源:https://stackoverflow.com/questions/37456627/how-to-change-the-infowindow-background-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!