James Tomkins has left West Ham United for Crystal Palace, signing a five-year deal with his new club.