diff --git a/CMakeLists.txt b/CMakeLists.txt index b6949e707..e17924f62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,15 @@ if(PROJECT_VERSION_RC) set(PROJECT_VERSION "${PROJECT_VERSION}-rc${PROJECT_VERSION_RC}") endif() +##================================================ +## Build customizations +##================================================ +option(KEPKA_OPTION_USE_YANDEX_MAPS "Use Yandex.Maps static API for locations (instead Google Maps)" OFF) + +if(KEPKA_OPTION_USE_YANDEX_MAPS) + add_definitions("-DKEPKA_USE_YANDEX_MAPS") +endif() + set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules/") if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.10) diff --git a/Telegram/SourceFiles/history/history_location_manager.cpp b/Telegram/SourceFiles/history/history_location_manager.cpp index 0252cad8c..88892f51f 100644 --- a/Telegram/SourceFiles/history/history_location_manager.cpp +++ b/Telegram/SourceFiles/history/history_location_manager.cpp @@ -48,10 +48,20 @@ void LocationClickHandler::onClick(Qt::MouseButton button) const { } } +// This option could be enabled in core CMakeLists.txt +#ifdef KEPKA_USE_YANDEX_MAPS +void LocationClickHandler::setup() { + // Yandex.Maps accepts ll string in "longitude,latitude" format + auto latlon = _coords.lonAsString() + "%2C" + _coords.latAsString(); + _text = qsl("https://maps.yandex.ru/?ll=") + latlon + qsl("&z=16"); +} + +#else void LocationClickHandler::setup() { auto latlon = _coords.latAsString() + ',' + _coords.lonAsString(); _text = qsl("https://maps.google.com/maps?q=") + latlon + qsl("&ll=") + latlon + qsl("&z=16"); } +#endif namespace { LocationManager *locationManager = nullptr; @@ -133,14 +143,28 @@ void LocationManager::getData(LocationData *data) { w = convertScale(w); h = convertScale(h); } +#ifdef KEPKA_USE_YANDEX_MAPS + // see https://tech.yandex.ru/maps/doc/staticapi/1.x/dg/concepts/input_params-docpage/ for API parameters reference. + auto coords = data->coords.lonAsString() + ',' + data->coords.latAsString(); // Yandex.Maps accepts ll string in "longitude,latitude" format + const char *mapsApiUrl = "https://static-maps.yandex.ru/1.x/?ll="; + QString mapsApiParams = "&z=%1&size=%2,%3&l=map&scale=%4&pt="; + const char *mapsMarkerParams = ",pm2rdl"; // red large marker looking like "9" +#else auto coords = data->coords.latAsString() + ',' + data->coords.lonAsString(); - QString url = qsl("https://maps.googleapis.com/maps/api/staticmap?center=") + coords + - qsl("&zoom=%1&size=%2x%3&maptype=roadmap&scale=%4&markers=color:red|size:big|") + const char *mapsApiUrl = "https://maps.googleapis.com/maps/api/staticmap?center="; + QString mapsApiParams = "&zoom=%1&size=%2,%3&maptype=roadmap&scale=%4&markers=color:red|size:big|"; + const char *mapsMarkerParams = "&sensor=false"; +#endif + QString url = // qsl("https://maps.googleapis.com/maps/api/staticmap?center=") + coords + + // qsl("&zoom=%1&size=%2x%3&maptype=roadmap&scale=%4&markers=color:red|size:big|") + mapsApiUrl + coords + mapsApiParams .arg(zoom) .arg(w) .arg(h) .arg(scale) + - coords + qsl("&sensor=false"); + coords + + mapsMarkerParams; + //+ qsl("&sensor=false"); QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url))); imageLoadings[reply] = data; }