

npm i tango-map-cw @amap/amap-jsapi-loadernpm i ol// React
import { TangoMapViewer } from "tango-map-cw";
// Next
import dynamic from "next/dynamic";
const TangoMapViewer = dynamic(
() => import("tango-map-cw").then(mod => mod.TangoMapViewer),
{ ssr: false }
);
// provide WGS84
const beijingGugong: [number, number] = [116.390741, 39.917351];
<TangoMapViewer
provider="amap" // map provider,support amap and ol(OpenStreetMap)
mapKey="your map key"
center={beijingGugong}
zoom={13} // the initial zoom ratio of the map, the zoom size of the map when loading(3-18)
style={{ width: "600px", height: "400px" }}
/>
// provide WGS84
type Marker = {
id: string | number;
mark: [number, number]; // [lon, lat],WGS84
icon?: {
url: string; // supports images, but not SVG
size?: [number, number]; // width, height, icon size
};
};
// makers array
const markers = [
{
id: "point 1",
mark: [116.390741, 39.917351],
},
{
id: "point 2",
mark: [116.400741, 39.917351],
},
{
id: "point 3",
mark: [116.400741, 39.927351],
},
];
// show on map
<TangoMapViewer
provider="amap"
mapKey="your map key"
center={beijingGugong}
zoom={13}
style={{ width: "600px", height: "400px" }}
markers={markers} // markers array
/>
// provide WGS84
type Line ={
id: string | number;
coordinates: number[][];
strokeColor?: string;
strokeWidth?: number;
lineJoin?: "round" | "bevel" | "miter"; // polyline inflection point connection style
}
// array of node coordinates of the polyline
const allLines = [
{
id: "userLine1",
coordinates: [
[116.397128, 39.926],
[116.404, 39.914],
[116.388, 39.92],
[116.406, 39.921],
[116.39, 39.913],
[116.397128, 39.926],
],
strokeWidth: 4, // line width
strokeColor: "blue", // line color
lineJoin: "round", // polyline inflection point connection style
},
];
// show on map
<TangoMapViewer
provider="amap"
mapKey="your map key"
center={beijingGugong}
zoom={13}
style={{ width: "600px", height: "400px" }}
line={allLines} // polylines array
/>
<TangoMapViewer
provider="amap"
mapKey="your map key"
center={beijingGugong}
zoom={13}
style={{ width: "600px", height: "400px" }}
location // get the current location and display the positioning button
onLocate={(data) => { // positioning success callback
console.log("data ==> ", data);
}}
/>
Props | Type | Value | Description | Default Value |
|---|---|---|---|---|
provider | String | amap | ol | map provider(Next support amap,React support amap and ol) | ol |
mapKey | String | - | your map key | - |
center | Array | - | map center coordinate (WGS84) | - |
zoom | Number | - | map initial zoom(3-18) | 10 |
minZoom | Number | - | map minimum zoom(3-18) | 3 |
maxZoom | Number | - | map maximum zoom(3-18) | 18 |
markers | Array | - | map markers array,one marker or more markers | - |
location | Boolean | - | enable positioning (currently supports browser positioning based on Amap SDK in mainland China, and supports native positioning in the international market) | false |
onLocate | () => void | - | callback after successful positioning (data.position.pos is the coordinate after positioning) | - |
viewMode | String | 2D | 3D | map view mode | 2D |
line | Array | - | the coordinate array of the vector polyline nodes on the map, supporting one or more vector polylines | - |
onClick | () => void | - | map click callback | - |
style | Object | - | custom map style | - |