getSource method

Future<Source?> getSource(
  1. String sourceId
)

Get the source with sourceId from the current style.

Implementation

Future<Source?> getSource(String sourceId) async {
  final properties = await getStyleSourceProperties(sourceId);

  Source? source;

  final map = json.decode(properties);

  final type = map["type"];
  switch (type) {
    case "vector":
      source = VectorSource(id: sourceId);
      break;
    case "geojson":
      source = GeoJsonSource(id: sourceId);
      break;
    case "image":
      source = ImageSource(id: sourceId);
      break;
    case "raster-dem":
      source = RasterDemSource(id: sourceId);
      break;
    case "raster":
      source = RasterSource(id: sourceId);
      break;
    case "raster-array":
      source = RasterArraySource(id: sourceId);
      break;
    default:
      print("Source type: $type unknown.");
  }

  source?.bind(this);
  return Future.value(source);
}