forked from organicmaps/organicmaps
Edited features support in the Index.
This commit is contained in:
parent
2eb1db0912
commit
8f4f450aec
2 changed files with 64 additions and 18 deletions
|
@ -119,6 +119,11 @@ bool Index::FeaturesLoaderGuard::IsWorld() const
|
|||
|
||||
void Index::FeaturesLoaderGuard::GetFeatureByIndex(uint32_t index, FeatureType & ft) const
|
||||
{
|
||||
m_vector.GetByIndex(index, ft);
|
||||
ft.SetID(FeatureID(m_handle.GetId(), index));
|
||||
FeatureID const fid(m_handle.GetId(), index);
|
||||
ASSERT(!m_editor.IsFeatureDeleted(fid), ("Deleted feature was cached. Please review your code."));
|
||||
if (!m_editor.Instance().GetEditedFeature(fid, ft))
|
||||
{
|
||||
m_vector.GetByIndex(index, ft);
|
||||
ft.SetID(fid);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "indexer/features_offsets_table.hpp"
|
||||
#include "indexer/features_vector.hpp"
|
||||
#include "indexer/mwm_set.hpp"
|
||||
#include "indexer/osm_editor.hpp"
|
||||
#include "indexer/scale_index.hpp"
|
||||
#include "indexer/unique_index.hpp"
|
||||
|
||||
|
@ -92,9 +93,16 @@ private:
|
|||
template <typename F> class ReadMWMFunctor
|
||||
{
|
||||
F & m_f;
|
||||
osm::Editor & m_editor = osm::Editor::Instance();
|
||||
public:
|
||||
ReadMWMFunctor(F & f) : m_f(f) {}
|
||||
|
||||
/// Used by Editor to inject new features.
|
||||
void operator()(FeatureType & feature)
|
||||
{
|
||||
m_f(feature);
|
||||
}
|
||||
|
||||
void operator()(MwmHandle const & handle, covering::CoveringGetter & cov, uint32_t scale) const
|
||||
{
|
||||
MwmValue const * pValue = handle.GetValue<MwmValue>();
|
||||
|
@ -122,18 +130,26 @@ private:
|
|||
|
||||
for (auto const & i : interval)
|
||||
{
|
||||
index.ForEachInIntervalAndScale([&] (uint32_t index)
|
||||
{
|
||||
if (checkUnique(index))
|
||||
{
|
||||
FeatureType feature;
|
||||
|
||||
fv.GetByIndex(index, feature);
|
||||
feature.SetID(FeatureID(mwmID, index));
|
||||
|
||||
m_f(feature);
|
||||
}
|
||||
}, i.first, i.second, scale);
|
||||
index.ForEachInIntervalAndScale(
|
||||
[&](uint32_t index)
|
||||
{
|
||||
FeatureID const fid(mwmID, index);
|
||||
if (m_editor.IsFeatureDeleted(fid))
|
||||
return;
|
||||
FeatureType feature;
|
||||
if (m_editor.GetEditedFeature(fid, feature))
|
||||
{
|
||||
m_f(feature);
|
||||
return;
|
||||
}
|
||||
if (checkUnique(index))
|
||||
{
|
||||
fv.GetByIndex(index, feature);
|
||||
feature.SetID(fid);
|
||||
m_f(feature);
|
||||
}
|
||||
},
|
||||
i.first, i.second, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,9 +158,16 @@ private:
|
|||
template <typename F> class ReadFeatureIndexFunctor
|
||||
{
|
||||
F & m_f;
|
||||
osm::Editor & m_editor = osm::Editor::Instance();
|
||||
public:
|
||||
ReadFeatureIndexFunctor(F & f) : m_f(f) {}
|
||||
|
||||
/// Used by Editor to inject new features.
|
||||
void operator()(FeatureID const & fid) const
|
||||
{
|
||||
m_f(fid);
|
||||
}
|
||||
|
||||
void operator()(MwmHandle const & handle, covering::CoveringGetter & cov, uint32_t scale) const
|
||||
{
|
||||
MwmValue const * pValue = handle.GetValue<MwmValue>();
|
||||
|
@ -171,8 +194,9 @@ private:
|
|||
{
|
||||
index.ForEachInIntervalAndScale([&] (uint32_t index)
|
||||
{
|
||||
if (checkUnique(index))
|
||||
m_f(FeatureID(mwmID, index));
|
||||
FeatureID const fid(mwmID, index);
|
||||
if (!m_editor.IsFeatureDeleted(fid) && checkUnique(index))
|
||||
m_f(fid);
|
||||
}, i.first, i.second, scale);
|
||||
}
|
||||
}
|
||||
|
@ -215,6 +239,7 @@ public:
|
|||
{
|
||||
auto fidIter = features.begin();
|
||||
auto const endIter = features.end();
|
||||
auto & editor = osm::Editor::Instance();
|
||||
while (fidIter != endIter)
|
||||
{
|
||||
MwmId const & id = fidIter->m_mwmId;
|
||||
|
@ -225,9 +250,13 @@ public:
|
|||
FeaturesVector const featureReader(pValue->m_cont, pValue->GetHeader(), pValue->m_table);
|
||||
do
|
||||
{
|
||||
ASSERT(!editor.IsFeatureDeleted(*fidIter), ("Deleted feature was cached. Please review your code."));
|
||||
FeatureType featureType;
|
||||
featureReader.GetByIndex(fidIter->m_index, featureType);
|
||||
featureType.SetID(*fidIter);
|
||||
if (!editor.GetEditedFeature(*fidIter, featureType))
|
||||
{
|
||||
featureReader.GetByIndex(fidIter->m_index, featureType);
|
||||
featureType.SetID(*fidIter);
|
||||
}
|
||||
f(featureType);
|
||||
}
|
||||
while (++fidIter != endIter && id == fidIter->m_mwmId);
|
||||
|
@ -255,6 +284,7 @@ public:
|
|||
private:
|
||||
MwmHandle m_handle;
|
||||
FeaturesVector m_vector;
|
||||
osm::Editor & m_editor = osm::Editor::Instance();
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
|
@ -282,6 +312,8 @@ private:
|
|||
|
||||
MwmId worldID[2];
|
||||
|
||||
osm::Editor & editor = osm::Editor::Instance();
|
||||
|
||||
for (shared_ptr<MwmInfo> const & info : mwms)
|
||||
{
|
||||
if (info->m_minScale <= scale && scale <= info->m_maxScale &&
|
||||
|
@ -294,6 +326,9 @@ private:
|
|||
{
|
||||
MwmHandle const handle = GetMwmHandleById(id);
|
||||
f(handle, cov, scale);
|
||||
// Check created features container.
|
||||
// Need to do it on a per-mwm basis, because Drape relies on features in a sorted order.
|
||||
editor.ForEachFeatureInMwmRectAndScale(id, f, rect, scale);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -312,12 +347,18 @@ private:
|
|||
{
|
||||
MwmHandle const handle = GetMwmHandleById(worldID[0]);
|
||||
f(handle, cov, scale);
|
||||
// Check edited/created features container.
|
||||
// Need to do it on a per-mwm basis, because Drape relies on features in a sorted order.
|
||||
editor.ForEachFeatureInMwmRectAndScale(worldID[0], f, rect, scale);
|
||||
}
|
||||
|
||||
if (worldID[1].IsAlive())
|
||||
{
|
||||
MwmHandle const handle = GetMwmHandleById(worldID[1]);
|
||||
f(handle, cov, scale);
|
||||
// Check edited/created features container.
|
||||
// Need to do it on a per-mwm basis, because Drape relies on features in a sorted order.
|
||||
editor.ForEachFeatureInMwmRectAndScale(worldID[1], f, rect, scale);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue