2019-06-21 12:27:46 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "data/data_location.h"
|
|
|
|
|
|
|
|
#include "ui/image/image.h"
|
|
|
|
#include "data/data_file_origin.h"
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
namespace {
|
|
|
|
|
2020-05-28 13:05:44 +00:00
|
|
|
[[nodiscard]] QString AsString(float64 value) {
|
|
|
|
constexpr auto kPrecision = 6;
|
|
|
|
return QString::number(value, 'f', kPrecision);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
LocationPoint::LocationPoint(const MTPDgeoPoint &point)
|
|
|
|
: _lat(point.vlat().v)
|
|
|
|
, _lon(point.vlong().v)
|
|
|
|
, _access(point.vaccess_hash().v) {
|
|
|
|
}
|
|
|
|
|
|
|
|
QString LocationPoint::latAsString() const {
|
|
|
|
return AsString(_lat);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString LocationPoint::lonAsString() const {
|
|
|
|
return AsString(_lon);
|
|
|
|
}
|
|
|
|
|
|
|
|
MTPGeoPoint LocationPoint::toMTP() const {
|
|
|
|
return MTP_geoPoint(
|
2020-10-06 12:58:16 +00:00
|
|
|
MTP_flags(0),
|
2020-05-28 13:05:44 +00:00
|
|
|
MTP_double(_lon),
|
|
|
|
MTP_double(_lat),
|
2020-10-06 12:58:16 +00:00
|
|
|
MTP_long(_access),
|
|
|
|
MTP_int(0)); // accuracy_radius
|
2020-05-28 13:05:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float64 LocationPoint::lat() const {
|
|
|
|
return _lat;
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 LocationPoint::lon() const {
|
|
|
|
return _lon;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64 LocationPoint::accessHash() const {
|
|
|
|
return _access;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t LocationPoint::hash() const {
|
|
|
|
return QtPrivate::QHashCombine().operator()(
|
|
|
|
std::hash<float64>()(_lat),
|
|
|
|
_lon);
|
|
|
|
}
|
|
|
|
|
|
|
|
GeoPointLocation ComputeLocation(const LocationPoint &point) {
|
2024-03-23 22:04:33 +00:00
|
|
|
const auto scale = 1 + (cScale() * style::DevicePixelRatio()) / 200;
|
2019-06-21 12:27:46 +00:00
|
|
|
const auto zoom = 13 + (scale - 1);
|
|
|
|
const auto w = st::locationSize.width() / scale;
|
|
|
|
const auto h = st::locationSize.height() / scale;
|
|
|
|
|
|
|
|
auto result = GeoPointLocation();
|
|
|
|
result.lat = point.lat();
|
|
|
|
result.lon = point.lon();
|
|
|
|
result.access = point.accessHash();
|
|
|
|
result.width = w;
|
|
|
|
result.height = h;
|
|
|
|
result.zoom = zoom;
|
|
|
|
result.scale = scale;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Data
|