angular-google-maps icon indicating copy to clipboard operation
angular-google-maps copied to clipboard

Event handler arguments

Open dmitriykharchenko opened this issue 12 years ago • 4 comments

The way of passing arguments to event handlers is a bit confusing for me. Why not to go simple and preserve original google maps api in this case?

// source code
getEventHandler = (eventName) ->
  ->
    scope.events[eventName].apply scope, [_m, eventName, arguments]

//bind handler
events:
  'click': (map, eventName, eventArguments) ->
     console.log eventArguments[0].latLng // looks strange

dmitriykharchenko avatar Apr 22 '14 04:04 dmitriykharchenko

The events attributes maps directly onto the Google Maps event API.

Can you suggest a less confusing interface, or is this just a documentation issue? On Apr 21, 2014 9:04 PM, "aki-russia" [email protected] wrote:

The way of passing arguments to event handlers is a bit confusing for me. Why not to go simple and preserve original google maps api in this case?

// source code getEventHandler = (eventName) -> -> scope.events[eventName].apply scope, [_m, eventName, arguments]

//bind handler events: 'click': (map, eventName, eventArguments) -> console.log eventArguments[0].latLng // looks strange

— Reply to this email directly or view it on GitHubhttps://github.com/nlaplante/angular-google-maps/issues/378 .

rickhuizinga avatar Apr 22 '14 04:04 rickhuizinga

As for me, less confusing could be same as in google maps. But, I understand that map and eventName was added for some reason.

My suggestion is to pass arguments as it in google-maps, but also concat additional from directive:

events:
  'click': (event, map, eventName) ->
     console.log event.latLng // looks better

Second way is to concat original arguments to directive's:

events:
  'click': (map, eventName, event) ->
     console.log event.latLng //looks even better

dmitriykharchenko avatar Apr 22 '14 04:04 dmitriykharchenko

Removing and/or reordering the map and eventName parameters from the callback function would break many existing applications.

We'll update the documentation for the events attribute, as they don't document the existence of these two callback function parameters.

rickhuizinga avatar Apr 22 '14 20:04 rickhuizinga

Added documentation for events callback function parameters in [website-develop] to be released with v1.1. See 1275ad98dfcef946485edf59392d8b67d45f8520

rickhuizinga avatar Apr 23 '14 01:04 rickhuizinga