longitudeToTileX method
@param scaleFactor the scale factor for which the size of the world map should be returned. @return the horizontal and vertical size of the map in pixel at the given scale. @throws IllegalArgumentException if the given scale factor is < 1 Converts a longitude coordinate to the corresponding tile X number.
Handles edge cases at the world boundaries (±180°) and ensures the result is within valid tile coordinate range.
longitude The longitude coordinate in degrees (-180 to +180)
Returns the tile X coordinate (0 to scalefactor-1)
Implementation
// double _mapSizeWithScaleFactor(double scaleFactor) {
// assert(scaleFactor >= 1);
// return (tileSize.toDouble() * (pow(2, Projection.scaleFactorToZoomLevel(scaleFactor))));
// }
/// Converts a longitude coordinate to the corresponding tile X number.
///
/// Handles edge cases at the world boundaries (±180°) and ensures
/// the result is within valid tile coordinate range.
///
/// [longitude] The longitude coordinate in degrees (-180 to +180)
/// Returns the tile X coordinate (0 to scalefactor-1)
@override
int longitudeToTileX(double longitude) {
if (longitude >= 180) {
return _maxTileCount - 1;
}
if (longitude <= -180) {
return 0;
}
int result = ((longitude + 180) / 360 * _scalefactor.scalefactor).floor();
return result;
}