I have just started to use leaflet and am experiencing issues showing markers on a basic map. The network tab in my web browser reports that the GET http://cdn.leafletjs.com/leaflet/v1.3.1/images/marker-icon.png
and GET http://cdn.leafletjs.com/leaflet/v1.3.1/images/marker-shadow.pngrequests return a 403 error code.
Your code is legit, and I confirm that there seems to be an issue on the leaflet.js side. Somewhat unexpected, but do have a look at the project website: https://leafletjs.com/
As a workaround I would suggest either using addCircleMarkers() or addAwesomeMarkers() - the first would add plain circles in place of markers (I find these less distracting than the pin shaped markers, but that could be just me...) and the second uses markers with icons.
On an unrelated note: while it is technically legit to have both popup and label with the same content (magnitude of the earthquake) it seems somewhat odd... I would pick just one, and dropped the other.
Thanks for the link and the reality check! I did not realize that there might be a connection
Coming back to the issue at hand and your suggestions to use addAwesomeMarkers, I experimented with this based upon various tutorials/bloq posts listed by DuckDuckGo search but faced another problem: how to tell leaflet it must use the v5 or v6 fontawesome library? Cursory testing suggests that the v4.7 library is used.
I am afraid the leaflet font awesome extension is somewhat dated, and works only with the old icons.
As far as the leaflet web page is concerned: my speculation is that as the maintainers of leaflet.js moved the web content to the /SlavaUkraini/ folder the hard-coded paths in R package {leaflet} broke.
On second thought: it may be possible to "override" - and I am putting it in quotation marks, since you are using the correct markers - the broken marker images with an updated version of the same, hosted on Cloudflare.
library(leaflet)
data(quakes)
# a working path to icon & shadow, hosted on https://cdnjs.com/libraries/leaflet
marker_icon <- makeIcon(
iconUrl = "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.8.0-beta.0/images/marker-icon.png",
shadowUrl = "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.8.0-beta.0/images/marker-shadow.png",
)
leaflet(data = quakes[1:20,]) %>%
addTiles() %>%
addMarkers(~long,
~lat,
icon = marker_icon,
popup = ~as.character(mag),
label = ~as.character(mag))
In combination with your blog post, I got to create the map I needed... Now I need to resolve why my labels are showing at odd places when my map is shown in a xaringan slide deck. But that could be the topic of another thread.