calculateBoundingBox method

BoundingBox calculateBoundingBox(
  1. Dimension viewDimension
)

Implementation

BoundingBox calculateBoundingBox(Dimension viewDimension) {
  assert(viewDimension != null);
  if (boundingBox != null) return boundingBox;

  double centerY = _mercatorProjection.latitudeToPixelY(_latitude);
  double centerX = _mercatorProjection.longitudeToPixelX(_longitude);
  double leftX = centerX - viewDimension.width / 2;
  double rightX = centerX + viewDimension.width / 2;
  double topY = centerY - viewDimension.height / 2;
  double bottomY = centerY + viewDimension.height / 2;
  boundingBox = BoundingBox(
      _mercatorProjection.pixelYToLatitude(min(bottomY, _mercatorProjection.mapSize)),
      _mercatorProjection.pixelXToLongitude(max(leftX, 0)),
      _mercatorProjection.pixelYToLatitude(max(topY, 0)),
      _mercatorProjection.pixelXToLongitude(min(rightX, _mercatorProjection.mapSize)));
  _leftUpper = Mappoint(leftX, topY);
  return boundingBox;
}