worldToPosition method
Transforms world
coordinates to a position.
Coordinate value ranges:
- world x (double):
0.0 .. mapWidth(0)
- world y (double):
0.0 .. mapHeight(0)
Implementation
@override
Geographic worldToPosition(Projected world) {
// world coordinates size: number of pixels for x and y at the zoom level 0
final width = mapWidth(0);
final height = mapHeight(0);
// world coordinates
final px = world.x;
final double py;
// handle origin variations
switch (origin) {
case CanvasOrigin.topLeft:
py = world.y;
break;
case CanvasOrigin.bottomLeft:
py = height - world.y;
break;
}
// unproject world coordinates to geographic position
return Geographic(
lon: converter.fromScaledX(px, width: width),
lat: converter.fromScaledY(py, height: height),
// optional z and m are copied
elev: world.optZ,
m: world.optM,
);
}