Skip to main content

Light

Light represents the light source for extruded geometries (3D buildings and terrain). It controls how these 3D features are lit and shaded.

Import

import { Light } from '@rnmapbox/maps';

Basic Usage

import { MapView, Light, Camera } from '@rnmapbox/maps';

function MyMap() {
  return (
    <MapView style={{ flex: 1 }}>
      <Light
        style={{
          intensity: 0.8,
          color: '#ffffff',
          position: [1.5, 90, 60],
        }}
      />
      <Camera
        centerCoordinate={[-74.006, 40.7128]}
        zoomLevel={16}
        pitch={60}
      />
    </MapView>
  );
}

Props

style

style
LightLayerStyleProps
required
Customizable style attributes for the light source.

Style Properties

The style prop accepts a LightLayerStyleProps object with the following properties:

anchor

style.anchor
'map' | 'viewport'
default:"viewport"
Whether extruded geometries are lit relative to the map or viewport.
  • map - The light source rotates with the map
  • viewport - The light source is fixed to the viewport (user’s view)
<Light
  style={{
    anchor: 'map',
  }}
/>

position

style.position
[number, number, number]
default:"[1.15, 210, 30]"
Position of the light source relative to lit geometries, in [r, a, p] format:
  • r (radial) - Distance from the center of the base of an object to its light
  • a (azimuthal) - Position of the light in degrees (0° = top/north, clockwise)
  • p (polar) - Height of the light (0° = directly above, 180° = directly below)
<Light
  style={{
    position: [1.5, 90, 45],  // [radial, azimuth, polar]
  }}
/>

positionTransition

style.positionTransition
{ duration: number, delay: number }
default:"{ duration: 300, delay: 0 }"
The transition affecting any changes to the position property.
<Light
  style={{
    position: [1.5, 90, 45],
    positionTransition: {
      duration: 1000,
      delay: 0,
    },
  }}
/>

color

style.color
string
default:"#ffffff"
Color tint for lighting extruded geometries. Accepts any valid CSS color.
<Light
  style={{
    color: '#ffcc00',
  }}
/>

colorTransition

style.colorTransition
{ duration: number, delay: number }
default:"{ duration: 300, delay: 0 }"
The transition affecting any changes to the color property.
<Light
  style={{
    color: '#ffcc00',
    colorTransition: {
      duration: 1000,
      delay: 0,
    },
  }}
/>

intensity

style.intensity
number
default:"0.5"
Intensity of lighting on a scale from 0 to 1. Higher numbers create more extreme contrast.
  • 0 - No lighting effect
  • 1 - Maximum lighting effect
<Light
  style={{
    intensity: 0.8,
  }}
/>

intensityTransition

style.intensityTransition
{ duration: number, delay: number }
default:"{ duration: 300, delay: 0 }"
The transition affecting any changes to the intensity property.
<Light
  style={{
    intensity: 0.8,
    intensityTransition: {
      duration: 500,
      delay: 0,
    },
  }}
/>

Examples

import { MapView, Light, Camera } from '@rnmapbox/maps';

function BasicLighting() {
  return (
    <MapView style={{ flex: 1 }}>
      <Light
        style={{
          intensity: 0.7,
          color: '#ffffff',
        }}
      />
      <Camera
        centerCoordinate={[-74.006, 40.7128]}
        zoomLevel={16}
        pitch={60}
      />
    </MapView>
  );
}

Usage with 3D Buildings

import { MapView, Light, Camera, FillExtrusionLayer, VectorSource } from '@rnmapbox/maps';

function BuildingsWithLighting() {
  return (
    <MapView style={{ flex: 1 }}>
      <Light
        style={{
          intensity: 0.8,
          color: '#ffffff',
          position: [1.5, 135, 60],
        }}
      />
      <Camera
        centerCoordinate={[-74.006, 40.7128]}
        zoomLevel={16}
        pitch={60}
      />
      <VectorSource id="composite" url="mapbox://mapbox.mapbox-streets-v8">
        <FillExtrusionLayer
          id="3d-buildings"
          sourceLayer="building"
          filter={['==', 'extrude', 'true']}
          style={{
            fillExtrusionColor: '#aaa',
            fillExtrusionHeight: ['get', 'height'],
            fillExtrusionBase: ['get', 'min_height'],
            fillExtrusionOpacity: 0.6,
          }}
        />
      </VectorSource>
    </MapView>
  );
}

Additional Resources

Build docs developers (and LLMs) love