how to create two sets of markers in two layers
imlearningr opened this issue · comments
Hi @ramnathv ,
Thank you so much for your time and work in creating such a great package. I have been using it in a project to demonstrate job site and it empowers us to do something we haven't been able to before. I do have a question that I do not know how to tackle. I have read all the issues and your demonstrations on how to use the heatmap and routing plugins, but I am still a little uncertain. I hope you would help me out with some direction.
okay, this is what I am trying to do. We have both the lat/long for center of job sites (centroid) and the individual locations within the job sites (raw points). So far, I have been successful in adding the centroid as markers on the map and use it in shiny. But now, I also want to add another sets of markers for the raw points, but I want it to be in a conditional layer so that when the map is first loaded, only the centroid would show but user can choose to show the raw points layer. I have read there are some layer control plugins but now sure how to incorporate them. Here is my code so far, but I was not successful in plotting two sets of markers, the second sets of markers just replaced the first one.
`
load initial map
map <- Leaflet$new()
map$setView(c(mean(js_cluster_subset$GPS_LATITUDE), mean(js_cluster_subset$GPS_LONGITUDE)), zoom = 10)
map$tileLayer(provider = "MapQuestOpen.OSM")
map$set(height=750, width=1177)
map
create markers for job site centroid
js_cluster_subset <- subset(js_cluster, VMC_VIN=="1VRB31072E1000179")
for (i in 1:dim(js_cluster_subset)[1]) {
map$marker(
c(js_cluster_subset$GPS_LATITUDE[i], js_cluster_subset$GPS_LONGITUDE[i]),
bindPopup = paste(paste0('Job Site #', js_cluster_subset$JOB_SITE_NO[i]),
paste('Job Period:', js_cluster_subset$JOB_BEGIN_DATE[i], 'to', js_cluster_subset$JOB_END_DATE[i]),
paste0('Engine Hour Used:', format(round(js_cluster_subset$ENGINE_HOUR[i],2), big.mark=",")),
paste0('Fuel Used (gal):', format(round(js_cluster_subset$FUEL_USED_GAL[i],2), big.mark=",")),
paste0('Total Distance Moved (ft.):', format(round(js_cluster_subset$DISTANCE_MOVED_FEET[i],2), big.mark=",")),
sep=' | ')
)
}
map
create markers for raw GPS points
js_data_cluste_subset <- subset(js_data_cluster, VMC_VIN=="1VRB31072E1000179")
for (i in 1:dim(js_data_cluste_subset)[1]) {
map$marker(
c(js_data_cluste_subset$GPS_LATITUDE[i], js_data_cluste_subset$GPS_LONGITUDE[i])
)
}
map
`
+1
I'd like to add a polygon and a marker (actually, a circle whose size depends on a variable). Haven't figured out how to do this, but I think if I see a solution to your problem I can figure it out.