Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

477
Views
React-Leaflet: no se puede mostrar el mapa del folleto correctamente después de alternar usando el componente funcional

Cuando hago clic en el botón "Buscar patrimonio", quiero mostrar el mapa en mi página web. Sin embargo, el mapa del folleto no se puede mostrar correctamente como se muestra a continuación:

visualización de la página web

El mapa se puede mostrar completamente sin ningún problema una vez que cambio el tamaño de mi página web. He encontrado algunas soluciones que pueden resolver este problema en función del componente de clase, pero no tengo idea de cómo resolverlo cuando uso un componente funcional.

Aquí está mi código actual.

  1. folleto.tsx
 import "./leaflet.css"; import { MapContainer, TileLayer, useMap, Popup, Marker } from "react-leaflet"; export default function Leaflet() { const mapRef: any = createRef(); useEffect(() => { const map = mapRef.leafletElement; setTimeout(() => { map.invalidateSize(); }, 1000); }, [mapRef]); return ( <div className="map"> <MapContainer center={[22.3193, 114.1694]} zoom={10} scrollWheelZoom={false} ref={mapRef} > <TileLayer attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" /> <Marker position={[50.5, 30.5]}> <Popup></Popup> </Marker> </MapContainer> </div> ); }

2.folleto.css

 font-family: sans-serif; text-align: center; } .leaflet-container { height: 600px; width: 100%; } .leaflet-div-icon { background: transparent; border: none; }

Estoy usando el folleto de reacción ^ 4.0.0

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!