设置 MapView 的最小缩放级别
有没有办法为我的 MapView 设置最小缩放级别?当缩放级别设置为 1 时,地图看起来非常丑陋,因为整个世界地图都被复制了。
我想阻止该缩放级别。理想情况下,无论用户是通过手势还是缩放控件进行缩放,它都可以工作。
Is there a way I can set a minimum zooM level for my MapView?. The map looks really ugly when zoom level is set to one because the whole world map replicated.
I would like to block that zoom level. Ideally, it would work whether the user is zooming through gestures or zoom controls.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需在 onCreate 中编写以下代码:
just write onCreate following code:
幸运的是,我的 MapView 中有一个叠加层。否则,我想你将不得不创建一个,只是为了这个微小的功能:-/。我想知道为什么没有其他方法可以更轻松地做到这一点。
无论如何,你只需要像这样重写你的绘制方法:
Ger
Fortunately, i was having an overlay in my MapView. Otherwise, i guess you will have to create one, just for this tiny feature :-/. I wonder why there isn't any other way of doing this easier.
Anyways, you just need to override your draw method like this:
Ger
与 ggomeze 的答案类似,通过重写
*draw()
方法,但最好在MapView
中重写dispatchDraw()
代码>.通过这种方式,您可以阻止对图块为空的缩放级别进行绘制。另请注意,此时最好将地图居中,就好像您使用触摸手势进行缩放一样,手动设置缩小一级可能会导致地图每次偏离中心(这使得 MapView代码> 看起来有点狡猾!)。
这可以通过在手势发生时跟踪缩放级别来改进,这样用户在手势时就看不到部分缩放到被阻止的最低缩放级别 (1),但我想上面的情况最适合并且很多更轻松!
Similar to ggomeze's answer by overriding a
*draw()
method but it may be better to overridedispatchDraw()
inMapView
. This way you can block the draw for the zoom level where the tiles are empty.Also note that its good to center the map at this point as if you are zooming with touch gestures manually setting the zoom out by one level can cause the map to shift away from the center each time (which makes the
MapView
look a bit more dodgy!).This could be improved upon by tracking the zoom level while the gesture is taking place also so the user can not see the partial zoom to the blocked lowest zoom level (1) while gesturing but i imagine the case above will suit most and is a lot easier!