Jvectormap突出显示多个国家

2024-03-11

我目前正在使用J向量图 http://jvectormap.com/并试图在将鼠标悬停在文本上时突出显示多个国家,我已经达到了这样的程度:如果我将鼠标悬停在“非洲”一词上,它将突出显示整个地图,当我将鼠标悬停在内容上时,我将如何过滤它以仅突出显示非洲非洲的名称。

目前我正在使用创建一个大陆列表jQuery.each我回来了continentCodes,其中包含所有国家/地区代码(ZA、US)并为其分配了颜色...我尝试执行以下操作:

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);
  }
 });
});

但后来我重复每个陈述,但我无法获得动态大陆。

这里有一个JSFIDDLE http://jsfiddle.net/dawidvdh/EpGep/8/

JS 如下:

jQuery(function(){
//JSON MARKERS
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...'}];
//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();
});

和 HTML:

  <div id="world-map" style="width: 960px; height: 400px"></div>
    <div id="infobox"></div>
        <ul id="continentList"></ul>
        <ul id="countryList"></ul>

我已经重组了你的代码,请参阅JSFIDDLE http://jsfiddle.net/dawidvdh/EpGep/10/这是更正后的 JavaScript:

jQuery(function(){
//JSON MARKERS
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...'}];
//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 to Country Function
jQuery('.countryLink').click(function(e) {
    jQuery('#world-map').vectorMap('set', 'focus', this.id);
});

//Continent Hover function

});

Enjoy :D

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Jvectormap突出显示多个国家 的相关文章

随机推荐

  • 动态加载用户控件 ASP.net 中的单选选项 GroupName 问题

    我有用户控制 table tr td td tr table
  • 如何自定义FirebaseUI-Web主题

    我只想定制徽标和颜色 有谁知道解决方案吗 我只看到了安卓的解决方案 下面的代码 if process browser const firebaseui require firebaseui console log firebaseui co
  • (python) Telegram bot - 如何定期发送消息?

    我对我的电报机器人感到左右为难 假设我必须创建一个函数 每周 每月一次向每个连接到机器人的用户询问一个问题 def check the week bot update reply keyboard YES NO bot send messa
  • 可以在没有 Visual Studio 的情况下安装 Roslyn 最终用户预览版吗?

    Roslyn 最终用户预览是 VSIX Visual Studio 扩展 但它取代了系统 NET Framework 安装中的编译器 这样从命令行涉及 csc exe 将开始使用 Roslyn 是否可以在未安装 Visual Studio
  • 为什么 C# 不需要显式转换来将 Long 转换为 Double?

    首先 抱歉我的英语不好 我有代码片段 long x 9223372036854775807L double f x Console WriteLine x Console WriteLine f 输出是 922337203685477580
  • 如何使用 xmlrpclib Python 库向 WordPress 帖子添加缩略图?

    我正在尝试开发一个Python脚本 它需要将内容发布到wordpress博客 问题是我需要将图像设置为帖子的缩略图 但我不知道如何做到这一点 这是将某些内容 没有缩略图 发布到 WP 的代码示例 import xmlrpclib user
  • 如何将带有 mtl 和纹理的 obj 上传到存储桶?

    正如标题所示 如何上传 obj 模型的材质文件和纹理 因为它们是硬编码在 obj 文件中的 我可以上传压缩的目录结构或多个关系正确的文件 因为 obj 的硬编码性质 吗 这是 dotty 试用网站上的带有材质和纹理的 OBJ 模型 http
  • 保持 OAuth 访问令牌的秘密有多重要?

    一旦我收到使用 OAuth 的网站 例如 facebook 的访问令牌 保守这个秘密有多重要 如果有人掌握了它 会发生什么恶意的事情吗 我想知道将令牌保存在 cookie 或会话中是否是一个坏主意 是的 访问令牌相当于您的用户名 密码 大多
  • SYMPY:特征向量计算后如何细化整个矩阵?

    我想使用 sympy 来计算特征向量 我用 jupyter 笔记本做了一些试验 from sympy import a b symbols a b real True M Matrix a b b a T D M diagonalize n
  • 使用没有会话或 cookie 数据的 iFrame(隐身)

    如果您使用iFrameHTML 文档中的元素 子页面将加载来自浏览器的所有会话和 cookie 数据 例如 h1 Stack Overflow in an iFrame h1 暂时忽略 SO 实际上不允许自己加载到 iFrame 中 如果是
  • 将 csv 文件添加到 HTTP POST

    我想发送一个邮递员 HTTP POST 在此请求中 对于关键 fisier 我想附加一个 csv 文件 如何做到这一点 https i stack imgur com Pnkii png https i stack imgur com Pn
  • 通过 websockets 发送 popen 的输出

    我使用 popen 和 fgets 异步读取 tcpdump 的输出 下面的代码应该在命令行中运行 而不是使用 apache 并在浏览器中查看它 handle popen tcpdump nnX r while true output fg
  • CSS:在绝对定位的div之后有一个div

    我想知道如何做到这一点 我当前的标记如下 div div class widget style width 313px height 269px Hello div div class widget style width 80px hei
  • Kotlin 用于基于 Cordova/Ionic 的插件

    是否可以使用 Kotlin 作为框架 语言作为 Cordova 插件 第一个问题是它没有复制 kt 文件 因为它查找 java 或 xml 如果是这样 有人知道如何设置的参考吗 最近我一直在 Cordova 插件中使用 Kotlin 但是当
  • 可以使用webpack分别生成CSS和JS吗?

    I have 我想要捆绑的 JS 文件 我想要编译为 CSS 的 LESS 文件 将 imports 解析为单个包 我希望将它们指定为两个单独的输入并具有两个单独的输出 可能通过 extract text webpack plugin We
  • 如何在netbeans中运行php文件

    我创建了一个扩展名为 php 的文件 那么我应该如何使用 netbeans 运行这个文件 我已经下载了带有所有捆绑功能的 netbeans 6 8 我已经看到 php 文件可以与 netbeans 一起运行 所以我想问一下 请解释一下 运行
  • SQL 中的多个 LIKE 语句

    我有一个包含有关零售商店信息的表 我有一个零售连锁店名称列表 沃尔玛 塔吉特 伊顿等 当用户选择一个时 我基本上会运行一个查询来查找与该连锁店有关的任何信息 SELECT FROM stores WHERE store name LIKE
  • 如何使用 dotnet test 命令发布结果

    我有一个用 dotnet core 编写的测试项目 这需要以 XML 或 HTML 格式发布结果 有没有办法使用相同的命令将结果发布到特定目录 result directory不适合我 你可以看到所有dotnet test通过执行选项dot
  • 在嵌入式 vimeo 播放器上添加覆盖层

    这是我嵌入到我的网站中的视频 Fiddle https jsfiddle net hgtvqatm 问题是 它很小 并且播放和其他按钮覆盖了半个屏幕 那么有什么方法可以在播放器上添加图层图像 当您单击该图像时 视频应该开始播放 http c
  • Jvectormap突出显示多个国家

    我目前正在使用J向量图 http jvectormap com 并试图在将鼠标悬停在文本上时突出显示多个国家 我已经达到了这样的程度 如果我将鼠标悬停在 非洲 一词上 它将突出显示整个地图 当我将鼠标悬停在内容上时 我将如何过滤它以仅突出显