importLandmarksWithDataBuffer method

ProgressListener? importLandmarksWithDataBuffer({
  1. required Uint8List buffer,
  2. required LandmarkFileFormat format,
  3. required Img image,
  4. void onComplete(
    1. GemError error
    )?,
  5. void onProgressUpdated(
    1. int progress
    )?,
  6. int categoryId = uncategorizedLandmarkCategId,
})

Asynchronously imports landmarks into this store from a raw data buffer.

Use this when landmark data is available directly in memory (for example downloaded or received over a network). Parameters and completion semantics match importLandmarks.

Parameters

  • buffer: Binary data containing the landmark file content.
  • format: The LandmarkFileFormat of the buffer.
  • image: An Img used as the landmark image for imported items.
  • onComplete: Optional callback invoked with a GemError when the import finishes.
  • onProgressUpdated: Optional progress callback (0-100).
  • categoryId: Optional category id to assign to imported landmarks.

Returns

See also:

Implementation

ProgressListener? importLandmarksWithDataBuffer({
  required Uint8List buffer,
  required LandmarkFileFormat format,
  required Img image,
  final void Function(GemError error)? onComplete,
  final void Function(int progress)? onProgressUpdated,
  int categoryId = uncategorizedLandmarkCategId,
}) {
  final EventDrivenProgressListener progressListener =
      EventDrivenProgressListener();

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

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

  GemKitPlatform.instance.registerEventHandler(
    progressListener.id,
    progressListener,
  );
  final dynamic dataBufferPointer = GemKitPlatform.instance.toNativePointer(
    buffer,
  );
  final OperationResult resultString = objectMethod(
    pointerId,
    'LandmarkStore',
    'importLandmarksWithDataBuffer',
    args: <String, dynamic>{
      'dataBuffer': dataBufferPointer.address,
      'dataBufferSize': buffer.length,
      'fileFormat': format.id,
      'image': image.pointerId,
      'categoryId': categoryId,
      'listener': progressListener.id,
    },
  );
  GemKitPlatform.instance.freeNativePointer(dataBufferPointer);
  final GemError errorCode = GemErrorExtension.fromCode(
    resultString['result'],
  );

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

  return progressListener;
}