calculateBoundaryWithSymbol method
Implementation
MapRectangle calculateBoundaryWithSymbol(MapPositioning pos, double fontWidth, double fontHeight) {
assert(fontWidth > 0, "fontWidth must be positive ($fontWidth)");
assert(fontWidth < 10000, "fontWidth must be less than 10000 ($fontWidth)");
assert(fontHeight > 0, "fontHeight must be positive ($fontHeight)");
assert(fontHeight < 10000, "fontHeight must be less than 10000 ($fontHeight)");
// print("captoin: $pos $fontWidth $fontHeight $symbolBoundary for caption $textKey");
MapRectangle? symBoundary = symbolBoundary;
if (pos == MapPositioning.CENTER && symBoundary != null) {
// sensible defaults: below if symbolContainer is present, center if not
pos = MapPositioning.BELOW;
}
if (symBoundary == null) {
// symbol not available, draw the text at the center
pos = MapPositioning.CENTER;
symBoundary = const MapRectangle.zero();
}
double halfWidth = fontWidth / 2;
double halfHeight = fontHeight / 2;
switch (pos) {
case MapPositioning.AUTO:
case MapPositioning.CENTER:
boundary = MapRectangle(-halfWidth, -halfHeight + dy, halfWidth, halfHeight + dy);
break;
case MapPositioning.BELOW:
boundary = MapRectangle(-halfWidth, symBoundary.bottom + 0 + gap + dy, halfWidth, symBoundary.bottom + fontHeight + gap + dy);
break;
case MapPositioning.BELOW_LEFT:
boundary = MapRectangle(
symBoundary.left - fontWidth - gap,
symBoundary.bottom + 0 + gap + dy,
symBoundary.left - 0 - gap,
symBoundary.bottom + fontHeight + gap + dy,
);
break;
case MapPositioning.BELOW_RIGHT:
boundary = MapRectangle(
symBoundary.right + 0 + gap,
symBoundary.bottom + 0 + gap + dy,
symBoundary.right + fontWidth + gap,
symBoundary.bottom + fontHeight + gap + dy,
);
break;
case MapPositioning.ABOVE:
boundary = MapRectangle(-halfWidth, symBoundary.top - fontHeight - gap + dy, halfWidth, symBoundary.top - 0 - gap + dy);
break;
case MapPositioning.ABOVE_LEFT:
boundary = MapRectangle(
symBoundary.left - fontWidth - gap,
symBoundary.top - fontHeight - gap + dy,
symBoundary.left - 0 - gap,
symBoundary.top + 0 - gap + dy,
);
break;
case MapPositioning.ABOVE_RIGHT:
boundary = MapRectangle(
symBoundary.right + 0 + gap,
symBoundary.top - fontHeight - gap + dy,
symBoundary.right + fontWidth + gap,
symBoundary.top + 0 - gap + dy,
);
break;
case MapPositioning.LEFT:
boundary = MapRectangle(symBoundary.left - fontWidth - gap, -halfHeight + dy, symBoundary.left - 0 - gap, halfHeight + dy);
break;
case MapPositioning.RIGHT:
boundary = MapRectangle(symBoundary.right + 0 + gap, -halfHeight + dy, symBoundary.right + fontHeight + gap, halfHeight + dy);
break;
}
return boundary!;
}