Page view counter

ModalPopupExtender + iFrame + Google Maps = Off Center Map

Last post 03-13-2008 8:36 AM by melmendo. 9 replies.

Sort Posts:

  • ModalPopupExtender + iFrame + Google Maps = Off Center Map

    01-17-2008, 1:56 PM
    • Loading...
    • blkbam
    • Joined on 01-17-2008, 4:41 PM
    • Posts 5
    • Points 0

    I'm embedding an iFrame in the ModalPopupExtender which loads a page that has a Google Map on it.  When I load the page that has the map either directly or through an iFrame on the page the map centers properly but if I load it in the ModalPopupExtender, my map is off center.  Anyone have any ideas on why this happens or if there is a work around?  There are parameters for the minimap2.apsx page but they just populate the hidden fields which I've given defaults.  This happens in ie and ff.

     Parent Page:

    <form runat="server" action="">
    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />

    <a id="showModalPopupClientButton" href="#" runat="server">Click Me</a><br /><br /><br />
    <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>

    <asp:Panel runat="server" ID="Panel1" Style="display:none;width:600px;height:475px;" CssClass="modalPopup">
    <iframe width="600" height="450" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="minimap2.aspx?lat=39.86887222271858&long=-75.35767078399658&desc=just%26a%26sample"></iframe><br />
    <asp:Button runat="server" ID="cmdClose" Text="Close" />
    </asp:Panel>

    <iframe width="600" height="450" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="minimap2.aspx?lat=39.86887222271858&long=-75.35767078399658&desc=just%26a%26sample"></iframe><br />

    <ajaxToolkit:ModalPopupExtender ID="mpeMap" runat="server"
    TargetControlID="LinkButton1"
    PopupControlID="Panel1"
    BackgroundCssClass="modalBackground"
    DropShadow="true"
    CancelControlID="cmdClose"
    OkControlID="cmdClose"
    />
    </form>

      

     minimap2.aspx:

     

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="minimap2.aspx.cs" Inherits="minimap2" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>Untitled Document</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA_XiVe3s1cch6aJ-k4pFNjRQAlgRJcslAtUBAvx2XFbBowwn5jxTJXB-9lVOvGtDSThRTDM1pmzlXug" type="text/javascript"></script>
    <script type="text/javascript">
    var map;
    var icon0;
    var newpoints = new Array();

    function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
    window.onload = func
    } else {
    window.onload = function() {
    oldonload();
    func();
    }
    }
    }

    addLoadEvent(loadMap);
    addLoadEvent(addPoints);

    function loadMap()
    {
    var dLat = Number(document.getElementById('<%= hdLat.ClientID %>').value);
    var dLong = Number(document.getElementById('<%= hdLong.ClientID %>').value);
    var sCaption = document.getElementById('<%= hdCaption.ClientID %>').value;

    map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng( dLat, dLong), 13);
    map.setMapType(G_MAP_TYPE);
    //G_MAP_TYPE, G_SATELLITE_TYPE, or G_HYBRID_TYPE
    icon0 = new GIcon();
    icon0.image = "http://www.google.com/mapfiles/marker.png";
    icon0.shadow = "http://www.google.com/mapfiles/shadow50.png";
    icon0.iconSize = new GSize(20, 34);
    icon0.shadowSize = new GSize(37, 34);
    icon0.iconAnchor = new GPoint(9, 34);
    icon0.infoWindowAnchor = new GPoint(9, 2);
    icon0.infoShadowAnchor = new GPoint(18, 25);
    }

    function addPoints()
    {

    var dLat = Number(document.getElementById('<%= hdLat.ClientID %>').value);
    var dLong = Number(document.getElementById('<%= hdLong.ClientID %>').value);
    var sCaption = document.getElementById('<%= hdCaption.ClientID %>').value;

    newpoints[0] = new Array(dLat, dLong, icon0, 'Picture', sCaption);

    for(var i = 0; i < newpoints.length; i++) {
    var point = new GPoint(newpoints[i][1],newpoints[i][0]);
    var popuphtml = newpoints[i][4] ;
    var marker = createMarker(point,newpoints[i][2],popuphtml);
    map.addOverlay(marker);
    }
    }

    function createMarker(point, icon, popuphtml)
    {
    var popuphtml = "<div id=\"popup\">" + popuphtml + "<\/div>";
    var marker = new GMarker(point, icon);
    GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(popuphtml);
    });
    return marker;
    }
    </script>

    <style type="text/css">
    div#popup
    {
    background:#EFEFEF;
    border:1px solid #999999;
    margin:0px;
    padding:7px;
    width:270px;
    }
    </style>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:HiddenField runat="server" Value="39.869053382069" ID="hdLat" />
    <asp:HiddenField runat="server" Value="-75.35773515701294" ID="hdLong" />
    <asp:HiddenField runat="server" Value="Test" ID="hdCaption" />
    <div id="map" style="width: 600px; height: 450px">
    </div>
    </form>
    </body>
    </html>

      

     

  • Re: ModalPopupExtender + iFrame + Google Maps = Off Center Map

    01-21-2008, 1:41 PM
    Answer
    • Loading...
    • blkbam
    • Joined on 01-17-2008, 4:41 PM
    • Posts 5
    • Points 0

    I found the reason for the problem and a workaround.  I don't totally understand the cause but it has to do with the iFrame being loaded while invisible.  If you load the page bring up the ModalPopUp Extender before iFrame loads, it is centered correctly.  If you wait and let it load while invisible, it will render off center.  Now, it just dynamically create the iFrame instead of having it load when the page loads

     Workaround:

    <script type="text/javascript">
    function showDialog()
    {
    var modalPopupBehaviorCtrl = $find('<%= mpeMap.ClientID %>');
    modalPopupBehaviorCtrl.show();
    document.getElementById('divMap').innerHTML = '<iframe runat="server" id="mm" width="600" height="450" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="minimap2.aspx?lat=39.86887222271858&long=-75.35767078399658&desc=just%26a%26sample"></iframe><br />';
    }
    </script>
    <form runat="server" action="">
    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />

    <a id="showModalPopupClientButton" href="#" runat="server" onclick="showDialog();">Click Me</a><br /><br /><br />
    <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>

    <asp:Panel runat="server" ID="Panel1" Style="display:inherit;width:600px;height:475px;" CssClass="modalPopup">
    <div id="divMap"></div>
    <asp:Button runat="server" ID="cmdClose" Text="Close" />
    </asp:Panel>

    <iframe id="test" width="600" height="450" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="minimap2.aspx?lat=39.86887222271858&long=-75.35767078399658&desc=just%26a%26sample"></iframe><br />

    <ajaxToolkit:ModalPopupExtender ID="mpeMap" runat="server"
    TargetControlID="LinkButton1"
    PopupControlID="Panel1" BackgroundCssClass="modalBackground" DropShadow="true" CancelControlID="cmdClose" OkControlID="cmdClose" /> </form>
      
  • Re: ModalPopupExtender + iFrame + Google Maps = Off Center Map

    02-18-2008, 10:17 AM

    Hi, I had the same problem when using AJAX tabpanels with google maps.

     See the google groups conversation that I started for this.

     

    Chris

    Christopher

    Are you looking for London ExCel Hotels in the Docklands?
  • Re: ModalPopupExtender + iFrame + Google Maps = Off Center Map

    02-29-2008, 4:55 PM
    • Loading...
    • suntzu88
    • Joined on 02-29-2008, 9:55 PM
    • Posts 11
    • Points 11
  • Re: ModalPopupExtender + iFrame + Google Maps = Off Center Map

    03-09-2008, 2:00 PM

    I got a response from someone in the google groups. The javascript code to fix this problem is

    var map;
    var marker;
    var html;

    function loadMap ()
    {
    if (GBrowserIsCompatible())
    {

    map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl());
    map.enableScrollWheelZoom();
    map.setCenter(new GLatLng(51.508358 ,-0.12477701), 13);

    var point = new GLatLng(51.508358,-0.12477701);
    html = "<img  src='http://myimage.jpg' alt='myimage'/>";

    marker = createMarker(point,html);
    map.addOverlay(marker);
    GEvent.addListener(marker, "click", function()
    {marker.openInfoWindowHtml(html);});
    GEvent.trigger(marker, 'click');

    window.onload=function(){window.onload;loadMap();}

    function createMarker(point, html)
    {
    var icon = new GIcon(G_DEFAULT_ICON);
    var marker = new GMarker(point, icon);
    return marker;

    }

    the key part is the
    window.onload=function(){window.onload;loadMap(); which calls the onload funtion. I presume that it's mostly due to load order of the page.

     

    Christopher

    Are you looking for London ExCel Hotels in the Docklands?
  • Re: ModalPopupExtender + iFrame + Google Maps = Off Center Map

    03-10-2008, 4:31 PM
    • Loading...
    • melmendo
    • Joined on 10-26-2007, 3:03 PM
    • Virginia
    • Posts 51
    • Points 204

    Does this work for anybody else?  My google map is still off center when adding "window.onload=function(){window.onload;loadMap();"

     

    Thanks in advance,

    Mark

    http://www.marktheweb.com
  • Re: ModalPopupExtender + iFrame + Google Maps = Off Center Map

    03-11-2008, 4:36 AM

    Mark,

     can you post the page where it doesn't work?

    Christopher

    Are you looking for London ExCel Hotels in the Docklands?
  • Re: ModalPopupExtender + iFrame + Google Maps = Off Center Map

    03-12-2008, 2:26 PM
    • Loading...
    • melmendo
    • Joined on 10-26-2007, 3:03 PM
    • Virginia
    • Posts 51
    • Points 204

    Hi Chris,

    Sorry for my delayed response.

    Page that works (doesn't use ajax tab panels) http://206.113.151.114/wct/googlemaps.aspx

    Page that DOES NOT work (uses ajax tab panels) http://206.113.151.114/wct/hoteldetail.aspx?hi=10010834

    Thanks again,

    Mark

    http://www.marktheweb.com
  • Re: ModalPopupExtender + iFrame + Google Maps = Off Center Map

    03-13-2008, 4:13 AM

    Mark,

     you'll need to take out the loadMap from your onload event in the body tag

    <body id="ctl00_MasterBody" onload="loadMap();" onunload="GUnload();">

    I don't completely understand the source of the problem, but it seems to be related to when the different components are loaded. The window.onload=function(){window.onload;loadMap();} is enough to fire the loadMap function. As it later in the page load order it will resolve the problem.

     let us know if it works. - CB

    Christopher

    Are you looking for London ExCel Hotels in the Docklands?
  • Re: ModalPopupExtender + iFrame + Google Maps = Off Center Map

    03-13-2008, 8:36 AM
    • Loading...
    • melmendo
    • Joined on 10-26-2007, 3:03 PM
    • Virginia
    • Posts 51
    • Points 204

    I have it working, but it's kind of a hack.

    1. I took your exact code and got it working on a plain old .aspx page. -- working
    2. Next, I used the same code but put it in a ajax TabPanel. -- still working
    3. Then I wrapped that in an extremely simple master page to see if that was breaking it. -- nope still working
    4. Finally, I used my original stylesheet and WHAM -- it uncentered the map.

    The only thing I know is that if my right sidebar has more content (length) then my main content div, then it breaks???  Not to be confused with the div that actually holds the google map <div id="map".  This was happening across all browsers that I have tested with (ie, firefox, opera).  Thats unfortunately all I know.

    I will continue to investigateIf anyone understands what may be causing the issue now I would be greatly appreciative.

    Again, thank you much.

    Mark

    http://www.marktheweb.com
Page 1 of 1 (10 items)