import React, { useMemo, useState } from 'react'; import { Amap, Circle as AmapCircle, InfoWindow } from '@amap/amap-react'; import type { MapConfig, MapValue } from '../index'; export interface MapCircleValue { center: Partial; radius: number; } export interface MapCircleProps extends MapConfig { value?: MapCircleValue; } export function Circle(props: MapCircleProps) { const center = useMemo(() => { if (!props.value) return undefined; const data = props.value.center; if (data.coordinate) return data.coordinate; else if (data.longitude && data.latitude) return [data.longitude, data.latitude]; return undefined; }, [props.value]); const radius = useMemo(() => { if (!props.value) return 0; return props.value.radius; }, [props.value]); const [active, setActive] = useState(false); return (
{props.headerTip && (
{props.headerTip}
)} {center && ( { if (!props.showTip) return; setActive(true); }} /> )} {props.showTip && center && active && ( { setActive(false); }} content={`中心点:${center.join(',')};半径:${radius}`} /> )}
); }