convert method

  1. @override
GeographicArea? convert(
  1. GeographicAreaType toType
)
override

Attempts to convert this geographic area to a different type.

Tries to create a new geographic area of the specified type that approximates the same spatial region. Conversion success depends on the source and target types - some conversions may result in loss of precision or may not be possible at all.

Parameters

Returns

  • A new GeographicArea of the requested type on successful conversion, or null if conversion is not possible or fails.

Implementation

@override
GeographicArea? convert(GeographicAreaType toType) {
  final OperationResult resultString = objectMethod(
    pointerId,
    'TilesCollectionGeographicArea',
    'convert',
    args: toType.id,
  );

  if (resultString['gemApiError'] != 0) {
    return null;
  }

  switch (toType) {
    case GeographicAreaType.rectangle:
      return RectangleGeographicArea.fromJson(resultString.data['result']);
    case GeographicAreaType.circle:
      return CircleGeographicArea.fromJson(resultString['result']);
    case GeographicAreaType.polygon:
      return PolygonGeographicArea.fromJson(resultString['result']);
    case GeographicAreaType.tileCollection:
      return TilesCollectionGeographicArea.init(resultString['result']);
    case GeographicAreaType.undefined:
      return RectangleGeographicArea(
        topLeft: Coordinates(),
        bottomRight: Coordinates(),
      );
  }
}