r-spatial / leafgl

R package for fast web gl rendering for leaflet
Other
262 stars 31 forks source link

Polygons are deformed #93

Open cschuster89 opened 3 months ago

cschuster89 commented 3 months ago

Hi, first of all I would like to thank you for the great libary, which significantly increases the performance of my maps.

Unfortunately, I have a small problem with the display of my polygons.

Map without LeafGL:

image

Map section with LeafGL:

image

The code I'm using looks like:

building <- building %>% addPolygons(data = filtered_buildings,
                                           color = colors_building[i],
                                           fillColor = colors_building[i],
                                           fillOpacity = 0.7,
                                           highlightOptions = highlightOptions(color = "white", weight = 2,
                                                                               bringToFront = TRUE),
                                           popup = ~paste0("Some popup Options"))

And when I'm using leafgl I just change it to "addGlPolygons" and use "leafglOutput" instead of my "leafletOutput".

Also, my highlightOptions don't work anymore when using addGlPolygons. Is there a way to make them work?

Thanks in advance!

trafficonese commented 3 months ago

This is still a problem in the underlying library https://github.com/robertleeplummerjr/Leaflet.glify/issues/137

cschuster89 commented 3 months ago

Ok, I see. Thanks for the quick reply and the reference to the underlying problem.

trafficonese commented 3 months ago

No worries :) but let's keep it open, as it's still a bug in this library aswell.

RayLarone commented 3 months ago

I have an open pull request on the leaflet.glify repo which should solve this issue

https://github.com/robertleeplummerjr/Leaflet.glify/pull/138

Until this pull request gets reviewed, I have a fork of the leafgl package with this fix implemented. This works on my system, although I forked it a while ago so can't guarantee it will be free from issues. Try removing the current leafgl package and run the following code.

install.pacakages("devtools")
devtools::install_github("RayLarone/leafgl")
cschuster89 commented 3 months ago

Awesome. It works great for me. It seems to be a bit slower, but the performance is still good for several hundred thousand polygons.

Just out of interest: What exactly did you change and where? Did you move the origin of the map to the center of the displayed area?

RayLarone commented 3 months ago

That's good. Tbh, the performance difference really should be negligible. I may have added some other things to the fork which may be affecting performance, though I can't quite remember.

You can see the changes made and explanations in the pull request links above. Essentially, normalising some of the pixel coordinates around (0, 0) in the underlying library seems to fix the issue.

cschuster89 commented 3 months ago

Thank you very much!