This page is a work in progress. Please bear with us while we're working on this content.
This tutorial will look at various API functions that can be used with a MapChart
.
Converting between screen and geographical coordinates
A map chart has two methods that can be used to convert screen coordinates to longitude/latitude and back:
- invert() - converts screen coordinates to latitude/longitude.
- convert() - converts latitude/longitude to screen coordinates.
The following code will capture click on a map chart and use point
(which holds screen coordinates) to retrieve latitude/longitude of the click place.
chart.events.on("click", function(ev) { console.log(chart.invert(ev.point)) });
chart.events.on("click", function(ev) { console.log(chart.invert(ev.point)) });
Similarly, if we need to convert geographical coordinates to an X/Y coordinate within the map chart area, we can use convert()
method:
console.log("NYC", chart.convert({ latitude: 40.712776, longitude: -74.005974 }));
console.log("NYC", chart.convert({ latitude: 40.712776, longitude: -74.005974 }));
See the Pen
Retrieving lat/long coordinates of a map click by amCharts team (@amcharts)
on CodePen.0