Intro
Getting Started
Reference
MapRasterRegionPickerFillLineMapProvider

MapProvider

The MapProvider component (imported from @carbonplan/maps/core) allows use of an external map object from Maplibre GL JS or Mapbox GL JS. Only the web-mercator projection is supported at this time. All imports should be from the /core namespace when used with MapProvider to avoid bundling unneeded mapbox-gl dependencies and mixing react context.

PropDescription
mapMaplibre or Mapbox Map instance
optional props
stylecss object for @carbonplan/maps canvas. Use zIndex to bring canvas above or below main map.
setLoadingTracks any pending requests made by containing Raster layers
setMetadataLoadingTracks any metadata and coordinate requests made on initialization by containing Raster layers
setChunkLoadingTracks any requests of new chunks by containing Raster layers
import { useRef, useEffect, useState } from 'react'
import { useThemedColormap } from '@carbonplan/colormaps'
import { MapProvider, Raster } from '@carbonplan/maps/core'
import { Map } from 'maplibre-gl'
import 'maplibre-gl/dist/maplibre-gl.css'
const BringYourOwnMap = () => {
const colormap = useThemedColormap('warm')
const mapContainer = useRef()
const map = useRef(null)
const [isMapLoaded, setIsMapLoaded] = useState(false)
useEffect(() => {
if (mapContainer.current && !map.current) {
map.current = new Map({
container: mapContainer.current,
style: {
version: 8,
sources: {
// basemap sources
},
layers: [
// basemap layers
],
},
})
map.current.on('load', () => {
setIsMapLoaded(true)
})
}
}, [])
return (
<Box ref={mapContainer}>
{isMapLoaded && map.current && (
<MapProvider
map={map.current}
style={{
zIndex: -1, // place raster below main map
}}
>
<Raster
colormap={colormap}
clim={[-20, 30]}
source={'demo/tavg'}
variable={'tavg'}
/>
</MapProvider>
)}
</Box>
)
}
EMAIL
hello@carbonplan.org
NEWSLETTER
Subscribe
CarbonPlan is a registered nonprofit public benefit corporation in California with 501(c)(3) status.
(c) 2025
CARBONPLAN
TERMS OF USE
/
PRIVACY POLICY
X,Y: 0000,0000
a9bf5b9