leaflet icon indicating copy to clipboard operation
leaflet copied to clipboard

modify icon size

Open heliconius-maps opened this issue 1 year ago • 4 comments

Using the quakes data as an example and the code below, I wish to modify the icon size. I need to keep the rest of the code as unchanged as possible, I just want to make the icons smaller. I wish to do this because maps with many data points become excessively crowded. Can you please help?

NB I did post this issue on StackOverflow a couple of years ago, but have never received any replies.

library(leaflet)
data(quakes)
quakes<-head(quakes,10)
quakes$stations<-as.factor(quakes$stations)
map<-leaflet()
map<-addTiles(map,group = "OSM (default)")
map<-addMarkers(map,quakes$lon, quakes$lat, group = quakes$stations,
    clusterOptions = markerClusterOptions(maxClusterRadius = 5,transparent=TRUE,singleMarkerMode=TRUE,zoomToBoundsOnClick=FALSE,
        iconCreateFunction=JS(paste0("function(cluster) {
            var c = ' marker-cluster-small';
            var html = '<div style=\"background-color:rgba(","#FF00DB",")\"><span>' + cluster.getChildCount() + '</div><span>'
            return new L.DivIcon({html: html, className: 'marker-cluster' + c,iconSize: new L.Point(40, 40) });
        }"))
    )
)   

map

heliconius-maps avatar Apr 17 '24 16:04 heliconius-maps

Did you find a workaround?

micahwilhelm avatar Nov 06 '24 15:11 micahwilhelm

Yes, I did - I think I managed to do it by modifying the .css Thanks for your response.

rosserlab avatar Nov 06 '24 17:11 rosserlab

Would you care to share the modified css code, please?

micahwilhelm avatar Nov 07 '24 15:11 micahwilhelm

Below are the .css parameters I tweaked. It was fiddly, and it also depends on what is being passed to the iconCreateFunction. But in the end I managed to get the desired results.

.marker-cluster {
	background-clip: padding-box;
	border-radius: 20px;
	}
.marker-cluster div {
	width: 22.5px;
	height: 22.5px;
	margin-left: 3.75px;
	margin-top: 3.75px;

	text-align: center;
	border-radius: 15px;
	font: 12px "Helvetica Neue", Arial, Helvetica, sans-serif;
	}
.marker-cluster span {
	line-height: 22.5px;
	}

heliconius-maps avatar Nov 11 '24 21:11 heliconius-maps