apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.26k stars 382 forks source link

Add showInfowindow method to Markers #306

Closed excid3 closed 10 years ago

excid3 commented 11 years ago

I wanted to propose adding a method like this to the Marker classes:

  showInfowindow : () ->
    @controller._closeVisibleInfoWindow()
    @infowindow.open(@getMap(), @serviceObject)
    @controller._setVisibleInfoWindow @infowindow

We've got this method:

  _openInfowindow : () ->
    that = @
    return ->
      # Close the latest selected marker before opening the current one.
      that.controller._closeVisibleInfoWindow()
      that.infowindow.open(that.getMap(), that.serviceObject)
      that.controller._setVisibleInfoWindow that.infowindow

Which is very similar and wondered what your thoughts were on adding something like this. It makes it really easy for me to add a "View on Map" link that I can use a data attribute to quickly find the marker and show the infowindow like so:

  $('.marker-link').on 'click', ->
    id = $(this).data("marker-id")
    marker = $.grep Gmaps.map.markers, (e) ->
      e.id is id
    marker[0].showInfowindow()

Figured this might be useful, but wanted to get some feedback before I submitted a pull request.

apneadiving commented 11 years ago

what about:

showInfowindow : () ->
   (@_openInfowindow())()
excid3 commented 11 years ago

Yes if that works! (I'm not great at javascript yet). Just mainly wanted a simpler way to find and show the infowindow from javascript.

excid3 commented 11 years ago

I'm revisiting this pretty late, but I can confirm that your code does work for me. (and it's a lot simpler :smile:)

I can submit a pull request for this on just Google Maps, but I'm not familiar with how to do this on OpenLayers or Bing maps since I've never used them. I imagine it'd be useful to have on each, so do you know which docs to point me to and I'll see about adding this for the other providers?