addImage method

Future<void> addImage(
  1. String name,
  2. Uint8List bytes, [
  3. bool sdf = false
])

Adds an image to the style currently displayed in the map, so that it can later be referred to by the provided name.

This allows you to add an image to the currently displayed style once, and from there on refer to it e.g. in the Symbol.iconImage anytime you add a Symbol later on. Set sdf to true if the image you add is an SDF image. Returns after the image has successfully been added to the style. Note: This can only be called after OnStyleLoadedCallback has been invoked and any added images will have to be re-added if a new style is loaded.

Example: Adding an asset image and using it in a new symbol:

Future<void> addImageFromAsset() async{
  final ByteData bytes = await rootBundle.load("assets/someAssetImage.jpg");
  final Uint8List list = bytes.buffer.asUint8List();
  await controller.addImage("assetImage", list);
  controller.addSymbol(
   SymbolOptions(
    geometry: LatLng(0,0),
    iconImage: "assetImage",
   ),
  );
}

Example: Adding a network image (with the http package) and using it in a new symbol:

Future<void> addImageFromUrl() async{
 var response = await get("https://example.com/image.png");
 await controller.addImage("testImage",  response.bodyBytes);
 controller.addSymbol(
  SymbolOptions(
    geometry: LatLng(0,0),
    iconImage: "testImage",
  ),
 );
}

Implementation

Future<void> addImage(String name, Uint8List bytes, [bool sdf = false]) {
  return _mapboxGlPlatform.addImage(name, bytes, sdf);
}