Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

百度地图坐标转换成pixel 出现x = 256 或者 y=256, 溢出? #5

Closed
lizecn opened this issue Jul 25, 2017 · 4 comments
Closed

Comments

@lizecn
Copy link

lizecn commented Jul 25, 2017

zoom level 10
百度坐标 {lng: 120.097447, lat: 31.780346}
返回pixel {pixelX: 256, pixelY: 163}
tile 大小 256 x 256 x或者y 0-255, 转换后256是不是溢出了?

@CntChen
Copy link
Owner

CntChen commented Jul 27, 2017

感谢测试,应该是边界问题,我跟进一下。

@lizecn
Copy link
Author

lizecn commented Jul 28, 2017

另外还发现tile pixel 中x 或者 y 有正负1 pixel的误差,这个误差在level 10 情况下, 造成的偏移量还是不容忽视的。 可能跟上述的issue相关。

@lizecn
Copy link
Author

lizecn commented Aug 11, 2017

var pixelX = Math.round(x * this._getMapSize(level) * 256 % 256);
var pixelY = Math.round(y * this._getMapSize(level) * 256 % 256);

两行使用了round 进行了向上取整, 所以有256的出现了。 改成
Math.floor(y * this._getMapSize(level) * 256 % 256); 可能会解决问题,
小小思路, 希望lz 尽快解决这个问题。

@CntChen
Copy link
Owner

CntChen commented Aug 12, 2017

对,就是这个问题.用 Math.round 是有问题的.会导致取值区间变为 [0, 256],一共 257 个取值.
用 Math.floor 是对的,取值区间为 [0, 255],一共 256 个取值.
已经修复了,其他地图的转换也存在这个问题,也一并修复了.

@CntChen CntChen closed this as completed Aug 12, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants