Skip to content

Overlays API

Overlay components are used to display various graphic elements on the map.

Circle

Properties

PropertyTypeDefaultDescription
centerLatLng-Circle center coordinate (required)
radiusnumber-Radius (meters)
fillColorstring-Fill color
strokeColorstring-Stroke color
strokeWidthnumber1Stroke width

Example

tsx
<MapView>
  <Circle
    center={{ latitude: 39.9, longitude: 116.4 }}
    radius={1000}
    fillColor="#8800FF00"
    strokeColor="#FFFF0000"
    strokeWidth={2}
    onPress={() => console.log('Circle pressed')}
  />
</MapView>

Marker

Properties

PropertyTypeDefaultDescription
positionLatLng-Marker coordinate (required)
titlestring-Title
snippetstring-Description
draggablebooleanfalseWhether draggable
iconstring-Custom icon
iconWidthnumber40Icon width
iconHeightnumber40Icon height

Example

tsx
<MapView>
  <Marker
    position={{ latitude: 39.9, longitude: 116.4 }}
    title="Beijing"
    snippet="Capital of China"
    draggable={true}
    onPress={() => console.log('Marker pressed')}
    onDragEnd={(e) => console.log('Drag ended', e.nativeEvent)}
  />
</MapView>

Custom Icon

tsx
import { Image } from 'react-native';

const iconUri = Image.resolveAssetSource(require('./marker.png')).uri;

<Marker
  position={{ latitude: 39.9, longitude: 116.4 }}
  icon={iconUri}
  iconWidth={50}
  iconHeight={50}
/>

Custom View

tsx
<Marker
  position={{ latitude: 39.9, longitude: 116.4 }}
>
  <View style={{ backgroundColor: '#fff', padding: 8, borderRadius: 8 }}>
    <Text>Custom Content</Text>
  </View>
</Marker>

Polyline

Properties

PropertyTypeDefaultDescription
pointsLatLng[]-Polyline coordinate array (required)
widthnumber5Line width
colorstring-Line color
texturestring-Texture image URL

Example

tsx
<MapView>
  <Polyline
    points={[
      { latitude: 39.9, longitude: 116.4 },
      { latitude: 39.95, longitude: 116.45 },
      { latitude: 40.0, longitude: 116.5 },
    ]}
    width={5}
    color="#FFFF0000"
    onPress={() => console.log('Polyline pressed')}
  />
</MapView>

Polygon

Properties

PropertyTypeDefaultDescription
pointsLatLng[]-Polygon vertex array (required)
fillColorstring-Fill color
strokeColorstring-Stroke color
strokeWidthnumber1Stroke width

Example

tsx
<MapView>
  <Polygon
    points={[
      { latitude: 39.9, longitude: 116.3 },
      { latitude: 39.9, longitude: 116.4 },
      { latitude: 39.8, longitude: 116.4 },
    ]}
    fillColor="#8800FF00"
    strokeColor="#FFFF0000"
    strokeWidth={2}
    onPress={() => console.log('Polygon pressed')}
  />
</MapView>

Color Format

Overlay colors use ARGB format: #AARRGGBB

  • AA: Alpha (00-FF)
  • RR: Red (00-FF)
  • GG: Green (00-FF)
  • BB: Blue (00-FF)

Examples:

  • #FFFF0000 - Opaque red
  • #8800FF00 - 50% transparent green
  • #FF0000FF - Opaque blue

Complete Example

tsx
import { MapView, Circle, Marker, Polyline, Polygon } from 'expo-gaode-map';

export default function OverlaysExample() {
  return (
    <MapView
      style={{ flex: 1 }}
      initialCameraPosition={{
        target: { latitude: 39.9, longitude: 116.4 },
        zoom: 10,
      }}
    >
      {/* Circle */}
      <Circle
        center={{ latitude: 39.9, longitude: 116.4 }}
        radius={1000}
        fillColor="#8800FF00"
        strokeColor="#FFFF0000"
      />

      {/* Marker */}
      <Marker
        position={{ latitude: 39.95, longitude: 116.45 }}
        title="Marker"
      />

      {/* Polyline */}
      <Polyline
        points={[
          { latitude: 39.9, longitude: 116.4 },
          { latitude: 39.95, longitude: 116.45 },
        ]}
        width={5}
        color="#FF0000FF"
      />

      {/* Polygon */}
      <Polygon
        points={[
          { latitude: 39.85, longitude: 116.35 },
          { latitude: 39.85, longitude: 116.45 },
          { latitude: 39.75, longitude: 116.40 },
        ]}
        fillColor="#880000FF"
      />
    </MapView>
  );
}

Cluster

Used to display large amounts of point data, automatically clustering nearby points.

Properties

PropertyTypeDefaultDescription
pointsClusterPoint[]-Cluster point data array (required)
radiusnumber30Cluster radius
minClusterSizenumber1Minimum cluster size (count >= this value shows cluster style)
clusterStyleViewStyle-Base cluster style (backgroundColor, borderColor, borderWidth, width, height)
clusterTextStyleTextStyle-Cluster text style (color, fontSize, fontWeight)
clusterBucketsBucket[]-Tiered style configuration
onClusterPressfunction-Press event

Tiered Style (clusterBuckets)

The clusterBuckets property allows displaying different colors based on the cluster count.

tsx
clusterBuckets={[
  { minPoints: 1, backgroundColor: '#00BFFF' }, // 1: Blue
  { minPoints: 2, backgroundColor: '#32CD32' }, // 2-4: Green
  { minPoints: 5, backgroundColor: '#FFA500' }, // 5-9: Orange
  { minPoints: 10, backgroundColor: '#FF4500' } // 10+: Red
]}

Example

tsx
<Cluster
  points={data}
  radius={30}
  minClusterSize={1}
  clusterBuckets={[
    { minPoints: 1, backgroundColor: '#00BFFF' },
    { minPoints: 5, backgroundColor: '#FFA500' }
  ]}
  clusterStyle={{
    width: 40,
    height: 40,
    borderColor: 'white',
    borderWidth: 2,
  }}
  onClusterPress={(e) => console.log(e.nativeEvent)}
/>

MultiPoint (MassPoint)

Used to display thousands of points on the map, with better performance than standard Markers.

Properties

PropertyTypeDefaultDescription
pointsMultiPointItem[]-Point data array (required)
iconstring-Icon resource URI
iconWidthnumber-Icon width
iconHeightnumber-Icon height
onMultiPointPressfunction-Press event

Example

tsx
import { Image } from 'react-native';
const iconUri = Image.resolveAssetSource(require('./point.png')).uri;

<MultiPoint
  points={points}
  icon={iconUri}
  iconWidth={30}
  iconHeight={30}
  onMultiPointPress={(e) => console.log('Clicked index:', e.nativeEvent.index)}
/>

HeatMap

Used to display data density distribution.

Android Notes

If you use HeatMap on Android, you must enable Jetifier in your app's android/gradle.properties (otherwise you may hit java.lang.NoClassDefFoundError: android.support.v4.util.LongSparseArray and the heatmap won't render):

android.enableJetifier=true

Properties

PropertyTypeDefaultDescription
dataHeatMapPoint[]-Heat map data (lat, lng, count)
radiusnumber12Heat radius
opacitynumber0.6Opacity (0-1)
gradientobject-Gradient configuration

Example

tsx
<HeatMap
  data={points}
  radius={30}
  opacity={0.5}
  gradient={{
    colors: ['blue', 'green', 'red'],
    startPoints: [0.2, 0.5, 0.9]
  }}
/>