Files
twentyone-world.github.io/index.html
2022-04-26 17:46:05 +02:00

94 lines
2.8 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 = '#F2A900';
const cGray = '#333';
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'
}
});
map.addLayer('countries', {
title: function (d) { return d.name },
styles: {
stroke: '#222',
fill: cGray
},
mouseenter: function (d, path) {
path.attr('fill', Math.random() < 0.5 ? cDarkOrange : cDarkWhite );
},
mouseleave: function (d, path) {
path.animate({ fill: pathColors[d.iso] }, 1000);
},
click: function (d, path) {
console.log(d.iso);
}
});
$.ajax({
url: 'data/countries.json',
dataType: 'json',
success: function (countries) {
var scale = kartograph.scale.sqrt(countries.concat([{ nb_visits: 0 }]), 'nb_visits').range([0, 60]);
var orangeCountries = countries.filter(function hasLink(c) {
var hasLink = c.link ? true : false;
return hasLink;
});
map.getLayer('countries').style('fill', function (data) {
var orangeCountryCodes = orangeCountries.map(function(c) {
return c.alpha3;
});
var isOrangeCountry = orangeCountryCodes.includes(data.iso)
pathColors[data.iso] = isOrangeCountry ? cOrange : cGray;
return isOrangeCountry ? cOrange : cGray;
});
}
});
}, { padding: -5 });
});
</script>
<div id="map" style="margin-bottom:1em">
</div>
<p>Lorem ipsum, add your stuff.</p>