UK Regions in Google Geocharts

自闭症网瘾萝莉.ら 提交于 2020-01-01 19:09:12

问题


We are implementing Geo Chart heat Map for our website, but they have limitations to display regions for UK, they can list only 4 Regions only, England, Scotland, Wales and Northern Ireland and Not more than that. Can anyone help me to know if we can list all regions for UK and also if we can show cities, counties under those regions in UK as well like Preston etc.

Also can we pass more then 3 parameters to show more data on mouse over.

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

     var chart; 
     var data;
     var options;   

     google.setOnLoadCallback(drawRegionsMap);

      function drawRegionsMap() {
        data = google.visualization.arrayToDataTable([

          ['Region', 'Popularity', 'Total Votes'],


          ['England', 8, 6],
          ['Scotland', 8, 6],
          ['Wales ', 9, 7],
          ['Northern Ireland', 2, 5],

          ['United Kingdom', 2, 4]

        ]);

        var maxV = 5;  // to ensure scale is equal on both ends.
        var minV = maxV*-1;

        options =   { 
        colorAxis: {colors: ['blue', 'white', 'red'], minValue: minV, maxValue: maxV},
            };

        chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
        chart.draw(data, options);
    google.visualization.events.addListener(chart, 'regionClick', selectHandler);
    };

function selectHandler(e) {
    var selection = e['region'];
    //alert(selection);
        options['resolution'] = 'provinces';
        options['region'] = selection;
            chart.draw(data, options);
            document.getElementById('goback').style.display='block';
    };

    </script>

As you can see, only 3 parameters, can we pass extra parameters? or any tool tip for it.

thanks in advance


回答1:


Short answer: no you cannot display any more specific divisions than England, Wales, Scotland, and Northern Ireland.

Google Maps does not have any more specific maps currently available, so you aren't going to be able to map it using geocharts.

If you want to show cities, you could use the marker mode to display them. If you do want to show all the ISO-3166-2 regions for the UK your only choice is to create coordinates in marker mode for each of them, and then code them in as circles, not shaded regions.

As far as showing more tooltips is concerned, you can add a ToolTip column to display whatever your heart desires (caveat: no carriage returns allowed):

function drawVisualization() {
  data = new google.visualization.DataTable();
  data.addColumn('string', 'Region');
  data.addColumn('number', 'Popularity');
  data.addColumn('number', 'Total Votes');
  data.addColumn({type: 'string', role: 'tooltip'}, 'ToolTip');
  data.addRows([
    ['England', 8, 6, 'This is England'],
    ['Scotland', 8, 6, 'This is Scotland'],
    ['Wales ', 9, 7, 'This is Wales'],
    ['Northern Ireland', 2, 5, 'This is Northern Ireland'],
    ['United Kingdom', 2, 4, 'This is the UK']
  ]);

  var maxV = 5;  // to ensure scale is equal on both ends.
  var minV = maxV*-1;

  options =   {
    colorAxis: {colors: ['blue', 'white', 'red'], minValue: minV, maxValue: maxV},
  };

  chart = new google.visualization.GeoChart(document.getElementById('visualization'));
  chart.draw(data, options);
  google.visualization.events.addListener(chart, 'regionClick', selectHandler);
}

function selectHandler(e) {
  var selection = e['region'];
  //alert(selection);
  options['resolution'] = 'provinces';
  options['region'] = selection;
  chart.draw(data, options);
  //document.getElementById('goback').style.display='block';
};

In the future, HTML ToolTips will also likely be supported, but even in the experimental 1.1 version, they aren't currently enabled for geocharts.



来源:https://stackoverflow.com/questions/14723087/uk-regions-in-google-geocharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!