1

我在弹出窗口上加载谷歌静态地图并动态设置图像的图像 URL。源代码显示正确的地址,但在页面加载时未显示在页面上。如果我将鼠标悬停在 Image 的源代码中,那么它将被加载到源代码中(Firefox 中的 ei Firebug),如果我重新打开弹出窗口,则 Image 加载成功。请提出为什么它没有第一次加载。

步骤 1 打开我的页面

步骤 2 点击地图。它是空白的

第 3 步如果我们在 Firebug 中查看此静态地图图像的 HTMl 代码,那么

鼠标移到图像源代码上的第 4 步,图像加载但静态图像弹出窗口上仍然没有任何内容 点击查看图像

步骤 5 关闭弹出窗口

第 6 步如果我们再次打开地图弹出窗口,图像加载成功。
点击查看图片

图像不会加载,直到我们没有将鼠标悬停在 Firebug 中图像的 HTML 源代码上。请在这个案例中提出建议。

代码源代码:

                       <tr> 
                        <td width=""114"" height=""22""> 
                            <asp:Localize runat=""server"" ID=""locPickUpLocation"" Text=""Pick-up Location:"" meta:resourcekey=""locPickUpLocationResource1""></asp:Localize>  
                        </td> 
                        <td width=""182""> 
                            <b> 
                                <asp:Literal ID=""ltPick"" runat=""server"" meta:resourcekey=""ltPickResource1""></asp:Literal> <span id=""divPickMapLink"" runat=""server"" class=""CarMapBut apf""><span><asp:Localize runat=""server"" ID=""picklocMap"" Text=""Map"" meta:resourcekey=""picklocMapResource1""></asp:Localize></span></span> 
                            </b> 
                        </td> 
                        <td width=""116"" class=""padlt5""> 
                           <asp:Localize runat=""server"" ID=""locDropOffLocation"" Text=""Drop-off Location:"" meta:resourcekey=""locDropOffLocationResource1""></asp:Localize>   
                        </td> 
                        <td width=""183""> 
                            <b> 
                                <asp:Literal ID=""ltDrop"" runat=""server"" meta:resourcekey=""ltDropResource1""></asp:Literal>  <span id=""divDropMapLink"" runat=""server"" class=""CarMapBut apf""><span><asp:Localize runat=""server"" ID=""droplocMap"" Text=""Map"" meta:resourcekey=""droplocMapResource1""></asp:Localize></span></span> 
                            </b> 
                        </td> 
                    </tr> 

后面的代码:

            string pickAdd = ltPick.Text.Replace(""<br />"", """");         
            divPickMapLink.Attributes.Add(""onclick"", ""javascript:DisplayMapByAddress('"" + pickAdd + ""');"");         
            ltDrop.Text = carBooking_.GetDropoffLocationDescription("", "");         
            string dropAdd = ltDrop.Text.Replace(""<br />"", """");         
            divDropMapLink.Attributes.Add(""onclick"", ""javascript:DisplayMapByAddress('"" + dropAdd + ""');""); 

HTML 页面
GoogleMapStatic.htm

<div id=""popup_box"">
<a id=""popupBoxClose"">Close</a>
<div id=""ViewMap"" class=""CarMap"">
<img id=""GoogleStaticImage"" src=""http://maps.googleapis.com/maps/api/staticmap?sensor=false&key=<%= DTIsland.DTCarIslandSettings.CarGoogleMapKey %>&zoom=13&size=600x420&center=New York&markers=color:green%7Clabel:A%7CNew York"" />
</div>
</div>
<div id=""greyBgBkgrnd""></div>

   <script type=""text/javascript"" charset=""utf-8"">   
        $(document).ready(function () {

    $(document).keypress(function (e) {
        if (e.keyCode == 27) { unloadPopupBox(); }
    });

    $('#popupBoxClose').click(function () {
        unloadPopupBox();
    });
});

function unloadPopupBox() { // TO Unload the Popupbox
    $('#popup_box').fadeOut(""slow"");
    $(""#greyBgBkgrnd"").css({ // this is just for style  
        ""opacity"": ""1""
    });
    $('#popup_box').hide();
    CloseGreyBg();
}

function loadPopupBox() {

    // To Load the Popupbox
    $('#popup_box').fadeIn(""slow"");
    $('#popup_box').css({
        ""left"": ""300px"",
        ""top"": ""150px"",
        'zIndex': 400
    });
    $(""#greyBgBkgrnd"").css({ // this is just for style
        ""opacity"": ""0.3""
    });
    DisplayGreyBg();
}

function DisplayGreyBg() {
    var bWidth = ($('body').width()) + 25;
    if ($.browser.msie && $.browser.version == 7) {
        var bWidth = $('body').width();
        $('.filterreg:first').css('z-index', '300');
    }
    var bHeight = $('body').height();
    $('#greyBgBkgrnd').css({ 'width': bWidth + 'px', 'height': bHeight + 'px', 'zIndex': 399, 'background': '#666666', 'opacity': '0.5', 'filter': 'alpha(opacity = 50)', 'position': 'absolute', 'top': '0', 'left': '0' });
    $('#greyBgBkgrnd').fadeIn(""slow"");
    $('body').css('overflow', 'hidden');
    //IE6 Bug with SELECT element always showing up on top
    if ($.browser.msie && $.browser.version < 7) {
        $('select').each(function () {
            $(this).hide();
        });
    }
}

function CloseGreyBg() {
    $('#greyBgBkgrnd').css({ 'width': '0px', 'height': '0px', 'zIndex': -1 });
    $('#greyBgBkgrnd').fadeOut(""slow"");

    if ($.browser.msie && $.browser.version == 7) {
        $('body').css('overflow-y', 'auto');
        $('.filterreg:first').css('z-index', '99998');
    } else {
        $('body').css('overflow', 'auto');
    }
    //IE6 Bug with SELECT element always showing up on top
    if ($.browser.msie && $.browser.version < 7) {
        $('select').each(function () {
            $(this).show();
        });
    }
}

///// Display map on Popup with long, lat
function DisplayMapByLatLong(lat_, long_) {
    loadPopupBox();
    // When map object is created it tries to figure out how big the canvas is and if popup is not fully loaded yet it may get wrong values.
    // So 'loadPopupBox()' function is called before showMap and setTimeout is called to wait till popup is proper loaded
    $('#popupBoxClose').show();
    setTimeout("""", 100);
    var imgsrc = ""http://maps.googleapis.com/maps/api/staticmap?sensor=false&key=<%= DTIsland.DTCarIslandSettings.CarGoogleMapKey %>&zoom=13&size=600x420&center="" + lat_ + "","" + long_ + ""&markers=color:green%7Clabel:A%7C"" + lat_ + "","" + long_;
    $(""#GoogleStaticImage"").attr(""src"", imgsrc);
}

///// Display map on Popup with address
function DisplayMapByAddress(address) {   
    loadPopupBox();
    // When map object is created it tries to figure out how big the canvas is and if popup is not fully loaded yet it may get wrong values.
    // So 'loadPopupBox()' function is called before showMap and setTimeout is called to wait till popup is proper loaded
    $('#popupBoxClose').show();
    setTimeout("""", 100);
    var imgsrc = ""http://maps.googleapis.com/maps/api/staticmap?sensor=false&key=<%= DTIsland.DTCarIslandSettings.CarGoogleMapKey %>&zoom=13&size=600x420&center="" + address + ""&markers=color:green%7Clabel:A%7C"" + address;
    $(""#GoogleStaticImage"").attr(""src"", imgsrc);

  }

</script>                                                                                           





 Problem is with API key for static map. I am using invalid API key.
4

0 回答 0