setRepositories()#1

chooseCRANmirror()#2

ibrary(leaflet)#学习地址:http://rstudio.github.io/leaflet/markers.html
library(leafletCN)
library(sp)

#library(devtools)
#install_github('badbye/baidumap')

#library(REmap)
#library(RbaiduMaps)#
library(baidumap)
options(baidumap.key='mkn2zLugAMjfTHCzYBFGE03k1gHTW8Kj')#我的百度api密钥
#library("RJSONIO")

#读取数据
nzddata=read.csv('C:\\Users\\lenovo\\Desktop\\产业园\\01chanye.csv')
#根据地址过去经纬???
long_bat=getCoordinate(nzddata$address, formatted = T)
nzddata$long=as.vector(long_bat[,1])
nzddata$bat=as.vector(long_bat[,2])
#添加提示???
nzddata$产业园全称
nzddata$show=paste(
paste0('<div class="t" style="">
<h3><a href="',nzddata$cyy_url,'" target="_blank">',nzddata$产业园全称 ,'</a></h3>'),
paste0( '地址:',nzddata$address,'<br/>'),
paste0('主导产业:',nzddata$主导产业,'<img src="',nzddata$url_icon,'" weight="34px" height="34px"><br/>'),
paste0( '类型:',nzddata$类型,'<br/>'),
paste0( '资金使用方案:','<a href="',nzddata$money_plan_url,'">资金使用方案</a><br/>'),
paste0('种植面积:',nzddata$种植.万亩.,'(万亩)<br/>'),
paste0('计划总投资:',nzddata$计划总投资,'(万元)<br/>'),
paste0('产业园带动农民数::',nzddata$产业园带动农民数量.人.,'(人)<br/>'),
#paste0('一二三产业融合情况:',nzddata$一二三产业融合情况,'<br/>'),
paste('产业园实施主体:',nzddata$产业园牵头实施主体名,'<br/></div>')
)
#分类添加图标
#iconList 生成小框

iconList = awesomeIconList(
"蔬菜" = makeAwesomeIcon(icon = "glyphicon-eye-open",markerColor = "#01F1F3",text='蔬菜'),
"水稻" = makeAwesomeIcon(icon = "cutlery",markerColor = "green",text='水稻'),
"花卉" = makeAwesomeIcon(icon = "plus-sign",markerColor = "orange",text='花卉'),
"茶叶" = makeAwesomeIcon(icon = "globe",markerColor = "purple",text='茶叶'),
"香芋" = makeAwesomeIcon(markerColor = "darkpurple",text='香芋'),
"猕猴桃" = makeAwesomeIcon(markerColor = "deeppink",text='猕猴桃'),
"桃子" = makeAwesomeIcon(markerColor = "darkred",text='桃子'),
"柚子" = makeAwesomeIcon(markerColor = "cadetblue",text='柚子'),
"橙子" = makeAwesomeIcon(markerColor = "darkpurple",text='橙子'),
"萝卜" = makeAwesomeIcon(markerColor = "dodgerblue",text='萝卜'),
"鱼" = makeAwesomeIcon(markerColor = "pink",text='鱼'),
"家禽" = makeAwesomeIcon(markerColor = "blue",text='家禽'),
"药材" = makeAwesomeIcon(markerColor = "beige",text='药材'),
"菠萝" = makeAwesomeIcon(markerColor = "lightgray",text='菠萝'),
"火龙果" = makeAwesomeIcon(markerColor = "red",text='火龙果'),
"荔枝" = makeAwesomeIcon(markerColor = "orangered1",text='荔枝'),
"沉香" = makeAwesomeIcon(markerColor = "pink",text='沉香'),
"青梅" = makeAwesomeIcon(markerColor = "sienna",text='青梅'),
"土猪" = makeAwesomeIcon(markerColor = "black",text='土猪')
)

library(stringr)
nzddata$shi=str_sub(nzddata$产业园全称,1,3)#节选字符串
#每个小框框的坐标,经纬度
nzddata$shi1=nzddata$类型

leaflet(nzddata)%>% addProviderTiles("Thunderforest.SpinalMap")%>%addTiles()%>%addAwesomeMarkers(lng=~long,lat=~bat,icon = ~iconList[shi1],popup=~show,label=~产业园全称)
#addMarkers(lng=~long,lat=~lat,popup=~show,label=~dth_title)%>%

#涂色
region=regionNames("china")#找下级省-》市,市-》县,县-》村

dat = data.frame(region,c(runif(11),1,runif(22)))
map = leafletGeo("china", dat)

map1=map[c(1:11,13:32),]#qudiao

#涂色环节
pal <- colorNumeric(
#palette = c('#111946','yellow','green','red'),
palette = c('#0A0F23'),
domain = map1$value)

#
#载入高德地图amap
m=leaflet(map1) %>% amap() %>%
#加入框边界及颜色
addPolygons(stroke = TRUE,
smoothFactor = 0.1,
fillOpacity =1.1,
weight = 1,
color = ~pal(value),
popup = ~htmltools::htmlEscape(popup)
)%>% setView(lng='113.3',lat='21.9',zoom=6)%>%
addAwesomeMarkers(lng=nzddata$long,lat=nzddata$bat,icon = ~iconList[nzddata$shi1],popup=nzddata$show,label=nzddata$产业园全称)
m

04-13 16:32