1

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.

1

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.

  • Thanks Peter. Unfortunately I am unable to test this because the project was just released, and the requirement was no longer deemed necessary. Therefore I cannot test it, but I understand your logic and it makes sense to do it your way – Haki_z Jun 27 '16 at 19:19
1

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.

  • 1
    Removing all layers will eventually also close the map window. It might be faster to just close the map window and then make a new map window. Or change the layer settings in the existing map to match the new layer settings – Peter Horsbøll Møller Jun 17 '16 at 8:37
  • Good point Peter, I hadn't considered that! Perhaps you should put that into an answer as it's certainly a better solution to this question. – T_Bacon Jun 17 '16 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.