buildPositionedForOverlay method

  1. @override
Positioned buildPositionedForOverlay(
  1. MapState map
)
override

Implementation

@override
Positioned buildPositionedForOverlay(MapState map) {
  final pixelOrigin = map.getPixelOrigin();

  final pxTopLeft = map.project(topLeftCorner) - pixelOrigin;
  final pxBottomRight = map.project(bottomRightCorner) - pixelOrigin;
  final pxBottomLeft = (map.project(bottomLeftCorner) - pixelOrigin);
  // calculate pixel coordinate of top-right corner by calculating the
  // vector from bottom-left to top-left and adding it to bottom-right
  final pxTopRight = (pxTopLeft - pxBottomLeft + pxBottomRight);

  // update/enlarge bounds so the new corner points fit within
  final bounds = Bounds<num>(pxTopLeft, pxBottomRight)
      .extend(pxTopRight)
      .extend(pxBottomLeft);

  final vectorX = (pxTopRight - pxTopLeft) / bounds.size.x;
  final vectorY = (pxBottomLeft - pxTopLeft) / bounds.size.y;
  final offset = pxTopLeft - bounds.topLeft;

  final a = vectorX.x.toDouble();
  final b = vectorX.y.toDouble();
  final c = vectorY.x.toDouble();
  final d = vectorY.y.toDouble();
  final tx = offset.x.toDouble();
  final ty = offset.y.toDouble();

  return Positioned(
      left: bounds.topLeft.x.toDouble(),
      top: bounds.topLeft.y.toDouble(),
      width: bounds.size.x.toDouble(),
      height: bounds.size.y.toDouble(),
      child: Transform(
          transform:
              Matrix4(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1),
          filterQuality: filterQuality,
          child: buildImageForOverlay()));
}