Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Tiles/Projections/BaseProjection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
32 changes: 32 additions & 0 deletions src/Tiles/Projections/MercatorProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

2 changes: 2 additions & 0 deletions src/Tiles/Projections/MercatorProjection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};