render method
void
render({
- required Mappoint leftUpper,
- required int tileSize,
- required HgtTileRenderer tileRenderer,
- required Uint8List pixels,
Implementation
void render({required Mappoint leftUpper, required int tileSize, required HgtTileRenderer tileRenderer, required Uint8List pixels}) {
_ElevationGrid? elevationGrid = _calculateGrid(leftUpper: leftUpper, tileSize: tileSize);
//print("elevationGrid: $elevationGrid");
if (elevationGrid == null) {
return;
}
ILatLong leftUpperLL = projection.pixelToLatLong(leftUpper.x, leftUpper.y);
int row = 0;
int maxY = 0;
for (int y = 0; y < tileSize; ++y) {
int column = 0;
if (y > maxY) {
++row;
// not enough rows available, out of boundary of the file(s), nothing to render
if (row + 1 == elevationGrid.rows) break;
}
_ElevationPoint leftTop = elevationGrid.get(column, row);
_ElevationPoint rightTop = elevationGrid.get(column + 1, row);
_ElevationPoint leftBottom = elevationGrid.get(column, row + 1);
_ElevationPoint rightBottom = elevationGrid.get(column + 1, row + 1);
_ElevationArea area = _ElevationArea(leftTop: leftTop, rightTop: rightTop, leftBottom: leftBottom, rightBottom: rightBottom);
maxY = leftBottom != const _ElevationPoint.invalid()
? leftBottom.y
: rightBottom != const _ElevationPoint.invalid()
? rightBottom.y
: maxY;
for (int x = 0; x < tileSize; ++x) {
int elevation = _interpolatedElevation(area, x, y);
tileRenderer.render(pixels, tileSize, x, y, projection, leftUpperLL.latitude, leftUpperLL.longitude, elevation);
if (x > rightTop.x) {
if (column + 2 == elevationGrid.columns) break;
++column;
leftTop = elevationGrid.get(column, row);
rightTop = elevationGrid.get(column + 1, row);
leftBottom = elevationGrid.get(column, row + 1);
rightBottom = elevationGrid.get(column + 1, row + 1);
area = _ElevationArea(leftTop: leftTop, rightTop: rightTop, leftBottom: leftBottom, rightBottom: rightBottom);
maxY = leftBottom != const _ElevationPoint.invalid()
? leftBottom.y
: rightBottom != const _ElevationPoint.invalid()
? rightBottom.y
: maxY;
}
}
}
// for (int x = tileSize - 10; x < tileSize; ++x) {
// for (int y = tileSize - 10; y < tileSize; ++y) {
// int idx = y * tileSize + x;
// pixels.buffer.asUint32List()[idx] = 0xff00ff00;
// }
// }
}