Skip to content

Commit 2971ea3

Browse files
nextfullstormpmeems
authored andcommitted
Add support to tiles from local filesystem
BaseProvider modified to allow URLs like "file:///c:\temp\maps\{zoom}\{x}\{y}.ext" and offline tile loading from filesystem without ms4w.
1 parent 49a6167 commit 2971ea3

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

src/Tiles/Providers/BaseProvider.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CString BaseProvider::_proxyUsername = "";
2828
CString BaseProvider::_proxyPassword = "";
2929
CString BaseProvider::_proxyDomain = "";
3030
CCriticalSection BaseProvider::_clientLock;
31+
const CString filePrefix = "file:///";
3132

3233
// ************************************************************
3334
// GetTileImage()
@@ -90,6 +91,34 @@ CMemoryBitmap* BaseProvider::GetTileHttpData(CString url, CString shortUrl, bool
9091
return bmp;
9192
}
9293

94+
// ************************************************************
95+
// GetTileFileData()
96+
// ************************************************************
97+
CMemoryBitmap* BaseProvider::GetTileFileData(CString url, CString shortUrl, bool recursive)
98+
{
99+
url.Delete(0, filePrefix.GetLength());
100+
url.Replace("|", ":");
101+
url.Replace("/", "\\");
102+
103+
std::ifstream fl = std::ifstream(url.GetBuffer(), std::ofstream::binary);
104+
if (!fl)
105+
return nullptr;
106+
107+
fl.seekg(0, std::ios::end);
108+
int sz = fl.tellg();
109+
if (sz == 0)
110+
return nullptr;
111+
112+
std::vector<char> buf(sz);
113+
114+
fl.seekg(0, std::ios::beg);
115+
fl.read(buf.data(), buf.size());
116+
if (!fl)
117+
return nullptr;
118+
119+
return ReadBitmap(buf.data(), buf.size());
120+
}
121+
93122
// ************************************************************
94123
// DownloadBitmap()
95124
// ************************************************************
@@ -100,9 +129,10 @@ CMemoryBitmap* BaseProvider::DownloadBitmap(CPoint& pos, int zoom)
100129

101130
shortUrl.Format(R"(\zoom=%d\x=%d\y=%d)", zoom, pos.x, pos.y);
102131

103-
CMemoryBitmap* bmp = GetTileHttpData(url, shortUrl);
104-
105-
return bmp;
132+
if (url.Find(filePrefix) == 0)
133+
return GetTileFileData(url, shortUrl);
134+
else
135+
return GetTileHttpData(url, shortUrl);
106136
}
107137

108138
// ************************************************************

0 commit comments

Comments
 (0)