Thousands of people have fled their homes after a magnitude-7.7 earthquake and 341 aftershocks hit the island.