0

Im using react-leaflet to render heatmap using big amount of polygons that I get from database. Polygons are preconfigured and I don't perform any actions on them. My issue is that when user wants to display certain heatmap, the amount of polygons to render on leaflet map is so big (30k) that is causes browser to lag. My issue is that I dont know how to show user that heatmap is loading (ex. using wait cursor), becouse lag starts at the beginning of rendering map loop and ends when all polygons are rendered. Im using

{
    // dependencies
    "leaflet": "^1.9.4",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-leaflet": "^4.2.1",
    // devDependencies
    "vite": "^5.1.5"
  }

all the code responsible for rendering polygons

{ visibleHeatmap && heatmapsData.map( ( { pollutant, polygonSimData } ) => {
     if( visibleHeatmap !== pollutant ) return <></>

     return polygonSimData.map( ( { color, coordinates }, index ) => (
        <Polygon key={ index } positions={ coordinates }
                 pathOptions={ styleHeatmapPolygon( color ) }/>
     ) );
} ) }

where

  • visibleHeatmap is useState variable which changes when user clicks button in parent component.
  • polygonSimData consists all the needed data

I tried switching to rendering polygons on L.canvas but it didnt solve the problem.

How should I change the code, so that I would be able to show user that heatmap is rendering?

2
  • so you are looping in a 30k data to create the component no wonder it will hiccup hard. I want to understand why are you using polygon to display heatmap anyway you should use a heatmap library instead it will accept an array of an array so you wont have to loop it in client side. like this leaflet plugin github.com/Leaflet/Leaflet.heat Commented Apr 14, 2024 at 10:36
  • @RenzSalanga I'm using polygons, becouse every one of them has other coordinates, color and intensity assigned to them. Each polygon is a square, so each coords is array of 4 latlng tuples. I guess its not a classical heatmap then. Hope it clarifies things a bit. More help appreciated! Commented Apr 14, 2024 at 21:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.