I'd like to know how to close all the layers on MapInfo but keep the tables open using MapBasic code. The idea is to be able to keep the tables open so that I can create multiple different maps using the same tables. Basically, for every map I create and export as an image , I want to close the layers for that map and then start creating my next map with the same tables as before. I don't want to Close all and then reopen the tables.
As I stated in a comment above, removing all layers from a map window, will eventually close the map.
It might be faster just to close the map window:
nMapWinID = FrontWindow() 'make sure the map window is at the front before running this Close Window nMapWinID
Now the map window has been closed and you can create a new one. By the way, you can have more than one map window as a time if needed.
Alternatively, you can change the layer settings for the existing map to match the requirement of the next map. You don't have to start over everytime.
What you need to do is loop through the layers of the map window and remove them individually from the mapper window. This way they are not closed, just removed from the map. e.g.
Dim nLayers, i, nMapWinID as Integer nMapWinID = FrontWindow() '// make sure the map window is at the front before running this nLayers = MapperInfo(nMapWinID, MAPPER_INFO_LAYERS) '// get the total number of layers in the mapper '// remove each layer starting at the last and working down to layer 1 For i = nLayers to 1 Step -1 Remove Map Window nMapWinID Layer i Next
Remember that you need to start at the last layer and work down otherwise the layer indexing will go wrong and you'll get an error.