1

Been stuck on this for quite a while. I have an amcharts5 map in which I want to pre-zoom to a specific country and set it's state to active.

The zoom part was easy - polygonSeries.zoomToDataItem()

But I can't seem to understand how to set the state to active, in amchart4 it was straightforward (https://www.amcharts.com/docs/v4/tutorials/pre-zooming-map-to-a-country/#Highlighting_selected_country), but in amcharts5 ..

Thanks

2 Answers2

1

Got it!!!

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

9 - index of country

mc-user
  • 1,769
  • 4
  • 14
  • 25
1
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/

Foo Bar
  • 11
  • 2