Testing GCGCMap Shortcode
Current status of this test: I have it working.
This has not been as easy to implement as one might think at first. Putting multiple maps on a page is trivial but putting any number of maps on a page without knowing how many is not so easy. If you are interested in the technical details of how I have solved this problem to date, I am writing a post about it on my technical blog. Check back for the link or book mark TheGarage.
The goal is to allow multiple shortcodes in a post as well as multiple text widgets containing a shortcode. Or even multiple shortcodes in a single text widget.
Right off the bat the need to provide dynamically created divs with unique id attributes is evident and it quickly became obvious that the Javascript map objects must be managed in a way such that the last map doesn’t get constructed before the previous map is complete. Without the proper management technique you will invariably wind up with either the same map in every div or only one map in the last div on the page.
AT first I believed javascript closures were the proper way to implement what I needed but I couldn’t get it to work properly. Then I realized that since I have to have a php function to process the shortcode anyway, I could simply calculate the proper map instance name in php using a static variable and spit the value out on the page as a javascript function parameter. Yucky sounding I know, but very simple to implement. Like 5 minutes.
Javascript Closures may or may not be implemented in the next revision. I think it would be beneficial to encapsulate the entire xmldoc object returned from a maps ajax call as well as the Google Map object. Then every map instance would have its own xmldoc and I wouldn’t need to insert the smallPause(100) between shortcode calls or refresh the window to get all the maps to show. I’m just going to have to do so more research to find the optimal implementation of dynamic map loading.
I really want to get this figured out before the release but it may have to wait.