Skip to content

Commit

Permalink
update possible basemap issue due to international characters
Browse files Browse the repository at this point in the history
  • Loading branch information
lixun910 committed Jun 6, 2017
1 parent 136b97d commit ab83084
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 50 deletions.
5 changes: 4 additions & 1 deletion DataViewer/DataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ wxString FileDataSource::GetJsonStr()
wxString json_tmp = "{\"ds_type\":\"%s\", \"ds_path\":\"%s\"}";
wxString json_path = file_repository_path;
json_path.Replace("\\", "\\\\");
wxString json_str = wxString::Format(json_tmp, GetDataTypeNameByGdaDSType(ds_type), json_path);

//wxString json_str = wxString::Format(json_tmp, GetDataTypeNameByGdaDSType(ds_type), json_path);
wxString json_str = "{\"ds_type\":\""+GetDataTypeNameByGdaDSType(ds_type)+"\", \"ds_path\":\""+json_path+"\"}";

return json_str;
}

Expand Down
54 changes: 19 additions & 35 deletions Explore/Basemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ XY::XY(double _x, double _y)
Basemap::Basemap(Screen* _screen,
MapLayer *_map,
int map_type,
string _cachePath,
wxString _cachePath,
OGRCoordinateTransformation *_poCT )
{
poCT = _poCT;
Expand Down Expand Up @@ -119,9 +119,8 @@ Basemap::~Basemap() {

void Basemap::CleanCache()
{
std::ostringstream filepathBuf;
filepathBuf << cachePath << "basemap_cache"<< separator();
wxString filename = filepathBuf.str();
wxString filename;
filename << cachePath << "basemap_cache"<< separator();
wxDir dir(filename);
if (dir.IsOpened() ) {
wxString file;
Expand Down Expand Up @@ -528,11 +527,10 @@ size_t curlCallback(void *ptr, size_t size, size_t nmemb, void* userdata)
void Basemap::DownloadTile(int x, int y)
{
// detect if file exists in temp/ directory
std::string filepathStr = GetTilePath(x, y);
char* filepath = new char[filepathStr.length() + 1];
std::strcpy(filepath, filepathStr.c_str());
wxString filepathStr = GetTilePath(x, y);
std::string filepath = GET_ENCODED_FILENAME(filepathStr);

if (!is_file_exist(filepath)) {
if (!wxFileExists(filepathStr)) {
// otherwise, download the image
std::string urlStr = GetTileUrl(x, y);
char* url = new char[urlStr.length() + 1];
Expand All @@ -544,7 +542,7 @@ void Basemap::DownloadTile(int x, int y)

image = curl_easy_init();
if (image) {
fp = fopen(filepath, "wb");
fp = fopen(filepath.c_str(), "wb");
if (fp)
{
curl_easy_setopt(image, CURLOPT_URL, url);
Expand All @@ -557,19 +555,6 @@ void Basemap::DownloadTile(int x, int y)
// Grab image
imgResult = curl_easy_perform(image);

/*
if( imgResult ){
cout << "Cannot grab the image!\n";
}
int res_code = 0;
curl_easy_getinfo(image, CURLINFO_RESPONSE_CODE, &res_code);
if (!((res_code == 200 || res_code == 201) && imgResult != CURLE_ABORTED_BY_CALLBACK))
{
printf("!!! Response code: %d\n", res_code);
}
*/
// Clean up the resources
curl_easy_cleanup(image);
fclose(fp);
}
Expand All @@ -580,7 +565,6 @@ void Basemap::DownloadTile(int x, int y)
}
isTileReady = false; // notice template_canvas to draw
//canvas->Refresh(true);
delete[] filepath;
}


Expand Down Expand Up @@ -646,23 +630,24 @@ std::string Basemap::GetTileUrl(int x, int y)
return urlStr;
}

std::string Basemap::GetTilePath(int x, int y)
wxString Basemap::GetTilePath(int x, int y)
{
std::ostringstream filepathBuf;
//std::ostringstream filepathBuf;
wxString filepathBuf;
filepathBuf << cachePath << "basemap_cache"<< separator();
filepathBuf << mapType << "-";
filepathBuf << zoom << "-" << x << "-" << y << imageSuffix;
std::string filepathStr = filepathBuf.str();
std::string newpath;
for (int i = 0; i < filepathStr.length() ;i++)
filepathBuf << zoom << "-" << x << "-" << y << imageSuffix;

wxString newpath;
for (int i = 0; i < filepathBuf.length() ;i++)
{
if(filepathStr[i] == '\\')
if(filepathBuf[i] == '\\')
{
newpath += filepathStr[i];
newpath += filepathStr[i];
newpath += filepathBuf[i];
newpath += filepathBuf[i];
}
else
newpath += filepathStr[i];
newpath += filepathBuf[i];
}
return newpath;
}
Expand Down Expand Up @@ -690,8 +675,7 @@ bool Basemap::Draw(wxBitmap* buffer)
idx_x = nn + i;

int idx_y = j < 0 ? nn + j : j;
std::string filepathStr = GetTilePath(idx_x, idx_y);
wxString wxFilePath(filepathStr);
wxString wxFilePath = GetTilePath(idx_x, idx_y);
wxFileName fp(wxFilePath);
wxBitmap bmp;
if (imageSuffix == ".png") {
Expand Down
6 changes: 3 additions & 3 deletions Explore/Basemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class Basemap {
Basemap(Screen *_screen,
MapLayer *_map,
int map_type,
std::string _cachePath,
wxString _cachePath,
OGRCoordinateTransformation *_poCT );
~Basemap();

Expand Down Expand Up @@ -263,7 +263,7 @@ class Basemap {
Screen* screen;
MapLayer* map;
MapLayer* origMap;
std::string cachePath;
wxString cachePath;

double Deg2Rad (double degree) { return degree * M_PI / 180.0; }
double Rad2Deg (double radians) { return radians * 180.0 / M_PI;}
Expand All @@ -272,7 +272,7 @@ class Basemap {
void LatLngToXY(double lng, double lat, int &x, int &y);

std::string GetTileUrl(int x, int y);
std::string GetTilePath(int x, int y);
wxString GetTilePath(int x, int y);

bool Draw(wxBitmap* buffer);

Expand Down
14 changes: 7 additions & 7 deletions GenUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,35 +1335,35 @@ wxString GenUtils::WrapText(wxWindow *win, const wxString& text, int widthMax)
return wrapper.GetWrapped();
}

std::string GenUtils::GetBasemapCacheDir()
wxString GenUtils::GetBasemapCacheDir()
{
wxString exePath = wxStandardPaths::Get().GetExecutablePath();
wxFileName exeFile(exePath);
wxString exeDir = exeFile.GetPathWithSep();
return std::string(GET_ENCODED_FILENAME(exeDir));
return exeDir;
}

std::string GenUtils::GetWebPluginsDir()
wxString GenUtils::GetWebPluginsDir()
{
wxString exePath = wxStandardPaths::Get().GetExecutablePath();
wxFileName exeFile(exePath);
wxString exeDir = exeFile.GetPathWithSep();
exeDir << "web_plugins" << wxFileName::GetPathSeparator();

return std::string(GET_ENCODED_FILENAME(exeDir));
return exeDir;
}

std::string GenUtils::GetResourceDir()
wxString GenUtils::GetResourceDir()
{
wxString exePath = wxStandardPaths::Get().GetExecutablePath();
wxFileName exeFile(exePath);
wxString exeDir = exeFile.GetPathWithSep();
exeDir << "../Resources" << wxFileName::GetPathSeparator();

return std::string(GET_ENCODED_FILENAME(exeDir));
return exeDir;
}

std::string GenUtils::GetSamplesDir()
wxString GenUtils::GetSamplesDir()
{
#ifdef __WXOSX__
return GetResourceDir();
Expand Down
8 changes: 4 additions & 4 deletions GenUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,10 @@ namespace GenUtils {

wxString WrapText(wxWindow *win, const wxString& text, int widthMax);

std::string GetBasemapCacheDir();
std::string GetWebPluginsDir();
std::string GetResourceDir();
std::string GetSamplesDir();
wxString GetBasemapCacheDir();
wxString GetWebPluginsDir();
wxString GetResourceDir();
wxString GetSamplesDir();

bool less_vectors(const std::vector<int>& a,const std::vector<int>& b);
}
Expand Down

0 comments on commit ab83084

Please sign in to comment.