code: function(boundsSWNE, mapSize) {
      // sometimes the map reports size = 0 so return null
      if(mapSize.x === 0 || mapSize.y === 0) return null;
      var size = [mapSize.x, mapSize.y],
      zoom = this.get('minZoom') || 0,
      maxZoom = this.get('maxZoom') || 24,
      ne = boundsSWNE[1],
      sw = boundsSWNE[0],
      boundsSize = [],
      nePoint,
      swPoint,
      zoomNotFound = true;
  
      do {
        zoom++;
        nePoint = cdb.geo.Map.latlngToMercator(ne, zoom);
        swPoint = cdb.geo.Map.latlngToMercator(sw, zoom);
        boundsSize[0] = Math.abs(nePoint[0] - swPoint[0]);
        boundsSize[1] = Math.abs(swPoint[1] - nePoint[1]);
        zoomNotFound = boundsSize[0] <= size[0] || boundsSize[1] <= size[1];
      } while (zoomNotFound && zoom <= maxZoom);
  
      if (zoomNotFound) {
        return maxZoom;
      }
  
      return zoom - 1;
    }
docs: adapted from leaflat src @return {Number, null} Calculated zoom from given bounds or the maxZoom if no appropriate zoom level could be found or null if given mapSize has no size.