Google地图街景视图仅在第一次显示

时间:2015-02-15 21:24:45

标签: javascript jquery-ui google-maps-api-3

我有一个谷歌地图页面填充了数据库中的标记。在标记InfoWindow中是一个可单击的链接,用于打开带有该位置的StreetView的jquery对话框。 问题是,StreetView只在我第一次点击InfoWindow链接时显示。如果我关闭对话框并尝试再次打开它(点击其他信息窗口或者再次点击同一个信息),我会看到带有StreetView控件的对话框,也会显示新地址(“地址是近似值”),但其余的对话框是一种均匀的浅灰色。

我已尝试在stackoverflow上发布了一些warkarounds(如this one)但灰色对话框仍然存在于我的情况中。

修改:JSFiddle Example

使用onclick监听器创建标记:

function addMarker(feature) {
    var marker = new google.maps.Marker({
        position: feature.position,
        icon: icons[feature.type].icon,
        map: map
    });
    //Create Infowindow
    var infowindow = new google.maps.InfoWindow();
    var content = '<h1 id="Heading" class="Heading">' + feature.shopName + '</h1>' +
                  '<div id="iwcontent" class="iwcontent">'+
                  '<p><b>Naslov : </b>' + feature.shopAddress + '</br>' +
                  '<p><b>Telefon : </b>' + feature.shopTel + '</br>' +
                  '</div>'+
                  '<div id="iwsw" class="iwsw">StreetView</div>'
                  ;
    //Call StreetView
    google.maps.event.addDomListener(infowindow, 'domready', function () {
        $('.iwsw').click(function () {
            showStreetView(feature.position);
        });
    });
    .
    .
    .

showStreetView功能:

//Display dialog with streetview
function showStreetView(position){
    var panoramaOptions = {position: position, pov: {heading: 34,pitch: 10}};
    var panorama = new  google.maps.StreetViewPanorama(document.getElementById("dialog-sw-canvas"), panoramaOptions);
    map.setStreetView(panorama);
    $( "#dialog-sw-canvas" ).dialog("open");
}

对话框定义:

$(function(){
    $('#dialog-sw-canvas').dialog({
        title: 'Street View',
        width: 1024,
        height: 768,
        closed: true,
        cache: false,
        modal: true,
        onClose: function(){
            $('#dialog-sw-canvas').empty();
        }
    });
});

一切都像魅力一样,但只有一次。

1 个答案:

答案 0 :(得分:5)

打开对话框后触发全景图的调整大小事件,然后API将能够重新计算全景图的大小:

//Display dialog with streetview
function showStreetView(position){
    var panoramaOptions = {position: position, pov: {heading: 34,pitch: 10}};
    var panorama = new  google.maps
        .StreetViewPanorama(document.getElementById("dialog-sw-canvas"), panoramaOptions);
    map.setStreetView(panorama);
    $( "#dialog-sw-canvas" ).dialog("open");
    google.maps.event.trigger(panorama,'resize');
}