I am trying to figure out how to obtain the coordinates on mouse click when rendering a 3D globe in Echarts. I am rendering a Lines3D series to designate geographical boundaries and a Scatter3D series that renders a marker at the centroid in a limited subset of those boundaries. This is being done within React using the echarts-for-react echarts wrapper
I am successfully using the convertFromPixel function documented here in the “geo” coordinate system in a 2d map to obtain latitude and longitude coordinates:
https://echarts.apache.org/en/api.html#echartsInstance.convertFromPixel
However that function returns this error message when the coordinate system is “globe”
convertFromPixel not supported for coordinate mode ‘globe’
Here is a code excerpt which binds the a click event to the map
const onChartClick = (params: { event: { zrX: number; zrY: number; }; }) => {
const coordinatePixelMode = 'globe'
const echartInstance = chartRef.current.getEchartsInstance();
const converted = echartInstance.convertFromPixel(coordinatePixelMode, [params.event.zrX, params.event.zrY]);
console.log(converted);
}
const echartInstance = chartRef.current.getEchartsInstance();
const zr = echartInstance.getZr();
zr.off('click')
zr.on('click', onChartClick);
The strange thing is that when tooltips are enabled on the ‘globe’ mode for the Scatter3D series, the tooltips contain the latitude and longitude of the Scatter3D data point which leads me to believe it must be possible to obtain the lat/lng coordinates on click.
Any ideas?
The expected result was convertFromPixel returns lat/lon when coordinateSystem is ‘globe’ but I can only get it to work for ‘geo’
EKcharts is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.