千家信息网

leaflet怎么构造路径图

发表于:2024-12-13 作者:千家信息网编辑
千家信息网最后更新 2024年12月13日,这篇文章主要介绍"leaflet怎么构造路径图",在日常操作中,相信很多人在leaflet怎么构造路径图问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"leaflet怎么
千家信息网最后更新 2024年12月13日leaflet怎么构造路径图

这篇文章主要介绍"leaflet怎么构造路径图",在日常操作中,相信很多人在leaflet怎么构造路径图问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"leaflet怎么构造路径图"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

library(leaflet)

library(dplyr)

data<-read.table("D:/R/File/subwayline.txt",header=TRUE,stringsAsFactors = FALSE)

data$Type<-as.factor(data$Type)

data1<-filter(data,Type=="NO1")

data2<-filter(data,Type=="NO5")

以上我用百度地图的坐标拾取平台采点拾取的背景地铁一号线和五号线的车站地理位置信息,(因为没有现成的数据,只能手工采点,可能不是很准确)

今天要介绍的leaflet类型是线条,也即addPolylines函数,其基本语法如下:

addPolylines(map, lng = NULL,lat = NULL, #指定数据源并做经纬度声明

layerId = NULL,

group = NULL, #图层分组(制作动态可见性交互时使用)

stroke = TRUE, #是否呈现路径线

color = "#03F",weight = 5,opacity = 0.5, #关于线条的颜色、宽度、透明度

fill = FALSE, fillColor = color, fillOpacity = 0.2,

dashArray = NULL, smoothFactor = 1, noClip = FALSE, #线型参数,平滑度等

popup = NULL, options = pathOptions(), data = getMapData(map)) #弹窗、选项控制

以下构造色盘:

pal <- colorFactor(topo.colors(2),data$Type)

作图函数:使用默认点标识

leaflet()%>%

addTiles()%>%

addPolylines(data=data1,~lon,~lat,color="blue")%>%

addPolylines(data=data2,~lon,~lat,color="green")%>%

addMarkers(data=data,~lon, ~lat,popup = ~address)

使用可自定义的圆点标识车站位置

leaflet()%>%

addTiles()%>%

addPolylines(data=data1,~lon,~lat,color="blue")%>%

addPolylines(data=data2,~lon,~lat,color="green")%>%

addCircles(data=data,~lon, ~lat,popup = ~address,color="red")

leaflet()%>%

addTiles()%>%

addPolylines(data=data1,~lon,~lat,color="blue")%>%

addPolylines(data=data2,~lon,~lat,color="green")%>%

addCircleMarkers(data=data,~lon, ~lat,popup = ~address,color=~Type)

以下是几种比较常用的地图背景素材

addProviderTiles("Esri.WorldStreetMap")

addProviderTiles("Esri.WorldImagery")

addProviderTiles("Esri.WorldTerrain")

addProviderTiles("Esri.NatGeoWorldMap")

leaflet()%>%

addProviderTiles("Esri.WorldStreetMap")%>%

addPolylines(data=data1,~lon,~lat,color="blue")%>%

addPolylines(data=data2,~lon,~lat,color="green")%>%

addCircles(data=data,~lon, ~lat,popup = ~address,color=~Type)

leaflet()%>%

addProviderTiles("Esri.WorldImagery")%>%

addPolylines(data=data1,~lon,~lat,color="blue")%>%

addPolylines(data=data2,~lon,~lat,color="green")%>%

addCircles(data=data,~lon, ~lat,popup = ~address,color=~Type)

leaflet()%>%

addProviderTiles("Esri.WorldGrayCanvas") %>%

addPolylines(data=data1,~lon,~lat,color="blue")%>%

addPolylines(data=data2,~lon,~lat,color="green")%>%

addCircles(data=data,~lon, ~lat,popup = ~address,color=~Type)

leaflet()%>%

addProviderTiles("Esri.NatGeoWorldMap") %>%

addPolylines(data=data1,~lon,~lat,color="blue")%>%

addPolylines(data=data2,~lon,~lat,color="green")%>%

addCircles(data=data,~lon, ~lat,popup = ~address,color=~Type)

是不是觉得花样不够多呀,那好吧,以下这些,全部都送给你,那好不谢!

###############################

# OpenStreetMap.Mapnik

# OpenStreetMap.BlackAndWhite

# OpenStreetMap.DE

# OpenStreetMap.France

# OpenStreetMap.HOT

# OpenTopoMap

# Thunderforest.OpenCycleMap

# Thunderforest.Transport

# Thunderforest.TransportDark

# Thunderforest.SpinalMap

# Thunderforest.Landscape

# Thunderforest.Outdoors

# Thunderforest.Pioneer

# OpenMapSurfer.Roads

# OpenMapSurfer.Grayscale

# Hydda.Full

# Stamen.Toner

# Stamen.TonerBackground

# Stamen.TonerLite

# Stamen.Watercolor

# Stamen.Terrain

# Stamen.TerrainBackground

# Stamen.TopOSMRelief

# Esri.WorldStreetMap

# Esri.DeLorme

# Esri.WorldTopoMap

# Esri.WorldImagery

# Esri.WorldTerrain

# Esri.WorldShadedRelief

# Esri.WorldPhysical

# Esri.OceanBasemap

# Esri.NatGeoWorldMap

# Esri.WorldGrayCanvas

# MtbMap

# CartoDB.Positron

# CartoDB.PositronNoLabels

# CartoDB.PositronOnlyLabels

# CartoDB.DarkMatter

# CartoDB.DarkMatterNoLabels

# CartoDB.DarkMatterOnlyLabels

# HikeBike.HikeBike

# HikeBike.HillShading

# NASAGIBS.ModisTerraTrueColorCR

# NASAGIBS.ModisTerraBands367CR

# NASAGIBS.ViirsEarthAtNight2012

# NASAGIBS.ModisTerraLSTDay

# NASAGIBS.ModisTerraSnowCover

# NASAGIBS.ModisTerraAOD

# NASAGIBS.ModisTerraChlorophyll

到此,关于"leaflet怎么构造路径图"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!

0