objectivehtml/Google-Maps-for-Craft

Keep map centred when browser window size changes

Closed this issue · 1 comments

What's the best way to make use of this solution, which keeps the map centred when the browser window size changes?

I know this is super old, but I ended up having some health issues and didn't work most of last year. I'm back now though and figured I would post the solution to this for future reference.

{% set options = {
    id: 'map', 
    width: '100%', 
    height: '100%',
    center: 'The Florida Keys'
} %}

{{ craft.googleMaps.map(options) }}

<script type="text/javascript">
    var mapCenter;

    window.onload = function() {
        mapCenter = map.getCenter();
    };

    window.onresize = function(e) {
        map.setCenter(mapCenter.lat(), mapCenter.lng());
    };

</script>