Thanks pete and Rossko! It was a dumb mistake on my part. I completely
overlooked the fact that it was creating a new layer each time.

Thanks again.

On Jun 21, 7:16 pm, pete <[email protected]> wrote:
> Hi Michael,
>
> As Rossko said, you are creating a layer every time.
> Instead, create the layer once, on initialize then toggle it.
>
> Step 1 - Set it as a global
> var trafficLayer;
>
> Step 2 - Create the layer in your initialize() function
> trafficLayer = new google.maps.TrafficLayer();
>
> Step 3 - Remove the new layer reference from togglTraffic
> //trafficLayer = new google.maps.TrafficLayer();
>
> So simply put, you create the traffic layer on page load, but only
> "set" it when you click your control
>
> Hope this has helped
>
> On Jun 22, 8:39 am, Rossko <[email protected]> wrote:
>
> > > I have a toggle function that handles this:
>
> > >     function toggleTraffic (toggle, map) {
> > >         var trafficLayer = new google.maps.TrafficLayer();
> > >         if (toggle) {
> > >             trafficLayer.setMap(map);
> > >         } else {
> > >             alert("Should Work");
> > >             trafficLayer.setMap(null);
> > >         }
> > >     }
>
> > > I get the alert "Should Work", but the traffic layer persists.
>
> > Which layer?   Every time you run that function, you create a new
> > layer.  Creating a new layer and immediately 'hiding' it, won't change
> > anything about any layer you may have created before.

-- 
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