apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.58k stars 19.62k forks source link

[Bug] convertFromPixel在'geo'上使用时,返回值出错 #16771

Open Jalor-Lv opened 2 years ago

Jalor-Lv commented 2 years ago

Version

5.3.0

Link to Minimal Reproduction

https://echarts.apache.org/examples/zh/editor.html?c=map-usa-projection&version=5.3.0

Steps to Reproduce

myChart.showLoading();
$.when(
  $.get(ROOT_PATH + '/data/asset/geo/USA.json'),
  $.getScript('https://cdn.jsdelivr.net/npm/d3-array'),
  $.getScript('https://cdn.jsdelivr.net/npm/d3-geo')
).done(function (res) {
  const usaJson = res[0];
  const projection = d3.geoAlbersUsa();
  myChart.hideLoading();
  echarts.registerMap('USA', usaJson);
  option = {
    title: {
      text: 'USA Population Estimates (2012)',
      subtext: 'Data from www.census.gov',
      sublink: 'http://www.census.gov/popest/data/datasets.html',
      left: 'right'
    },
    geo: {
        name: 'USA PopEstimates',
        type: 'map',
        map: 'USA',
        projection: {
          project: function (point) {
            return projection(point);
          },
          unproject: function (point) {
            return projection.invert(point);
          }
        },
        emphasis: {
          label: {
            show: true
          }
        }
      }
  };
  myChart.setOption(option);
  const pos = [-97.54294,41.25546];
  const pos1 = myChart.convertToPixel('geo', pos);
  const isin = myChart.containPixel('geo', pos1);
  const pos2 = myChart.convertFromPixel('geo', pos1);
  console.log('p', pos, pos1, isin, pos2);

});

Current Behavior

pos为我选取的经纬度坐标,pos1是转换的像素值,pos2是反转回去的经纬度,经过输出,pos和pos2的值相差较大

Expected Behavior

预期pos和pos2的值相差无几

Environment

- OS:
- Browser:
- Framework:

Any additional comments?

在5.2.2版本没有遇到这个问题

echarts-bot[bot] commented 2 years ago

@godjb It seems you are not using English, I've helped translate the content automatically. To make your issue understood by more people and get helped, we'd like to suggest using English next time. 🤗

TRANSLATED
**TITLE** [Bug] When convertFromPixel is used on 'geo', the return value is wrong
helgasoft commented 1 year ago

d3 projection is the offender, works without it - Demo code

p (2) [-117, 32] 
(2) [218.20446191988958, 327.4760103577731] 
true 
(2) [-116.99999999999997, 31.999999999999986]

Of course it would be much better if we can use projections...

freelancer1845 commented 7 months ago

Im facing the same problem. The "unproject" callback does not get the correct point as parameter