API Reference
Complete reference for all map components and their props.
Component Anatomy
All parts of the component that you can use and combine to build your map.
<Map>
<MapMarker longitude={...} latitude={...}>
<MarkerContent>
<MarkerLabel />
</MarkerContent>
<MarkerPopup />
<MarkerTooltip />
</MapMarker>
<MapPopup longitude={...} latitude={...} />
<MapControls />
<MapRoute coordinates={...} />
<MapClusterLayer data={...} />
<MapPolygon coordinates={...} />
<MapCircle center={...} radius={...} />
<MapHeatmap data={...} />
<MapTrafficLayer />
<MapSatelliteLayer />
</Map>Map
The root container component that initializes AMap JS API and provides context to child components. Automatically handles theme switching between light and dark modes.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Child components (markers, popups, controls, routes, etc.). |
styles | { light?: string; dark?: string } | — | Custom AMap style URLs for light and dark themes. |
bounds | [[number, number], [number, number]] | — | Fit the viewport to [SW corner, NE corner] bounds. Reacts to prop changes. |
viewMode | "2D" | "3D" | "3D" | Map projection mode. Only takes effect on initial mount. |
onLoad | () => void | — | Called once when the map finishes loading. |
onClick | (lngLat: { lng: number; lat: number }) => void | — | Called when the map canvas is clicked. |
onMoveEnd | () => void | — | Called when the map finishes panning. |
onZoomEnd | () => void | — | Called when the map finishes zooming. |
onError | (error: Error) => void | — | Called when AMap JS API fails to load. |
useMap
A hook that provides access to the AMap map instance and loading state. Must be used within a Map component.
const { map, isLoaded } = useMap();Returns map (AMap.Map) and isLoaded (boolean) tells you if the map is loaded and ready to use.
useMapEvent
Subscribes to a map event and cleans up automatically on unmount. Must be called inside a Map component.
useMapEvent("click", (e) => console.log(e.lnglat));Accepts any AMap map event name such as click, moveend, zoomend, pitchchange, etc.
useMapBounds
Returns the current viewport bounds, updating automatically on every pan/zoom. Must be called inside a Map component.
const bounds = useMapBounds();
// { north, south, east, west } | nullCoordinate Utilities
AMap uses the GCJ-02 coordinate system (China national standard). GPS devices output WGS-84. Use these utilities to convert between them.
import { wgs84ToGcj02, gcj02ToWgs84 } from "amapcn";
// Convert GPS coordinates to AMap (GCJ-02)
const [lng, lat] = wgs84ToGcj02(121.473, 31.230);
// Convert back to WGS-84
const [wgsLng, wgsLat] = gcj02ToWgs84(lng, lat);| Prop | Type | Default | Description |
|---|---|---|---|
wgs84ToGcj02(lng, lat) | [number, number] | — | Converts WGS-84 GPS coordinates to GCJ-02 (AMap). Returns [lng, lat]. |
gcj02ToWgs84(lng, lat) | [number, number] | — | Converts GCJ-02 (AMap) coordinates back to WGS-84 GPS via iterative approximation. Returns [lng, lat]. |
MapControls
Renders map control buttons (zoom, compass, locate, fullscreen, scale). Must be used inside Map.
| Prop | Type | Default | Description |
|---|---|---|---|
position | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "bottom-right" | Position of the controls on the map. |
showZoom | boolean | true | Show zoom in/out buttons. |
showCompass | boolean | false | Show compass button to reset bearing. |
showLocate | boolean | false | Show locate button to find user's location. |
showFullscreen | boolean | false | Show fullscreen toggle button. |
showScale | boolean | false | Show a scale bar at the bottom-left of the map. |
className | string | — | Additional CSS classes for the controls container. |
onLocate | (coords: { longitude: number; latitude: number }) => void | — | Callback with user coordinates when located. |
MapMarker
A container for marker-related components. Provides context for its children and handles marker positioning.
Extends MarkerOptions from AMap JS API (excluding element).
| Prop | Type | Default | Description |
|---|---|---|---|
longitude | number | — | Longitude coordinate for marker position. |
latitude | number | — | Latitude coordinate for marker position. |
children | ReactNode | — | Marker subcomponents (MarkerContent, MarkerPopup, etc). |
onClick | () => void | — | Callback when marker is clicked. |
onMouseEnter | () => void | — | Callback when mouse enters marker. |
onMouseLeave | () => void | — | Callback when mouse leaves marker. |
onDragStart | (lngLat: { lng: number; lat: number }) => void | — | Callback when marker drag starts (requires draggable: true). |
onDragEnd | (lngLat: { lng: number; lat: number }) => void | — | Callback when marker drag ends (requires draggable: true). |
visible | boolean | true | Show or hide the marker. |
MarkerContent
Renders the visual content of a marker. Must be used inside MapMarker. If no children provided, renders a default blue dot marker.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Custom marker content. Defaults to a blue dot. |
className | string | — | Additional CSS classes for the marker container. |
MarkerPopup
Renders a popup attached to the marker that opens on click. Must be used inside MapMarker.
Extends PopupOptions from AMap JS API (excluding className and closeButton).
className and closeButtonfrom AMap's PopupOptions are excluded to prevent style conflicts. Use the component's own props to style the popup. AMap's default popup styles are reset via CSS.| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Popup content. |
className | string | — | Additional CSS classes for the popup container. |
closeButton | boolean | false | Show a close button in the popup. |
MarkerTooltip
Renders a tooltip that appears on hover. Must be used inside MapMarker.
Extends PopupOptions from AMap JS API (excluding className, closeButton, and closeOnClick as tooltips auto-dismiss on hover out).
classNamefrom AMap's PopupOptions is excluded to prevent style conflicts. Use the component's own classNameprop to style the tooltip content. AMap's default popup styles are reset via CSS.| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Tooltip content. |
className | string | — | Additional CSS classes for the tooltip container. |
MarkerLabel
Renders a text label above or below the marker. Must be used inside MarkerContent.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Label text content. |
className | string | — | Additional CSS classes for the label. |
position | "top" | "bottom" | "top" | Position of the label relative to the marker. |
MapPopup
A standalone popup component that can be placed anywhere on the map without a marker. Must be used inside Map.
Extends PopupOptions from AMap JS API (excluding className and closeButton).
className and closeButtonfrom AMap's PopupOptions are excluded to prevent style conflicts. Use the component's own props to style the popup. AMap's default popup styles are reset via CSS.| Prop | Type | Default | Description |
|---|---|---|---|
longitude | number | — | Longitude coordinate for popup position. |
latitude | number | — | Latitude coordinate for popup position. |
onClose | () => void | — | Callback when popup is closed. |
children | ReactNode | — | Popup content. |
className | string | — | Additional CSS classes for the popup container. |
closeButton | boolean | false | Show a close button in the popup. |
MapRoute
Renders a line/route on the map connecting coordinate points. Must be used inside Map.
| Prop | Type | Default | Description |
|---|---|---|---|
coordinates | [number, number][] | — | Array of [longitude, latitude] coordinate pairs. |
color | string | "#4285F4" | Line color (CSS color value). |
width | number | 4 | Line width in pixels. |
opacity | number | 0.8 | Line opacity (0 to 1). |
dashed | boolean | false | Render the route as a dashed line. |
onClick | () => void | — | Callback when the route line is clicked. |
MapClusterLayer
Renders clustered point data using AMap JS API's native clustering. Automatically groups nearby points into clusters that expand on click. Must be used inside Map. Supports a generic type parameter for typed feature properties: MapClusterLayer<MyProperties>.
| Prop | Type | Default | Description |
|---|---|---|---|
data | string | GeoJSON.FeatureCollection | — | GeoJSON FeatureCollection data or URL to fetch GeoJSON from. |
clusterColors | [string, string, string] | ["#51bbd6", "#f1f075", "#f28cb1"] | Colors for cluster circles: [small, medium, large] based on point count. |
pointColor | string | "#3b82f6" | Color for unclustered individual points. |
onPointClick | (feature: GeoJSON.Feature, coordinates: [number, number]) => void | — | Callback when an unclustered point is clicked. |
MapPolygon
Draws a filled polygon. Must be used inside Map. Requires at least 3 coordinate pairs. See Shapes for a full example.
| Prop | Type | Default | Description |
|---|---|---|---|
coordinates | [number, number][] | — | Array of [lng, lat] pairs (min 3 points). |
fillColor | string | "#3b82f6" | Fill color. |
fillOpacity | number | 0.3 | Fill opacity (0 to 1). |
strokeColor | string | "#3b82f6" | Stroke color. |
strokeWidth | number | 2 | Stroke width in pixels. |
strokeOpacity | number | 0.8 | Stroke opacity (0 to 1). |
onClick | () => void | — | Click callback. |
onMouseEnter | () => void | — | Mouse enter callback. |
onMouseLeave | () => void | — | Mouse leave callback. |
MapCircle
Draws a circle with a given center and radius in meters. Must be used inside Map. See Shapes for a full example.
| Prop | Type | Default | Description |
|---|---|---|---|
center | [number, number] | — | Circle center [longitude, latitude] in GCJ-02. |
radius | number | — | Radius in meters. |
fillColor | string | "#3b82f6" | Fill color. |
fillOpacity | number | 0.2 | Fill opacity (0 to 1). |
strokeColor | string | "#3b82f6" | Stroke color. |
strokeWidth | number | 2 | Stroke width in pixels. |
strokeOpacity | number | 0.8 | Stroke opacity (0 to 1). |
onClick | () => void | — | Click callback. |
onMouseEnter | () => void | — | Mouse enter callback. |
onMouseLeave | () => void | — | Mouse leave callback. |
MapHeatmap
Renders a density heatmap. Must be used inside Map. Uses AMap's AMap.HeatMap plugin. See Heatmap for a full example.
| Prop | Type | Default | Description |
|---|---|---|---|
data | HeatmapPoint[] | GeoJSON.FeatureCollection<Point> | — | Array of { lng, lat, count? } or GeoJSON FeatureCollection<Point>. |
radius | number | 30 | Point influence radius in pixels. |
opacity | number | 0.8 | Maximum opacity (0 to 1). |
gradient | Record<string, string> | — | Color gradient. Keys are 0-1 positions. Defaults to blue → cyan → green → yellow → red. |
max | number | 100 | Maximum count value for normalization. |
MapTrafficLayer
Overlays real-time traffic conditions. Must be used inside Map. See Layers for a full example.
| Prop | Type | Default | Description |
|---|---|---|---|
visible | boolean | true | Show or hide the layer. |
opacity | number | 1 | Layer opacity (0 to 1). |
MapSatelliteLayer
Overlays satellite/aerial imagery. Must be used inside Map. See Layers for a full example.
| Prop | Type | Default | Description |
|---|---|---|---|
visible | boolean | true | Show or hide the layer. |
opacity | number | 1 | Layer opacity (0 to 1). |