Highlight country flag on blank world map when hovered on specific country

微笑、不失礼 提交于 2019-12-10 17:22:43

问题


I'm using jVectormap plugin for country highlighting on world map. Now As my question suggests i want to show country's flag when specific country is hovered over.

I don't want to do image mapping for whole world map. so don't post that solution, i don't think its a feasible solution as i don't have such time to do that.

if anybody has done this functionality using any plugin, svg, google maps, js anything please help me out.

If any paid plugin is there even then i would like to know. I have searched for 2 days. But i haven't come across such functionality yet.


回答1:


You can provide a function for onRegionLabelShow that uses the region code to construct a URL for the country flag and then customize the label.

$(function() {
    $('#map').vectorMap({
        onRegionLabelShow: function(event, label, code)
        {
           label.html(label.html()+
           '<br><img src="'+getFlagImgSrc(code)+'" height="20">');
        }
    });

    /*
    * Constructs a URL for a country flag image on Flags Of The World 
    * using the ISO-3166 Digraph 
    */
    function getFlagImgSrc(code)
    {
       return 'http://www.fotw.us/images/'+
               code.toLowerCase().substring(0,1)+
               '/'+
               code.toLowerCase()+
               '.gif';  
    }    

});​

An example of how the rendered label looks with the country flag when you mouse over a region:



来源:https://stackoverflow.com/questions/10052519/highlight-country-flag-on-blank-world-map-when-hovered-on-specific-country

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!