Skip to main content

Polygon

The Polygon component draws a filled area on the map. You can define the shape either as a list of coordinates or as a circle. Must be rendered as a child of <Map>.

Import

import { Polygon } from 'react-native-here-explore';
import type { PolygonProps } from 'react-native-here-explore';

Usage

From coordinates

<Map mapScheme="NORMAL_DAY" geoCoordinates={{ latitude: 34.0, longitude: -6.8 }} zoomValue={10}>
<Polygon
geoPolyline={[
{ latitude: 33.819096, longitude: -7.320056 },
{ latitude: 34.460004, longitude: -7.320056 },
{ latitude: 34.460004, longitude: -6.121828 },
{ latitude: 33.819096, longitude: -6.121828 },
]}
color="rgba(0, 120, 255, 0.3)"
outlineColor="#0078FF"
outlineWidth={2}
/>
</Map>

Circle polygon

<Polygon
geoCircle={{
center: { latitude: 33.819096, longitude: -7.320056 },
radiusInMeters: 5000,
}}
color="rgba(255, 100, 0, 0.25)"
outlineColor="#FF6400"
outlineWidth={3}
/>

Highlight a zone

<Polygon
geoPolyline={zoneCoordinates}
color="rgba(76, 175, 80, 0.4)"
outlineColor="#388E3C"
outlineWidth={1}
/>

Props

Common props (both modes)

PropTypeRequiredDefaultDescription
colorColorValueNoblackFill color of the polygon
outlineColorColorValueNoBorder color
outlineWidthnumberNo0Border thickness in pixels

Via geoPolyline

PropTypeRequiredDescription
geoPolylineGeoPolylineYesArray of coordinates forming the polygon boundary. The shape is closed automatically

Via geoCircle

PropTypeRequiredDescription
geoCircleGeoCircleYesCenter coordinate and radius in meters
note

Use either geoPolyline or geoCircle — not both.


Color formats

All color props accept any React Native ColorValue:

"green"                       // named color
"#4CAF50" // hex
"rgba(76, 175, 80, 0.4)" // rgba with transparency
"#4CAF5066" // hex with alpha

Using a semi-transparent fill color (rgba with alpha < 1) lets the map show through the polygon, which is usually the desired effect.