forked from organicmaps/organicmaps-tmp
[drape] draw road numbers
This commit is contained in:
parent
34a3eb7557
commit
38fdec0664
7 changed files with 64 additions and 15 deletions
|
@ -265,9 +265,11 @@ void ApplyAreaFeature::ProcessRule(Stylist::rule_wrapper_t const & rule)
|
|||
|
||||
ApplyLineFeature::ApplyLineFeature(EngineContext & context, TileKey tileKey,
|
||||
FeatureID const & id, CaptionDescription const & captions,
|
||||
double nextModelViewScale)
|
||||
double currentScaleGtoP,
|
||||
double nextScaleGtoP)
|
||||
: TBase(context, tileKey, id, captions)
|
||||
, m_nextModelViewScale(nextModelViewScale)
|
||||
, m_currentScaleGtoP(currentScaleGtoP)
|
||||
, m_nextScaleGtoP(nextScaleGtoP)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -328,7 +330,7 @@ void ApplyLineFeature::ProcessRule(Stylist::rule_wrapper_t const & rule)
|
|||
params.m_step = symRule.offset() * mainScale;
|
||||
params.m_offset = symRule.step() * mainScale;
|
||||
|
||||
m_context.InsertShape(m_tileKey, dp::MovePointer<MapShape>(new PathSymbolShape(m_spline, params, m_nextModelViewScale)));
|
||||
m_context.InsertShape(m_tileKey, dp::MovePointer<MapShape>(new PathSymbolShape(m_spline, params, m_nextScaleGtoP)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -340,4 +342,43 @@ void ApplyLineFeature::ProcessRule(Stylist::rule_wrapper_t const & rule)
|
|||
}
|
||||
}
|
||||
|
||||
void ApplyLineFeature::Finish()
|
||||
{
|
||||
string const & roadNumber = m_captions.GetRoadNumber();
|
||||
if (roadNumber.empty())
|
||||
return;
|
||||
|
||||
double pathPixelLength = m_spline->GetLength() * m_currentScaleGtoP;
|
||||
int const textHeight = static_cast<int>(11 * df::VisualParams::Instance().GetVisualScale());
|
||||
|
||||
// I don't know why we draw by this, but it's work before and will work now
|
||||
if (pathPixelLength > (roadNumber.size() + 2) * textHeight)
|
||||
{
|
||||
// TODO in future we need to choose emptySpace according GtoP scale.
|
||||
double const emptySpace = 1000.0;
|
||||
int const count = static_cast<int>((pathPixelLength / emptySpace) + 2);
|
||||
double const splineStep = pathPixelLength / count;
|
||||
|
||||
FontDecl font;
|
||||
font.m_color = dp::Color(150, 75, 0, 255);
|
||||
font.m_needOutline = true;
|
||||
font.m_outlineColor = dp::Color(255, 255, 255, 255);
|
||||
font.m_size = textHeight;
|
||||
|
||||
TextViewParams viewParams;
|
||||
viewParams.m_depth = 0;
|
||||
viewParams.m_anchor = dp::Center;
|
||||
viewParams.m_featureID = FeatureID();
|
||||
viewParams.m_primaryText = roadNumber;
|
||||
viewParams.m_primaryTextFont = font;
|
||||
|
||||
m2::Spline::iterator it = m_spline.CreateIterator();
|
||||
while (!it.BeginAgain())
|
||||
{
|
||||
m_context.InsertShape(m_tileKey, dp::MovePointer<MapShape>(new TextShape(it.m_pos, viewParams)));
|
||||
it.Step(splineStep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace df
|
||||
|
|
|
@ -88,15 +88,18 @@ public:
|
|||
TileKey tileKey,
|
||||
FeatureID const & id,
|
||||
CaptionDescription const & captions,
|
||||
double nextModelViewScale);
|
||||
double currentScaleGtoP,
|
||||
double nextScaleGtoP);
|
||||
|
||||
void operator ()(CoordPointT const & point);
|
||||
bool HasGeometry() const;
|
||||
void ProcessRule(Stylist::rule_wrapper_t const & rule);
|
||||
void Finish();
|
||||
|
||||
private:
|
||||
m2::SharedSpline m_spline;
|
||||
double m_nextModelViewScale;
|
||||
double m_currentScaleGtoP;
|
||||
double m_nextScaleGtoP;
|
||||
};
|
||||
|
||||
} // namespace df
|
||||
|
|
|
@ -82,16 +82,18 @@ private:
|
|||
float m_symbolHalfHeight;
|
||||
};
|
||||
|
||||
PathSymbolShape::PathSymbolShape(m2::SharedSpline const & spline, PathSymbolViewParams const & params, float maxScale)
|
||||
PathSymbolShape::PathSymbolShape(m2::SharedSpline const & spline,
|
||||
PathSymbolViewParams const & params,
|
||||
float nextScaleGtoP)
|
||||
: m_params(params)
|
||||
, m_spline(spline)
|
||||
, m_maxScale(1.0f / maxScale)
|
||||
, m_nextScaleGtoP(nextScaleGtoP)
|
||||
{
|
||||
}
|
||||
|
||||
void PathSymbolShape::Draw(dp::RefPointer<dp::Batcher> batcher, dp::RefPointer<dp::TextureSetHolder> textures) const
|
||||
{
|
||||
int maxCount = (m_spline->GetLength() * m_maxScale - m_params.m_offset) / m_params.m_step + 1;
|
||||
int maxCount = (m_spline->GetLength() * m_nextScaleGtoP - m_params.m_offset) / m_params.m_step + 1;
|
||||
if (maxCount <= 0)
|
||||
return;
|
||||
|
||||
|
|
|
@ -15,13 +15,13 @@ namespace df
|
|||
class PathSymbolShape : public MapShape
|
||||
{
|
||||
public:
|
||||
PathSymbolShape(m2::SharedSpline const & spline, PathSymbolViewParams const & params, float maxScale);
|
||||
PathSymbolShape(m2::SharedSpline const & spline, PathSymbolViewParams const & params, float nextScaleGtoP);
|
||||
virtual void Draw(dp::RefPointer<dp::Batcher> batcher, dp::RefPointer<dp::TextureSetHolder> textures) const;
|
||||
|
||||
private:
|
||||
PathSymbolViewParams m_params;
|
||||
m2::SharedSpline m_spline;
|
||||
float m_maxScale;
|
||||
float m_nextScaleGtoP;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -23,11 +23,12 @@ RuleDrawer::RuleDrawer(drawer_callback_fn const & fn, TileKey const & tileKey, E
|
|||
int32_t tileSize = df::VisualParams::Instance().GetTileSize();
|
||||
m_geometryConvertor.OnSize(0, 0, tileSize, tileSize);
|
||||
m_geometryConvertor.SetFromRect(m2::AnyRectD(m_globalRect));
|
||||
m_currentScaleGtoP = 1.0f / m_geometryConvertor.GetScale();
|
||||
|
||||
int nextDrawScale = df::GetDrawTileScale(m_globalRect) + 1;
|
||||
m2::RectD nextScaleRect = df::GetRectForDrawScale(nextDrawScale, m_globalRect.Center());
|
||||
ScreenBase nextScaleScreen(m2::RectI(m_geometryConvertor.PixelRect()), m2::AnyRectD(nextScaleRect));
|
||||
m_nextModelViewScale = nextScaleScreen.GetScale();
|
||||
m_nextScaleGtoP = 1.0f / nextScaleScreen.GetScale();
|
||||
}
|
||||
|
||||
void RuleDrawer::operator()(FeatureType const & f)
|
||||
|
@ -64,12 +65,14 @@ void RuleDrawer::operator()(FeatureType const & f)
|
|||
}
|
||||
else if (s.LineStyleExists())
|
||||
{
|
||||
ApplyLineFeature apply(m_context, m_tileKey, f.GetID(), s.GetCaptionDescription(), m_nextModelViewScale);
|
||||
ApplyLineFeature apply(m_context, m_tileKey, f.GetID(),
|
||||
s.GetCaptionDescription(),
|
||||
m_currentScaleGtoP, m_nextScaleGtoP);
|
||||
f.ForEachPointRef(apply, m_tileKey.m_zoomLevel);
|
||||
|
||||
if (apply.HasGeometry())
|
||||
s.ForEachRule(bind(&ApplyLineFeature::ProcessRule, &apply, _1));
|
||||
//apply.Finish();
|
||||
apply.Finish();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -33,7 +33,8 @@ private:
|
|||
EngineContext & m_context;
|
||||
m2::RectD m_globalRect;
|
||||
ScreenBase m_geometryConvertor;
|
||||
double m_nextModelViewScale;
|
||||
double m_currentScaleGtoP;
|
||||
double m_nextScaleGtoP;
|
||||
set<string> m_coastlines;
|
||||
};
|
||||
|
||||
|
|
|
@ -82,5 +82,4 @@ struct PathSymbolViewParams : CommonViewParams
|
|||
float m_step;
|
||||
};
|
||||
|
||||
|
||||
} // namespace df
|
||||
|
|
Loading…
Add table
Reference in a new issue