The game has a concept of scenes for different UI states which are handled by a scene manager. You could hook into the scene for the world map and listen to the callback that is fired when it shows or hides.
This code in worldmap.lua gives an example how it works.