forked from organicmaps/organicmaps
Finished location refactoring
This commit is contained in:
parent
a2139bfbfc
commit
1bfcb8df5c
5 changed files with 52 additions and 64 deletions
|
@ -516,7 +516,7 @@ public:
|
|||
|
||||
m_informationDisplay.doDraw(pDrawer);
|
||||
|
||||
InformationDisplay::DrawMyPosition(*pDrawer, m_navigator.Screen(), m_locationState);
|
||||
m_locationState.DrawMyPosition(*pDrawer, m_navigator.Screen());
|
||||
|
||||
e->drawer()->screen()->endFrame();
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "information_display.hpp"
|
||||
#include "drawer_yg.hpp"
|
||||
#include "location_state.hpp"
|
||||
|
||||
#include "../indexer/mercator.hpp"
|
||||
#include "../yg/defines.hpp"
|
||||
|
@ -16,10 +15,6 @@
|
|||
#include "../base/logging.hpp"
|
||||
#include "../base/mutex.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
using namespace location;
|
||||
|
||||
InformationDisplay::InformationDisplay()
|
||||
{
|
||||
enableDebugPoints(false);
|
||||
|
@ -50,46 +45,6 @@ void InformationDisplay::setDisplayRect(m2::RectI const & rect)
|
|||
m_displayRect = rect;
|
||||
}
|
||||
|
||||
void InformationDisplay::DrawMyPosition(DrawerYG & drawer,
|
||||
ScreenBase const & screen,
|
||||
location::State const & state)
|
||||
{
|
||||
double pxErrorRadius;
|
||||
m2::PointD pxPosition;
|
||||
if ((state & State::EGps) || (state & State::ECompass))
|
||||
{
|
||||
pxPosition = screen.GtoP(state.Position());
|
||||
pxErrorRadius = pxPosition.Length(screen.GtoP(state.Position()
|
||||
+ m2::PointD(state.ErrorRadius(), 0)));
|
||||
}
|
||||
|
||||
if (state & State::EGps)
|
||||
{
|
||||
// my position symbol
|
||||
drawer.drawSymbol(pxPosition, "current-position", yg::EPosCenter, yg::maxDepth);
|
||||
// my position circle
|
||||
drawer.screen()->fillSector(pxPosition, 0, math::pi * 2, pxErrorRadius,
|
||||
yg::Color(0, 0, 255, (state & State::EPreciseMode) ? 32 : 16),
|
||||
yg::maxDepth - 3);
|
||||
// display compass only if position is available
|
||||
if (state & State::ECompass)
|
||||
{
|
||||
drawer.screen()->drawSector(pxPosition,
|
||||
state.Heading() - state.HeadingAccuracy(),
|
||||
state.Heading() + state.HeadingAccuracy(),
|
||||
pxErrorRadius,
|
||||
yg::Color(255, 255, 255, 192),
|
||||
yg::maxDepth);
|
||||
drawer.screen()->fillSector(pxPosition,
|
||||
state.Heading() - state.HeadingAccuracy(),
|
||||
state.Heading() + state.HeadingAccuracy(),
|
||||
pxErrorRadius,
|
||||
yg::Color(255, 255, 255, 96),
|
||||
yg::maxDepth - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InformationDisplay::enableDebugPoints(bool doEnable)
|
||||
{
|
||||
m_isDebugPointsEnabled = doEnable;
|
||||
|
|
|
@ -73,10 +73,6 @@ public:
|
|||
|
||||
InformationDisplay();
|
||||
|
||||
static void DrawMyPosition(DrawerYG & drawer,
|
||||
ScreenBase const & screen,
|
||||
location::State const & state);
|
||||
|
||||
void setScreen(ScreenBase const & screen);
|
||||
void setDisplayRect(m2::RectI const & rect);
|
||||
void setBottomShift(double bottomShift);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "location_state.hpp"
|
||||
#include "drawer_yg.hpp"
|
||||
|
||||
#include "../platform/location.hpp"
|
||||
|
||||
|
@ -7,7 +8,7 @@
|
|||
namespace location
|
||||
{
|
||||
|
||||
State::State() : m_deviceOrientation(-math::pi / 2), m_type(ENone)
|
||||
State::State() : m_deviceOrientation(-math::pi / 2), m_flags(ENone)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -16,11 +17,11 @@ namespace location
|
|||
if (info.m_status == EAccurateMode
|
||||
|| info.m_status == ERoughMode)
|
||||
{
|
||||
m_type |= EGps;
|
||||
m_flags |= EGps;
|
||||
if (info.m_status == EAccurateMode)
|
||||
m_type |= EPreciseMode;
|
||||
m_flags |= EPreciseMode;
|
||||
else
|
||||
m_type &= !EPreciseMode;
|
||||
m_flags &= !EPreciseMode;
|
||||
|
||||
m_positionMercator = m2::PointD(MercatorBounds::LonToX(info.m_longitude),
|
||||
MercatorBounds::LatToY(info.m_latitude));
|
||||
|
@ -32,13 +33,13 @@ namespace location
|
|||
}
|
||||
else
|
||||
{
|
||||
m_type &= !EGps;
|
||||
m_flags &= !EGps;
|
||||
}
|
||||
}
|
||||
|
||||
void State::UpdateCompass(CompassInfo const & info)
|
||||
{
|
||||
m_type |= ECompass;
|
||||
m_flags |= ECompass;
|
||||
|
||||
m_headingRad = ((info.m_trueHeading >= 0.0) ? info.m_trueHeading : info.m_magneticHeading)
|
||||
/ 180 * math::pi;
|
||||
|
@ -63,4 +64,42 @@ namespace location
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void State::DrawMyPosition(DrawerYG & drawer, ScreenBase const & screen)
|
||||
{
|
||||
double pxErrorRadius;
|
||||
m2::PointD pxPosition;
|
||||
if ((m_flags & State::EGps) || (m_flags & State::ECompass))
|
||||
{
|
||||
pxPosition = screen.GtoP(Position());
|
||||
pxErrorRadius = pxPosition.Length(screen.GtoP(Position()
|
||||
+ m2::PointD(ErrorRadius(), 0)));
|
||||
}
|
||||
|
||||
if (m_flags & State::EGps)
|
||||
{
|
||||
// my position symbol
|
||||
drawer.drawSymbol(pxPosition, "current-position", yg::EPosCenter, yg::maxDepth);
|
||||
// my position circle
|
||||
drawer.screen()->fillSector(pxPosition, 0, math::pi * 2, pxErrorRadius,
|
||||
yg::Color(0, 0, 255, (m_flags & State::EPreciseMode) ? 32 : 16),
|
||||
yg::maxDepth - 3);
|
||||
// display compass only if position is available
|
||||
if (m_flags & State::ECompass)
|
||||
{
|
||||
drawer.screen()->drawSector(pxPosition,
|
||||
m_deviceOrientation + m_headingRad - m_headingAccuracyRad,
|
||||
m_deviceOrientation + m_headingRad + m_headingAccuracyRad,
|
||||
pxErrorRadius,
|
||||
yg::Color(255, 255, 255, 192),
|
||||
yg::maxDepth);
|
||||
drawer.screen()->fillSector(pxPosition,
|
||||
m_deviceOrientation + m_headingRad - m_headingAccuracyRad,
|
||||
m_deviceOrientation + m_headingRad + m_headingAccuracyRad,
|
||||
pxErrorRadius,
|
||||
yg::Color(255, 255, 255, 96),
|
||||
yg::maxDepth - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "../geometry/point2d.hpp"
|
||||
#include "../geometry/screenbase.hpp"
|
||||
|
||||
class DrawerYG;
|
||||
|
||||
namespace location
|
||||
{
|
||||
class GpsInfo;
|
||||
|
@ -32,24 +34,20 @@ namespace location
|
|||
double ErrorRadius() const { return m_errorRadiusMercator; }
|
||||
/// @return GPS center point in mercator
|
||||
m2::PointD Position() const { return m_positionMercator; }
|
||||
/// takes into account device's orientation
|
||||
/// @return angle in radians
|
||||
double Heading() const { return m_deviceOrientation + m_headingRad; }
|
||||
/// @return angle in radians
|
||||
double HeadingAccuracy() const { return m_headingAccuracyRad; }
|
||||
|
||||
void TurnOff() { m_type = ENone; }
|
||||
void TurnOff() { m_flags = ENone; }
|
||||
void UpdateGps(GpsInfo const & info);
|
||||
void UpdateCompass(CompassInfo const & info);
|
||||
void SetOrientation(EOrientation orientation);
|
||||
|
||||
void DrawMyPosition(DrawerYG & drawer, ScreenBase const & screen);
|
||||
operator int() const
|
||||
{
|
||||
return m_type;
|
||||
return m_flags;
|
||||
}
|
||||
|
||||
private:
|
||||
/// stores flags from SymbolType
|
||||
int m_type;
|
||||
int m_flags;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue