importLandmarks method

ProgressListener? importLandmarks({
  1. required String filePath,
  2. required LandmarkFileFormat format,
  3. required Img image,
  4. void onCompleteCallback(
    1. GemError error
    )?,
  5. void onProgressUpdated(
    1. int progress
    )?,
  6. int categoryId = uncategorizedLandmarkCategId,
})

Asynchronously import landmarks from given file format

Parameters

  • IN filePath The file path
  • IN format The file format, see LandmarkFileFormat.
  • IN image The landmark map image. If left empty, a default image is assigned
  • IN onProgressUpdated Callback that gets triggered with the associated progress when the update process is in progress.
  • IN onCompleteCallback Callback that gets triggered with the associated GemError when the update process is completed.
  • IN categoryId The category for the new imported landmarks. The category must exist or use uncategorizedLandmarkCategId to set the landmark as uncategorized

Returns

  • The associated ProgressListener if the request can be started, null otherwise.

Throws

  • An exception if it fails to initialize.

Implementation

ProgressListener? importLandmarks({
  required String filePath,
  required LandmarkFileFormat format,
  required Img image,
  final void Function(GemError error)? onCompleteCallback,
  final void Function(int progress)? onProgressUpdated,
  int categoryId = uncategorizedLandmarkCategId,
}) {
  final EventDrivenProgressListener progressListener =
      EventDrivenProgressListener();

  if (onCompleteCallback != null) {
    progressListener.registerOnCompleteWithDataCallback(
      (final int err, final String hint, final Map<dynamic, dynamic> json) =>
          onCompleteCallback(GemErrorExtension.fromCode(err)),
    );
  }

  if (onProgressUpdated != null) {
    progressListener.registerOnProgressCallback(onProgressUpdated);
  }

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

  final OperationResult resultString = objectMethod(
    _pointerId,
    'LandmarkStore',
    'importLandmarks',
    args: <String, dynamic>{
      'path': filePath,
      'fileFormat': format.id,
      'image': image.pointerId,
      'categoryId': categoryId,
      'listener': progressListener.id,
    },
  );
  final GemError errorCode = GemErrorExtension.fromCode(
    resultString['result'],
  );

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

  return progressListener;
}