Distance based filtering in search API is more robust now (for coordinate wrapping, etc)
@@ -287,11 +287,15 @@ namespace carto {
throw NullArgumentException("Null projection while geometry is not null");
}
- MapPos centerPos = request->getProjection()->toWgs84(request->getGeometry()->getCenterPos());
+ MapPos wgs84CenterPos = request->getProjection()->toWgs84(request->getGeometry()->getCenterPos());
_geometry = convertToEPSG3857(request->getGeometry(), request->getProjection());
MapBounds geometryBounds = _geometry->getBounds();
- _searchRadius = request->getSearchRadius() / std::cos(centerPos.getY() * Const::DEG_TO_RAD);
- _searchBounds = MapBounds(geometryBounds.getMin() - MapVec(_searchRadius, _searchRadius), geometryBounds.getMax() + MapVec(_searchRadius, _searchRadius));
+ _searchRadius = request->getSearchRadius() / std::cos(std::min(89.9, std::abs(wgs84CenterPos.getY())) * Const::DEG_TO_RAD);
+ MapPos boundsPos0 = geometryBounds.getMin() - MapVec(_searchRadius, _searchRadius);
+ MapPos boundsPos1 = geometryBounds.getMax() + MapVec(_searchRadius, _searchRadius);
+ boundsPos0[0] = std::max(boundsPos0[0], EPSG3857().getBounds().getMin()[0] * 0.9999);
+ boundsPos1[0] = std::min(boundsPos1[0], EPSG3857().getBounds().getMax()[0] * 0.9999);
+ _searchBounds = MapBounds(boundsPos0, boundsPos1);
} else {
_searchBounds = convertToEPSG3857(mapBounds, proj);
}
