我正在尝试这个例子:链接通过单击ajax按钮初始化第二个地图,但地图没有初始化。我正在使用最新版本的gmaps4rails。我的来源:
= gmaps("map_options" => { "detect_location" => true, "center_on_user" => true, "auto_adjust" => true, "zoom" => 12, "auto_zoom" => false })
%button#ajax_map Ajax Map
#map_container
#map2
js:
$(function() {
$('#ajax_map').click(function(){
$('#map_container').addClass('map_container');
$('#map2').addClass('gmaps4rails_map');
Gmaps.map2.map_options.detect_location = true;
Gmaps.map2.map_options.center_on_user = true;
Gmaps.map2.initialize();
});
});
css: .map_container {
width: 600px;
}
#map {
width: 600px;
height: 400px;
}
#map2 {
width: 600px;
height: 400px;
}
我做错了什么?
从1.0.0开始,我创建了'真正的' js对象。
所以你需要实例化它:
Gmaps.map2 = new Gmaps4RailsGoogle(); // for a google map