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

AmCharts 4 - drill map - get country iso code

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

如何获得iso_code点击的国家?

是否可以隐藏其他国家并在地图上仅显示 selected?

我的代码:

  // 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). The chart should recognize changes and rerender itself. But bare in mind, that changes on an array are not easy to detect, so you should reassign the exclude or include property. (docs)

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

或者您使用以下语法:

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