Exactly soluble magnetoelastic lattice with a magnetic phase transition