这段代码使用Google Geomap API
绘制地图<script type="text/javascript">
google.setOnLoadCallback(drawMap);
function drawMap() {
var data = new google.visualization.DataTable();
data.addColumn('string','iso'); //e.g.: mx
data.addColumn('number','population'); //e.g.: 114
data.addRows([["mx",114],["ec",14],["ve",28]]);
var options = {
region: '005',
width: '511px',
height: '280px',
showLegend: true
};
var geomap = new google.visualization.GeoMap(document.getElementById('map'));
geomap.draw(data,options);
};
</script>
默认选择的区域是005(南美洲)。这些是其他可用区域:
如何以恐怖方式更改已绘制地图的区域?像这样:
<a href="javascript:void(null);" onclick="changeRegion(150);">Europe</a>
我知道地图必须重新绘制,但我有点陷入区域属性修改步骤。任何想法都会有所帮助谢谢!
答案 0 :(得分:1)
如果您已有数据,我会在自己的应用中为您提供一个代码段。我猜想更容易理解而不是长篇解释。希望能帮助到你。 就我而言,我想在同一地区按国家/地区显示数字。
geomap = new google.visualization.GeoMap(document.getElementById('geo_chart'));
google.visualization.events.addListener( geomap, 'regionClick',
function(e)
{
var dataLocal = new google.visualization.DataTable();
var grouped_cities;
if (e['region'] == "0")
return;
options['colors'] = [0xaacdf8, 0x164177]; //orange colors
options['dataMode'] = 'markers';
options['region'] = e['region'];
options['showZoomOut'] = true;
if ( previous_region != e['region'] )
{
var indexes = dataFull.getFilteredRows([{column: 0, value: e['region']}]);
dataLocal.addRows(indexes.length);
dataLocal.addColumn('string', 'City');
dataLocal.addColumn('number', 'Views');
for ( i=0; i<indexes.length; i++ )
{
dataLocal.setValue(i, 0, dataFull.getValue(indexes[i], 2));
dataLocal.setValue(i, 1, dataFull.getValue(indexes[i], 3));
}
grouped_cities = google.visualization.data.group( dataLocal, [0],[{'column': 1, 'aggregation': google.visualization.data.sum, 'type': 'number'}]);
previous_region = e['region'];
}
geomap.draw(grouped_cities, options);
delete grouped_cities;
delete dataLocal;
}
);