我们有一个很好的Rails应用程序使用旧的gmaps4rails工作。我终于试图更新到新的v2,它似乎记录不足,缺少功能。
侧边栏
侧边栏哪里消失了?源或示例中没有对它的引用。之前,在我的控制器中,我有marker.sidebar "#{shop.name} - #{shop.location}"
。这引发了一个例外。
选项
我认为这些东西在那里,但是没有例子了。如何重现这一点:
<%= gmaps( "map_options" => {
"auto_adjust" => false,
"auto_zoom" => false,
"zoom" => 6,
"bounds" => '[{"lat": 54, "lng": 6 }, {"lat": 48 , "lng": 15 }]'
},
"markers" => {
"data" => @json,
"options" => {"list_container" => "markers_list", "randomize" => false, "max_random_distance" => 10000 }
}) %>
我可以弄明白zoom
,但其他一切看起来大不相同。
答案 0 :(得分:2)
使用干净的js恢复侧边栏的示例:
@hash = Gmaps4rails.build_markers(@shops) do |shop, marker|
marker.lat shop.latitude
marker.lng shop.longitude
marker.title shop.name
marker.json({
id: shop.id,
country: "random",
name: shop.name,
location: shop.location
})
end
$(document).ready(function(){
var raw_markers = <%=raw @hash.to_json %>;
var gmaps_markers;
function createSidebarLi(shop_json) {
return ("<li><a>" + shop_json.name + " - " + shop_json.location + "<\/a></li>");
};
function bindLiToMarker($li, marker){
$li.click(function(){
marker.panTo(); //to pan to the marker
google.maps.event.trigger(marker.getServiceObject(), "click"); // to open infowindow
});
};
function createSidebar(){
for (var i=0;i<raw_markers.length;i++){
var $li = $( createSidebarLi(raw_markers[i]) );
$li.appendTo($('#markers_list'));
bindLiToMarker($li, gmaps_markers[i]);
}
};
handler = Gmaps.build('Google', {markers: { maxRandomDistance: 10000} });
handler.buildMap({ provider: {zoom: 6}, internal: {id: 'map'}}, function(){
gmaps_markers = handler.addMarkers(raw_markers);
handler.map.centerOn({ lat: 51, lng: 11 });
createSidebar();
});
});