1

我正在使用 gmaps4rails。我正在尝试实现以下目标:地图显示带有标记的位置,用户可以根据需要缩放/移动他的视窗。我想要的是,当他这样做时,地图旁边的列表应该动态更新所有当前可见的位置。我尝试使用回调机制和 getBounds 来过滤可见的数据结构,但没有成功。我该怎么办?

非常感谢!朱利安

在我的控制器中:类 LocationsController < ApplicationController

  def index
    if (params[:sw_y] && params[:sw_x] && params[:ne_y] && params[:ne_x])
        bounds = [ [params[:sw_x].to_f, params[:sw_y].to_f], 
                 [params[:ne_x].to_f, params[:ne_y].to_f] ]
        @locations_within_bounds = Location.within_bounds(bounds)
    else
        @locations_within_bounds = Location.all
    end   
  @locations = Location.all
  @json = Location.all.to_gmaps4rails

在我看来:

<%= gmaps("markers" => {"data" => @json, "options" => {"list_container" => "markers_list", "do_clustering" => true } }   ) %>

<table>
  <tr>
    <th>Name</th>
    <th>Address</th>
    <th>Longitude</th>
    <th>Latitude</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @locations_within_bounds.each do |location| %>
  <tr>
    <td><%= location.name %></td>
    <td><%= location.address %></td>
    <td><%= location.longitude %></td>
    <td><%= location.latitude %></td>
 </tr>
<% end %>
</table>
4

0 回答 0