# Creating New Layers

Creating a new map layer is just as easy as it is to create a normal `StatelessWidget` or `StatefulWidget`.

Only one method call is needed to 'connect' the widget to the map state: `FlutterMapState.maybeOf()`. This call does two important things:

* Cause the widget/layer to rebuild automatically when required (if in the `build` method)
* Expose the map's internal state, meaning that it's information (such as zoom) can be accessed

You can see an example of how this is done below:

```dart
class CustomLayer extends StatelessWidget {
  const CustomLayer({super.key});

  @override
  Widget build(BuildContext context) {
    final mapState = FlutterMapState.maybeOf(context)!;
    // Use `mapState` as necessary, for example `mapState.zoom`
  }
}
```

{% hint style="warning" %}
Attempting to use the widget above outside of a `FlutterMap` widget will result in an error.

The `FlutterMapState.maybeOf` method will return `null`, because it cannot locate a parent/inherited state, and therefore cause a null exception.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fleaflet.dev/v4/plugins/making-a-plugin/creating-new-layers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
