The first version of your code was much better. :-) You understood scoping
correctly; there's no need to move those variables to the global scope.

That said, I don't know what the problem is either. It certainly looks like
you're making the right call when I stop and look at it in Firebug.

I suspect that Pil is right - it "looks like a bug". That comment was not
sarcasm, just a bit unclear: it looks like it could be a bug in the *Maps
API*, especially considering the overlay rendering changes in the latest
version of the API.

Did you test it with V3.3 or 3.2? I would try those older versions to see
what happens:

http://code.google.com/apis/maps/documentation/javascript/basics.html#Versioning

<http://code.google.com/apis/maps/documentation/javascript/basics.html#Versioning>
-Mike

On Wed, Apr 27, 2011 at 10:33 AM, Val <[email protected]> wrote:

> The map and the traffic variables were in the closure of the event callback
> but just in case I'm wrong I modified the script to:
>
> google.maps.event.addDomListener( window, 'load', init );
>   map = null;
>   traffic = null;
>         function init() {
>             var options = {
>                     zoom: 7,
>                     center: new google.maps.LatLng( 39.8333333, -98.5833333
> ),
>                     mapTypeId: google.maps.MapTypeId.ROADMAP,
>                     overviewMapControl: false   // see
> http://code.google.com/apis/maps/documentation/javascript/forum.html?place=topic/google-maps-js-api-v3/YxDUmSzksqs
>                 };
>
>             map = new google.maps.Map( document.getElementById( "map" ),
> options );
>             traffic = new google.maps.TrafficLayer();
>             traffic.setMap( window.map );
>              google.maps.event.addDomListener(
>                 document.getElementById( 'b' ),
>                 'click',
>                 function() {
>                     traffic.setMap( traffic.getMap() === null ? map : null
> )
>                 } );
>         }
>
> Still doesn't work...
>
> Val
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps JavaScript API v3" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to