highlight continent with mouseover using Google Vi

2019-09-20 11:27发布

问题:

I have following code and I expect that when I have mouseover that a continent it should highlight that continent: I tried this code but I did not got that working

google.maps.event.addListener(map,'mouseover',function(e){

            google.load('visualization', '1', {'packages': ['geochart']});
            google.setOnLoadCallback(drawRegionsMap);

      function drawRegionsMap() {
        var data = google.visualization.arrayToDataTable([
          ['Country', 'Popularity'],
          ['Germany', 200],
          ['United States', 300],
          ['Brazil', 400],
          ['Canada', 500],
          ['France', 600],
          ['RU', 700]
        ]);

         var options = {colors:['#002e5f','#CCCCCC']}; 

        var chart = new google.visualization.GeoChart(document.getElementById('googleMap'));
        chart.draw(data, options);
    };

回答1:

In order to highlight continents, you will have to set the resolution option to 'continents'. This is incompatible with using country-level data, however.



回答2:

This code should help:

google.setOnLoadCallback(drawRegionsMap);

function drawRegionsMap() {

  var data = google.visualization.arrayToDataTable([
      ['Region Code', 'Continent', 'Popularity'],
      ['142', 'Asia', 200],
      ['150', 'Europe', 300],
      ['019', 'Americas', 400],
      ['009', 'Oceania', 600],
      ['002', 'Africa', 700]
  ]);

  var options = {
      resolution: 'continents'
  };

  var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));

  chart.draw(data, options);
}