如何在osmdroid中设置最大缩放?
我已经检查了这个答案,但该示例除了显示灰色瓷砖之外什么也没做(我处于离线模式)缩放级别大于我给出的限制(在我的情况下为 4)...
OnlineTileSourceBase source = new XYTileSource("tiles", ResourceProxy.string.offline_mode, 0, 4, 256, ".png", "");
以下代码显示 maxZoom=4
:
int zoomLevel = source.getMaximumZoomLevel();
Toast.makeText(this, "maxZoom=" + zoomLevel, Toast.LENGTH_SHORT).show();
缩放级别介于0 和 4 我的代码按预期工作:它从 SD 卡加载地图图块。我对问题的理解是,代码显示了它找到的每个缩放的所有图块,并且当没有找到其他缩放时,它仍然会放大。
API 明确指定设置最大缩放XYTileSource
构造函数中的 level (final int aZoomMaxLevel
):
public XYTileSource(final String aName, final string aResourceId, final int aZoomMinLevel,
final int aZoomMaxLevel, final int aTileSizePixels, final String aImageFilenameEnding,
final String... aBaseUrl)
有解决方法吗?我做错了什么?如何阻止缩放以使用户无法超出级别 4?
I already checked this answer, but the example does nothing else than show gray tiles (I'm in offline mode) for zoom level greater than the limit I give (4 in my case)...
OnlineTileSourceBase source = new XYTileSource("tiles", ResourceProxy.string.offline_mode, 0, 4, 256, ".png", "");
The following code shows maxZoom=4
:
int zoomLevel = source.getMaximumZoomLevel();
Toast.makeText(this, "maxZoom=" + zoomLevel, Toast.LENGTH_SHORT).show();
For zoom levels between 0 and 4 my code works as expected: it loads map tiles from the SD card. My understanding of the problem is that the code shows all the tiles for each zoom it finds and when no other zooms are found it still zooms in.
The API clearly specifies setting the max zoom level in the constructor of XYTileSource
(final int aZoomMaxLevel
):
public XYTileSource(final String aName, final string aResourceId, final int aZoomMinLevel,
final int aZoomMaxLevel, final int aTileSizePixels, final String aImageFilenameEnding,
final String... aBaseUrl)
Any workarounds? What am I doing wrong? How can I block the zoom so that the user can't go beyond level 4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MapView
类定义公共函数getMaxZoomLevel()
。 MapView 的一个简单扩展将允许您覆盖该函数以返回您想要的任何内容,而无需将 osmdroid 源重新编译到 JAR 中:您不需要最小缩放级别,但如果需要,< code>getMinZoomLevel() 也是公共的并且可以被覆盖。显然,使用常量文字 4 可能是一个坏主意;最好从
SharedPreferences
动态加载,除非您知道您的图像永远不会改变。The
MapView
class defines the public functiongetMaxZoomLevel()
. A trivial extension ofMapView
will let you override that function to return whatever you want without having to recompile the osmdroid source into a JAR:You don't need a minimum zoom level, but if you did,
getMinZoomLevel()
is also public and could be overridden. And obviously using the constant literal 4 is probably a bad idea; better to load dynamically fromSharedPreferences
unless you know your imagery will never, ever change.我们找到了一种解决方法来为整个应用程序全局设置最大缩放级别。您必须在 osmdroid-android 项目中的 org.osmdroid.tileprovider.constants 包中的文件 OpenStreetMapTileProviderConstants 中将值更改为所需的级别。这不是正确的方法,但对我们来说效果很好! :)
We found a workaround to set the maximum zoomlevel globally for the whole application.You have to change the value to your desired level in the file OpenStreetMapTileProviderConstants in the package org.osmdroid.tileprovider.constants in the osmdroid-android project. It´s not the proper way, but works quite fine for us! :)
您可以在此处找到如何构建 jar 的详细说明
。 org.osmdroid.views.util.constants.MapViewConstants
和 org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants
应该做这项工作。
从 SVN 获取 osmdroid 源 http://osmdroid.googlecode.com/svn/branches/release_3_0_5
我推荐这个版本,因为最终在缩放限制旁边应用滚动限制补丁会更容易。
You can find detailed intruction how to build the jar here here
Changing MAXIMUM_ZOOMLEVEL in both org.osmdroid.views.util.constants.MapViewConstants
and org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants
should do the job.
Get the osmdroid source from SVN http://osmdroid.googlecode.com/svn/branches/release_3_0_5
I recomend this version cause it will be easier to eventualy apply the scroll limit patch beside the zoom limit.