score:2

Accepted answer

You could call all json functions in order, and have each callback trigger the init function. The init function would then have to count how many calls have been made and only once the count reaches the correct value, do the actual initialization.

d3.json('Cata_provincias.geojson', function(contents){
    provincias_json = contents
    init()
})
d3.json('Cata_girona.geojson', function(contents_girona){
    girona_json = contents_girona
    init()
})
d3.json('Cata_barcelona.geojson', function(contents_barcelona){
    barcelona_json = contents_barcelona
    init()
})
d3.json('Cata_tarragona.geojson', function(contents_tarragona){
    tarragona_json = contents_tarragona
    init()
})
d3.json('Cata_lleida.geojson', function(contents_lleida){
    lleida_json = contents_lleida
    init()
})

var count = 0
function init() {
    if(++count < 5)
        return

    // Do actual initialization here 
}

Related Query

More Query from same tag