#!/usr/bin/env bash # tiles-build [tippecanoe options and inputs…] (roadmap 15.17c): one tippecanoe build, # except that zooms below 7 get their own pass at a quarter of the detail (1,024 units a tile: about a pixel on screen) # and at most 150 KB a tile (the smallest features dropped first), so a wide view of land, units or public land stays # light on a phone. Zooms 7 and up are built exactly as asked; tile-join puts the two passes together. set -euo pipefail [[ $# -ge 3 ]] || { echo "usage: tiles-build [tippecanoe args…]" >&2; exit 2; } out="$1" minzoom="$2" maxzoom="$3" shift 3 LOW_TOP=6 # the last zoom of the light pass LOW_DETAIL=10 # 2^10 units across a tile (tippecanoe's default is 12) LOW_MAX_BYTES=150000 if (( minzoom > LOW_TOP )); then exec tippecanoe -o "$out" --force -Z"$minzoom" -z"$maxzoom" "$@" fi low="${out%.pmtiles}.low.pmtiles" high="${out%.pmtiles}.high.pmtiles" lowmax=$(( maxzoom < LOW_TOP ? maxzoom : LOW_TOP )) # Options given after the caller's win, so the light pass's limits hold whatever the caller asked for. tippecanoe -o "$low" --force -Z"$minzoom" -z"$lowmax" "$@" \ --full-detail="$LOW_DETAIL" --low-detail="$LOW_DETAIL" --maximum-tile-bytes="$LOW_MAX_BYTES" --drop-smallest-as-needed if (( maxzoom <= LOW_TOP )); then mv -f "$low" "$out" exit 0 fi tippecanoe -o "$high" --force -Z$(( LOW_TOP + 1 )) -z"$maxzoom" "$@" # Both passes carry the caller's name and credit; tile-join would join them ("X + X"), so it's given them once. meta=() for (( i = 1; i <= $#; i++ )); do case "${!i}" in -n|--name|-A|--attribution) j=$(( i + 1 )); meta+=("${!i}" "${!j}") ;; --name=*|--attribution=*) meta+=("${!i}") ;; esac done tile-join -o "$out" -f -q -pk "${meta[@]}" "$low" "$high" 2> >(grep -v 'mismatched maxzooms' >&2) rm -f "$low" "$high"