小编박병찬*_*박병찬的帖子

当中心状态改变时,React 传单中心属性不会改变

应用程序.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)

leaflet reactjs

5
推荐指数
2
解决办法
4243
查看次数

标签 统计

leaflet ×1

reactjs ×1