1

The issue I am facing is with the loading time. I am building an application to show trees of a city on a leaflet map. The trees are getting loaded as the map pans, on a particular zoom level. Locations having about 2000 trees get loaded fast enough. But there are some locations where the density of trees is too high. So as soon as I pan to that location, it takes a while to load up the data. Is there any way I could reduce the loading time? The query I am using to fetch data at a particular distance from the center of the viewport is,

SELECT gt.latitude_dl, gt.longitude_dl, t.name_vc, 
        p.project_vc, gt.height_dc, gt.age_dc, gt.address_txt, gt.canopy_diameter_dc, o.ownership_vc,
        c.condition_vc, gt.remark_txt,
        SQRT(
            POW( 69.1 * ( gt.latitude_dl - [ center_lat ] ), 2) +
            POW( 69.1 * ( [ center_lon ] - gt.longitude_dl ) * COS( gt.latitude_dl / 57.3 ), 2 )
        ) AS distance
        FROM tree_geotags_t gt
        LEFT JOIN mst_tree_t t ON t.tree_id = gt.tree_id
        LEFT JOIN mst_project_t p ON p.project_id = gt.project_id
        LEFT JOIN mst_tree_condition_t c ON c.tree_condition_id = gt.tree_condition_id
        LEFT JOIN mst_ownership_type_t o ON o.ownership_type_id = gt.ownership_type_id
        HAVING distance < 0.4 ORDER BY distance

Where [ center_lon ] and [ center_lat ] are the viewport center coordinates I am passing via ajax.

Abhishek Acharya
  • 339
  • 4
  • 12
  • 1
    Have you profiled this to determine from where the delay is originating? Is it the database, or is it rendering? – eggyal Feb 20 '17 at 10:47
  • I'm not sure how to do that. I was expecting it to be a database issue since its fetching and processing so many records. The only rendering issue might be the tree image file I am using as a marker, but it weighs only 1.1kb.. – Abhishek Acharya Feb 20 '17 at 10:50
  • 2
    Rendering also involves plotting thousands of such markers at the correct locations on the map... – eggyal Feb 20 '17 at 10:52
  • 2
    See https://stackoverflow.com/questions/37735847/leaflet-adding-layer-group-to-map-is-very-slow?noredirect=1&lq=1 – ghybs Feb 20 '17 at 11:16
  • Thanks ghybs and eggyal for the suggestions. It was infact the rendering process that was slowing down the browser. Using marker clusters sorted it out. – Abhishek Acharya Feb 24 '17 at 08:50

0 Answers0