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

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

          <bdo id='8CoHx'></bdo><ul id='8CoHx'></ul>

        <legend id='8CoHx'><style id='8CoHx'><dir id='8CoHx'><q id='8CoHx'></q></dir></style></legend>

      1. <small id='8CoHx'></small><noframes id='8CoHx'>

        使用 Leaflet-react 時如何調用 fitBounds()?

        How do you call fitBounds() when using leaflet-react?(使用 Leaflet-react 時如何調用 fitBounds()?)

        <small id='3KEEG'></small><noframes id='3KEEG'>

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

              • <bdo id='3KEEG'></bdo><ul id='3KEEG'></ul>
                <tfoot id='3KEEG'></tfoot>

                    <tbody id='3KEEG'></tbody>
                • 本文介紹了使用 Leaflet-react 時如何調用 fitBounds()?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

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

                  如果我只是使用香草傳單,此解決方案將完美運行:縮放以適應 Mapbox 或 Leaflet 中的所有標記

                  不幸的是,我正在使用 react-leaflet.

                  如果我只是單獨使用傳單,這就是解決方案.

                  var leafletMap = new L.featureGroup([marker1, marker2, marker3]);map.fitBounds(leafletMap.getBounds());

                  我認為這段代碼(我的代碼) this.mapRef.current.leafletElement 相當于 var leafletMap = new L.featureGroup([marker1, marker2, marker3]);leafletMap.getBounds();,但是 map.fitBounds(); 相當于 react-leaflet 中的什么?

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

                  這是我的代碼.

                  import React, { createRef, Component } from 'react'從 'react-leaflet' 導入 { Map, TileLayer, Marker, Popup, FeatureGroup }導出默認類 MasterLeafletMap 擴展組件 {構造函數(道具){超級(道具);this.markers = this.markers.bind(this);this.handleClick = this.handleClick.bind(this);this.mapRef = createRef()}手柄點擊(){常量 leafletMap = this.mapRef.current.leafletElement;this.mapRef.current.fitBounds(leafletMap.getBounds());//不起作用LeafletMap.fitBounds(leafletMap.getBounds());//不起作用(只是試圖獲取標記的邊界并調整視圖)this.mapRef.current.leafletElement.flyToBounds(leafletMap.getBounds());//不起作用}標記(){if (this.props.search.items instanceof Array) {返回 this.props.search.items.map(function(object, i) {常量位置 = [object._geoloc.lat, object._geoloc.lng];返回<標記位置={位置}><彈出窗口><跨度><h4>{object.title}</h4>{object.address}, <br/>{object.city}、{object.state}、{object.zip} <br/>{object._geoloc.lat},{object._geoloc.lng}</span></彈出窗口></標記>})}}使成為() {const hasLoaded = this.props.search.items instanceof Array;如果(!已加載){返回空值;}常量位置 = [this.props.search.items[0]._geoloc.lat, this.props.search.items[0]._geoloc.lng];返回 (<div className="leaflet-map-container"><div onClick={this.handleClick}>你好</div><地圖中心={位置} zoom={13} ref={this.mapRef}>

                  提前致謝.

                  解決方案

                  這是一個如何通過 完成的示例react-leaflet

                  handleClick() {常量映射 = this.mapRef.current.leafletElement;//獲取本地地圖實例常量組 = this.groupRef.current.leafletElement;//獲取本機featureGroup實例map.fitBounds(group.getBounds());}

                  在哪里

                  <button onClick={this.handleClick}>縮放</button><地圖中心={this.props.center}縮放={this.props.zoom}參考={this.mapRef}>

                  對應于

                  var leafletMap = new L.featureGroup([marker1, marker2, marker3]);map.fitBounds(leafletMap.getBounds());

                  這是一個演示

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

                  If I was just using vanilla leaflet, this solution would work perfectly: Zoom to fit all markers in Mapbox or Leaflet

                  Unfortunately, I am using react-leaflet.

                  Here is the solution if I was just using leaflet by itself.

                  var leafletMap = new L.featureGroup([marker1, marker2, marker3]);
                  map.fitBounds(leafletMap.getBounds());
                  

                  I think this code (my code) this.mapRef.current.leafletElement is equivalent to var leafletMap = new L.featureGroup([marker1, marker2, marker3]); leafletMap.getBounds();, but what is map.fitBounds(); equivalent to in react-leaflet?

                  Basically, I am trying to display multiple markers on the map and have the view adjust accordingly (zoom in, zoom out, fly to, etc.).

                  Here is my code.

                  import React, { createRef, Component } from 'react'
                  import { Map, TileLayer, Marker, Popup, FeatureGroup } from 'react-leaflet'
                  
                  export default class MasterLeafletMap extends Component {
                    constructor(props) {
                      super(props);
                      this.markers = this.markers.bind(this);
                      this.handleClick = this.handleClick.bind(this);
                      this.mapRef = createRef()
                    }
                  
                    handleClick() {
                      const leafletMap = this.mapRef.current.leafletElement;
                      this.mapRef.current.fitBounds(leafletMap.getBounds()); // Doesn't work
                      leafletMap.fitBounds(leafletMap.getBounds()); // Doesn't work (just trying to get the bounds of the markers that are there and adjust the view)
                      this.mapRef.current.leafletElement.flyToBounds(leafletMap.getBounds()); // Doesn't work
                    }
                    markers() {
                      if (this.props.search.items instanceof Array) {
                        return this.props.search.items.map(function(object, i) {
                          const position = [object._geoloc.lat, object._geoloc.lng];
                          return <Marker position={position}>
                            <Popup>
                              <span>
                                <h4>{object.title}</h4>
                                {object.address}, <br /> {object.city}, {object.state}, {object.zip} <br /> {object._geoloc.lat}, {object._geoloc.lng}
                              </span>
                            </Popup>
                          </Marker>
                        })
                      }
                  
                    }
                    render() {
                      const hasLoaded = this.props.search.items instanceof Array;
                      if (!hasLoaded) {
                        return null;
                      }
                  
                      const position = [this.props.search.items[0]._geoloc.lat, this.props.search.items[0]._geoloc.lng];
                  
                      return (
                        <div className="leaflet-map-container">
                          <div onClick={this.handleClick}>Hello</div>
                          <Map center={position} zoom={13} ref={this.mapRef}>
                            <TileLayer
                              attribution="&amp;copy <a href=&quot;http://osm.org/copyright&quot;>OpenStreetMap</a> contributors"
                              url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
                            />
                            <FeatureGroup>
                              {this.markers()}
                            </FeatureGroup>
                          </Map>
                        </div>
                      )
                    }
                  }
                  

                  Thanks in advance.

                  解決方案

                  Here is an example how to accomplish it via react-leaflet

                  handleClick() {
                      const map = this.mapRef.current.leafletElement;  //get native Map instance
                      const group = this.groupRef.current.leafletElement; //get native featureGroup instance
                      map.fitBounds(group.getBounds());
                  }
                  

                  where

                  <div>
                      <button onClick={this.handleClick}>Zoom</button>
                      <Map
                        center={this.props.center}
                        zoom={this.props.zoom}
                        ref={this.mapRef}
                      >
                        <TileLayer
                          attribution='&amp;copy <a >OpenStreetMap</a> contributors'
                          url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
                        />
                        <FeatureGroup ref={this.groupRef}>
                          {this.props.locations.map(location => (
                            <Marker
                              key={location.name}
                              position={{ lat: location.lat, lng: location.lng }}
                            >
                              <Popup>
                                <span>
                                  <h4>{location.name}</h4>
                                </span>
                              </Popup>
                            </Marker>
                          ))}
                        </FeatureGroup>
                      </Map>
                   </div>
                  

                  which corresponds to

                  var leafletMap = new L.featureGroup([marker1, marker2, marker3]);
                  map.fitBounds(leafletMap.getBounds());
                  

                  Here is a demo

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

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

                  相關文檔推薦

                  Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 傳播運算符上的意外令牌)
                  Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以將標志傳遞給 Gulp 以使其以不同的方式運行任務?)
                  Why do we need to install gulp globally and locally?(為什么我們需要在全局和本地安裝 gulp?)
                  How to run Gulp tasks sequentially one after the other(如何一個接一個地依次運行 Gulp 任務)
                  Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時 Visual Studio 2015 崩潰)
                  Detect FLASH plugin crashes(檢測 FLASH 插件崩潰)

                  • <i id='0oQM8'><tr id='0oQM8'><dt id='0oQM8'><q id='0oQM8'><span id='0oQM8'><b id='0oQM8'><form id='0oQM8'><ins id='0oQM8'></ins><ul id='0oQM8'></ul><sub id='0oQM8'></sub></form><legend id='0oQM8'></legend><bdo id='0oQM8'><pre id='0oQM8'><center id='0oQM8'></center></pre></bdo></b><th id='0oQM8'></th></span></q></dt></tr></i><div class="7hl7jnt" id='0oQM8'><tfoot id='0oQM8'></tfoot><dl id='0oQM8'><fieldset id='0oQM8'></fieldset></dl></div>
                      • <bdo id='0oQM8'></bdo><ul id='0oQM8'></ul>
                        <tfoot id='0oQM8'></tfoot><legend id='0oQM8'><style id='0oQM8'><dir id='0oQM8'><q id='0oQM8'></q></dir></style></legend>

                        1. <small id='0oQM8'></small><noframes id='0oQM8'>

                            <tbody id='0oQM8'></tbody>

                            主站蜘蛛池模板: 818手游网_提供当下热门APP手游_最新手机游戏下载 | 金属回收_废铜废铁回收_边角料回收_废不锈钢回收_废旧电缆线回收-广东益夫金属回收公司 | 丁基胶边来料加工,医用活塞边角料加工,异戊二烯橡胶边来料加工-河北盛唐橡胶制品有限公司 | 温州富欧金属封头-不锈钢封头厂家| 河北凯普威医疗器材有限公司,高档轮椅系列,推车系列,座厕椅系列,协步椅系列,拐扙系列,卫浴系列 | CE认证_FCC认证_CCC认证_MFI认证_UN38.3认证-微测检测 CNAS实验室 | LHH药品稳定性试验箱-BPS系列恒温恒湿箱-意大利超低温冰箱-上海一恒科学仪器有限公司 | 陕西视频监控,智能安防监控,安防系统-西安鑫安5A安防工程公司 | 曙光腾达官网-天津脚手架租赁-木板架出租-移动门式脚手架租赁「免费搭设」 | 恒温恒湿试验箱厂家-高低温试验箱维修价格_东莞环仪仪器_东莞环仪仪器 | 洗地机-全自动/手推式洗地机-扫地车厂家_扬子清洁设备 | 不锈钢发酵罐_水果酒发酵罐_谷物发酵罐_山东誉诚不锈钢制品有限公司 | 铝板冲孔网,不锈钢冲孔网,圆孔冲孔网板,鳄鱼嘴-鱼眼防滑板,盾构走道板-江拓数控冲孔网厂-河北江拓丝网有限公司 | 精密五金加工厂-CNC数控车床加工_冲压件|蜗杆|螺杆加工「新锦泰」 | 右手官网|右手工业设计|外观设计公司|工业设计公司|产品创新设计|医疗产品结构设计|EMC产品结构设计 | 量子管通环-自清洗过滤器-全自动反冲洗过滤器-沼河浸过滤器 | 北京网络营销推广_百度SEO搜索引擎优化公司_网站排名优化_谷歌SEO - 北京卓立海创信息技术有限公司 | 护腰带生产厂家_磁石_医用_热压护腰_登山护膝_背姿矫正带_保健护具_医疗护具-衡水港盛 | 科昊仪器超纯水机系统-可成气相液氮罐-美菱超低温冰箱-西安昊兴生物科技有限公司 | 南京办公用品网-办公文具用品批发-打印机耗材采购 | 量子管通环-自清洗过滤器-全自动反冲洗过滤器-北京罗伦过滤技术集团有限公司 | 四川成都干燥设备_回转筒干燥机_脉冲除尘器_输送设备_热风炉_成都川工星科机电设备有限公司 | 玻璃钢型材-玻璃钢风管-玻璃钢管道,生产厂家-[江苏欧升玻璃钢制造有限公司] | 超声波成孔成槽质量检测仪-压浆机-桥梁预应力智能张拉设备-上海硕冠检测设备有限公司 | 无线遥控更衣吊篮_IC卡更衣吊篮_电动更衣吊篮配件_煤矿更衣吊篮-力得电子 | 盛源真空泵|空压机-浙江盛源空压机制造有限公司-【盛源官网】 | 化妆品加工厂-化妆品加工-化妆品代加工-面膜加工-广东欧泉生化科技有限公司 | 泰国专线_泰国物流专线_广州到泰国物流公司-泰廊曼国际 | 杭州代理记账费用-公司注销需要多久-公司变更监事_杭州福道财务管理咨询有限公司 | 广州展览制作|展台制作工厂|展览设计制作|展览展示制作|搭建制作公司 | 深圳市源和塑胶电子有限公司-首页 | 智能家居全屋智能系统多少钱一套-小米全套价格、装修方案 | 深圳标识制作公司-标识标牌厂家-深圳广告标识制作-玟璟广告-深圳市玟璟广告有限公司 | 档案密集柜_手动密集柜_智能密集柜_内蒙古档案密集柜-盛隆柜业内蒙古密集柜直销中心 | 颚式破碎机,圆锥破碎机,制砂机-新乡市德诚机电制造有限公司 | 雷冲击高压发生器-水内冷直流高压发生器-串联谐振分压器-武汉特高压电力科技有限公司 | 深圳昂为官网-气体分析仪,沼气分析仪,动态配气仪,气体传感器厂家 | 螺旋压榨机-刮泥机-潜水搅拌机-电动泥斗-潜水推流器-南京格林兰环保设备有限公司 | 缠绕机|缠绕膜包装机|缠绕包装机-上海晏陵智能设备有限公司 | 北京包装设计_标志设计公司_包装设计公司-北京思逸品牌设计 | 棕刚玉_白刚玉_铝酸钙-锐石新材料 |