0

New here, well, after a long hiatus...

Think it's a fairly simple fix, but going round in circles and tired.

In Leaflet (R), once basemap has been successfully loaded, once I add my local shapefile, the basemap disappears.

R leaflet: adding polygons from shapefile removes tiles

Above does not return a successful result.

What have I missed?

data_test <- read_sf("Ports_100km_test.geojson")

data_test <- st_transform(data_test, crs = '+proj=longlat +datum=WGS84')

map <- leaflet() %>% 
   addProviderTiles(providers$Esri.OceanBasemap) %>% 
   setView(lng = -4.2026458, lat = 56.4906712, zoom = 5)
map

map <- leaflet() %>% 
   addTiles(providers$Esri.OceanBasemap) %>% 
   setView(lng = -4.2026458, lat = 56.4906712, zoom = 5) %>% 
   addPolygons(data = data_test, color = "blue", stroke = 0.5, opacity = 0.5
   )
map

I expected a basemap with my shapefile overlayed.

  • Please, try to make to make a [reproducible example](https://stackoverflow.com/a/5963610/11932936). Currently, no one can see exactly what your problem is, because we can't run your code without your geojson file. If it is publicly available, post the link. If it is not, try to reproduce the issue with a built-in dataset like `leaflet::gadmCHE` or one that is publicly available. That will substantially improve your chance of getting useful advice here. – shs Feb 10 '23 at 19:15
  • When I replace `data_test` with `gadmCHE` on my device, it works perfectly fine: `leaflet() %>% addProviderTiles(providers$Esri.OceanBasemap) %>% setView(lng = -4.2026458, lat = 56.4906712, zoom = 5) %>% addPolygons(data = gadmCHE, color = "blue", stroke = 0.5, opacity = 0.5)` – shs Feb 10 '23 at 19:31
  • 1
    Many thanks for your reply. First time posting for code, was not prompted by Stack Exchange to include file so was not aware, noted. The code ran when I just tried it so maybe it was a network or local processing issue, problem solved, thank-you. – AlexaQuinoa Feb 10 '23 at 22:53

0 Answers0