我正在使用GM4Rails Gem。如何配置Google Maps for Rails地图配置文件?
我很喜欢Rails,我试图找到配置文件,所以我可以得到一个HYBRID谷歌地图,而不是ROADMAP。
我无法找到该文件:https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Map
有反正我可以改变的配置?
我正在使用GM4Rails Gem。如何配置Google Maps for Rails地图配置文件?
我很喜欢Rails,我试图找到配置文件,所以我可以得到一个HYBRID谷歌地图,而不是ROADMAP。
我无法找到该文件:https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Map
有反正我可以改变的配置?
你必须知道:
<%= gmaps4rails(@json) %>
是一条捷径:
<%= gmaps("map_options" => { "auto_adjust" => true},
"markers" => { "data" => @json })
%>
当你需要通过额外的选项,你必须使用gmaps
帮手。在你的情况下:
<%= gmaps("map_options" => { "auto_adjust" => true, "type" => "HYBRID" },
"markers" => { "data" => @json })
%>
正如你看到更多的选项可用。
所以显示的地图,你使用类似下面的代码:
<%= gmaps({
"map_options" => {"container_id" => "connections_map_container", "auto_adjust" => "true", "bounds" => '[{"lat": 0, "lng": 0 }, {"lat": 80 , "lng": 100 }]'},
... #add here data you want to display
})
%>
这是你在你的地图选择传球,在该行因此任何地方,你会插入"type" => "HYBRID"
所以修改例如会是什么样子
<%= gmaps({
"map_options" => {"container_id" => "connections_map_container", "auto_adjust" => "true", "bounds" => '[{"lat": 0, "lng": 0 }, {"lat": 80 , "lng": 100 }]'}, "type" => "HYBRID"
... #add here data you want to display
})
%>
如果直接调用Gmaps.loadMaps();
功能,使用方法:
search_map = new Gmaps4RailsGoogle();
Gmaps.search_map = search_map;
search_map.map_options.raw.streetViewControl = false; // yes, raw
// more options
search_map.map_options.id = "search_map";
search_map.map_options.maxZoom = 14;
search_map.map_options.zoom = 12;
Gmaps.loadMaps();
我不是太肯定的代码(这是从旧的代码库)的其余部分,但你正在寻找的行是search_map.map_options.raw.streetViewControl = false;
非常感谢!这是工作。我不知道gmaps4rails是扩展gmaps(...)方法的捷径。 我认为我对其他初学者的建议是创建一个帮助器,将HELPER方法中的所有其他选项封装起来,以便代码在VIEW中保持DRY状态。 – 2011-06-09 22:31:10