Skip to content

Commit

Permalink
add fmt_gps_josn funs to transform df to echarts lines json data
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceZhaoR committed Oct 12, 2018
1 parent b2c4e78 commit 601c6b0
Show file tree
Hide file tree
Showing 9 changed files with 376 additions and 3 deletions.
9 changes: 6 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ BugReports: https://github.com/BruceZhaoR/pjutils/issues
Depends:
R (>= 3.5)
Imports:
Rcpp
Rcpp,
tibble,
magrittr
Suggests:
dplyr,
knitr,
rmarkdown,
testthat,
tibble,
tidyselect,
microbenchmark,
ggplot2,
covr
covr,
jsonlite,
purrr
LinkingTo:
Rcpp
VignetteBuilder: knitr
Expand Down
15 changes: 15 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,35 @@
S3method(fill_na,data.frame)
S3method(fill_na,default)
S3method(fill_na,tbl_df)
export("%>%")
export(add_row)
export(as_data_frame)
export(as_tibble)
export(auc)
export(bd2gcj)
export(bd2wgs)
export(binary_search_cpp)
export(binary_search_r)
export(cal_user_coef)
export(data_frame)
export(fill_na)
export(fmt_gps_json)
export(gcj2bd)
export(gcj2wgs)
export(get_score)
export(get_score_vec)
export(glimpse)
export(rf2score)
export(sum_rf_score)
export(tibble)
export(wgs2bd)
export(wgs2gcj)
importFrom(Rcpp,sourceCpp)
importFrom(magrittr,"%>%")
importFrom(tibble,add_row)
importFrom(tibble,as_data_frame)
importFrom(tibble,as_tibble)
importFrom(tibble,data_frame)
importFrom(tibble,glimpse)
importFrom(tibble,tibble)
useDynLib(pjutils, .registration = TRUE)
25 changes: 25 additions & 0 deletions R/coordinate_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,28 @@ bd2wgs <- function(bd_lon, bd_lat){
c(wgs_lon, wgs_lat)
}

#' Generate GPS lines data for echarts
#'
#' Your can see the package/inst/misc files.
#'
#' @param df data.frame with starLon, starLat, endLon, endLat
#'
#' @return json txt
#' @export
#'
#' @examples
#' \dontrun{
#' test <- select(df, startLon, startLat, endLon, endLat)
#' as_tibble(t(apply(test, 1, function(x) {
#' x <- as.numeric(x)
#' start_gps <- wgs2bd(x[1], x[2])
#' end_gps <- wgs2bd(x[3], x[4])
#' c(start_gps[1], start_gps[2], end_gps[1], end_gps[2])
#' })))
#'}
fmt_gps_json <- function(df) {
list_mat <- df %>%
purrr::pmap( ~ matrix(c(..1, ..2, ..3, ..4), byrow = TRUE, ncol = 2))
tibble::tibble(coords = list_mat) %>%
jsonlite::toJSON()
}
29 changes: 29 additions & 0 deletions R/reexport-tibble.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# dataframe ---------------------------------------------------------------

#' @importFrom tibble data_frame
#' @export
tibble::data_frame

#' @importFrom tibble as_data_frame
#' @export
tibble::as_data_frame


#' @importFrom tibble add_row
#' @export
tibble::add_row

# glimpse -----------------------------------------------------------------

#' @importFrom tibble glimpse
#' @export
tibble::glimpse

#' @importFrom tibble tibble
#' @export
tibble::tibble

#' @importFrom tibble as_tibble
#' @export
tibble::as_tibble

3 changes: 3 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#' @importFrom magrittr %>%
#' @export
magrittr::`%>%`

#' Get the position of x in vector y
#'
Expand Down
244 changes: 244 additions & 0 deletions inst/misc/gps-start-end-lines-template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
<!DOCTYPE html>
<html style="height: 100%">
<head>
<meta charset="utf-8">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/echarts-all-3.js"></script>
<script type="text/javascript" src="js/ecStat.min.js"></script>
<script type="text/javascript" src="js/dataTool.min.js"></script>
<script type="text/javascript" src="js/china.js"></script>
<script type="text/javascript" src="js/world.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/getscript?v=2.0&ak=30DBi9lWqva00t5mPZyonlzpQroDtfiC"></script>
<script type="text/javascript" src="js/bmap.min.js"></script>

<title>上海市</title>
</head>

<body style="height: 100%; margin: 0">
<div id="container" style="height: 100%"></div>
<script type="text/javascript">
var dom = document.getElementById("container");
var myChart = echarts.init(dom);


$.getJSON('../json/<<usr_id>>.json', function(data) {
var lines = data;

myChart.setOption(option = {
bmap: {
center: [121.480524,31.23595],
zoom: 12,
roam: true,
// mapStyle: {
// styleJson: [
// {
// 'featureType': 'land', //调整土地颜色
// 'elementType': 'geometry',
// 'stylers': {
// 'color': '#081734'
// }
// },
// {
// 'featureType': 'building', //调整建筑物颜色
// 'elementType': 'geometry',
// 'stylers': {
// 'color': '#04406F'
// }
// },
// {
// 'featureType': 'building', //调整建筑物标签是否可视
// 'elementType': 'labels',
// 'stylers': {
// 'visibility': 'on'
// }
// },
// {
// 'featureType': 'highway', //调整高速道路颜色
// 'elementType': 'geometry',
// 'stylers': {
// 'visibility': 'off'
// // 'color': '#015B99'
// }
// },
// {
// 'featureType': 'highway', //调整高速名字是否可视
// 'elementType': 'labels',
// 'stylers': {
// 'visibility': 'off'
// }
// },
// {
// 'featureType': 'arterial', //调整一些干道颜色
// 'elementType': 'geometry',
// 'stylers': {
// 'color':'#003051'
// }
// },
// {
// 'featureType': 'arterial',
// 'elementType': 'labels',
// 'stylers': {
// 'visibility': 'off'
// }
// },
// {
// 'featureType': 'green',
// 'elementType': 'geometry',
// 'stylers': {
// 'visibility': 'off'
// }
// },
// {
// 'featureType': 'water',
// 'elementType': 'geometry',
// 'stylers': {
// 'color': '#044161'
// }
// },
// {
// 'featureType': 'subway', //调整地铁颜色
// 'elementType': 'geometry.stroke',
// 'stylers': {
// 'visibility': 'off'
// // 'color': '#003051'
// }
// },
// {
// 'featureType': 'subway',
// 'elementType': 'labels',
// 'stylers': {
// 'visibility': 'off'
// }
// },
// {
// 'featureType': 'railway',
// 'elementType': 'geometry',
// 'stylers': {
// 'visibility': 'off'
// }
// },
// {
// 'featureType': 'railway',
// 'elementType': 'labels',
// 'stylers': {
// 'visibility': 'off'
// }
// },
// {
// 'featureType': 'all', //调整所有的标签的边缘颜色
// 'elementType': 'labels.text.stroke',
// 'stylers': {
// 'color': '#313131'
// }
// },
// {
// 'featureType': 'all', //调整所有标签的填充颜色
// 'elementType': 'labels.text.fill',
// 'stylers': {
// 'color': '#FFFFFF'
// }
// },
// {
// 'featureType': 'manmade',
// 'elementType': 'geometry',
// 'stylers': {
// 'visibility': 'off'
// }
// },
// {
// 'featureType': 'manmade',
// 'elementType': 'labels',
// 'stylers': {
// 'visibility': 'on'
// }
// },
// {
// 'featureType': 'local',
// 'elementType': 'geometry',
// 'stylers': {
// 'visibility': 'off'
// }
// },
// {
// 'featureType': 'local',
// 'elementType': 'labels',
// 'stylers': {
// 'visibility': 'off'
// }
// },
// {
// 'featureType': 'subway',
// 'elementType': 'geometry',
// 'stylers': {
// 'lightness': -65
// }
// },
// {
// 'featureType': 'railway',
// 'elementType': 'all',
// 'stylers': {
// 'lightness': -40
// }
// },
// {
// 'featureType': 'boundary',
// 'elementType': 'geometry',
// 'stylers': {
// 'color': '#8b8787',
// 'weight': '1',
// 'lightness': 10
// }
// }]
// }
},
title: {
text: '\n 用户行程的起点终点分布情况',
left: 'center',
textStyle: {
color: '#fff',
fontWeight: 'bold',
fontSize: 26
}
},
series: [ {
type: 'lines',
coordinateSystem: 'bmap',
polyline: false,
data: lines,
large:true,
lineStyle: {
normal: {
color: '#66C2A5',
width: 1.5,
opacity: 0.5,
curveness: 0.2,
}
},
effect: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 1,
y2: 1,
colorStops: [{
offset: 0, color: 'red' // 0% 处的颜色
}, {
offset: 1, color: 'blue' // 100% 处的颜色
}],
globalCoord: true // 缺省为 false
},
constantSpeed: 30,
show: true,
trailLength: 0,
symbol: 'pin',
symbolSize: 5
},
zlevel: 1
}],
blendMode: 'lighter'
});
});
</script>
</body>
</html>
28 changes: 28 additions & 0 deletions man/fmt_gps_json.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 601c6b0

Please sign in to comment.