• <i id='dWnH1'><tr id='dWnH1'><dt id='dWnH1'><q id='dWnH1'><span id='dWnH1'><b id='dWnH1'><form id='dWnH1'><ins id='dWnH1'></ins><ul id='dWnH1'></ul><sub id='dWnH1'></sub></form><legend id='dWnH1'></legend><bdo id='dWnH1'><pre id='dWnH1'><center id='dWnH1'></center></pre></bdo></b><th id='dWnH1'></th></span></q></dt></tr></i><div id='dWnH1'><tfoot id='dWnH1'></tfoot><dl id='dWnH1'><fieldset id='dWnH1'></fieldset></dl></div>

  • <legend id='dWnH1'><style id='dWnH1'><dir id='dWnH1'><q id='dWnH1'></q></dir></style></legend>

        <bdo id='dWnH1'></bdo><ul id='dWnH1'></ul>
    1. <tfoot id='dWnH1'></tfoot>

      <small id='dWnH1'></small><noframes id='dWnH1'>

      1. 反应传单地图未正确显示

        时间:2023-08-09
          <bdo id='m2zB4'></bdo><ul id='m2zB4'></ul>

            <legend id='m2zB4'><style id='m2zB4'><dir id='m2zB4'><q id='m2zB4'></q></dir></style></legend>
              <tbody id='m2zB4'></tbody>
            1. <small id='m2zB4'></small><noframes id='m2zB4'>

              <i id='m2zB4'><tr id='m2zB4'><dt id='m2zB4'><q id='m2zB4'><span id='m2zB4'><b id='m2zB4'><form id='m2zB4'><ins id='m2zB4'></ins><ul id='m2zB4'></ul><sub id='m2zB4'></sub></form><legend id='m2zB4'></legend><bdo id='m2zB4'><pre id='m2zB4'><center id='m2zB4'></center></pre></bdo></b><th id='m2zB4'></th></span></q></dt></tr></i><div id='m2zB4'><tfoot id='m2zB4'></tfoot><dl id='m2zB4'><fieldset id='m2zB4'></fieldset></dl></div>
                • <tfoot id='m2zB4'></tfoot>
                  本文介绍了反应传单地图未正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 react-leaflet 来显示地图.我使用

                  这是我的代码:

                  DeviceMap.js

                  从'react'导入反应从'react-leaflet'导入{地图,标记,弹出窗口,TileLayer};导出类 DeviceMap 扩展 React.Component {构造函数(){极好的();这个.state = {纬度:51.505,液化天然气:-0.09,缩放:13,};}使成为() {常量位置 = [this.state.lat, this.state.lng];返回 (<地图中心={position} zoom={this.state.zoom} scrollWheelZoom={false}>

                  DeviceTabs.js

                  导出类 DeviceTabs 扩展 React.Component {状态 = {指数:0};handleTabChange = (索引) =>{this.setState({ index })};使成为 () {返回 (<标签索引={this.state.index} onChange={this.handleTabChange}><标签标签='值'><DeviceTable {...this.props}/></标签><标签标签='地图'><div className={style.leaflet}><设备映射/></div></标签></标签>)}}

                  style.scss

                  .leaflet {高度:300px;宽度:100%;}

                  控制台中没有错误,我不知道在哪里搜索.由于小提琴正在工作,因此它不是错误.我错过了什么吗?

                  解决方案

                  看起来你还没有加载 Leaflet 样式表.

                  来自 react-leaflet GitHub 指南:

                  <块引用>

                  如果您不熟悉 Leaflet,请确保在使用此库之前阅读其快速入门指南.您尤其需要将其 CSS 添加到您的页面以正确呈现地图,并设置容器的高度.

                  http://leafletjs.com/examples/quick-start/

                  这是你需要的:

                  更新

                  注意 @ThomasThiebaud 表示您可能还需要设置 .leaflet-container

                  的高度

                  --

                  Ange Loron 还提供了一个正确的、可选的 JS 模块导入(相对于 cdn 或样式链接)

                  导入'leaflet/dist/leaflet.css';



                  对于它的价值,文档页面设计不佳...维护者在 GitHub 中不断处理这个问题,但由于某种原因,这个问题是*错误的用户不断不进行所需的设置./s

                  I'm trying to use react-leaflet to display a map. I use the code from this fiddle which is working, but on my computer I have this output

                  Here is my code :

                  DeviceMap.js

                  import React from 'react'
                  import { Map, Marker, Popup, TileLayer } from 'react-leaflet';
                  
                  export class DeviceMap 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} scrollWheelZoom={false}>
                          <TileLayer
                            attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                            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 DeviceMap
                  

                  DeviceTabs.js

                  export class DeviceTabs extends React.Component {
                    state = {
                      index: 0
                    };
                  
                    handleTabChange = (index) => {
                      this.setState({ index })
                    };
                  
                    render () {
                      return (
                        <Tabs index={this.state.index} onChange={this.handleTabChange}>
                          <Tab label='Values'>
                            <DeviceTable {...this.props} />
                          </Tab>
                          <Tab label='Map'>
                            <div className={style.leaflet}>
                              <DeviceMap />
                            </div>
                          </Tab>
                        </Tabs>
                      )
                    }
                  }
                  

                  style.scss

                  .leaflet {
                    height: 300px;
                    width: 100%;
                  }
                  

                  There is no error in the console, and I have no more idea where to search. Since the fiddle is working it is not a bug. Did I miss something ?

                  解决方案

                  Looks like you haven't loaded in the Leaflet stylesheet.

                  From the react-leaflet GitHub guide:

                  If you are not familiar with Leaflet, make sure you read its quick start guide before using this library. You will notably need to add its CSS to your page to render the map properly, and set the height of the container.

                  http://leafletjs.com/examples/quick-start/

                  Here is what you'll need:

                  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css" />
                  

                  Update

                  Note @ThomasThiebaud indicates you may also have to set up the height of .leaflet-container

                  --

                  Ange Loron also gave a correct, optional, JS module import (vs cdn or style link)

                  import 'leaflet/dist/leaflet.css';



                  For what its worth, the documentation page is poorly designed... and the maintainer continuously deals with this issue in GitHub, but for some reason, the issue is the *fault of the users who continuously don't do the required setup. /s

                  这篇关于反应传单地图未正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                      <tbody id='2P9Mo'></tbody>
                    • <tfoot id='2P9Mo'></tfoot><legend id='2P9Mo'><style id='2P9Mo'><dir id='2P9Mo'><q id='2P9Mo'></q></dir></style></legend>

                      <small id='2P9Mo'></small><noframes id='2P9Mo'>

                        <bdo id='2P9Mo'></bdo><ul id='2P9Mo'></ul>
                          <i id='2P9Mo'><tr id='2P9Mo'><dt id='2P9Mo'><q id='2P9Mo'><span id='2P9Mo'><b id='2P9Mo'><form id='2P9Mo'><ins id='2P9Mo'></ins><ul id='2P9Mo'></ul><sub id='2P9Mo'></sub></form><legend id='2P9Mo'></legend><bdo id='2P9Mo'><pre id='2P9Mo'><center id='2P9Mo'></center></pre></bdo></b><th id='2P9Mo'></th></span></q></dt></tr></i><div id='2P9Mo'><tfoot id='2P9Mo'></tfoot><dl id='2P9Mo'><fieldset id='2P9Mo'></fieldset></dl></div>