-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaflet_map.R
56 lines (50 loc) · 1.92 KB
/
leaflet_map.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
con <- dbConnect(odbc(), Driver = "ODBC Driver 17 for SQL Server", Server = "nvsql3t.ecdcnet.europa.eu", Database = "ref",
uid = "NCOV_Shiny", pwd = "Pandemonium$9000")
con_pop <- dbConnect(odbc(), Driver = "ODBC Driver 17 for SQL Server", Server = "nsql3.ecdcnet.europa.eu", Database = "DM_ref",
uid = "NCOV_Shiny", pwd = "Pandemonium$9000")
shapes <- dbGetQuery(con,"select [LocationGeometryPLGId]
,[LocationCode]
,[LocationType]
,[Shape_PLG_WKT_WGS84]
from [ref].[dLocationGeometryPLG]
where LocationType = 'Country'")
coordinates <- dbGetQuery(con, "SELECT [LocationCode]
,[LocationName]
,[CountryISO2Code]
,[CentroidLatitude]
,[CentroidLongitude]
,[Centroid_PNT]
,[Centroid_PNT_WKT_LAEA]
,[Centroid_PNT_WKT_WGS84]
FROM [REF].[ref].[dLocationGeometryPNT]
where LocationType = 'Country'")
dataset_map = dataset %>%
group_by(GeoId) %>%
count() %>%
rename(LocationCode = GeoId) %>%
mutate(PopupText = paste0("Number of cases in ", LocationCode, ": ", n)) %>%
left_join(shapes) %>%
st_as_sf(wkt = "Shape_PLG_WKT_WGS84")
shapes = shapes %>%
filter(LocationCode != "AQ") %>%
st_as_sf(wkt = "Shape_PLG_WKT_WGS84")
leaflet() %>%
addPolygons(data = shapes,
stroke = F,
highlightOptions = highlightOptions(
weight = 5,
color = "#666",
fillOpacity = 1,
bringToFront = F),
layerId = ~LocationCode) %>%
# addProviderTiles(providers$Esri.WorldGrayCanvas) %>%
addPolygons(data = dataset_map,
fillColor = ~n,
stroke = F,
highlightOptions = highlightOptions(
weight = 5,
color = "#666",
fillOpacity = 0.7,
bringToFront = T),
popup = ~PopupText,
layerId = ~LocationCode)