简体   繁体   中英

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

I am using Gmap.net in which I have successfully implemented mbtile map. This works fine in machine when folder GMap.NET is created in " C:\\Users\\manish.jain\\AppData\\Local\\GMap.NET " for the first time when internet connection is available in the system. At this time; there are multiple folders create as follows:

  1. DllCache
  2. GeocoderCache
  3. IpGeoCacheDB
  4. leafletjs
  5. PlacemarkCache
  6. RouteCache
  7. TileDBv5
  8. UrlCache

But when same thing perform in offline mode then only two folders created in the same location as:

  1. DllCache
  2. TileDBv5

In this case I got message on every tile of the map as

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

I have attached snapshot of the same. 在此处输入图片说明

My requirement is to do all the map work always in offline mode as in client side there is no internet connection available.

Please let me know meaning and purpose of all these folders and solution of this problem. I have used this line of code for Map's Mode:

MainMap.Manager.Mode = AccessMode.ServerAndCache;

and to load mbtile from defined location as:

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

I have searched a lot for this issue but could not found any solution in google or in stackoverflow. Please Help!

Finally, I got a solution of this issue after spending valuable 4-5 hours that there is a issue occurred when trying to open SQLite Connection. I was getting an exception as "Cannot open database file". This connection has been resolved using below line where parseViaFramework need to be passed at the time of connection instance creation as follows:

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

Inside MBTileHelper.cs class :

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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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