SymbolixAU / mapdeck
1
#include <Rcpp.h>
2

3
#include "mapdeck_defaults.hpp"
4
#include "layers/layer_colours.hpp"
5
#include "spatialwidget/spatialwidget.hpp"
6

7 1
Rcpp::List line_defaults(int n) {
8 1
	return Rcpp::List::create(
9 1
		_["stroke_colour"] = mapdeck::defaults::default_stroke_colour(n),
10 1
		_["stroke_width"] = mapdeck::defaults::default_stroke_width(n),
11 1
		_["height"] = mapdeck::defaults::default_arc_height(n)
12
	);
13
}
14

15 1
Rcpp::List arc_defaults(int n) {
16 1
	return Rcpp::List::create(
17 1
		_["stroke_from"] = mapdeck::defaults::default_stroke_colour(n),
18 1
		_["stroke_to"] = mapdeck::defaults::default_stroke_colour(n),
19 1
		_["tilt"] = mapdeck::defaults::default_arc_tilt(n),
20 1
		_["height"] = mapdeck::defaults::default_arc_height(n)
21
	);
22
}
23

24 0
Rcpp::List greatcircle_defaults(int n) {
25 0
	return Rcpp::List::create(
26 0
		_["stroke_from"] = mapdeck::defaults::default_stroke_colour(n),
27 0
		_["stroke_to"] = mapdeck::defaults::default_stroke_colour(n),
28 0
		_["tilt"] = mapdeck::defaults::default_arc_tilt(n),
29 0
		_["height"] = mapdeck::defaults::default_arc_height(n)
30
	);
31
}
32

33 1
Rcpp::List get_od_defaults( std::string layer_name, int data_rows ) {
34 1
	if( layer_name == "line" ) {
35 1
		return line_defaults( data_rows );
36 1
	} else if ( layer_name == "arc" ) {
37 1
		return arc_defaults( data_rows );
38
	}
39 0
	return greatcircle_defaults( data_rows );
40
}
41

42

43

44

45 1
std::unordered_map< std::string, std::string > get_od_colours( std::string layer_name ) {
46

47 1
	if( layer_name == "line" ) {
48 1
	  return mapdeck::layer_colours::stroke_colours;
49
	}
50

51
	// else arc, greatcircle
52 1
	return mapdeck::layer_colours::stroke_od_colours;
53
}
54

55 1
Rcpp::StringVector get_od_legend( std::string layer_name ) {
56

57 1
	if( layer_name == "line" ) {
58 1
		return mapdeck::layer_colours::stroke_legend;;
59
	}
60
	// else arc, greatcircle
61 1
	return mapdeck::layer_colours::stroke_od_legend;
62

63
}
64

65
// [[Rcpp::export]]
66 0
Rcpp::List rcpp_od_geojson(
67
		Rcpp::DataFrame data,
68
		Rcpp::List params,
69
		Rcpp::StringVector geometry_columns,
70
		int digits,
71
		std::string layer_name
72
) {
73

74 0
	int data_rows = data.nrows();
75

76 0
	Rcpp::List lst_defaults = get_od_defaults( layer_name, data_rows );
77

78 0
	std::unordered_map< std::string, std::string > od_colours = get_od_colours( layer_name );
79 0
	Rcpp::StringVector od_legend = get_od_legend( layer_name );
80

81 0
	Rcpp::StringVector parameter_exclusions = Rcpp::StringVector::create("legend","legend_options","palette","na_colour");
82

83 0
	return spatialwidget::api::create_geojson(
84
		data,
85
		params,
86
		lst_defaults,
87
		od_colours,
88
		od_legend,
89
		data_rows,
90
		parameter_exclusions,
91
		geometry_columns,
92
		true,  // jsonify legend
93 0
		digits
94
	);
95
}
96

97
// [[Rcpp::export]]
98 1
Rcpp::List rcpp_od_geojson_df(
99
		Rcpp::DataFrame data,
100
		Rcpp::List params,
101
		Rcpp::List geometry_columns,
102
		int digits,
103
		std::string layer_name
104
) {
105

106 1
	int data_rows = data.nrows();
107

108 1
	Rcpp::List lst_defaults = get_od_defaults( layer_name, data_rows );
109

110 1
	std::unordered_map< std::string, std::string > od_colours = get_od_colours( layer_name );
111 1
	Rcpp::StringVector od_legend = get_od_legend( layer_name );
112

113 1
	Rcpp::StringVector parameter_exclusions = Rcpp::StringVector::create("legend","legend_options","palette","na_colour");
114

115 1
	return spatialwidget::api::create_geojson(
116
		data,
117
		params,
118
		lst_defaults,
119
		od_colours,
120
		od_legend,
121
		data_rows,
122
		parameter_exclusions,
123
		geometry_columns,
124
		true,  // jsonify legend
125
		true,  // elevation
126 1
		digits
127
	);
128
}
129

130

131
// [[Rcpp::export]]
132 0
Rcpp::List rcpp_od_polyline(
133
		Rcpp::DataFrame data,
134
		Rcpp::List params,
135
		Rcpp::StringVector geometry_columns,
136
		std::string layer_name
137
) {
138

139 0
	int data_rows = data.nrows();
140

141 0
	Rcpp::List lst_defaults = get_od_defaults( layer_name, data_rows );
142

143 0
	std::unordered_map< std::string, std::string > od_colours = get_od_colours( layer_name );
144 0
	Rcpp::StringVector od_legend = get_od_legend( layer_name );
145

146 0
	Rcpp::StringVector parameter_exclusions = Rcpp::StringVector::create("legend","legend_options","palette","na_colour");
147

148 0
	return spatialwidget::api::create_polyline(
149
		data,
150
		params,
151
		lst_defaults,
152
		od_colours,
153
		od_legend,
154
		data_rows,
155
		parameter_exclusions,
156 0
		geometry_columns,
157
		true  // jsonify legend
158
	);
159
}

Read our documentation on viewing source code .

Loading