Highmaps / highcharts 是一个 javascript/jquery 适配器,可以在浏览器等中呈现地图。
我有一张突出显示单个国家的地图,但是,(世界)地图的比例是这样的,我想在地图加载到相关国家后放大。
看着 API,我确信这是可能的。
有一个事件监听器,这样我就可以在加载时执行自定义函数。如本例所示,在加载时添加了一个系列(Js fiddle)
此外,还有一种方法mapZoom
允许您使用以下参数指定要缩放到的点:
mapZoom (Number howMuch, [Number centerX], [Number centerY], [Number mouseX], [Number mouseY])
但是当我尝试调用这个方法 onload (我的代码在下面尝试,JS fiddle here)时,什么也没有发生。
$(function () {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=world-population-density.json&callback=?', function (data) {
// Assign id's
$.each(data, function () {
this.id = this.code;
});
// Initiate the chart
$('#container').highcharts('Map', {
chart: {
events: {
load: function () {
mapZoom(0.5, 100, 100);
}
}
},
title: {
text: 'Zoom on load attempt'
},
legend: {
title: {
text: 'Population density per km²'
}
},
colorAxis: {
min: 1,
max: 1000,
type: 'logarithmic'
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'bottom'
}
},
series : [{
data : data,
mapData: Highcharts.maps['custom/world-highres'],
joinBy: ['iso-a2', 'code'],
name: 'Population density',
allowPointSelect: true,
cursor: 'pointer',
states: {
hover: {
color: '#BADA55'
}
},
tooltip: {
pointFormat: '{point.id} {point.name}',
valueSuffix: '/km²'
}
}]
});
});
});