14

I'm trying to create an event listener that turns off a google fusion layer once the map is zoomed in to a certain level. I'm pretty new to javascript and its google maps api, so any help is appreciated. I found some code that seems close to what I need:

google.maps.event.addDomListener(map, 'zoom_changed', function() {
  var zoom = map.getZoom();
  if (zoom >= 1 && zoom <= 9) { 
    layer_0.setMap(map);
    layer_1.setMap(map);
  } 
  else if (zoom > 9 && zoom <= 11) {
    layer_0.setMap(map);
    layer_1.setMap(map);
  }
  else if (zoom > 11) {
    layer_0.setMap(null);
    layer_1.setMap(map);
  }
});
2

1 Answer 1

18

Here is some code I'm successfully using to toggle a Fusion Tables layer in one of my maps:

google.maps.event.addListener(map, 'zoom_changed', function() {
    zoomLevel = map.getZoom();
    if (zoomLevel >= minFTZoomLevel) {
        FTlayer.setMap(map);
    } else {
        FTlayer.setMap(null);
    }
});

it looks almost identical to your code, apart from addListener vs addDomListener. Can you try adding a breakpoint inside your function to make sure it's actually running?

1
  • Thanks for your help. I'm definitely a novice when in comes to Google Maps and Javascript, so I'm still working on it.
    – b-rad-b
    Commented Aug 20, 2013 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.