How to get my MapContainer bounding box in Codename One

早过忘川 提交于 2019-12-04 16:59:15

The problem is in the javadocs for getCoordAtPosition(). This will be corrected. getCoordAtPosition() expects absolute coordinates, not relative.

E.g

Coord NE = currentMap.getCoordAtPosition(currentMap.getWidth(), 0); 
Coord SW = currentMap.getCoordAtPosition(0, currentMap.getHeight());

Should be

Coord NE = currentMap.getCoordAtPosition(currentMap.getAbsoluteX() + currentMap.getWidth(), currentMap.getAbsoluteY()); 
Coord SW = currentMap.getCoordAtPosition(currentMap.getAbsoluteX(), currentMap.getAbsoluteY() + currentMap.getHeight());

I tried this out on the coordinates that you provided and it returns valid results.

EDIT March 21, 2017 : It turns out that some of the platforms expected relative coordinates, and others expected absolute coordinates. I have had to standardize it, and I have chosen to use relative coordinates across all platforms to be consistent with the Javadocs. So your first attempt:

Coord NE = currentMap.getCoordAtPosition(currentMap.getWidth(), 0); 
Coord SW = currentMap.getCoordAtPosition(0, currentMap.getHeight());

Will now work in the latest version of the library.

I have also added another method : getBoundingBox() that will get the bounding box for you without worrying about relative/absolute coordinates.

This is probably something that can be exposed easily by forking the project and providing a pull request. We're currently working on updating the map component so this is a good time to make changes and add features.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!