0

I have a weird issue with my react leaft app. I want to create a leaflet map with react ionic. When I run it the map dose not render properly. enter image description here

However, when I add just <div></div> , or any element, before the MapContainer, and click on save the map renders without any issue.

 import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/react';
import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet';
import './Tab1.css';

const Tab1: React.FC = () => {
  return (
    <IonPage>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Tab 1</IonTitle>
        </IonToolbar>
      </IonHeader>
      <IonContent fullscreen>
        <IonHeader collapse="condense">
          <IonToolbar>
            <IonTitle size="large">Tab 1</IonTitle>
          </IonToolbar>
        </IonHeader>
        <MapContainer className='map-container' center={[51.505, -0.09]} zoom={13} scrollWheelZoom={false}>
          <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={[51.505, -0.09]}>
            <Popup>
              A pretty CSS3 popup. <br /> Easily customizable.
            </Popup>
          </Marker>
        </MapContainer>

      </IonContent>
    </IonPage>
  );
};

export default Tab1;

enter image description here

Now, if I just refresh the app, the map goes away, and does not display correctly again.

nabaz
  • 55
  • 9
  • Hey, can you copy and paste the code snippet instead of posting a screenshot? This way, it can be indexed better, and also people will be able to paste the code to play with it to come up with an answer. – f.khantsis Sep 29 '22 at 15:51

0 Answers0