[英]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 時,這在機器上工作正常。 此時; 有多個文件夾創建如下:
但是,當在離線模式下執行相同的操作時,只有兩個文件夾創建在與以下位置相同的位置:
在這種情況下,我在地圖的每個圖塊上都收到了消息
"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.