Optimizing large WP Query
The first thing I would consider is saving the resulting $markersArray into a transient - I'm not sure how much data you can fit into one transient, so you might need to split the data into couple of transients. More about transients, https://developer.wordpress.org/apis/handbook/transients/
The basic idea is to run the costly query once, store the result into one value in the wp_options table, and then use that value on any subsequent requests, skipping the query alltogether.
But with transient you need to decide when and how you invalidate and rebuild them. Do you give them some lifespan (minutes, hours, days...) and let them recreate themselves whenever the lifespan expires. Or is the transient only recreated whenever you add a new post or update an existing post. Or you could conjure a scheduled action (WP Cron, replaced with system cron for accuracy) that runs the query and updates the transient at a low-traffic time of the day, which can cause delay between post publish/update and the data actually showing on the public view.
Another option could be to skip the query on the initial php load and move it to an ajax request. So you would first show an empty map, which would get populated by a looping ajax request either to admin-ajax.php or to a custom WP REST Api endpoint. For example first fetch the first 1000 posts, when they're ready the next 1000 (i.e. page 2), and so on until all of the posts / map pins have been fetched. The pin json could then be stored to the user's browser, if needed.
I'm not a database expert, but I'd imagine you could also add a custom db table to serve as a aggregate table, which would contain appropriate columns for the pins. This table would get populated / updated whenever you would add or update a post - i.e. the save_post_{$post-&gt;post_type} action, https://developer.wordpress.org/reference/hooks/save_post_post-post_type/. Then you'd query this aggregate table with $wpdb and get all of the pin data on one go.
Or instead of an aggragate table or a transient, turn the query result into json and store it into a file, which you could then include and have the map script consume.
And if not all map pins are needed at the very beginning, get only the pins for the currently visible area with an ajax request when you know the map boundaries. Then fetch more pins when the boundaries change.