简体   繁体   English

TileLayer 以不同的顺序显示(使用 React-Leaflet 库)

[英]TileLayer displays in different order (Using React-Leaflet library)

I'm trying to do a simple Web App using the library react-leaflet.我正在尝试使用库 react-leaflet 做一个简单的 Web 应用程序。

I have the following code:我有以下代码:

import React from 'react';
import { Map, Marker, Popup, TileLayer } from 'react-leaflet';

class LeafletMap extends React.Component {
  constructor() {
    super();
    this.state = {
      lat: 51.505,
      lng: -0.09,
      zoom: 13,
    };
  }

  render() {
    const position = [this.state.lat, this.state.lng];
    return (
      <Map center={position} zoom={this.state.zoom}>
        <TileLayer
          url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
        />
        <Marker position={position}>
          <Popup>
            <span>A pretty CSS3 popup. <br/> Easily customizable.</span>
          </Popup>
        </Marker>
      </Map>
    );
  }
}
export default LeafletMap;

However, The TileLayer is displaying in random order all the time.但是,TileLayer 始终以随机顺序显示。 I've read a lot of code where It must work with ComponentDidMount() by Reactjs , but The renders that I've seen are totally different compared to the library.我已经阅读了很多代码,其中它必须与Reactjs ComponentDidMount() Reactjs ,但是与库相比,我看到的渲染完全不同。

Do you have any idea what can I do?你知道我能做什么吗?

The only reason It was not working is because we need to add the following code in index.html :它不起作用的唯一原因是我们需要在index.html添加以下代码:

<link rel="stylesheet" href="https://npmcdn.com/leaflet@1.0.0-rc.2/dist/leaflet.css" />
<style type="text/css">
    .leaflet-container {
        height: 400px;
    }
</style>

That's all.仅此而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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