开发者

Google-Maps-for-Rails : Link for marker InfoWindow

I'm rebuilding a site using Ruby on Rails and thinking of using the excellent Google-Maps-for-Rails 开发者_如何学JAVAgem.

The gem has the option to generate a list of customised links for all the markers as:

<ul id="markers_list">
 <li>
  <a href="javascript:void(0);">Marker A</a>
 </li>
 <li>
  <a href="javascript:void(0);">Marker B</a>
 </li>
</ul>

However, I need to add additional content, so rather than just showing a list of links I need to generate the following for each marker

<ul id="marker_a">
  <li><h3>Marker A</h3></li>
  <li>Details about Marker A</li>
  <li>
    <a href="javascript:void(0);">Show Marker A on Map</a>
  </li>
</ul>

Can anyone suggest the best way of going about this?


I've forked the project to enable a standalone link for each marker. Have a look at https://github.com/noddy/Google-Maps-for-Rails

In your model (using Location in this example) you need to add extra methods:

class Location < ActiveRecord::Base
 def gmaps4rails_link
   id.to_s
 end

 def gmaps4rails_link_text
   "Show #{name} on Map"
 end
end

Then in your view (using HAML here), you could add the following:

- @locations.each do |location|
  %ul
    %li
      %h2
        = location.name
    %li{:id => "map_link_" + location.id.to_s}

and then call gmaps4rails properly using

 <%= gmaps("markers" => {"data" => @json, "options" => {"link_container" => "map_link_" } }) %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜