I am currently using JvectorMap and trying to highlight several countries when I hover over the text, I got it to the extent that if I hover over the word Africa, it will highlight the whole map, as if I would filter it to select only Africa when I'm soaring for the content of the name of Africa.
I am currently creating a list of continents using jQuery.each, and I am returning continentCodes, which contains all the country codes (ZA, US) with the color assigned to them ... I tried to do the following:
jQuery('.continentLink').hover(function() {
jQuery.each(mapObject.mapData.paths, function(i, val) {
if (val.continent == "africa"){
continentCodes[i] = "#3e9d01";
mapObject.series.regions[0].setValues(continentCodes);
}
});
});
but then I repeat every statement, and I can’t get dynamic continents.
Here is JSFIDDLE
So Heres the JS:
jQuery(function(){
var markers = [{latLng: [-34.033333300000000000, 23.066666700000040000], name: 'Knysna', info:'its got a lake...'},
{latLng: [-33.924868500000000000, 18.424055299999963000], name: 'Cape Town', info:'its nice...'}];
var markerStyle = {initial: {fill: '#F8E23B',stroke: '#383f47'}};
var regionStyling = {initial: {fill: '#128da7'},hover: {fill: "#A0D1DC"}};
var countryList = "", continentList = "";
var continentCodes = {};
jQuery('#world-map').vectorMap({
map: 'world_mill_en',
normalizeFunction: 'polynomial',
markerStyle:markerStyle,
regionStyle:regionStyling,
backgroundColor: '#383f47',
series: {regions: [{values: {},attribute: 'fill'}]},
markers: markers,
onRegionClick:function (event, code){
jQuery('#world-map').vectorMap('set', 'focus', code);
},
onMarkerClick: function(events, index){
jQuery('#infobox').html(markers[index].name);
}
});
var mapObject = jQuery('#world-map').vectorMap('get', 'mapObject');
function createList() {
jQuery.each(mapObject.mapData.paths, function(i, val) {
countryList += '<li><a id='+i+' class="countryLink">'+val.name+'</a></li>';
continentList += '<li><a id='+val.continent+' class="continentLink">'+val.continent+'</a></li>';
continentCodes[i] = "#3e9d01";
return continentCodes;
});
jQuery('#continentList').html(continentList);
jQuery('#countryList').html(countryList);
jQuery('.continentLink').hover(function() {
mapObject.series.regions[0].setValues(continentCodes);
console.log(continentCodes);
});
jQuery('.countryLink').click(function(e) {
jQuery('#world-map').vectorMap('set', 'focus', this.id);
});
}
createList();
});
and HTML:
<div id="world-map" style="width: 960px; height: 400px"></div>
<div id="infobox"></div>
<ul id="continentList"></ul>
<ul id="countryList"></ul>