Principal component. All others components described in this library need to be defined as children of this one.
This component take his props from MapOptions, map events, and some extra configuration options.
It instantiates a Map object and register event listeners to it. Only a few props are responsive (see reference below).
Hello world.
The RMap component accepts the style and mapStyle props to respectively define the style attribute of the
containing element div.maplibregl-map and the style to apply to the Map instance.
Internally the style prop is wrapped inside a useMemo, you can therefore define this object inline without affecting performance.
The mapStyle is a reactive value. You can specify the url of a style file or directly an object. If you propose an object
be careful to give a stable object for performance reasons the verification is done with a strict equal and not a deepEqual.
MapProps vs MapOptions
You can use all options from the MapLibre MapOptions type as props for the RMap component. Some of these options are reactives and some are not. To distinguish them, non-reactive options have been prefixed with initial and event handlers are prefixed with on.
This set constitutes a new type : MapProps (see below for complete reference).
For performance reasons, if your prop is an array or an object, define your variable outside your component if it's a readonly value or inside a useMemo to skip re-rendering of components.
You don't need to follow this rule with callbacks (type MapCallbacks). They were implemented following the React principle of useEffectEvents.
Manipulating the map instance
Using the ref prop you get the original MapLibre Map instance. You can also listen to the onMounted event which is called as soon as your map object is accessible.
onMounted is called just after instantiating a Map object while onLoad is called later when the style is loaded.
Children components
the RMap component accepts child components.
Native controls added with their wrapper components (like RNavigationControl) are added
in the same place as with the vanilla MapLibre lib. Other components are added as children of the div.maplibregl-children element.
It is not recommended to add content in this way because you can quickly have overlaps with native controls. A best practice is to use the useRControl hook to add components that will not conflict with vanilla content.
Reference
The RMap component accept principally MapProps as props but also some additional options. You will find complete details here.
MapProps type come from the MapLibre MapOptions type. They have been renamed following the conventions described below. Check the MapLibre MapOptions reference page for details of MapInitialOptions and MapReactiveOptions.