A React component library for declarative web map application development.
yarn add @mapcomponents/react-core
to install and add this package as a dependency to your projects package.json
Build esm and csm packages and save them to ./dist
.
Run tests and watch & rerun tests for affected components if the filesystem changes.
MapComponentsProvider must be imported and wrapped around all MapComponents.
MapComponentsProvider requires exactly one use of the MapLibreMap or OpenLayersMap components somewhere down the component tree that will create a map engine instance and register it to MapContext (using mapContext.registerMap()
).
The MapContext component can be used to access the registered map eninge instances from components located in the component tree somewhere below MapComponentsProvider. Import the useContext hook from React and the MapContext component from react-map-components-core (both named exports).
import { useContext } from "react";
import { MapContext } from "react-map-components-core";
In the body of your function component add the following:
const mapContext = useContext(MapContext);
You can now retrieve map engine instances using mapContext.getMap(mapId)