gmaps4rails this.clusterer在this.clusterer.addMarker(marker)中未定义;(gmaps4rails this.clusterer is undef

编程入门 行业动态 更新时间:2024-10-28 20:26:48
gmaps4rails this.clusterer在this.clusterer.addMarker(marker)中未定义;(gmaps4rails this.clusterer is undefined in this.clusterer.addMarker(marker);)

我收到错误this.clusterer undefined 。 您可以在下面看到我的配置。

预期行为:加载页面,而不是使用#search_form定义的查询从控制器加载标记。 最后将标记添加到#map并将它们聚类。

我的js.coffee

$ -> handler = Gmaps.build('Google'); handler.buildMap { provider: {center: new google.maps.LatLng(49.639177, 9.536133),zoom: 6}, internal: {id: 'map'}}, ()-> handler._createClusterer() markers = [] placeMarkers = (data, textStatus, jqXHR) -> handler.removeMarkers(markers); markers = handler.addMarkers(data) # <<--- here is the error $("#search_form").submit (e) -> valuesToSubmit = $(this).serialize $.ajax({ url: $(this).attr("action"), data: valuesToSubmit, success: placeMarkers, dataType: 'json' }) e.preventDefault $("#search_form").submit()

和控制器:

def index respond_to do |format| format.html {} format.json { seminars = Seminar.search(params[:search]) @markers = Gmaps4rails.build_markers(seminars) do |seminar, marker| return if seminar.location.is_a? String marker.lat seminar.location.lat marker.lng seminar.location.lon marker.infowindow render_to_string(:partial => 'seminars/seminar.html.haml', :locals => {seminar: seminar}) marker.title seminar.course.title marker.json({ :id => seminar.id }) end render json: @markers } end end

以及控制器的响应:

[{"lat":52.517,"lng":13.3889,"marker_title":"Title1","id":1}, {"lat":51.5114,"lng":7.46517,"marker_title":"Title2","id":3}]

这是堆栈跟踪

Gmaps.Objects.Handler.Handler.addMarker (application.js:22417) (anonymous function) (application.js:22409) _.map._.collect (application.js:21094) Gmaps.Objects.Handler.Handler.addMarkers (application.js:22408) placeMarkers (application.js:23263) jQuery.Callbacks.fire (application.js:3049) jQuery.Callbacks.self.fireWith (application.js:3161) done (application.js:8236) jQuery.ajaxTransport.send.callback (application.js:8779)

版本gmaps4rails-2.1.1

I receive the error this.clusterer is undefined. You can see my configuration below.

Expected behaviour: Load the Page, than AJAX-load the Markers from the controller using the query defined in #search_form. Finally add the markers to the #map and cluster them.

my js.coffee

$ -> handler = Gmaps.build('Google'); handler.buildMap { provider: {center: new google.maps.LatLng(49.639177, 9.536133),zoom: 6}, internal: {id: 'map'}}, ()-> handler._createClusterer() markers = [] placeMarkers = (data, textStatus, jqXHR) -> handler.removeMarkers(markers); markers = handler.addMarkers(data) # <<--- here is the error $("#search_form").submit (e) -> valuesToSubmit = $(this).serialize $.ajax({ url: $(this).attr("action"), data: valuesToSubmit, success: placeMarkers, dataType: 'json' }) e.preventDefault $("#search_form").submit()

And the Controller:

def index respond_to do |format| format.html {} format.json { seminars = Seminar.search(params[:search]) @markers = Gmaps4rails.build_markers(seminars) do |seminar, marker| return if seminar.location.is_a? String marker.lat seminar.location.lat marker.lng seminar.location.lon marker.infowindow render_to_string(:partial => 'seminars/seminar.html.haml', :locals => {seminar: seminar}) marker.title seminar.course.title marker.json({ :id => seminar.id }) end render json: @markers } end end

And the response from the controller:

[{"lat":52.517,"lng":13.3889,"marker_title":"Title1","id":1}, {"lat":51.5114,"lng":7.46517,"marker_title":"Title2","id":3}]

Here is the stacktrace

Gmaps.Objects.Handler.Handler.addMarker (application.js:22417) (anonymous function) (application.js:22409) _.map._.collect (application.js:21094) Gmaps.Objects.Handler.Handler.addMarkers (application.js:22408) placeMarkers (application.js:23263) jQuery.Callbacks.fire (application.js:3049) jQuery.Callbacks.self.fireWith (application.js:3161) done (application.js:8236) jQuery.ajaxTransport.send.callback (application.js:8779)

Version gmaps4rails-2.1.1

最满意答案

很奇怪,我再也无法重现了......

我认为更改是将$("#search_form").submit()到onMapLoad处理程序。

$ -> handler = Gmaps.build('Google'); handler.buildMap { provider: {center: new google.maps.LatLng(49.639177, 9.536133),zoom: 6}, internal: {id: 'map'}}, ()-> $("#search_form").submit()

谢谢您的提示@apneadiving

Very strange, I can't reproduce it any more...

I think the change was to add the $("#search_form").submit() to the onMapLoad handler.

$ -> handler = Gmaps.build('Google'); handler.buildMap { provider: {center: new google.maps.LatLng(49.639177, 9.536133),zoom: 6}, internal: {id: 'map'}}, ()-> $("#search_form").submit()

Thank you for your hint @apneadiving

更多推荐

本文发布于:2023-08-03 02:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1382889.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中未   定义   clusterer   gmaps4rails   addMarker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!