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

      <tfoot id='a56nK'></tfoot>

      <legend id='a56nK'><style id='a56nK'><dir id='a56nK'><q id='a56nK'></q></dir></style></legend>
      • <bdo id='a56nK'></bdo><ul id='a56nK'></ul>
      1. <small id='a56nK'></small><noframes id='a56nK'>

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

        Leaflet React在功能組件中獲取地圖實(shí)例

        Leaflet React get map instance in functional component(Leaflet React在功能組件中獲取地圖實(shí)例)

        1. <tfoot id='bx9dE'></tfoot>
        2. <small id='bx9dE'></small><noframes id='bx9dE'>

          <legend id='bx9dE'><style id='bx9dE'><dir id='bx9dE'><q id='bx9dE'></q></dir></style></legend>
                <tbody id='bx9dE'></tbody>
                  <bdo id='bx9dE'></bdo><ul id='bx9dE'></ul>
                  <i id='bx9dE'><tr id='bx9dE'><dt id='bx9dE'><q id='bx9dE'><span id='bx9dE'><b id='bx9dE'><form id='bx9dE'><ins id='bx9dE'></ins><ul id='bx9dE'></ul><sub id='bx9dE'></sub></form><legend id='bx9dE'></legend><bdo id='bx9dE'><pre id='bx9dE'><center id='bx9dE'></center></pre></bdo></b><th id='bx9dE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='bx9dE'><tfoot id='bx9dE'></tfoot><dl id='bx9dE'><fieldset id='bx9dE'></fieldset></dl></div>
                  本文介紹了Leaflet React在功能組件中獲取地圖實(shí)例的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我想在地圖外有一個(gè)按鈕,可以將視圖更改為另一個(gè)坐標(biāo).

                  I want to have a button outside the map that changes the view to another coordinates.

                  有沒(méi)有辦法讓 mapContainer 實(shí)例調(diào)用它們的函數(shù)?或者我該如何實(shí)現(xiàn)這個(gè)功能?

                  Is there any way to get mapContainer instance to call their functions? Or how can I implement that function?

                  我試圖通過(guò)使用 ref 來(lái)獲取它,但它不起作用.這是我當(dāng)前的代碼

                  I tried to get it by using ref, but it's not working. Here is my current code

                  const zoom = 13;
                  
                  function Map({ regionCoord, regionName }) {
                  
                      const mapRef = useRef();
                  
                      function handleFlyToClick() {
                        // This don't work
                        // const map = mapRef.current.leafletElement 
                        // map.flyTo(regionCoord, zoom)
                      }
                  
                   return (   
                          <React.Fragment>
                              <Grid container >
                                  <Grid item xs={10}>
                                      {regionCoord && <MapContainer
                                          ref={mapRef}                     
                                          center={[50,50]} 
                                          zoom={zoom}                    
                                          >
                                          <TileLayer
                                              attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                                              url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
                                          />            
                     
                                          <Marker position={regionCoord}>
                                            <Popup>{regionName}</Popup>
                                          </Marker>        
                                      </MapContainer>}                               
                                  </Grid>
                                  <Grid item xs={2}>
                                      <button onClick={handleFlyToClick}>Fly To</button>
                                  </Grid>
                              </Grid>
                          </React.Fragment>  
                      )
                      
                  }
                  
                  export default Map
                  

                  我正在使用 react-leaflet v3

                  I'm using react-leaflet v3

                  推薦答案

                  你需要使用一個(gè)包含你的按鈕的組件.要獲取地圖實(shí)例,請(qǐng)使用 MapContainerwhenCreated 屬性.我認(rèn)為 mapRef 在最新版本中不再有效.

                  You need to use a component which will include your button inside. To take the map instance use whenCreated prop of MapContainer. I think mapRef is not valid anymore with the latest version.

                  地圖容器:

                   const [map, setMap] = useState(null);
                  
                   <MapContainer
                        center={[50, 50]}
                        zoom={zoom}
                        style={{ height: "90vh" }}
                        whenCreated={setMap}
                    >
                  ...
                  
                  </MapContainer>
                  <FlyToButton />  // use the button here outside of the MapContainer
                  
                  ....
                  

                  使用按鈕及其事件創(chuàng)建組件

                  Create the component with the button and its event

                  function FlyToButton() {
                    const onClick = () => map.flyTo(regionCoord, zoom);
                      
                    return <button onClick={onClick}>Add marker on click</button>;
                  }
                  

                  演示

                  這篇關(guān)于Leaflet React在功能組件中獲取地圖實(shí)例的文章就介紹到這了,希望我們推薦的答案對(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è)邊欄)
                  • <bdo id='JKrEC'></bdo><ul id='JKrEC'></ul>
                    1. <i id='JKrEC'><tr id='JKrEC'><dt id='JKrEC'><q id='JKrEC'><span id='JKrEC'><b id='JKrEC'><form id='JKrEC'><ins id='JKrEC'></ins><ul id='JKrEC'></ul><sub id='JKrEC'></sub></form><legend id='JKrEC'></legend><bdo id='JKrEC'><pre id='JKrEC'><center id='JKrEC'></center></pre></bdo></b><th id='JKrEC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JKrEC'><tfoot id='JKrEC'></tfoot><dl id='JKrEC'><fieldset id='JKrEC'></fieldset></dl></div>

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

                            <legend id='JKrEC'><style id='JKrEC'><dir id='JKrEC'><q id='JKrEC'></q></dir></style></legend>
                            <tfoot id='JKrEC'></tfoot>
                              <tbody id='JKrEC'></tbody>

                            主站蜘蛛池模板: 九九在线视频 | 久久久蜜桃一区二区人 | 精品国产免费人成在线观看 | 神马久久久久久久久久 | 成人在线一区二区 | 蜜臀久久99精品久久久久野外 | 看a网站| 亚洲国产精品成人 | 黄色免费av | 黄视频网址| av在线免费观看不卡 | 国产精品久久久久久久久久妞妞 | 久久综合av | 国产99久久精品一区二区永久免费 | 天天拍天天色 | 91精品久久久 | 国产成人免费一区二区60岁 | 中文字幕免费 | 天堂久久天堂综合色 | 狠狠躁天天躁夜夜躁婷婷老牛影视 | 国产成人综合久久 | 欧美日韩久久 | 五月婷婷在线播放 | 中文字幕精品一区久久久久 | 国产清纯白嫩初高生在线播放视频 | 欧美一区二区在线播放 | 国产又色又爽又黄又免费 | 久久aⅴ乱码一区二区三区 91综合网 | 日操操 | 亚洲成人精品 | 午夜性视频 | 日本aa毛片a级毛片免费观看 | 国产精品久久 | 中文天堂在线一区 | 国产一区日韩在线 | 色狠狠桃花综合 | 羞羞视频在线网站观看 | 天堂久久久久久久 | 国内精品久久久久久久影视简单 | 久久麻豆精品 | 国产目拍亚洲精品99久久精品 |