初始化谷歌地图上的AJAX刷新部分 [英] Initialize Google map on AJAX refreshed partial

查看:377
本文介绍了初始化谷歌地图上的AJAX刷新部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以显示标记一个谷歌地图没有问题,但我不能让一个地图以显示在局部时局部刷新使用AJAX。我猜这是因为这最后的初始化在端线使用Ajax时,不会触发:

I can display a google map with markers no problem but I can't get a map to display within a partial when that partial is refreshed using ajax. I'm guessing it's because this final initialization line at the end isn't fired when using ajax:

function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

var marker = new google.maps.Marker({
  position: myLatlng,
  map: map,
  title: 'Hello World!'
});
}

google.maps.event.addDomListener(window, 'load', initialize);

所以,我可以初始化地图使用AJAX的成功处理程序之一?我试过这个没有运气,但语法可能是错误的,我不知道在哪里把这样的:

So can I initialize the map by using one of the ajax success handlers? I've tried this with no luck but the syntax is probably wrong and I don't know where to put this:

$(document).ajaxSuccess(function() {
    google.maps.event.initialize;
});

任何想法?

编辑:

我通过增加加载在 #response DIV属性/ index.html.erb页部分_property_details.html.erb 远程=>真正的来的链接,这是show.js.erb code:

I'm loading the partial _property_details.html.erb in the #response div of the properties/index.html.erb page by adding remote => true to the links and this is the show.js.erb code:

属性/ show.js.erb

$(#响应)HTML(<%= escape_javascript(渲染('property_details'))%>);

在谷歌code是所有在属性/ index.html.erb 页中的脚本标记的底部。

The Google code is all at the bottom of the properties/index.html.erb page in a script tag.

推荐答案

这应该使它发挥作用,假设你的局部刷新的使用jQuery做。

This should make it work, assuming your partial refresh is done with jQuery.

google.maps.event.addDomListener(window, 'load', initialize);
$(document).ajaxStop(initialize);

这篇关于初始化谷歌地图上的AJAX刷新部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆