应用程序.js
import { useState } from 'react';
const App = () => {
// This state is used to the center attribute of MapContainer component
const [mapCenter, setMapCenter] = useState([34.80746, -40.4796]);
// This state is used to the zoom attribute of MapContainer component
const [mapZoom, setMapZoom] = useState(3);
const onClickHandler = () => {
setMapCenter([20, 100]);
setMapZoom(5);
};
return (
<>
<button onClick={onClickHandler}>Change map's center location</button>
<Map center={mapCenter} zoom={mapZoom} />
</>
);
};
Run Code Online (Sandbox Code Playgroud)
地图.js
import React from 'react';
import './Map.css'; …Run Code Online (Sandbox Code Playgroud)