Adjust Zoom Gmaps4Rails

Gmaps4rails V2 - change default zoom

remove:

handler.fitMapToBounds();

Replace with:

handler.getMap().setZoom(yourValue);

Adjust Zoom Gmaps4Rails

You're simply missing that seeing the whole map means providing a very small number, not a big one!

<%= gmaps({
"map_options" => {"auto_adjust" => false, "zoom" => 0 },
"markers" => {"data" => @json }
})
%>

Zoom bar disfigured in Google-Maps-for-Rails (gmaps4rails)

Add this to your css... there you will also have an issue with the terrain and overlays dropdowns...

#mapCanvas label { width: auto; display:inline; }
#mapCanvas img { max-width: none; }

Changing zoom causes all hidden markers to re-appear on Google Map (Gmaps4rails)

Basically, when you use a clusterer, it stores all markers.

  • When you zoom out, it sets their map to null and adds cluster pics.

  • When you zoom in, it removes the cluster pic and sets the map again in the markers.

So when you do marker.setMap(null), it's not enough: you have to remove the markers from the clusterer too!

_.each markers, (marker, i) ->
marker.setMap(null)
handler.clusterer.removeMarker(marker)

But I also needed this scenario, so just do:

_.each markers, (marker, i) ->
handler.removeMarker(marker)

Or even:

handler.removeMarkers(markers)

gmaps4rails single marker auto zoom

Ok, the interface changed a lot since I posted the answer you quote.

<%= gmaps("markers" => {"data" => @json, "options" => {"auto_zoom" => false} }) %>

<% content_for :scripts do %>
<script type="text/javascript" charset="utf-8">
Gmaps.map.callback = function() {
if (Gmaps.map.markers.length == 1) {
//only one marker, choose the zoom level you expect
setTimeout(function() { Gmaps.map.serviceObject.setZoom(5);}, 50);
}
else{
//more than one marker, let's auto_zoom
Gmaps.map.map_options.auto_zoom = true;
Gmaps.map.adjustMapToBounds();
}
}
</script>
<% end %>

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

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>


Related Topics



Leave a reply



Submit