我想使用gmaps4rails gem
创建一个infowindow,我也放置了集群。到目前为止,我可以创建聚类,但是当我点击聚类时,它会放大到单个标记。我使用部分模板来显示信息。但是,我无法做模板。因为我无法获得标记的个别信息。因此,它显示了标记的所有信息。这里;
缩小后;
我喜欢做的是,它显示像第二页一样的群集,当我点击infowindow打开时。相反,它像第一张照片一样放大。
这是我的locations_controller
;
class LocationsController < ApplicationController
def index
if params[:search].present?
@locations = Location.near(params[:search], 5) #Kac mile cevresinde aranıldıgının bilgisi bu km ile değişebilir
else
@locations = Location.all
end
@hash = Gmaps4rails.build_markers(@locations) do |location, marker|
marker.lat location.latitude
marker.lng location.longitude
marker.infowindow render_to_string(:partial => "/locations/my_template", :formats => [:html], :locals => { :object => location})
end
end
end
这里是_my_template
部分;
<% @locations.each do |location|%>
<li>
<%= location.address %>
</li>
<% end %>
和index.html.erb
;
<script src="//maps.google.com/maps/api/js?v=3.13&sensor=false&libraries=geometry" type="text/javascript"></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>
<h3>Nearby locations</h3>
<ul>
<% @locations.each do |location| %>
<li><%=location.address %></li> (<%= location.distance.round(2) %> miles)
<% end %>
</ul>
<div style='width: 800px;'>
<div id="map" style='width: 800px; height: 400px;'></div>
</div>
<script type="text/javascript">
handler = Gmaps.build("Google", { markers: { maxRandomDistance: 5 , clusterer: {gridSize: 45, maxZoom: 20} } })
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
编辑1:
但这是一个群集信息窗口的例子
或者这是一个弹出窗口?