diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2018-04-05 19:15:46 +0300 |
---|---|---|
committer | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2018-04-05 19:47:16 +0300 |
commit | c8d81293081afdb0e88ae6db27236942725e700c (patch) | |
tree | 1b051ca12d9bb6e8aa1c94f785d10f180907bc5f /kml | |
parent | c55ab01992c088f2e56caacadd6ad0fcac25d81e (diff) |
Fixed reading tracks from KML
Diffstat (limited to 'kml')
-rw-r--r-- | kml/serdes.cpp | 34 | ||||
-rw-r--r-- | kml/serdes.hpp | 4 |
2 files changed, 32 insertions, 6 deletions
diff --git a/kml/serdes.cpp b/kml/serdes.cpp index 82a37367cd..0f74787e53 100644 --- a/kml/serdes.cpp +++ b/kml/serdes.cpp @@ -605,14 +605,14 @@ void KmlParser::ParseColor(std::string const & value) m_color = ToRGBA(fromHex[3], fromHex[2], fromHex[1], fromHex[0]); } -bool KmlParser::GetColorForStyle(std::string const & styleUrl, uint32_t & color) +bool KmlParser::GetColorForStyle(std::string const & styleUrl, uint32_t & color) const { if (styleUrl.empty()) return false; // Remove leading '#' symbol auto const it = m_styleUrl2Color.find(styleUrl.substr(1)); - if (it != m_styleUrl2Color.end()) + if (it != m_styleUrl2Color.cend()) { color = it->second; return true; @@ -620,6 +620,19 @@ bool KmlParser::GetColorForStyle(std::string const & styleUrl, uint32_t & color) return false; } +double KmlParser::GetTrackWidthForStyle(std::string const & styleUrl) const +{ + if (styleUrl.empty()) + return kDefaultTrackWidth; + + // Remove leading '#' symbol + auto const it = m_styleUrl2Width.find(styleUrl.substr(1)); + if (it != m_styleUrl2Width.cend()) + return it->second; + + return kDefaultTrackWidth; +} + bool KmlParser::Push(std::string const & name) { m_tags.push_back(name); @@ -701,12 +714,18 @@ void KmlParser::Pop(std::string const & tag) if (!m_styleId.empty()) { m_styleUrl2Color[m_styleId] = m_color; + m_styleUrl2Width[m_styleId] = m_trackWidth; m_color = 0; + m_trackWidth = kDefaultTrackWidth; } } } - else if (tag == "mwm:additionalLineStyle" || tag == "LineStyle") + else if ((tag == "LineStyle" && m_tags.size() > 2 && GetTagFromEnd(2) == kPlacemark) || + (tag == "mwm:additionalLineStyle" && m_tags.size() > 3 && GetTagFromEnd(3) == kPlacemark)) { + // This code assumes that <Style> is stored inside <Placemark>. + // It is a violation of KML format, but it must be here to support + // loading of KML files which were stored by older versions of MAPS.ME. TrackLayer layer; layer.m_lineWidth = m_trackWidth; layer.m_color.m_predefinedColor = PredefinedColor::None; @@ -815,12 +834,12 @@ void KmlParser::CharData(std::string value) { m_name[kDefaultLang] = value; } - else if (currTag == "styleUrl") + else if (currTag == kStyleUrl) { // Bookmark draw style. m_predefinedColor = ExtractPlacemarkPredefinedColor(value); - // Check if url is in styleMap map. + // Track draw style. if (!GetColorForStyle(value, m_color)) { // Remove leading '#' symbol. @@ -828,6 +847,11 @@ void KmlParser::CharData(std::string value) if (!styleId.empty()) GetColorForStyle(styleId, m_color); } + TrackLayer layer; + layer.m_lineWidth = GetTrackWidthForStyle(value); + layer.m_color.m_predefinedColor = PredefinedColor::None; + layer.m_color.m_rgba = m_color; + m_trackLayers.push_back(std::move(layer)); } else if (currTag == "description") { diff --git a/kml/serdes.hpp b/kml/serdes.hpp index cbe4a63f64..bb21443cb2 100644 --- a/kml/serdes.hpp +++ b/kml/serdes.hpp @@ -85,7 +85,8 @@ private: char const * coordSeparator); bool MakeValid(); void ParseColor(std::string const &value); - bool GetColorForStyle(std::string const & styleUrl, uint32_t & color); + bool GetColorForStyle(std::string const & styleUrl, uint32_t & color) const; + double GetTrackWidthForStyle(std::string const & styleUrl) const; FileData & m_data; @@ -98,6 +99,7 @@ private: std::string m_mapStyleId; std::string m_styleUrlKey; std::map<std::string, uint32_t> m_styleUrl2Color; + std::map<std::string, double> m_styleUrl2Width; std::map<std::string, std::string> m_mapStyle2Style; int8_t m_attrCode; |