objectivehtml / Google-Maps-for-Craft

The complete geolocation toolkit for Craft CMS.
Other
94 stars 20 forks source link

Can't seem to set zoom #46

Closed andyharris closed 8 years ago

andyharris commented 9 years ago

Hi - I'm having real problems with the default zoom setting. My code looks like this:

        {% if entry.mapZoom %}
            {% set mapZoom = entry.mapZoom %}
        {% else %}
            {% set mapZoom = 17 %}
        {% endif %}

        {% set options = {
            id: 'map' ~ entry.id, 
            width: '100%', 
            height: '400px',

            options: {
                disableDoubleClickZoom: true,
                zoom: 4,
                zoomControlOptions: {
                    position: 'google.maps.ControlPosition.LEFT_CENTER',
                    style: 'google.maps.ZoomControlStyle.LARGE'
                }
            }
        } %}

        {{ craft.googleMaps.map(options) }}
        {{ craft.googleMaps.data('map' ~ entry.id, entry.map) }}

According to the Google docs, I should be able to pass a numerical zoom value in there, but this doesn't seem to work - it shows the full close up map regardless of what I put in there.

Ideally what I want to do is to pass in the mapZoom value which comes from the CMS, but if I use:

zoom: mapZoom

I get a console error of "Uncaught InvalidValueError: setZoom: not a number". This is less of a problem though if I can at least get the zoom working.

objectivehtml commented 8 years ago

I know this likely isn't an issue anymore, but I wanted to still back and address it incase others have the same issue. Hope all is well Andy! Sorry for the lack of replies dude. Had a rough year last year, but trying to come back from it.

{% set options = {
    id: 'map' ~ entry.id, 
    width: '100%', 
    height: '400px',

    options: {
        disableDoubleClickZoom: true,
        zoom: 4,
        zoomControlOptions: {
            position: 'google.maps.ControlPosition.LEFT_CENTER',
            style: 'google.maps.ZoomControlStyle.LARGE'
        }
    }
} %}

{{ craft.googleMaps.map(options) }}
{{ craft.googleMaps.zoom('map' ~ entry.id, mapZoom) }}
{{ craft.googleMaps.center('map' ~ entry.id, entry.map.markers[0].lat, entry.map.markers[0].lng) }}

{{ craft.googleMaps.data('map' ~ entry.id, entry.map, {
    fitBounds: false
}) }}

The premise behind the fix is to set fitBounds to false, and instead define your own bounds (a zoom and map center).

andyharris commented 8 years ago

Thanks Justin, I had managed to get it working - typically the site I wanted it for STILL hasn't launched. Gotta love web dev.

I'm good, hope you're well and here's for a better year!