Skip to content

Commit

Permalink
fix stamen basemap
Browse files Browse the repository at this point in the history
  • Loading branch information
lixun910 committed Aug 17, 2023
1 parent 8095b6d commit d58fa23
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ BuildTools/macosx/build/
BuildTools/macosx/GeoDa.xcodeproj/
BuildTools/macosx/GeoDa.xcodeproj/xcuserdata/
BuildTools/macosx/GeoDa-leopard.xcodeproj/
BuildTools/reactgeoda
BuildTools/node_modules

build/

*.dmg
*.mode1v3
Expand Down
26 changes: 21 additions & 5 deletions Explore/Basemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include <ogr_spatialref.h>

#include <curl/curl.h>
#include "../GdaConst.h"
#include "../GeneralWxUtils.h"
#include "../ShapeOperations/OGRDataAdapter.h"
#include "Basemap.h"

Expand Down Expand Up @@ -156,8 +158,6 @@ XYFraction::XYFraction(double _x, double _y)
yfrac = modf(_y, &yint);
}

const char *Basemap::USER_AGENT = "GeoDa 1.14 contact spatial@uchiago.edu";

Basemap::Basemap(BasemapItem& _basemap_item,
Screen* _screen,
MapLayer* _map,
Expand Down Expand Up @@ -612,6 +612,21 @@ size_t curlCallback(void *ptr, size_t size, size_t nmemb, void* userdata)
return written;
}

wxString Basemap::GetUserAgent(const wxString& url)
{
if (url.Find("openstreetmap") != wxNOT_FOUND) {
return GdaConst::gda_basemap_osm_useragent;
}
if (GeneralWxUtils::isWindows()) {
return GdaConst::gda_basemap_win_useragent;
} else if (GeneralWxUtils::isMac()) {
return GdaConst::gda_basemap_mac_useragent;
} else {
return GdaConst::gda_basemap_linux_useragent;
}

}

wxString Basemap::GetContentType()
{
wxString url = GetTileUrl(16, 11); // guerry
Expand All @@ -621,7 +636,8 @@ wxString Basemap::GetContentType()
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.ToUTF8().data());
curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_easy_setopt(curl, CURLOPT_USERAGENT, Basemap::USER_AGENT);
curl_easy_setopt(curl, CURLOPT_USERAGENT, GetUserAgent(url).ToUTF8().data());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1L);
Expand Down Expand Up @@ -670,10 +686,10 @@ void Basemap::DownloadTile(int x, int y)
if (fp) {
curl_easy_setopt(image, CURLOPT_URL, url.ToUTF8().data());
curl_easy_setopt(image, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_easy_setopt(image, CURLOPT_USERAGENT, Basemap::USER_AGENT);
curl_easy_setopt(image, CURLOPT_USERAGENT, GetUserAgent(url).ToUTF8().data());
curl_easy_setopt(image, CURLOPT_WRITEFUNCTION, curlCallback);
curl_easy_setopt(image, CURLOPT_WRITEDATA, fp);
//curl_easy_setopt(image, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(image, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(image, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(image, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(image, CURLOPT_CONNECTTIMEOUT, 1L);
Expand Down
26 changes: 13 additions & 13 deletions Explore/Basemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ namespace Gda {
east = _e;
south = _s;
}
OGRSpatialReference* s1 = poCT->GetTargetCS();
OGRSpatialReference* s2 = poCT->GetSourceCS();
const OGRSpatialReference* s1 = poCT->GetTargetCS();
const OGRSpatialReference* s2 = poCT->GetSourceCS();
#ifdef __PROJ6__
s1->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
s2->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
const_cast<OGRSpatialReference*>(s1)->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
const_cast<OGRSpatialReference*>(s2)->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
#endif
poCT_rev = OGRCreateCoordinateTransformation(s1, s2);
}
Expand Down Expand Up @@ -327,20 +327,20 @@ namespace Gda {
poCT_rev = NULL;
if (other) {
if (other->poCT) {
OGRSpatialReference* s1 = other->poCT->GetSourceCS();
OGRSpatialReference* s2 = other->poCT->GetTargetCS();
const OGRSpatialReference* s1 = other->poCT->GetSourceCS();
const OGRSpatialReference* s2 = other->poCT->GetTargetCS();
#ifdef __PROJ6__
s1->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
s2->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
const_cast<OGRSpatialReference*>(s1)->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
const_cast<OGRSpatialReference*>(s2)->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
#endif
poCT = OGRCreateCoordinateTransformation(s1, s2);
}
if (other->poCT_rev) {
OGRSpatialReference* s1 = other->poCT_rev->GetSourceCS();
OGRSpatialReference* s2 = other->poCT_rev->GetTargetCS();
const OGRSpatialReference* s1 = other->poCT_rev->GetSourceCS();
const OGRSpatialReference* s2 = other->poCT_rev->GetTargetCS();
#ifdef __PROJ6__
s1->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
s2->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
const_cast<OGRSpatialReference*>(s1)->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
const_cast<OGRSpatialReference*>(s2)->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
#endif
poCT_rev = OGRCreateCoordinateTransformation(s1, s2);
}
Expand Down Expand Up @@ -377,7 +377,6 @@ namespace Gda {
double scale_factor = 1.0);
~Basemap();

static const char* USER_AGENT;
OGRCoordinateTransformation *poCT;
BasemapItem basemap_item;
wxString basemapName;
Expand Down Expand Up @@ -439,6 +438,7 @@ namespace Gda {

void CleanCache();
wxString GetContentType();
wxString GetUserAgent(const wxString& url);
};

}
Expand Down
4 changes: 4 additions & 0 deletions GdaConst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ wxString GdaConst::gda_basemap_sources =
"\nOther (China).GaoDe,http://webst{s}.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}"
"\nOther (China).GaoDe(Satellite),http://webst{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}"
;
const wxString GdaConst::gda_basemap_osm_useragent = "GeoDa 1.14 contact spatial@uchiago.edu";
const wxString GdaConst::gda_basemap_win_useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36";
const wxString GdaConst::gda_basemap_mac_useragent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36";
const wxString GdaConst::gda_basemap_linux_useragent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36";

const wxString GdaConst::gda_lbl_not_sig = _("Not Significant");
const wxString GdaConst::gda_lbl_undefined = _("Undefined");
Expand Down
6 changes: 6 additions & 0 deletions GdaConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ class GdaConst {
static const int ShpHeaderSize = 50; // size of the header record in Shapefile
static const int ShpObjIdLen = 20; // length of the ID of shape object

// Basemap
static const wxString gda_basemap_osm_useragent;
static const wxString gda_basemap_win_useragent;
static const wxString gda_basemap_mac_useragent;
static const wxString gda_basemap_linux_useragent;

static wxCursor zoomInCursor;
static wxCursor zoomOutCursor;

Expand Down

0 comments on commit d58fa23

Please sign in to comment.