Files
twentyone-world.github.io/index.html
2022-04-26 18:32:00 +02:00

106 lines
3.3 KiB
HTML

---
layout: map
title: Twentyone.World
jsplugins:
qtip: '/js/jquery.qtip.min.js'
---
<link rel="stylesheet" type="text/css" href="/css/jquery.qtip.css">
<script type="text/javascript" src="/js/jquery.qtip.min.js"></script>
<script type="text/javascript">
$(function () {
// Colors
const cOrange = '#F79621';
const cGray = '#333';
const cDarkGray = '#222';
const cDarkOrange = '#735000';
const cDarkWhite = '#BBB';
var pathColors = [];
// initialize tooltips
$.fn.qtip.defaults.style.classes = 'ui-tooltip-bootstrap';
$.fn.qtip.defaults.style.def = false;
var map = kartograph.map('#map');
map.loadMap('map/world.svg', function () {
map.addLayer('context', {
styles: {
stroke: '#aaa',
fill: '#f6f4f2'
}
});
map.addLayer('countries', {
id: 'bg',
styles: {
stroke: '#000',
'stroke-width': 6.15,
'stroke-linejoin': 'round'
}
});
$.ajax({
url: 'data/countries.json',
dataType: 'json',
success: function (countries) {
var orangeCountries = countries.filter(function hasLink(c) {
var hasLink = c.link ? true : false;
return hasLink;
});
var orangeCountryCodes = orangeCountries.map(function(c) {
return c.alpha3;
});
function isOrange(iso) {
return orangeCountryCodes.includes(iso);
}
map.addLayer('countries', {
title: function (d) { return d.name },
styles: {
stroke: cDarkGray,
fill: cGray
},
mouseenter: function (d, path) {
if (!isOrange(d.iso)) {
path.attr('fill', Math.random() < 0.5 ? cDarkOrange : cDarkWhite );
}
return;
},
mouseleave: function (d, path) {
if (!isOrange(d.iso)) {
path.animate({ fill: pathColors[d.iso] }, 1000);
}
return;
},
click: function (d, path) {
let country = countries.find(c => c.alpha3 == d.iso);
if (country.link) {
window.open(country.link);
} else {
window.open('/add');
}
}
});
map.getLayer('countries').style('fill', function (data) {
pathColors[data.iso] = isOrange(data.iso) ? cOrange : cGray;
return pathColors[data.iso];
});
}
});
}, { padding: -5 });
});
</script>
<div id="map" style="margin-bottom:1em">
</div>