简体   繁体   English

Gmaps4rails:通过AJAX添加标记后启用集群的正确方法是什么?

[英]Gmaps4rails: What's the proper way to enable clustering after adding markers via AJAX?

I tried to search the answer from docs, but couldn't find.. 我试图从文档中搜索答案,但是找不到。

How can I enable clustering in Gmaps4rails when I add markers on the map via AJAX. 通过AJAX在地图上添加标记时,如何在Gmaps4rails中启用群集。 My view has this: 我的看法是这样的:

<%= gmaps( map_options: { zoom: 15, auto_adjust: false } ) %>

and in my javascript I add the markers like this: 并在我的JavaScript中添加如下标记:

     $.getJSON(path, { lat: lat, lng: lng, user_lat: user_lat, user_lng: user_lng }, function(markers_json) {
        Gmaps.map.replaceMarkers(markers_json); 
     });

I'd just like to set the do_clustering option to true, but because I don't have markers json in the map gmaps() call, I can't add the markers options either. 我只想将do_clustering选项设置为true,但是因为在地图gmaps()调用中没有标记json,所以我也无法添加标记选项。

Tell gmaps4rails directly: 直接告诉gmaps4rails

Gmaps.map.markers_conf.do_clustering = true;

And include this script: 并包括以下脚本:

<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.9/src/markerclusterer_packed.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM