On Jan 16, 9:02 pm, "[email protected]" <[email protected]>
wrote:
>
> Try using function closure.
>

Doesn't help.  Or at least I don't think it helps.  The problem is
that when the dblclick event is fired I need some way to identify the
marker that was clicked.  Calling an outside function is fine, but I
still need to know who got the dblclick.

> That looks a lot like pitfall 
> #3.http://groups.google.com/group/google-maps-js-api-v3/search?group=goo...
>

I think so.

So .. here is a workaround that could be described as clever or
kludgy.  I tend toward the latter.

I found that the object "this" is in fact the MarkerOptions of the
marker that was clicked.  Not the marker object itself.  So I have
used the zIndex of the MarkerOptions (which I was not previously
using) to store an index into the marker array allPins.

        for(i=0;i<allPins.length;i++){if(allPins[i]!=null){
                allPins[i].setMap(griddedMap);
                google.maps.event.addListener(allPins[i], 'dblclick', 
function(obj)
{
                        if(allPins[this.zIndex]!=null){  //bug?  i+1 listeners 
are created
when allPins[i] is passed.
                                allPins[this.zIndex].setMap(null);
                                allPins[this.zIndex] = null;
                        }
                });
        }};

But there is one other thing going on here.  I think it is a bug at
Google.  When I pass allPins[i] as the marker for listening, there are
i+1 watchers created.  One for each element of allPins with an index =
i or smaller.  So, what happens is if, say, there are four markers
then I end up with four watchers on allPins[0], three on allPins[1],
and so forth.  That is why I have to test for null on the third line
of the code snippet.  Fortunately, my users will never have more than
a few markers of this type so I can take the overhead.

>Post a link to your map that exhibits the problem.

It's not on the internet plus there is a lot of user interaction
required before someone could get to the point of seeing the issue.
That's why I just posted a simplified snippet.

-- 
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