gpt4 book ai didi

javascript - AmCharts 4 - drill map - 获取国家iso代码

转载 作者:行者123 更新时间:2023-11-30 11:08:21 25 4
gpt4 key购买 nike

我在 AmCharts 4 map 上开始了一个新项目。首先我选择一个大陆,然后我选择一个国家。

如何获取 iso_code 点击国家?

是否可以隐藏其他国家并仅在 map 上显示选定的国家?

我的代码:

  // Countries
var countriesSeries = chart.series.push(new am4maps.MapPolygonSeries());
var countries = countriesSeries.mapPolygons;
countriesSeries.visible = false; // start off as hidden
countriesSeries.exclude = ["AQ"];
countriesSeries.geodata = am4geodata_worldLow;
countriesSeries.useGeodata = true;
// Hide each country so we can fade them in
countriesSeries.events.once("inited", function(){
hideCountries();
});

var countryTemplate = countries.template;
countryTemplate.applyOnClones = true;
countryTemplate.fill = am4core.color("#a791b4");
countryTemplate.fillOpacity = 0.3;
countryTemplate.strokeOpacity = 0.3;
countryTemplate.tooltipText = "{name}";

countryTemplate.events.on("hit", function(event){
chart.zoomToMapObject(event.target);

// how can i get iso_code clicked country ?
// and hide other countries

showPoints(); // function show point on selected country
});

最佳答案

您可以使用 event.target.dataItem.dataContext.id 处理国家代码。

countryTemplate.events.on("hit", function(event){
chart.zoomToMapObject(event.target);
var countryCode = event.target.dataItem.dataContext.id;
// ...
});

要隐藏一些国家,您可以使用 countriesSeries.exclude,就像您在示例代码中所做的那样。或者你可以使用 countriesSeries.include 这显然是相反的。 (docs)。图表应该识别更改并重新呈现自己。但请记住,数组的更改不容易检测到,因此您应该重新分配 excludeinclude 属性。 ( docs )

polygonSeries.data = JSON.parse(JSON.stringify(dataArray));

或者您使用以下语法:

countriesSeries.include.push("DE");
countriesSeries.include = [...countriesSeries.include];

关于javascript - AmCharts 4 - drill map - 获取国家iso代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54773945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com