render method

  1. @override
void render(
  1. Uint8List pixels,
  2. int tileSize,
  3. int px,
  4. int py,
  5. PixelProjection projection,
  6. double latitude,
  7. double longitude,
  8. int elev,
)
override

Implementation

@override
void render(Uint8List pixels, int tileSize, int px, int py, PixelProjection projection, double latitude, double longitude, int elev) {
  // -500 is ocean, see https://www.ngdc.noaa.gov/mgg/topo/report/s4/s4.html
  if (elev == HgtFile.ocean) {
    _setPixel(
      pixels,
      tileSize,
      px,
      py,
      (oceanColor.r * 255).round(),
      (oceanColor.g * 255).round(),
      (oceanColor.b * 255).round(),
      (oceanColor.a * 255).round(),
    );
    return;
  }

  // Clamp to typical SRTM range and map to [0..255].
  const minM = 0;
  const maxM = 5000;
  final clamped = elev.clamp(minM, maxM);
  final t = (clamped - minM) / (maxM - minM);
  final intensity = (t * 255).round().clamp(0, 255);
  _setPixel(pixels, tileSize, px, py, intensity, intensity, intensity, 255);
}