久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <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="qwawimqqmiuu" 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 中調用 fitBounds 和 getBounds?

        How to call fitBounds and getBounds in react-leaflet?(如何在 react-leaflet 中調用 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="qwawimqqmiuu" 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 中調用 fitBounds 和 getBounds?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

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

                  基本上,我試圖在地圖上顯示多個標記并相應地調整視圖(放大、縮小、飛到等).我還看到了一些示例

                  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

                  這篇關于如何在 react-leaflet 中調用 fitBounds 和 getBounds?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

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

                    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="qwawimqqmiuu" 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>
                            主站蜘蛛池模板: 亚洲一区二区三区四区五区午夜 | 91精品国产一区二区 | 婷婷久久综合 | 中文字幕在线视频一区二区三区 | 亚洲欧美日韩精品久久亚洲区 | 男人天堂免费在线 | 亚洲第1页 | 狠狠干天天干 | 中文字幕在线免费 | 亚洲国产成人久久久 | 中文字幕视频在线观看 | 午夜精品一区二区三区免费视频 | 亚洲风情在线观看 | 亚洲国产精品久久久久秋霞不卡 | 国产探花在线精品一区二区 | www.亚洲一区二区三区 | 天天操夜夜操 | 美女高潮网站 | 成人动漫视频网站 | 精品美女视频在免费观看 | 91精品国产一二三 | 成人一级黄色毛片 | 亚洲一区二区av在线 | 一区二区三区中文字幕 | 成人h免费观看视频 | 老司机久久 | 日韩欧美在线观看 | 成人毛片网站 | 中文字幕第三页 | 国产一区免费 | 国产精品久久久久久52avav | 日韩精品一| 91久久爽久久爽爽久久片 | 成人午夜精品一区二区三区 | 丁香久久 | 9191成人精品久久 | 欧美日本韩国一区二区 | 国产乱码精品一品二品 | 一区二区三区在线免费看 | 韩日av在线 | 欧美三级成人理伦 |