Closed fabn closed 9 years ago
Hey @fabn:
You can't use the .addMarkers
method when you are building markers with custom data.
You have to build them by map
.
You can check it out in the wiki here: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Adding-an-id-to-markers-and-access-them-later
Yes, I found out that. I've added this code to handle the situation:
# Monkey patch after init to attach custom json to marker
Gmaps.Google.Builders.Marker.prototype.after_init = ->
@serviceObject[k] = v for k,v of @args.data # Attacching data to already built marker
In this way I can attach custom data automatically with no restrictions
markers = Gmaps4rails.build_markers(collection) do |item, marker|
marker.json data: {id: item.id, foo: item.foo} # marker (serviceObject) will have a id and a foo properties
end
Wow, that's clean!
Can we close this @apneadiving?
@fabn nice way :) @plicjo here we go ;)
I'm using the
MarkersBuilder
ruby helper to build some marker data and it's awesome, however I have an issue. In the rubydoc you attach custom data to the marker with this syntax:What's that for? I'm adding markers to map using the handler:
In
myClickHandler
I don't know how to access thecode
and theid
I stored in the ruby code for the clicked marker.