繁体   English   中英

当缓存不可用时,如何在 Gmap.net 的离线模式下使用 mbtile 地图?

[英]How to use mbtile map in offline mode in Gmap.net when cache is not available?

我正在使用 Gmap.net,我已经成功地实现了 mbtile 地图。 当系统中的互联网连接可用时,当第一次在“ C:\\Users\\manish.jain\\AppData\\Local\\GMap.NET ”中创建文件夹 GMap.NET 时,这在机器上工作正常。 此时; 有多个文件夹创建如下:

  1. 缓存
  2. 地理编码缓存
  3. 地理缓存数据库
  4. 传单
  5. 地标缓存
  6. 路由缓存
  7. TileDBv5
  8. 缓存

但是,当在离线模式下执行相同的操作时,只有两个文件夹创建在与以下位置相同的位置:

  1. 缓存
  2. TileDBv5

在这种情况下,我在地图的每个图块上都收到了消息

"Exception:Buffer cannot be null. Paremeter name: buffer"

我附上了相同的快照。 在此处输入图片说明

我的要求是始终在离线模式下完成所有地图工作,因为在客户端没有可用的互联网连接。

请让我知道所有这些文件夹的含义和目的以及此问题的解决方案。 我在 Map's Mode 中使用了这行代码:

MainMap.Manager.Mode = AccessMode.ServerAndCache;

并从定义的位置加载 mbtile 为:

MainMap = new Demo.WindowsForms.Map();
MainMap.MapProvider = new MBTilesMapProvider(@"C:\\India.mbtiles");
MainMap.MinZoom = MainMap.MapProvider.MinZoom;
MainMap.MaxZoom = MainMap.MapProvider.MaxZoom;

我为这个问题搜索了很多,但在 google 或 stackoverflow 中找不到任何解决方案。 请帮忙!

最后,我花了宝贵的 4-5 个小时发现在尝试打开 SQLite 连接时出现问题后,我得到了这个问题的解决方案。 我收到了“无法打开数据库文件”的异常。 此连接已使用以下行解决,其中 parseViaFramework 需要在创建连接实例时传递,如下所示:

using (SQLiteConnection conn = new SQLiteConnection(String.Format("Data Source={0};Version=3;", Path),true))

在 MBTileHelper.cs 类中:

public byte[] GetTileStream(long x, long y, int zoom)
    {
        byte[] retval = null;
        try
        {
            //using (SQLiteConnection conn = new SQLiteConnection(String.Format("Data Source={0};Version=3;", Path)))
            using (SQLiteConnection conn = new SQLiteConnection(String.Format("Data Source={0};Version=3;", Path),true))
            {
                conn.Open(); // Here I was getting an exception.
                using (SQLiteCommand cmd = new SQLiteCommand() { Connection = conn, CommandText = String.Format("SELECT * FROM tiles WHERE tile_column = {0} and tile_row = {1} and zoom_level = {2};", x, y, zoom) })
                {
                    SQLiteDataReader reader = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        byte[] bytes = reader["tile_data"] as byte[];
                        retval = bytes;
                    }
                }
            }
        }
        catch(Exception ex)
        {
            retval = null;
        }
        return retval;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM