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

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

我正在使用 interactive map from codecanyon. I want to make a change so that the selected region changes color when the mouse is over it. I deployed an example,这是执行此操作的代码。

<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>

现在我希望所选区域像我这里的模型一样改变颜色。可以吗?

Plnkr Example

您可以使用 css 规则来完成此操作。 悬停规则适用于您的所有路径,而矩形规则不包括您的海洋,因此只有陆地区域会按照您的指示突出显示。 每条规则前面都有一个 ID 选择器,以确保规则仅适用于 div 您加载的地图。

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