简体   繁体   English

如果尝试第二次请求,则Google Map无法为同一div正确呈现

[英]Google Map is not rendering properly for same div if tried for second request

I have Master/Child type page. 我有主/子类型页面。 In master page there a link which open detail page. 在母版页中,有一个打开详细信息页面的链接。 On detail page I am displaying Map. 在详细信息页面上,我正在显示地图。 Detail page is opened in fancy box with Ajax call. 在带有Ajax调用的精美框中打开“详细信息”页面。 On first iteration of detail page click, I am appending google script to page. 在第一次点击详细页面时,我将google脚本附加到页面上。 I am not appending google script from next detail click as Script already added to DOM. 由于脚本已添加到DOM,因此我不会从下一个详细信息单击中添加Google脚本。 On first iteration of detail page click, Map is loading properly but after that Map is not rendering properly. 单击详细信息页面的第一次迭代时,Map会正确加载,但是此后Map无法正确呈现。 Map rendered in only half part of div. 地图仅在div的一半中呈现。

Code snippet as below for 如下代码片段

var instanceTime = 0
function loadgoogleapiInfoPopup() {

    mapCanvasId = "map_canvas_gdi";
    if (instanceTime == 0)
    {
        instanceTime = 1;
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.id = 'GoogleAPIMapInfoPop';
            script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&' + 'callback=infopopup.Init';
            document.body.appendChild(script);
        }
    else {

        $("#map_canvas_gdi").html('');        
        infopopup.Init();
        google.maps.event.trigger(infopopup.Map, 'resize');

    }
}

infopopup.Init = function () {    
    function initialize() {
        var center = new google.maps.LatLng(53.961687, -1.746825);

        var options =
        {
            zoom: 6,
            center: center,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        infopopup.Map = null;
        infopopup.Map = new google.maps.Map(document.getElementById(mapCanvasId), options);


    }

    initialize();
    infopopup.ClearMarkers();
    infopopup.FillMarkers();
}

Thanks ..Problem is solved , I have applied google.maps.event.trigger(garagemapinfopopup.Map, 'resize'); 谢谢..问题解决了,我已应用google.maps.event.trigger(garagemapinfopopup.Map,'resize'); in parent page, after child loaded in div. 在父页面中,在子项加载到div后。

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

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