简体   繁体   English

Google Maps StreetView仅首次显示

[英]Google Maps StreetView displays only the first time

I have a google map page populated with markers from database. 我有一个Google地图页面,其中填充了数据库中的标记。 In the marker InfoWindow is a clickable link that opens a jquery dialog with StreetView of the location. 在标记InfoWindow中,是一个可单击的链接,该链接打开一个带有该位置的StreetView的jquery对话框。 The problem is, that StreetView shows only the first time I click on the InfoWindow link. 问题是,街景视图仅在我第一次单击InfoWindow链接时显示。 If I close the dialog and try to open it again (clicking on other infowindows or even the same one again) , I get my dialog with StreetView controls , the new address is shown too (with "Address is approximate") , but the rest of dialog is an uniform light grey color. 如果我关闭对话框并尝试再次打开它(单击其他信息窗口,甚至再次单击相同的窗口),则会得到带有StreetView控件的对话框,新的地址也会显示(带有“地址是近似值”),但是其余的对话框的颜色是均匀的浅灰色。

I've tried some warkarounds posted on stackoverflow (like this one ) but the grey dialog persists in my case. 我试过计算器上发布(如一些warkarounds 这一个 ),但灰色的对话框在我的情况依然存在。

Edit : JSFiddle Example 编辑: JSFiddle示例

Marker creation with onclick listener: 使用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 function: 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");
}

Dialog definition: 对话框定义:

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

Everything works like a charm, but only once. 一切都像魅力一样,但只有一次。

Trigger the resize-event of the panorama after opening the dialog, then the API will be able to recalculate the size of the panorama: 打开对话框后触发全景图的调整大小事件,然后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');
}

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

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