apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.26k stars 382 forks source link

can't control zoom level in version 2.0.3 #403

Closed jobinthepast closed 10 years ago

jobinthepast commented 10 years ago

Hi,

I can't seem to figure out how to control the zoom level of the map while others options seem to work.

Here's my view:

        <script type="text/javascript">
          $(document).ready(function() {
            handler = Gmaps.build('Google', { markers: { maxRandomDistance: null }});
            handler.buildMap({ provider: { autoAdjust: false, autoZoom: false, zoom: 5, zoomControl: true, scrollwheel: false }, internal: {id: 'map'} }, function(){
              markers = handler.addMarkers(<%=raw @hash.to_json -%>);
              handler.bounds.extendWith(markers);
              handler.fitMapToBounds();
            });
          })
        </script>

the scrollwheel and maxZoom work. however autoAjust, autoZoom, zoom don't work.

any suggestions please?

Thanks.

apneadiving commented 10 years ago

autoAjust and autoZoom are not google maps options: https://developers.google.com/maps/documentation/javascript/reference?hl=fr#MapOptions

Zoom should be properly set, look here, the method is good: https://github.com/apneadiving/Google-Maps-for-Rails/blob/master/vendor/assets/javascripts/gmaps/google/builders/map.coffee#L10

apneadiving commented 10 years ago

I see:

if you do handler.fitMapToBounds();, well the map will be adjusted to the bounds, so your zoom wont be taken into account, pretty clear no?

You can do:

handler.fitMapToBounds();
handler.getMap().setZoom(5);
apneadiving commented 10 years ago

next time please ask question on stackoverflow

jobinthepast commented 10 years ago

Oh i'm sorry. Thank you!