简体   繁体   中英

React Leaflet Not Showing Map Correctly

I am trying to use react leaflet however map could not be rendered correctly below is the code:

import {Marker, Popup, TileLayer} from "leaflet/dist/leaflet-src.esm";
import {render} from "@testing-library/react";
import {useCallback, useMemo, useRef, useState} from "react";
import 'leaflet/dist/leaflet.css';

const center = {
    lat: 51.505,
    lng: -0.09,
}


function MapContainer(props) {
    return null;
}

render(
    <MapContainer /*center={center} zoom={13} scrollWheelZoom={false}*/>
        <TileLayer
            attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
            url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
        />
    </MapContainer>,
)
export default MapContainer;

and below is map rendered incorrectly.

I tried to search but i am not getting through it

在此处输入图片说明

I suggest u go throw this question and maybe u get ur answer

react-leaflet map not correctly displayed

adding below line in my .css worked

@import url("~leaflet/dist/leaflet.css");

.leaflet-container {
  width: 100%;
  height: 100vh;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM