【问题标题】:How to locate/show the map continent wise in jvectormap如何在 jvectormap 中定位/显示地图大陆
【发布时间】:2013-09-11 08:13:42
【问题描述】:

我目前正在使用 jvector 地图,当我将鼠标悬停在每个国家/地区时,其默认标签会显示每个国家/地区的名称。但是,我想根据大陆选择(世界地图)选择地区。

例如:

默认是世界地图,

当我将鼠标悬停在国家(美国、加拿大、墨西哥、巴西、玻利维亚等)时,它会显示国家名称,但我想将标签显示为 美国 并且整个美洲地区也需要突出显示。

欧洲、亚洲大陆也是如此。

请帮助我实现这一目标。

提前致谢。

【问题讨论】:

    标签: javascript jquery map jvectormap


    【解决方案1】:

    试试这个

    var data = {
        "countries" : [
                   {
                   "name" : "Brazil",
                   "code" : "BR",
                   "pGdp" : "6938",
                   "cGdp" : "1313590",
                   "pop" : "196342587",
                   "continent" : "America"
                   },
                   {
                   "name" : "United States",
                   "code" : "US",
                   "pGdp" : "45845",
                   "cGdp" : "13843825",
                   "pop" : "303824646",
                   "continent" : "America"
                   }
                  ]
    }
    
    var countryData = [];
    
    jQuery.each(data.countries, function() {
        countryData[this.code] = this[.pGdp];
    });
    

    jvm 配置...

    series : {
        regions : [ {
            values : countryData,
            scale : [ '#C8EEFF', '#0071A4' ],
            normalizeFunction : 'polynomial'
        } ]
    },
    onRegionLabelShow: function(e, el, code) {
        //search through data to find the selected country by it's code
        var country = $.grep(data.countries, function(obj, index) {
        return obj.code == code;
        })[0]; //snag the first one
        if (country != undefined) {
            el.html(el.html() + "<br/><b>Code: </b>" +country.code + "<br/><b>Continent : </b> " + country.continent);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      相关资源
      最近更新 更多