javascript - 方法 zoomToMapObject(ev.target) 不会在 amCharts 中缩放到美国
问题描述
我正在使用 amCharts 显示世界地图,并且当用户单击一个国家/地区时,我有以下代码:
var groupData = [
{
"name": "America",
"color": "#7DB378",
"data": [{
"title": "USA",
"id": "US",
"customData": "Data 1"
}, {
"title": "Mexico",
"id": "MX",
"customData": "Data 2"
}]
},
{
"name": "Europe",
"color": "#1AE5B9",
"data": [{
"title": "Spain",
"id": "ES",
"customData": "Data 3"
}]
},
{
"name": "Asia",
"color": "#193387",
"data": [{
"title": "China",
"id": "CN",
"customData": "Data 4"
}]
}
];
var excludedCountries = ["AQ"]; // Exclude Antarctica
// Create a series for each group, and populate the above array
groupData.forEach(function (group) {
var series = chart.series.push(new am4maps.MapPolygonSeries());
series.name = group.name;
series.useGeodata = true;
var includedCountries = [];
group.data.forEach(function (country) {
includedCountries.push(country.id);
excludedCountries.push(country.id);
});
series.include = includedCountries;
series.fill = am4core.color(group.color);
series.setStateOnChildren = true;
var seriesHoverState = series.states.create("hover");
// Country shape properties & behaviors
var mapPolygonTemplate = series.mapPolygons.template;
// Events
mapPolygonTemplate.events.on("hit", function(ev) {
// zoom to an object
ev.target.series.chart.zoomToMapObject(ev.target);
});
});
此代码适用于除美国以外的所有国家/地区。单击它时,它不会缩放,只是将世界地图居中一点,仅此而已。为什么这只是未能放大美国?我究竟做错了什么?
解决方案
推荐阅读
- google-cloud-platform - GBQ:SchemaField REPEATED 模式写入空数组
- django - 跨模型实例共享 Django 字段
- android - Android Studio 相机显示像素化人脸而不是虚拟场景
- reactjs - 如何使用从 React.js 中的数据库检索的图像路径显示图像
- python-3.x - 如何使用熊猫清理坐标系的 CSV 文件?
- java - 无法从 spring boot .jar 读取文件
- html - 在 sass 中定义字体真棒内容时不显示
- sql - Db2/sql:使用连接选择和更新最旧的条目
- python - 为列表的总和获取大量小数位。所有列表项的小数点后均不超过 2 位。我究竟做错了什么?
- spring-boot - 在 Spring Boot 中挂钩以插入自己的 RabbitMQ 客户端?