views:

243

answers:

1

Here's a page with the issue

To reproduce the error, using IE - click the directions tab, then any of the others.

What I'm trying to do is this:

On page load, do nothing really. However, when the directions tab loads - setup the map. Like so:

$('#tabs').bind('tabsshow', function(event, ui) {
    if (ui.panel.id == "tabs-5") {

        // get map for directions
        var dirMap = new GMap2($("div#dirMap").get(0));
        dirMap.setCenter(new GLatLng(35.79648921414565,139.40663874149323), 12);
        dirMap.enableScrollWheelZoom();
        dirMap.addControl(new PanoMapTypeControl());
        geocoder = new GClientGeocoder();

        $("#dirMap").resizable({
           stop: function() { dirMap.checkResize(); }
        });
        // clear dirText
        $("div#dirMapText").html("");
        dirMap.clearOverlays();

        var polygon = new GPolygon([new GLatLng(35.724496338474104,139.3444061279297),new GLatLng(35.74748750802863,139.3363380432129),new GLatLng(35.75765724051559,139.34303283691406),new GLatLng(35.76545779822543,139.3418312072754),new GLatLng(35.767547103447725,139.3476676940918),new GLatLng(35.75835374997911,139.34955596923828),new GLatLng(35.755149755962755,139.3567657470703),new GLatLng(35.74679090345495,139.35796737670898),new GLatLng(35.74762682821177,139.36294555664062),new GLatLng(35.744422402303826,139.36346054077148),new GLatLng(35.74860206266584,139.36946868896484),new GLatLng(35.735644401200986,139.36843872070312),new GLatLng(35.73843117306677,139.36174392700195),new GLatLng(35.73592308277646,139.3531608581543),new GLatLng(35.72686543236113,139.35298919677734),new GLatLng(35.724496338474104,139.3444061279297)], "#f33f00", 5, 1, "#ff0000", 0.2);dirMap.addOverlay(polygon);

        // load directions
        directions = new GDirections(dirMap, $("div#dirMapText").get(0));
        directions.load("from: [email protected],139.37083393335342 to: Ruby [email protected],139.40663874149323");

    }
});

What the heck is causing the error? The IE javascript debugger claims the error lies in main.js, line 139 character 28. (the google maps api file). Which is this line:

function zf(a,b){a=a.style;a.width=b.getWidthString();a.height=b.getHeightString()}

Any ideas? Thanks in advance!

+1  A: 

The problem appears to be a known issue with jQuery Tabs and IE, see: Why does my slider, Google Map, sIFR etc. not work when placed in a hidden (inactive) tab?

The suggested solution is to override the jQuery Tabs CSS using:

.ui-tabs .ui-tabs-hide {
    position: absolute;
    left: -10000px;
}

However, this does not immediately fix your problem because if you search the CSS you will see that your .ui-tabs-hide definition contains:

.ui-tabs .ui-tabs-hide { display: none !important; }

This CSS makes the suggested fix ineffective. So to fix the problem you need to tweak the suggested fix so that it reads:

.ui-tabs .ui-tabs-hide {
   display: block !important;
   position: absolute;
   left: -10000px;
}

This should get rid of the problem. HTH.

Mark McLaren
@Mark I was so hoping that was the issue... I tried it, but no fix. The problem only arises when the tab is selected, and then a different tab is selected. Almost like there is some kind of "cleanup" not happening (on the Google maps side of things most likely). I can't find a "tabhide" event that I could hookup to "cleanup" the maps when the tab is unloaded... ;(
Chad
Hi Chad,I copied the page source, added a <base> tag and added the fix inside a <style> element that was the last element on the page before the </body> and the problem went away!
Mark McLaren
@Mark I will give that a try! Thanks for taking the time to do that - way above and beyond how far most will go to help. Really appreciate it!
Chad
@Mark ok! the fix worked... except now the directions text that Google Maps loads, gets thrown out of the tabs - when selecting a tab other than directions. Also, the hover bg image can be seen at the bottom of the tabs. If I remove the directions text, it runs fine! yay no javascript error! But now I have to figure out how to get the directions text back in there.
Chad
Try adding: .ui-tabs .ui-tabs-hide #dirMapText{display: none;}
Mark McLaren
Works, you rock. Thanks for the help!
Chad