# Using with maps deck.gl works without a base map, but a base map gives geospatial layers context. This page describes what is shared by every base-map integration of `@deck.gl/react`. Each provider guide then covers installation, examples, and provider-specific options. For the underlying deck.gl concepts, see deck.gl's [Using with map](../../get-started/using-with-map.md) guide. ## Overlaid and interleaved rendering deck.gl integrates with a base map in one of two ways: - **Overlaid:** deck.gl renders into its own canvas above the map, and the two cameras stay in sync. The two libraries render independently. - **Interleaved:** deck.gl renders into the map's WebGL2 context, so deck.gl layers and map layers such as labels or 3D buildings can occlude each other. deck.gl's guide describes both modes in detail: [overlaid](../../get-started/using-with-map.md#overlaid) and [interleaved](../../get-started/using-with-map.md#interleaved). ## Supported base maps | Base map | Import path | deck.gl package | Host SDK | Overlaid | Interleaved | React Map GL | Guide | deck.gl guide | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Mapbox GL JS | `@deck.gl/react/mapbox` | [`@deck.gl/mapbox`](../../api-reference/mapbox/overview.md) | `mapbox-gl` | ✓ | ✓ | ✓ | [Using with Mapbox](base-maps/using-with-mapbox.md) | [Using with Mapbox](../base-maps/using-with-mapbox.md) | | MapLibre GL JS | `@deck.gl/react/maplibre` | [`@deck.gl/maplibre`](../../api-reference/maplibre/overview.md) | `maplibre-gl` | ✓ | ✓ | ✓ | [Using with MapLibre](base-maps/using-with-maplibre.md) | [Using with MapLibre](../base-maps/using-with-maplibre.md) | | Google Maps | `@deck.gl/react/google-maps` | [`@deck.gl/google-maps`](../../api-reference/google-maps/overview.md) | Maps JavaScript API | ✓ | ✓ (vector maps) | [React Google Maps](https://visgl.github.io/react-google-maps/) | [Using with Google Maps](base-maps/using-with-google-maps.md) | [Using with Google Maps](../base-maps/using-with-google-maps.md) | | Custom overlay | `createDeckGL` from `@deck.gl/react` | The overlay's package | The host's SDK | Overlay-specific | Overlay-specific | Overlay-specific | [Using with custom overlays](base-maps/using-with-custom-overlays.md) | None | ## Choose a provider root Use a provider root when the application owns a Mapbox, MapLibre or Google map and needs deck.gl as a map overlay: ```tsx import {DeckGL as MapboxDeckGL} from '@deck.gl/react/mapbox'; import {DeckGL as MapLibreDeckGL} from '@deck.gl/react/maplibre'; import {DeckGL as GoogleMapsDeckGL} from '@deck.gl/react/google-maps'; ``` A provider root creates the deck.gl overlay only. The application creates, configures, and removes the host map. Keep map tokens, styles, camera options, terrain, projection, event handlers, workers, and CSP configuration on the map creator or React Map GL ``, not on `DeckGL`. ## Choose the overlay mode Provider roots pass `interleaved?: boolean` to the overlay unchanged, so each overlay's own default applies: - Pass `false` for a dedicated deck canvas. This is the default of [`MapboxOverlay`](../../api-reference/mapbox/mapbox-overlay.md#constructor) and [`MapLibreOverlay`](../../api-reference/maplibre/overview.md). - Pass `true` to share the map's WebGL context. This is the default of [`GoogleMapsOverlay`](../../api-reference/google-maps/google-maps-overlay.md), on vector maps. The Mapbox and MapLibre overlays read `interleaved` only in their constructors, and the Google Maps overlay when it attaches to its map. When the prop changes, `DeckGL` finalizes the current overlay, which removes it from the map, and creates a new one. `onDeckChange` receives `null` and then the new instance. With the `map` prop, `DeckGL` attaches the new overlay itself; see [Attach the overlay to the host map](#attach-the-overlay-to-the-host-map). The new overlay starts without the old one's internal state, such as the hovered object. `interleaved` does not select the provider; select Mapbox, MapLibre or Google Maps through the import path. Other props that only apply when the overlay is created are listed in [Props that only apply at creation](../../api-reference/react/deckgl.md#props-that-only-apply-at-creation). Provider roots render no host DOM node. You can place them inside a React Map GL ``, or beside a manual `new Map({container})` integration without adding a child to the map container. ## Views beside the map The Mapbox and MapLibre roots send JSX views, merged with the `views` prop, to the overlay, which supports deck.gl's [multi-view usage](../../api-reference/mapbox/mapbox-overlay.md#multi-view-usage). Only one view follows the map camera and receives map interaction: the view with id `mapbox` on the `/mapbox` root and `maplibre` on the `/maplibre` root. The overlay adds it first when the list has none. Give a JSX view that id to set the map view's position in the list. Keep it the full size of the map, or its layers drift off the basemap. The Google Maps root does not send JSX views: `GoogleMapsOverlay` draws one view, which follows the map camera. See [Using with Google Maps](base-maps/using-with-google-maps.md#views). ```tsx import {OrthographicView} from '@deck.gl/react/core'; import {ScatterplotLayer} from '@deck.gl/react/layers'; import {DeckGL} from '@deck.gl/react/maplibre'; (viewport.id === 'inset') === layer.id.startsWith('inset')} > ; ``` ## Attach the overlay to the host map Keep the host map in React state and pass it in `map`: ```tsx const [map, setMap] = useState(null); {/* Layer components, such as */} ; ``` On the Mapbox and MapLibre roots, `map` takes a Mapbox or MapLibre `Map`, or a React Map GL `MapRef`. On the Google Maps root it takes a `google.maps.Map`. With it, `DeckGL`: - adds the overlay as soon as both exist, with `map.addControl` on Mapbox and MapLibre and `overlay.setMap(map)` on Google Maps. It does not wait for the map to load; `MapboxOverlay` and `MapLibreOverlay` wait for the style, and `GoogleMapsOverlay` for the map's rendering type, before they draw. - adds the new overlay when it recreates the overlay because `interleaved` changed. - moves the overlay when `map` changes, and removes it when `map` becomes `null` or `DeckGL` unmounts. The state matters: `DeckGL` sees the map only when a render passes it. A map created in an effect, as in the provider guides' manual examples, is set in state there. Without `map`, attach the overlay yourself: keep the instance from `onDeckChange` in state, add it with `map.addControl` in an effect, and remove it with `map.removeControl` in the effect's cleanup. On Google Maps, call `overlay.setMap(map)` and `overlay.setMap(null)` instead. The effect must depend on the instance, because `onDeckChange` reports `null` and then a new instance when the overlay is recreated. React Map GL's `useControl` cannot do this; see the provider guides. ## Provider prop boundary The provider root accepts supported deck.gl and overlay props, including layers, effects, picking callbacks, layer filtering, parameters, and `interleaved`. Do not pass map-owned values to it. `canvas`, `parent`, `device`, `viewState`, `initialViewState`, and `controller` belong to the host map. Some providers exclude more props; see the provider guide. Use a standalone root when the application needs `Deck` and its canvas. For a compatible custom overlay, use the native `createDeckGL` factory instead of trying to select a provider at render time. See [Using with custom overlays](base-maps/using-with-custom-overlays.md). ## Reverse-controlled maps deck.gl's guides describe a third mode, reverse controlled, in which the `@deck.gl/react/legacy` `DeckGL` component is the root, a React Map GL `` is its child, and deck.gl owns the camera. Provider roots do not support this mode. `DeckGL` renders its children with the deck.gl reconciler, which accepts only `` and `` elements, so it cannot render a `` child. An application that needs reverse-controlled rendering should keep using [`@deck.gl/react/legacy`](../../api-reference/react/legacy/deckgl.md) for that map. ## Base map renderer and data provider The JavaScript library that renders the map is separate from the service that provides its data. For example, MapLibre GL JS can render tiles from many vector tile services, and Mapbox GL JS can render any source that serves Mapbox Vector Tiles. Follow the terms of use and attribution requirements of both the rendering library and the data provider.