Implementing a mouse click event on a tile in a map

时间秒杀一切 提交于 2019-11-27 09:51:47
trashgod

On a sufficiently small map with a suitable projection, you can transform between coordinate systems using linear interpolation relative to the enclosing panel. Noting the following proportions, you can cross-multiply and solve for the missing coordinate, as shown in this complete example that maps mouse coordinates to pixel coordinates in an image.

mouse.x : panelWidthInPixels :: featureLongitude : tileWidthInDegrees
mouse.y : panelHeightInPixels :: featureLatitude : tileHeightInDegrees

More generally, use a library like JMapViewer that incorporates the map's projection into the transformation. A schema for hit-testing features is outlined here.

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