API Reference

Complete reference for all map components and their props.

Note: This library is built on top of AMap JS API. Most components extend the native AMap options. Refer to the AMap Map API for additional options not listed here.

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.

PropTypeDefaultDescription
childrenReactNode—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 } | null

Coordinate 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);
PropTypeDefaultDescription
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.

PropTypeDefaultDescription
position"top-left" | "top-right" | "bottom-left" | "bottom-right""bottom-right"Position of the controls on the map.
showZoombooleantrueShow zoom in/out buttons.
showCompassbooleanfalseShow compass button to reset bearing.
showLocatebooleanfalseShow locate button to find user's location.
showFullscreenbooleanfalseShow fullscreen toggle button.
showScalebooleanfalseShow a scale bar at the bottom-left of the map.
classNamestring—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).

PropTypeDefaultDescription
longitudenumber—Longitude coordinate for marker position.
latitudenumber—Latitude coordinate for marker position.
childrenReactNode—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).
visiblebooleantrueShow 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.

PropTypeDefaultDescription
childrenReactNode—Custom marker content. Defaults to a blue dot.
classNamestring—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).

The 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.
PropTypeDefaultDescription
childrenReactNode—Popup content.
classNamestring—Additional CSS classes for the popup container.
closeButtonbooleanfalseShow 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).

The 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.
PropTypeDefaultDescription
childrenReactNode—Tooltip content.
classNamestring—Additional CSS classes for the tooltip container.

MarkerLabel

Renders a text label above or below the marker. Must be used inside MarkerContent.

PropTypeDefaultDescription
childrenReactNode—Label text content.
classNamestring—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).

The 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.
PropTypeDefaultDescription
longitudenumber—Longitude coordinate for popup position.
latitudenumber—Latitude coordinate for popup position.
onClose() => void—Callback when popup is closed.
childrenReactNode—Popup content.
classNamestring—Additional CSS classes for the popup container.
closeButtonbooleanfalseShow a close button in the popup.

MapRoute

Renders a line/route on the map connecting coordinate points. Must be used inside Map.

PropTypeDefaultDescription
coordinates[number, number][]—Array of [longitude, latitude] coordinate pairs.
colorstring"#4285F4"Line color (CSS color value).
widthnumber4Line width in pixels.
opacitynumber0.8Line opacity (0 to 1).
dashedbooleanfalseRender 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>.

PropTypeDefaultDescription
datastring | 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.
pointColorstring"#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.

PropTypeDefaultDescription
coordinates[number, number][]—Array of [lng, lat] pairs (min 3 points).
fillColorstring"#3b82f6"Fill color.
fillOpacitynumber0.3Fill opacity (0 to 1).
strokeColorstring"#3b82f6"Stroke color.
strokeWidthnumber2Stroke width in pixels.
strokeOpacitynumber0.8Stroke 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.

PropTypeDefaultDescription
center[number, number]—Circle center [longitude, latitude] in GCJ-02.
radiusnumber—Radius in meters.
fillColorstring"#3b82f6"Fill color.
fillOpacitynumber0.2Fill opacity (0 to 1).
strokeColorstring"#3b82f6"Stroke color.
strokeWidthnumber2Stroke width in pixels.
strokeOpacitynumber0.8Stroke 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.

PropTypeDefaultDescription
dataHeatmapPoint[] | GeoJSON.FeatureCollection<Point>—Array of { lng, lat, count? } or GeoJSON FeatureCollection<Point>.
radiusnumber30Point influence radius in pixels.
opacitynumber0.8Maximum opacity (0 to 1).
gradientRecord<string, string>—Color gradient. Keys are 0-1 positions. Defaults to blue → cyan → green → yellow → red.
maxnumber100Maximum count value for normalization.

MapTrafficLayer

Overlays real-time traffic conditions. Must be used inside Map. See Layers for a full example.

PropTypeDefaultDescription
visiblebooleantrueShow or hide the layer.
opacitynumber1Layer opacity (0 to 1).

MapSatelliteLayer

Overlays satellite/aerial imagery. Must be used inside Map. See Layers for a full example.

PropTypeDefaultDescription
visiblebooleantrueShow or hide the layer.
opacitynumber1Layer opacity (0 to 1).