5

I am searching for a way to lock the size of the circle markers in Leaflet for R, addCircleMarkers(). I need the markers to retain the size they are relative to the polygon they are within upon zooming. At the moment, when you zoom, the markers stay the same size relative to your screen.

2 Answers 2

4

If I understand what you mean, you use addCircles() instead of addCircleMarkers(). Here's some (totally arbitrary) example code:

#create dummy dataframe
lon <- c(-80, -80.2, -80.4, -80.1, -80.3)
lat <- c(37, 37.05, 37.1, 37, 37.07)
num <- as.numeric(c(6000, 400, 10, 5000, 10))
x <- data.frame(lat, lon, num)

#plot with leaflet
leaflet(data = x) %>%
  addTiles() %>% 
  addCircles(lat = ~lat, lng = ~lon, radius = ~num)

Here's the initial map: enter image description here

And zoomed twice: enter image description here

1
0

It is important to remember the map projections.

It also depends on the projection you are using in Leaflet, it is good to check it with Leaflet's measurement tools or if you know the location well. To see the projections I recommend

crsDF <- rgdal::make_EPSG()
View(crsDF)

In my case, that I am in Chile (a long and narrow country) I use this projection for some places:

CRS 9155 =

"+proj=utm +zone=19 +south +ellps=GRS80 +units=m +no_defs +type=crs"

There you can see that I am using units in meters

Here I leave an image of some projections for my country.

View(crsDF)

View(crsDF)

You can find more in:

Greetings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.