LeafletJS,输入数据点的简化方式
LeafletJS, streamlined way to enter datapoints
我用 LeafletJS 创建了 this interactive toggle map
如果你see the source code,有超过 70 个数据点。
但是,我正在处理一个包含超过 1500 个数据点的项目。
是否有一种简化的方法来输入超过 1500 个数据点?
R 很简单,因为它读取 CSV,我不得不走 Javascript 路线来切换地图图层和数据点。
请告诉我有比在 EXCEL 中连接 1500 多行并创建输入字符串以复制并粘贴到源代码中更有效的方法。
如果您使用的是 R(我使用的是 Rstudio),您可以添加 Leaflet 包 (https://rstudio.github.io/leaflet/ it has some prerequisites). First you load the CSV as a dataframe, then you add a marker layer from it with a one liner (see https://rstudio.github.io/leaflet/markers.html)
以下显示了街道和图像之间的切换以及在传单中完成的两个单独的数据观察。
library(leaflet)
library(dplyr)
d <- read.table("http://www.hafro.is/hafroskip/sild.data",header=F)
names(d) <- c("id","date","lon","lat","cm1","cm2")
d$date <- lubridate::ymd_hm(d$date)
x1 <- d %>%
filter(id == 101109)
x2 <- d %>%
filter(id == 101143)
leaflet() %>%
addTiles(urlTemplate = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", group="streetmap") %>%
addTiles(urlTemplate = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
group="image") %>%
addCircleMarkers(data=x1, lng = ~lon, lat = ~lat, weight = 1, radius = 4, col="yellow",
popup = ~date, group="Less than something") %>%
addCircleMarkers(data=x2, lng = ~lon, lat = ~lat, weight = 1, radius = 4, col="green",
popup = ~date, group="More than something") %>%
addLayersControl(
baseGroups = c("streetmap","image"),
overlayGroups = c("Less than something","More than something"),
options = layersControlOptions(collapsed = FALSE))
希望这与您正在寻找的类似。
艾纳尔
我用 LeafletJS 创建了 this interactive toggle map
如果你see the source code,有超过 70 个数据点。
但是,我正在处理一个包含超过 1500 个数据点的项目。
是否有一种简化的方法来输入超过 1500 个数据点?
R 很简单,因为它读取 CSV,我不得不走 Javascript 路线来切换地图图层和数据点。
请告诉我有比在 EXCEL 中连接 1500 多行并创建输入字符串以复制并粘贴到源代码中更有效的方法。
如果您使用的是 R(我使用的是 Rstudio),您可以添加 Leaflet 包 (https://rstudio.github.io/leaflet/ it has some prerequisites). First you load the CSV as a dataframe, then you add a marker layer from it with a one liner (see https://rstudio.github.io/leaflet/markers.html)
以下显示了街道和图像之间的切换以及在传单中完成的两个单独的数据观察。
library(leaflet)
library(dplyr)
d <- read.table("http://www.hafro.is/hafroskip/sild.data",header=F)
names(d) <- c("id","date","lon","lat","cm1","cm2")
d$date <- lubridate::ymd_hm(d$date)
x1 <- d %>%
filter(id == 101109)
x2 <- d %>%
filter(id == 101143)
leaflet() %>%
addTiles(urlTemplate = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", group="streetmap") %>%
addTiles(urlTemplate = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
group="image") %>%
addCircleMarkers(data=x1, lng = ~lon, lat = ~lat, weight = 1, radius = 4, col="yellow",
popup = ~date, group="Less than something") %>%
addCircleMarkers(data=x2, lng = ~lon, lat = ~lat, weight = 1, radius = 4, col="green",
popup = ~date, group="More than something") %>%
addLayersControl(
baseGroups = c("streetmap","image"),
overlayGroups = c("Less than something","More than something"),
options = layersControlOptions(collapsed = FALSE))
希望这与您正在寻找的类似。
艾纳尔