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

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

<tfoot id='vwFr8'></tfoot>

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

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

      react-leaflet:在渲染新標記之前清除標記簇

      react-leaflet: Clear marker cluster before rendering new markers(react-leaflet:在渲染新標記之前清除標記簇)

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

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

              <tfoot id='b9GEV'></tfoot>

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

                本文介紹了react-leaflet:在渲染新標記之前清除標記簇的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                TLDR;有沒有辦法使用 react-leaflet 和 react-leaflet-markercluster 從標記簇中清除所有標記?

                是的,有!我剛剛向 MarkerClusterGroup 添加了一個關鍵道具,正如@SethLutske 推薦的那樣.現在,每次重新渲染地圖時,之前的標記都會被移除,只保留新的標記.

                Yes, there is! I just added a key prop to the MarkerClusterGroup, as @SethLutske recommended. Now, every time there is a re-render of the map, the previous markers are removed and only the new ones remain.

                <MarkerClusterGroup
                    key={uuidv4()}  
                    spiderfyDistanceMultiplier={1}
                    showCoverageOnHover={true}
                >
                


                我在我所在州的公安機關工作.有一個 API 可以從我所在州的所需城市獲取監控攝像頭的集合.我正在使用 React PWA 來檢索這些攝像頭的圖像,因此警察可以使用我的應用程序進行實時監控.警察在系統中進行身份驗證,使用表格按城市過濾攝像機,結果顯示在地圖中,地圖上帶有指示每個攝像機位置的標記.觸摸標記時,會顯示一個彈出窗口,其中包含該攝像機的信息,以及一個按鈕,觸摸時會在新頁面中顯示攝像機圖像.


                I work in the Public Security agency of my state. There is an API that gets a collection of monitoring cameras from a desired city of my State. I'm working in a React PWA that retrieves the image of these cameras, so the police can use my app for live monitoring. The policemen authenticate into the system, filter the cameras by their city using a form, and the result is shown in a map with markers that indicate the position of each camera. When touching a marker, a popup is shown with information of that camera and a button that shows the camera image in a new page when touched.

                地圖標記和彈出窗口

                我選擇 Leaflet 和 react-leaflet 進行地圖渲染,并選擇 react-leaflet-markercluster 來對彼此相鄰的標記進行分組.我有一個小問題:如果用戶按城市過濾相機,然后他返回表單并決定按不同城市過濾,我想要發生的行為是:

                I chose Leaflet and react-leaflet for the map rendering, and react-leaflet-markercluster to group the markers that are next each other. I'm having a little problem: if an user filters cameras by a city, then he returns to the form and decides to filter by a different city, the behavior that I wanted to happen is:

                • 清除上一個被過濾城市的所有標記;
                • 顯示當前城市的所有標記;

                但發生的情況是:前一個城市的標記仍保留在地圖中,彈出窗口為空.

                But what happens is this: the markers from the previous city remain in the map, with an empty popup.

                不同城市的標記組

                我的目標:我想在添加新城市的標記之前清除過去的城市標記!

                這是我的 MapContainer.盡管存在我提到的錯誤,但它運行良好.

                Here is how it is my MapContainer. It is working quite well, despite of the bug I mentioned.

                      <MapContainer            
                          center={[-26.627817, -51.196288]}
                          zoom={6}
                          scrollWheelZoom={false}
                          style={{ height: '100vh', width: '100wh' }}
                      >
                        {//<ClearLayers /> this clears the entire map, even the tile layer, leaving it blank
                        }
                          <TileLayer
                          attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                          url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
                          />
                          <MarkerClusterGroup
                              spiderfyDistanceMultiplier={1}
                              showCoverageOnHover={false}
                          >
                              {cameras.map((camera: Camera) => (
                                  <Marker icon={iconBTV} key={camera.name} position={[camera.latitude, camera.longitude]}>
                                      <Popup>
                                        {camera.name} <br /> {camera.description} <br />
                                        <Link
                                          to={{
                                            pathname: "/cameraScreen",
                                          }}
                                          style={{ textDecoration: 'none' }}
                                        >
                                          <button
                                            style={{marginTop: "1rem"}}
                                            onClick={(e) => insertLog(e, camera)}
                                          >Ver camera</button>
                                        </Link>                            
                                      </Popup>
                                  </Marker>
                              ))}
                          </MarkerClusterGroup>
                      </MapContainer>
                

                我嘗試使用此功能,但它沒有按我的意愿工作.它會破壞地圖,使其完全空白.

                I tried using this function, but it doesn't work as I wanted. It bugs the map, leaving it completely blank.

                function ClearLayers() {
                  const map = useMap();
                  map.eachLayer(function (layer) {
                    map.removeLayer(layer);
                  });
                  return null
                }
                

                我在這里搜索并接近解決方案:我能夠通過使用 Leaflet 的核心 API 并留下 react-leaflet-markercluster 包裝器來清除過去的城市標記 如本答案所示.在向 MCG 添加新標記之前,我確實執行了 clearLayers(),這樣就可以了.這是我嘗試做的:

                I've searched in here and came close to a resolution: I was able to clear the past city markers by using Leaflet's core API and leaving behind react-leaflet-markercluster wrapper as shown in this answer. I do execute clearLayers() before adding new markers to the MCG, and that does the trick. Here's what I tried to do:

                    import * as L from 'leaflet';
                    import 'leaflet.markercluster';
                
                    import { useMap } from 'react-leaflet';
                    import { useContext, useEffect } from 'react';
                    import { Link } from 'react-router-dom';
                    import CameraContext from '../../contexts/CameraContext';
                
                    const mcg = L.markerClusterGroup({
                        chunkedLoading: true,
                        showCoverageOnHover: false,
                    });
                
                    const MarkerCluster = ({ markers, icon }) => {
                        const { setCamera } = useContext(CameraContext);
                
                        const inserirLog = (e, camera) => {
                            setCamera(camera);
                            var ajax_log = new XMLHttpRequest();
                            ajax_log.open('GET', `https://fakeurl.sc.gov.br/api/ajax-log-bemtevi.php?camera=${camera.nome}&servidor=${camera.servidor}`);
                            ajax_log.send();
                        }   
                
                        console.log(markers);
                        const map = useMap();
                        useEffect(() => {
                            mcg.clearLayers();
                            const markerList = markers.map((camera) => {
                                return L.marker(new L.LatLng(camera.latitude, camera.longitude), {
                                    icon: icon,
                                }).bindPopup(
                                    `
                                    ${camera.name} <br /> ${camera.description} <br />
                                    <Link
                                    to={{
                                        pathname: "/cameraScreen",
                                    }}
                                    style={{ textDecoration: 'none' }}
                                    >
                                    <button
                                        style={{marginTop: "1rem"}}
                                        onClick={(e) => insertLog(e, camera)}
                                    >Watch camera</button>
                                    </Link>
                                    `
                                );
                            });
                            mcg.addLayers(markerList);
                            map.fitBounds(mcg.getBounds());
                            map.addLayer(mcg);
                        }, [markers, icon, map]);
                
                        return null;
                    };
                
                    export default MarkerCluster;
                

                通過這樣做,我無法在 Popup 中注入 JSX,也無法使用 react-router-dom 中的 Link 組件.我也無法將相機對象保存在上下文中以在下一頁中進一步使用它.所以我結束了堅持我當前的代碼,這是有效的,盡管有這個無法清除過去的城市標記".錯誤.

                By doing that, I can't inject JSX inside the Popup, and can't use the Link component from react-router-dom. I also couldn't save the camera object in a context to use it further in the next page. So I ended sticking to my current code, that is working, despite of having this "can't clear past city markers" bug.

                所以我想在使用 React 組件用于 Leaflet 地圖和 Marker Cluster 時有一種方法可以清除過去的城市標記.如果 MarkerClusterGroup 有一個鉤子,就像 Leaflet 地圖有一個鉤子一樣,我想這會更容易做到:我需要做的就是這樣簡單的事情:

                So I'd like to have a way to clear the past city markers when using the React components for Leaflet map and Marker Cluster. If there was a hook for the MarkerClusterGroup like there is one for the Leaflet map, I guess this would be easier to do: all I would need to do is something simple as this:

                    const markercluster = useMarkerClusterGroup();
                    markercluster.clearLayers();
                

                但是,據我所知,react-leaflet-markercluster 中沒有鉤子.

                But, as long as I know, there aren't hooks in react-leaflet-markercluster.

                推薦答案

                你可以在 MarkerClusterGroup 中添加一個 key 屬性,當你希望集群成為完全重新渲染.

                You can add a key prop to MarkerClusterGroup, and change it when you want the cluster to be completely rerendered.

                <MarkerClusterGroup
                  key={somekey}
                  spiderfyDistanceMultiplier={1}
                  showCoverageOnHover={false}
                >
                

                我不確定是什么邏輯觸發了標記的更改,但在相同的邏輯中,當標記更改時,會生成一個新的唯一值(無論是遞增的簡單計數器,還是新的 uuid),將 key 設置為該新值,整個組件應卸載并重新安裝.雖然如果有大量標記,這對性能來說并不是很好,但這聽起來像是您正在嘗試做的事情.

                I'm not sure what logic is triggering the markers to change, but within that same logic, when the markers change, generate a new unique value (whether its a simple counter that increments, or a new uuid), set the key to that new value, and the entire component should unmount and remount. While this isn't great for performance if there are a huge number of markers, it sounds like what you're trying to do.

                這篇關于react-leaflet:在渲染新標記之前清除標記簇的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 圖層控件添加到側邊欄)

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

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

                        • <bdo id='NJ8Pe'></bdo><ul id='NJ8Pe'></ul>
                          <tfoot id='NJ8Pe'></tfoot>
                            <tbody id='NJ8Pe'></tbody>

                          <legend id='NJ8Pe'><style id='NJ8Pe'><dir id='NJ8Pe'><q id='NJ8Pe'></q></dir></style></legend>
                          主站蜘蛛池模板: 日本三级黄视频 | 亚洲一区二区久久久 | 久在线视频 | 在线成人 | av在线伊人 | 男人天堂手机在线视频 | 久久综合久久自在自线精品自 | 精品一区二区久久久久久久网站 | av手机免费在线观看 | 中文在线视频 | 亚洲欧美一区二区在线观看 | 日韩精品免费一区二区在线观看 | 日韩中文字幕在线观看 | 亚洲精品一 | 黑人巨大精品欧美一区二区免费 | 日韩在线观看精品 | 亚洲精品99 | 精品亚洲一区二区三区四区五区高 | 99精品一区二区三区 | 中文字幕1区2区3区 日韩在线视频免费观看 | 精品伦精品一区二区三区视频 | 欧美天堂 | 国产精品日韩欧美一区二区三区 | 亚洲精品日韩在线 | 亚洲先锋影音 | 成人在线不卡 | 日韩精品在线播放 | 日韩一级欧美一级 | 亚洲精品在线播放 | 亚州精品天堂中文字幕 | 在线观看视频你懂得 | 一区二区三区免费 | 精品美女久久久 | 成人小视频在线观看 | 美女国内精品自产拍在线播放 | jⅰzz亚洲| 国产午夜精品久久久 | 国产欧美视频一区二区 | www.887色视频免费 | 欧美高清视频 | 亚洲欧洲日韩 |