forked from organicmaps/organicmaps
Transform area feature to point feature when no area-only drawing rules found (draw only name or symbol).
This commit is contained in:
parent
1f008f1b0e
commit
b86da3ddc7
3 changed files with 30 additions and 4 deletions
|
@ -30,6 +30,18 @@ bool FeatureBuilder1::IsGeometryClosed() const
|
|||
return (poly.size() > 2 && poly.front() == poly.back());
|
||||
}
|
||||
|
||||
m2::PointD FeatureBuilder1::GetGeometryCenter() const
|
||||
{
|
||||
ASSERT ( IsGeometryClosed(), () );
|
||||
m2::PointD ret(0.0, 0.0);
|
||||
|
||||
points_t const & poly = GetGeometry();
|
||||
size_t const count = poly.size();
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
ret += poly[i];
|
||||
return (ret / count);
|
||||
}
|
||||
|
||||
void FeatureBuilder1::SetCenter(m2::PointD const & p)
|
||||
{
|
||||
m_Center = p;
|
||||
|
|
|
@ -69,6 +69,7 @@ public:
|
|||
FeatureBase GetFeatureBase() const;
|
||||
|
||||
bool IsGeometryClosed() const;
|
||||
m2::PointD GetGeometryCenter() const;
|
||||
|
||||
inline size_t GetPointsCount() const { return GetGeometry().size(); }
|
||||
inline size_t GetPolygonsCount() const { return m_Polygons.size(); }
|
||||
|
|
|
@ -403,14 +403,27 @@ protected:
|
|||
if (count < 2)
|
||||
return;
|
||||
|
||||
bool const isClosed = (count > 2 && ft.IsGeometryClosed());
|
||||
|
||||
// Try to set area feature (point and linear types are also suitable for this)
|
||||
if (feature::IsDrawableLike(fValue.m_Types, FEATURE_TYPE_AREA) &&
|
||||
(count > 2) && ft.IsGeometryClosed())
|
||||
{
|
||||
if (isClosed && feature::IsDrawableLike(fValue.m_Types, FEATURE_TYPE_AREA))
|
||||
base_type::FinishAreaFeature(id, ft);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isClosed)
|
||||
{
|
||||
// Make point feature (in center) if geometry is closed and has point drawing rules.
|
||||
FeatureParams params(fValue);
|
||||
if (feature::RemoveNoDrawableTypes(params.m_Types, FEATURE_TYPE_POINT))
|
||||
{
|
||||
feature_t f;
|
||||
f.SetParams(params);
|
||||
f.SetCenter(ft.GetGeometryCenter());
|
||||
if (f.PreSerialize())
|
||||
base_type::m_emitter(f);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to set linear feature:
|
||||
// - it's a coastline, OR
|
||||
// - has linear types (remove others)
|
||||
|
|
Loading…
Add table
Reference in a new issue