importLandmarks method

ProgressListener? importLandmarks({
  1. required String filePath,
  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 file path.

The import supports formats defined by LandmarkFileFormat and can attach a map image to the imported landmarks. A ProgressListener is returned to monitor progress. The onComplete callback receives a GemError describing final status.

Parameters

  • filePath: Path to the file containing landmark data (KML, GeoJSON, etc.).
  • format: The LandmarkFileFormat describing the file contents.
  • image: An Img used as the landmark image for imported items (or default when omitted).
  • onComplete: Optional callback invoked with a GemError when the import finishes. Possible values include:
  • onProgressUpdated: Optional progress callback (0-100).
  • categoryId: Optional category id to assign to imported landmarks. Use uncategorizedLandmarkCategId to import without a category.

Returns

See also:

Implementation

ProgressListener? importLandmarks({
  required String filePath,
  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 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) {
    onComplete?.call(errorCode);
    return null;
  }

  return progressListener;
}