Gmaps4rails : Clustering not working? - ruby-on-rails

Since Gmaps4rails updated to 1.5 the clustering option has been set to false by default.
The documentation says that :do_clustering its the way to show clusters on flooding markers.
In code i´ve got:
<%= gmaps(:markers => {:data => #json}, :map_options => {:do_clustering => true}) %>
Edit: And of course it is supported
But clusters still not showing. Any thoughts?

Just realized:
You're passing do_clustering as a map option whereas it's a marker option.

Related

How to make a Chartkick Multipleseries

Hi I'm practically new on ruby on rails and having a hard time on making multipleseries on chartkick.
Based on :
http://chartkick.com/
Making Chartkick multipleseries is easy as :
<%= line_chart #goals.map{|goal|
{:name => goal.name, :data => goal.feats.group_by_week(:created_at).count }
} %>
but it seems to me is not working as it should since group_by deprecated in rails 4.
is there a way to produce the same effect like the code above?
thank you

Inverted Axis in AXLSX Bar Chart

I'm using this very straightforward code (practically the same as the bar chart examples here, however I am noticing that the Axes are inverted. The data that should be on the Val axis is shown on the Cat axis.
This is also true for the example linked above, and I can't seem to find a way to put them in the correct order.
Below is an image of the problem. The code used to generate it is:
sheet.add_chart(Axlsx::Bar3DChart,:title => "Chart", :show_legend => false, :start_at => "A1", :end_at => "P30", :bar_dir => :col) do |chart|
chart.add_series :data => sheet["B1:B25"], :labels => sheet["A1:A25"]
chart.valAxis.gridlines = false
chart.catAxis.gridlines = false
end
I fixed it. You can find my fork of axlsx here: https://github.com/HansCz/axlsx.
A pull request will be sent to https://github.com/randym/axlsx

Rails: gmaps4rails - Start the map location atlocation within the database

I dont think there is need for me to post specific code from my application.
In simple terms I have a db table with name,address,longitude,latitude,gmaps.
Each record stores a location. Okay. When I load the page, the google maps just starts off in the middle of the atlantic ocean, I was wondering is there a way for it to start off on one of my locations that I already have in my table?
Hey when you pass a record to the view you can use it to center the map.
<%= gmaps({
"map_options" => { "auto_adjust" => false, "center_longitude" => #record.long, "center_latitude" => #record.lat, "auto_zoom" => false, "zoom" => 5 },
"markers" => {"data" => #json }
})
%>
When you try this, make sure you have set auto_adjust to false.

How to add different type of markers in Gmaps4Rails

I need to show two different markers in my Google map. I am using rails 3 and Gmaps4rails gem.
I my controller I have
#marker1 = User.find(1)
#marker2 = User.find(2)
#json = [#marker1,#marker2].to_gmaps4rails
In view file
<%= gmaps({
"map_options" => { "zoom" => 12, "auto_adjust" => false, "center_latitude" => #marker1.lat, "center_longitude" => #marker1.lng},
"markers" => { "data" => #json }
})
%>
<%= yield :scripts %>
The map view I get is
I need to add different marker images for the each of them. How can this be done. please help.
I have simply one answer: it's explained in the wiki, within the Customize each marker section.
There is also some alternative to add the styles in a block from your controller instead of model level.

Google Maps, Ruby on Rails, Zoom level with one marker

I am adding google maps support with apneadiving / Google-Maps-for-Rails (thanks awesome gem)
I am finding one slight glitch, however, which very likely is my fault.
auto_zoom works great when there are multiple markers. However, when there is only one marker it is zoomed in to the max level which is not pretty.
"zoom" will only work when auto_zoom is false, so that's not what I want.
So therefore you could use "maxZoom" but now users cannot zoom in manually beyond that point which is not what I want.
Is there a way around this? Is my explanation making sense? Is this a limitation of Google Maps API?
Thanks...
This behavior is due to the auto_zoom built-in function in the google maps api.
One work around to this is to set it to false in the gmaps method:
<%= gmaps({
"map_options" => { "auto_zoom" => false},
"markers" => { "data" => #json }
})
%>
And then use the gmaps4rails_callback to fit your needs (be sure to have at least version 0.7.9)
<script type="text/javascript" charset="utf-8">
function gmaps4rails_callback() {
if (Gmaps4Rails.markers.length == 1) {
//only one marker, choose the zoom level you expect
Gmaps4Rails.map.setZoom(2);
}
else{
//more than one marker, let's auto_zoom
Gmaps4Rails.map_options.auto_zoom = true;
Gmaps4Rails.adjust_map_to_bounds();
}
}
</script>
I achieved this in a slightly different way as I know that I'll only ever have one marker on my map. I'm relatively new to rails, but this method feels a bit "cleaner" than using JS in your view.
I've got lat and lng stored in my model (encoded by geokit at time of creation), so did the following in my view:
<%= gmaps({
"map_options" => {"auto_zoom" => false, "zoom" => 15, "center_latitude" => #listing.lat, "center_longitude" => #listing.lng },
"markers" => {"data" => #markers }
})
%>
#markers is my JSON created by blah.to_gmaps4rails, and "listing" is my model.
thanks this helped me...
{"auto_zoom" => false, "zoom" => 15, "center_latitude" => #listing.lat, "center_longitude" => #listing.lng },
"markers" => {"data" => #markers }
})
%>

Resources