addStyleLayerJson method

Future<CommandCompletion> addStyleLayerJson(
  1. Object? layerJson, {
  2. String? beforeLayerId,
})

Adds a layer to the map's style.

layerJson is a [layer](https://maplibre.org/maplibre-style-spec/layers/) object. The layer goes below the layer named beforeLayerId, or above every layer when beforeLayerId is empty.

See mln_map_add_style_layer_json in the C API reference.

Errors:

  • Status.notFound when the style has no layer named beforeLayerId, or no source with the ID that the layer uses.
  • Status.alreadyExists when the style already has a layer with the new layer's ID.
  • Status.invalidState while the style isn't loaded, as MapHandle.setStyleUrl() describes.

Implementation

Future<CommandCompletion> addStyleLayerJson(
  Object? layerJson, {
  String? beforeLayerId,
}) => _command(
  (arena, completion) => raw.mln_map_add_style_layer_json(
    _handle.raw,
    _nativeJsonView(layerJson, arena),
    beforeLayerId == null
        ? arena<raw.mln_buffer_view>().ref
        : nativeStringView(beforeLayerId, arena).value,
    completion,
    nativeDiagnostic,
  ),
);