A population-genomic approach for estimating selection on polygenic traits in heterogeneous environments