AmCharts5 set active state on country

Viewed 82
2 Answers

Got it!!!

polygonSeries.mapPolygons.template._entities[9].set("active", true)

9 - index of country

let previousPolygon = null;

polygonSeries.mapPolygons.template.setAll({
  toggleKey: 'active',
});

polygonSeries.mapPolygons.template.on('active', (active, target) => {
  if (previousPolygon && previousPolygon !== target) {
    previousPolygon.set('active', false);
  }
  if (target.get('active')) {
    polygonSeries.zoomToDataItem(target.dataItem);
  } else {
    chart.goHome();
  }
  previousPolygon = target;
});

the code above allows to zoomIn/zoomOut onclick and toggle active state for target country https://www.amcharts.com/demos/zooming-to-countries-map/

Related