How to know when Map is done painting after create

I've noticed bugs when you attempt to modify a map (set region or other things) immediately after creating the map. I noticed that if you load mapkit, wait 5 seconds then create a map, it makes about 5 network calls, downloads a js file, and runs some javascript. I have an issue where I have to do some loading after the map is fully ready, and may need to destroy the original map.

To make a test of this, try creating a map then immediately call destroy and unmounting it. It'll produce a bunch of not defined errors as it's still trying to set up the map you just destroyed

How do I know that the map that was created is ready and done with all the work it was doing? When is it safe to destroy that map? I found there is a property called map._impl.state that will be Initialized or Ready. But when it gets to Ready it is still not fully done loading, a destroy there will still cause errors.

Is there an event listener or any way to tell that a map is completely done initializing and drawing on the screen? Currently I'm just using a timeout after the map._impl.state goes to Ready, but that's a terrible solution.

Replies

To be clear, these extra network calls and work being done is when creating the map, after the mapkit is already fully initialized. It creates a conflict with dojo loader which is why I need to create and destroy a map, before I can load dojo loader.