On Jan 17, 9:12 am, Myopia <[email protected]> wrote:
> 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.  

It is not an easy topic, you need to understand how it works.

> The problem is
> that when the dblclick event is fired I need some way to identify the
> marker that was clicked.  

Function closure can keep a reference to the marker.

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

I doubt it. Post a link to your map that demostrates the "bug", it is
most likely a problem in your code.

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

>From the v2 group, but still appropriate:
http://groups.google.com/group/google-maps-api/web/why-including-a-link-is-critical

If you can't post a link to a sanitized map that exhibits the problem,
you will have to fix it yourself (although from the sounds of things,
correctly using function closure will fix it).

  -- Larry

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