pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

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

    1. <tfoot id='R0XoU'></tfoot>

        <legend id='R0XoU'><style id='R0XoU'><dir id='R0XoU'><q id='R0XoU'></q></dir></style></legend>

          <bdo id='R0XoU'></bdo><ul id='R0XoU'></ul>

        如何在 react-leaflet 中調(diào)用 fitBounds 和 getBounds?

        How to call fitBounds and getBounds in react-leaflet?(如何在 react-leaflet 中調(diào)用 fitBounds 和 getBounds?)

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

                • <bdo id='xO2ZM'></bdo><ul id='xO2ZM'></ul>
                    <tbody id='xO2ZM'></tbody>

                  <i id='xO2ZM'><tr id='xO2ZM'><dt id='xO2ZM'><q id='xO2ZM'><span id='xO2ZM'><b id='xO2ZM'><form id='xO2ZM'><ins id='xO2ZM'></ins><ul id='xO2ZM'></ul><sub id='xO2ZM'></sub></form><legend id='xO2ZM'></legend><bdo id='xO2ZM'><pre id='xO2ZM'><center id='xO2ZM'></center></pre></bdo></b><th id='xO2ZM'></th></span></q></dt></tr></i><div class="fidy8dj" id='xO2ZM'><tfoot id='xO2ZM'></tfoot><dl id='xO2ZM'><fieldset id='xO2ZM'></fieldset></dl></div>
                • <small id='xO2ZM'></small><noframes id='xO2ZM'>

                  <tfoot id='xO2ZM'></tfoot>
                  本文介紹了如何在 react-leaflet 中調(diào)用 fitBounds 和 getBounds?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我不知道如何在 Leaflet 地圖上調(diào)用 fitBounds().

                  基本上,我試圖在地圖上顯示多個(gè)標(biāo)記并相應(yīng)地調(diào)整視圖(放大、縮小、飛到等).我還看到了一些示例

                  I cannot figure out how to call fitBounds() on the Leaflet map.

                  Basically, I am trying to display multiple markers on the map and have the view adjust accordingly (zoom in, zoom out, fly to, etc.). i also saw some example How do you call fitBounds() when using leaflet-react? and i tried to implement but it did not work. Here is my code that i tried.

                  import React, { createRef, Component } from "react";
                  import {
                    Map,
                    TileLayer,
                    Marker,
                    Popup
                  } from "react-leaflet";
                  import L from "leaflet";
                  import Header from "../Layout/Header";
                  import Card from "@material-ui/core/Card";
                  import CardContent from "@material-ui/core/CardContent";
                  import Typography from "@material-ui/core/Typography";
                  import "leaflet/dist/leaflet.css";
                  
                  export class Mapp extends Component {
                    constructor(props) {
                      super(props);
                  
                      this.state = {
                        map: [],
                        open: false,
                        bounds: null,
                        center: [35.000074, 104.999927]
                      };
                      this.mapRef = createRef();
                      this.groupRef = createRef();
                    }
                  
                    toggleHiddden1() {
                      this.setState({
                        open: false
                      });
                  
                    async componentDidMount() {
                      try {
                        await fetch(`https://coronaviva.herokuapp.com/api/1/infected/data/`, {
                          method: "GET",
                          headers: {
                            Accept: "application/json",
                            "Content-Type": "application/json",
                            Authorization: "Bearer F9bQK456iUpJVZJLTZsMEKhhENqnGJ"
                          }
                        })
                          .then(map => map.json())
                          .then(map => {
                            this.setState({
                              map
                            });
                          });
                      } catch (err) {
                        console.log(err);
                      }
                  
                      let mapInst = this.refs.map.leafletElement.fitBounds;
                      console.log(mapInst);  // i tried this but this not working.
                    }
                  
                    // centerUpdated(center) {
                    //   this.center = center;
                    // }
                    // boundsUpdated(bounds) {
                    //   this.bounds = bounds;
                    // }
                  
                    render() {
                      const { map } = this.state;
                  
                      const pointerIcon = new L.Icon({
                        iconUrl:
                          "https://icons.iconarchive.com/icons/paomedia/small-n-flat/512/map-marker-icon.png",
                        iconAnchor: [25, 40],
                        iconSize: [50, 50]
                      });
                      return (
                        <div>
                          <Header
                            state={this.state}
                            load={this.onChange}
                            submit={this.handleSubmit}
                          />
                          <Map
                            center={[51.9194, 19.1451]}
                            style={{ height: "100vh", width: "auto" }}
                            zoom={6}
                            ref="map"
                            bounceAtZoomLimits={true}
                            maxBoundsViscosity={0.95}
                            maxBounds={[
                              [-180, -90],
                              [180, 90]
                            ]}
                            className="map_map margin-zero map-padding"
                          >
                            {map.map(c => (
                              <Marker
                                position={[c.latitude, c.longitude]}
                                icon={pointerIcon}
                                onclick={this.toggleHiddden.bind(this)}
                              >
                                <Popup autoPan={false}>
                                  <Card className="carrr">
                                    {c.location === "Israel" ? (
                                      <img
                                        className="image"
                                        src="https://thehill.com/sites/default/files/styles/article_full/public/telaviv_skyline_09202018.jpg?itok=pxhk1Rtl"
                                        alt="Contemplative Reptile"
                                      />
                                    ) : (
                                      <img
                                        className="image"
                                        src="https://www.dwf.law/-/media/DWF/Images/Locations-Assets/Warsaw/Warsaw-700-x-388.ashx"
                                        alt="Contemplative Reptile"
                                      />
                                    )}
                                    <CardContent>
                                      <Typography gutterBottom variant="h5" component="h2">
                                        {c.location && <span> Place : {c.location} </span>}
                                      </Typography>
                  
                                      <h6>Address : {c.address}</h6>
                                      <p className="text-dark" style={{ marginTop: "-5px" }}>
                                        {c.info && (
                                          <span>
                                            <strong> Info</strong>: {c.info}{" "}
                                          </span>
                                        )}
                                      </p>
                  
                                      <p
                                        color="textSecondary text-secondary"
                                        component="p"
                                        className="lodl"
                                      >
                                        PlaceType : {c.place_type}
                                        <br></br>
                                        {c.start_hour && (
                                          <span>
                                            Start Hour : {c.start_hour}{" "}
                                            {c.start_hour > "12" ? "PM" : "AM"}
                                          </span>
                                        )}
                                        <br></br>
                                        {c.end_hour && (
                                          <span>
                                            End Hour : {c.end_hour}{" "}
                                            {c.end_hour > "12" ? "PM" : "AM"}
                                          </span>
                                        )}
                                      </p>
                                    </CardContent>
                                  </Card>
                                </Popup>
                              </Marker>
                            ))}
                  
                            <TileLayer
                              noWrap={true}
                              url="https://tiles.stadiamaps.com/tiles/alidade_smooth/{z}/{x}/{y}{r}.png"
                              subdomains="1234"
                              attribution='&copy; <a 
                            />
                          </Map>
                        </div>
                      );
                    }
                  }
                  
                  export default Mapp;
                  

                  解決方案

                  You have several errors in your code:

                  1. You do not close toggleHiddden1 with an }. Moreover you call it as toggleHiddden in the component. You should use one name for the method.

                  2. the map instance is derived from
                    let mapInst = this.mapRef.current.leafletElement;

                    not from let mapInst = this.refs.map.leafletElement;

                    Then you can call fitBounds()

                  3. The ref in the react-leaflet Map wrpapper should be ref={this.mapRef} and not ref="map"

                  4. Place a key when you looping over the markers.

                  Just used an openstreet map tiles url to be able to demonstrate the demo.

                  Edit To use both fitBounds and getBounds at the same time for a marker you need to wrap your markers loop with a FeatureGroup and give it a ref, then do

                  let mapInst = this.mapRef.current.leafletElement;
                  const group = this.groupRef.current.leafletElement; //get native featureGroup instance
                  mapInst.fitBounds(group.getBounds());
                  

                  inside your componentDidMount

                  and then you will get the desired result.

                  Demo

                  這篇關(guān)于如何在 react-leaflet 中調(diào)用 fitBounds 和 getBounds?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Check if a polygon point is inside another in leaflet(檢查一個(gè)多邊形點(diǎn)是否在傳單中的另一個(gè)內(nèi)部)
                  Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標(biāo)記群集圖標(biāo)顏色,繼承其余默認(rèn) CSS 屬性)
                  Trigger click on leaflet marker(觸發(fā)點(diǎn)擊傳單標(biāo)記)
                  How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認(rèn)加載磁貼顏色?)
                  Add external geojson to leaflet layer(將外部geojson添加到傳單層)
                  Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側(cè)邊欄)

                    1. <small id='AeeXS'></small><noframes id='AeeXS'>

                        1. <i id='AeeXS'><tr id='AeeXS'><dt id='AeeXS'><q id='AeeXS'><span id='AeeXS'><b id='AeeXS'><form id='AeeXS'><ins id='AeeXS'></ins><ul id='AeeXS'></ul><sub id='AeeXS'></sub></form><legend id='AeeXS'></legend><bdo id='AeeXS'><pre id='AeeXS'><center id='AeeXS'></center></pre></bdo></b><th id='AeeXS'></th></span></q></dt></tr></i><div class="cj3aji8" id='AeeXS'><tfoot id='AeeXS'></tfoot><dl id='AeeXS'><fieldset id='AeeXS'></fieldset></dl></div>

                            <tbody id='AeeXS'></tbody>
                          <tfoot id='AeeXS'></tfoot>
                          • <bdo id='AeeXS'></bdo><ul id='AeeXS'></ul>
                          • <legend id='AeeXS'><style id='AeeXS'><dir id='AeeXS'><q id='AeeXS'></q></dir></style></legend>
                            主站蜘蛛池模板: 硅胶管挤出机厂家_硅胶挤出机生产线_硅胶条挤出机_臣泽智能装备 贵州科比特-防雷公司厂家提供贵州防雷工程,防雷检测,防雷接地,防雷设备价格,防雷产品报价服务-贵州防雷检测公司 | 顺辉瓷砖-大国品牌-中国顺辉 | 361°官方网站| 不锈钢闸阀_球阀_蝶阀_止回阀_调节阀_截止阀-可拉伐阀门(上海)有限公司 | 布袋式除尘器|木工除尘器|螺旋输送机|斗式提升机|刮板输送机|除尘器配件-泊头市德佳环保设备 | 一体化污水处理设备_生活污水处理设备_全自动加药装置厂家-明基环保 | 动物麻醉机-数显脑立体定位仪-北京易则佳科技有限公司 | 3d可视化建模_三维展示_产品3d互动数字营销_三维动画制作_3D虚拟商城 【商迪3D】三维展示服务商 广东健伦体育发展有限公司-体育工程配套及销售运动器材的体育用品服务商 | 济南保安公司加盟挂靠-亮剑国际安保服务集团总部-山东保安公司|济南保安培训学校 | 视觉检测设备_自动化检测设备_CCD视觉检测机_外观缺陷检测-瑞智光电 | 北京网络营销推广_百度SEO搜索引擎优化公司_网站排名优化_谷歌SEO - 北京卓立海创信息技术有限公司 | 合肥汽车充电桩_安徽充电桩_电动交流充电桩厂家_安徽科帝新能源科技有限公司 | ◆大型吹塑加工|吹塑加工|吹塑代加工|吹塑加工厂|吹塑设备|滚塑加工|滚塑代加工-莱力奇塑业有限公司 | 诚暄电子公司首页-线路板打样,pcb线路板打样加工制作厂家 | 石英陶瓷,石英坩埚,二氧化硅陶瓷-淄博百特高新材料有限公司 | 周易算网-八字测算网 - 周易算网-宝宝起名取名测名字周易八字测算网 | 谷歌关键词优化-外贸网站优化-Google SEO小语种推广-思亿欧外贸快车 | 药品冷藏箱厂家_低温冰箱_洁净工作台-济南欧莱博电子商务有限公司官网 | 高低温万能试验机_拉力试验机_拉伸试验机-馥勒仪器科技(上海)有限公司 | 柔性测斜仪_滑动测斜仪-广州杰芯科技有限公司 | 电子厂招聘_工厂招聘_普工招聘_小时工招聘信息平台-众立方招工网 | 招商帮-一站式网络营销服务|互联网整合营销|网络推广代运营|信息流推广|招商帮企业招商好帮手|搜索营销推广|短视视频营销推广 | 火锅底料批发-串串香技术培训[川禾川调官网] | 石家庄网站建设|石家庄网站制作|石家庄小程序开发|石家庄微信开发|网站建设公司|网站制作公司|微信小程序开发|手机APP开发|软件开发 | 闭端端子|弹簧螺式接线头|防水接线头|插线式接线头|端子台|电源线扣+护线套|印刷电路板型端子台|金笔电子代理商-上海拓胜电气有限公司 | 卡诺亚轻高定官网_卧室系统_整家定制_定制家居_高端定制_全屋定制加盟_定制家具加盟_定制衣柜加盟 | 棕刚玉_白刚玉_铝酸钙-锐石新材料 | 全自动烧卖机厂家_饺子机_烧麦机价格_小笼汤包机_宁波江北阜欣食品机械有限公司 | 钢托盘,铁托盘,钢制托盘,镀锌托盘,饲料托盘,钢托盘制造商-南京飞天金属13260753852 | 滚筒烘干机_转筒烘干机_滚筒干燥机_转筒干燥机_回转烘干机_回转干燥机-设备生产厂家 | CPSE安博会 | 安平县鑫川金属丝网制品有限公司,防风抑尘网,单峰防风抑尘,不锈钢防风抑尘网,铝板防风抑尘网,镀铝锌防风抑尘网 | 温州在线网| 滚筒线,链板线,总装线,流水线-上海体能机电有限公司 | 带式过滤机厂家_价格_型号规格参数-江西核威环保科技有限公司 | 新密高铝耐火砖,轻质保温砖价格,浇注料厂家直销-郑州荣盛窑炉耐火材料有限公司 | 3d打印服务,3d打印汽车,三维扫描,硅胶复模,手板,快速模具,深圳市精速三维打印科技有限公司 | 压缩空气检测_气体_水质找上海京工-服务专业、价格合理 | 一体化污水处理设备_生活污水处理设备_全自动加药装置厂家-明基环保 | 防勒索软件_数据防泄密_Trellix(原McAfee)核心代理商_Trellix(原Fireeye)售后-广州文智信息科技有限公司 | 软启动器-上海能曼电气有限公司 真空搅拌机-行星搅拌机-双行星动力混合机-广州市番禺区源创化工设备厂 |