显示隐藏div后,Google Maps v3 infoWindow会自动调整大小

时间:2013-08-10 01:51:09

标签: google-maps-api-3 infowindow

我正在撰写一个包含谷歌地图的网页。我遇到了麻烦;

我有一个包含隐藏div的InfoWindow,当我点击infoWindow中的按钮时,我想显示它。但问题是,当我显示隐藏的div时,infoWindow的大小将无法自动适应新内容。

请您提出一些解决此问题的建议吗?非常感谢: - )

这是我的js:

function redraw() {
    var cmt = $("#bodyContent");
    cmt.show();
}

var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}

var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

var contentString = '<div id="content">'+
                    '<h2 id="firstHeading" class="firstHeading">Uluru</h2>'+
                    '<input type="button" value="Test" onclick="redraw()" />' +
                    '<div id="bodyContent" class="test">'+
                    '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
                    'sandstone rock formation in the southern part of the '+
                    'Northern Territory, central Australia. It lies 335 km (208 mi) '+
                    'south west of the nearest large town, Alice Springs; 450 km '+
                    '(280 mi) by road. Kata Tjuta and Uluru are the two major '+
                    'features of the Uluru - Kata Tjuta National Park. Uluru is '+
                    'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
                    'Aboriginal people of the area. It has many springs, waterholes, '+
                    'rock caves and ancient paintings. Uluru is listed as a World '+
                    'Heritage Site.</p>'+
                    '</div>'+
                    '</div>';

infowindow = new google.maps.InfoWindow({
                    maxWidth: 300,
                    content: contentString
                 });

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

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

0 个答案:

没有答案