MCPcopy Create free account
hub / github.com/ImGoodBai/MapGoGoGo / AmapView

Function AmapView

frontend/src/maps.tsx:212–445  ·  view source on GitHub ↗
({
  config,
  challenge,
  cells = [],
  unlocked = new Set(),
  mine = new Set(),
  currentPosition,
  currentCellId,
  selectedCenter,
  selectedRadiusM,
  rotationDeg = 0,
  onCenterChange,
  onCellClick,
  className,
}: MapProps)

Source from the content-addressed store, hash-verified

210}
211
212function AmapView({
213 config,
214 challenge,
215 cells = [],
216 unlocked = new Set(),
217 mine = new Set(),
218 currentPosition,
219 currentCellId,
220 selectedCenter,
221 selectedRadiusM,
222 rotationDeg = 0,
223 onCenterChange,
224 onCellClick,
225 className,
226}: MapProps) {
227 const containerRef = useRef<HTMLDivElement | null>(null);
228 const mapRef = useRef<any>(null);
229 const staticOverlaysRef = useRef<any[]>([]);
230 const cellPolygonsRef = useRef<Map<string, any>>(new Map());
231 const previousCellStyleRef = useRef<CellStyleState | null>(null);
232 const positionOverlaysRef = useRef<PositionOverlayState | null>(null);
233 const onCenterChangeRef = useRef(onCenterChange);
234 const onCellClickRef = useRef(onCellClick);
235 const fitKeyRef = useRef("");
236 const [error, setError] = useState("");
237 const [mapReady, setMapReady] = useState(0);
238 const [zoom, setZoom] = useState(challenge ? 15 : 13);
239
240 onCenterChangeRef.current = onCenterChange;
241 onCellClickRef.current = onCellClick;
242
243 useEffect(() => {
244 if (!config?.has_amap || !containerRef.current || mapRef.current) return;
245 loadAmap(config, ["AMap.ControlBar"])
246 .then((AMap: any) => {
247 const center = selectedCenter
248 ? [selectedCenter.lng, selectedCenter.lat]
249 : challenge
250 ? [challenge.center_lng, challenge.center_lat]
251 : [116.4074, 39.9042];
252 const map = new AMap.Map(containerRef.current, {
253 zoom,
254 center,
255 rotation: normalizeRotation(rotationDeg),
256 rotateEnable: true,
257 viewMode: "2D",
258 mapStyle: "amap://styles/whitesmoke",
259 });
260 map.on("zoomchange", () => setZoom(map.getZoom()));
261 map.on("click", (event: any) => {
262 onCenterChangeRef.current?.({ lat: event.lnglat.lat, lng: event.lnglat.lng });
263 });
264 mapRef.current = { map, AMap } satisfies AMapContext;
265 setMapReady((value) => value + 1);
266 })
267 .catch((err) => setError(String(err)));
268 }, [challenge, config, selectedCenter]);
269

Callers

nothing calls this directly

Calls 10

loadAmapFunction · 0.85
normalizeRotationFunction · 0.85
removeOverlaysFunction · 0.85
safeCellBoundaryFunction · 0.85
cellStyleFunction · 0.85
cloneCellStyleStateFunction · 0.85
addChangedCellsFunction · 0.85
applyOverlayOptionsFunction · 0.85
positionOverlayOptionsFunction · 0.85
zoomByFunction · 0.85

Tested by

no test coverage detected