It was quite convenient that the tip of Central America joining South America is so narrow that it was possible to build a canal. Imagine those Spanish invadors who had to sail around the treacherous Tierra del Fuego to get to the west coast. The French started a project in 1881 but abandoned it, the US started in 1904 and it opened in 1914. More recently a new wider/longer set of locks was built that opened in 2016. It is a remarkable engineering effort with lots of techical challenges to the various projects. And what a difference it has made to commerce and travel. An interesting wikipedia article is here.
Our long layover at Panama City allowed us to take a tour. We saw various boats going through - one of which barely fit. Some of the nearby buildings include a Trump Tower and a Frank Gehry building that is a biodiversity museum. We didn;t have time to go to it.