Pakillo/r-leaflet-maps

leaflet addpolygon fill

antoine4ucsd opened this issue · 5 comments

Hello

I am trying to show a worldmap of data. filling country by my variable. when I plot it, I have an issue with country being cut on one side. is it possible to make sure it does not happen. I tried different zoom and centering but it does not seem to work...

I used these base options

leaf_map_tiles =leaflet::leaflet(world_map,
                           options = leaflet::leafletOptions(attributionControl=F,
                                                             initialTileLayerAttribution="",
                                                             attributionPrefix=" ",
                                                                minZoom = 1.3,center = c(28,13), 
                                                             maxZoom = 4,
                                                             zoom=1.3))

but when I add polygon

leaf_map1 = leaf_map_tiles%>%
        leaflet::addPolygons(stroke = T, 
                             smoothFactor = 0.3,
                             weight = 1,
                            fillOpacity = ~factop(num_site2),
                             fillColor = ~pal2(num_site2),
                             color = "white")

then it shows up like below:

example1

how can I prevent the filled country to be cut and appear on both sides?

also if want to add a tile like this one on top of it:

example2

I do

leaf_map1 = leaf_map_tiles%>%
        leaflet::addPolygons(stroke = T, 
                             smoothFactor = 0.3,
                             weight = 1,
                            fillOpacity = ~factop(num_site2),
                             fillColor = ~pal2(num_site2),
                             color = "white")%>%leaflet::addTiles(tilesURL2)

but the filled countries are always on top even with the tiles (see north of pakistan)
example3

any suggestions?

thank you for your help with both issues!

Hi @antoine4ucsd

I think you may get better answers asking on stackoverflow or similar, but here are my 2 cents:

For Alaska, you may

(a) shift the geometry (e.g. see rstudio/leaflet#172 (comment)) OR https://stackoverflow.com/questions/73451858/add-tiles-to-leaflet-map-with-alaska-hawaii-geometry-shifted)

(b) add a mini map (see https://gis.stackexchange.com/questions/301839/how-to-create-independent-fixed-inset-maps-with-leaflet)

thank you for your reply. Much appreciated. I will investigate further and let you know how it works. my main issue is when multiple layer/tiles are involved. if you are interested (and have time), we can discuss further by mp.

Best.

For multiple layers, I'd suggest playing with different layer order and opacity. Also, it can be useful to add a control button so users can choose which layers to see: https://rstudio.github.io/leaflet/showhide.html

I love this option. thank you for the feedback

You're welcome