我有一个API V3地图,每个标记都有一个内容窗口。每个标记都有一个包含.SVG文件的信息窗口。 infowindow的内容跨越多行,但infowindow不会调整大小以适应所有内容,导致出现类似iframe的滚动。此外,我甚至无法关闭信息窗口。 有没有人帮我解决我的问题。 这是我的代码
function initialize(){
var myCenter = new google.maps.LatLng(36.4333, -117.9509);
var sfv = new google.maps.LatLng(34.18258, -118.43968);
var sgv = new google.maps.LatLng(34.07959, -118.03335);
var pasadena = new google.maps.LatLng(34.14778, -118.14452);
var la = new google.maps.LatLng(34.05223, -118.24368);
var oc = new google.maps.LatLng(33.71747, -117.83114);
var imageBounds=new google.maps.LatLngBounds(
new google.maps.LatLng(36.3943, -118.1050),
new google.maps.LatLng(36.4735, -117.8529));
var marker, marker1;
var mapProp = {
zoom:9,
center:la,
mapTypeId: google.maps.MapTypeId.ROADMAP}
var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
var marker=new google.maps.Marker({
position:myCenter,
animation:google.maps.Animation.BOUNCE
});
var marker1=new google.maps.Marker({
position:sfv,
animation:google.maps.Animation.BOUNCE
});
var marker2=new google.maps.Marker({
position:sgv,
animation:google.maps.Animation.BOUNCE
});
var marker3=new google.maps.Marker({
position:pasadena,
animation:google.maps.Animation.BOUNCE
});
var marker4=new google.maps.Marker({
position:la,
animation:google.maps.Animation.BOUNCE
});
var marker5=new google.maps.Marker({
position:oc,
animation:google.maps.Animation.BOUNCE
});
marker.setMap(map);
marker1.setMap(map);
marker2.setMap(map);
marker3.setMap(map);
marker4.setMap(map);
marker5.setMap(map);
var infowindow = new google.maps.InfoWindow({
content: '<IMG BORDER="0" ALIGN="Left" SRC="test.svg">'
});
var infowindow1 = new google.maps.InfoWindow({
content: '<IMG BORDER="0" ALIGN="Left" SRC="test.svg">'
});
var infowindow2 = new google.maps.InfoWindow({
content: '<IMG BORDER="0" ALIGN="Left" SRC="test.svg">'
});
var infowindow3 = new google.maps.InfoWindow({
content: '<IMG BORDER="0" ALIGN="Left" SRC="test.svg">'
});
var infowindow4 = new google.maps.InfoWindow({
content: '<IMG BORDER="0" ALIGN="Left" SRC="test.svg">'
});
var infowindow5 = new google.maps.InfoWindow({
content: '<IMG BORDER="0" ALIGN="Left" SRC="test.svg">'
});
// event handlers for clicking
google.maps.event.addListener(marker, 'click', function(){
infowindow.open(googleMap,marker);
});
google.maps.event.addListener(marker1, 'click', function(){
infowindow1.open(googleMap,marker1);
});
google.maps.event.addListener(marker2, 'click', function(){
infowindow2.open(googleMap,marker3);
});
google.maps.event.addListener(marker3, 'click', function(){
infowindow3.open(googleMap,marker3);
});
google.maps.event.addListener(marker4, 'click', function(){
infowindow4.open(googleMap,marker4);
});
google.maps.event.addListener(marker5, 'click', function(){
infowindow5.open(googleMap,marker5);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body onload = "initialize()">
<div id="googleMap" style="width:1080px;height:650px;"></div>
</body>
答案 0 :(得分:2)
您可以通过传递相关参数来设置最大宽度,如the docs:
中所述var infowindow = new google.maps.InfoWindow({
content: ...,
maxWidth: 300
})
相关文档。
请注意,宽度不能低于247.至于设置高度,没有特定的参数。但是,您可以使用CSS来控制它。只需为img
元素添加max-height
样式。