创建类似 Google 地图的视图?
我有一台服务器,将 GIS 数据库中的平铺地理图像传送到我的 Android 客户端应用程序。我希望用户能够像在 Google 地图中一样平移/缩放地图。
但是使用画布和 ImageView 以标准方式实现它存在一个问题:画布需要具有固定的宽度/高度,而 Geotiff 地图环绕地球,因此理论上是无限的(或至少数万像素宽)。即,如果我们的源是美国东北部的 Geotiff,则显示波士顿的卫星视图,并且用户想要平移到纽约市,然后放大到自由女神像。
现在我已经开始工作了,其中:
- 当用户平移/缩放并释放手指时,我获得 ImageView 左上角和右下角的像素坐标。
- 然后我告诉服务器在这些坐标处获取平铺地图(在将视口坐标转换为完整 Geotiff 图像的图像坐标之后)
- 绘制新平铺,同时重置 ImageView 的内部变换矩阵。我在内部跟踪图像的原点(左上角)相对于完整 Geotiff 图像的位置。
但这是超级黑客,并且在尝试渲染图标时会导致问题,因为每次绘制新图块时我们都会重置矩阵。另外,当用户继续缩放/平移时,几乎不可能动态绘制图块。
像无限画布这样的东西是最好的,因为我不受可绘制对象大小的限制。是否有一种使用标准 Android 容器集来实现此目的的非 hacky 方法?或者我不可避免地要使用 OpenGL 做一些自定义的事情?
I have a server feeding tiled geographic images from a GIS database, to my Android client app. I want users to be able to pan/zoom into the map like they'd do in Google Maps.
But there's an issue implementing it the standard way, with a canvas and ImageView: canvases need to have a fixed width/height, whereas Geotiff maps wraps around the globe and is thus theoretically unlimited (or at least tens of thousands of pixels wide). I.e. if our source is a Geotiff of the Northeastern USA, display a satellite view of Boston, and the user wants to pan over to New York City, then zoom into the Statue of Liberty.
Right now I have it sort of working, where:
- when the user pans/zooms and releases their finger, I obtain the pixel coordinates of the top left and bottom right corners of the ImageView.
- Then I tell the server to get me the tiled map at those coordinates (after converting the viewport coordinates to image coordinates of the full Geotiff image)
- Draw the new tile while resetting the ImageView's internal transformation matrix. I internally keep track of where the image's origin (top left corner) is relative to the full Geotiff image.
But it's super hacky and causes issues when trying to render icons since we're resetting the matrix each time a new tile is drawn. Plus this way it's pretty much impossible to dynamically draw tiles while the user is continuing to zoom/pan.
Something like an infinite-canvas would be best where I'm not limited by the size of a drawable. Is there a non-hacky way of achieving this using the standard set of Android containers? Or is it inevitable I do something custom with OpenGL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论