convert static method

TaskHandler? convert({
  1. required Projection from,
  2. required ProjectionType toType,
  3. required void onCompleteCallback(
    1. GemError err,
    2. Projection? result
    ),
})

Async method that returns the projection result from an input projection.

Parameters

  • IN type The type of projection to cast to.
  • IN from The input projection that needs to be converted.
  • IN onCompleteCallback Callback for the operation completion.

Returns

  • A TaskHandler that can be used to track the progress of the operation or null if it failed.

Implementation

static TaskHandler? convert(
    {required Projection from,
    required ProjectionType toType,
    required final void Function(GemError err, Projection? result)
        onCompleteCallback}) {
  final EventDrivenProgressListener progListener =
      EventDrivenProgressListener();

  late Projection result;

  switch (toType) {
    case ProjectionType.bng:
      result = BNGProjection(easting: 0, northing: 0);

    case ProjectionType.lam:
      result = LAMProjection(x: 0, y: 0);

    case ProjectionType.utm:
      result =
          UTMProjection(x: 0, y: 0, zone: 0, hemisphere: Hemisphere.north);

    case ProjectionType.mgrs:
      result = MGRSProjection(easting: 0, northing: 0, zone: '', letters: '');

    case ProjectionType.gk:
      result = GKProjection(x: 0, y: 0, zone: 0);

    case ProjectionType.wgs84:
      result = WGS84Projection(Coordinates());

    case ProjectionType.w3w:
      result = W3WProjection('');
    case ProjectionType.undefined:
      throw UnimplementedError();
  }

  GemKitPlatform.instance.registerEventHandler(progListener.id, progListener);

  progListener.registerOnCompleteWithDataCallback((
    final int err,
    final String hint,
    final Map<dynamic, dynamic> json,
  ) {
    GemKitPlatform.instance.unregisterEventHandler(progListener.id);

    if (err == GemError.success.code) {
      onCompleteCallback(GemErrorExtension.fromCode(err), result);
    } else {
      onCompleteCallback(GemErrorExtension.fromCode(err), null);
    }
  });

  final OperationResult resultString = staticMethod(
    'ProjectionService',
    'convert',
    args: <String, dynamic>{
      'from': from.pointerId,
      'to': result.pointerId,
      'listener': progListener.id,
    },
  );

  final GemError errorCode =
      GemErrorExtension.fromCode(resultString['result']);

  if (errorCode != GemError.success) {
    onCompleteCallback(errorCode, null);
    return null;
  }

  return TaskHandlerImpl(progListener.id);
}