diff --git a/src/Tiles/Projections/BaseProjection.h b/src/Tiles/Projections/BaseProjection.h index acaae3c1..56915bf5 100644 --- a/src/Tiles/Projections/BaseProjection.h +++ b/src/Tiles/Projections/BaseProjection.h @@ -91,7 +91,7 @@ class BaseProjection void GetTileMatrixSizeXY(int zoom, CSize &ret); void getTileRectXY(Extent extentsWgs84, int zoom, CRect &rect); - RectLatLng CalculateGeogBounds(CPoint pnt, int zoom); + virtual RectLatLng CalculateGeogBounds(CPoint pnt, int zoom); void Clip(CPoint& tilePnt, int zoom); diff --git a/src/Tiles/Projections/MercatorProjection.cpp b/src/Tiles/Projections/MercatorProjection.cpp index 0b63da76..8d568631 100644 --- a/src/Tiles/Projections/MercatorProjection.cpp +++ b/src/Tiles/Projections/MercatorProjection.cpp @@ -117,3 +117,35 @@ void MercatorProjection::FromXYToLatLng(CPoint pnt, int zoom, PointLatLng &ret) ret.Lng = 360 * xx; } +// **************************************************** +// CalculateGeogBounds +// **************************************************** +// check result from BaseProjection against min/max lat/lon, because BaseProjection don't +// have lat/lon limits, but Mercator do +RectLatLng MercatorProjection::CalculateGeogBounds(CPoint pnt, int zoom) +{ + auto res = BaseProjection::CalculateGeogBounds(pnt, zoom); + + //sanity check + + if (res.yLat > _maxLat) + res.yLat = _maxLat; + + if (res.yLat < _minLat) + res.yLat = _minLat; + + if (res.xLng > _maxLng) + res.xLng = _maxLng; + + if (res.xLng < _minLng) + res.xLng = _minLng; + + if ((res.xLng + res.WidthLng) > _maxLng) + res.WidthLng = _maxLng - res.xLng; + + if ((res.yLat - res.HeightLat) < _minLat) + res.HeightLat = res.yLat - _minLat; + + return res; +} + diff --git a/src/Tiles/Projections/MercatorProjection.h b/src/Tiles/Projections/MercatorProjection.h index 4ec312f7..9785afe4 100644 --- a/src/Tiles/Projections/MercatorProjection.h +++ b/src/Tiles/Projections/MercatorProjection.h @@ -60,4 +60,6 @@ class MercatorProjection: public BaseProjection // converts tile coordinates to decimal degrees void FromXYToLatLng(CPoint pnt, int zoom, PointLatLng &ret); + // override BaseProjection's member to check result + virtual RectLatLng CalculateGeogBounds(CPoint pnt, int zoom); };