diff --git a/iphone/Maps/Classes/MapViewController.h b/iphone/Maps/Classes/MapViewController.h index 9c36872a52..ae5bb60ad1 100644 --- a/iphone/Maps/Classes/MapViewController.h +++ b/iphone/Maps/Classes/MapViewController.h @@ -31,7 +31,7 @@ - (id) initWithCoder: (NSCoder *)coder; - (void) OnLocation: (m2::PointD const &) mercatorPoint -withConfidenceRadius: (double) confidenceRadius + withErrorRadius: (double) errorRadius withTimestamp: (NSDate *) timestamp; - (void) OnHeading: (CLHeading*) heading; diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 1981e26e01..9edd737704 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -101,10 +101,10 @@ typedef FrameWork frame } - (void) OnLocation: (m2::PointD const &) mercatorPoint - withConfidenceRadius: (double) confidenceRadius + withErrorRadius: (double) errorRadius withTimestamp: (NSDate *) timestamp { - m_framework->SetPosition(mercatorPoint, confidenceRadius); + m_framework->SetPosition(mercatorPoint, errorRadius); if (m_isDirtyPosition) { diff --git a/iphone/Maps/Classes/UserLocationController.h b/iphone/Maps/Classes/UserLocationController.h index b5270f21e9..fc0a707970 100644 --- a/iphone/Maps/Classes/UserLocationController.h +++ b/iphone/Maps/Classes/UserLocationController.h @@ -7,7 +7,7 @@ @required - (void) OnLocation: (m2::PointD const &) mercatorPoint -withConfidenceRadius: (double) confidenceRadius + withErrorRadius: (double) errorRadius withTimestamp: (NSDate *) timestamp; - (void) OnHeading: (CLHeading *)heading; - (void) OnLocationError: (NSString *) errorDescription; diff --git a/iphone/Maps/Classes/UserLocationController.mm b/iphone/Maps/Classes/UserLocationController.mm index 3c6cca7596..629cbac419 100644 --- a/iphone/Maps/Classes/UserLocationController.mm +++ b/iphone/Maps/Classes/UserLocationController.mm @@ -62,19 +62,18 @@ didUpdateToLocation: (CLLocation *) newLocation fromLocation: (CLLocation *) oldLocation { +// NSLog(@"NewLocation: %@", [newLocation description]); m2::PointD mercPoint(MercatorBounds::LonToX(newLocation.coordinate.longitude), - MercatorBounds::LatToY(newLocation.coordinate.latitude)); + MercatorBounds::LatToY(newLocation.coordinate.latitude)); - double confidenceRadius = sqrt(newLocation.horizontalAccuracy * newLocation.horizontalAccuracy - + newLocation.verticalAccuracy * newLocation.verticalAccuracy); + m2::RectD errorRectXY = MercatorBounds::MetresToXY(newLocation.coordinate.longitude, + newLocation.coordinate.latitude, + newLocation.horizontalAccuracy); - m2::RectD errorRect = MercatorBounds::ErrorToRadius(newLocation.coordinate.longitude, - newLocation.coordinate.latitude, - confidenceRadius); + double errorRadiusXY = sqrt((errorRectXY.SizeX() * errorRectXY.SizeX() + + errorRectXY.SizeY() * errorRectXY.SizeY()) / 4); - confidenceRadius = sqrt((errorRect.SizeX() * errorRect.SizeX() + errorRect.SizeY() * errorRect.SizeY()) / 4); - - [self.delegate OnLocation: mercPoint withConfidenceRadius: confidenceRadius withTimestamp: newLocation.timestamp]; + [self.delegate OnLocation: mercPoint withErrorRadius: errorRadiusXY withTimestamp: newLocation.timestamp]; } - (void) locationManager: (CLLocationManager *) manager @@ -83,4 +82,4 @@ [self.delegate OnLocationError: [error localizedDescription]]; } -@end \ No newline at end of file +@end diff --git a/map/framework.hpp b/map/framework.hpp index c3aecb2d9b..4fb9c7126f 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -111,6 +111,7 @@ class FrameWork /// is AddRedrawCommand enabled? bool m_isRedrawEnabled; + double m_metresMinWidth; void AddRedrawCommandSure() { @@ -170,7 +171,8 @@ public: GetPlatform().PeriodicalUpdateInterval(), GetPlatform().IsBenchmarking(), GetPlatform().ScaleEtalonSize()), - m_isRedrawEnabled(true) + m_isRedrawEnabled(true), + m_metresMinWidth(20) { m_informationDisplay.setBottomShift(bottomShift); #ifdef DRAW_TOUCH_POINTS @@ -184,8 +186,8 @@ public: m_informationDisplay.enableCenter(true); m_informationDisplay.enableRuler(true); - m_informationDisplay.setRulerParams(80, 20); - m_navigator.SetMinScreenParams(80, 20); + m_informationDisplay.setRulerParams(80, m_metresMinWidth); + m_navigator.SetMinScreenParams(80, m_metresMinWidth); #ifdef DEBUG m_informationDisplay.enableDebugInfo(true); @@ -456,9 +458,15 @@ public: UpdateNow(); } - void SetPosition(m2::PointD const & mercatorPos, double confidenceRadius) + void SetPosition(m2::PointD const & mercatorPos, double errorRadius) { - m_informationDisplay.setPosition(mercatorPos, confidenceRadius); + m_informationDisplay.setPosition(mercatorPos, errorRadius); + UpdateNow(); + } + + void CenterViewport(m2::PointD const & pt) + { + m_navigator.CenterViewport(pt); UpdateNow(); } @@ -481,7 +489,35 @@ public: void CenterAndScaleViewport() { - m_navigator.CenterViewport(m_informationDisplay.position()); + m2::PointD pt = m_informationDisplay.position(); + m_navigator.CenterViewport(pt); + + m2::RectD ClipRect = m_navigator.Screen().ClipRect(); + + double errorRadius = m_informationDisplay.errorRadius(); + + double xMinSize = 6 * max(errorRadius, MercatorBounds::ConvertMetresToX(pt.x, m_metresMinWidth)); + double yMinSize = 6 * max(errorRadius, MercatorBounds::ConvertMetresToY(pt.y, m_metresMinWidth)); + + bool needToScale = false; + + if (ClipRect.SizeX() < ClipRect.SizeY()) + needToScale = ClipRect.SizeX() > xMinSize * 3; + else + needToScale = ClipRect.SizeY() > yMinSize * 3; + + if ((ClipRect.SizeX() < 3 * errorRadius) || (ClipRect.SizeY() < 3 * errorRadius)) + needToScale = true; + + if (needToScale) + { + double k = max(xMinSize / ClipRect.SizeX(), + yMinSize / ClipRect.SizeY()); + + ClipRect.Scale(k); + m_navigator.SetFromRect(ClipRect); + } + UpdateNow(); } @@ -515,12 +551,6 @@ public: Repaint(); } - void CenterViewport(m2::PointD const & pt) - { - m_navigator.CenterViewport(pt); - UpdateNow(); - } - /// @name Drag implementation. //@{ void StartDrag(DragEvent const & e) diff --git a/map/information_display.cpp b/map/information_display.cpp index 245c5dd71c..c688208a5d 100644 --- a/map/information_display.cpp +++ b/map/information_display.cpp @@ -70,11 +70,11 @@ void InformationDisplay::enablePosition(bool doEnable) m_isPositionEnabled = doEnable; } -void InformationDisplay::setPosition(m2::PointD const & mercatorPos, double confidenceRadius) +void InformationDisplay::setPosition(m2::PointD const & mercatorPos, double errorRadius) { enablePosition(true); m_position = mercatorPos; - m_confidenceRadius = confidenceRadius; + m_errorRadius = errorRadius; } m2::PointD const & InformationDisplay::position() const @@ -82,16 +82,21 @@ m2::PointD const & InformationDisplay::position() const return m_position; } +double InformationDisplay::errorRadius() const +{ + return m_errorRadius; +} + void InformationDisplay::drawPosition(DrawerYG * pDrawer) { /// Drawing position and heading m2::PointD pxPosition = m_screen.GtoP(m_position); pDrawer->drawSymbol(pxPosition, "current-position", yg::EPosCenter, yg::maxDepth); - double pxConfidenceRadius = pxPosition.Length(m_screen.GtoP(m_position + m2::PointD(m_confidenceRadius, 0))); + double pxErrorRadius = pxPosition.Length(m_screen.GtoP(m_position + m2::PointD(m_errorRadius, 0))); - pDrawer->screen()->drawArc(pxPosition, 0, math::pi * 2, pxConfidenceRadius, yg::Color(0, 0, 255, 64), yg::maxDepth - 2); - pDrawer->screen()->fillSector(pxPosition, 0, math::pi * 2, pxConfidenceRadius, yg::Color(0, 0, 255, 32), yg::maxDepth - 3); + pDrawer->screen()->drawArc(pxPosition, 0, math::pi * 2, pxErrorRadius, yg::Color(0, 0, 255, 64), yg::maxDepth - 2); + pDrawer->screen()->fillSector(pxPosition, 0, math::pi * 2, pxErrorRadius, yg::Color(0, 0, 255, 32), yg::maxDepth - 3); } void InformationDisplay::enableHeading(bool doEnable) @@ -114,19 +119,19 @@ void InformationDisplay::drawHeading(DrawerYG *pDrawer) m2::PointD pxPosition = m_screen.GtoP(m_position); - double pxConfidenceRadius = pxPosition.Length(m_screen.GtoP(m_position + m2::PointD(m_confidenceRadius, 0))); + double pxErrorRadius = pxPosition.Length(m_screen.GtoP(m_position + m2::PointD(m_errorRadius, 0))); /// true heading pDrawer->screen()->drawSector(pxPosition, trueHeadingRad + m_headingOrientation - headingAccuracyRad, trueHeadingRad + m_headingOrientation + headingAccuracyRad, - pxConfidenceRadius, + pxErrorRadius, yg::Color(255, 255, 255, 64), yg::maxDepth); pDrawer->screen()->fillSector(pxPosition, trueHeadingRad + m_headingOrientation - headingAccuracyRad, trueHeadingRad + m_headingOrientation + headingAccuracyRad, - pxConfidenceRadius, + pxErrorRadius, yg::Color(255, 255, 255, 32), yg::maxDepth - 1); /* /// magnetic heading @@ -134,13 +139,13 @@ void InformationDisplay::drawHeading(DrawerYG *pDrawer) pDrawer->screen()->drawSector(pxPosition, magneticHeadingRad + m_headingOrientation - headingAccuracyRad, magneticHeadingRad + m_headingOrientation + headingAccuracyRad, - pxConfidenceRadius, + pxErrorRadius, yg::Color(0, 255, 0, 64), yg::maxDepth); pDrawer->screen()->fillSector(pxPosition, magneticHeadingRad + m_headingOrientation - headingAccuracyRad, magneticHeadingRad + m_headingOrientation + headingAccuracyRad, - pxConfidenceRadius, + pxErrorRadius, yg::Color(0, 255, 0, 32), yg::maxDepth - 1); */ @@ -299,9 +304,7 @@ void InformationDisplay::setCenter(m2::PointD const & pt) void InformationDisplay::drawCenter(DrawerYG * drawer) { - m_yOffset += 20; ostringstream out; - //out << "(" << m_centerPt.x << ", " << m_centerPt.y << ") Scale : " << m_currentScale; out << "(" << m_centerPt.x << ", " << m_centerPt.y << ")"; m2::RectD const & textRect = drawer->screen()->textRect( out.str().c_str(), diff --git a/map/information_display.hpp b/map/information_display.hpp index f0f5822cf6..9796381d9f 100644 --- a/map/information_display.hpp +++ b/map/information_display.hpp @@ -28,7 +28,7 @@ private: bool m_isPositionEnabled; m2::PointD m_position; - double m_confidenceRadius; + double m_errorRadius; /// for debugging purposes /// up to 10 debugging points @@ -84,8 +84,9 @@ public: void setOrientation(EOrientation orientation); void enablePosition(bool doEnable); - void setPosition(m2::PointD const & mercatorPos, double confidenceRadius); + void setPosition(m2::PointD const & mercatorPos, double errorRadius); m2::PointD const & position() const; + double errorRadius() const; void drawPosition(DrawerYG * pDrawer); void enableHeading(bool doEnable);