mirror of
https://github.com/aljazceru/twentyone-world.github.io.git
synced 2025-12-19 18:24:21 +01:00
refactor: DRY, isOrange func
This commit is contained in:
18
index.html
18
index.html
@@ -55,6 +55,9 @@ qtip: '/js/jquery.qtip.min.js'
|
|||||||
var orangeCountryCodes = orangeCountries.map(function(c) {
|
var orangeCountryCodes = orangeCountries.map(function(c) {
|
||||||
return c.alpha3;
|
return c.alpha3;
|
||||||
});
|
});
|
||||||
|
function isOrange(iso) {
|
||||||
|
return orangeCountryCodes.includes(iso);
|
||||||
|
}
|
||||||
|
|
||||||
map.addLayer('countries', {
|
map.addLayer('countries', {
|
||||||
title: function (d) { return d.name },
|
title: function (d) { return d.name },
|
||||||
@@ -63,10 +66,16 @@ qtip: '/js/jquery.qtip.min.js'
|
|||||||
fill: cGray
|
fill: cGray
|
||||||
},
|
},
|
||||||
mouseenter: function (d, path) {
|
mouseenter: function (d, path) {
|
||||||
path.attr('fill', Math.random() < 0.5 ? cDarkOrange : cDarkWhite );
|
if (!isOrange(d.iso)) {
|
||||||
|
path.attr('fill', Math.random() < 0.5 ? cDarkOrange : cDarkWhite );
|
||||||
|
}
|
||||||
|
return;
|
||||||
},
|
},
|
||||||
mouseleave: function (d, path) {
|
mouseleave: function (d, path) {
|
||||||
path.animate({ fill: pathColors[d.iso] }, 1000);
|
if (!isOrange(d.iso)) {
|
||||||
|
path.animate({ fill: pathColors[d.iso] }, 1000);
|
||||||
|
}
|
||||||
|
return;
|
||||||
},
|
},
|
||||||
click: function (d, path) {
|
click: function (d, path) {
|
||||||
let country = countries.find(c => c.alpha3 == d.iso);
|
let country = countries.find(c => c.alpha3 == d.iso);
|
||||||
@@ -79,9 +88,8 @@ qtip: '/js/jquery.qtip.min.js'
|
|||||||
});
|
});
|
||||||
|
|
||||||
map.getLayer('countries').style('fill', function (data) {
|
map.getLayer('countries').style('fill', function (data) {
|
||||||
var isOrangeCountry = orangeCountryCodes.includes(data.iso)
|
pathColors[data.iso] = isOrange(data.iso) ? cOrange : cGray;
|
||||||
pathColors[data.iso] = isOrangeCountry ? cOrange : cGray;
|
return pathColors[data.iso];
|
||||||
return isOrangeCountry ? cOrange : cGray;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user