forked from organicmaps/organicmaps
Fixed crash on track without style
This commit is contained in:
parent
6d604f95e1
commit
1f7e2c22b3
4 changed files with 35 additions and 5 deletions
|
@ -44,6 +44,7 @@ std::string const kExtendedDataFooter =
|
|||
auto const kDefaultLang = StringUtf8Multilang::kDefaultCode;
|
||||
|
||||
auto const kDefaultTrackWidth = 5.0;
|
||||
auto const kDefaultTrackColor = 0xe51b23ff;
|
||||
|
||||
std::string Indent(size_t count)
|
||||
{
|
||||
|
@ -734,7 +735,7 @@ void KmlParser::Pop(std::string const & tag)
|
|||
TrackLayer layer;
|
||||
layer.m_lineWidth = m_trackWidth;
|
||||
layer.m_color.m_predefinedColor = PredefinedColor::None;
|
||||
layer.m_color.m_rgba = m_color;
|
||||
layer.m_color.m_rgba = (m_color != 0 ? m_color : kDefaultTrackColor);
|
||||
m_trackLayers.push_back(std::move(layer));
|
||||
|
||||
m_trackWidth = kDefaultTrackWidth;
|
||||
|
@ -859,7 +860,7 @@ void KmlParser::CharData(std::string value)
|
|||
TrackLayer layer;
|
||||
layer.m_lineWidth = GetTrackWidthForStyle(value);
|
||||
layer.m_color.m_predefinedColor = PredefinedColor::None;
|
||||
layer.m_color.m_rgba = m_color;
|
||||
layer.m_color.m_rgba = (m_color != 0 ? m_color : kDefaultTrackColor);
|
||||
m_trackLayers.push_back(std::move(layer));
|
||||
}
|
||||
else if (currTag == "description")
|
||||
|
@ -993,6 +994,15 @@ void KmlParser::CharData(std::string value)
|
|||
}
|
||||
}
|
||||
|
||||
// static
|
||||
kml::TrackLayer KmlParser::GetDefaultTrackLayer()
|
||||
{
|
||||
kml::TrackLayer layer;
|
||||
layer.m_lineWidth = kDefaultTrackWidth;
|
||||
layer.m_color.m_rgba = kDefaultTrackColor;
|
||||
return layer;
|
||||
}
|
||||
|
||||
DeserializerKml::DeserializerKml(FileData & fileData)
|
||||
: m_fileData(fileData)
|
||||
{
|
||||
|
|
|
@ -70,6 +70,8 @@ public:
|
|||
void Pop(std::string const & tag);
|
||||
void CharData(std::string value);
|
||||
|
||||
static kml::TrackLayer GetDefaultTrackLayer();
|
||||
|
||||
private:
|
||||
enum GeometryType
|
||||
{
|
||||
|
|
|
@ -11,6 +11,21 @@
|
|||
#include "coding/file_reader.hpp"
|
||||
#include "coding/file_writer.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
void ValidateKmlData(std::unique_ptr<kml::FileData> & data)
|
||||
{
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
for (auto & t : data->m_tracksData)
|
||||
{
|
||||
if (t.m_layers.empty())
|
||||
t.m_layers.emplace_back(kml::KmlParser::GetDefaultTrackLayer());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<kml::FileData> LoadKmlFile(std::string const & file, bool useBinary)
|
||||
{
|
||||
std::unique_ptr<kml::FileData> kmlData;
|
||||
|
@ -35,14 +50,15 @@ std::unique_ptr<kml::FileData> LoadKmlData(Reader const & reader, bool useBinary
|
|||
{
|
||||
if (useBinary)
|
||||
{
|
||||
kml::binary::DeserializerKml des(*data.get());
|
||||
kml::binary::DeserializerKml des(*data);
|
||||
des.Deserialize(reader);
|
||||
}
|
||||
else
|
||||
{
|
||||
kml::DeserializerKml des(*data.get());
|
||||
kml::DeserializerKml des(*data);
|
||||
des.Deserialize(reader);
|
||||
}
|
||||
ValidateKmlData(data);
|
||||
}
|
||||
catch (Reader::Exception const & e)
|
||||
{
|
||||
|
@ -69,7 +85,7 @@ std::unique_ptr<kml::FileData> LoadKmlData(Reader const & reader, bool useBinary
|
|||
|
||||
bool SaveKmlFile(kml::FileData & kmlData, std::string const & file, bool useBinary)
|
||||
{
|
||||
bool success = false;
|
||||
bool success;
|
||||
try
|
||||
{
|
||||
FileWriter writer(file);
|
||||
|
|
|
@ -57,11 +57,13 @@ size_t Track::GetLayerCount() const
|
|||
|
||||
dp::Color Track::GetColor(size_t layerIndex) const
|
||||
{
|
||||
CHECK_LESS(layerIndex, m_data.m_layers.size(), ());
|
||||
return dp::Color(m_data.m_layers[layerIndex].m_color.m_rgba);
|
||||
}
|
||||
|
||||
float Track::GetWidth(size_t layerIndex) const
|
||||
{
|
||||
CHECK_LESS(layerIndex, m_data.m_layers.size(), ());
|
||||
return static_cast<float>(m_data.m_layers[layerIndex].m_lineWidth);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue