datamaps icon indicating copy to clipboard operation
datamaps copied to clipboard

Map doesn't resize responsively if Datamaps was obtained using JQuery

Open azertyfun opened this issue 7 years ago • 0 comments

The problem:

Using JQuery to load the Datamaps (as described in the readme):

var map = $("#container").datamaps({
    responsive: true
});

$(window).on('resize', function() {
    map.resize();
});

The map fills the window as expected, until the user resizes the window. At this point the map keeps its original size instead of resizing with the window.

Workaround

This is fixed by creating the Datamaps "classically":

var map = new Datamap({
    element: document.getElementById('container'),
    responsive: true
});


$(window).on('resize', function() {
    map.resize();
});

At which point the map resizes as expected.

Environment

I use a vanilla JS setup with JQuery 3.3.1, D3.js v3 and the latest topojson and datamaps:

        <script src="jquery-3.3.1.min.js"></script>
        <script src="https://d3js.org/d3.v3.min.js"></script>
        <script src="https://unpkg.com/topojson@3"></script>
        <script src="datamaps.world.min.js"></script>

My browser is Firefox 62.0.

azertyfun avatar Sep 18 '18 16:09 azertyfun