[GIS] Zoom Change Event Listener with google maps api

google-fusion-tablesgoogle-maps-apijavascript

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);
  }
});

Best Answer

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?