简体   繁体   English

将鼠标悬停在地图上时,如何使地图的区域变色?

[英]How can I make the map's regions change color when hover the mouse over it?

I'm using the interactive map from codecanyon. 我正在使用来自codecanyon的交互式地图 I want to make a change so that the selected region changes color when the mouse is over it. 我要进行更改,以使所选区域在鼠标悬停在其上方时更改颜色。 I deployed an example where this is the code that does it. 我部署了一个示例 ,其中的代码就是这样做的。

<script type='text/javascript' src='http://www.google.com/jsapi'></script>
<script type='text/javascript'>google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawVisualization);

  function drawVisualization() {var data = new google.visualization.DataTable();

 data.addColumn('string', 'Country');
 data.addColumn('number', 'Value'); 
 data.addColumn({type:'string', role:'tooltip'});var ivalue = new Array();

 var options = {
 backgroundColor: {fill:'#FFFFFF',stroke:'#FFFFFF' ,strokeWidth:25 },
 colorAxis:  {minValue: 0, maxValue: 0,  colors: []},
 legend: 'none',    
 backgroundColor: {fill:'#FFFFFF',stroke:'#FFFFFF' ,strokeWidth:25 },   
 datalessRegionColor: '#ffc801',
 displayMode: 'regions', 
 enableRegionInteractivity: 'true', 
 resolution: 'provinces',
 sizeAxis: {minValue: 1, maxValue:1,minSize:10,  maxSize: 10},
 region:'IN',
 keepAspectRatio: true,
 width:600,
 height:400,
 tooltip: {textStyle: {color: '#444444'}, trigger:'focus', isHtml: false}   
 };
  var chart = new google.visualization.GeoChart(document.getElementById('visualization')); 
  google.visualization.events.addListener(chart, 'select', function() {
  var selection = chart.getSelection();
  if (selection.length == 1) {
  var selectedRow = selection[0].row;
  var selectedRegion = data.getValue(selectedRow, 0);
  if(ivalue[selectedRegion] != '') { document.location = ivalue[selectedRegion];  }
  }
  });
 chart.draw(data, options);
 }
 </script>
 <div id='visualization'></div>

Now I want the selected region to change color like in my mockup here. 现在,我希望选定的区域像在我的模型中一样更改颜色。 Can it be done? 能做到吗

在此处输入图片说明

Plnkr Example Plnkr示例

You can accomplish this with a css rule. 您可以使用CSS规则完成此操作。 The hover rule applies to all your paths and the rect rule excludes your ocean so that only the land areas will highlight as you indicated. 悬停规则适用于您的所有路径,而rect规则不包括您的海洋,因此只有陆地区域将按照您的指示突出显示。 Each rule is preceded by an ID selector to keep the rules only applicable to the div your map loaded within. 每个规则之前都有一个ID选择器,以使这些规则仅适用于您的地图所加载的div。

<style xmlns="http://www.w3.org/2000/svg">
    #visualization path:hover { fill: cornflowerblue; }
    #visualization rect:hover {fill:transparent;}
</style>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我使用鼠标 hover 使用 CSS 时,我试图让按钮中的文本更改颜色 - I am trying to make the text in a button change color when I hover over in with the mouse using CSS 当我对它们进行 hover 时,如何使我的 Material Icons 改变颜色? - How can I make my Material Icons change color when I hover over them? 鼠标悬停时如何更改段落文本? - How do I change a paragraph text when mouse hover over? 如何在此js中更改鼠标悬停时星星的颜色??? - how can i change the color of the stars on mouse hover in this js??? 为什么 <li> 元素悬停在图像上后将鼠标悬停在元素上时,颜色和宽度不会改变吗? - Why does the <li> element not change color and width when I hover the mouse over it after hovering over the image? 当鼠标悬停在按钮上时,禁用按钮颜色更改 - Disable button color change when mouse hover over button 将鼠标悬停在传单地图上时如何更改多边形的突出显示颜色 - How can I change the highlight color of a polygon when hover on Leaflet map 鼠标悬停时自定义地图/区域 - Custom map/regions on mouse over 如何在鼠标 hover 上做出反应 FontAwesomeIcon 不改变颜色 - How to make react FontAwesomeIcon not to change color on mouse hover 当我将鼠标悬停在文本上时,它会改变颜色并且颜色保持不变,我该如何做到这一点? - How do I make it so when I hover over my text it changes color and the color stays changed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM