Oleksiy
September 17, 2017, 11:11pm
1
Hi everybody.
Not sure that it is the right place for my question, but did not find anything better.
In my Shiny app I use markers for mapping geolocation.
I am trying to add numbers to these markers.
So far, I found something for js, but I am totally unfamiliar with it.
http://charliecroom.com/index.php/web/numbered-markers-in-leaflet
leaflet_numbered_markers.css
.leaflet-div-icon {
background: transparent;
border: none;
}
.leaflet-marker-icon .number{
position: relative;
top: -37px;
font-size: 12px;
width: 25px;
This file has been truncated. show original
leaflet_numbered_markers.js
L.NumberedDivIcon = L.Icon.extend({
options: {
// EDIT THIS TO POINT TO THE FILE AT http://www.charliecroom.com/marker_hole.png (or your own marker)
iconUrl: '<%= image_path("leaflet/marker_hole.png") %>',
number: '',
shadowUrl: null,
iconSize: new L.Point(25, 41),
iconAnchor: new L.Point(13, 41),
popupAnchor: new L.Point(0, -33),
/*
This file has been truncated. show original
usage.js
//Make sure you downloaded the image file in numbered_markers.js
//Note that the text could also be letters instead of numbers if that's more appropriate
var marker = new L.Marker(new L.LatLng(0, 0), {
icon: new L.NumberedDivIcon({number: '1'})
});
Can it be solved only using R packages?
Sincerely
Oleksiy
1 Like
Oleksiy
September 20, 2017, 4:08am
2
Resolved personally.
library(leaflet)
library(dplyr)
Each icon was customized with numbers personally and was put into the working directory.
Then use icon_list()
# Create our own custom icons
icon_list <- iconList(
project1 = makeIcon("C:/Map/1.png", iconWidth = 24, iconHeight = 30),
project2 = makeIcon("C:/Map/2.png", iconWidth = 24, iconHeight = 30)
etc as many as you have
project1, project2 etc match the same names in the dataset column of course and in the dataset each project should have long and lat.
Then
data2 <- data %>% mutate(type = factor(data$project_id), c("project1",
"project2")
In server, the simple code will be something like this
m <- leaflet(data=data) %>%
addProviderTiles(providers$Stamen.TonerLite) %>%
addMarkers(~data2$long, ~data2$lat, icon=~icon_list[data2$project_id],
popup = state_popup)
Thanks to this question on stack overflow
3 Likes