from pymbtiles import MBtiles
import mapbox_vector_tile
import gzip

mb = MBtiles("./static/salida.mbtiles")

found = False

for z in range(
    int(mb.meta.get("minzoom", 0)),
    int(mb.meta.get("maxzoom", 14)) + 1
):
    for x in range(0, 2**z):
        for y in range(0, 2**z):
            tile = mb.read_tile(z, x, y)
            if tile:
                try:
                    # 🔑 DESCOMPRESIÓN
                    tile = gzip.decompress(tile)
                except OSError:
                    # no estaba comprimido
                    pass

                decoded = mapbox_vector_tile.decode(tile)

                print("✅ Tile encontrado")
                print("z:", z, "x:", x, "y:", y)
                print("Layers:", decoded.keys())

                found = True
                break
        if found:
            break
    if found:
        break
