On Jan 17, 1:38 pm, JKurtock <[email protected]> wrote:
> Actually, function closure does (for me) exactly what you're trying to
> do.  Hard to understand, but not hard to do.

Yes.  A little monkey-see, monkey-do programming based on your example
got the job done.  No more kludgy workaround!

> clickCallbackClosure is NOT the function handling the click event,
> rather it returns the (anonymous) function that does.  But through the
> magic of closure, the click handling function can identify (through
> variable MarkerNo) which Marker through the event.

Yes.  I see that.  clickCallbackClosure is actually called when the
listener is being set up.  I'll have to think about the whole concept
and do some reading.

>
> Note that using a global variable inside an ordinary event handling
> function won't work, because the global variable will be evaluated at
> the time the function is invoked (the event fired), not the time that
> the function was attached to the event.

Yes.  That's what I started with -- allPins[i] was getting evaluated
when the event fired (and i had some quasi-random value).  Very
confusing to sort out.

Re the "bug" where a stack of listeners seemed to be getting created
by addListener I have now determined that they are getting added in
another way.  When a pin is created (hence allPins gets one element
bigger) I recreate the whole map for reasons outside the scope of this
thread.  I had assumed that everything associated with the old map was
blown away (I even set the map variable griddedMap to null) but that
seems to not be the case.  Hence my stack of listeners.  So now I am
using clearListeners to make sure that the old lsteners are gone when
I put the pins and listeners onto the new map.  I am also going to re-
look the need to recreate the map.  It might be overkill for what I am
trying to do.

Anyway, thanks a lot gents.  You were a big help on what was a tough
problem for me.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to