Thanks Petr, but I just found out how to do it myself too! I totally forgot that I made something similar a year or 2 ago so I copied that code. I hope it's OK with you that I use my own code this time. It just feels good that I could do it. The map is also now 4000 x 4000 and makes no extra files. Plus the RAM memory is down to 109 mb.
(Code deleted, much better version a few pages from here.)
(Code deleted, much better version a few pages from here.)