Hey Berry

On Mar 3, 2011 6:47 AM, "bratliff" <bratl...@umich.edu> wrote:
>
> Berry,
>
> Your comment seems to be unrelated to the post. Please start a new
> thread.
>
> Thanks
> Ben
>
> Sorry
>
> The use of "function closures" for event listeners might work for a
> few dozen markers but it does not scale well for many hundred or many
> thousand.  Combining event listeners into a common function with
> something unique assigned to a property of the marker's "this" object
> is a step in the right direction.  The redundant function code is
> reduced but each marker still requires its own event listener pointing
> to the same common function.

It sounds like you're making a new function for each marker's listener. Note
that the event target is passed as 'this' to an event listener, so you can
reuse a single closure for a class of targets. This is what we do internally
for efficiency.

> CANVAS does not provide native mouse support.  All event listeners
> must call some function to determine which of many candidates in a
> tile caused the mouse event.  Instead of hundreds or thousands of
> pointers to a shared function, why not define the function once for an
> entire set of markers.  Similarly, separate calls to the "setMap"
> method might be combined.

We invert the control flow that you describe. On click a single function
computes which marker was hit, and triggers an event on the Marker object.

> The use of "function closures" must be supported for compatability but
> it ought to be discouraged & depreciated & replaced.

I appreciate the naive use of closures (eg. 1 per marker for 10k markers)
causes poor performance, but closures are fast when used well. I think this
is an issue of education then - good examples showing how to get the best
performance out of browsers.

Cheers
Ben

>
> --
> 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
google-maps-js-api-v3@googlegroups.com.
> To unsubscribe from this group, send email to
google-maps-js-api-v3+unsubscr...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>

-- 
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 google-maps-js-api-v3@googlegroups.com.
To unsubscribe from this group, send email to 
google-maps-js-api-v3+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to