import * as am5 from "@amcharts/amcharts5"; import * as am5map from "@amcharts/amcharts5/map"; import am5geodata_worldLow from "@amcharts/amcharts5-geodata/worldLow"; import am5themes_Animated from "@amcharts/amcharts5/themes/Animated"; import am5themes_ResponsiveMax from "@amcharts/amcharts5/themes/ResponsiveMax"; // Create root element // https://docs.amcharts.com/v5/getting-started/#root-element const root = am5.Root.new("chartdiv"); // Set themes // https://docs.amcharts.com/v5/concepts/themes/ root.setThemes([ am5themes_Animated.new(root), am5themes_ResponsiveMax.new(root) // fits the chart to small screens ]); // Create chart // https://docs.amcharts.com/v5/charts/map-chart/ const chart = root.container.children.push(am5map.MapChart.new(root, { projection: am5map.geoOrthographic(), // a globe panX: "rotateX", // dragging sideways spins the globe... panY: "rotateY" // ...and dragging up or down tilts it })); // Add globe background // https://docs.amcharts.com/v5/charts/map-chart/map-polygon-series/#background-polygon const backgroundSeries = chart.series.push(am5map.MapPolygonSeries.new(root, {})); backgroundSeries.mapPolygons.template.setAll({ fill: root.interfaceColors.get("alternativeBackground"), // black on a light theme... fillOpacity: 0.06, // ...but barely there: a faint disc for the sea strokeOpacity: 0 // no outline }); backgroundSeries.data.push({ geometry: am5map.getGeoRectangle(90, 180, -90, -180) // one polygon over the whole earth }); // Add countries // https://docs.amcharts.com/v5/charts/map-chart/map-polygon-series/ chart.series.push(am5map.MapPolygonSeries.new(root, { geoJSON: am5geodata_worldLow })); // Add points: bullets lie on the surface and flatten towards the edge // https://docs.amcharts.com/v5/charts/map-chart/map-point-series/ const pointSeries = chart.series.push(am5map.MapPointSeries.new(root, { surfaceBullets: true, // the pins turn and squash with the globe, as if painted on it latitudeField: "latitude", longitudeField: "longitude" })); // A pin, drawn with its tip at the point pointSeries.bullets.push(() => { return am5.Bullet.new(root, { sprite: am5.Graphics.new(root, { svgPath: "M0,0 C-5,-7 -9,-11 -9,-17 A9,9 0 1 1 9,-17 C9,-11 5,-7 0,0 Z M0,-20.5 A3.5,3.5 0 1 0 0,-13.5 A3.5,3.5 0 1 0 0,-20.5 Z", fill: am5.color(0xff621f), stroke: root.interfaceColors.get("background"), // a thin outline in the background color strokeWidth: 1, tooltipText: "{title}", // the city's name from the data // keyboard: one Tab stop for all the cities, the up and down arrow keys step through them. No tooltip // on focus: on a pin lying on the globe it shows away from it focusable: true, focusableGroup: "cities", ariaLabel: "{title}" }) }); }); // Set data pointSeries.data.setAll([ { title: "New York", latitude: 40.7128, longitude: -74.006 }, { title: "Mexico City", latitude: 19.4326, longitude: -99.1332 }, { title: "Sao Paulo", latitude: -23.5505, longitude: -46.6333 }, { title: "Reykjavik", latitude: 64.1466, longitude: -21.9426 }, { title: "London", latitude: 51.5072, longitude: -0.1276 }, { title: "Lagos", latitude: 6.5244, longitude: 3.3792 }, { title: "Cape Town", latitude: -33.9249, longitude: 18.4241 }, { title: "Cairo", latitude: 30.0444, longitude: 31.2357 }, { title: "Moscow", latitude: 55.7558, longitude: 37.6173 }, { title: "Delhi", latitude: 28.6139, longitude: 77.209 }, { title: "Tokyo", latitude: 35.6895, longitude: 139.6917 }, { title: "Sydney", latitude: -33.8688, longitude: 151.2093 }, ]); // Accessibility: keyboard and screen reader support // https://docs.amcharts.com/v5/concepts/accessibility/ chart.setAll({ focusable: true, // Tab reaches the globe, and a screen reader names it ariaLabel: "Globe with twelve city pins that lie flat on its surface. Tab to the cities, then move between them with the up and down arrow keys" }); // the cities: set up in their bullet function above // Make stuff animate on load // https://docs.amcharts.com/v5/concepts/animations/#forcing-appearance-animation chart.appear(1000, 100);