worldToTile method
Returns a tile at zoom covering a region in world coordinates.
Coordinate value ranges:
- world x (double):
0.0 .. mapWidth(0) - world y (double):
0.0 .. mapHeight(0) - tile x (int):
0 .. matrixWidth(zoom) - 1 - tile y (int):
0 .. matrixHeight(zoom) - 1
Implementation
Scalable2i worldToTile(Projected world, {int zoom = 0}) {
final scale = (1 << zoom) / tileSize;
return Scalable2i(
zoom: zoom,
x: (world.x * scale).floor().clamp(0, matrixWidth(zoom) - 1),
y: (world.y * scale).floor().clamp(0, matrixHeight(zoom) - 1),
);
}