如何通过将地图图块图像保存到 sqlite 数据库中来使用 osmdroid 实现离线地图?

发布于 2024-12-15 15:18:52 字数 132 浏览 0 评论 0 原文

我有一个项目也需要在离线模式下显示地图数据。我也使用过 OpenStreet 地图。我已经保存了地图图像(图块),每个图块都由数据库中的图块键引用。我想从数据库访问这些地图图块并相应地使用它们。

请建议我。

提前致谢。

I have a project that has a requirement of displaying map data in offline mode also. I have used OpenStreet maps for the same. I have saved map images(tiles) and each tile is referenced by a tilekey in database. I want to access these map tiles from database and use them accordingly.

Please suggest me.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃扇骨 2024-12-22 15:18:52

Osmdroid 中的地图图块由地图图块提供商提供。 Osmdroid 使用的默认图块提供程序是 MapTileProviderBasic。此提供程序扩展了 MapTileProviderArray ,这意味着它是几个其他图块提供程序的数组 - 当请求图块时,这些图块提供程序将被一一请求提供图块图像,直到其中一个提供为止。看一下 MapTileProviderBasic 的构造函数:

public MapTileProviderBasic(final IRegisterReceiver pRegisterReceiver,
              final INetworkAvailablityCheck aNetworkAvailablityCheck, 
                                        final ITileSource pTileSource) {

    super(pTileSource, pRegisterReceiver);    
    final TileWriter tileWriter = new TileWriter();

    final MapTileFilesystemProvider fileSystemProvider = 
        new MapTileFilesystemProvider(pRegisterReceiver, pTileSource);
    mTileProviderList.add(fileSystemProvider);

    final MapTileFileArchiveProvider archiveProvider = 
        new MapTileFileArchiveProvider(pRegisterReceiver, pTileSource);
    mTileProviderList.add(archiveProvider);

    final MapTileDownloader downloaderProvider = 
        new MapTileDownloader(pTileSource, tileWriter, aNetworkAvailablityCheck);
    mTileProviderList.add(downloaderProvider);
}

提供程序数组中添加了三个地图切片提供程序,按以下顺序:

  • MapTileFilesystemProvider - 提供来自文件系统(SD卡目录)
  • MapTileFileArchiveProvider - 提供来自文件系统中存档的图块
  • MapTileDownloader - 通过从互联网(例如从 OSM 服务器)下载图块来提供

图块MapTileProviderBasic 首先在文件系统中查找给定的图块,如果该图块不可用,则在存档文件中查找它,如果不可用,则再次从 Internet 下载该图块。

好的,这是默认机制。如果您想更改此机制以查找存储在数据库中的图块,那么您可以创建自己的类似于 MapTileProviderBasic 的类。因此,您的类也可以扩展 MapTileProviderArray 并仅在构造函数中使用其他提供程序。在Osmdroid中有一个类DatabaseFileArchive 它可能可以帮助您从数据库中读取图块。

创建您自己的图块提供程序后,您应该使用它而不是默认的提供程序。地图图块提供程序附加到MapViewMapView 的某些构造函数将 MapTileProviderBase 作为参数 - 您可以使用其中之一来附加您自己的提供程序。

Map tiles in Osmdroid are provided by map tile providers. The default tile provider used by Osmdroid is MapTileProviderBasic. This provider extends MapTileProviderArray, which means that it is an array of a few other tile providers - when a tile is requested these tile providers are asked one by one for a tile image until one of them provides it. Take a look at the constructor of MapTileProviderBasic:

public MapTileProviderBasic(final IRegisterReceiver pRegisterReceiver,
              final INetworkAvailablityCheck aNetworkAvailablityCheck, 
                                        final ITileSource pTileSource) {

    super(pTileSource, pRegisterReceiver);    
    final TileWriter tileWriter = new TileWriter();

    final MapTileFilesystemProvider fileSystemProvider = 
        new MapTileFilesystemProvider(pRegisterReceiver, pTileSource);
    mTileProviderList.add(fileSystemProvider);

    final MapTileFileArchiveProvider archiveProvider = 
        new MapTileFileArchiveProvider(pRegisterReceiver, pTileSource);
    mTileProviderList.add(archiveProvider);

    final MapTileDownloader downloaderProvider = 
        new MapTileDownloader(pTileSource, tileWriter, aNetworkAvailablityCheck);
    mTileProviderList.add(downloaderProvider);
}

There are three map tile providers added to the array of providers, in this order:

  • MapTileFilesystemProvider - provides tiles from the file system (SD card directory)
  • MapTileFileArchiveProvider - provides tiles from archive in file system
  • MapTileDownloader - provides tiles by downloading them from the Internet (e.g. from OSM servers)

So the MapTileProviderBasic looks for a given tile first in the file system, if the tile is not available then it looks for it in archive files and again if it is not available there it downloads the tile from the Internet.

Ok, this is the default mechanism. If you want to change this mechanism to look for tiles stored in a DB then you can create you own class similar to MapTileProviderBasic. So your class could also extend MapTileProviderArray and just use other providers in the constructor. In Osmdroid there is a class DatabaseFileArchive which could probably help you in reading tiles from the DB.

After creating your own tile provider you should use it instead of the default one. Map tile providers are attached to the MapView. Some of the constructors of MapView take MapTileProviderBase as an argument - you can use one of them to attach your own provider.

七秒鱼° 2024-12-22 15:18:52

让离线地图与默认提供程序一起使用的最简单方法 MapTileProviderBasic 是将您的地图档案放在 OSMDROID_PATH

换句话说,将 .zip、.sqlite、.mbtiles.gemf 文件下载到 osmdroid/ 目录中。

如果您查看 MapTileFileArchiveProvider 你看到它在 getArchiveFiles() href="https://github.com/osmdroid/osmdroid/blob/master/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/ArchiveFileFactory.java" rel="nofollow"> ArchiveFileFactory 根据文件扩展名选择正确的存档提供程序。

The simplest way to get offline maps to work with the default provider MapTileProviderBasic is to put your map arhive(s) in OSMDROID_PATH.

In other words, download your .zip, .sqlite, .mbtiles or .gemf file into the osmdroid/ directory.

If you look at MapTileFileArchiveProvider you see it calls getArchiveFiles() in ArchiveFileFactory which chooses the right archive provider based on the file extensions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文