pointer to this map from outside your script

23 views
Skip to first unread message

Vincent

unread,
Nov 23, 2011, 6:10:06 PM11/23/11
to WPGmappity
Hello
thank you for this very nice tool.
I have one request : is it possible to interact (in javascript) with
the google.map object (called wpgmappitymap1) after the page is
loaded ?

I tried to get back the object, but this one is declared into the
function "wpgmappity_maps_loaded1() ", so it is local to this
function...

As a consequence, when I try to use is like
wpgmappitymap1.setCenter(lnlg); I have a 'object not found' error


Thus, my main problem is that the source code is instanciated locally
in a function, without any reference to the document or something
else. I tried to get the object with methods like getElementById, but
i cannot get a result.
My current workaround (outside wordpress) is to declare a global
variable into the Head part of the page, and add "publicmap =
wpgmappitymap1;" at the end of you function. Now I can use the object
publicmap anywhere...

Vincent

Matt Schwartz

unread,
Nov 23, 2011, 8:27:51 PM11/23/11
to wpgma...@googlegroups.com
Hiya Vincent,

It is wrapped up in that function on purpose to keep things from polluting the global scope.  In fact I should probably wrap the whole thing up in a closure to keep even the function name out of it.

However, a quick hack can move the map object back out of the global scope.  Check out this branch on github:


Just a couple of changes to the PHP file that cobbles together the JS when a post is displayed will move it back out so you can latch on to it.

In line #80 of wpgmappity-posts.php the object is declared before the function name therefore making it global.


The other change would be on line 93 where instead of declaring a new variable with function scope the code in this branch removes the "var" so the variable will just reference the global:


Hope this helps.  I don't know that I will maintain both branches, but if you need to update the plugin at any point you can go back and make the change to those two lines to get the results you need.

Matt
Reply all
Reply to author
Forward
0 new messages