forked from organicmaps/organicmaps-tmp
Fixed my-position state machine in case of routing and app launching
This commit is contained in:
parent
a93154ea33
commit
6d674553e8
2 changed files with 41 additions and 39 deletions
|
@ -28,7 +28,6 @@ double const kMaxPendingLocationTimeSec = 60.0;
|
|||
double const kMaxTimeInBackgroundSec = 60.0 * 60;
|
||||
double const kMaxNotFollowRoutingTimeSec = 10.0;
|
||||
double const kMaxUpdateLocationInvervalSec = 30.0;
|
||||
double const kMaxWaitStartLocationSec = 5.0;
|
||||
|
||||
int const kZoomThreshold = 10;
|
||||
int const kMaxScaleZoomLevel = 16;
|
||||
|
@ -109,7 +108,8 @@ private:
|
|||
|
||||
MyPositionController::MyPositionController(location::EMyPositionMode initMode,
|
||||
double timeInBackground, bool isFirstLaunch)
|
||||
: m_mode(initMode)
|
||||
: m_mode(location::PendingPosition)
|
||||
, m_desiredInitMode(initMode)
|
||||
, m_isFirstLaunch(isFirstLaunch)
|
||||
, m_isInRouting(false)
|
||||
, m_needBlockAnimation(false)
|
||||
|
@ -129,11 +129,14 @@ MyPositionController::MyPositionController(location::EMyPositionMode initMode,
|
|||
, m_isDirectionAssigned(false)
|
||||
{
|
||||
if (isFirstLaunch)
|
||||
{
|
||||
m_mode = location::NotFollowNoPosition;
|
||||
m_desiredInitMode = location::NotFollowNoPosition;
|
||||
}
|
||||
else if (timeInBackground >= kMaxTimeInBackgroundSec)
|
||||
m_mode = location::Follow;
|
||||
|
||||
m_startLocationTimer.Reset();
|
||||
{
|
||||
m_desiredInitMode = location::Follow;
|
||||
}
|
||||
}
|
||||
|
||||
MyPositionController::~MyPositionController()
|
||||
|
@ -333,36 +336,44 @@ void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool
|
|||
m_isDirtyViewport = true;
|
||||
}
|
||||
|
||||
if (m_mode == location::PendingPosition || m_mode == location::NotFollowNoPosition)
|
||||
if (!m_isPositionAssigned)
|
||||
{
|
||||
ChangeMode(location::Follow);
|
||||
if (!m_isFirstLaunch)
|
||||
{
|
||||
if (GetZoomLevel(screen, m_position, m_errorRadius) <= kMaxScaleZoomLevel)
|
||||
{
|
||||
m2::PointD const size(m_errorRadius, m_errorRadius);
|
||||
ChangeModelView(m2::RectD(m_position - size, m_position + size));
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeModelView(m_position, kMaxScaleZoomLevel);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!AnimationSystem::Instance().AnimationExists(Animation::MapPlane))
|
||||
ChangeModelView(m_position, kDoNotChangeZoom);
|
||||
}
|
||||
}
|
||||
else if (!m_isPositionAssigned)
|
||||
{
|
||||
ChangeMode(m_mode);
|
||||
ChangeMode(m_desiredInitMode);
|
||||
if (m_mode == location::Follow)
|
||||
ChangeModelView(m_position, kDoNotChangeZoom);
|
||||
else if (m_mode == location::FollowAndRotate)
|
||||
ChangeModelView(m_position, m_drawDirection,
|
||||
m_isInRouting ? m_centerPixelPositionRouting : m_centerPixelPosition, kDoNotChangeZoom);
|
||||
}
|
||||
else if (m_mode == location::PendingPosition || m_mode == location::NotFollowNoPosition)
|
||||
{
|
||||
if (m_isInRouting)
|
||||
{
|
||||
ChangeMode(location::FollowAndRotate);
|
||||
UpdateViewport(kMaxScaleZoomLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeMode(location::Follow);
|
||||
if (!m_isFirstLaunch)
|
||||
{
|
||||
if (GetZoomLevel(screen, m_position, m_errorRadius) <= kMaxScaleZoomLevel)
|
||||
{
|
||||
m2::PointD const size(m_errorRadius, m_errorRadius);
|
||||
ChangeModelView(m2::RectD(m_position - size, m_position + size));
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeModelView(m_position, kMaxScaleZoomLevel);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!AnimationSystem::Instance().AnimationExists(Animation::MapPlane))
|
||||
ChangeModelView(m_position, kDoNotChangeZoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_isPositionAssigned = true;
|
||||
SetIsVisible(true);
|
||||
|
@ -429,15 +440,6 @@ void MyPositionController::Render(uint32_t renderMode, ScreenBase const & screen
|
|||
ChangeMode(location::NotFollowNoPosition);
|
||||
}
|
||||
|
||||
// We do not have assigned position but mode requires location.
|
||||
// Go to Pending state if the time is up.
|
||||
if (!m_isPositionAssigned && IsInStateWithPosition() &&
|
||||
m_startLocationTimer.ElapsedSeconds() >= kMaxWaitStartLocationSec)
|
||||
{
|
||||
m_pendingTimer.Reset();
|
||||
ChangeMode(location::PendingPosition);
|
||||
}
|
||||
|
||||
if (IsInRouting() && m_mode == location::NotFollow &&
|
||||
m_routingNotFollowTimer.ElapsedSeconds() >= kMaxNotFollowRoutingTimeSec)
|
||||
{
|
||||
|
@ -534,7 +536,7 @@ void MyPositionController::SetTimeInBackground(double time)
|
|||
{
|
||||
if (time >= kMaxTimeInBackgroundSec && m_mode == location::NotFollow)
|
||||
{
|
||||
ChangeMode(location::Follow);
|
||||
ChangeMode(m_isInRouting ? location::FollowAndRotate : location::Follow);
|
||||
UpdateViewport(kDoNotChangeZoom);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,6 +126,7 @@ private:
|
|||
|
||||
private:
|
||||
location::EMyPositionMode m_mode;
|
||||
location::EMyPositionMode m_desiredInitMode;
|
||||
bool m_isFirstLaunch;
|
||||
|
||||
bool m_isInRouting;
|
||||
|
@ -147,7 +148,6 @@ private:
|
|||
my::Timer m_pendingTimer;
|
||||
my::Timer m_routingNotFollowTimer;
|
||||
my::Timer m_updateLocationTimer;
|
||||
my::Timer m_startLocationTimer;
|
||||
double m_lastLocationTimestamp;
|
||||
|
||||
m2::RectD m_pixelRect;
|
||||
|
|
Loading…
Add table
Reference in a new issue