Вы не добавили файл css листовки в свой index.html
.
Для листовки версии 1.3.4
добавьте следующее в index.html
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"
integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
crossorigin=""/>
В файле CSS компонента карты переопределите класс leaflet-container
с желаемой высотой и шириной.
.leaflet-container {
height: 600px;
width: 100%;
}
Как только вы добавите это, используйте Map
и TileLayer
Компоненты react-leaflet
для рендеринга карты.
import React, { Component } from "react";
import ReactDOM from "react-dom";
import { Map, TileLayer } from "react-leaflet";
import "./styles.css";
class App extends Component {
state = {
center: [51.505, -0.091],
zoom: 13
};
render() {
return (
<div>
<Map center={this.state.center} zoom={this.state.zoom}>
<TileLayer
attribution='&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.osm.org/{z}/{x}/{y}.png"
/>
</Map>
</div>
);
}
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Вы можете найти рабочий код здесь.https://codesandbox.io/s/2wnv7o1mlr