Local adaptation and maintenance of variation in heterogeneous environments