const ANNOTATIONS = {
points: [
{
at: [-77.04, -12.05],
label: { text: 'Humboldt current\nupwelling', position: 'left' },
marker: { shape: 'pin', size: 12 },
connector: true,
},
{
at: [139.7, 35.7],
label: { text: 'Tokyo', background: 'none' },
marker: { shape: 'circle', size: 7 },
},
{
at: [31.24, 30.04],
label: { text: 'Nile delta', position: 'right' },
marker: { shape: 'diamond', size: 9 },
connector: { dashArray: '2 2' },
},
],
features: [
{
key: 'IND',
label: { text: 'Fastest-growing\nof the ten largest', position: 'bottom' },
outline: true,
},
{
key: 'BRA',
label: 'Amazon basin',
outline: { color: '#00E396', width: 2, dashArray: '5 3' },
},
],
areas: [
{
bounds: [-20, 10, 40, 30],
label: 'The Sahel',
fill: '#FEB019',
fillOpacity: 0.16,
stroke: { color: '#FEB019', width: 1.5, dashArray: '4 3' },
},
],
}
const data = [
{ name: 'Peru', value: 41 }, { name: 'Japan', value: 80 }, { name: 'Egypt', value: 48 },
{ name: 'India', value: 66 }, { name: 'Brazil', value: 72 }, { name: 'Chad', value: 22 },
{ name: 'Nigeria', value: 55 }, { name: 'France', value: 77 }, { name: 'China', value: 71 },
]
const map = new ApexMaps(document.getElementById('map'), {
chart: { height: 520 },
geo: { map: 'world/countries@110m' },
dataLabels: { enabled: false, minFeatureArea: 400 },
annotations: ANNOTATIONS,
series: [
{ type: 'choropleth', name: 'Illustrative index', joinBy: 'name', data, scale: { palette: 'blues', classes: 5 } },
],
})
map.render()
let labelsOn = false
document.getElementById('toggle-labels').addEventListener('click', async () => {
labelsOn = !labelsOn
await map.updateOptions({ dataLabels: { enabled: labelsOn } })
console.log(`${map.labels.placedCount} labels placed, ${map.labels.droppedCount} dropped`)
})
let annotationsOn = true
document.getElementById('toggle-annotations').addEventListener('click', async () => {
annotationsOn = !annotationsOn
await map.updateOptions({
annotations: annotationsOn ? ANNOTATIONS : { points: [], features: [], areas: [] },
})
console.log(`${map.annotations.count} annotation(s)`)
})