javascript - Jvectormap highlight Multiple countries -


i using jvectormap , trying highlight multiple countries when hovering on text, have gotten point if hover on word africa, highlight entire map, how filter highlight africa when hovering on content name of africa.

currently creating list of continents using jquery.each , returning continentcodes, contains of country codes (za, us) color assigned them... have tried doing 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 repeating each statement , can not dynamic continents.

here jsfiddle

so heres js:

jquery(function(){ //json markers var markers = [{latlng: [-34.033333300000000000, 23.066666700000040000], name: 'knysna', info:'its got lake...'},     {latlng: [-33.924868500000000000, 18.424055299999963000], name: 'cape town', info:'its nice...'}]; //json markers    //json styling var markerstyle = {initial: {fill: '#f8e23b',stroke: '#383f47'}}; var regionstyling = {initial: {fill: '#128da7'},hover: {fill: "#a0d1dc"}}; //json styling  //global variables var countrylist = "", continentlist = ""; var continentcodes = {}; //global variables  //init map plugin 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);     } }); //init map plugin  var mapobject  = jquery('#world-map').vectormap('get', 'mapobject');  //list countries & continents function createlist() {      //get list     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;     });     //display continents     jquery('#continentlist').html(continentlist);      //display countries     jquery('#countrylist').html(countrylist);      //create hover function     jquery('.continentlink').hover(function() {         mapobject.series.regions[0].setvalues(continentcodes);         console.log(continentcodes);     });      //create zoom function     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> 

i have restructured code, please see jsfiddle , here corrected javascript:

jquery(function(){ //json markers var markers = [{latlng: [-34.033333300000000000, 23.066666700000040000], name: 'knysna', info:'its got lake...'},     {latlng: [-33.924868500000000000, 18.424055299999963000], name: 'cape town', info:'its nice...'}]; //json markers    //json styling var markerstyle = {initial: {fill: '#f8e23b',stroke: '#383f47'}}; var regionstyling = {initial: {fill: '#128da7'},hover: {fill: "#a0d1dc"}}; //json styling  //global variables var countrylist = "", continentlist = ""; var resultsdup = {}; var continentcodes = {}; //global variables  //init map plugin 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);     } }); //init map plugin  var mapobject  = jquery('#world-map').vectormap('get', 'mapobject');  //list countries & continents jquery.each(mapobject.mapdata.paths, function(i, val) {      countrylist += '<li><a id='+i+' class="countrylink">'+val.name+'</a></li>';      //remove duplicate continents     var resultslist = val.continent;     if (resultsdup[resultslist]) {         jquery(this).remove();     }else{         resultsdup[resultslist] = true;         continentlist += '<li><a id='+val.continent+' class="continentlink">'+val.continent+'</a></li>';     }     //remove duplicate continents   }); //display countries jquery('#countrylist').html(countrylist);  //display continents jquery('#continentlist').html(continentlist);  var continentid ="" function getid(continentid){     jquery.each(mapobject.mapdata.paths, function(i, val) {             if (val.continent == continentid){                 continentcodes[i] = "#3e9d01";                 mapobject.series.regions[0].setvalues(continentcodes);             }     }); }  function removegetid(continentid){     jquery.each(mapobject.mapdata.paths, function(i, val) {             if (val.continent == continentid){                 continentcodes[i] = "#128da7";                 mapobject.series.regions[0].setvalues(continentcodes);             }     }); }  //list countries & continents temp jquery('.continentlink').hover(function(e) {     continentid = this.id;     getid(continentid); }, function(){     removegetid(continentid); });  //zoom country function jquery('.countrylink').click(function(e) {     jquery('#world-map').vectormap('set', 'focus', this.id); });  //continent hover function  }); 

enjoy :d


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -