diff options
author | vng <viktor.govako@gmail.com> | 2012-05-07 11:44:55 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:38:02 +0300 |
commit | f7c8042ce06e4bbb02d1e8ef34c1c03bcdd59e27 (patch) | |
tree | 3c8611e35efb25971a8b733e4f2c335411f707b6 /map/geourl_process.cpp | |
parent | d9d5959c4f925375419be9b6450a403c9a6b5e6d (diff) |
Proces url for coordinates and viewport.
Diffstat (limited to 'map/geourl_process.cpp')
-rw-r--r-- | map/geourl_process.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/map/geourl_process.cpp b/map/geourl_process.cpp new file mode 100644 index 0000000000..f22f490a87 --- /dev/null +++ b/map/geourl_process.cpp @@ -0,0 +1,104 @@ +#include "geourl_process.hpp" + +#include "../indexer/scales.hpp" +#include "../indexer/mercator.hpp" + +#include "../base/string_utils.hpp" + + +namespace url_scheme +{ + void Info::Reset() + { + m_lat = m_lon = EmptyValue(); + m_zoom = scales::GetUpperScale(); + } + + m2::RectD Info::GetViewport() const + { + ASSERT ( IsValid(), () ); + + return scales::GetRectForLevel(m_zoom, + m2::PointD(MercatorBounds::LonToX(m_lon), + MercatorBounds::LatToY(m_lat)), + 1.0); + } + + + class DoParse + { + Info & m_info; + + enum TMode { START, LAT, LON, ZOOM, FINISH }; + TMode m_mode; + + static void ToDouble(string const & token, double & d) + { + double temp; + if (strings::to_double(token, temp)) + d = temp; + } + + bool CheckKeyword(string const & token) + { + if (token == "lat" || token == "point") + m_mode = LAT; + else if (token == "lon") + m_mode = LON; + else if (token == "zoom") + m_mode = ZOOM; + else + return false; + + return true; + } + + public: + DoParse(Info & info) : m_info(info), m_mode(START) + { + } + + void operator()(string const & token) + { + switch (m_mode) + { + case START: + ASSERT(token == "geo" || token == "mapswithme", (token)); + m_mode = LAT; + break; + + case LAT: + if (!CheckKeyword(token)) + { + ToDouble(token, m_info.m_lat); + m_mode = LON; + } + break; + + case LON: + if (!CheckKeyword(token)) + { + ToDouble(token, m_info.m_lon); + m_mode = ZOOM; + } + break; + + case ZOOM: + if (!CheckKeyword(token)) + { + ToDouble(token, m_info.m_zoom); + m_mode = FINISH; + } + break; + + default: + break; + } + } + }; + + void ParseURL(string const & s, Info & info) + { + strings::Tokenize(s, ":/?&=,", DoParse(info)); + } +} |