forked from organicmaps/organicmaps
[search] Simplify ReverseGeocoder interface.
This commit is contained in:
parent
86d7c1f50a
commit
a774050c4c
4 changed files with 35 additions and 87 deletions
|
@ -2959,27 +2959,22 @@ void SetStreet(search::ReverseGeocoder const & coder, DataSource const & dataSou
|
|||
auto const & editor = osm::Editor::Instance();
|
||||
// Get exact feature's street address (if any) from mwm,
|
||||
// together with all nearby streets.
|
||||
auto const streets = coder.GetNearbyFeatureStreets(ft);
|
||||
auto const & streetsPool = streets.first;
|
||||
auto const & featureStreetIndex = streets.second;
|
||||
vector<search::ReverseGeocoder::Street> streets;
|
||||
coder.GetNearbyStreets(ft, streets);
|
||||
|
||||
string street;
|
||||
bool const featureIsInEditor = editor.GetEditedFeatureStreet(ft.GetID(), street);
|
||||
bool const featureHasStreetInMwm = featureStreetIndex < streetsPool.size();
|
||||
if (!featureIsInEditor && featureHasStreetInMwm)
|
||||
street = streetsPool[featureStreetIndex].m_name;
|
||||
string street = coder.GetFeatureStreetName(ft);
|
||||
|
||||
auto localizedStreets = TakeSomeStreetsAndLocalize(streetsPool, dataSource);
|
||||
auto localizedStreets = TakeSomeStreetsAndLocalize(streets, dataSource);
|
||||
|
||||
if (!street.empty())
|
||||
{
|
||||
auto it = find_if(begin(streetsPool), end(streetsPool),
|
||||
auto it = find_if(begin(streets), end(streets),
|
||||
[&street](search::ReverseGeocoder::Street const & s)
|
||||
{
|
||||
return s.m_name == street;
|
||||
});
|
||||
|
||||
if (it != end(streetsPool))
|
||||
if (it != end(streets))
|
||||
{
|
||||
osm::LocalizedStreet ls;
|
||||
if (!LocalizeStreet(dataSource, it->m_id, ls))
|
||||
|
@ -3149,9 +3144,7 @@ osm::Editor::SaveResult Framework::SaveEditedMapObject(osm::EditableMapObject em
|
|||
string originalFeatureStreet;
|
||||
if (!isCreatedFeature)
|
||||
{
|
||||
auto const streets = coder.GetNearbyFeatureStreets(originalFeature);
|
||||
if (streets.second < streets.first.size())
|
||||
originalFeatureStreet = streets.first[streets.second].m_name;
|
||||
originalFeatureStreet = coder.GetOriginalFeatureStreetName(originalFeature);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -29,10 +29,7 @@ unique_ptr<FeatureType> EditorDelegate::GetOriginalFeature(FeatureID const & fid
|
|||
string EditorDelegate::GetOriginalFeatureStreet(FeatureType & ft) const
|
||||
{
|
||||
search::ReverseGeocoder const coder(m_dataSource);
|
||||
auto const streets = coder.GetNearbyOriginalFeatureStreets(ft);
|
||||
if (streets.second < streets.first.size())
|
||||
return streets.first[streets.second].m_name;
|
||||
return {};
|
||||
return coder.GetOriginalFeatureStreetName(ft);
|
||||
}
|
||||
|
||||
void EditorDelegate::ForEachFeatureAtPoint(osm::Editor::FeatureTypeFn && fn,
|
||||
|
|
|
@ -52,23 +52,6 @@ void AddStreet(FeatureType & ft, m2::PointD const & center,
|
|||
|
||||
streets.emplace_back(ft.GetID(), feature::GetMinDistanceMeters(ft, center), name);
|
||||
}
|
||||
|
||||
void GetNearbyStreetsImpl(DataSource const & source, MwmSet::MwmId const & id,
|
||||
m2::PointD const & center, vector<ReverseGeocoder::Street> & streets,
|
||||
FillStreets && fillStreets)
|
||||
{
|
||||
m2::RectD const rect = GetLookupRect(center, ReverseGeocoder::kLookupRadiusM);
|
||||
MwmSet::MwmHandle mwmHandle = source.GetMwmHandleById(id);
|
||||
|
||||
if (!mwmHandle.IsAlive())
|
||||
return;
|
||||
|
||||
auto const addStreet = [¢er, &streets](FeatureType & ft) { AddStreet(ft, center, streets); };
|
||||
|
||||
fillStreets(move(mwmHandle), rect, addStreet);
|
||||
|
||||
sort(streets.begin(), streets.end(), base::LessBy(&ReverseGeocoder::Street::m_distanceMeters));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
ReverseGeocoder::ReverseGeocoder(DataSource const & dataSource) : m_dataSource(dataSource) {}
|
||||
|
@ -88,13 +71,12 @@ void ReverseGeocoder::GetNearbyStreets(search::MwmContext & context, m2::PointD
|
|||
void ReverseGeocoder::GetNearbyStreets(MwmSet::MwmId const & id, m2::PointD const & center,
|
||||
vector<Street> & streets) const
|
||||
{
|
||||
auto const fillStreets = [](MwmSet::MwmHandle && handle, m2::RectD const & rect,
|
||||
AppendStreet && addStreet)
|
||||
MwmSet::MwmHandle mwmHandle = m_dataSource.GetMwmHandleById(id);
|
||||
if (mwmHandle.IsAlive())
|
||||
{
|
||||
search::MwmContext(move(handle)).ForEachFeature(rect, addStreet);
|
||||
};
|
||||
|
||||
GetNearbyStreetsImpl(m_dataSource, id, center, streets, move(fillStreets));
|
||||
search::MwmContext context(move(mwmHandle));
|
||||
GetNearbyStreets(context, center, streets);
|
||||
}
|
||||
}
|
||||
|
||||
void ReverseGeocoder::GetNearbyStreets(FeatureType & ft, vector<Street> & streets) const
|
||||
|
@ -103,18 +85,6 @@ void ReverseGeocoder::GetNearbyStreets(FeatureType & ft, vector<Street> & street
|
|||
GetNearbyStreets(ft.GetID().m_mwmId, feature::GetCenter(ft), streets);
|
||||
}
|
||||
|
||||
void ReverseGeocoder::GetNearbyOriginalStreets(MwmSet::MwmId const & id, m2::PointD const & center,
|
||||
vector<Street> & streets) const
|
||||
{
|
||||
auto const fillStreets = [](MwmSet::MwmHandle && handle, m2::RectD const & rect,
|
||||
AppendStreet && addStreet)
|
||||
{
|
||||
search::MwmContext(move(handle)).ForEachOriginalFeature(rect, addStreet);
|
||||
};
|
||||
|
||||
GetNearbyStreetsImpl(m_dataSource, id, center, streets, move(fillStreets));
|
||||
}
|
||||
|
||||
// static
|
||||
size_t ReverseGeocoder::GetMatchedStreetIndex(strings::UniString const & keyName,
|
||||
vector<Street> const & streets)
|
||||
|
@ -148,33 +118,20 @@ size_t ReverseGeocoder::GetMatchedStreetIndex(strings::UniString const & keyName
|
|||
return result;
|
||||
}
|
||||
|
||||
pair<vector<ReverseGeocoder::Street>, uint32_t>
|
||||
ReverseGeocoder::GetNearbyFeatureStreets(FeatureType & ft) const
|
||||
string ReverseGeocoder::GetFeatureStreetName(FeatureType & ft) const
|
||||
{
|
||||
pair<vector<ReverseGeocoder::Street>, uint32_t> result;
|
||||
|
||||
GetNearbyStreets(ft, result.first);
|
||||
|
||||
Address addr;
|
||||
HouseTable table(m_dataSource);
|
||||
if (!table.Get(ft.GetID(), result.second))
|
||||
result.second = numeric_limits<uint32_t>::max();
|
||||
|
||||
return result;
|
||||
GetNearbyAddress(table, FromFeature(ft, 0.0 /* distMeters */), false /* ignoreEdits */, addr);
|
||||
return addr.m_street.m_name;
|
||||
}
|
||||
|
||||
pair<vector<ReverseGeocoder::Street>, uint32_t>
|
||||
ReverseGeocoder::GetNearbyOriginalFeatureStreets(FeatureType & ft) const
|
||||
string ReverseGeocoder::GetOriginalFeatureStreetName(FeatureType & ft) const
|
||||
{
|
||||
pair<vector<ReverseGeocoder::Street>, uint32_t> result;
|
||||
|
||||
ASSERT(ft.GetID().IsValid(), ());
|
||||
GetNearbyOriginalStreets(ft.GetID().m_mwmId, feature::GetCenter(ft), result.first);
|
||||
|
||||
Address addr;
|
||||
HouseTable table(m_dataSource);
|
||||
if (!table.Get(ft.GetID(), result.second))
|
||||
result.second = numeric_limits<uint32_t>::max();
|
||||
|
||||
return result;
|
||||
GetNearbyAddress(table, FromFeature(ft, 0.0 /* distMeters */), true /* ignoreEdits */, addr);
|
||||
return addr.m_street.m_name;
|
||||
}
|
||||
|
||||
void ReverseGeocoder::GetNearbyAddress(m2::PointD const & center, Address & addr) const
|
||||
|
@ -195,7 +152,8 @@ void ReverseGeocoder::GetNearbyAddress(m2::PointD const & center, double maxDist
|
|||
{
|
||||
// It's quite enough to analize nearest kMaxNumTriesToApproxAddress houses for the exact nearby address.
|
||||
// When we can't guarantee suitable address for the point with distant houses.
|
||||
if (GetNearbyAddress(table, b, addr) || (++triesCount == kMaxNumTriesToApproxAddress))
|
||||
if (GetNearbyAddress(table, b, false /* ignoreEdits */, addr) ||
|
||||
(++triesCount == kMaxNumTriesToApproxAddress))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -205,14 +163,15 @@ bool ReverseGeocoder::GetExactAddress(FeatureType & ft, Address & addr) const
|
|||
if (ft.GetHouseNumber().empty())
|
||||
return false;
|
||||
HouseTable table(m_dataSource);
|
||||
return GetNearbyAddress(table, FromFeature(ft, 0.0 /* distMeters */), addr);
|
||||
return GetNearbyAddress(table, FromFeature(ft, 0.0 /* distMeters */), false /* ignoreEdits */,
|
||||
addr);
|
||||
}
|
||||
|
||||
bool ReverseGeocoder::GetNearbyAddress(HouseTable & table, Building const & bld,
|
||||
bool ReverseGeocoder::GetNearbyAddress(HouseTable & table, Building const & bld, bool ignoreEdits,
|
||||
Address & addr) const
|
||||
{
|
||||
string street;
|
||||
if (osm::Editor::Instance().GetEditedFeatureStreet(bld.m_id, street))
|
||||
if (!ignoreEdits && osm::Editor::Instance().GetEditedFeatureStreet(bld.m_id, street))
|
||||
{
|
||||
addr.m_building = bld;
|
||||
addr.m_street.m_name = street;
|
||||
|
|
|
@ -86,15 +86,12 @@ public:
|
|||
void GetNearbyStreets(MwmSet::MwmId const & id, m2::PointD const & center,
|
||||
std::vector<Street> & streets) const;
|
||||
void GetNearbyStreets(FeatureType & ft, std::vector<Street> & streets) const;
|
||||
void GetNearbyOriginalStreets(MwmSet::MwmId const & id, m2::PointD const & center,
|
||||
std::vector<Street> & streets) const;
|
||||
|
||||
/// @returns [a lot of] nearby feature's streets and an index of a feature's street.
|
||||
/// Returns a value greater than vector size when there are no Street the feature belongs to.
|
||||
/// @note returned vector can contain duplicated street segments.
|
||||
std::pair<std::vector<Street>, uint32_t> GetNearbyFeatureStreets(FeatureType & ft) const;
|
||||
/// Same as GetNearbyFeatureStreets but returns streets from MWM only.
|
||||
std::pair<std::vector<Street>, uint32_t> GetNearbyOriginalFeatureStreets(FeatureType & ft) const;
|
||||
/// @return feature street name.
|
||||
/// Returns empty string when there is no street the feature belongs to.
|
||||
std::string GetFeatureStreetName(FeatureType & ft) const;
|
||||
/// Same with GetFeatureStreetName but gets street from mwm only (not editor).
|
||||
std::string GetOriginalFeatureStreetName(FeatureType & ft) const;
|
||||
|
||||
/// @return The nearest exact address where building has house number and valid street match.
|
||||
void GetNearbyAddress(m2::PointD const & center, Address & addr) const;
|
||||
|
@ -120,7 +117,9 @@ private:
|
|||
MwmSet::MwmHandle m_handle;
|
||||
};
|
||||
|
||||
bool GetNearbyAddress(HouseTable & table, Building const & bld, Address & addr) const;
|
||||
/// Ignores changes from editor if |ignoreEdits| is true.
|
||||
bool GetNearbyAddress(HouseTable & table, Building const & bld, bool ignoreEdits,
|
||||
Address & addr) const;
|
||||
|
||||
/// @return Sorted by distance houses vector with valid house number.
|
||||
void GetNearbyBuildings(m2::PointD const & center, double maxDistanceM,
|
||||
|
|
Loading…
Add table
Reference in a new issue